CesiumGS/cesium

Remove need to check ready before calling getGeometryInstanceAttributes

Open

#2 174 ouverte le 2 oct. 2014

Voir sur GitHub
 (5 commentaires) (2 réactions) (0 assignés)JavaScript (3 324 forks)batch import
category - graphicsgood first issuetype - cleanuptype - enhancement

Métriques du dépôt

Stars
 (11 758 stars)
Métriques de merge PR
 (Merge moyen 15j 12h) (23 PRs mergées en 30 j)

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

Guide contributeur