CesiumGS/cesium

Remove need to check ready before calling getGeometryInstanceAttributes

Open

#2174 aperta il 2 ott 2014

Vedi su GitHub
 (5 commenti) (2 reazioni) (0 assegnatari)JavaScript (3324 fork)batch import
category - graphicsgood first issuetype - cleanuptype - enhancement

Metriche repository

Star
 (11.758 star)
Metriche merge PR
 (Merge medio 15g 12h) (23 PR mergiate in 30 g)

Descrizione

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

Guida contributor