您好,欢迎来到刀刀网。
搜索
您的当前位置:首页Cesium 加载 GLTF/GLB模型保存原始

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文档参见

entity模型的数据参考文档

但是这份数据中没有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原始数据了,如下:

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务