Skip to content
Shapemetry

Types - glTF

API reference for ./io/gltfScene on @huukhanhnguyen/types — the option and result records of @huukhanhnguyen/io's glTF reader/writer.

See the Guide for the package's role.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

BuiltGltf

type

type BuiltGltf
// = {
    document: Record<string, unknown>;
    /** Geometry/accessor (and GLB-mode image) bytes referenced by bufferViews. */
    buffer: Uint8Array;
    /** External-mode texture files (uri matches images[].uri). Empty for GLB. */
    externalImages: Array<{
        uri: string;
        data: Uint8Array;
    }>;
}

ClipAccumulator

type

One clip's channels/samplers while the writer accumulates them.

type ClipAccumulator
// = {
    channels: Record<string, unknown>[];
    samplers: Record<string, unknown>[];
}

GltfAccessor

type

type GltfAccessor
// = {
    bufferView: number;
    byteOffset?: number;
    componentType: number;
    count: number;
    type: GltfAccessorType;
    min?: number[];
    max?: number[];
    normalized?: boolean;
}

GltfAccessorDoc

type

type GltfAccessorDoc
// = {
    bufferView?: number;
    byteOffset?: number;
    componentType: number;
    count: number;
    type: string;
}

GltfAccessorType

type

type GltfAccessorType
// = "SCALAR" | "VEC2" | "VEC3" | "VEC4" | "MAT4"

GltfAnimationDoc

type

type GltfAnimationDoc
// = {
    name?: string;
    channels: GltfChannelDoc[];
    samplers: GltfSamplerDoc[];
}

GltfBufferView

type

type GltfBufferView
// = {
    buffer: 0;
    byteOffset: number;
    byteLength: number;
    target?: number;
}

GltfBufferViewDoc

type

type GltfBufferViewDoc
// = {
    buffer: number;
    byteOffset?: number;
    byteLength: number;
    byteStride?: number;
}

GltfCamera

type

An exported camera. Carries the same projection choice Camera does — an ANGLE or a BOX, exactly one — spelled in this door's own field names because glTF names them yfov (radians) and ymag.

yfovDegrees XOR height is NOT expressible in the reader's JSON, so the writer checks it: both, or neither, is a named error rather than a defaulted 45° (which is what it silently was until 2026-08-15).

type GltfCamera
// = {
    name: string;
    position: Point;
    target: Point;
    /** VERTICAL field of view in DEGREES — converted to glTF's radian `yfov`
     *  on write. Exclusive with `height`. */
    yfovDegrees?: number;
    /** Orthographic world height visible, in the model's unit — glTF's `ymag`
     *  is half of it. Exclusive with `yfovDegrees`, and needs `aspectRatio`,
     *  since glTF's `xmag` is mandatory and a height alone cannot supply it. */
    height?: number;
    /** Width / height of the frame the consumer will render into.
     *  Orthographic only: glTF leaves perspective `aspectRatio` optional
     *  exactly so the viewport can decide. */
    aspectRatio?: number;
    znear?: number;
    zfar?: number;
}

GltfChannelDoc

type

type GltfChannelDoc
// = {
    sampler: number;
    target: {
        node?: number;
        path: string;
    };
}

GltfDocument

type

type GltfDocument
// = {
    nodes?: GltfNodeDoc[];
    skins?: GltfSkinDoc[];
    animations?: GltfAnimationDoc[];
    accessors?: GltfAccessorDoc[];
    bufferViews?: GltfBufferViewDoc[];
    /** Inline, not a named type: the only name for a glTF `buffers[]` entry
     *  is the format's own word, which law 6 reads as naming storage rather
     *  than a subject. Nothing outside this document annotates one. */
    buffers?: Array<{
        uri?: string;
        byteLength: number;
    }>;
    meshes?: GltfMeshDoc[];
}

GltfMaterialVariant

type

type GltfMaterialVariant
// = {
    name: string;
    /** Map current material name → replacement material name (must exist in materials). */
    materials: Record<string, string>;
}

GltfMeshDoc

type

type GltfMeshDoc
// = {
    primitives: Array<{
        targets?: Array<Record<string, number>>;
    }>;
    extras?: {
        targetNames?: string[];
    };
}

GltfNodeDoc

type

The glTF JSON document as READ (@huukhanhnguyen/io's glbAnimation.ts), as opposed to the records above, which describe what the writer BUILDS. The two views of a format differ in what each side may assume: a writer knows it emits one buffer and a known accessor type, a reader is parsing a file it did not write and must treat both as open. Hence GltfAccessorDoc/GltfBufferViewDoc/GltfBufferDoc beside GltfAccessor/GltfBufferView rather than folded into them — a known duplication, measured 2026-08-14, not yet resolved.

type GltfNodeDoc
// = {
    name?: string;
    children?: number[];
    translation?: number[];
    rotation?: number[];
    scale?: number[];
    matrix?: number[];
    skin?: number;
    mesh?: number;
}

GltfOptions

type

type GltfOptions
// = {
    /** Document material records — a mesh group's material NAME resolves
     *  against this list; an unresolved name renders with glTF's default material. */
    materials?: MaterialData[];
    /** Emitting entities reduced to point/spot records (model's
     *  `collectLights`) — KHR_lights_punctual has no area type, so a disk or
     *  rectangle emitter exports at its centre with a named warning. */
    lights?: LightEntity[];
    /** The document's resolved sun/sky. Only the sun crosses into glTF (as a
     *  KHR_lights_punctual `directional`); a sky fill or HDRI has no punctual
     *  equivalent and is reported in `warnings`. */
    environment?: ResolvedEnvironment;
    /** Camera bookmarks — typically the `cameras[]` lane, one per entry. */
    cameras?: GltfCamera[];
    /** Resolved skeletons — not scanned from entities. Each joint carries its
     *  own OPTIONAL `positionTrack`/`rotationTrack`/`scaleTrack` reference
     *  (into `tracks` below) — the export walk resolves those, not a flat
     *  target+property list. */
    skeletons?: Skeleton[];
    /** The full evaluated track pool — every `Track` any consumer
     *  (`SkeletonJoint.*Track`, `GltfMeshInput.weightsTrack`) may reference
     *  by key, keyed by `Track.key`. A track absent from every `animations[]`
     *  clip below still resolves for its consumer, but emits no glTF
     *  `animations[]` entry (nothing to name it) — e.g. a parameter-driver
     *  track never meant for export. */
    tracks?: Track[];
    /** Named clips — each just the member track KEYS (into `tracks` above)
     *  that make up that glTF `animations[]` entry. */
    animations?: AnimationClip[];
    /**
     * Optional KHR_materials_variants — export-only (NOT a document field).
     * Host builds the list: material-option params and/or a manual tick list.
     * Each variant maps material names currently on the mesh to replacements.
     */
    variants?: GltfMaterialVariant[];
    /**
     * Warnings collected during export (e.g. an area emitter has no KHR
     * punctual type). Caller may surface them; never silent drops.
     */
    warnings?: string[];
    /** Block definitions a `BlockEntity` places. glTF INSTANCES them: one mesh
     *  in the buffer, one node per placement carrying the placement matrix. */
    definitions?: Map<string, import("../evaluate/block.js").BlockDefinition> | ReadonlyMap<string, import("../evaluate/block.js").BlockDefinition>;
}

GltfPackMode

type

type GltfPackMode
// = "glb" | "external"

GltfPrimitive

type

type GltfPrimitive
// = {
    attributes: Record<string, number>;
    indices: number;
    mode: number;
    material?: number;
    targets?: Array<Record<string, number>>;
    extensions?: Record<string, unknown>;
    /** Internal — stripped before JSON write. */
    _sourceMaterial?: string;
}

GltfSamplerDoc

type

type GltfSamplerDoc
// = {
    input: number;
    output: number;
    interpolation?: string;
}

GltfSkinDoc

type

type GltfSkinDoc
// = {
    name?: string;
    joints: number[];
    inverseBindMatrices?: number;
}

JointTag

type

type JointTag
// = {
    skeleton: string;
    joint: string;
    index: number;
    parent?: string;
    position: Point;
    rotation?: Quaternion;
    scale?: Vector;
    positionTrack?: string;
    rotationTrack?: string;
    scaleTrack?: string;
}
Last updated: 📖 1 min readEdit on GitHub