AnalyticalGraphicsInc/cesium — pull request #2340 by pjcozzi (2014-12-21 19:05:19+00:00)
Title: Model caching

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.

```javascript
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