feat(web): add full setup view rendering the whole save

Add a /mod/:id/setup page that lays out every renderable object in a single shared scene. Export object-facing mesh wrappers from the viewers and share geometry and materials across objects via module-level caches.
This commit is contained in:
2026-08-08 18:28:03 +08:00
parent 12418898d0
commit e88dd03fac
9 changed files with 469 additions and 98 deletions
@@ -0,0 +1,42 @@
import * as THREE from 'three';
/**
* Module-level caches so the full-setup view can share geometry and materials
* across many objects instead of rebuilding them per object. Keyed by a
* canonical string describing the resource, so identical objects reuse one
* instance. drei already caches textures globally by URL, so sharing the
* material on top avoids per-object material allocation for tiles/tokens with
* the same image.
*
* These caches live for the session (like drei's global texture cache) and are
* not disposed on unmount; see `docs/full-setup-view.md`.
*/
const geometryCache = new Map<string, THREE.BufferGeometry>();
const materialCache = new Map<string, THREE.MeshStandardMaterial>();
/** Get or create a geometry for `key`. */
export function getSharedGeometry(
key: string,
build: () => THREE.BufferGeometry,
): THREE.BufferGeometry {
let geo = geometryCache.get(key);
if (!geo) {
geo = build();
geometryCache.set(key, geo);
}
return geo;
}
/** Get or create a standard material for `key`. */
export function getSharedMaterial(
key: string,
params: THREE.MeshStandardMaterialParameters,
): THREE.MeshStandardMaterial {
let mat = materialCache.get(key);
if (!mat) {
mat = new THREE.MeshStandardMaterial(params);
materialCache.set(key, mat);
}
return mat;
}