-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
src/textures: move to es6 classes #20009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mrdoob
merged 16 commits into
mrdoob:dev
from
DefinitelyMaybe:src/textures--move-to-es6-classes
Feb 20, 2021
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
503e10e
move to es6 classes
DefinitelyMaybe 65cf52e
is* adjustment
DefinitelyMaybe d661009
id update & static props
DefinitelyMaybe e098de5
linting update
DefinitelyMaybe 16f7d68
Object.defineProperty()
DefinitelyMaybe 4245df7
Merge branch 'dev' into src/textures--move-to-es6-classes
DefinitelyMaybe da12e00
linting fix
DefinitelyMaybe 88c78b6
Merge branch 'dev' into src/textures--move-to-es6-classes
DefinitelyMaybe b263538
lint fix
DefinitelyMaybe 6298c07
serializeImage -> this.serializeImage
DefinitelyMaybe a3475bd
move to static variables
DefinitelyMaybe 921c087
back to static and catches on serializeImage
DefinitelyMaybe be7cf4f
Merge branch 'src/textures--move-to-es6-classes' of https://github.co…
DefinitelyMaybe 2d31d48
using static class properties again
DefinitelyMaybe e90d0bd
serializeImage back to internal helper function
DefinitelyMaybe a45af31
reintroduce class.prototype.is* properties
DefinitelyMaybe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,17 @@ | ||
| import { Texture } from './Texture.js'; | ||
|
|
||
| function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) { | ||
| class CanvasTexture extends Texture { | ||
|
|
||
| Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); | ||
| constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) { | ||
|
|
||
| this.needsUpdate = true; | ||
| super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); | ||
|
|
||
| } | ||
| Object.defineProperty( this, 'isCanvasTexture', { value: true } ); | ||
|
|
||
| this.needsUpdate = true; | ||
|
|
||
| CanvasTexture.prototype = Object.create( Texture.prototype ); | ||
| CanvasTexture.prototype.constructor = CanvasTexture; | ||
| CanvasTexture.prototype.isCanvasTexture = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export { CanvasTexture }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,28 @@ | ||
| import { Texture } from './Texture.js'; | ||
|
|
||
| function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { | ||
| class CompressedTexture extends Texture { | ||
|
|
||
| Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); | ||
| constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { | ||
|
|
||
| this.image = { width: width, height: height }; | ||
| this.mipmaps = mipmaps; | ||
| super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); | ||
|
|
||
| // no flipping for cube textures | ||
| // (also flipping doesn't work for compressed textures ) | ||
| Object.defineProperty( this, 'isCompressedTexture', { value: true } ); | ||
|
|
||
| this.flipY = false; | ||
| this.image = { width: width, height: height }; | ||
| this.mipmaps = mipmaps; | ||
|
|
||
| // can't generate mipmaps for compressed textures | ||
| // mips must be embedded in DDS files | ||
| // no flipping for cube textures | ||
| // (also flipping doesn't work for compressed textures ) | ||
|
|
||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
|
|
||
| } | ||
| // can't generate mipmaps for compressed textures | ||
| // mips must be embedded in DDS files | ||
|
|
||
| CompressedTexture.prototype = Object.create( Texture.prototype ); | ||
| CompressedTexture.prototype.constructor = CompressedTexture; | ||
| this.generateMipmaps = false; | ||
|
|
||
| CompressedTexture.prototype.isCompressedTexture = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export { CompressedTexture }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,46 @@ | ||
| import { Texture } from './Texture.js'; | ||
| import { CubeReflectionMapping, RGBFormat } from '../constants.js'; | ||
|
|
||
| function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) { | ||
| class CubeTexture extends Texture { | ||
|
|
||
| images = images !== undefined ? images : []; | ||
| mapping = mapping !== undefined ? mapping : CubeReflectionMapping; | ||
| format = format !== undefined ? format : RGBFormat; | ||
| constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) { | ||
|
|
||
| Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); | ||
| images = images !== undefined ? images : []; | ||
| mapping = mapping !== undefined ? mapping : CubeReflectionMapping; | ||
| format = format !== undefined ? format : RGBFormat; | ||
|
|
||
| this.flipY = false; | ||
| super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); | ||
|
|
||
| // Why CubeTexture._needsFlipEnvMap is necessary: | ||
| // | ||
| // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js) | ||
| // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words, | ||
| // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly. | ||
| Object.defineProperty( this, 'isCubeTexture', { value: true } ); | ||
|
|
||
| // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped | ||
| // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false) | ||
| // when using WebGLCubeRenderTarget.texture as a cube texture. | ||
| // Why CubeTexture._needsFlipEnvMap is necessary: | ||
| // | ||
| // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js) | ||
| // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words, | ||
| // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly. | ||
|
|
||
| this._needsFlipEnvMap = true; | ||
| // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped | ||
| // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false) | ||
| // when using WebGLCubeRenderTarget.texture as a cube texture. | ||
|
|
||
| } | ||
|
|
||
| CubeTexture.prototype = Object.create( Texture.prototype ); | ||
| CubeTexture.prototype.constructor = CubeTexture; | ||
| this._needsFlipEnvMap = true; | ||
|
|
||
| CubeTexture.prototype.isCubeTexture = true; | ||
| this.flipY = false; | ||
|
|
||
| Object.defineProperty( CubeTexture.prototype, 'images', { | ||
| } | ||
|
|
||
| get: function () { | ||
| get images() { | ||
|
|
||
| return this.image; | ||
|
|
||
| }, | ||
| } | ||
|
|
||
| set: function ( value ) { | ||
| set images( value ) { | ||
|
|
||
| this.image = value; | ||
|
|
||
| } | ||
|
|
||
| } ); | ||
|
|
||
| } | ||
|
|
||
| export { CubeTexture }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,27 @@ | ||
| import { Texture } from './Texture.js'; | ||
| import { NearestFilter } from '../constants.js'; | ||
|
|
||
| function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { | ||
| class DataTexture extends Texture { | ||
|
|
||
| Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); | ||
| constructor( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { | ||
|
|
||
| this.image = { data: data || null, width: width || 1, height: height || 1 }; | ||
| super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); | ||
|
|
||
| this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; | ||
| this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; | ||
| Object.defineProperty( this, 'isDataTexture', { value: true } ); | ||
|
|
||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
| this.unpackAlignment = 1; | ||
| this.image = { data: data || null, width: width || 1, height: height || 1 }; | ||
|
|
||
| this.needsUpdate = true; | ||
| this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; | ||
| this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; | ||
|
|
||
| } | ||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
| this.unpackAlignment = 1; | ||
|
|
||
| DataTexture.prototype = Object.create( Texture.prototype ); | ||
| DataTexture.prototype.constructor = DataTexture; | ||
| this.needsUpdate = true; | ||
|
|
||
| DataTexture.prototype.isDataTexture = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export { DataTexture }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,28 @@ | ||
| import { Texture } from './Texture.js'; | ||
| import { ClampToEdgeWrapping, NearestFilter } from '../constants.js'; | ||
|
|
||
| function DataTexture2DArray( data = null, width = 1, height = 1, depth = 1 ) { | ||
| class DataTexture2DArray extends Texture { | ||
|
|
||
| Texture.call( this, null ); | ||
| constructor( data = null, width = 1, height = 1, depth = 1 ) { | ||
|
|
||
| this.image = { data, width, height, depth }; | ||
| super( null ); | ||
|
|
||
| this.magFilter = NearestFilter; | ||
| this.minFilter = NearestFilter; | ||
| Object.defineProperty( this, 'isDataTexture2DArray', { value: true } ); | ||
|
|
||
| this.wrapR = ClampToEdgeWrapping; | ||
| this.image = { data, width, height, depth }; | ||
|
|
||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
| this.magFilter = NearestFilter; | ||
| this.minFilter = NearestFilter; | ||
|
|
||
| this.needsUpdate = true; | ||
| this.wrapR = ClampToEdgeWrapping; | ||
|
|
||
| } | ||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
|
|
||
| this.needsUpdate = true; | ||
|
|
||
| DataTexture2DArray.prototype = Object.create( Texture.prototype ); | ||
| DataTexture2DArray.prototype.constructor = DataTexture2DArray; | ||
| DataTexture2DArray.prototype.isDataTexture2DArray = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export { DataTexture2DArray }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,36 @@ | ||
| import { Texture } from './Texture.js'; | ||
| import { ClampToEdgeWrapping, NearestFilter } from '../constants.js'; | ||
|
|
||
| function DataTexture3D( data = null, width = 1, height = 1, depth = 1 ) { | ||
| class DataTexture3D extends Texture { | ||
|
|
||
| // We're going to add .setXXX() methods for setting properties later. | ||
| // Users can still set in DataTexture3D directly. | ||
| // | ||
| // const texture = new THREE.DataTexture3D( data, width, height, depth ); | ||
| // texture.anisotropy = 16; | ||
| // | ||
| // See #14839 | ||
| constructor( data = null, width = 1, height = 1, depth = 1 ) { | ||
|
|
||
| Texture.call( this, null ); | ||
| // We're going to add .setXXX() methods for setting properties later. | ||
| // Users can still set in DataTexture3D directly. | ||
| // | ||
| // const texture = new THREE.DataTexture3D( data, width, height, depth ); | ||
| // texture.anisotropy = 16; | ||
| // | ||
| // See #14839 | ||
|
|
||
| this.image = { data, width, height, depth }; | ||
| super( null ); | ||
|
|
||
| this.magFilter = NearestFilter; | ||
| this.minFilter = NearestFilter; | ||
| Object.defineProperty( this, 'isDataTexture3D', { value: true } ); | ||
|
|
||
| this.wrapR = ClampToEdgeWrapping; | ||
| this.image = { data, width, height, depth }; | ||
|
|
||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
| this.magFilter = NearestFilter; | ||
| this.minFilter = NearestFilter; | ||
|
|
||
| this.needsUpdate = true; | ||
| this.wrapR = ClampToEdgeWrapping; | ||
|
|
||
| this.generateMipmaps = false; | ||
| this.flipY = false; | ||
|
|
||
| } | ||
| this.needsUpdate = true; | ||
|
|
||
| } | ||
|
|
||
| DataTexture3D.prototype = Object.create( Texture.prototype ); | ||
| DataTexture3D.prototype.constructor = DataTexture3D; | ||
| DataTexture3D.prototype.isDataTexture3D = true; | ||
| } | ||
|
|
||
| export { DataTexture3D }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,36 @@ | ||
| import { Texture } from './Texture.js'; | ||
| import { NearestFilter, UnsignedShortType, UnsignedInt248Type, DepthFormat, DepthStencilFormat } from '../constants.js'; | ||
|
|
||
| function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) { | ||
| class DepthTexture extends Texture { | ||
|
|
||
| format = format !== undefined ? format : DepthFormat; | ||
| constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) { | ||
|
|
||
| if ( format !== DepthFormat && format !== DepthStencilFormat ) { | ||
| format = format !== undefined ? format : DepthFormat; | ||
|
|
||
| throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' ); | ||
| if ( format !== DepthFormat && format !== DepthStencilFormat ) { | ||
|
|
||
| } | ||
| throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' ); | ||
|
|
||
| if ( type === undefined && format === DepthFormat ) type = UnsignedShortType; | ||
| if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type; | ||
| } | ||
|
|
||
| Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); | ||
| if ( type === undefined && format === DepthFormat ) type = UnsignedShortType; | ||
| if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type; | ||
|
|
||
| this.image = { width: width, height: height }; | ||
| super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); | ||
|
|
||
| this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; | ||
| this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; | ||
| Object.defineProperty( this, 'isDepthTexture', { value: true } ); | ||
|
|
||
| this.flipY = false; | ||
| this.generateMipmaps = false; | ||
| this.image = { width: width, height: height }; | ||
|
|
||
| } | ||
| this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; | ||
| this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; | ||
|
|
||
| DepthTexture.prototype = Object.create( Texture.prototype ); | ||
| DepthTexture.prototype.constructor = DepthTexture; | ||
| DepthTexture.prototype.isDepthTexture = true; | ||
| this.flipY = false; | ||
| this.generateMipmaps = false; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| export { DepthTexture }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.