在Cesium3DTileset中获取特征的几何图形

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

((CesiumJS版本1.37)

我将batched 3D tileet层加载到CesiumJS中;我知道可以使用tile.content;访问该tileet中每个tile的内容;就我而言,该图块内容中的每个要素都对应一栋建筑物。读取功能(=建筑物)的所有属性非常简单:

var content = tile.content;
for (let i = 0; i < content.featuresLength; i++) {
  const feature = content.getFeature(i);
  const propertyNames = feature.getPropertyNames()
  const numProperties = propertyNames.length
  for(let j = 0; j < numProperties; j++){
    const propertyName = propertyNames[j]
    const propertyValue = feature.getProperty(propertyName)
    console.log('    ' + propertyName + ': ' + propertyValue)
  }
}

但是现在我寻求一种类似的简单方法来获取特征的几何形状(在我的情况下为建筑物)。我感觉到此信息有些隐藏,因为批处理的3D tileet图层引用的gltf(或更确切地说是glb)文件会立即进入图形卡,而我却无法访问(?)。

javascript cesium gltf
1个回答
0
投票

我似乎找到了一种效果很好的骇客。我的问题与我想访问某个特征的几何图形(即gltf)有关,这与加载内容后的时间有关。我发现虽然可以在加载时访问几何。因此整个问题变成了:“如何拦截加载过程,以便可以在加载时对几何进行自己的分析”。

背景:几何存储在content._model.gltf中。如果content._model.releaseGltfJson为true,则Cesium会在加载后删除content._model.gltf(或此getter所引用的缓存条目)。

我的拦截是:

    // HACK!
    const oldB3dmFactory = Cesium.Cesium3DTileContentFactory.b3dm 
    Cesium.Cesium3DTileContentFactory.b3dm = function(tileset, tile, url, arrayBuffer, 
    byteOffset) {
        const content = oldB3dmFactory(tileset, tile, url, arrayBuffer, byteOffset)
        console.log("Cesium3DTileContentFactory.b3dm intercepted, so we can access the content with the GLTF")
        const gltf = content._model.gltf
        content.readyPromise.then(()=>{
            // _model.gltf is undefined because 
            // releaseGltfJson === true
            content.log(content._model.gltf)
        })
        return content
    }

注意:这仅适用于批处理的3d Tileset(b3dm)。您需要将Cesium.Cesium3DTileContentFactory.b3dm替换为pntsi3dmcmptjson,此代码段才能与其他类型的几何一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.