Capítulo 640 de 859

Chapter 640: BufferAttribute

Core Idea

This class stores data for an attribute (such as vertex positions, face indices, normals, colors, UVs, and any custom attributes ) associated with a geometry, which allows for more efficient passing of data to the GPU.

When working with vector-like data, the fromBufferAttribute( attribute, index ) helper methods on vector and color class might be helpful. E.g. Vector3#fromBufferAttribute.

Key Concepts

  • array : TypedArray: The array holding the attribute data. It should have itemSize * numVertices elements, where numVertices is the number of vertices in th…
  • count : number (readonly): Represents the number of items this buffer attribute stores. It is internally computed by dividing the array length by the itemSize.
  • gpuType : FloatType | IntType: Configures the bound GPU type for use in shaders.
  • id : number (readonly): The ID of the buffer attribute.
  • isBufferAttribute : boolean (readonly): This flag can be used for type testing.
  • itemSize : number: The number of values of the array that should be associated with a particular vertex. For instance, if this attribute is storing a 3-compon…
  • name : string: The name of the buffer attribute.
  • needsUpdate : number: Flag to indicate that this attribute has changed and should be re-sent to the GPU. Set this to true when you modify the value of the arra…
  • normalized : boolean: Applies to integer data only. Indicates how the underlying data in the buffer maps to the values in the GLSL code. For instance, if array
  • updateRanges : Array.<Object>: This can be used to only update some components of stored vectors (for example, just the component related to color). Use the `addUpdateRan…

Reference Tables

Constructor

Signature
new BufferAttribute( array : TypedArray, itemSize : number, normalized : boolean )

Properties

PropertyDescription
.array : TypedArrayThe array holding the attribute data. It should have itemSize * numVertices elements, where numVertices is the number of vertices in the associated geometry.
.count : number (readonly)Represents the number of items this buffer attribute stores. It is internally computed by dividing the array length by the itemSize.
`.gpuType : FloatTypeIntType`
.id : number (readonly)The ID of the buffer attribute.
.isBufferAttribute : boolean (readonly)This flag can be used for type testing.
.itemSize : numberThe number of values of the array that should be associated with a particular vertex. For instance, if this attribute is storing a 3-component vector (such as a position, normal, or color), then the …
.name : stringThe name of the buffer attribute.
.needsUpdate : numberFlag to indicate that this attribute has changed and should be re-sent to the GPU. Set this to true when you modify the value of the array.
.normalized : booleanApplies to integer data only. Indicates how the underlying data in the buffer maps to the values in the GLSL code. For instance, if array is an instance of UInt16Array, and normalized is true
.updateRanges : Array.<Object>This can be used to only update some components of stored vectors (for example, just the component related to color). Use the addUpdateRange() function to add ranges to this array.
`.usage : StaticDrawUsageDynamicDrawUsage
.version : numberA version number, incremented every time the needsUpdate is set to true.

Methods

MethodDescription
.addUpdateRange( start : number, count : number )Adds a range of data in the data array to be updated on the GPU.
.applyMatrix3( m : Matrix3 ) : BufferAttributeApplies the given 3x3 matrix to the given attribute. Works with item size 2 and 3.
.applyMatrix4( m : Matrix4 ) : BufferAttributeApplies the given 4x4 matrix to the given attribute. Only works with item size 3.
.applyNormalMatrix( m : Matrix3 ) : BufferAttributeApplies the given 3x3 normal matrix to the given attribute. Only works with item size 3.
.clearUpdateRanges()Clears the update ranges.
.clone() : BufferAttributeReturns a new buffer attribute with copied values from this instance.
.copy( source : BufferAttribute ) : BufferAttributeCopies the values of the given buffer attribute to this instance.
`.copyArray( array : TypedArrayArray ) : BufferAttribute`
.copyAt( index1 : number, attribute : BufferAttribute, index2 : number ) : BufferAttributeCopies a vector from the given buffer attribute to this one. The start and destination position in the attribute buffers are represented by the given indices.
.dispose()Disposes of the buffer attribute. Available only in WebGPURenderer.
.getComponent( index : number, component : number ) : numberReturns the given component of the vector at the given index.
.getW( index : number ) : numberReturns the w component of the vector at the given index.
.getX( index : number ) : numberReturns the x component of the vector at the given index.
.getY( index : number ) : numberReturns the y component of the vector at the given index.
.getZ( index : number ) : numberReturns the z component of the vector at the given index.
.onUpload( callback : function ) : BufferAttributeSets the given callback function that is executed after the Renderer has transferred the attribute array data to the GPU. Can be used to perform clean-up operations after the upload when attribute da…
.onUploadCallback()A callback function that is executed after the renderer has transferred the attribute array data to the GPU.
`.set( value : TypedArrayArray, offset : number ) : BufferAttribute`
.setComponent( index : number, component : number, value : number ) : BufferAttributeSets the given value to the given component of the vector at the given index.
`.setUsage( value : StaticDrawUsageDynamicDrawUsage
.setW( index : number, w : number ) : BufferAttributeSets the w component of the vector at the given index.
.setX( index : number, x : number ) : BufferAttributeSets the x component of the vector at the given index.
.setXY( index : number, x : number, y : number ) : BufferAttributeSets the x and y component of the vector at the given index.
.setXYZ( index : number, x : number, y : number, z : number ) : BufferAttributeSets the x, y and z component of the vector at the given index.
.setXYZW( index : number, x : number, y : number, z : number, w : number ) : BufferAttributeSets the x, y, z and w component of the vector at the given index.
.setY( index : number, y : number ) : BufferAttributeSets the y component of the vector at the given index.
.setZ( index : number, z : number ) : BufferAttributeSets the z component of the vector at the given index.
.toJSON() : ObjectSerializes the buffer attribute into JSON.
.transformDirection( m : Matrix4 ) : BufferAttributeApplies the given 4x4 matrix to the given attribute. Only works with item size 3 and with direction vectors.

Key Takeaways

  1. Most relevant properties: array, count, gpuType, id.
  2. Key methods: addUpdateRange, applyMatrix3, applyMatrix4, applyNormalMatrix.

Connects To