Accessors store lists of numeric, vector, or matrix elements in a typed array.

All large data for Mesh, Skin, and Animation properties is stored in Accessors, organized into one or more Buffers. Each accessor provides data in typed arrays, with two abstractions:

Elements are the logical divisions of the data into useful types: "SCALAR", "VEC2", "VEC3", "VEC4", "MAT3", or "MAT4". The element type can be determined with the getType() method, and the number of elements in the accessor determine its getCount(). The number of components in an element — e.g. 9 for "MAT3" — are its getElementSize(). See Accessor.Type.

Components are the numeric values within an element — e.g. .x and .y for "VEC2". Various component types are available: BYTE, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT, UNSIGNED_INT, and FLOAT. The component type can be determined with the getComponentType method, and the number of bytes in each component determine its getComponentSize. See Accessor.ComponentType.

Usage:

const accessor = doc.createAccessor('myData')
    .setArray(new Float32Array([1,2,3,4,5,6,7,8,9,10,11,12]))
    .setType(Accessor.Type.VEC3)
    .setBuffer(doc.listBuffers()[0]);

accessor.getCount();        // → 4
accessor.getElementSize();  // → 3
accessor.getByteLength();   // → 48
accessor.getElement(1, []); // → [4, 5, 6]

accessor.setElement(0, [10, 20, 30]);

Data access through the getElement and setElement methods reads or overwrites the content of the underlying typed array. These methods use element arrays intended to be compatible with the gl-matrix library, or with the toArray/fromArray methods of libraries like three.js and babylon.js.

Each Accessor must be assigned to a Buffer, which determines where the accessor's data is stored in the final file. Assigning Accessors to different Buffers allows the data to be written to different .bin files.

glTF-Transform does not expose many details of sparse, normalized, or interleaved accessors through its API. It reads files using those techniques, presents a simplified view of the data for editing, and attempts to write data back out with optimizations. For example, vertex attributes will typically be interleaved by default, regardless of the input file.

References:

Hierarchy

  • ExtensibleProperty
    • Accessor

Properties

propertyType: ACCESSOR = ...
ComponentType: Record<string, AccessorComponentType> = ...

Data type of the values composing each element in the accessor.

Type: Record<string, AccessorType> = ...

Element type contained by the accessor (SCALAR, VEC2, ...).

Methods

  • dispose(): void
  • Removes both inbound references to and outbound references from this object. At the end of the process the object holds no references, and nothing holds references to it. A disposed object is not reusable.

  • getArray(): TypedArray
  • getByteLength(): number
  • getComponentSize(): number
  • getCount(): number
  • getElement(index: number, target: number[]): number[]
  • getElementSize(): number
  • Number of components in each element of the accessor. For example, the element size of a VEC2 accessor is 2. This value is determined automatically based on array length and accessor type, specified with setType().

  • getExtension<Prop>(name: string): Prop
  • getExtras(): Record<string, unknown>
  • Returns a reference to the Extras object, containing application-specific data for this Property. Extras should be an Object, not a primitive value, for best portability.

  • getMax(target: number[]): number[]
  • getMaxNormalized(target: number[]): number[]
  • Maximum value of each component in this attribute. Unlike in a final glTF file, values returned by this method will reflect the minimum accounting for {@link .normalized} state.

  • getMin(target: number[]): number[]
  • getMinNormalized(target: number[]): number[]
  • Minimum value of each component in this attribute. Unlike in a final glTF file, values returned by this method will reflect the minimum accounting for {@link .normalized} state.

  • getName(): string
  • Returns the name of this property. While names are not required to be unique, this is encouraged, and non-unique names will be overwritten in some tools. For custom data about a property, prefer to use Extras.

  • getNormalized(): boolean
  • Specifies whether integer data values should be normalized (true) to [0, 1] (for unsigned types) or [-1, 1] (for signed types), or converted directly (false) when they are accessed. This property is defined only for accessors that contain vertex attributes or animation output data.

  • getScalar(index: number): number
  • isDisposed(): boolean
  • listExtensions(): ExtensionProperty[]
  • listParents(): Property[]
  • Returns a list of all properties that hold a reference to this property. For example, a material may hold references to various textures, but a texture does not hold references to the materials that use it.

    It is often necessary to filter the results for a particular type: some resources, like Accessors, may be referenced by different types of properties. Most properties include the Root as a parent, which is usually not of interest.

    Usage:

    const materials = texture
        .listParents()
        .filter((p) => p instanceof Material)
    
  • setElement(index: number, value: number[]): Accessor
  • setExtension<Prop>(name: string, extensionProperty: Prop): Accessor
  • setExtras(extras: Record<string, unknown>): Accessor
  • Sets the name of this property. While names are not required to be unique, this is encouraged, and non-unique names will be overwritten in some tools. For custom data about a property, prefer to use Extras.

  • setNormalized(normalized: boolean): Accessor
  • Specifies whether integer data values should be normalized (true) to [0, 1] (for unsigned types) or [-1, 1] (for signed types), or converted directly (false) when they are accessed. This property is defined only for accessors that contain vertex attributes or animation output data.

  • setScalar(index: number, x: number): Accessor
  • Sets type of element stored in the accessor. VEC2, VEC3, etc. Array length must be a multiple of the component size (VEC2 = 2, VEC3 = 3, ...) for the selected type.

Function symbol, f(📦) → 📦, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy TypeDoc documentation Copyright 2021 under MIT license