feat(repair): broken parts spawn from exploded model node positions
🔍 Lint / 🪄 Check lint (push) Has been cancelled
🔍 Lint / 🎨 Check format (push) Has been cancelled
🔍 Lint / 🔎 Typecheck (push) Has been cancelled
📊 Quality / 🔒 Security Audit (push) Has been cancelled
📊 Quality / 📋 Dependency Freshness (push) Has been cancelled
📊 Quality / 📦 Bundle Size (push) Has been cancelled
🔍 Lint / 🏗 Build (push) Has been cancelled
🔍 Lint / 🪄 Check lint (push) Has been cancelled
🔍 Lint / 🎨 Check format (push) Has been cancelled
🔍 Lint / 🔎 Typecheck (push) Has been cancelled
📊 Quality / 🔒 Security Audit (push) Has been cancelled
📊 Quality / 📋 Dependency Freshness (push) Has been cancelled
📊 Quality / 📦 Bundle Size (push) Has been cancelled
🔍 Lint / 🏗 Build (push) Has been cancelled
Render the exploded mission model during the repairing step so broken nodes (e.g. ebike refroidisseur) stay visible in the world, and surface their world positions to RepairRepairingStep so broken pieces spawn from where they belong on the model rather than from a static offset. - ExplodableModel: add hideNodeNames (mesh visibility off, restored on unmount) and nodeAnchorNames + onNodeAnchorsChange (per-frame world positions debounced via signature so React state updates only when the values actually move). - RepairGame: render ExplodableModel during 'repairing' with the broken node names hidden + anchors forwarded; threads brokenAnchors state to RepairRepairingStep. - RepairScanSequence + RepairRepairingStep: propagate targetNodeName through scanned and fallback broken-part lists. - RepairRepairingStep: broken parts spawn at brokenAnchors[targetNodeName] when set, falling back to legacy BROKEN_PART_START_OFFSETS otherwise.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { Component, useEffect, useMemo } from "react";
|
||||
import { Component, useEffect, useMemo, useRef } from "react";
|
||||
import * as THREE from "three";
|
||||
import { useFrame } from "@react-three/fiber";
|
||||
import { useLoggedGLTF } from "@/hooks/three/useLoggedGLTF";
|
||||
import { useClonedObject } from "@/hooks/three/useClonedObject";
|
||||
@@ -9,6 +10,10 @@ import type { ModelTransformProps, Vector3Tuple } from "@/types/three/three";
|
||||
import { logModelLoadError } from "@/utils/three/modelLoadLogger";
|
||||
import { toVector3Scale } from "@/utils/three/scale";
|
||||
|
||||
export type ExplodedNodeAnchors = Readonly<Record<string, Vector3Tuple>>;
|
||||
|
||||
const _anchorWorld = new THREE.Vector3();
|
||||
|
||||
interface ModelErrorBoundaryProps {
|
||||
children: ReactNode;
|
||||
modelPath: string;
|
||||
@@ -67,6 +72,9 @@ interface ExplodableModelInnerProps extends ModelTransformProps {
|
||||
split: boolean;
|
||||
splitDistance?: number;
|
||||
onPartsReady?: (parts: readonly ExplodedPart[]) => void;
|
||||
hideNodeNames?: readonly string[];
|
||||
nodeAnchorNames?: readonly string[];
|
||||
onNodeAnchorsChange?: (anchors: ExplodedNodeAnchors) => void;
|
||||
}
|
||||
|
||||
export function ExplodableModel(
|
||||
@@ -93,6 +101,9 @@ function ExplodableModelInner({
|
||||
scale = 1,
|
||||
splitDistance = 1.2,
|
||||
onPartsReady,
|
||||
hideNodeNames,
|
||||
nodeAnchorNames,
|
||||
onNodeAnchorsChange,
|
||||
}: ExplodableModelInnerProps): React.JSX.Element {
|
||||
const { scene } = useLoggedGLTF(modelPath, {
|
||||
scope: "ExplodableModel",
|
||||
@@ -106,6 +117,24 @@ function ExplodableModelInner({
|
||||
[model, splitDistance],
|
||||
);
|
||||
const parsedScale = toVector3Scale(scale);
|
||||
const anchorSignatureRef = useRef("");
|
||||
|
||||
useEffect(() => {
|
||||
if (!hideNodeNames || hideNodeNames.length === 0) return;
|
||||
const hidden: THREE.Object3D[] = [];
|
||||
model.traverse((child) => {
|
||||
if (hideNodeNames.includes(child.name)) {
|
||||
hidden.push(child);
|
||||
child.visible = false;
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
hidden.forEach((object) => {
|
||||
object.visible = true;
|
||||
});
|
||||
};
|
||||
}, [hideNodeNames, model]);
|
||||
|
||||
useEffect(() => {
|
||||
explodedModel.setSplit(split);
|
||||
@@ -117,6 +146,35 @@ function ExplodableModelInner({
|
||||
|
||||
useFrame((_, delta) => {
|
||||
explodedModel.update(delta);
|
||||
|
||||
if (
|
||||
!onNodeAnchorsChange ||
|
||||
!nodeAnchorNames ||
|
||||
nodeAnchorNames.length === 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const anchors: Record<string, Vector3Tuple> = {};
|
||||
nodeAnchorNames.forEach((name) => {
|
||||
const node = model.getObjectByName(name);
|
||||
if (!node) return;
|
||||
node.getWorldPosition(_anchorWorld);
|
||||
anchors[name] = [_anchorWorld.x, _anchorWorld.y, _anchorWorld.z];
|
||||
});
|
||||
|
||||
const signature = nodeAnchorNames
|
||||
.map((name) => {
|
||||
const a = anchors[name];
|
||||
return a
|
||||
? `${name}:${a[0].toFixed(3)},${a[1].toFixed(3)},${a[2].toFixed(3)}`
|
||||
: `${name}:?`;
|
||||
})
|
||||
.join("|");
|
||||
|
||||
if (signature === anchorSignatureRef.current) return;
|
||||
anchorSignatureRef.current = signature;
|
||||
onNodeAnchorsChange(anchors);
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user