Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Model animation #2078

Closed
hpinkos opened this issue Aug 22, 2014 · 0 comments
Closed

Incorrect Model animation #2078

hpinkos opened this issue Aug 22, 2014 · 0 comments

Comments

@hpinkos
Copy link
Contributor

hpinkos commented Aug 22, 2014

The error happens when creating more than 1 model using new Model(). It looks like the second models animation is using the rotation from the first model.

In the example below, the truck wheels use the rotation of the plane propellers.

image

I've included a sandcastle example below. To reproduce, switch between truck and plane twice. The first time creates the models using fromGltf. The second time creates the models using new Model and the truck should show the bad animation.

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

var planegltf;
var groundgltf;

function createModel(url, height, name) {
    height = Cesium.defaultValue(height, 0.0);

    var modelMatrix = Cesium.Transforms.northEastDownToFixedFrame(Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height));

    scene.primitives.removeAll(); // Remove previous model
    var options = {
        modelMatrix : modelMatrix,
        minimumPixelSize : 128
    };
    var model;
    if (name === 'plane' && Cesium.defined(planegltf)) {
        options.gltf = planegltf;
        model = scene.primitives.add(new Cesium.Model(options));
    } else if (name === 'ground' && Cesium.defined(groundgltf)) {
        options.gltf = groundgltf;
        model = scene.primitives.add(new Cesium.Model(options));
    } else {
        options.url = url;
        model = scene.primitives.add(Cesium.Model.fromGltf(options));
    }

    model.readyToRender.addEventListener(function(model) {
        if (name === 'plane' && !Cesium.defined(planegltf)) {
            planegltf = model.gltf;
        }

        if (name === 'ground' && !Cesium.defined(groundgltf)) {
            groundgltf = model.gltf;
        }

        // Play and loop all animations at half-spead
        model.activeAnimations.addAll({
            speedup : 0.5,
            loop : Cesium.ModelAnimationLoop.REPEAT
        });

        // Zoom to model
        var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());
        var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);
        var camera = scene.camera;
        camera.transform = transform;
        var controller = scene.screenSpaceCameraController;
        var r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near);
        controller.minimumZoomDistance = r * 0.5;
        camera.lookAt(new Cesium.Cartesian3(r, r, r), Cesium.Cartesian3.ZERO, Cesium.Cartesian3.UNIT_Z);
    });
}

///////////////////////////////////////////////////////////////////////////

var options = [{
text : 'Aircraft',
onselect : function() {
    createModel('../../SampleData/models/CesiumAir/Cesium_Air.gltf', 5000.0, 'plane');
    }
}, {
text : 'Ground vehicle',
    onselect : function() {
        createModel('../../SampleData/models/CesiumGround/Cesium_Ground.gltf', 0.0, 'ground');
    }
}];

Sandcastle.addToolbarMenu(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant