feat(optimize): optimize Falukant 3D models during build and update deployment scripts
All checks were successful
Deploy to production / deploy (push) Successful in 3m3s
All checks were successful
Deploy to production / deploy (push) Successful in 3m3s
This commit is contained in:
@@ -1,41 +1,53 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Optimiert Falukant-Charakter-GLBs mit Draco + Textur-Optimierung.
|
||||
* 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 { execSync } from 'child_process';
|
||||
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 models = [
|
||||
'male.glb', 'female.glb',
|
||||
'male_adult.glb', 'male_child.glb', 'male_preteen.glb', 'male_teen.glb', 'male_toddler.glb',
|
||||
'female_adult.glb', 'female_child.glb', 'female_preteen.glb', 'female_teen.glb', 'female_toddler.glb',
|
||||
];
|
||||
|
||||
const cli = path.join(__dirname, '..', 'node_modules', '.bin', 'gltf-transform');
|
||||
const cmd = (input, output) =>
|
||||
`"${cli}" optimize "${input}" "${output}" --compress draco --texture-size 1024`;
|
||||
|
||||
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 {
|
||||
execSync(`node "${cli}" optimize "${input}" "${output}" --compress draco --texture-size 1024`, {
|
||||
stdio: 'inherit',
|
||||
cwd: path.join(__dirname, '..'),
|
||||
});
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user