UNPKG

@blockv/threejs-to-v3d

Version:

Converts any format supported by ThreeJS to V3D.

43 lines (32 loc) 1.32 kB
#!/usr/bin/env node // // ThreeJS FBX to V3D command-line executable const fs = require("fs.promised"); const ThreeJSConverter = require("./src"); // Read command line args const args = require('command-line-args')([ { name: 'input', type: String, alt: "i", multiple: true, defaultOption: true }, { name: 'output', type: String, alt: "o" } ]); // Check input file count if (!args.input || args.input.length == 0 || !args.output) { console.log(""); console.log(" Converts .fbx files to .v3d. This can support any file type supported by ThreeJS (but not yet). "); console.log(""); console.log(" Usage: threejs-to-v3d file.fbx tex1.jpg tex2.jpg ... --output file.v3d"); console.log(""); process.exit(0); } // Create .v3d data var converter = new ThreeJSConverter(args.input); converter.onprogress = function(text) { console.log("> " + text); } converter.convert().then(data => fs.writeFile(args.output, new Buffer(data))).then(_ => { // Output warnings for (var issue of converter.issues) console.warn("Warning: " + issue.description); // Done! console.log("Conversion complete, output file is " + (converter.result.byteLength / 1024 / 1024).toFixed(2) + " MB.") }).catch(err => { // Failed! console.error("Conversion failed: " + err.message); });