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

type Components
"SCALAR" 1
"VEC2" 2
"VEC3" 3
"VEC4" 4
"MAT2" 4
"MAT3" 9
"MAT4" 16

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. Component types are identified by WebGL enum values, below.

componentType Bytes
5120 (BYTE) 1
5121 (UNSIGNED_BYTE) 1
5122 (SHORT) 2
5123 (UNSIGNED_SHORT) 2
5125 (UNSIGNED_INT) 4
5126 (FLOAT) 4

Usage:

const accessor = doc.createAccessor('myData')
    .setArray(new Float32Array([1,2,3,4,5,6,7,8,9,10,11,12]))
    .setType('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

Properties

propertyType: string

Property type.

Methods

  • clone(): this
  • copy(other: this, resolve: PropertyResolver<Property>): this
  • Copies all data from another property to this one. Child properties are copied by reference, unless a 'resolve' function is given to override that.

  • detach(): this
  • Removes all inbound references to this object. At the end of the process the object is considered 'detached': it may hold references to child resources, but nothing holds references to it. A detached object may be re-attached.

  • 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
  • Size of each component (a value in the raw array), in bytes. For example, the componentSize of data backed by a float32 array is 4 bytes.

  • getComponentType(): AccessorComponentType
  • Component type (float32, uint16, etc.). This value is determined automatically, and can only be modified by replacing the underlying array.

  • getCount(): number
  • Number of elements in the accessor. An array of length 30, containing 10 VEC3 elements, will have a count of 10.

  • getElement(index: number, target: number[]): number[]
  • Returns the vector or matrix element value at the given index, accounting for normalization if applicable.

  • 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(): object
  • 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
  • Returns the scalar element value at the given index, accounting for normalization if applicable.

  • getType(): AccessorType
  • isDisposed(): boolean
  • 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)
  • setArray(array: TypedArray): this
  • setBuffer(buffer: Buffer): this
  • setElement(index: number, value: number[]): this
  • Assigns the vector or matrix element value at the given index, accounting for normalization if applicable.

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

  • setName(name: string): this
  • 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): this
  • 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): this
  • Assigns the scalar element value at the given index, accounting for normalization if applicable.

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

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

Object literals

ComponentType: object

Supported component types.

Type: object

Supported element types.

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

Made by Don McCurdy TypeDoc documentation Copyright 2020 under MIT license