Capítulo 232 de 859

Chapter 232: Texture

Core Idea

Base class for all textures.

Note: After the initial use of a texture, its dimensions, format, and type cannot be changed. Instead, call Texture#dispose on the texture and instantiate a new one.

Key Concepts

  • anisotropy : number: The number of samples taken along the axis through the pixel that has the highest density of texels. By default, this value is 1. A highe…
  • center : Vector2: The point around which rotation occurs. A value of (0.5, 0.5) corresponds to the center of the texture. Default is (0, 0), the lower le…
  • channel : number: Lets you select the uv attribute to map the texture to. 0 for uv, 1 for uv1, 2 for uv2 and 3 for uv3.
  • colorSpace : string: Textures containing color data should be annotated with SRGBColorSpace or LinearSRGBColorSpace.
  • depth: The depth of the texture in pixels.
  • flipY : boolean: If set to true, the texture is flipped along the vertical axis when uploaded to the GPU.
  • format : number: The format of the texture.
  • generateMipmaps : boolean: Whether to generate mipmaps (if possible) for a texture.
  • height: The height of the texture in pixels.
  • id : number (readonly): The ID of the texture.

Reference Tables

Constructor

Signature
new Texture( image : Object, mapping : number, wrapS : number, wrapT : number, magFilter : number, minFilter : number, format : number, type : number, anisotropy : number, colorSpace : string )

Properties

PropertyDescription
.anisotropy : numberThe number of samples taken along the axis through the pixel that has the highest density of texels. By default, this value is 1. A higher value gives a less blurry result than a basic mipmap, at t…
.center : Vector2The point around which rotation occurs. A value of (0.5, 0.5) corresponds to the center of the texture. Default is (0, 0), the lower left.
.channel : numberLets you select the uv attribute to map the texture to. 0 for uv, 1 for uv1, 2 for uv2 and 3 for uv3.
.colorSpace : stringTextures containing color data should be annotated with SRGBColorSpace or LinearSRGBColorSpace.
.depthThe depth of the texture in pixels.
.flipY : booleanIf set to true, the texture is flipped along the vertical axis when uploaded to the GPU.
.format : numberThe format of the texture.
.generateMipmaps : booleanWhether to generate mipmaps (if possible) for a texture.
.heightThe height of the texture in pixels.
.id : number (readonly)The ID of the texture.
.image : ObjectThe image object holding the texture data.
.internalFormat : stringThe default internal format is derived from Texture#format and Texture#type and defines how the texture data is going to be stored on the GPU.
.isArrayTexture : boolean (readonly)Indicates if a texture should be handled like a texture array.
.isRenderTargetTexture : boolean (readonly)Indicates whether a texture belongs to a render target or not.
.isTexture : boolean (readonly)This flag can be used for type testing.
`.magFilter : NearestFilterNearestMipmapNearestFilter
`.mapping : UVMappingCubeReflectionMapping
.matrix : Matrix3The uv-transformation matrix of the texture.
.matrixAutoUpdate : booleanWhether to update the texture's uv-transformation Texture#matrix from the properties Texture#offset, Texture#repeat, [Texture#rota…
`.minFilter : NearestFilterNearestMipmapNearestFilter
.mipmaps : Array.<Object>An array holding user-defined mipmaps.
.name : stringThe name of the texture.
.needsPMREMUpdate : booleanSetting this property to true indicates the engine the PMREM must be regenerated.
.needsUpdate : booleanSetting this property to true indicates the engine the texture must be updated in the next render. This triggers a texture upload to the GPU and ensures correct texture parameter configuration.
.normalized : booleanWhether the texture should use one of the 16 bit integer formats which are normalized to [0, 1] or [-1, 1] (depending on signed/unsigned) when sampled.
.offset : Vector2How much a single repetition of the texture is offset from the beginning, in each direction U and V. Typical range is 0.0 to 1.0.
.onUpdate : functionA callback function, called when the texture is updated (e.g., when Texture#needsUpdate has been set to true and then the texture is used).
.pmremVersion : number (readonly)Indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures).
.premultiplyAlpha : booleanIf set to true, the alpha channel, if present, is multiplied into the color channels when the texture is uploaded to the GPU.
`.renderTarget : RenderTargetWebGLRenderTarget`
.repeat : Vector2How many times the texture is repeated across the surface, in each direction U and V. If repeat is set greater than 1 in either direction, the corresponding wrap parameter should also be set to `Re…
.rotation : numberHow much the texture is rotated around the center point, in radians. Positive values are counter-clockwise.
.source : SourceThe data definition of a texture. A reference to the data source can be shared across textures. This is often useful in context of spritesheets where multiple textures render the same data but with d…
.type : numberThe data type of the texture.
.unpackAlignment : numberSpecifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8
.updateRanges : Array.<Object>This can be used to only update a subregion or specific rows of the texture (for example, just the first 3 rows). Use the addUpdateRange() function to add ranges to this array.
.userData : ObjectAn object that can be used to store custom data about the texture. It should not hold references to functions as these will not be cloned.
.uuid : string (readonly)The UUID of the texture.
.version : number (readonly)This starts at 0 and counts how many times Texture#needsUpdate is set to true.
.widthThe width of the texture in pixels.
`.wrapS : RepeatWrappingClampToEdgeWrapping
`.wrapT : RepeatWrappingClampToEdgeWrapping
.DEFAULT_ANISOTROPY : numberThe default anisotropy value for all textures.
.DEFAULT_IMAGE : ImageThe default image for all textures.
.DEFAULT_MAPPING : numberThe default mapping for all textures.

Methods

MethodDescription
.addUpdateRange( start : number, count : number )Adds a range of data in the data texture to be updated on the GPU.
.clearUpdateRanges()Clears the update ranges.
.clone() : TextureReturns a new texture with copied values from this instance.
.copy( source : Texture ) : TextureCopies the values of the given texture to this instance.
.dispose()Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
.setValues( values : Object )Sets this texture's properties based on values.
`.toJSON( meta : Objectstring ) : Object`
.transformUv( uv : Vector2 ) : Vector2Transforms the given uv vector with the textures uv transformation matrix.
.updateMatrix()Updates the texture transformation matrix from the properties Texture#offset, Texture#repeat, Texture#rotation, and [Texture#cen…

Key Takeaways

  1. Texture extends: EventDispatcher
  2. Most relevant properties: anisotropy, center, channel, colorSpace.
  3. Key methods: addUpdateRange, clearUpdateRanges, clone, copy.

Connects To