Skip to content

Type the glTF 0.8 and 1.0 upgrades in updateVersion - #14150

Open
jjhembd wants to merge 17 commits into
gltf-typesfrom
gltf-typed-upgrade
Open

jjhembd wants to merge 17 commits into
gltf-typesfrom
gltf-typed-upgrade

Conversation

@jjhembd

@jjhembd jjhembd commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Description

updateVersion upgraded glTF 0.8 and 1.0 assets in place, passing them through states that match no glTF version, so #14123 typed its helpers as any. This PR replaces the in-place upgrade with typed conversions: gltf08to1 builds a new Gltf1 from a Gltf08, and gltf1to2 builds a new Gltf2 from a Gltf1, one object type at a time. After this PR, packages/gltf/Source has no any types.

Code changes

The changes are organized so that they can be reviewed one commit at a time.

Preparation

  • Simplify the upgrade chain: glTF08to10 and glTF10to20 become gltf08to1 and gltf1to2, and updateVersion calls them directly.
  • Find the empty glTF 1.0 nodes before converting nodes to an array, without modifying the asset.

A converter per glTF object type

Each commit replaces the in-place reference fixes for some object types with converters that build a new glTF 2.0 object from a glTF 1.0 object: convertAsset, convertBuffer, convertCamera, convertImage, convertTexture, convertMesh, convertAnimation, convertMaterial, convertNode, convertScene, convertSkin, and convertBufferViewsAndAccessors. IdMaps types the maps from glTF 1.0 ids to glTF 2.0 indices. ESLint's no-unused-vars now sets ignoreRestSiblings, so converters can leave out properties with rest destructuring.

updateVersion returns the upgraded glTF

updateVersion returns the upgraded asset, which may be a new object, and GltfJsonLoader uses the return value. Most of the updateVersionSpec.js diff is from this commit, which makes each test assign the result. Later commits leave updateVersionSpec.js unchanged.

gltf1to2 builds a new Gltf2

gltf1to2 takes a Gltf1 and assembles the Gltf2 from the converted arrays, and objectsToArrays is deleted. objectToArray now only converts id-keyed objects to arrays, and the new getIdMap builds the id map.

Typed glTF 0.8 upgrade

The glTF 0.8 upgrade moves to gltf08to1.js, then becomes a conversion from Gltf08, a new @internal type with the glTF 0.8 properties that gltf08to1 reads, since glTF 0.8 has no schema. convert08Material converts the 0.8 instanceTechnique, which some non-compliant glTF 1.0 assets also have.

Remaining any types

  • The six ForEach functions that the new converters no longer call are deleted, with their specs.
  • ForEach functions and handler types are generic in the value type, and ForEach.topLevel is replaced with ForEach.object on each top-level array.
  • The KHR_materials_common material extension gets a private type, since it has no schema file.

Adding types for a new extension

The last commit shows how to add a new extension's types: it adds 3DTILES_shape_ellipsoid_region to gltfSchemaSources.json, regenerates SchemaTypes, and uses the generated type in constructBoundingVolumeJson in place of an inline cast.

Changes to the upgraded glTF JSON

  • A glTF 2.0 bufferView holding glTF 1.0 accessors gets a byteLength that ends at the last byte of its accessors' data, which can be shorter than its glTF 1.0 byteLength.
  • The extensionsRequired of a glTF 2.0 asset upgraded from glTF 1.0 lists CESIUM_RTC and WEB3D_quantized_attributes when they're in extensionsUsed, and ignores any extensionsRequired in the input, which glTF 1.0 doesn't define.

updateVersion is @internal, so this PR needs no CHANGES.md entry.

Issue number and link

Part of #13949.

Testing plan

  • npm run tsc -w @cesium/gltf, npm run eslint, and npm run sg-scan should pass.
  • npm run test -w @cesium/gltf and npm run test -- --includeName Scene/Gltf should pass. A new test checks that interleaved glTF 1.0 vertex attributes share one bufferView.
  • npx jsdoc --configure Tools/jsdoc/conf.json --pedantic should print no errors.
  • grep -rnE "\{any\}|\{\*\}|[<,] ?\*>|: any\b|<any>" packages/gltf/Source should print nothing.
  • glTF 1.0 models, such as the ones in Specs/Data/Models/glTF-1.0, should load and render as on main.

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 15:00
@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:00

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

A critical bug removes strides from animation accessors in mixed bufferViews without repacking their data, corrupting animation timing.

2 open issues
What changed in this PR

Replaces in-place legacy glTF upgrades with typed conversions, continuing the workspace typing work in #14123 and #13949.

Changes:

  • Builds upgraded assets through typed converters and updates the loader to use the returned object.
  • Removes remaining any types and adds interleaved-accessor coverage.
  • Generates ellipsoid-region extension types for bounding-volume conversion.
File Description
packages/​gltf/​Specs/​updateVersionSpec.js Uses returned assets and tests interleaved attributes.
packages/​gltf/​Specs/​ForEachSpec.js Removes tests for deleted helpers.
packages/​gltf/​Source/​usesExtension.js Includes glTF 0.8 input types.
packages/​gltf/​Source/​updateVersion.js Introduces typed object converters.
packages/​gltf/​Source/​removePipelineExtras.js Types pipeline-buffer access.
packages/​gltf/​Source/​removeExtension.js Replaces unrestricted types with unknown.
packages/​gltf/​Source/​parseGlb.js Includes glTF 0.8 return types.
packages/​gltf/​Source/​KHR_materials_common.ts Defines private material-extension types.
packages/​gltf/​Source/​IdMaps.ts Types legacy ID-to-index maps.
packages/​gltf/​Source/​gltf08to1.js Extracts typed glTF 0.8 conversion.
packages/​gltf/​Source/​Gltf08.ts Defines legacy glTF 0.8 types.
packages/​gltf/​Source/​ForEachNamedHandler.ts Adds generic callback value types.
packages/​gltf/​Source/​ForEachIdHandler.ts Uses unknown callback returns.
packages/​gltf/​Source/​ForEachElementHandler.ts Adds generic element types.
packages/​gltf/​Source/​forEachBuffer.js Types callbacks and legacy inputs.
packages/​gltf/​Source/​ForEach.js Types iterators and removes unused helpers.
packages/​gltf/​Source/​convert08Material.js Converts legacy material technique properties.
packages/​gltf/​Source/​constructBoundingVolumeJson.js Uses generated ellipsoid-region types.
packages/​gltf/​Source/​addPipelineExtras.js Includes glTF 0.8 input types.
packages/​gltf/​scripts/​gltfSchemaSources.json Registers the ellipsoid-region schema.
packages/​gltf/​SchemaTypes/​index.ts Exports generated extension types.
packages/​gltf/​SchemaTypes/​Gltf2.ts Adds typed shape-extension support.
packages/​gltf/​SchemaTypes/​Extensions/​3DTILES_shape_ellipsoid_region.ts Defines generated ellipsoid-region types.
packages/​gltf/​gltf.entry.d.ts Exports Gltf08.
packages/​engine/​Source/​Scene/​GltfJsonLoader.js Consumes the returned upgraded asset.
eslint.config.js Allows unused rest-destructuring siblings.

Review effort: Balanced

Comment thread packages/gltf/Source/updateVersion.js Resolved
Comment thread packages/gltf/Source/updateVersion.js Resolved
@jjhembd
jjhembd force-pushed the gltf-typed-upgrade branch from 7205c6e to 0eb3d9e Compare December 4, 2026 15:06
@jjhembd
jjhembd force-pushed the gltf-typed-upgrade branch 3 times, most recently from 560f577 to 2bd8a0e Compare December 4, 2026 18:26
@jjhembd
jjhembd requested a balanced review from Copilot December 4, 2026 18:32

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.

🔵 Needs a closer look

Changes to legacy glTF object identity and buffer-view ranges require loading and rendering validation on representative glTF 0.8/1.0 assets that this source-only review cannot provide.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@jjhembd
jjhembd force-pushed the gltf-typed-upgrade branch from 833a678 to 59fb017 Compare December 4, 2026 20:30
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.

2 participants