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

Model caching #2340

Merged
merged 21 commits into from
Dec 23, 2014
Merged

Model caching #2340

merged 21 commits into from
Dec 23, 2014

Conversation

pjcozzi
Copy link
Contributor

@pjcozzi pjcozzi commented Dec 21, 2014

Would like to get this in for 1.5.

Open the Chrome task manager, and note the memory usage and load time for the following Sandcastle example using both master and this branch.

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

function createModel(url, position, zoom) {
    var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);

    var model = scene.primitives.add(Cesium.Model.fromGltf({
        url : url,
        modelMatrix : modelMatrix,
        scale : 0.25 + (1.75 * Cesium.Math.nextRandomNumber()),
        minimumPixelSize : 128
    }));

    model.readyToRender.addEventListener(function(model) {
        // Play and loop all animations at half-speed
        model.activeAnimations.addAll({
            speedup : 0.2 + (2.0 * Cesium.Math.nextRandomNumber()),
            loop : Cesium.ModelAnimationLoop.REPEAT
        });

        // Zoom to model
        if (zoom) {
            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 url = '../../SampleData/models/CesiumAir/Cesium_Air.gltf';
//var url = '../../SampleData/models/CesiumGround/Cesium_Ground.gltf';
 var url = '../../SampleData/models/CesiumMan/Cesium_Man.gltf';

var zoom = true;
for (var x = 0; x < 20; ++x) {
    for (var y = 0; y < 20; ++y) {
        createModel(url, Cesium.Cartesian3.fromDegrees(-123.0 - (x * 0.0002), 44.0 - (y * 0.0002), 0.0), zoom);
        zoom = false;
    }
}

Master:

GPU Process: 2.7 GB
Tab: 680 MB

This branch:

GPU Process: 323 MB
Tab: 400 MB

This adds caching to glTF models. This is a replacement for #2177. Although this doesn't include any commits from that pull request, I have still credited @Relfos in CONTRIBUTORS.md for his significant work here.

Also added a few ideas for improvements to the model roadmap: #927

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Dec 23, 2014

@bagnell can you review?

bagnell added a commit that referenced this pull request Dec 23, 2014
@bagnell bagnell merged commit e8976ef into master Dec 23, 2014
@bagnell bagnell deleted the model-cache branch December 23, 2014 21:06
@pjcozzi pjcozzi mentioned this pull request Dec 24, 2014
return destroyObject(this);
};

return Model;
});

//TODO: ref count cached animations
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagnell we should not have let these TODOs get into master (they are on the roadmap). I'll remove them shortly in my next pull request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I wasn't sure because we have other TODO, PERFORMANCE_IDEA, PERFORMANCE_TODO comments. Some of which I implemented optimizing some of the geometries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes I leave a PERFORMANCE_IDEA (and they even come in handy once in a while), but call me on it if I leave a TODO in.

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

Successfully merging this pull request may close these issues.

2 participants