add: scan fragmented repair parts sequentially

This commit is contained in:
Tom Boullay
2026-05-08 02:12:58 +01:00
parent 95d9bd4f3e
commit 7a3baa4c0b
9 changed files with 96 additions and 29 deletions
+11 -15
View File
@@ -4,11 +4,8 @@ import { RepairCompletionStep } from "@/components/three/gameplay/RepairCompleti
import { RepairInspectionObject } from "@/components/three/gameplay/RepairInspectionObject";
import { RepairMissionCase } from "@/components/three/gameplay/RepairMissionCase";
import { RepairRepairingStep } from "@/components/three/gameplay/RepairRepairingStep";
import { RepairScanVisual } from "@/components/three/gameplay/RepairScanVisual";
import {
REPAIR_FRAGMENTATION_SEQUENCE_SECONDS,
REPAIR_SCAN_SEQUENCE_SECONDS,
} from "@/data/gameplay/repairGameConfig";
import { RepairScanSequence } from "@/components/three/gameplay/RepairScanSequence";
import { REPAIR_FRAGMENTATION_SEQUENCE_SECONDS } from "@/data/gameplay/repairGameConfig";
import { REPAIR_MISSIONS } from "@/data/gameplay/repairMissions";
import { useRepairFragmentationInput } from "@/hooks/gameplay/useRepairFragmentationInput";
import { useRepairMissionStep } from "@/hooks/gameplay/useRepairMissionStep";
@@ -47,17 +44,11 @@ export function RepairGame({
useEffect(() => {
if (mainState !== mission) return undefined;
if (step !== "fragmented" && step !== "scanning") return undefined;
const nextStep = step === "fragmented" ? "scanning" : "repairing";
const sequenceSeconds =
step === "fragmented"
? REPAIR_FRAGMENTATION_SEQUENCE_SECONDS
: REPAIR_SCAN_SEQUENCE_SECONDS;
if (step !== "fragmented") return undefined;
const timeoutId = window.setTimeout(() => {
setMissionStep(mission, nextStep);
}, sequenceSeconds * 1000);
setMissionStep(mission, "scanning");
}, REPAIR_FRAGMENTATION_SEQUENCE_SECONDS * 1000);
return () => {
window.clearTimeout(timeoutId);
@@ -79,7 +70,12 @@ export function RepairGame({
{step === "fragmented" ? (
<ExplodableModel modelPath={config.modelPath} split />
) : null}
{step === "scanning" ? <RepairScanVisual config={config} /> : null}
{step === "scanning" ? (
<RepairScanSequence
config={config}
onComplete={() => setMissionStep(mission, "repairing")}
/>
) : null}
{step === "repairing" ? (
<RepairRepairingStep
config={config}
@@ -0,0 +1,51 @@
import { useEffect, useState } from "react";
import { ExplodableModel } from "@/components/three/models/ExplodableModel";
import { RepairScanVisual } from "@/components/three/gameplay/RepairScanVisual";
import { REPAIR_SCAN_PART_SECONDS } from "@/data/gameplay/repairGameConfig";
import type { RepairMissionConfig } from "@/data/gameplay/repairMissions";
import type { ExplodedPart } from "@/utils/three/ExplodedModel";
interface RepairScanSequenceProps {
config: RepairMissionConfig;
onComplete: () => void;
}
export function RepairScanSequence({
config,
onComplete,
}: RepairScanSequenceProps): React.JSX.Element {
const [parts, setParts] = useState<readonly ExplodedPart[]>([]);
const [activePartIndex, setActivePartIndex] = useState(0);
const activePart = parts[activePartIndex];
useEffect(() => {
if (parts.length === 0) return undefined;
const timeoutId = window.setTimeout(() => {
setActivePartIndex((currentIndex) => {
const nextIndex = currentIndex + 1;
if (nextIndex >= parts.length) {
onComplete();
return currentIndex;
}
return nextIndex;
});
}, REPAIR_SCAN_PART_SECONDS * 1000);
return () => {
window.clearTimeout(timeoutId);
};
}, [activePartIndex, onComplete, parts.length]);
return (
<group>
<ExplodableModel
modelPath={config.modelPath}
split
onPartsReady={setParts}
/>
<RepairScanVisual target={activePart?.object} />
</group>
);
}
@@ -1,27 +1,36 @@
import { useRef } from "react";
import { useFrame } from "@react-three/fiber";
import * as THREE from "three";
import { RepairPromptVideo } from "@/components/three/gameplay/RepairPromptVideo";
import type { RepairMissionConfig } from "@/data/gameplay/repairMissions";
interface RepairScanVisualProps {
config: RepairMissionConfig;
target?: THREE.Object3D | null | undefined;
}
export function RepairScanVisual({
config,
target = null,
}: RepairScanVisualProps): React.JSX.Element {
const groupRef = useRef<THREE.Group>(null);
const scanLineRef = useRef<THREE.Mesh>(null);
const worldPosition = useRef(new THREE.Vector3());
const localPosition = useRef(new THREE.Vector3());
useFrame(({ clock }) => {
const group = groupRef.current;
const scanLine = scanLineRef.current;
if (!scanLine) return;
if (!group || !scanLine) return;
if (target) {
target.getWorldPosition(worldPosition.current);
localPosition.current.copy(worldPosition.current);
group.parent?.worldToLocal(localPosition.current);
group.position.copy(localPosition.current);
}
scanLine.position.y = 0.35 + Math.sin(clock.elapsedTime * 4) * 0.7;
});
return (
<group>
<group ref={groupRef}>
<mesh rotation={[Math.PI / 2, 0, 0]}>
<torusGeometry args={[1.35, 0.035, 12, 96]} />
<meshBasicMaterial color="#38bdf8" transparent opacity={0.75} />
@@ -39,7 +48,6 @@ export function RepairScanVisual({
<sphereGeometry args={[1.25, 32, 16]} />
<meshBasicMaterial color="#0ea5e9" transparent opacity={0.12} />
</mesh>
<RepairPromptVideo src={config.brokenUiPath} position={[0, 2.3, 0]} />
</group>
);
}
@@ -4,6 +4,7 @@ import { useFrame } from "@react-three/fiber";
import { useLoggedGLTF } from "@/hooks/three/useLoggedGLTF";
import { useClonedObject } from "@/hooks/three/useClonedObject";
import { ExplodedModel } from "@/utils/three/ExplodedModel";
import type { ExplodedPart } from "@/utils/three/ExplodedModel";
import type { ModelTransformProps, Vector3Tuple } from "@/types/three/three";
import { logModelLoadError } from "@/utils/three/modelLoadLogger";
import { toVector3Scale } from "@/utils/three/scale";
@@ -55,6 +56,7 @@ interface ExplodableModelInnerProps extends ModelTransformProps {
modelPath: string;
split: boolean;
splitDistance?: number;
onPartsReady?: (parts: readonly ExplodedPart[]) => void;
}
export function ExplodableModel(
@@ -78,6 +80,7 @@ function ExplodableModelInner({
rotation = [0, 0, 0],
scale = 1,
splitDistance = 1.2,
onPartsReady,
}: ExplodableModelInnerProps): React.JSX.Element {
const { scene } = useLoggedGLTF(modelPath, {
scope: "ExplodableModel",
@@ -96,6 +99,10 @@ function ExplodableModelInner({
explodedModel.setSplit(split);
}, [explodedModel, split]);
useEffect(() => {
onPartsReady?.(explodedModel.getParts());
}, [explodedModel, onPartsReady]);
useFrame((_, delta) => {
explodedModel.update(delta);
});
+1 -1
View File
@@ -442,7 +442,7 @@ Ce document liste les fonctionnalités présentes dans le code actuel.
- \`RepairGame\` de production réutilisable monté pour les états de mission \`bike\`, \`pylone\` et \`ferme\`
- Configuration de mission partagée via \`src/data/gameplay/repairMissions.ts\`
- Flow repair-game avec \`waiting -> inspected -> fragmented -> scanning -> repairing -> done -> next mission\`, prompts \`.webm\`, apparition/ouverture/sortie de la mallette, touche \`E\`, hold deux poings, transition de modèle explosé, visuels de scan, plusieurs choix de pièces grabbables, validation de la bonne pièce et complétion de mission
- Flow repair-game avec \`waiting -> inspected -> fragmented -> scanning -> repairing -> done -> next mission\`, prompts \`.webm\`, apparition/ouverture/sortie de la mallette, touche \`E\`, hold deux poings, transition de modèle explosé, scan visuel par pièce, plusieurs choix de pièces grabbables, validation de la bonne pièce et complétion de mission
## Audio
+1 -1
View File
@@ -1,3 +1,3 @@
export const REPAIR_FRAGMENTATION_FIST_HOLD_SECONDS = 1;
export const REPAIR_FRAGMENTATION_SEQUENCE_SECONDS = 4;
export const REPAIR_SCAN_SEQUENCE_SECONDS = 4;
export const REPAIR_SCAN_PART_SECONDS = 1.2;
+5 -1
View File
@@ -1,6 +1,6 @@
import * as THREE from "three";
interface ExplodedPart {
export interface ExplodedPart {
object: THREE.Object3D;
originalPosition: THREE.Vector3;
targetPosition: THREE.Vector3;
@@ -31,6 +31,10 @@ export class ExplodedModel {
this.targetProgress = split ? 1 : 0;
}
getParts(): readonly ExplodedPart[] {
return this.parts;
}
update(delta: number): void {
const diff = this.targetProgress - this.progress;
if (Math.abs(diff) < 0.001) {