-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy patharticulated-gltf-to-urdf.js
executable file
·64 lines (57 loc) · 2.09 KB
/
articulated-gltf-to-urdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
/* jshint esversion: 6 */
const VERSION = '0.0.1';
const STK = require('../stk-ssc');
const URDFExporter = STK.exporters.URDFExporter;
const cmd = require('commander');
const process_asset_helper = require("../ssc-process-assets");
cmd
.version(VERSION)
.description('Loads an GLTF model with articulations and exports it as an URDF')
.option('--input <filename>', 'Input GLTF filename')
.option('--output_dir <dir>', 'Output directory')
.option('--output_mesh_format <format>', 'Output mesh format', /^(obj|gltf|glb|dae)$/, 'glb')
.parse(process.argv);
function exportURDF(name, target) {
const exportOpts = {
name: name,
meshFormat: cmd.output_mesh_format,
meshExportOpts: {
exportTextures: true // For OBJMTL export
}
};
// parameters for creating exporter
const exporterOpts = {
fs: STK.fs
};
const exporter = new URDFExporter(exporterOpts);
exporter.export(target, exportOpts);
}
function createAssetManager() {
//const useSearchController = cmd.use_search_controller;
const useSearchController = STK.Constants.baseUrl.startsWith('http://') || STK.Constants.baseUrl.startsWith('https://');
const assetManager = new STK.assets.AssetManager({
autoAlignModels: cmd.auto_align,
autoScaleModels: false,
assetCacheSize: cmd.assetCacheSize,
enableLights: cmd.use_lights,
defaultLightState: cmd.use_lights,
supportArticulated: true, mergeFixedParts: true,
searchController: useSearchController ? new STK.search.BasicSearchController() : null
});
return assetManager;
}
const assetManager = createAssetManager();
function convertAsset() {
const inputInfo = process_asset_helper.prepareAssetInfo('path', cmd.input,
{ assetType: 'model', source: cmd.source, inputFormat: cmd.format,
outputDir: cmd.output_dir, assetsDb: null });
const assetLoadInfo = inputInfo.loadInfo;
assetManager.loadModel(assetLoadInfo, (err, mInst) => {
STK.util.waitImagesLoaded(() => {
mInst.getArticulatedObjects();
exportURDF(inputInfo.outputname, mInst.object3D);
});
});
}
convertAsset();