如何获得用铯渲染的gltf纹理的状态

时间:2019-02-15 03:05:09

标签: cesium

我是新手,有一个3dsmax模型,该模型转换为带有很多纹理图像的gltf,在加载铯并飞向模型后,首先加载白色骨骼,然后需要很长时间来渲染纹理。我想在所有纹理渲染之前显示一个加载图像。反正有获取纹理渲染状态的信息吗?

1 个答案:

答案 0 :(得分:0)

如果直接将模型用作图形原语(而不是在Cesium实体上使用),那么会有Model.readyPromise会告诉您模型何时完成加载。

这里是铯1.54的Sandcastle Demo

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

var scene = viewer.scene;
var model;

var modelUrl = '../../../../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb';

var height = 0.0;
var heading = 0.0, pitch = 0.0, roll = 0.0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);

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

scene.primitives.removeAll(); // Remove previous model
model = scene.primitives.add(Cesium.Model.fromGltf({
    url : modelUrl,
    modelMatrix: modelMatrix
}));

console.log('Model is loading...');

model.readyPromise.then(function(model) {

    console.log('Model loading complete.');

    // Zoom to model
    var camera = viewer.camera;
    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){
    console.error(error);
});