Repository navigation
Conversation
There was a problem hiding this comment.
🟡 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
02dc90e to
18b1325
Compare
8f47d0a to
7f368c1
Compare
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 (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...) |

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.jsonpins the repository, branch, and commit of the glTF 1.0, 2.0, and 2.1 schemas, and of the schemas of 47 extensions: those inModelUtility.supportedExtensions, plus any other glTF extension read inpackages/engine/Sourceorpackages/gltf/Source. Each extension also lists the glTF versions it applies to (1.0,2.x, or2.1) and the objects it extends.There are 3 supported extensions for which I was not able to find a schema:
CESIUM_mesh_vector: deprecated, no schema availableNGA_gpm_local: the website https://nsgreg.nga.mil/csmwg.jsp is down. We could potentially add this from local files in a follow-up PR if desired, but it would break the repeatability of the scripts.KHR_materials_common: no schema available. Type the glTF 0.8 and 1.0 upgrades in updateVersion #14150 will add a hand-authored.tsfile to cover it.Scripts
npm run download-schemas -w @cesium/gltfdownloads the pinned schemas intopackages/gltf/Build/Schemas/, which is gitignored.npm run generate-types -w @cesium/gltfwritespackages/gltf/SchemaTypes/:Gltf1.ts,Gltf2.ts, a file per extension inExtensions/, and anindex.tsthat re-exports them.Both are rerun by hand when a pin changes, and the regenerated files are committed with the new pin.
Generated types
Gltf1andGltf2are the root objects, with a nested type per schema in a namespace of the same name:accessor.sparse.indices.schema.jsonbecomesGltf2.Accessor.Sparse.Indices.Gltf2is 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)"._if the name starts with a digit:EXT_structural_metadata.Mesh.Primitive,_3DTILES_tileset.Gltf.extensionsproperty lists the extensions that extend that object, such asGltf2.Mesh.Primitive.Extensions.EXT_structural_metadata, and accepts any other extension asunknown.translationare tuples, and descriptions and@defaultvalues come from the schemas.@internal, like the rest of the@cesium/gltfAPI, so this PR needs noCHANGES.mdentry.Configuration
packages/gltf/tsconfig.jsonincludesSchemaTypes/**/*.ts, andpackages/gltf/gltf.entry.d.tsre-exports them.eslint.config.jslintsSchemaTypeswith 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/gltfandnpm run eslintshould pass.npm run download-schemas -w @cesium/gltfandnpm run generate-types -w @cesium/gltf,git status packages/gltf/SchemaTypesshould show no changes.npm run build-ts,packages/gltf/index.d.tsshould contain the new types, andSource/Cesium.d.tsshould be unchanged..gltffile underSpecs/DataandApps/SampleDatawas type-checked againstGltf1orGltf2with a temporary script. One glTF 1.0 test model had a numberasset.version, fixed in this PR. The other failures are fixed in the next PR.Author checklist
CONTRIBUTORS.mdCHANGES.mdwith a short summary of my changeAI acknowledgment
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