perf(falukant): deploy prebuilt models and release WebGL contexts
All checks were successful
Deploy to production / deploy (push) Successful in 2m19s
All checks were successful
Deploy to production / deploy (push) Successful in 2m19s
This commit is contained in:
45
frontend/scripts/build-falukant-runtime-models.mjs
Normal file
45
frontend/scripts/build-falukant-runtime-models.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Creates deployment-ready Falukant GLBs in the asset repository.
|
||||
* Sources remain in models-src; only optimized *_opt.glb files are written
|
||||
* to public/models and are later fetched by update-frontend.sh.
|
||||
*
|
||||
* Example:
|
||||
* npm run build-runtime-models -- --assets-dir ../YourPart3Assets
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const frontendDir = path.resolve(scriptDir, '..');
|
||||
const args = process.argv.slice(2);
|
||||
const optionIndex = args.indexOf('--assets-dir');
|
||||
const assetsDir = path.resolve(optionIndex >= 0 && args[optionIndex + 1]
|
||||
? args[optionIndex + 1]
|
||||
: path.join(frontendDir, '..', '..', 'YourPart3Assets'));
|
||||
const sourceRoot = path.join(assetsDir, 'models-src', '3d', 'falukant');
|
||||
const outputRoot = path.join(assetsDir, 'public', 'models', '3d', 'falukant');
|
||||
|
||||
for (const category of ['characters', 'houses']) {
|
||||
const sourceDir = path.join(sourceRoot, category);
|
||||
const outputDir = path.join(outputRoot, category);
|
||||
if (!fs.existsSync(sourceDir)) {
|
||||
throw new Error(`Missing model source directory: ${sourceDir}`);
|
||||
}
|
||||
|
||||
const result = spawnSync(process.execPath, [path.join(scriptDir, 'optimize-glb.mjs')], {
|
||||
cwd: frontendDir,
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
MODEL_SOURCE_DIR: sourceDir,
|
||||
MODEL_OUTPUT_DIR: outputDir,
|
||||
CLEAN_MODEL_OUTPUT: 'true',
|
||||
},
|
||||
});
|
||||
if (result.status !== 0) process.exit(result.status ?? 1);
|
||||
}
|
||||
|
||||
console.log(`Runtime models ready in ${outputRoot}`);
|
||||
@@ -35,8 +35,9 @@ function removeStaleOptimizedModels(outputDir) {
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
return;
|
||||
}
|
||||
const cleanAllModels = process.env.CLEAN_MODEL_OUTPUT === 'true';
|
||||
for (const file of fs.readdirSync(outputDir)) {
|
||||
if (file.endsWith('_opt.glb')) {
|
||||
if (file.endsWith('_opt.glb') || (cleanAllModels && file.endsWith('.glb'))) {
|
||||
fs.unlinkSync(path.join(outputDir, file));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user