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.
Constructs a new buffer attribute.
array
The array holding the attribute data.
itemSize
The item size.
normalized
Whether the data are normalized or not.
Default is false.
The array holding the attribute data. It should have itemSize * numVertices elements, where numVertices is the number of vertices in the associated geometry.
Represents the number of items this buffer attribute stores. It is internally computed by dividing the array length by the itemSize.
Configures the bound GPU type for use in shaders.
Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, use Float16BufferAttribute.
Default is FloatType.
The ID of the buffer attribute.
This flag can be used for type testing.
Default is true.
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 value should be 3.
The name of the buffer attribute.
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.
Default is false.
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, the values 0 - +65535 in the array data will be mapped to 0.0f - +1.0f in the GLSL attribute. If normalized is false, the values will be converted to floats unmodified, i.e. 65535 becomes 65535.0f.
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.
Defines the intended usage pattern of the data store for optimization purposes.
Note: After the initial use of a buffer, its usage cannot be changed. Instead, instantiate a new one and set the desired usage before the next render.
Default is StaticDrawUsage.
A version number, incremented every time the needsUpdate is set to true.
Adds a range of data in the data array to be updated on the GPU.
start
Position at which to start update.
count
The number of components to update.
Applies the given 3x3 matrix to the given attribute. Works with item size 2 and 3.
m
The matrix to apply.
Returns: A reference to this instance.
Applies the given 4x4 matrix to the given attribute. Only works with item size 3.
m
The matrix to apply.
Returns: A reference to this instance.
Applies the given 3x3 normal matrix to the given attribute. Only works with item size 3.
m
The normal matrix to apply.
Returns: A reference to this instance.
Clears the update ranges.
Returns a new buffer attribute with copied values from this instance.
Returns: A clone of this instance.
Copies the values of the given buffer attribute to this instance.
source
The buffer attribute to copy.
Returns: A reference to this instance.
Copies the given array data into this buffer attribute.
array
The array to copy.
Returns: A reference to this instance.
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.
index1
The destination index into this buffer attribute.
attribute
The buffer attribute to copy from.
index2
The source index into the given buffer attribute.
Returns: A reference to this instance.
Returns the given component of the vector at the given index.
index
The index into the buffer attribute.
component
The component index.
Returns: The returned value.
Returns the w component of the vector at the given index.
index
The index into the buffer attribute.
Returns: The w component.
Returns the x component of the vector at the given index.
index
The index into the buffer attribute.
Returns: The x component.
Returns the y component of the vector at the given index.
index
The index into the buffer attribute.
Returns: The y component.
Returns the z component of the vector at the given index.
index
The index into the buffer attribute.
Returns: The z component.
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 data are not needed anymore on the CPU side.
callback
The onUpload() callback.
Returns: A reference to this instance.
A callback function that is executed after the renderer has transferred the attribute array data to the GPU.
Sets the given array data in the buffer attribute.
value
The array data to set.
offset
The offset in this buffer attribute's array.
Default is 0.
Returns: A reference to this instance.
Sets the given value to the given component of the vector at the given index.
index
The index into the buffer attribute.
component
The component index.
value
The value to set.
Returns: A reference to this instance.
Sets the usage of this buffer attribute.
value
The usage to set.
Returns: A reference to this buffer attribute.
Sets the w component of the vector at the given index.
index
The index into the buffer attribute.
w
The value to set.
Returns: A reference to this instance.
Sets the x component of the vector at the given index.
index
The index into the buffer attribute.
x
The value to set.
Returns: A reference to this instance.
Sets the x and y component of the vector at the given index.
index
The index into the buffer attribute.
x
The value for the x component to set.
y
The value for the y component to set.
Returns: A reference to this instance.
Sets the x, y and z component of the vector at the given index.
index
The index into the buffer attribute.
x
The value for the x component to set.
y
The value for the y component to set.
z
The value for the z component to set.
Returns: A reference to this instance.
Sets the x, y, z and w component of the vector at the given index.
index
The index into the buffer attribute.
x
The value for the x component to set.
y
The value for the y component to set.
z
The value for the z component to set.
w
The value for the w component to set.
Returns: A reference to this instance.
Sets the y component of the vector at the given index.
index
The index into the buffer attribute.
y
The value to set.
Returns: A reference to this instance.
Sets the z component of the vector at the given index.
index
The index into the buffer attribute.
z
The value to set.
Returns: A reference to this instance.
Serializes the buffer attribute into JSON.
Returns: A JSON object representing the serialized buffer attribute.
Applies the given 4x4 matrix to the given attribute. Only works with item size 3 and with direction vectors.
m
The matrix to apply.
Returns: A reference to this instance.