简体   繁体   English

将伪造查看器场景导出到 GLTF

[英]Exporting forge viewer scene to GLTF

I am trying to convert some isolated elements on forge viewer to GLTF I have included this script我正在尝试将伪造查看器上的一些孤立元素转换为 GLTF 我已包含此脚本

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

I am using this code to export to GLTF我正在使用此代码导出到 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} );
}

but unfortunately I receive empty GLTF output like this但不幸的是,我收到这样的空 GLTF 输出

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

R103+ THREE.GLTFExporter() is not compatible with THREE R71 (since we use a modified BufferGeometry), hence why you are getting no geometry. R103+ THREE.GLTFExporter() 与 THREE R71 不兼容(因为我们使用了修改后的 BufferGeometry),因此您没有得到几何图形。

Alex is right, use glTF-convert-utils. Alex 是对的,使用 glTF-convert-utils。

Here's an example node.js script, with DBID filter.这是一个带有 DBID 过滤器的示例 node.js 脚本。 Use this to filter out a sub-set of the full drawing:使用它来过滤掉完整图形的子集:

// 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);

Remember to fill in the urn, guid & token with your forge details.请记住用您的伪造详细信息填写urn, guid & token The script will connect to forge, download svf, convert to gltf, then convert to glb (with MeshOpt compression using glTFpack).该脚本将连接到 forge,下载 svf,转换为 gltf,然后转换为 glb(使用 glTFpack 进行 MeshOpt 压缩)。

如果你想模型的片段导出到glTF结账这里

I am not sure it's possible to extract the Forge scene with ThreeJS exporters.我不确定是否可以使用 ThreeJS 导出器提取 Forge 场景。

If you want to extract your Forge model into glTF format, one of the best way (as of today) is to use the Forge Convert Utils package.如果您想将Forge模型提取为glTF格式,最好的方法之一(截至目前)是使用Forge Convert Utils包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM