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.
This commit is contained in:
28
backend/routers/modelsProxyRouter.js
Normal file
28
backend/routers/modelsProxyRouter.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user