types-gltf
v1.0.0
Published
TypeScript declarations for the glTF 2.0 specification and every Complete registry extension, generated from the Khronos JSON Schema.
Maintainers
Readme
types-gltf
TypeScript declarations for the glTF 2.0 specification and every registry extension marked Complete, generated from the Khronos JSON Schema. No runtime, no dependencies.
Installation
npm install types-gltfUsage
Import the specification as a namespace: the spec's own type names (Node,
Image, Buffer, Texture) shadow DOM globals otherwise.
import type * as GLTF from "types-gltf";
function pickBaseColor(material: GLTF.Material) {
return material.pbrMetallicRoughness?.baseColorFactor ?? [1, 1, 1, 1];
}Extensions live under types-gltf/extensions, one module each, and are
namespaced for the same reason — every module names its types after the object
the extension attaches to, so Material and Node recur across them:
import type { KHR_materials_ior } from "types-gltf/extensions";
const ior = (
material.extensions?.KHR_materials_ior as KHR_materials_ior.Material
)?.ior;extensions on the core types stays an open index signature rather than a union
over the registry. Typing it would pull every extension module into every
consumer's build, and would still be wrong for the extensions that ship no
schema.
License
MIT. See license file.
