Skip to content

Instantly share code, notes, and snippets.

@wallabyway
Last active December 23, 2021 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallabyway/4cd3112b3e86dc6d235bd3a0d86e87a5 to your computer and use it in GitHub Desktop.
Save wallabyway/4cd3112b3e86dc6d235bd3a0d86e87a5 to your computer and use it in GitHub Desktop.
svf2gltf-with-filter
// 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 url = `dXJuOm...j0z`;
const guid = `2588ca45-8487-cddf-b974-7f04179909a2`;
const token = `eyJhbG......gJHNA`
const dstPath = `out`;
convert(url, guid, token, dstPath);
//var args = process.argv.slice(2);
//convert(args[0],args[1],args[2],args[3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment