【问题标题】:How can i get model loading event in cesium viewer如何在铯查看器中获取模型加载事件
【发布时间】:2016-03-05 09:18:59
【问题描述】:

在 cesium 中我添加 3dmodel 如下(url 只是 .gltf 文件的路径)

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

在 cesium 查看器中加载 gltf 文件需要 30 到 60 秒,所以我想在加载 3dmodel 时显示处理中的 Gif 图像。为了实现这一点,我无法找到 3dmodel 加载事件。我的意思是实际加载完成的时间。 我尝试在函数结束后使用“then”子句。但是它不起作用

【问题讨论】:

    标签: cesium gltf


    【解决方案1】:

    目前,没有正式的方法可以做到这一点。 Entity API 层故意将图形基元层隐藏在其下方,以防止抽象泄漏。 Cesium 的未来版本应该将 Model.readyModel.readyPromise 暴露给 Entity API,但目前尚未实现。

    我确实花了一点时间来研究在 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.');
            });
        });
    }
    

    【讨论】:

    • 谢谢 emackey,但这不起作用,我收到 Uncaught TypeError: Cannot read property '_visualizers' of undefined。请检查一下并告诉我。
    • 我使用的是 Cesium-1.15 版本。能否请您发送与相同版本兼容的解决方案。谢谢
    • 编辑了我针对 Cesium 1.15 的答案。
    猜你喜欢
    • 2015-12-28
    • 2021-11-25
    • 2021-07-03
    • 2017-08-04
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    相关资源
    最近更新 更多