58 lines
1.6 KiB
JavaScript
Executable File
58 lines
1.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Optimiert alle Falukant-Charakter-GLBs mit Draco + Textur-Optimierung.
|
|
* Ausgabe: *_opt.glb im selben Verzeichnis.
|
|
* Voraussetzung: npm install (@gltf-transform/cli als Dev-Dep)
|
|
*
|
|
* Aufruf: npm run optimize-models
|
|
*/
|
|
|
|
import fs from 'fs';
|
|
import { spawnSync } from 'child_process';
|
|
import { fileURLToPath } from 'url';
|
|
import path from 'path';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const charsDir = path.join(__dirname, '..', 'public', 'models', '3d', 'falukant', 'characters');
|
|
const cli = path.join(__dirname, '..', 'node_modules', '.bin', 'gltf-transform');
|
|
|
|
function listSourceModels() {
|
|
return fs.readdirSync(charsDir)
|
|
.filter((file) => file.endsWith('.glb'))
|
|
.filter((file) => !file.endsWith('_opt.glb'))
|
|
.sort((a, b) => a.localeCompare(b));
|
|
}
|
|
|
|
console.log('Optimize Falukant character GLBs (Draco + texture 1024)\n');
|
|
|
|
const models = listSourceModels();
|
|
if (models.length === 0) {
|
|
console.log('No source GLBs found.');
|
|
process.exit(0);
|
|
}
|
|
|
|
for (const f of models) {
|
|
const input = path.join(charsDir, f);
|
|
const out = f.replace(/\.glb$/, '_opt.glb');
|
|
const output = path.join(charsDir, out);
|
|
|
|
try {
|
|
const result = spawnSync(
|
|
'node',
|
|
[cli, 'optimize', input, output, '--compress', 'draco', '--texture-size', '1024'],
|
|
{
|
|
stdio: 'inherit',
|
|
cwd: path.join(__dirname, '..'),
|
|
}
|
|
);
|
|
if (result.status !== 0) {
|
|
throw new Error(`gltf-transform exited with ${result.status}`);
|
|
}
|
|
} catch (e) {
|
|
console.error(`Failed: ${f}`);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
|
|
console.log('\nDone. Use *_opt.glb in Character3D (with DRACOLoader).');
|