Skip to content

⬅️ Back to Table of Contents

📄 InterleavedBufferAttribute.js

📊 Analysis Summary

Metric Count
🔧 Functions 18
🧱 Classes 1
📦 Imports 4
📊 Variables & Constants 10

📚 Table of Contents

🛠️ File Location:

📂 src/core/InterleavedBufferAttribute.js

📦 Imports

Name Source
Vector3 ../math/Vector3.js
BufferAttribute ./BufferAttribute.js
denormalize ../math/MathUtils.js
normalize ../math/MathUtils.js

Variables & Constants

Name Type Kind Value Exported
_vector Vector3 let/var new Vector3()
value TypedArray let/var this.array[ index * this.data.stride + this.offset + component ]
x any let/var this.data.array[ index * this.data.stride + this.offset ]
y any let/var this.data.array[ index * this.data.stride + this.offset + 1 ]
z any let/var this.data.array[ index * this.data.stride + this.offset + 2 ]
w any let/var this.data.array[ index * this.data.stride + this.offset + 3 ]
array any[] let/var []
index number let/var i * this.data.stride + this.offset
array any[] let/var []
index number let/var i * this.data.stride + this.offset

Functions

InterleavedBufferAttribute.applyMatrix4(m: Matrix4): InterleavedBufferAttribute

JSDoc:

/**
     * Applies the given 4x4 matrix to the given attribute. Only works with
     * item size `3`.
     *
     * @param {Matrix4} m - The matrix to apply.
     * @return {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • m Matrix4

Returns: InterleavedBufferAttribute

Calls:

  • _vector.fromBufferAttribute
  • _vector.applyMatrix4
  • this.setXYZ
Code
applyMatrix4( m ) {

        for ( let i = 0, l = this.data.count; i < l; i ++ ) {

            _vector.fromBufferAttribute( this, i );

            _vector.applyMatrix4( m );

            this.setXYZ( i, _vector.x, _vector.y, _vector.z );

        }

        return this;

    }

InterleavedBufferAttribute.applyNormalMatrix(m: Matrix3): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • m Matrix3

Returns: InterleavedBufferAttribute

Calls:

  • _vector.fromBufferAttribute
  • _vector.applyNormalMatrix
  • this.setXYZ
Code
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;

    }

InterleavedBufferAttribute.transformDirection(m: Matrix4): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • m Matrix4

Returns: InterleavedBufferAttribute

Calls:

  • _vector.fromBufferAttribute
  • _vector.transformDirection
  • this.setXYZ
Code
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;

    }

InterleavedBufferAttribute.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
getComponent( index, component ) {

        let value = this.array[ index * this.data.stride + this.offset + component ];

        if ( this.normalized ) value = denormalize( value, this.array );

        return value;

    }

InterleavedBufferAttribute.setComponent(index: number, component: number, value: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • component number
  • value number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setComponent( index, component, value ) {

        if ( this.normalized ) value = normalize( value, this.array );

        this.data.array[ index * this.data.stride + this.offset + component ] = value;

        return this;

    }

InterleavedBufferAttribute.setX(index: number, x: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • x number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setX( index, x ) {

        if ( this.normalized ) x = normalize( x, this.array );

        this.data.array[ index * this.data.stride + this.offset ] = x;

        return this;

    }

InterleavedBufferAttribute.setY(index: number, y: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • y number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setY( index, y ) {

        if ( this.normalized ) y = normalize( y, this.array );

        this.data.array[ index * this.data.stride + this.offset + 1 ] = y;

        return this;

    }

InterleavedBufferAttribute.setZ(index: number, z: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • z number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setZ( index, z ) {

        if ( this.normalized ) z = normalize( z, this.array );

        this.data.array[ index * this.data.stride + this.offset + 2 ] = z;

        return this;

    }

InterleavedBufferAttribute.setW(index: number, w: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • w number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setW( index, w ) {

        if ( this.normalized ) w = normalize( w, this.array );

        this.data.array[ index * this.data.stride + this.offset + 3 ] = w;

        return this;

    }

InterleavedBufferAttribute.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
getX( index ) {

        let x = this.data.array[ index * this.data.stride + this.offset ];

        if ( this.normalized ) x = denormalize( x, this.array );

        return x;

    }

InterleavedBufferAttribute.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
getY( index ) {

        let y = this.data.array[ index * this.data.stride + this.offset + 1 ];

        if ( this.normalized ) y = denormalize( y, this.array );

        return y;

    }

InterleavedBufferAttribute.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
getZ( index ) {

        let z = this.data.array[ index * this.data.stride + this.offset + 2 ];

        if ( this.normalized ) z = denormalize( z, this.array );

        return z;

    }

InterleavedBufferAttribute.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
getW( index ) {

        let w = this.data.array[ index * this.data.stride + this.offset + 3 ];

        if ( this.normalized ) w = denormalize( w, this.array );

        return w;

    }

InterleavedBufferAttribute.setXY(index: number, x: number, y: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • x number
  • y number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setXY( index, x, y ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;

        return this;

    }

InterleavedBufferAttribute.setXYZ(index: number, x: number, y: number, z: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • x number
  • y number
  • z number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setXYZ( index, x, y, z ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );
            z = normalize( z, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;
        this.data.array[ index + 2 ] = z;

        return this;

    }

InterleavedBufferAttribute.setXYZW(index: number, x: number, y: number, z: number, w: number): InterleavedBufferAttribute

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 {InterleavedBufferAttribute} A reference to this instance.
     */

Parameters:

  • index number
  • x number
  • y number
  • z number
  • w number

Returns: InterleavedBufferAttribute

Calls:

  • normalize (from ../math/MathUtils.js)
Code
setXYZW( index, x, y, z, w ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );
            z = normalize( z, this.array );
            w = normalize( w, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;
        this.data.array[ index + 2 ] = z;
        this.data.array[ index + 3 ] = w;

        return this;

    }

InterleavedBufferAttribute.clone(data: any): BufferAttribute | InterleavedBufferAttribute

JSDoc:

/**
     * Returns a new buffer attribute with copied values from this instance.
     *
     * If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
     *
     * @param {Object} [data] - An object with interleaved buffers that allows to retain the interleaved property.
     * @return {BufferAttribute|InterleavedBufferAttribute} A clone of this instance.
     */

Parameters:

  • data any

Returns: BufferAttribute | InterleavedBufferAttribute

Calls:

  • console.log
  • array.push
  • this.data.clone
Code
clone( data ) {

        if ( data === undefined ) {

            console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );

            const array = [];

            for ( let i = 0; i < this.count; i ++ ) {

                const index = i * this.data.stride + this.offset;

                for ( let j = 0; j < this.itemSize; j ++ ) {

                    array.push( this.data.array[ index + j ] );

                }

            }

            return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );

        } else {

            if ( data.interleavedBuffers === undefined ) {

                data.interleavedBuffers = {};

            }

            if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {

                data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );

            }

            return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );

        }

    }

InterleavedBufferAttribute.toJSON(data: any): any

JSDoc:

/**
     * Serializes the buffer attribute into JSON.
     *
     * If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
     *
     * @param {Object} [data] - An optional value holding meta information about the serialization.
     * @return {Object} A JSON object representing the serialized buffer attribute.
     */

Parameters:

  • data any

Returns: any

Calls:

  • console.log
  • array.push
  • this.data.toJSON

Internal Comments:

// de-interleave data and save it as an ordinary buffer attribute for now
// save as true interleaved attribute

Code
toJSON( data ) {

        if ( data === undefined ) {

            console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );

            const array = [];

            for ( let i = 0; i < this.count; i ++ ) {

                const index = i * this.data.stride + this.offset;

                for ( let j = 0; j < this.itemSize; j ++ ) {

                    array.push( this.data.array[ index + j ] );

                }

            }

            // de-interleave data and save it as an ordinary buffer attribute for now

            return {
                itemSize: this.itemSize,
                type: this.array.constructor.name,
                array: array,
                normalized: this.normalized
            };

        } else {

            // save as true interleaved attribute

            if ( data.interleavedBuffers === undefined ) {

                data.interleavedBuffers = {};

            }

            if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {

                data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );

            }

            return {
                isInterleavedBufferAttribute: true,
                itemSize: this.itemSize,
                data: this.data.uuid,
                offset: this.offset,
                normalized: this.normalized
            };

        }

    }

Classes

InterleavedBufferAttribute

Class Code
class InterleavedBufferAttribute {

    /**
     * Constructs a new interleaved buffer attribute.
     *
     * @param {InterleavedBuffer} interleavedBuffer - The buffer holding the interleaved data.
     * @param {number} itemSize - The item size.
     * @param {number} offset - The attribute offset into the buffer.
     * @param {boolean} [normalized=false] - Whether the data are normalized or not.
     */
    constructor( interleavedBuffer, itemSize, offset, normalized = false ) {

        /**
         * This flag can be used for type testing.
         *
         * @type {boolean}
         * @readonly
         * @default true
         */
        this.isInterleavedBufferAttribute = true;

        /**
         * The name of the buffer attribute.
         *
         * @type {string}
         */
        this.name = '';

        /**
         * The buffer holding the interleaved data.
         *
         * @type {InterleavedBuffer}
         */
        this.data = interleavedBuffer;

        /**
         * The item size, see {@link BufferAttribute#itemSize}.
         *
         * @type {number}
         */
        this.itemSize = itemSize;

        /**
         * The attribute offset into the buffer.
         *
         * @type {number}
         */
        this.offset = offset;

        /**
         * Whether the data are normalized or not, see {@link BufferAttribute#normalized}
         *
         * @type {InterleavedBuffer}
         */
        this.normalized = normalized;

    }

    /**
     * The item count of this buffer attribute.
     *
     * @type {number}
     * @readonly
     */
    get count() {

        return this.data.count;

    }

    /**
     * The array holding the interleaved buffer attribute data.
     *
     * @type {TypedArray}
     */
    get array() {

        return this.data.array;

    }

    /**
     * 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 ) {

        this.data.needsUpdate = value;

    }

    /**
     * Applies the given 4x4 matrix to the given attribute. Only works with
     * item size `3`.
     *
     * @param {Matrix4} m - The matrix to apply.
     * @return {InterleavedBufferAttribute} A reference to this instance.
     */
    applyMatrix4( m ) {

        for ( let i = 0, l = this.data.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 {InterleavedBufferAttribute} 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 {InterleavedBufferAttribute} 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;

    }

    /**
     * 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.data.stride + this.offset + 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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setComponent( index, component, value ) {

        if ( this.normalized ) value = normalize( value, this.array );

        this.data.array[ index * this.data.stride + this.offset + component ] = value;

        return this;

    }

    /**
     * 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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setX( index, x ) {

        if ( this.normalized ) x = normalize( x, this.array );

        this.data.array[ index * this.data.stride + this.offset ] = x;

        return this;

    }

    /**
     * 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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setY( index, y ) {

        if ( this.normalized ) y = normalize( y, this.array );

        this.data.array[ index * this.data.stride + this.offset + 1 ] = y;

        return this;

    }

    /**
     * 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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setZ( index, z ) {

        if ( this.normalized ) z = normalize( z, this.array );

        this.data.array[ index * this.data.stride + this.offset + 2 ] = z;

        return this;

    }

    /**
     * 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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setW( index, w ) {

        if ( this.normalized ) w = normalize( w, this.array );

        this.data.array[ index * this.data.stride + this.offset + 3 ] = w;

        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.data.array[ index * this.data.stride + this.offset ];

        if ( this.normalized ) x = denormalize( x, this.array );

        return x;

    }

    /**
     * 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.data.array[ index * this.data.stride + this.offset + 1 ];

        if ( this.normalized ) y = denormalize( y, this.array );

        return y;

    }

    /**
     * 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.data.array[ index * this.data.stride + this.offset + 2 ];

        if ( this.normalized ) z = denormalize( z, this.array );

        return z;

    }

    /**
     * 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.data.array[ index * this.data.stride + this.offset + 3 ];

        if ( this.normalized ) w = denormalize( w, this.array );

        return w;

    }

    /**
     * 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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setXY( index, x, y ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setXYZ( index, x, y, z ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );
            z = normalize( z, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;
        this.data.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 {InterleavedBufferAttribute} A reference to this instance.
     */
    setXYZW( index, x, y, z, w ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );
            z = normalize( z, this.array );
            w = normalize( w, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;
        this.data.array[ index + 2 ] = z;
        this.data.array[ index + 3 ] = w;

        return this;

    }

    /**
     * Returns a new buffer attribute with copied values from this instance.
     *
     * If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
     *
     * @param {Object} [data] - An object with interleaved buffers that allows to retain the interleaved property.
     * @return {BufferAttribute|InterleavedBufferAttribute} A clone of this instance.
     */
    clone( data ) {

        if ( data === undefined ) {

            console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );

            const array = [];

            for ( let i = 0; i < this.count; i ++ ) {

                const index = i * this.data.stride + this.offset;

                for ( let j = 0; j < this.itemSize; j ++ ) {

                    array.push( this.data.array[ index + j ] );

                }

            }

            return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );

        } else {

            if ( data.interleavedBuffers === undefined ) {

                data.interleavedBuffers = {};

            }

            if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {

                data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );

            }

            return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );

        }

    }

    /**
     * Serializes the buffer attribute into JSON.
     *
     * If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
     *
     * @param {Object} [data] - An optional value holding meta information about the serialization.
     * @return {Object} A JSON object representing the serialized buffer attribute.
     */
    toJSON( data ) {

        if ( data === undefined ) {

            console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );

            const array = [];

            for ( let i = 0; i < this.count; i ++ ) {

                const index = i * this.data.stride + this.offset;

                for ( let j = 0; j < this.itemSize; j ++ ) {

                    array.push( this.data.array[ index + j ] );

                }

            }

            // de-interleave data and save it as an ordinary buffer attribute for now

            return {
                itemSize: this.itemSize,
                type: this.array.constructor.name,
                array: array,
                normalized: this.normalized
            };

        } else {

            // save as true interleaved attribute

            if ( data.interleavedBuffers === undefined ) {

                data.interleavedBuffers = {};

            }

            if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {

                data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );

            }

            return {
                isInterleavedBufferAttribute: true,
                itemSize: this.itemSize,
                data: this.data.uuid,
                offset: this.offset,
                normalized: this.normalized
            };

        }

    }

}

Methods

applyMatrix4(m: Matrix4): InterleavedBufferAttribute
Code
applyMatrix4( m ) {

        for ( let i = 0, l = this.data.count; i < l; i ++ ) {

            _vector.fromBufferAttribute( this, i );

            _vector.applyMatrix4( m );

            this.setXYZ( i, _vector.x, _vector.y, _vector.z );

        }

        return this;

    }
applyNormalMatrix(m: Matrix3): InterleavedBufferAttribute
Code
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;

    }
transformDirection(m: Matrix4): InterleavedBufferAttribute
Code
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;

    }
getComponent(index: number, component: number): number
Code
getComponent( index, component ) {

        let value = this.array[ index * this.data.stride + this.offset + component ];

        if ( this.normalized ) value = denormalize( value, this.array );

        return value;

    }
setComponent(index: number, component: number, value: number): InterleavedBufferAttribute
Code
setComponent( index, component, value ) {

        if ( this.normalized ) value = normalize( value, this.array );

        this.data.array[ index * this.data.stride + this.offset + component ] = value;

        return this;

    }
setX(index: number, x: number): InterleavedBufferAttribute
Code
setX( index, x ) {

        if ( this.normalized ) x = normalize( x, this.array );

        this.data.array[ index * this.data.stride + this.offset ] = x;

        return this;

    }
setY(index: number, y: number): InterleavedBufferAttribute
Code
setY( index, y ) {

        if ( this.normalized ) y = normalize( y, this.array );

        this.data.array[ index * this.data.stride + this.offset + 1 ] = y;

        return this;

    }
setZ(index: number, z: number): InterleavedBufferAttribute
Code
setZ( index, z ) {

        if ( this.normalized ) z = normalize( z, this.array );

        this.data.array[ index * this.data.stride + this.offset + 2 ] = z;

        return this;

    }
setW(index: number, w: number): InterleavedBufferAttribute
Code
setW( index, w ) {

        if ( this.normalized ) w = normalize( w, this.array );

        this.data.array[ index * this.data.stride + this.offset + 3 ] = w;

        return this;

    }
getX(index: number): number
Code
getX( index ) {

        let x = this.data.array[ index * this.data.stride + this.offset ];

        if ( this.normalized ) x = denormalize( x, this.array );

        return x;

    }
getY(index: number): number
Code
getY( index ) {

        let y = this.data.array[ index * this.data.stride + this.offset + 1 ];

        if ( this.normalized ) y = denormalize( y, this.array );

        return y;

    }
getZ(index: number): number
Code
getZ( index ) {

        let z = this.data.array[ index * this.data.stride + this.offset + 2 ];

        if ( this.normalized ) z = denormalize( z, this.array );

        return z;

    }
getW(index: number): number
Code
getW( index ) {

        let w = this.data.array[ index * this.data.stride + this.offset + 3 ];

        if ( this.normalized ) w = denormalize( w, this.array );

        return w;

    }
setXY(index: number, x: number, y: number): InterleavedBufferAttribute
Code
setXY( index, x, y ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;

        return this;

    }
setXYZ(index: number, x: number, y: number, z: number): InterleavedBufferAttribute
Code
setXYZ( index, x, y, z ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );
            z = normalize( z, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;
        this.data.array[ index + 2 ] = z;

        return this;

    }
setXYZW(index: number, x: number, y: number, z: number, w: number): InterleavedBufferAttribute
Code
setXYZW( index, x, y, z, w ) {

        index = index * this.data.stride + this.offset;

        if ( this.normalized ) {

            x = normalize( x, this.array );
            y = normalize( y, this.array );
            z = normalize( z, this.array );
            w = normalize( w, this.array );

        }

        this.data.array[ index + 0 ] = x;
        this.data.array[ index + 1 ] = y;
        this.data.array[ index + 2 ] = z;
        this.data.array[ index + 3 ] = w;

        return this;

    }
clone(data: any): BufferAttribute | InterleavedBufferAttribute
Code
clone( data ) {

        if ( data === undefined ) {

            console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );

            const array = [];

            for ( let i = 0; i < this.count; i ++ ) {

                const index = i * this.data.stride + this.offset;

                for ( let j = 0; j < this.itemSize; j ++ ) {

                    array.push( this.data.array[ index + j ] );

                }

            }

            return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );

        } else {

            if ( data.interleavedBuffers === undefined ) {

                data.interleavedBuffers = {};

            }

            if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {

                data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );

            }

            return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );

        }

    }
toJSON(data: any): any
Code
toJSON( data ) {

        if ( data === undefined ) {

            console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );

            const array = [];

            for ( let i = 0; i < this.count; i ++ ) {

                const index = i * this.data.stride + this.offset;

                for ( let j = 0; j < this.itemSize; j ++ ) {

                    array.push( this.data.array[ index + j ] );

                }

            }

            // de-interleave data and save it as an ordinary buffer attribute for now

            return {
                itemSize: this.itemSize,
                type: this.array.constructor.name,
                array: array,
                normalized: this.normalized
            };

        } else {

            // save as true interleaved attribute

            if ( data.interleavedBuffers === undefined ) {

                data.interleavedBuffers = {};

            }

            if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {

                data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );

            }

            return {
                isInterleavedBufferAttribute: true,
                itemSize: this.itemSize,
                data: this.data.uuid,
                offset: this.offset,
                normalized: this.normalized
            };

        }

    }