📄 BufferAttribute.js
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 39 |
🧱 Classes | 10 |
📦 Imports | 8 |
📊 Variables & Constants | 9 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 src/core/BufferAttribute.js
📦 Imports¶
Name | Source |
---|---|
Vector3 |
../math/Vector3.js |
Vector2 |
../math/Vector2.js |
denormalize |
../math/MathUtils.js |
normalize |
../math/MathUtils.js |
StaticDrawUsage |
../constants.js |
FloatType |
../constants.js |
fromHalfFloat |
../extras/DataUtils.js |
toHalfFloat |
../extras/DataUtils.js |
Variables & Constants¶
Name | Type | Kind | Value | Exported |
---|---|---|---|---|
_vector |
Vector3 |
let/var | new Vector3() |
✗ |
_vector2 |
Vector2 |
let/var | new Vector2() |
✗ |
_id |
number |
let/var | 0 |
✗ |
value |
TypedArray |
let/var | this.array[ index * this.itemSize + component ] |
✗ |
x |
TypedArray |
let/var | this.array[ index * this.itemSize ] |
✗ |
y |
TypedArray |
let/var | this.array[ index * this.itemSize + 1 ] |
✗ |
z |
TypedArray |
let/var | this.array[ index * this.itemSize + 2 ] |
✗ |
w |
TypedArray |
let/var | this.array[ index * this.itemSize + 3 ] |
✗ |
data |
{ itemSize: number; type: any; array:... |
let/var | { itemSize: this.itemSize, type: this.array.constructor.name, array: Array.fr... |
✗ |
Functions¶
BufferAttribute.onUploadCallback(): void
¶
JSDoc:
/**
* A callback function that is executed after the renderer has transferred the attribute
* array data to the GPU.
*/
Returns: void
BufferAttribute.setUsage(value: any): BufferAttribute
¶
JSDoc:
/**
* Sets the usage of this buffer attribute.
*
* @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
* @return {BufferAttribute} A reference to this buffer attribute.
*/
Parameters:
value
any
Returns: BufferAttribute
BufferAttribute.addUpdateRange(start: number, count: number): void
¶
JSDoc:
/**
* Adds a range of data in the data array to be updated on the GPU.
*
* @param {number} start - Position at which to start update.
* @param {number} count - The number of components to update.
*/
Parameters:
start
number
count
number
Returns: void
Calls:
this.updateRanges.push
BufferAttribute.clearUpdateRanges(): void
¶
JSDoc:
Returns: void
BufferAttribute.copy(source: BufferAttribute): BufferAttribute
¶
JSDoc:
/**
* Copies the values of the given buffer attribute to this instance.
*
* @param {BufferAttribute} source - The buffer attribute to copy.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
source
BufferAttribute
Returns: BufferAttribute
Code
BufferAttribute.copyAt(index1: number, attribute: BufferAttribute, index2: number): BufferAttribute
¶
JSDoc:
/**
* 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.
*
* @param {number} index1 - The destination index into this buffer attribute.
* @param {BufferAttribute} attribute - The buffer attribute to copy from.
* @param {number} index2 - The source index into the given buffer attribute.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index1
number
attribute
BufferAttribute
index2
number
Returns: BufferAttribute
Code
BufferAttribute.copyArray(array: any): BufferAttribute
¶
JSDoc:
/**
* Copies the given array data into this buffer attribute.
*
* @param {(TypedArray|Array)} array - The array to copy.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
array
any
Returns: BufferAttribute
Calls:
this.array.set
BufferAttribute.applyMatrix3(m: Matrix3): BufferAttribute
¶
JSDoc:
/**
* Applies the given 3x3 matrix to the given attribute. Works with
* item size `2` and `3`.
*
* @param {Matrix3} m - The matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
m
Matrix3
Returns: BufferAttribute
Calls:
_vector2.fromBufferAttribute
_vector2.applyMatrix3
this.setXY
_vector.fromBufferAttribute
_vector.applyMatrix3
this.setXYZ
Code
applyMatrix3( m ) {
if ( this.itemSize === 2 ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector2.fromBufferAttribute( this, i );
_vector2.applyMatrix3( m );
this.setXY( i, _vector2.x, _vector2.y );
}
} else if ( this.itemSize === 3 ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector.fromBufferAttribute( this, i );
_vector.applyMatrix3( m );
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
}
}
return this;
}
BufferAttribute.applyMatrix4(m: Matrix4): BufferAttribute
¶
JSDoc:
/**
* Applies the given 4x4 matrix to the given attribute. Only works with
* item size `3`.
*
* @param {Matrix4} m - The matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
m
Matrix4
Returns: BufferAttribute
Calls:
_vector.fromBufferAttribute
_vector.applyMatrix4
this.setXYZ
Code
BufferAttribute.applyNormalMatrix(m: Matrix3): BufferAttribute
¶
JSDoc:
/**
* Applies the given 3x3 normal matrix to the given attribute. Only works with
* item size `3`.
*
* @param {Matrix3} m - The normal matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
m
Matrix3
Returns: BufferAttribute
Calls:
_vector.fromBufferAttribute
_vector.applyNormalMatrix
this.setXYZ
Code
BufferAttribute.transformDirection(m: Matrix4): BufferAttribute
¶
JSDoc:
/**
* Applies the given 4x4 matrix to the given attribute. Only works with
* item size `3` and with direction vectors.
*
* @param {Matrix4} m - The matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
m
Matrix4
Returns: BufferAttribute
Calls:
_vector.fromBufferAttribute
_vector.transformDirection
this.setXYZ
Code
BufferAttribute.set(value: any, offset: number): BufferAttribute
¶
JSDoc:
/**
* Sets the given array data in the buffer attribute.
*
* @param {(TypedArray|Array)} value - The array data to set.
* @param {number} [offset=0] - The offset in this buffer attribute's array.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
value
any
offset
number
Returns: BufferAttribute
Calls:
this.array.set
Internal Comments:
Code
BufferAttribute.getComponent(index: number, component: number): number
¶
JSDoc:
/**
* Returns the given component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} component - The component index.
* @return {number} The returned value.
*/
Parameters:
index
number
component
number
Returns: number
Calls:
denormalize (from ../math/MathUtils.js)
Code
BufferAttribute.setComponent(index: number, component: number, value: number): BufferAttribute
¶
JSDoc:
/**
* Sets the given value to the given component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} component - The component index.
* @param {number} value - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
component
number
value
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.getX(index: number): number
¶
JSDoc:
/**
* Returns the x component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The x component.
*/
Parameters:
index
number
Returns: number
Calls:
denormalize (from ../math/MathUtils.js)
Code
BufferAttribute.setX(index: number, x: number): BufferAttribute
¶
JSDoc:
/**
* Sets the x component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
x
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.getY(index: number): number
¶
JSDoc:
/**
* Returns the y component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The y component.
*/
Parameters:
index
number
Returns: number
Calls:
denormalize (from ../math/MathUtils.js)
Code
BufferAttribute.setY(index: number, y: number): BufferAttribute
¶
JSDoc:
/**
* Sets the y component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} y - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
y
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.getZ(index: number): number
¶
JSDoc:
/**
* Returns the z component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The z component.
*/
Parameters:
index
number
Returns: number
Calls:
denormalize (from ../math/MathUtils.js)
Code
BufferAttribute.setZ(index: number, z: number): BufferAttribute
¶
JSDoc:
/**
* Sets the z component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} z - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
z
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.getW(index: number): number
¶
JSDoc:
/**
* Returns the w component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The w component.
*/
Parameters:
index
number
Returns: number
Calls:
denormalize (from ../math/MathUtils.js)
Code
BufferAttribute.setW(index: number, w: number): BufferAttribute
¶
JSDoc:
/**
* Sets the w component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} w - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
w
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.setXY(index: number, x: number, y: number): BufferAttribute
¶
JSDoc:
/**
* Sets the x and y component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value for the x component to set.
* @param {number} y - The value for the y component to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
x
number
y
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.setXYZ(index: number, x: number, y: number, z: number): BufferAttribute
¶
JSDoc:
/**
* Sets the x, y and z component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value for the x component to set.
* @param {number} y - The value for the y component to set.
* @param {number} z - The value for the z component to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
x
number
y
number
z
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
BufferAttribute.setXYZW(index: number, x: number, y: number, z: number, w: number): BufferAttribute
¶
JSDoc:
/**
* Sets the x, y, z and w component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value for the x component to set.
* @param {number} y - The value for the y component to set.
* @param {number} z - The value for the z component to set.
* @param {number} w - The value for the w component to set.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
index
number
x
number
y
number
z
number
w
number
Returns: BufferAttribute
Calls:
normalize (from ../math/MathUtils.js)
Code
setXYZW( index, x, y, z, w ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
w = normalize( w, this.array );
}
this.array[ index + 0 ] = x;
this.array[ index + 1 ] = y;
this.array[ index + 2 ] = z;
this.array[ index + 3 ] = w;
return this;
}
BufferAttribute.onUpload(callback: Function): BufferAttribute
¶
JSDoc:
/**
* 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.
*
* @param {Function} callback - The `onUpload()` callback.
* @return {BufferAttribute} A reference to this instance.
*/
Parameters:
callback
Function
Returns: BufferAttribute
BufferAttribute.clone(): BufferAttribute
¶
JSDoc:
/**
* Returns a new buffer attribute with copied values from this instance.
*
* @return {BufferAttribute} A clone of this instance.
*/
Returns: BufferAttribute
Calls:
new this.constructor( this.array, this.itemSize ).copy
BufferAttribute.toJSON(): any
¶
JSDoc:
/**
* Serializes the buffer attribute into JSON.
*
* @return {Object} A JSON object representing the serialized buffer attribute.
*/
Returns: any
Calls:
Array.from
Code
Float16BufferAttribute.getX(index: any): number
¶
Parameters:
index
any
Returns: number
Calls:
fromHalfFloat (from ../extras/DataUtils.js)
denormalize (from ../math/MathUtils.js)
Code
Float16BufferAttribute.setX(index: any, x: any): this
¶
Parameters:
index
any
x
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
Float16BufferAttribute.getY(index: any): number
¶
Parameters:
index
any
Returns: number
Calls:
fromHalfFloat (from ../extras/DataUtils.js)
denormalize (from ../math/MathUtils.js)
Code
Float16BufferAttribute.setY(index: any, y: any): this
¶
Parameters:
index
any
y
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
Float16BufferAttribute.getZ(index: any): number
¶
Parameters:
index
any
Returns: number
Calls:
fromHalfFloat (from ../extras/DataUtils.js)
denormalize (from ../math/MathUtils.js)
Code
Float16BufferAttribute.setZ(index: any, z: any): this
¶
Parameters:
index
any
z
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
Float16BufferAttribute.getW(index: any): number
¶
Parameters:
index
any
Returns: number
Calls:
fromHalfFloat (from ../extras/DataUtils.js)
denormalize (from ../math/MathUtils.js)
Code
Float16BufferAttribute.setW(index: any, w: any): this
¶
Parameters:
index
any
w
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
Float16BufferAttribute.setXY(index: any, x: any, y: any): this
¶
Parameters:
index
any
x
any
y
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
Float16BufferAttribute.setXYZ(index: any, x: any, y: any, z: any): this
¶
Parameters:
index
any
x
any
y
any
z
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
setXYZ( index, x, y, z ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
this.array[ index + 2 ] = toHalfFloat( z );
return this;
}
Float16BufferAttribute.setXYZW(index: any, x: any, y: any, z: any, w: any): this
¶
Parameters:
index
any
x
any
y
any
z
any
w
any
Returns: this
Calls:
normalize (from ../math/MathUtils.js)
toHalfFloat (from ../extras/DataUtils.js)
Code
setXYZW( index, x, y, z, w ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
w = normalize( w, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
this.array[ index + 2 ] = toHalfFloat( z );
this.array[ index + 3 ] = toHalfFloat( w );
return this;
}
Classes¶
BufferAttribute
¶
Class Code
class BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {TypedArray} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized = false ) {
if ( Array.isArray( array ) ) {
throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
}
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isBufferAttribute = true;
/**
* The ID of the buffer attribute.
*
* @name BufferAttribute#id
* @type {number}
* @readonly
*/
Object.defineProperty( this, 'id', { value: _id ++ } );
/**
* The name of the buffer attribute.
*
* @type {string}
*/
this.name = '';
/**
* The array holding the attribute data. It should have `itemSize * numVertices`
* elements, where `numVertices` is the number of vertices in the associated geometry.
*
* @type {TypedArray}
*/
this.array = array;
/**
* 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`.
*
* @type {number}
*/
this.itemSize = itemSize;
/**
* Represents the number of items this buffer attribute stores. It is internally computed
* by dividing the `array` length by the `itemSize`.
*
* @type {number}
* @readonly
*/
this.count = array !== undefined ? array.length / itemSize : 0;
/**
* 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`.
*
* @type {boolean}
*/
this.normalized = normalized;
/**
* 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.
*
* @type {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)}
* @default StaticDrawUsage
*/
this.usage = StaticDrawUsage;
/**
* 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.
*
* @type {Array<Object>}
*/
this.updateRanges = [];
/**
* 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`.
*
* @type {(FloatType|IntType)}
* @default FloatType
*/
this.gpuType = FloatType;
/**
* A version number, incremented every time the `needsUpdate` is set to `true`.
*
* @type {number}
*/
this.version = 0;
}
/**
* A callback function that is executed after the renderer has transferred the attribute
* array data to the GPU.
*/
onUploadCallback() {}
/**
* 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.
*
* @type {number}
* @default false
* @param {boolean} value
*/
set needsUpdate( value ) {
if ( value === true ) this.version ++;
}
/**
* Sets the usage of this buffer attribute.
*
* @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
* @return {BufferAttribute} A reference to this buffer attribute.
*/
setUsage( value ) {
this.usage = value;
return this;
}
/**
* Adds a range of data in the data array to be updated on the GPU.
*
* @param {number} start - Position at which to start update.
* @param {number} count - The number of components to update.
*/
addUpdateRange( start, count ) {
this.updateRanges.push( { start, count } );
}
/**
* Clears the update ranges.
*/
clearUpdateRanges() {
this.updateRanges.length = 0;
}
/**
* Copies the values of the given buffer attribute to this instance.
*
* @param {BufferAttribute} source - The buffer attribute to copy.
* @return {BufferAttribute} A reference to this instance.
*/
copy( source ) {
this.name = source.name;
this.array = new source.array.constructor( source.array );
this.itemSize = source.itemSize;
this.count = source.count;
this.normalized = source.normalized;
this.usage = source.usage;
this.gpuType = source.gpuType;
return this;
}
/**
* 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.
*
* @param {number} index1 - The destination index into this buffer attribute.
* @param {BufferAttribute} attribute - The buffer attribute to copy from.
* @param {number} index2 - The source index into the given buffer attribute.
* @return {BufferAttribute} A reference to this instance.
*/
copyAt( index1, attribute, index2 ) {
index1 *= this.itemSize;
index2 *= attribute.itemSize;
for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
this.array[ index1 + i ] = attribute.array[ index2 + i ];
}
return this;
}
/**
* Copies the given array data into this buffer attribute.
*
* @param {(TypedArray|Array)} array - The array to copy.
* @return {BufferAttribute} A reference to this instance.
*/
copyArray( array ) {
this.array.set( array );
return this;
}
/**
* Applies the given 3x3 matrix to the given attribute. Works with
* item size `2` and `3`.
*
* @param {Matrix3} m - The matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
applyMatrix3( m ) {
if ( this.itemSize === 2 ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector2.fromBufferAttribute( this, i );
_vector2.applyMatrix3( m );
this.setXY( i, _vector2.x, _vector2.y );
}
} else if ( this.itemSize === 3 ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector.fromBufferAttribute( this, i );
_vector.applyMatrix3( m );
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
}
}
return this;
}
/**
* Applies the given 4x4 matrix to the given attribute. Only works with
* item size `3`.
*
* @param {Matrix4} m - The matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
applyMatrix4( m ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector.fromBufferAttribute( this, i );
_vector.applyMatrix4( m );
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
}
return this;
}
/**
* Applies the given 3x3 normal matrix to the given attribute. Only works with
* item size `3`.
*
* @param {Matrix3} m - The normal matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
applyNormalMatrix( m ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector.fromBufferAttribute( this, i );
_vector.applyNormalMatrix( m );
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
}
return this;
}
/**
* Applies the given 4x4 matrix to the given attribute. Only works with
* item size `3` and with direction vectors.
*
* @param {Matrix4} m - The matrix to apply.
* @return {BufferAttribute} A reference to this instance.
*/
transformDirection( m ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector.fromBufferAttribute( this, i );
_vector.transformDirection( m );
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
}
return this;
}
/**
* Sets the given array data in the buffer attribute.
*
* @param {(TypedArray|Array)} value - The array data to set.
* @param {number} [offset=0] - The offset in this buffer attribute's array.
* @return {BufferAttribute} A reference to this instance.
*/
set( value, offset = 0 ) {
// Matching BufferAttribute constructor, do not normalize the array.
this.array.set( value, offset );
return this;
}
/**
* Returns the given component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} component - The component index.
* @return {number} The returned value.
*/
getComponent( index, component ) {
let value = this.array[ index * this.itemSize + component ];
if ( this.normalized ) value = denormalize( value, this.array );
return value;
}
/**
* Sets the given value to the given component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} component - The component index.
* @param {number} value - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
setComponent( index, component, value ) {
if ( this.normalized ) value = normalize( value, this.array );
this.array[ index * this.itemSize + component ] = value;
return this;
}
/**
* Returns the x component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The x component.
*/
getX( index ) {
let x = this.array[ index * this.itemSize ];
if ( this.normalized ) x = denormalize( x, this.array );
return x;
}
/**
* Sets the x component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
setX( index, x ) {
if ( this.normalized ) x = normalize( x, this.array );
this.array[ index * this.itemSize ] = x;
return this;
}
/**
* Returns the y component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The y component.
*/
getY( index ) {
let y = this.array[ index * this.itemSize + 1 ];
if ( this.normalized ) y = denormalize( y, this.array );
return y;
}
/**
* Sets the y component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} y - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
setY( index, y ) {
if ( this.normalized ) y = normalize( y, this.array );
this.array[ index * this.itemSize + 1 ] = y;
return this;
}
/**
* Returns the z component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The z component.
*/
getZ( index ) {
let z = this.array[ index * this.itemSize + 2 ];
if ( this.normalized ) z = denormalize( z, this.array );
return z;
}
/**
* Sets the z component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} z - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
setZ( index, z ) {
if ( this.normalized ) z = normalize( z, this.array );
this.array[ index * this.itemSize + 2 ] = z;
return this;
}
/**
* Returns the w component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @return {number} The w component.
*/
getW( index ) {
let w = this.array[ index * this.itemSize + 3 ];
if ( this.normalized ) w = denormalize( w, this.array );
return w;
}
/**
* Sets the w component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} w - The value to set.
* @return {BufferAttribute} A reference to this instance.
*/
setW( index, w ) {
if ( this.normalized ) w = normalize( w, this.array );
this.array[ index * this.itemSize + 3 ] = w;
return this;
}
/**
* Sets the x and y component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value for the x component to set.
* @param {number} y - The value for the y component to set.
* @return {BufferAttribute} A reference to this instance.
*/
setXY( index, x, y ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
}
this.array[ index + 0 ] = x;
this.array[ index + 1 ] = y;
return this;
}
/**
* Sets the x, y and z component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value for the x component to set.
* @param {number} y - The value for the y component to set.
* @param {number} z - The value for the z component to set.
* @return {BufferAttribute} A reference to this instance.
*/
setXYZ( index, x, y, z ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
}
this.array[ index + 0 ] = x;
this.array[ index + 1 ] = y;
this.array[ index + 2 ] = z;
return this;
}
/**
* Sets the x, y, z and w component of the vector at the given index.
*
* @param {number} index - The index into the buffer attribute.
* @param {number} x - The value for the x component to set.
* @param {number} y - The value for the y component to set.
* @param {number} z - The value for the z component to set.
* @param {number} w - The value for the w component to set.
* @return {BufferAttribute} A reference to this instance.
*/
setXYZW( index, x, y, z, w ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
w = normalize( w, this.array );
}
this.array[ index + 0 ] = x;
this.array[ index + 1 ] = y;
this.array[ index + 2 ] = z;
this.array[ index + 3 ] = w;
return this;
}
/**
* 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.
*
* @param {Function} callback - The `onUpload()` callback.
* @return {BufferAttribute} A reference to this instance.
*/
onUpload( callback ) {
this.onUploadCallback = callback;
return this;
}
/**
* Returns a new buffer attribute with copied values from this instance.
*
* @return {BufferAttribute} A clone of this instance.
*/
clone() {
return new this.constructor( this.array, this.itemSize ).copy( this );
}
/**
* Serializes the buffer attribute into JSON.
*
* @return {Object} A JSON object representing the serialized buffer attribute.
*/
toJSON() {
const data = {
itemSize: this.itemSize,
type: this.array.constructor.name,
array: Array.from( this.array ),
normalized: this.normalized
};
if ( this.name !== '' ) data.name = this.name;
if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
return data;
}
}
Methods¶
onUploadCallback(): void
¶
setUsage(value: any): BufferAttribute
¶
addUpdateRange(start: number, count: number): void
¶
clearUpdateRanges(): void
¶
copy(source: BufferAttribute): BufferAttribute
¶
Code
copyAt(index1: number, attribute: BufferAttribute, index2: number): BufferAttribute
¶
Code
copyArray(array: any): BufferAttribute
¶
applyMatrix3(m: Matrix3): BufferAttribute
¶
Code
applyMatrix3( m ) {
if ( this.itemSize === 2 ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector2.fromBufferAttribute( this, i );
_vector2.applyMatrix3( m );
this.setXY( i, _vector2.x, _vector2.y );
}
} else if ( this.itemSize === 3 ) {
for ( let i = 0, l = this.count; i < l; i ++ ) {
_vector.fromBufferAttribute( this, i );
_vector.applyMatrix3( m );
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
}
}
return this;
}
applyMatrix4(m: Matrix4): BufferAttribute
¶
Code
applyNormalMatrix(m: Matrix3): BufferAttribute
¶
Code
transformDirection(m: Matrix4): BufferAttribute
¶
Code
set(value: any, offset: number): BufferAttribute
¶
Code
getComponent(index: number, component: number): number
¶
Code
setComponent(index: number, component: number, value: number): BufferAttribute
¶
Code
getX(index: number): number
¶
Code
setX(index: number, x: number): BufferAttribute
¶
Code
getY(index: number): number
¶
Code
setY(index: number, y: number): BufferAttribute
¶
Code
getZ(index: number): number
¶
Code
setZ(index: number, z: number): BufferAttribute
¶
Code
getW(index: number): number
¶
Code
setW(index: number, w: number): BufferAttribute
¶
Code
setXY(index: number, x: number, y: number): BufferAttribute
¶
Code
setXYZ(index: number, x: number, y: number, z: number): BufferAttribute
¶
Code
setXYZW(index: number, x: number, y: number, z: number, w: number): BufferAttribute
¶
Code
setXYZW( index, x, y, z, w ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
w = normalize( w, this.array );
}
this.array[ index + 0 ] = x;
this.array[ index + 1 ] = y;
this.array[ index + 2 ] = z;
this.array[ index + 3 ] = w;
return this;
}
onUpload(callback: Function): BufferAttribute
¶
clone(): BufferAttribute
¶
toJSON(): any
¶
Code
Int8BufferAttribute
¶
Class Code
class Int8BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Int8Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Int8Array( array ), itemSize, normalized );
}
}
Uint8BufferAttribute
¶
Class Code
class Uint8BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Uint8Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Uint8Array( array ), itemSize, normalized );
}
}
Uint8ClampedBufferAttribute
¶
Class Code
class Uint8ClampedBufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Uint8ClampedArray)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Uint8ClampedArray( array ), itemSize, normalized );
}
}
Int16BufferAttribute
¶
Class Code
class Int16BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Int16Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Int16Array( array ), itemSize, normalized );
}
}
Uint16BufferAttribute
¶
Class Code
class Uint16BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Uint16Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Uint16Array( array ), itemSize, normalized );
}
}
Int32BufferAttribute
¶
Class Code
class Int32BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Int32Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Int32Array( array ), itemSize, normalized );
}
}
Uint32BufferAttribute
¶
Class Code
class Uint32BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Uint32Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Uint32Array( array ), itemSize, normalized );
}
}
Float16BufferAttribute
¶
Class Code
class Float16BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Uint16Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Uint16Array( array ), itemSize, normalized );
this.isFloat16BufferAttribute = true;
}
getX( index ) {
let x = fromHalfFloat( this.array[ index * this.itemSize ] );
if ( this.normalized ) x = denormalize( x, this.array );
return x;
}
setX( index, x ) {
if ( this.normalized ) x = normalize( x, this.array );
this.array[ index * this.itemSize ] = toHalfFloat( x );
return this;
}
getY( index ) {
let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );
if ( this.normalized ) y = denormalize( y, this.array );
return y;
}
setY( index, y ) {
if ( this.normalized ) y = normalize( y, this.array );
this.array[ index * this.itemSize + 1 ] = toHalfFloat( y );
return this;
}
getZ( index ) {
let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );
if ( this.normalized ) z = denormalize( z, this.array );
return z;
}
setZ( index, z ) {
if ( this.normalized ) z = normalize( z, this.array );
this.array[ index * this.itemSize + 2 ] = toHalfFloat( z );
return this;
}
getW( index ) {
let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );
if ( this.normalized ) w = denormalize( w, this.array );
return w;
}
setW( index, w ) {
if ( this.normalized ) w = normalize( w, this.array );
this.array[ index * this.itemSize + 3 ] = toHalfFloat( w );
return this;
}
setXY( index, x, y ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
return this;
}
setXYZ( index, x, y, z ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
this.array[ index + 2 ] = toHalfFloat( z );
return this;
}
setXYZW( index, x, y, z, w ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
w = normalize( w, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
this.array[ index + 2 ] = toHalfFloat( z );
this.array[ index + 3 ] = toHalfFloat( w );
return this;
}
}
Methods¶
getX(index: any): number
¶
Code
setX(index: any, x: any): this
¶
Code
getY(index: any): number
¶
Code
setY(index: any, y: any): this
¶
Code
getZ(index: any): number
¶
Code
setZ(index: any, z: any): this
¶
Code
getW(index: any): number
¶
Code
setW(index: any, w: any): this
¶
Code
setXY(index: any, x: any, y: any): this
¶
Code
setXYZ(index: any, x: any, y: any, z: any): this
¶
Code
setXYZ( index, x, y, z ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
this.array[ index + 2 ] = toHalfFloat( z );
return this;
}
setXYZW(index: any, x: any, y: any, z: any, w: any): this
¶
Code
setXYZW( index, x, y, z, w ) {
index *= this.itemSize;
if ( this.normalized ) {
x = normalize( x, this.array );
y = normalize( y, this.array );
z = normalize( z, this.array );
w = normalize( w, this.array );
}
this.array[ index + 0 ] = toHalfFloat( x );
this.array[ index + 1 ] = toHalfFloat( y );
this.array[ index + 2 ] = toHalfFloat( z );
this.array[ index + 3 ] = toHalfFloat( w );
return this;
}
Float32BufferAttribute
¶
Class Code
class Float32BufferAttribute extends BufferAttribute {
/**
* Constructs a new buffer attribute.
*
* @param {(Array<number>|Float32Array)} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
*/
constructor( array, itemSize, normalized ) {
super( new Float32Array( array ), itemSize, normalized );
}
}