CesiumGS / CesiumGS/cesium

Clunky code needed to load and use a Model

Open
#11,216 0 comments 1 reaction 0 assignees View on GitHub
category - architecture / api category - model/gltf
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

I have code that needs to access model.boundingSphere as soon as the model is created. For some reason `Model.fromGltfAsync` resolves before the model.boundingSphere is "ready" to be accessed. This means that in order to do what I need, I have to always subscribe to the ready event and then immediately unsubscribe when it fires. The code looks something like this:

```js
async function loadAndZoom(url, scene) {
const doSomethingWithBoundingSphere = (model) => {
// model.boundingSphere
};

const model = await Model.fromGltfAsync({
url: url,
scene: scene
});

if (model.ready) {
doSomethingWithBoundingSphere();
} else {
const unSub = model.readyEvent.addEventListener(() => {
unSub();
doSomethingWithBoundingSphere(model);
});
}
}
```

I'm not sure why we can't access `boundingSphere` after the async factor function resolves. If that's possible, great! Otherwise if there are technical reasons that can't happen I think we need to rethink the API here.

Contributor guide

Open the contributing guide

Research direction

Start by tracing Model.fromGltfAsync, model.ready, readyEvent, and boundingSphere in the Model implementation and its existing tests. Determine whether the async factory can guarantee boundingSphere availability; done means either that access works immediately after resolution or the API behavior is clearly redesigned and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.