svf-utils
v8.0.0
Published
Tools for working with the SVF format used by Autodesk Platform Services.
Maintainers
Readme
svf-utils

Experimental utilities for working with Autodesk Platform Services SVF file formats.
Usage
Command line
Install the package globally (npm install --global svf-utils), and use one of the commands listed below.
SVF
- run the
svf-to-gltfcommand without parameters for usage info - run the command with a path to a local SVF file
- run the command with a Model Derivative URN (and optionally viewable GUID)
- to access APS you must also specify credentials (
APS_CLIENT_IDandAPS_CLIENT_SECRET) or an authentication token (APS_ACCESS_TOKEN) as env. variables - this will also download the property database in sqlite format
- to access APS you must also specify credentials (
- optionally, use any combination of the following command line args:
--output-folder <folder>to change output folder (by default '.')--deduplicateto try and remove duplicate geometries--skip-unused-uvsto skip texture UVs that are not used by any material--ignore-meshesto exclude mesh geometry from the output--ignore-linesto exclude line geometry from the output--ignore-pointsto exclude point geometry from the output--centermove the model to origin
On Unix/macOS:
svf-to-gltf <path to local svf> --output-folder <path to output folder>or
export APS_CLIENT_ID=<client id>
export APS_CLIENT_SECRET=<client secret>
svf-to-gltf <urn> --output-folder <path to output folder>or
export APS_ACCESS_TOKEN=<access token>
svf-to-gltf <urn> --output-folder <path to output folder>On Windows:
svf-to-gltf <path to local svf> --output-folder <path to output folder>or
set APS_CLIENT_ID=<client id>
set APS_CLIENT_SECRET=<client secret>
svf-to-gltf <urn> --output-folder <path to output folder>or
set APS_ACCESS_TOKEN=<access token>
svf-to-gltf <urn> --output-folder <path to output folder>Node.js
The library can be used at different levels of granularity.
The easiest way to convert an SVF file is to read the entire model into memory using SVFReader#read methods, and save the model into glTF using GLTFWriter#write. See samples/remote-svf-to-gltf.js.
If you don't want to read the entire model into memory (for example, when distributing the parsing of an SVF over multiple servers), you can use methods like SVFReader#enumerateFragments or SVFReader#enumerateGeometries to asynchronously iterate over individual elements:
const { SVFReader } = require('svf-utils');
// ...
const reader = await SVFReader.FromDerivativeService(urn, guid, authProvider);
for await (const fragment of reader.enumerateFragments()) {
console.log(fragment);
}And finally, if you already have the individual SVF assets in memory, you can parse the binary data directly using synchronous iterators like parseMeshes:
const { parseMeshes } = require('svf-utils/lib/svf/meshes');
// ...
for (const mesh of parseMeshes(buffer)) {
console.log(mesh);
}For additional examples, see the samples subfolder.
Customization
You can customize the translation by sub-classing the reader and/or the writer class. For example:
- samples/custom-gltf-attribute.js adds the dbID of each SVF node as a new attribute in its mesh
- samples/filter-by-area.js only outputs geometries that are completely contained within a specified area
Metadata
When converting models from Model Derivative service, you can retrieve the model properties and metadata in form of a sqlite database. The command line tool downloads this database automatically as properties.sqlite file directly in your output folder. If you're using this library in your own Node.js code, you can find the database in the manifest by looking for an asset with type "resource", and role "Autodesk.CloudPlatform.PropertyDatabase":
...
const pdbDerivatives = manifestHelper.search({ type: 'resource', role: 'Autodesk.CloudPlatform.PropertyDatabase' });
if (pdbDerivatives.length > 0) {
const databaseStream = modelDerivativeClient.getDerivativeChunked(urn, pdbDerivatives[0].urn, 1 << 20);
databaseStream.pipe(fs.createWriteStream('./properties.sdb'));
}
...The structure of the sqlite database, and the way to extract model properties from it is explained in https://github.com/wallabyway/propertyServer/blob/master/pipeline.md.
GLB, Draco, and other post-processing
Following the Unix philosophy, we removed post-processing dependencies from this project, and instead leave it to developers to "pipe" the output of this library to other tools such as https://github.com/CesiumGS/gltf-pipeline or https://github.com/zeux/meshoptimizer. See ./samples/local-svf-to-gltf.sh or ./samples/remote-svf-to-gltf.sh for examples.
Development
- clone the repository
- install dependencies:
yarn install - build the library (transpile TypeScript):
yarn run build - run samples in the test subfolder, for example:
APS_CLIENT_ID=<your client id> APS_CLIENT_SECRET=<your client secret> node test/remote-svf-to-gltf.js <model urn> <path to output folder>
If you're using Visual Studio Code, you can use the following "task" and "launch" configurations:
In .vscode/tasks.json:
...
{
"label": "build",
"type": "npm",
"script": "build",
"problemMatcher": [
"$tsc"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": false
}
}
...In .vscode/launch.json:
...
{
"type": "node",
"request": "launch",
"name": "Convert Model Derivative SVF to glTF",
"program": "${workspaceFolder}/test/remote-svf-to-gltf.js",
"args": ["<your model urn>", "<path to output folder>"],
"env": {
"APS_CLIENT_ID": "<your client id>",
"APS_CLIENT_SECRET": "<your client secret>"
},
"preLaunchTask": "build"
},
{
"type": "node",
"request": "launch",
"name": "Convert Local SVF to glTF",
"program": "${workspaceFolder}/test/local-svf-to-gltf.js",
"args": ["<path to svf file>", "<path to output folder>"],
"preLaunchTask": "build"
}
...Intermediate Format
The project provides a collection of interfaces for an intermediate 3D format that is meant to be used by all loaders and writers. When implementing a new loader, make sure that its output implements the intermediate format's IScene interface. Similarly, this interface should also be expected as the input to all new writers.
