Cesium 加载 GLTF/GLB模型保存原始

Cesium加载GLTF/GLB模型使用的接口是

        const entity = viewer.entities.add({
            name: "model layer",
            position: position,
            orientation: orientation,
            model: {
                uri: url,
                minimumPixelSize: 128,
                maximumScale: 20000,
            },
        });

相关API文档参见

ModelGraphics - Cesium Documentation

entity模型的数据参考文档

Model - Cesium Documentation

但是这份数据中没有gltf/glb的原始文档数据,如果想要像babylon那样反显模型的数据结构,Cesium是做不到的

除非……

修改源码

在源码仓库中找到这个文件

packages\engine\Source\Scene\GltfJsonLoader.js

找到这个方法 processGltfJson

async function processGltfJson(gltfJsonLoader, gltf) {
  try {
    addPipelineExtras(gltf);

    await decodeDataUris(gltf);
    await upgradeVersion(gltfJsonLoader, gltf);
    addDefaults(gltf);
    await loadEmbeddedBuffers(gltfJsonLoader, gltf);
    removePipelineExtras(gltf);

    const version = gltf.asset.version;
    if (version !== "1.0" && version !== "2.0") {
      throw new RuntimeError(`Unsupported glTF version: ${version}`);
    }

    const extensionsRequired = gltf.extensionsRequired;
    if (defined(extensionsRequired)) {
      ModelUtility.checkSupportedExtensions(extensionsRequired);
    }

    gltfJsonLoader._gltf = gltf;
    gltfJsonLoader._state = ResourceLoaderState.READY;
    return gltfJsonLoader;
  } catch (error) {
    if (gltfJsonLoader.isDestroyed()) {
      return;
    }

    handleError(gltfJsonLoader, error);
  }
}

将第9行的 removePiplelineExtras(gltf) 注释掉

就可以在前端加载gltf模型的时候看到gltfjson原始数据了,如下:

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值