CesiumGS/cesium
View on GitHubRemove need to check ready before calling getGeometryInstanceAttributes
Open
#2174 opened on Oct 2, 2014
category - graphicsgood first issuetype - cleanuptype - enhancement
Description
This leads to workarounds like:
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