From 55810e2e3ab79e4a3b3e1d36af27d1c1ef82182b Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 30 Jul 2026 09:59:53 +0200 Subject: [PATCH] Add male toddler character model in GLB format --- backend/services/modelsProxyService.js | 14 ++++++----- frontend/scripts/optimize-glb.mjs | 34 ++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/backend/services/modelsProxyService.js b/backend/services/modelsProxyService.js index 68ceb76..5dcdec1 100755 --- a/backend/services/modelsProxyService.js +++ b/backend/services/modelsProxyService.js @@ -14,6 +14,7 @@ const PROJECT_ROOT = path.join(BACKEND_DIR, '..'); const MODELS_REL = path.join('models', '3d', 'falukant', 'characters'); const DIST_MODELS = path.join(PROJECT_ROOT, 'frontend', 'dist', 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 CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform'); @@ -103,16 +104,17 @@ export async function getOptimizedModelPath(filename) { 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 cachePath = path.join(CACHE_DIR, cacheFilename); - if (!fs.existsSync(sourcePath)) { - throw new Error(`Source model not found: ${filename} (looked in ${sourceDir})`); - } - ensureCacheDir(); - if (isCacheValid(sourcePath, cachePath)) { + if (isCacheValid(rawSourcePath, cachePath)) { return cachePath; } @@ -120,7 +122,7 @@ export async function getOptimizedModelPath(filename) { if (!promise) { promise = (async () => { try { - await runOptimize(sourcePath, cachePath); + await runOptimize(rawSourcePath, cachePath); return cachePath; } finally { pending.delete(filename); diff --git a/frontend/scripts/optimize-glb.mjs b/frontend/scripts/optimize-glb.mjs index c646087..4d10518 100755 --- a/frontend/scripts/optimize-glb.mjs +++ b/frontend/scripts/optimize-glb.mjs @@ -13,18 +13,42 @@ 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 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'); function listSourceModels() { - return fs.readdirSync(charsDir) + return fs.readdirSync(sourceDir) .filter((file) => file.endsWith('.glb')) .filter((file) => !file.endsWith('_opt.glb')) .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'); +if (!fs.existsSync(sourceDir)) { + console.error(`Source directory not found: ${sourceDir}`); + process.exit(1); +} + +ensureOutputDir(); +removeStaleOptimizedModels(); + const models = listSourceModels(); if (models.length === 0) { console.log('No source GLBs found.'); @@ -32,9 +56,9 @@ if (models.length === 0) { } 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 output = path.join(charsDir, out); + const output = path.join(outputDir, out); try { 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}`);