Hi,
When loading a model Cesium.Model.fromGltf, the model readyPromise is never fulfilled.
Based on examples I found around, it seems that it only works when the primitive is added to the scene.
What I would like to achieve is to prevent the rendering to break when the model can not be loaded for any given reason (404, invalid format, etc…)
I expect the model promise to be triggered when the model is fully loaded before I can add it to the scene. I could prevent it to reach rendering if the promise reach the “otherwise” method.
I modified this example from Matthew Amato to highlight the problem:
The Original states:
var model = scene.primitives.add(Cesium.Model.fromGltf({…
``
Mine does:
var model = Cesium.Model.fromGltf({
``
The whole thing to be ran in Sandcastle:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;
var height = 5000.0;
var heading = 0.0;
var pitch = Cesium.Math.toRadians(10.0);
var roll = Cesium.Math.toRadians(-20.0);
var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, heading, pitch, roll);
var model = Cesium.Model.fromGltf({
url : ‘…/…/SampleData/models/CesiumAir/Cesium_Air.gltf’,
modelMatrix : modelMatrix,
minimumPixelSize : 128
});
model.readyPromise.then(function(model) {
scene.primitives.add(model);
// Play and loop all animations at half-speed
model.activeAnimations.addAll({
speedup : 0.5,
loop : Cesium.ModelAnimationLoop.REPEAT
});
var camera = viewer.camera;
// Zoom to model
var controller = scene.screenSpaceCameraController;
var r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near);
controller.minimumZoomDistance = r * 0.5;
var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());
var heading = Cesium.Math.toRadians(230.0);
var pitch = Cesium.Math.toRadians(-20.0);
camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, r * 2.0));
}).otherwise(function(error){
window.alert(error);
});
``
Cheers,
Xavier.