rhodonite
    Preparing search index...

    Class Accessor

    Accessor class provides a high-level interface for reading and writing data from/to a BufferView. It handles different data types (scalar, vector, matrix) and provides type-safe access to buffer data. This class is commonly used in 3D graphics applications for managing vertex attributes, indices, and other buffer data.

    Index

    Constructors

    • Creates a new Accessor instance.

      Parameters

      • params: {
            arrayLength: number;
            bufferView: BufferView;
            byteOffsetInBufferView: number;
            byteStride: number;
            componentType: ComponentTypeEnum;
            compositionType: CompositionTypeEnum;
            count: number;
            max?: number[];
            min?: number[];
            normalized: boolean;
            raw: ArrayBuffer;
        }

        Configuration object for the accessor

        • arrayLength: number

          Length of array for each element

        • bufferView: BufferView

          The BufferView that contains the data

        • byteOffsetInBufferView: number

          Byte offset within the buffer view

        • byteStride: number

          Byte stride between elements (0 for tightly packed)

        • componentType: ComponentTypeEnum

          Component data type (byte, short, int, float, etc.)

        • compositionType: CompositionTypeEnum

          Type of data composition (scalar, vec2, vec3, vec4, mat3, mat4)

        • count: number

          Number of elements

        • Optionalmax?: number[]

          Optional maximum values for each component

        • Optionalmin?: number[]

          Optional minimum values for each component

        • normalized: boolean

          Whether integer values should be normalized to [0,1] or [-1,1]

        • raw: ArrayBuffer

          Raw ArrayBuffer containing the data

      Returns Accessor

    Properties

    _primitive?: WeakRef<Primitive>

    Accessors

    • get arrayBufferOfBufferView(): ArrayBuffer

      Gets the underlying ArrayBuffer of the buffer view.

      Returns ArrayBuffer

      The ArrayBuffer containing the data

    • get byteOffsetInBufferView(): number

      Gets the byte offset within the buffer view.

      Returns number

      The byte offset in the buffer view

    • get byteOffsetInRawArrayBufferOfBuffer(): number

      Gets the byte offset in the raw ArrayBuffer of the buffer.

      Returns number

      The byte offset in the raw ArrayBuffer

    • get byteStride(): number

      Gets the byte stride between elements. For tightly packed data, this equals elementSizeInBytes. For interleaved data, this may be larger.

      Returns number

      The byte stride

    • get dataViewOfBufferView(): DataView

      Gets the DataView of the buffer view.

      Returns DataView

      The DataView for accessing the buffer data

    • get elementCount(): number

      Gets the total number of elements in this accessor. Each element may be a scalar, vec2, vec3, vec4, matrix, etc.

      Returns number

      The element count

    • get elementSizeInBytes(): number

      Gets the size in bytes of each element (numberOfComponents * componentSizeInBytes).

      Returns number

      The element size in bytes

    • get isAoS(): boolean

      Checks if this accessor uses Array of Structures (AoS) layout. AoS means data is interleaved (e.g., XYZXYZXYZ for positions).

      Returns boolean

      True if using AoS layout

    • get isMinMaxDirty(): boolean

      Gets whether the min/max values are dirty and need recalculation.

      Returns boolean

      True if min/max values are dirty

    • get isSoA(): boolean

      Checks if this accessor uses Structure of Arrays (SoA) layout. SoA means data is tightly packed (e.g., XXXYYYZZZ for positions).

      Returns boolean

      True if using SoA layout

    • get max(): number[]

      Gets the maximum values for each component. Calculates min/max if dirty.

      Returns number[]

      Array of maximum values

    • get min(): number[]

      Gets the minimum values for each component. Calculates min/max if dirty.

      Returns number[]

      Array of minimum values

    • get numberOfComponents(): number

      Gets the number of components per element (e.g., 3 for Vec3, 4 for Vec4).

      Returns number

      The number of components

    • get takenCount(): number

      Gets the number of elements that have been taken from this accessor.

      Returns number

      The count of taken elements

    • get version(): number

      Gets the version number of this accessor. Increments when data is modified.

      Returns number

      The version number

    Methods

    • Adds an element from another accessor with the same composition type, scaled by a coefficient.

      Parameters

      • i: number

        The target element index

      • accessor: Accessor

        The source accessor to add from

      • coeff: number

        The coefficient to multiply the source values by

      • OptionalsecondIdx: number

        Optional source index (defaults to i)

      Returns void

    • Copies data from a TypedArray into this accessor. The data is copied element by element with proper type conversion.

      Parameters

      • typedArray: TypedArray

        The TypedArray to copy data from

      Returns void

    • Gets the DataView getter method name for the given component type.

      Parameters

      Returns string | undefined

      The DataView getter method name, or undefined if unknown

    • Gets the DataView setter method name for the given component type.

      Parameters

      Returns string | undefined

      The DataView setter method name, or undefined if unknown

    • Gets a 3x3 matrix as an array at the specified index.

      Parameters

      • i: number

        The element index

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns number[]

      A 9-element array containing the matrix components in row-major order

    • Gets a 3x3 matrix at the specified index and stores it in the provided output object. This method avoids creating new objects and is more memory-efficient.

      Parameters

      • i: number

        The element index

      • out: MutableMatrix33

        The output MutableMatrix33 object to store the result

      • options: { endian?: boolean; indicesAccessor?: Accessor }

        Access options including indices accessor and endianness

      Returns Matrix33

      The output Matrix33 object (same as the out parameter)

    • Gets a 4x4 matrix as an array at the specified index.

      Parameters

      • i: number

        The element index

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns number[]

      A 16-element array containing the matrix components in row-major order

    • Gets a scalar value at the specified index with a composition offset.

      Parameters

      • i: number

        The element index

      • compositionOffset: number

        Byte offset within the element

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns number

      The scalar value

    • Gets the underlying TypedArray for this accessor. Note: If the buffer view uses interleaved data (AoS), direct access may not work as expected.

      Returns TypedArray

      The TypedArray containing the data

    • Gets a Uint8Array view of this accessor's data. Useful for raw byte-level access to the buffer data.

      Returns Uint8Array

      A Uint8Array view of the accessor's data

    • Checks if this accessor is the same as another accessor. Compares byte length, offset, and underlying buffer.

      Parameters

      • rnAccessor: Accessor

        The accessor to compare with

      Returns boolean

      True if the accessors are the same

    • Sets an element from another accessor, handling different composition types. Automatically converts between different vector/scalar types as needed.

      Parameters

      • i: number

        The target element index

      • accessor: Accessor

        The source accessor to copy from

      • OptionalsecondIdx: number

        Optional source index (defaults to i)

      Returns void

    • Sets an element from another accessor with the same composition type.

      Parameters

      • i: number

        The target element index

      • accessor: Accessor

        The source accessor to copy from

      • OptionalsecondIdx: number

        Optional source index (defaults to i)

      Returns void

    • Sets a 3x3 matrix at the specified index.

      Parameters

      • i: number

        The element index

      • v0: number

        Matrix component at position [0,0]

      • v1: number

        Matrix component at position [0,1]

      • v2: number

        Matrix component at position [0,2]

      • v3: number

        Matrix component at position [1,0]

      • v4: number

        Matrix component at position [1,1]

      • v5: number

        Matrix component at position [1,2]

      • v6: number

        Matrix component at position [2,0]

      • v7: number

        Matrix component at position [2,1]

      • v8: number

        Matrix component at position [2,2]

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns void

    • Sets a 4x4 matrix at the specified index.

      Parameters

      • i: number

        The element index

      • v0: number

        Matrix component at position [0,0]

      • v1: number

        Matrix component at position [0,1]

      • v2: number

        Matrix component at position [0,2]

      • v3: number

        Matrix component at position [0,3]

      • v4: number

        Matrix component at position [1,0]

      • v5: number

        Matrix component at position [1,1]

      • v6: number

        Matrix component at position [1,2]

      • v7: number

        Matrix component at position [1,3]

      • v8: number

        Matrix component at position [2,0]

      • v9: number

        Matrix component at position [2,1]

      • v10: number

        Matrix component at position [2,2]

      • v11: number

        Matrix component at position [2,3]

      • v12: number

        Matrix component at position [3,0]

      • v13: number

        Matrix component at position [3,1]

      • v14: number

        Matrix component at position [3,2]

      • v15: number

        Matrix component at position [3,3]

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns void

    • Sets the minimum and maximum values for this accessor.

      Parameters

      • min: number[]

        Array of minimum values for each component

      • max: number[]

        Array of maximum values for each component

      Returns void

    • Sets a scalar value at the specified index with a composition offset.

      Parameters

      • i: number

        The element index

      • compositionOffset: number

        Byte offset within the element

      • value: number

        The scalar value to set

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns void

    • Sets the data from a TypedArray into this accessor. If the provided array uses the same buffer, no copying is needed. Otherwise, data is copied element by element with proper type conversion.

      Parameters

      • typedArray: TypedArray

        The TypedArray to copy data from

      Returns void

    • Sets a 2D vector at the specified index.

      Parameters

      • i: number

        The element index

      • x: number

        The X component value

      • y: number

        The Y component value

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns void

    • Sets a 3D vector at the specified index.

      Parameters

      • i: number

        The element index

      • x: number

        The X component value

      • y: number

        The Y component value

      • z: number

        The Z component value

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns void

    • Sets a 4D vector at the specified index.

      Parameters

      • i: number

        The element index

      • x: number

        The X component value

      • y: number

        The Y component value

      • z: number

        The Z component value

      • w: number

        The W component value

      • options: IndicesAccessOption

        Access options including indices accessor and endianness

      Returns void

    • Takes one element from the accessor and returns a TypedArray view of it. This method allocates a new view for the next available element.

      Returns TypedArray

      A TypedArray view of the taken element

      Error if trying to allocate more elements than available