cesium加载大容量的3D模型文件

由于3D建模的数据可能很大,初步建议在数据加载的时候加上提示框,告知用户“需要等待”,但cesium加载模型的方法类似于require,无法做到通过回调来控制提示信息的显示于消失,写法如下

 

      this.gltfEntity = this.viewer.entities.add({
              position: Cesium.Cartesian3.fromDegrees(
                114.307031,
                30.555222,
                0
              ),
              model: {
                uri: "/static/modeldata/output/wuhan_new.gltf",
                minimumPixelSize: 1,
                scale: 1
              }
            });
      this.viewer.zoomTo(this.gltfEntity)

 

但仔细查看cesium的API,发现zoomTo方法返回的是promise

 

 

所以完全可以使用promise.then的成功回调来做一些操作,比如影藏掉提示框等,下面只是简单的打印时间信息:

      let startTime = new Date().getTime();
            let endTime;
            this.gltfEntity = this.viewer.entities.add({
              position: Cesium.Cartesian3.fromDegrees(
                114.307031,
                30.555222,
                0
              ),
              model: {
                uri: "/static/modeldata/output/wuhan_new.gltf",
                minimumPixelSize: 1,
                scale: 1
              }
            });
            this.viewer.zoomTo(this.gltfEntity).then(function() {
              endTime = new Date().getTime();
              console.log('加载完毕,共耗时', endTime - startTime)
            });

  

网上还有3DTiles方法,待后续了解

posted @ 2019-05-05 17:43  Mr_Kahn  阅读(2415)  评论(0)    收藏  举报