Files
yourpart3/backend/routers/modelsProxyRouter.js
Torsten Schulz (local) 4379b0b955 Implement model optimization and caching for 3D characters
- Added a new modelsProxyRouter to handle requests for optimized 3D character models.
- Introduced modelsProxyService to manage GLB file optimization using gltf-transform with Draco compression.
- Updated app.js to include the new modelsProxyRouter for API access.
- Enhanced .gitignore to exclude model cache files.
- Added scripts for optimizing GLB models and updated README with optimization instructions.
- Integrated DRACOLoader in Character3D.vue for loading compressed models.
- Updated FamilyView.vue to streamline character rendering logic.
2026-01-22 13:24:47 +01:00

29 lines
934 B
JavaScript

import express from 'express';
import path from 'path';
import { getOptimizedModelPath } from '../services/modelsProxyService.js';
const router = express.Router();
/**
* GET /api/models/3d/falukant/characters/:filename
* Liefert die Draco-optimierte GLB-Datei (aus Cache oder nach Optimierung).
*/
router.get('/3d/falukant/characters/:filename', async (req, res) => {
const { filename } = req.params;
try {
const cachePath = await getOptimizedModelPath(filename);
res.setHeader('Content-Type', 'model/gltf-binary');
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
res.sendFile(cachePath);
} catch (e) {
if (e.message?.includes('Invalid model filename') || e.message?.includes('not found')) {
return res.status(404).send(e.message);
}
console.error('[models-proxy]', e.message);
res.status(500).send('Model optimization failed');
}
});
export default router;