Accessor

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

Static properties

ComponentType: Record<string, GLTF.AccessorComponentType>

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

Type: Record<string, GLTF.AccessorType>

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

Static methods

  • getComponentSize(componentType: GLTF.AccessorComponentType): number
  • getElementSize(type: GLTF.AccessorType): number

Properties

propertyType: PropertyType.ACCESSOR

Methods

  • getArray(): TypedArray | null
  • getByteLength(): number
  • getComponentType(): GLTF.AccessorComponentType
  • getComponentSize(): number
  • getCount(): number
  • dispatchEvent(event: BaseEvent): this
  • Dispatches an event on the GraphNode, and on the associated Graph. Event types on the graph are prefixed, "node:[type]".

  • 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.

  • 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().

  • getElement(index: number, target: number[]): number[]
  • setElement(index: number, value: number[]): Accessor
  • equals(other: Property, skip?: Set<string>): boolean
  • Returns true if two properties are deeply equivalent, recursively comparing the attributes of the properties. Optionally, a 'skip' set may be included, specifying attributes whose values should not be considered in the comparison.

    Example: Two Primitives are equivalent if they have accessors and materials with equivalent content β€” but not necessarily the same specific accessors and materials.

  • addEventListener(type: string, listener: EventListener<T>): this
  • removeEventListener(type: string, listener: EventListener<T>): this
  • getExtension(name: string): Prop | null
  • listExtensions(): ExtensionProperty[]
  • 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.

  • setExtras(extras: Record<string, unknown>): Property
  • Updates the Extras object, containing application-specific data for this Property. Extras should be an Object, not a primitive value, for best portability.

  • isDisposed(): boolean
  • Returns true if the node has been permanently removed from the graph.

  • 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.

  • getMax(target: number[]): number[]
  • Maximum value of each component in this attribute. Values returned by this method do not reflect normalization: use {@link .getMinNormalized} in that case.

  • 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.

  • getMin(target: number[]): number[]
  • Minimum value of each component in this attribute. Values returned by this method do not reflect normalization: use {@link .getMinNormalized} in that case.

  • 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.

  • 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.

  • 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.

  • 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.

  • 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)
    
  • getScalar(index: number): number
  • setScalar(index: number, x: number): Accessor
  • getSparse(): boolean
  • Specifies whether the accessor should be stored sparsely. When written to a glTF file, sparse accessors store only values that differ from base values. When loaded in glTF Transform (or most runtimes) a sparse accessor can be treated like any other accessor. Currently, glTF Transform always uses zeroes for the base values when writing files.

  • Specifies whether the accessor should be stored sparsely. When written to a glTF file, sparse accessors store only values that differ from base values. When loaded in glTF Transform (or most runtimes) a sparse accessor can be treated like any other accessor. Currently, glTF Transform always uses zeroes for the base values when writing files.

  • getType(): GLTF.AccessorType
  • setType(type: GLTF.AccessorType): 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, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.