-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconvert.js
More file actions
34 lines (29 loc) · 1.06 KB
/
convert.js
File metadata and controls
34 lines (29 loc) · 1.06 KB
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
const fs = require('fs');
const path = require('path');
const convert = require('fbx2gltf');
function convertFBXFiles(inputDir, outputDir) {
fs.readdirSync(inputDir).forEach(file => {
const filePath = path.join(inputDir, file);
const stats = fs.statSync(filePath);
if (stats.isFile() && path.extname(file) === '.fbx') {
const outputFile = path.join(outputDir, file.replace('.fbx', '.glb'));
console.log(`Converting file: ${filePath}`);
convert(filePath, outputFile, ['--khr-materials-unlit']).then(
destPath => {
console.log(`File converted: ${destPath}`);
},
error => {
console.error(`Error converting file: ${filePath}`);
console.error(error);
}
);
} else if (stats.isDirectory()) {
const newInputDir = path.join(inputDir, file);
const newOutputDir = path.join(outputDir, file);
fs.mkdirSync(newOutputDir, { recursive: true });
convertFBXFiles(newInputDir, newOutputDir);
}
});
}
// Convert Files Function
convertFBXFiles('_input', '_output');