CesiumGS / CesiumGS/cesium

Remove need to check ready before calling getGeometryInstanceAttributes

Open
#2,174 5 comments 2 reactions 0 assignees View on GitHub
category - graphics good first issue type - cleanup type - enhancement
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

This leads to workarounds like:

``` javascript
var frameNumber = 0;
var scratch = new Cesium.Cartesian3();
var ready = false;

viewer.clock.onTick.addEventListener(function() {
var length = updates.length;
var k;
var u;

if (!ready && primitive.ready) {
ready = true;
for (k = 0; k < length; ++k) {
u = updates[k];
u.attributes = primitive.getGeometryInstanceAttributes(k);
}

return;
}

if (ready) {
for (k = 0; k < length; ++k) {
u = updates[k];
scratch = Cesium.Cartesian3.multiplyByScalar(u.direction, (Math.sin(frameNumber * u.speed) * u.maxHeight), scratch);
u.attributes.offset = Cartesian3InstanceAttribute.toValue(scratch, u.offsetArray);
}
}

++frameNumber;
});
```

Full example: https://gist.github.com/pjcozzi/4bc8fbf5a2907de6c3a9

We can just buffer the attributes, which will also eliminate the need for a scratch variable each time an attribute is set (`u.offsetArray` above), which caught me recently. I suspect this can be done without creating GC pressure so the performance drop should be insignificant compared to the usability gain.

CC #766

Contributor guide

Open the contributing guide

Research direction

Start by tracing the getGeometryInstanceAttributes entry point and the primitive.ready behavior described in the issue. Use the linked full example to reproduce the current workaround, then determine how buffered attributes should behave before readiness and verify that updates no longer require a ready check or per-update scratch variable.

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
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.