Add male toddler character model in GLB format

This commit is contained in:
Torsten Schulz (local)
2026-07-30 09:59:53 +02:00
parent 12985bf3fa
commit 55810e2e3a
2 changed files with 37 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ const PROJECT_ROOT = path.join(BACKEND_DIR, '..');
const MODELS_REL = path.join('models', '3d', 'falukant', 'characters'); const MODELS_REL = path.join('models', '3d', 'falukant', 'characters');
const DIST_MODELS = path.join(PROJECT_ROOT, 'frontend', 'dist', MODELS_REL); const DIST_MODELS = path.join(PROJECT_ROOT, 'frontend', 'dist', MODELS_REL);
const PUBLIC_MODELS = path.join(PROJECT_ROOT, 'frontend', 'public', MODELS_REL); const PUBLIC_MODELS = path.join(PROJECT_ROOT, 'frontend', 'public', MODELS_REL);
const SOURCE_MODELS = path.join(PROJECT_ROOT, 'frontend', 'models-src', '3d', 'falukant', 'characters');
const CACHE_DIR = path.join(BACKEND_DIR, 'data', 'model-cache'); const CACHE_DIR = path.join(BACKEND_DIR, 'data', 'model-cache');
const CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform'); const CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform');
@@ -103,16 +104,17 @@ export async function getOptimizedModelPath(filename) {
return sourcePath; return sourcePath;
} }
const rawSourcePath = path.join(SOURCE_MODELS, filename);
if (!fs.existsSync(rawSourcePath)) {
throw new Error(`Raw source model not found: ${filename} (looked in ${SOURCE_MODELS})`);
}
const cacheFilename = filename.replace(/\.glb$/, '_opt.glb'); const cacheFilename = filename.replace(/\.glb$/, '_opt.glb');
const cachePath = path.join(CACHE_DIR, cacheFilename); const cachePath = path.join(CACHE_DIR, cacheFilename);
if (!fs.existsSync(sourcePath)) {
throw new Error(`Source model not found: ${filename} (looked in ${sourceDir})`);
}
ensureCacheDir(); ensureCacheDir();
if (isCacheValid(sourcePath, cachePath)) { if (isCacheValid(rawSourcePath, cachePath)) {
return cachePath; return cachePath;
} }
@@ -120,7 +122,7 @@ export async function getOptimizedModelPath(filename) {
if (!promise) { if (!promise) {
promise = (async () => { promise = (async () => {
try { try {
await runOptimize(sourcePath, cachePath); await runOptimize(rawSourcePath, cachePath);
return cachePath; return cachePath;
} finally { } finally {
pending.delete(filename); pending.delete(filename);

View File

@@ -13,18 +13,42 @@ import { fileURLToPath } from 'url';
import path from 'path'; import path from 'path';
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const charsDir = path.join(__dirname, '..', 'public', 'models', '3d', 'falukant', 'characters'); const sourceDir = path.join(__dirname, '..', 'models-src', '3d', 'falukant', 'characters');
const outputDir = path.join(__dirname, '..', 'public', 'models', '3d', 'falukant', 'characters');
const cli = path.join(__dirname, '..', 'node_modules', '.bin', 'gltf-transform'); const cli = path.join(__dirname, '..', 'node_modules', '.bin', 'gltf-transform');
function listSourceModels() { function listSourceModels() {
return fs.readdirSync(charsDir) return fs.readdirSync(sourceDir)
.filter((file) => file.endsWith('.glb')) .filter((file) => file.endsWith('.glb'))
.filter((file) => !file.endsWith('_opt.glb')) .filter((file) => !file.endsWith('_opt.glb'))
.sort((a, b) => a.localeCompare(b)); .sort((a, b) => a.localeCompare(b));
} }
function ensureOutputDir() {
fs.mkdirSync(outputDir, { recursive: true });
}
function removeStaleOptimizedModels() {
if (!fs.existsSync(outputDir)) {
return;
}
for (const file of fs.readdirSync(outputDir)) {
if (file.endsWith('_opt.glb')) {
fs.unlinkSync(path.join(outputDir, file));
}
}
}
console.log('Optimize Falukant character GLBs (Draco + texture 1024)\n'); console.log('Optimize Falukant character GLBs (Draco + texture 1024)\n');
if (!fs.existsSync(sourceDir)) {
console.error(`Source directory not found: ${sourceDir}`);
process.exit(1);
}
ensureOutputDir();
removeStaleOptimizedModels();
const models = listSourceModels(); const models = listSourceModels();
if (models.length === 0) { if (models.length === 0) {
console.log('No source GLBs found.'); console.log('No source GLBs found.');
@@ -32,9 +56,9 @@ if (models.length === 0) {
} }
for (const f of models) { for (const f of models) {
const input = path.join(charsDir, f); const input = path.join(sourceDir, f);
const out = f.replace(/\.glb$/, '_opt.glb'); const out = f.replace(/\.glb$/, '_opt.glb');
const output = path.join(charsDir, out); const output = path.join(outputDir, out);
try { try {
const result = spawnSync( const result = spawnSync(
@@ -54,4 +78,4 @@ for (const f of models) {
} }
} }
console.log('\nDone. Use *_opt.glb in Character3D (with DRACOLoader).'); console.log(`\nDone. Optimized models written to ${outputDir}`);