1

In cesium I am adding 3dmodel as the follows(url is nothing but the path of .gltf file)

function load3dmodel(url, x, y) {
    viewer.entities.removeAll();
    viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(x, y), model: {
            uri: url
         }
    });
}

It is taking 30 to 60 sec to laod the gltf file in cesium viewer, so i want to display a processing Gif image while loading 3dmodel. to achieve this i am not able to find the 3dmodel loading event. I mean when actually the loading completed. I tried using "then" clause after the function gets end. bu it is not working

4

1 回答 1

2

目前,没有官方的方法可以做到这一点。Entity API 层故意将图形基元层隐藏在其下方,以防止抽象泄漏。Cesium 的未来版本应该向实体 API 公开Model.ready和公开Model.readyPromise,但目前尚未实现。

我确实花了一点时间来看看在 Cesium 1.15 版中找出模型原语需要什么。找到它的代码非常难看,它使用“私有”(以 为前缀_)变量,这些变量没有记录在案,并且可以在没有警告的情况下进行更改。所以这不是一个长期的解决方案,并且可能无法跨版本工作。

function load3dmodel(url, x, y) {
    viewer.entities.removeAll();
    var entity = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(x, y), model: {
            uri: url
        }
    });

    // Use of _private variables is undocumented, subject to change without notice.
    // Do not use this code in production.
    Cesium.requestAnimationFrame(function() {
        viewer.dataSourceDisplay.defaultDataSource._visualizers.reduce(function(a,b) {
            return (a instanceof Cesium.ModelVisualizer) ? a : b; }
        )._modelHash[entity.id].modelPrimitive.readyPromise.then(function() {
            console.log('Your model has loaded.');
        });
    });
}
于 2015-12-01T15:16:50.400 回答