# [name]

This class stores data for an attribute (such as vertex positions, face indices, normals, colors, UVs, and any custom attributes ) associated with a [page:BufferGeometry], which allows for more efficient passing of data to the GPU. See that page for details and a usage example. When working with vector-like data, the .fromBufferAttribute( attribute, index ) helper methods on [page:Vector2.fromBufferAttribute Vector2], [page:Vector3.fromBufferAttribute Vector3], [page:Vector4.fromBufferAttribute Vector4], and [page:Color.fromBufferAttribute Color] classes may be helpful.

## Constructor

### [name]( [param:TypedArray array], [param:Integer itemSize], [param:Boolean normalized] )

[page:TypedArray array] -- Must be a [link:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/TypedArray TypedArray]. Used to instantiate the buffer.
This array should have `itemSize * numVertices` elements, where numVertices is the number of vertices in the associated [page:BufferGemetry BufferGeometry].
[page:Integer itemSize] -- 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 itemSize should be 3.
[page:Boolean normalized] -- (optional) Applies to integer data only. Indicates how the underlying data in the buffer maps to the values in the GLSL code. For instance, if [page:TypedArray array] is an instance of UInt16Array, and [page:Boolean normalized] is true, the values `0 - +65535` in the array data will be mapped to 0.0f - +1.0f in the GLSL attribute. An Int16Array (signed) would map from -32768 - +32767 to -1.0f - +1.0f. If [page:Boolean normalized] is false, the values will be converted to floats unmodified, i.e. 32767 becomes 32767.0f.

## Properties

### [property:TypedArray array]

The [page:TypedArray array] holding data stored in the buffer.

### [property:Integer count]

Represents the number of items this buffer attribute stores. It is internally computed by dividing the [page:BufferAttribute.array array]'s length by the [page:BufferAttribute.itemSize itemSize]. Read-only property.

### [property:Number gpuType]

Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType]. Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].

### [property:Boolean isBufferAttribute]

Read-only flag to check if a given object is of type [name].

### [property:Integer itemSize]

The length of vectors that are being stored in the [page:BufferAttribute.array array].

### [property:String name]

Optional name for this attribute instance. Default is an empty string.

### [property:Boolean needsUpdate]

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.
Setting this to true also increments the [page:BufferAttribute.version version].

### [property:Boolean normalized]

Indicates how the underlying data in the buffer maps to the values in the GLSL shader code. See the constructor above for details.

### [property:Function onUploadCallback]

A callback function that is executed after the Renderer has transferred the attribute array data to the GPU.

### [property:Object updateRanges]

Array of objects containing:
[page:Integer start]: Position at which to start update.
[page:Integer count]: The number of components to update.
This can be used to only update some components of stored vectors (for example, just the component related to color). Use the [page:BufferAttribute.addUpdateRange addUpdateRange] function to add ranges to this array.

### [property:Usage usage]

Defines the intended usage pattern of the data store for optimization purposes. Corresponds to the `usage` parameter of [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData WebGLRenderingContext.bufferData](). Default is [page:BufferAttributeUsage StaticDrawUsage]. See usage [page:BufferAttributeUsage constants] for all possible values.
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.

### [property:Integer version]

A version number, incremented every time the [page:BufferAttribute.needsUpdate needsUpdate] property is set to true.

## Methods

### [method:this applyMatrix3]( [param:Matrix3 m] )

Applies matrix [page:Matrix3 m] to every Vector3 element of this BufferAttribute.

### [method:this applyMatrix4]( [param:Matrix4 m] )

Applies matrix [page:Matrix4 m] to every Vector3 element of this BufferAttribute.

### [method:this applyNormalMatrix]( [param:Matrix3 m] )

Applies normal matrix [page:Matrix3 m] to every Vector3 element of this BufferAttribute.

### [method:this transformDirection]( [param:Matrix4 m] )

Applies matrix [page:Matrix4 m] to every Vector3 element of this BufferAttribute, interpreting the elements as a direction vectors.

### [method:this addUpdateRange]( [param:Integer start], [param:Integer count] )

Adds a range of data in the data array to be updated on the GPU. Adds an object describing the range to the [page:BufferAttribute.updateRanges updateRanges] array.

### [method:this clearUpdateRanges]()

Clears the [page:BufferAttribute.updateRanges updateRanges] array.

### [method:BufferAttribute clone]()

Return a copy of this bufferAttribute.

### [method:this copy]( [param:BufferAttribute bufferAttribute] )

Copies another BufferAttribute to this BufferAttribute.

### [method:this copyArray]( array )

Copy the array given here (which can be a normal array or TypedArray) into [page:BufferAttribute.array array].
See [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set TypedArray.set] for notes on requirements if copying a TypedArray.

### [method:this copyAt] ( [param:Integer index1], [param:BufferAttribute bufferAttribute], [param:Integer index2] )

Copy a vector from bufferAttribute[index2] to [page:BufferAttribute.array array][index1].

### [method:Number getComponent]( [param:Integer index], [param:Integer component] )

Returns the given component of the vector at the given index.

### [method:Number getX]( [param:Integer index] )

Returns the x component of the vector at the given index.

### [method:Number getY]( [param:Integer index] )

Returns the y component of the vector at the given index.

### [method:Number getZ]( [param:Integer index] )

Returns the z component of the vector at the given index.

### [method:Number getW]( [param:Integer index] )

Returns the w component of the vector at the given index.

### [method:this onUpload]( [param:Function callback] )

Sets the value of the onUploadCallback property.
In the [example:webgl_buffergeometry WebGL / Buffergeometry] this is used to free memory after the buffer has been transferred to the GPU.

### [method:this set] ( [param:Array value], [param:Integer offset] )

value -- an [page:Array] or [page:TypedArray] from which to copy values.
offset -- (optional) index of the [page:BufferAttribute.array array] at which to start copying.
Calls [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set TypedArray.set]( [page:Array value], [page:Integer offset] ) on the [page:BufferAttribute.array array].
In particular, see that page for requirements on [page:Array value] being a [page:TypedArray].

### [method:this setUsage] ( [param:Usage value] )

Set [page:BufferAttribute.usage usage] to value. See usage [page:BufferAttributeUsage constants] for all possible input values.
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.

### [method:Number setComponent]( [param:Integer index], [param:Integer component], [param:Float value] )

Sets the given component of the vector at the given index.

### [method:this setX]( [param:Integer index], [param:Float x] )

Sets the x component of the vector at the given index.

### [method:this setY]( [param:Integer index], [param:Float y] )

Sets the y component of the vector at the given index.

### [method:this setZ]( [param:Integer index], [param:Float z] )

Sets the z component of the vector at the given index.

### [method:this setW]( [param:Integer index], [param:Float w] )

Sets the w component of the vector at the given index.

### [method:this setXY]( [param:Integer index], [param:Float x], [param:Float y] )

Sets the x and y components of the vector at the given index.

### [method:this setXYZ]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z] )

Sets the x, y and z components of the vector at the given index.

### [method:this setXYZW]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z], [param:Float w] )

Sets the x, y, z and w components of the vector at the given index.

## Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]