Skip to content

Generate glTF JSON types from the glTF schemas - #14148

Open
jjhembd wants to merge 11 commits into
gltf-cleanupfrom
gltf-schema-types
Open

jjhembd wants to merge 11 commits into
gltf-cleanupfrom
gltf-schema-types

Conversation

@jjhembd

@jjhembd jjhembd commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds TypeScript types for glTF JSON, generated from the glTF JSON Schemas, and exports them from @cesium/gltf. The next PRs in this stack use them: first to fix test data that doesn't match the schemas, then to type-check @cesium/gltf.

Code changes

The changes can be reviewed one commit at a time. About 6,900 of the added lines are the generated files in packages/gltf/SchemaTypes, which can be spot-checked; the parts to review are the schema list and the two scripts.

Schema sources

packages/gltf/scripts/gltfSchemaSources.json pins the repository, branch, and commit of the glTF 1.0, 2.0, and 2.1 schemas, and of the schemas of 47 extensions: those in ModelUtility.supportedExtensions, plus any other glTF extension read in packages/engine/Source or packages/gltf/Source. Each extension also lists the glTF versions it applies to (1.0, 2.x, or 2.1) and the objects it extends.

There are 3 supported extensions for which I was not able to find a schema:

Scripts

  • npm run download-schemas -w @cesium/gltf downloads the pinned schemas into packages/gltf/Build/Schemas/, which is gitignored.
  • npm run generate-types -w @cesium/gltf writes packages/gltf/SchemaTypes/: Gltf1.ts, Gltf2.ts, a file per extension in Extensions/, and an index.ts that re-exports them.

Both are rerun by hand when a pin changes, and the regenerated files are committed with the new pin.

Generated types

  • Gltf1 and Gltf2 are the root objects, with a nested type per schema in a namespace of the same name: accessor.sparse.indices.schema.json becomes Gltf2.Accessor.Sparse.Indices.
  • Gltf2 is generated from the glTF 2.1 schemas and covers glTF 2.0. Descriptions mark the objects, properties, and enum values that are new in 2.1 with "(glTF 2.1)".
  • Each extension is a namespace named after it, prefixed with _ if the name starts with a digit: EXT_structural_metadata.Mesh.Primitive, _3DTILES_tileset.Gltf.
  • Each object's extensions property lists the extensions that extend that object, such as Gltf2.Mesh.Primitive.Extensions.EXT_structural_metadata, and accepts any other extension as unknown.
  • Required properties are required, fixed-size arrays such as translation are tuples, and descriptions and @default values come from the schemas.
  • The types are @internal, like the rest of the @cesium/gltf API, so this PR needs no CHANGES.md entry.

Configuration

  • packages/gltf/tsconfig.json includes SchemaTypes/**/*.ts, and packages/gltf/gltf.entry.d.ts re-exports them.
  • eslint.config.js lints SchemaTypes with the TypeScript rules, using @typescript-eslint/no-redeclare, which allows an interface and a namespace to share a name.

Issue number and link

Part of #13949.

Testing plan

  • npm run tsc -w @cesium/gltf and npm run eslint should pass.
  • Regenerating should reproduce the committed files: after npm run download-schemas -w @cesium/gltf and npm run generate-types -w @cesium/gltf, git status packages/gltf/SchemaTypes should show no changes.
  • After npm run build-ts, packages/gltf/index.d.ts should contain the new types, and Source/Cesium.d.ts should be unchanged.
  • Every .gltf file under Specs/Data and Apps/SampleData was type-checked against Gltf1 or Gltf2 with a temporary script. One glTF 1.0 test model had a number asset.version, fixed in this PR. The other failures are fixed in the next PR.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

AI acknowledgment

  • I used AI to generate content in this PR
  • If yes, I have reviewed the AI-generated content before submitting

If yes, I used the following Tools(s) and/or Service(s): GitHub Copilot

If yes, I used the following Model(s): Claude Opus 5.5

@jjhembd
jjhembd added this pull request to stack #14151 December 4, 2026 14:59
@jjhembd
jjhembd requested a balanced review from Copilot December 4, 2026 15:00
@jjhembd
jjhembd marked this pull request as ready for review December 4, 2026 15:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The generated types lose numeric array constraints, leave the KHR_techniques_webgl root extension untyped, and reject valid embedded glTF 1.0 resources.

3 open issues
What changed in this PR

Adds schema-generated glTF JSON types to @cesium/gltf, supporting the documentation and type-checking work in #13949.

Changes:

  • Pins schema sources and adds download and type-generation scripts.
  • Exports generated types with extension mappings and schema documentation.
  • Updates TypeScript and lint configuration, and corrects one fixture’s asset version.
File Description
Specs/​Data/​Models/​glTF-1.0/​box-textured-embedded/​box-textured-embedded.gltf Corrects asset version to a string.
packages/​gltf/​tsconfig.json Includes generated types.
packages/​gltf/​scripts/​gltfSchemaSources.json Pins schemas and extension attachments.
packages/​gltf/​scripts/​generateGltfTypes.js Generates documented TypeScript types.
packages/​gltf/​scripts/​downloadGltfSchemas.js Downloads pinned schemas.
packages/​gltf/​SchemaTypes/​index.ts Re-exports generated types.
packages/​gltf/​SchemaTypes/​Extensions/​WEB3D_quantized_attributes.ts Adds quantized attribute types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_texture_transform.ts Adds texture transform types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_texture_basisu.ts Adds Basis Universal texture types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_techniques_webgl.ts Adds shader technique types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_spz_gaussian_splats_compression.ts Adds SPZ compression types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_node_visibility.ts Adds node visibility types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_meshopt_compression.ts Adds meshopt compression types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_unlit.ts Adds unlit material types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_transmission.ts Adds material transmission types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_specular.ts Adds specular material types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_pbrSpecularGlossiness.ts Adds specular-glossiness material types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_emissive_strength.ts Adds emissive strength types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_clearcoat.ts Adds clearcoat material types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_materials_anisotropy.ts Adds anisotropic material types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_implicit_shapes.ts Adds implicit shape types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_gaussian_splatting.ts Adds Gaussian splatting types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_gaussian_splatting_compression_spz_2.ts Adds SPZ v2 compression types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_draco_mesh_compression.ts Adds Draco compression types.
packages/​gltf/​SchemaTypes/​Extensions/​KHR_binary_glTF.ts Adds binary glTF resource types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_voxels.ts Adds node voxel types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_textureInfo_constant_lod.ts Adds constant-detail texture types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_texture_webp.ts Adds WebP texture types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_structural_metadata.ts Adds structural metadata types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_primitive_voxels.ts Adds primitive voxel types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_meshopt_compression.ts Adds legacy meshopt compression types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_mesh_primitive_restart.ts Adds primitive restart types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_mesh_primitive_edge_visibility.ts Adds edge visibility types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_mesh_polygon.ts Adds polygon topology types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_mesh_gpu_instancing.ts Adds mesh instancing types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_mesh_features.ts Adds mesh feature types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_instance_features.ts Adds instance feature types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_implicit_ellipsoid_region.ts Adds ellipsoid region types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_implicit_cylinder_region.ts Adds cylinder region types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_geospatial_crs.ts Adds coordinate reference system types.
packages/​gltf/​SchemaTypes/​Extensions/​EXT_feature_metadata.ts Adds legacy feature metadata types.
packages/​gltf/​SchemaTypes/​Extensions/​CESIUM_tile_edges.ts Adds tile edge types.
packages/​gltf/​SchemaTypes/​Extensions/​CESIUM_RTC.ts Adds relative-center types.
packages/​gltf/​SchemaTypes/​Extensions/​CESIUM_primitive_outline.ts Adds primitive outline types.
packages/​gltf/​SchemaTypes/​Extensions/​BENTLEY_materials_point_style.ts Adds point styling types.
packages/​gltf/​SchemaTypes/​Extensions/​BENTLEY_materials_planar_fill.ts Adds planar fill types.
packages/​gltf/​SchemaTypes/​Extensions/​BENTLEY_materials_line_style.ts Adds line styling types.
packages/​gltf/​SchemaTypes/​Extensions/​AGI_articulations.ts Adds articulation types.
packages/​gltf/​SchemaTypes/​Extensions/​3DTILES_tileset.ts Adds tileset types.
packages/​gltf/​SchemaTypes/​Extensions/​3DTILES_tileset_voxels.ts Adds voxel tileset types.
packages/​gltf/​SchemaTypes/​Extensions/​3DTILES_subtree.ts Adds subtree availability types.
packages/​gltf/​SchemaTypes/​Extensions/​3DTILES_implicit_tiling.ts Adds implicit tiling types.
packages/​gltf/​package.json Adds schema maintenance commands.
packages/​gltf/​gltf.entry.d.ts Exports schema types from the package.
eslint.config.js Enables TypeScript lint rules for generated types.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The schema list omits three supported/read extensions, leaving their payloads typed as unknown; schema coverage must be added or the exclusions documented.

1 open issue
3 resolved since last review

Review effort: Balanced

@jjhembd
jjhembd requested a review from lukemckinstry December 4, 2026 18:46
@javagl

javagl commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Each object's extensions property lists the extensions that extend that object, such as Gltf2.Mesh.Primitive.Extensions.EXT_structural_metadata, and accepts any other extension as unknown.

While I understand the intention (namely, convenience and typedness), I wonder if this may raise a few questions ... (ironically) about extensibility: How would this affect users when an extension that was previously unknown suddenly is "promoted" to be a fully typed object?

(In doubt, I'll have to check this based on this state and some hypothetical example. I only quickly scrolled over the files, maybe I misunderstood some detail here...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants