fix5
This commit is contained in:
1 parent
36fe6cc7b3
commit
0bc9708829
3 files changed
+29
-13
No files matched your search
@@ -88,7 +88,8 @@ for (const [systemSlug, items] of bySystem) {
|
|||||||
.createNode(item.meshName)
|
.createNode(item.meshName)
|
||||||
.setMesh(mesh)
|
.setMesh(mesh)
|
||||||
.setTranslation(item.position)
|
.setTranslation(item.position)
|
||||||
.setRotation(eulerToQuat(item.rotation ?? [0, 0, 0]));
|
.setRotation(eulerToQuat(item.rotation ?? [0, 0, 0]))
|
||||||
|
.setExtras({ slug: item.slug });
|
||||||
|
|
||||||
scene.addChild(node);
|
scene.addChild(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,12 @@ for (const { fbx, key } of SOURCES) {
|
|||||||
const slugPart = slugify(uniqueMeshName) || `sem-nome-${totalStructures}`;
|
const slugPart = slugify(uniqueMeshName) || `sem-nome-${totalStructures}`;
|
||||||
const slug = `${systemSlug}-${slugPart}`;
|
const slug = `${systemSlug}-${slugPart}`;
|
||||||
|
|
||||||
|
// Gravamos o slug como "extras" do nó (→ vira object.userData no
|
||||||
|
// three.js) em vez de confiar só no "name": nós com mais de um
|
||||||
|
// material viram um Group + sub-Meshes com nomes gerados pelo
|
||||||
|
// GLTFLoader, diferentes do nome original — extras não sofre isso.
|
||||||
|
node.setExtras({ slug });
|
||||||
|
|
||||||
manifest.push({
|
manifest.push({
|
||||||
system: systemSlug,
|
system: systemSlug,
|
||||||
slug,
|
slug,
|
||||||
|
|||||||
@@ -29,12 +29,9 @@ export function SystemModel({
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const { scene } = useGLTF(modelUrl(modelFile));
|
const { scene } = useGLTF(modelUrl(modelFile));
|
||||||
const clonedRef = useRef<THREE.Group>();
|
const clonedRef = useRef<THREE.Group>();
|
||||||
// Nome original de CADA objeto (não só malhas) como veio do .glb,
|
// Nome original de cada objeto (fallback), capturado uma única vez no
|
||||||
// capturado uma única vez no clone. Precisamos disso porque quando um
|
// clone — usado apenas se o objeto não tiver o "slug" gravado em
|
||||||
// nó do glTF tem mais de um material, o GLTFLoader do three.js cria um
|
// userData (ver abaixo).
|
||||||
// Group com o nome do nó e sub-malhas (children) com nomes DIFERENTES
|
|
||||||
// (gerados pelo loader) — sem isso, a maioria das estruturas com mais
|
|
||||||
// de um material nunca batia com o manifesto e ficava sempre oculta.
|
|
||||||
const originalNames = useRef<WeakMap<THREE.Object3D, string>>(new WeakMap());
|
const originalNames = useRef<WeakMap<THREE.Object3D, string>>(new WeakMap());
|
||||||
|
|
||||||
if (!clonedRef.current) {
|
if (!clonedRef.current) {
|
||||||
@@ -50,20 +47,32 @@ export function SystemModel({
|
|||||||
}
|
}
|
||||||
const root = clonedRef.current!;
|
const root = clonedRef.current!;
|
||||||
|
|
||||||
const byMeshName = useMemo(
|
const bySlugInFile = useMemo(
|
||||||
|
() => new Map(structuresInFile.map((s) => [s.slug, s])),
|
||||||
|
[structuresInFile],
|
||||||
|
);
|
||||||
|
const byMeshNameInFile = useMemo(
|
||||||
() => new Map(structuresInFile.map((s) => [s.meshName, s])),
|
() => new Map(structuresInFile.map((s) => [s.meshName, s])),
|
||||||
[structuresInFile],
|
[structuresInFile],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sobe pelos pais até achar um nome (do próprio objeto ou de um
|
// Sobe pelos pais até achar uma correspondência. Preferimos o "slug"
|
||||||
// ancestral) que bata com alguma estrutura do manifesto.
|
// gravado em userData (extras do glTF) — sobrevive intacto por todo o
|
||||||
|
// pipeline (assimp, simplificação, GLTFLoader). O nome ("name") é usado
|
||||||
|
// só como fallback, pois um nó com mais de um material vira um Group
|
||||||
|
// (com o nome original) + sub-Meshes com nomes gerados pelo loader.
|
||||||
function resolveStructure(obj: THREE.Object3D): Structure | undefined {
|
function resolveStructure(obj: THREE.Object3D): Structure | undefined {
|
||||||
let node: THREE.Object3D | null = obj;
|
let node: THREE.Object3D | null = obj;
|
||||||
while (node) {
|
while (node) {
|
||||||
|
const slug = node.userData?.slug as string | undefined;
|
||||||
|
if (slug) {
|
||||||
|
const bySlug = bySlugInFile.get(slug);
|
||||||
|
if (bySlug) return bySlug;
|
||||||
|
}
|
||||||
const name = originalNames.current.get(node);
|
const name = originalNames.current.get(node);
|
||||||
if (name) {
|
if (name) {
|
||||||
const structure = byMeshName.get(name);
|
const byName = byMeshNameInFile.get(name);
|
||||||
if (structure) return structure;
|
if (byName) return byName;
|
||||||
}
|
}
|
||||||
node = node.parent;
|
node = node.parent;
|
||||||
}
|
}
|
||||||
@@ -92,7 +101,7 @@ export function SystemModel({
|
|||||||
mat.emissiveIntensity = isSelected ? 0.6 : 0;
|
mat.emissiveIntensity = isSelected ? 0.6 : 0;
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [root, byMeshName, visibleSystems, selectedSlug, clippingPlanes]);
|
}, [root, bySlugInFile, byMeshNameInFile, visibleSystems, selectedSlug, clippingPlanes]);
|
||||||
|
|
||||||
const handleClick = (e: ThreeEvent<MouseEvent>) => {
|
const handleClick = (e: ThreeEvent<MouseEvent>) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|||||||
Reference in new issue
Block a user