Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-21 20:48:59 +00:00
parent dfe44a6fd3
commit caea7f0f6f
+35
View File
@@ -0,0 +1,35 @@
import * as THREE from 'three';
/**
* Registry of the innermost local-frame group of each model in the scene.
* Measurements are stored in this local frame so they follow the model
* when the user repositions/rotates it via the "Posicionar" tool.
*/
const localGroups = new Map<string, THREE.Object3D>();
export function registerModelLocalGroup(modelId: string, obj: THREE.Object3D) {
localGroups.set(modelId, obj);
}
export function unregisterModelLocalGroup(modelId: string, obj?: THREE.Object3D) {
// Only delete if the registered object matches (avoid race between unmount/mount of the same id)
const current = localGroups.get(modelId);
if (!obj || current === obj) localGroups.delete(modelId);
}
export function getModelLocalGroup(modelId: string | null | undefined): THREE.Object3D | undefined {
if (!modelId) return undefined;
return localGroups.get(modelId);
}
export function worldToModelLocal(
modelId: string | null | undefined,
p: { x: number; y: number; z: number },
): { x: number; y: number; z: number } | null {
const g = getModelLocalGroup(modelId);
if (!g) return null;
g.updateWorldMatrix(true, false);
const v = new THREE.Vector3(p.x, p.y, p.z);
g.worldToLocal(v);
return { x: v.x, y: v.y, z: v.z };
}