Add male toddler character model in GLB format
All checks were successful
Deploy to production / deploy (push) Successful in 3m27s
All checks were successful
Deploy to production / deploy (push) Successful in 3m27s
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
21
frontend/models-src/3d/falukant/characters/README.md
Normal file
21
frontend/models-src/3d/falukant/characters/README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Falukant 3D Source Models
|
||||||
|
|
||||||
|
Dieses Verzeichnis enthaelt die unoptimierten Quellmodelle fuer Falukant.
|
||||||
|
|
||||||
|
Regeln:
|
||||||
|
- Hier liegen die bearbeitbaren `*.glb`-Originale.
|
||||||
|
- Dieses Verzeichnis wird nicht direkt vom Frontend ausgeliefert.
|
||||||
|
- Die Web-Versionen werden per `npm run optimize-models` nach
|
||||||
|
`frontend/public/models/3d/falukant/characters/` geschrieben.
|
||||||
|
|
||||||
|
Pipeline:
|
||||||
|
1. Quelldateien hier ablegen oder aktualisieren
|
||||||
|
2. `npm run optimize-models`
|
||||||
|
3. Danach Frontend-Build / Deploy
|
||||||
|
|
||||||
|
Namenskonvention:
|
||||||
|
- `male.glb`, `female.glb`
|
||||||
|
- `male_adult.glb`, `female_toddler.glb`, usw.
|
||||||
|
- exakte Altersvarianten wie `female_1y.glb`
|
||||||
|
|
||||||
|
Die ausgelieferten Dateien heissen immer `*_opt.glb`.
|
||||||
89
frontend/public/models/3d/falukant/characters/README.md
Executable file → Normal file
89
frontend/public/models/3d/falukant/characters/README.md
Executable file → Normal file
@@ -1,87 +1,16 @@
|
|||||||
# 3D-Charakter-Modelle
|
# Falukant 3D Web Models
|
||||||
|
|
||||||
## Verzeichnisstruktur
|
Dieses Verzeichnis enthaelt nur die ausgelieferten, optimierten Web-Modelle.
|
||||||
|
|
||||||
Dieses Verzeichnis enthält die 3D-Modelle für Falukant-Charaktere.
|
- Dateien in diesem Ordner werden vom Frontend und vom Backend-Proxy ausgeliefert.
|
||||||
|
- Sie werden aus `frontend/models-src/3d/falukant/characters/` erzeugt.
|
||||||
|
- Quelldateien gehoeren nicht hierher.
|
||||||
|
|
||||||
## Dateinamen-Konvention
|
Erzeugung:
|
||||||
|
|
||||||
### Basis-Modelle (Fallback)
|
|
||||||
- `male.glb` - Basis-Modell männlich
|
|
||||||
- `female.glb` - Basis-Modell weiblich
|
|
||||||
|
|
||||||
### Altersspezifische Modelle
|
|
||||||
|
|
||||||
#### Altersbereich-Modelle (Fallback für Altersgruppen)
|
|
||||||
- `male_toddler.glb` - Männlich, Kleinkind (0-3 Jahre)
|
|
||||||
- `male_child.glb` - Männlich, Kind (4-7 Jahre)
|
|
||||||
- `male_preteen.glb` - Männlich, Vor-Teenager (8-12 Jahre)
|
|
||||||
- `male_teen.glb` - Männlich, Teenager (13-17 Jahre)
|
|
||||||
- `male_adult.glb` - Männlich, Erwachsen (18+ Jahre)
|
|
||||||
- `female_toddler.glb` - Weiblich, Kleinkind (0-3 Jahre)
|
|
||||||
- `female_child.glb` - Weiblich, Kind (4-7 Jahre)
|
|
||||||
- `female_preteen.glb` - Weiblich, Vor-Teenager (8-12 Jahre)
|
|
||||||
- `female_teen.glb` - Weiblich, Teenager (13-17 Jahre)
|
|
||||||
- `female_adult.glb` - Weiblich, Erwachsen (18+ Jahre)
|
|
||||||
|
|
||||||
#### Genaue Alters-Modelle (optional, für spezifische Altersstufen)
|
|
||||||
- `male_1y.glb`, `male_2y.glb`, `male_3y.glb`, etc. - Männlich, genaues Alter in Jahren
|
|
||||||
- `female_1y.glb`, `female_2y.glb`, `female_5y.glb`, etc. - Weiblich, genaues Alter in Jahren
|
|
||||||
|
|
||||||
**Hinweis:** Genaue Alters-Modelle haben Vorrang vor Altersbereich-Modellen. Wenn z.B. für Alter 1 sowohl `female_1y.glb` als auch `female_toddler.glb` existieren, wird `female_1y.glb` verwendet.
|
|
||||||
|
|
||||||
## Fallback-Verhalten
|
|
||||||
|
|
||||||
Die Komponente verwendet eine dreistufige Fallback-Hierarchie:
|
|
||||||
|
|
||||||
1. **Genaues Alter:** Zuerst wird nach einem Modell für das genaue Alter gesucht (z.B. `female_1y.glb` für Alter 1)
|
|
||||||
2. **Altersbereich:** Falls kein genaues Alters-Modell existiert, wird das Altersbereich-Modell verwendet (z.B. `female_toddler.glb` für Alter 1-3)
|
|
||||||
3. **Basis-Modell:** Falls auch kein Altersbereich-Modell existiert, wird das Basis-Modell verwendet (`male.glb` / `female.glb`)
|
|
||||||
|
|
||||||
## Dateigröße
|
|
||||||
|
|
||||||
- **Aktuell:** ~14–17 MB pro Modell → lange Ladezeiten
|
|
||||||
- **Empfohlen:** < 500 KB pro Modell
|
|
||||||
- **Maximal:** ~1–2 MB pro Modell (Web, 60 FPS)
|
|
||||||
|
|
||||||
## Optimierung (wichtig für kürzere Ladezeiten)
|
|
||||||
|
|
||||||
### Option A: gltf-transform (CLI, Draco + Textur-Optimierung)
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install -g @gltf-transform/cli
|
cd frontend
|
||||||
# Pro Modell (Beispiel):
|
npm run optimize-models
|
||||||
gltf-transform optimize male_adult.glb male_adult_opt.glb --compress draco --texture-size 1024
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Danach optimierte Dateien z. B. als `*_opt.glb` ablegen und im Frontend verwenden.
|
Das Frontend laedt nur `*_opt.glb`.
|
||||||
**Hinweis:** Bei Draco-Compression muss im Frontend `DRACOLoader` von Three.js genutzt werden (siehe Three.js-Doku zu `KHR_draco_mesh_compression`).
|
|
||||||
|
|
||||||
### Option B: Blender
|
|
||||||
|
|
||||||
1. Modell in Blender öffnen
|
|
||||||
2. Decimate-Modifier anwenden (Polygonanzahl reduzieren)
|
|
||||||
3. Texturen komprimieren (WebP, max. 1024×1024)
|
|
||||||
4. GLB-Export mit aktivierter Kompression
|
|
||||||
5. Optional: Online-Tools (z. B. [glb.babylonpress.org](https://glb.babylonpress.org)) für Draco-Kompression
|
|
||||||
|
|
||||||
### Option C: Nur Texturen verkleinern (ohne Draco)
|
|
||||||
|
|
||||||
Ohne Draco-Extension reicht oft schon:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
gltf-transform optimize input.glb output.glb --texture-size 1024
|
|
||||||
```
|
|
||||||
|
|
||||||
## Model-Proxy (Backend)
|
|
||||||
|
|
||||||
Das Frontend lädt Modelle über **`GET /api/models/3d/falukant/characters/:filename`**. Ein Backend-Proxy:
|
|
||||||
|
|
||||||
1. Liest die angeforderte `.glb`-Datei aus diesem Verzeichnis.
|
|
||||||
2. Optimiert sie bei Bedarf mit gltf-transform (Draco + Textur 1024).
|
|
||||||
3. Legt das Ergebnis in `backend/data/model-cache/` ab (File-Cache).
|
|
||||||
4. Liefert die optimierte Datei aus und setzt `Cache-Control` für Browser-Caching.
|
|
||||||
|
|
||||||
- **Service:** `backend/services/modelsProxyService.js`
|
|
||||||
- **Router:** `backend/routers/modelsProxyRouter.js`
|
|
||||||
- **Cache:** `backend/data/model-cache/` (wird bei neuerer Quelldatei automatisch neu erzeugt)
|
|
||||||
|
|||||||
BIN
frontend/public/models/3d/falukant/characters/female_1y_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/female_1y_opt.glb
Normal file
Binary file not shown.
BIN
frontend/public/models/3d/falukant/characters/female_2y_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/female_2y_opt.glb
Normal file
Binary file not shown.
BIN
frontend/public/models/3d/falukant/characters/female_5y_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/female_5y_opt.glb
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
frontend/public/models/3d/falukant/characters/female_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/female_opt.glb
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
frontend/public/models/3d/falukant/characters/male_adult_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/male_adult_opt.glb
Normal file
Binary file not shown.
0
frontend/public/models/3d/falukant/characters/male_child_opt.glb
Executable file → Normal file
0
frontend/public/models/3d/falukant/characters/male_child_opt.glb
Executable file → Normal file
BIN
frontend/public/models/3d/falukant/characters/male_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/male_opt.glb
Normal file
Binary file not shown.
Binary file not shown.
BIN
frontend/public/models/3d/falukant/characters/male_teen_opt.glb
Normal file
BIN
frontend/public/models/3d/falukant/characters/male_teen_opt.glb
Normal file
Binary file not shown.
Binary file not shown.
@@ -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}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user