Capítulo 640 de 859
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.
itemSize * numVertices elements, where numVertices is the number of vertices in th…array length by the itemSize.true when you modify the value of the arra…array…Constructor
| Signature |
|---|
new BufferAttribute( array : TypedArray, itemSize : number, normalized : boolean ) |
Properties
| Property | Description |
|---|---|
.array : TypedArray | The 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 : FloatType | IntType` |
.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-component vector (such as a position, normal, or color), then the … |
.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 array. |
.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 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 : StaticDrawUsage | DynamicDrawUsage |
.version : number | A version number, incremented every time the needsUpdate is set to true. |
Methods
| Method | Description |
|---|---|
.addUpdateRange( start : number, count : number ) | Adds a range of data in the data array to be updated on the GPU. |
.applyMatrix3( m : Matrix3 ) : BufferAttribute | Applies the given 3x3 matrix to the given attribute. Works with item size 2 and 3. |
.applyMatrix4( m : Matrix4 ) : BufferAttribute | Applies the given 4x4 matrix to the given attribute. Only works with item size 3. |
.applyNormalMatrix( m : Matrix3 ) : BufferAttribute | Applies the given 3x3 normal matrix to the given attribute. Only works with item size 3. |
.clearUpdateRanges() | Clears the update ranges. |
.clone() : BufferAttribute | Returns a new buffer attribute with copied values from this instance. |
.copy( source : BufferAttribute ) : BufferAttribute | Copies the values of the given buffer attribute to this instance. |
| `.copyArray( array : TypedArray | Array ) : BufferAttribute` |
.copyAt( index1 : number, attribute : BufferAttribute, index2 : number ) : BufferAttribute | Copies 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 ) : number | Returns the given component of the vector at the given index. |
.getW( index : number ) : number | Returns the w component of the vector at the given index. |
.getX( index : number ) : number | Returns the x component of the vector at the given index. |
.getY( index : number ) : number | Returns the y component of the vector at the given index. |
.getZ( index : number ) : number | Returns the z component of the vector at the given index. |
.onUpload( callback : function ) : BufferAttribute | Sets 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 : TypedArray | Array, offset : number ) : BufferAttribute` |
.setComponent( index : number, component : number, value : number ) : BufferAttribute | Sets the given value to the given component of the vector at the given index. |
| `.setUsage( value : StaticDrawUsage | DynamicDrawUsage |
.setW( index : number, w : number ) : BufferAttribute | Sets the w component of the vector at the given index. |
.setX( index : number, x : number ) : BufferAttribute | Sets the x component of the vector at the given index. |
.setXY( index : number, x : number, y : number ) : BufferAttribute | Sets the x and y component of the vector at the given index. |
.setXYZ( index : number, x : number, y : number, z : number ) : BufferAttribute | Sets the x, y and z component of the vector at the given index. |
.setXYZW( index : number, x : number, y : number, z : number, w : number ) : BufferAttribute | Sets the x, y, z and w component of the vector at the given index. |
.setY( index : number, y : number ) : BufferAttribute | Sets the y component of the vector at the given index. |
.setZ( index : number, z : number ) : BufferAttribute | Sets the z component of the vector at the given index. |
.toJSON() : Object | Serializes the buffer attribute into JSON. |
.transformDirection( m : Matrix4 ) : BufferAttribute | Applies the given 4x4 matrix to the given attribute. Only works with item size 3 and with direction vectors. |