CesiumGS / CesiumGS/cesium

`GltfLoader` fails for glTF with no scenes

Open
#12,447 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

category - model/gltf type - bug
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

### What happened?

I was testing a glTF model that contains no `scene` or `scenes` property. `GltfLoader` is *supposed* to resolve this by picking the first node in the `nodes` array. However, the code results in attempting to access an `undefined` node.

I have narrowed it down to some weird behavior in `loadScene`. The function `getSceneNodeIds` is called before it, and it's supposed to substitutde the `nodes` array if no `scenes` exist. This is successfully chosen. It is the following line that results in an `undefined` node being added to the scene:

```
scene.nodes = sceneNodeIds.map(function (sceneNodeId) {
return nodes[sceneNodeId];
});
```

### Reproduction steps

This is most easily reproduced in locally-built CesiumJS.

1. Open `Apps/SampleData/Models/BoxUnlit/BoxUnlit.gltf` in a text editor like VSCode.
2. Delete the `scene` and `scenes` properties from the file.
3. Navigate to the "3D Models" sandcastle. Select "Unlit Box" from the dropdown. You'll get this error:

```
An error occurred while rendering. Rendering has stopped.
TypeError: Cannot read properties of undefined (reading 'matrix')
TypeError: Cannot read properties of undefined (reading 'matrix')
at ModelUtility.getNodeTransform (http://localhost:8080/Build/CesiumUnminified/index.js:72701:28)
at traverseAndCreateSceneGraph (http://localhost:8080/Build/CesiumUnminified/index.js:100266:43)
at initialize14 (http://localhost:8080/Build/CesiumUnminified/index.js:100182:27)
at new ModelSceneGraph (http://localhost:8080/Build/CesiumUnminified/index.js:100098:3)
at Model.update (http://localhost:8080/Build/CesiumUnminified/index.js:103316:24)
at PrimitiveCollection.update (http://localhost:8080/Build/CesiumUnminified/index.js:141598:19)
at updateAndRenderPrimitives (http://localhost:8080/Build/CesiumUnminified/index.js:241846:21)
at executeCommandsInViewport (http://localhost:8080/Build/CesiumUnminified/index.js:241697:3)
at Scene4.updateAndExecuteCommands (http://localhost:8080/Build/CesiumUnminified/index.js:241519:5)
at render (http://localhost:8080/Build/CesiumUnminified/index.js:242270:9)
```

### Sandcastle example

http://localhost:8080/Apps/Sandcastle/index.html?src=3D%20Models.html

### Environment

Browser: Google Chrome 131.0.6778.265
CesiumJS Version: 1.124
Operating System: Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by removing `scene` and `scenes` from Apps/SampleData/Models/BoxUnlit/BoxUnlit.gltf and loading it in the 3D Models Sandcastle. Start by tracing `getSceneNodeIds` into `GltfLoader`'s `loadScene`, especially the `scene.nodes` mapping shown in the issue. Done means the model loads without an undefined node or rendering error when no scenes are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.