【问题标题】:Exporting forge viewer scene to GLTF将伪造查看器场景导出到 GLTF
【发布时间】:2021-12-25 20:25:12
【问题描述】:

我正在尝试将 Forge 查看器上的一些孤立元素转换为 GLTF 我已包含此脚本

<script src="https://unpkg.com/three@0.126.0/examples/js/exporters/GLTFExporter.js"></script>

我正在使用此代码导出到 GLTF

const exporter=new THREE.GLTFExporter()
const exportGLTF = () => {
  var scene = viewer.impl.scene
  exporter.parse( scene, function ( gltf ) {
    const output = JSON.stringify( gltf, null, 2 );
    console.log(output)    
    //saveString( output, 'scene.gltf' );
  }, {trs: true} );
}

但不幸的是,我收到这样的空 GLTF 输出

{
  "asset": {
    "version": "2.0",
    "generator": "THREE.GLTFExporter"
  },
  "scenes": [
    {}
  ],
  "scene": 0
}

【问题讨论】:

    标签: three.js autodesk-forge autodesk-viewer


    【解决方案1】:

    R103+ THREE.GLTFExporter() 与 THREE R71 不兼容(因为我们使用了修改后的 BufferGeometry),因此您没有得到几何图形。

    Alex 是对的,使用 glTF-convert-utils。

    这是一个示例 node.js 脚本,带有 DBID 过滤器。使用它来过滤掉完整绘图的子集:

    // convert SVF to dstPath/output.glb (with zeux compression)
    // but only convert a subset of objects (see filter on line 23)
    
    // INSTALL:
    // > npm install forge-convert-utils forge-server-utils fs-extra gltfpack
    
    // RUN:
    // > node convert url  guid  token  dstPath
    
    const path = require('path');
    const fs = require('fs-extra');
    var gltfpack = require('gltfpack');
    const { SvfReader, GltfWriter } = require('forge-convert-utils');
    
    async function convert(urn, guid, token, dstPath) {
    
      // Convert SVF to glTF
      const reader = await SvfReader.FromDerivativeService(urn, guid, { token });
      const writer = new GltfWriter({
        ignoreLineGeometry: true,
        ignorePointGeometry: true,
        skipUnusedUvs: false,
        center: false,
        filter: (dbid) => (
            [34044, 40936, 41095, 39471, 40933, 40939, 41092, 41097, 41090, 40946].indexOf(dbid)>-1)
      });
      const svf = await reader.read();
      const gltfDir = path.join(path.dirname(dstPath), 'gltf');
      fs.ensureDirSync(gltfDir);
      await writer.write(svf, gltfDir);
    
      gltfpack.pack(['-cc', '-i', './gltf/output.gltf', '-o', 'output.glb'], { read: fs.readFileSync, write: fs.writeFileSync})
    }
    
    
    const urn = `dXJuOm...j0z`;
    const guid = `2588ca45-8487-cddf-b974-7f04179909a2`;
    const token = `eyJhbG......gJHNA`
    const dstPath = `out`;
    
    convert(urn, guid, token, dstPath);
    

    记得在urn, guid &amp; token 中填写您的伪造详细信息。该脚本将连接到 forge,下载 svf,转换为 gltf,然后转换为 glb(使用 glTFpack 进行 MeshOpt 压缩)。

    【讨论】:

    • 是的,我使用了它,但是模型从它作为参数输入到 three.js USDZExporter 以获取 usdz 文件,USDZ 没有很好地居中它似乎没有以 IOS AR 模式为中心,出现在头顶
    • 首先是获取glTF。然后我们可以转到 USDZ 部分。您首先需要一个以原点为中心的 glTF。所以开始使用forge-convert-utils 和选项center:true。这将添加一个父 gltf 节点,该节点以全局偏移量为中心设置 glTF 文件。但是,偏移量是根据所有内容计算的,您希望它根据过滤子集中的 dbid 计算它。手动执行此操作(使用 AABB 质心计算过滤后的 dbid 集的中心),然后使用新的偏移值修改 gltf 文件和父节点。
    【解决方案2】:

    我不确定是否可以使用 ThreeJS 导出器提取 Forge 场景。

    如果您想将 Forge 模型提取为 glTF 格式,最好的方法之一(截至目前)是使用 Forge Convert Utils 包。

    【讨论】:

    • 我已经特别使用了这个工具这个代码,但是我收到了每个文件是 2 kb 的空节点,里面没有任何文件,但不幸的是我收到的文件没有节点 "scenes": [ { "nodes": [ 0 ] } ], "场景": 0
    猜你喜欢
    • 2020-04-14
    • 2019-05-15
    • 2020-05-28
    • 2018-11-23
    • 2019-12-28
    • 2021-05-22
    • 2018-06-28
    • 2018-10-22
    • 2020-05-30
    相关资源
    最近更新 更多