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

问题描述 投票:2回答:1

我是新手,有一个3dsmax模型转换为gltf与大量的纹理图像,加载铯和flyto模型后,首先加载白色骨骼,然后需要很长时间来渲染纹理。我想在渲染所有纹理之前显示加载图像。反正有没有获得纹理渲染状态?

cesium
1个回答
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);
});
© www.soinside.com 2019 - 2024. All rights reserved.