feat: stage 2 real CAD conveyor, hybrid physics drops, mobile policy (WIP)
- CAD pipeline: conveer.FCStd -> FreeCAD headless -> conveyor-web.glb (555KB Draco, 42 named nodes) integrated into main scene; gates and rollers animated from domain state - Domain-driven adapter sorterVisualState.ts; per-SKU visual physics profiles (VISUAL_PHYSICS_ESTIMATE) - Hybrid Rapier physics: kinematic belt travel -> dynamic drop handoff -> verified freeze; shared collider layout (physicsWorldLayout) used by runtime and headless validation sim (physicsDropSim + 13 tests) - Gravity chutes / open roll-cage front redesign (drop tuning in progress: 4/7 routes verified headless) - Premium industrial visual: PBR, ACES, PCFSoft shadows, Lightformer env, UI cleanup behind ?debug=1 - Mobile capability policy: SVG fallback / Mobile Low / full tiers, Telegram WebView forced to SVG, e2e stubs for weak devices - Performance benchmarks cad-light/physics/full pass; stage2 artifacts tsc clean. Physics drop validation for 3 SKU routes still in progress. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
148
src/components/ThreeD/ConveyorCadModel.tsx
Normal file
148
src/components/ThreeD/ConveyorCadModel.tsx
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Stage 2 — CAD-derived conveyor (runtime GLB from 3d_models/conveer.FCStd).
|
||||
*
|
||||
* Asset: public/models/sorter/conveyor-web.glb (159k tris, 555 KB, Draco).
|
||||
* Node statuses: REAL_CAD (all groups; see docs/stage2_real_sorter/mechanism-map.md).
|
||||
* Animation (domain-synced via refs/useFrame, no per-frame React state):
|
||||
* - stop-gate/* barriers: vertical lift stroke 80 mm, eased ~300 ms
|
||||
* - rollers/Ролик*, rollers/Вал: spin ω = beltVelocity / 0.025 m
|
||||
* GLB vertices are baked in module coordinates — animated meshes are re-pivoted
|
||||
* around their own bbox center at load time.
|
||||
*/
|
||||
import { useEffect, useMemo, useRef } from 'react';
|
||||
import * as THREE from 'three';
|
||||
import { useFrame, useLoader } from '@react-three/fiber';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
||||
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
||||
|
||||
export const CONVEYOR_CAD_URL = '/models/sorter/conveyor-web.glb';
|
||||
|
||||
/** World placement: CAD camera arch lands on the domain inspection point. */
|
||||
export const CONVEYOR_CAD_POSITION: [number, number, number] = [-2.02, 0.594, 0];
|
||||
/** CAD module world span after placement (m). */
|
||||
export const CONVEYOR_CAD_SPAN_X: [number, number] = [-2.086, -0.076];
|
||||
|
||||
const GATE_STROKE_M = 0.08;
|
||||
const GATE_SPEED_PER_SEC = 1 / 0.3;
|
||||
|
||||
const MATERIALS: Record<string, THREE.MeshStandardMaterial> = {};
|
||||
function materialFor(slot: string): THREE.MeshStandardMaterial {
|
||||
if (!MATERIALS[slot]) {
|
||||
const defs: Record<string, { color: string; metalness: number; roughness: number }> = {
|
||||
'painted-metal': { color: '#8b9cae', metalness: 0.55, roughness: 0.45 },
|
||||
'brushed-metal': { color: '#b9c2cc', metalness: 0.9, roughness: 0.3 },
|
||||
'rubber-belt': { color: '#39424a', metalness: 0.0, roughness: 0.92 },
|
||||
'dark-mechanical': { color: '#3a4148', metalness: 0.6, roughness: 0.5 },
|
||||
'safety-yellow': { color: '#f5b301', metalness: 0.2, roughness: 0.55 },
|
||||
};
|
||||
MATERIALS[slot] = new THREE.MeshStandardMaterial(defs[slot] ?? defs['painted-metal']);
|
||||
}
|
||||
return MATERIALS[slot];
|
||||
}
|
||||
|
||||
function slotFor(nodeName: string): string {
|
||||
const grp = nodeName.split('/')[0];
|
||||
switch (grp) {
|
||||
case 'conveyor-belt': return 'rubber-belt';
|
||||
case 'rollers': return 'brushed-metal';
|
||||
case 'motor-and-drive': return 'dark-mechanical';
|
||||
case 'stop-gate': return 'safety-yellow';
|
||||
case 'pusher-servo': return 'dark-mechanical';
|
||||
case 'inspection-frame': return 'painted-metal';
|
||||
default: return 'painted-metal';
|
||||
}
|
||||
}
|
||||
|
||||
/** Re-pivot a world-baked mesh around its own bbox center; returns the pivot group. */
|
||||
function repivot(mesh: THREE.Mesh): THREE.Group {
|
||||
const parent = mesh.parent;
|
||||
const bbox = new THREE.Box3().setFromObject(mesh);
|
||||
const center = bbox.getCenter(new THREE.Vector3());
|
||||
const pivot = new THREE.Group();
|
||||
pivot.name = `pivot/${mesh.name}`;
|
||||
pivot.position.copy(center);
|
||||
pivot.userData.baseY = center.y;
|
||||
mesh.position.sub(center);
|
||||
pivot.add(mesh);
|
||||
parent?.add(pivot);
|
||||
return pivot;
|
||||
}
|
||||
|
||||
export function ConveyorCadModel({
|
||||
gateOpen,
|
||||
beltVelocityMps,
|
||||
rollerOmegaRadPerSec,
|
||||
shadows = false,
|
||||
}: {
|
||||
gateOpen: boolean;
|
||||
beltVelocityMps: number;
|
||||
rollerOmegaRadPerSec: number;
|
||||
shadows?: boolean;
|
||||
}) {
|
||||
const gltf = useLoader(GLTFLoader, CONVEYOR_CAD_URL, (loader) => {
|
||||
const draco = new DRACOLoader();
|
||||
draco.setDecoderPath('/draco/');
|
||||
loader.setDRACOLoader(draco);
|
||||
});
|
||||
|
||||
const gatePivots = useRef<THREE.Group[]>([]);
|
||||
const rollerPivots = useRef<THREE.Group[]>([]);
|
||||
const gateOpenAmount = useRef(0);
|
||||
const rollerAngle = useRef(0);
|
||||
|
||||
const root = useMemo(() => {
|
||||
gatePivots.current = [];
|
||||
rollerPivots.current = [];
|
||||
const scene = gltf.scene.clone(true);
|
||||
const toPivot: THREE.Mesh[] = [];
|
||||
scene.traverse((obj) => {
|
||||
const mesh = obj as THREE.Mesh;
|
||||
if (!mesh.isMesh) return;
|
||||
const name = mesh.name || mesh.parent?.name || '';
|
||||
mesh.material = materialFor(slotFor(name));
|
||||
mesh.castShadow = shadows;
|
||||
mesh.receiveShadow = shadows;
|
||||
if (name.startsWith('stop-gate/') || name.startsWith('rollers/Ролик') || name.startsWith('rollers/Вал')) {
|
||||
toPivot.push(mesh);
|
||||
}
|
||||
});
|
||||
for (const mesh of toPivot) {
|
||||
const pivot = repivot(mesh);
|
||||
if (mesh.name.startsWith('stop-gate/')) gatePivots.current.push(pivot);
|
||||
else rollerPivots.current.push(pivot);
|
||||
}
|
||||
return scene;
|
||||
}, [gltf, shadows]);
|
||||
|
||||
useEffect(() => () => {
|
||||
// Materials are module-cached; geometry belongs to the shared GLTF cache.
|
||||
}, []);
|
||||
|
||||
useFrame((_, rawDelta) => {
|
||||
const delta = Math.min(rawDelta, 0.05);
|
||||
// Stop-gate barriers: eased lift (extend/hold/retract), no teleport.
|
||||
const target = gateOpen ? 1 : 0;
|
||||
const cur = gateOpenAmount.current;
|
||||
const next = cur + Math.sign(target - cur) * Math.min(Math.abs(target - cur), GATE_SPEED_PER_SEC * delta);
|
||||
gateOpenAmount.current = next;
|
||||
const eased = next < 0.5 ? 2 * next * next : 1 - Math.pow(-2 * next + 2, 2) / 2;
|
||||
for (const pivot of gatePivots.current) {
|
||||
pivot.position.y = (pivot.userData.baseY as number) + GATE_STROKE_M * eased;
|
||||
}
|
||||
// Rollers: ω = v / r, angle integrated in a ref (belt velocity already 0 on halt).
|
||||
rollerAngle.current += rollerOmegaRadPerSec * delta;
|
||||
for (const pivot of rollerPivots.current) {
|
||||
pivot.rotation.z = rollerAngle.current;
|
||||
}
|
||||
});
|
||||
|
||||
return <primitive object={root} position={CONVEYOR_CAD_POSITION} />;
|
||||
}
|
||||
|
||||
export function preloadConveyorCad() {
|
||||
useLoader.preload(GLTFLoader, CONVEYOR_CAD_URL, (loader) => {
|
||||
const draco = new DRACOLoader();
|
||||
draco.setDecoderPath('/draco/');
|
||||
loader.setDRACOLoader(draco);
|
||||
});
|
||||
}
|
||||
@@ -58,20 +58,20 @@ function FallbackPrimitive({ type, color, accentColor, emissiveIntensity, roughn
|
||||
);
|
||||
}
|
||||
|
||||
export const PhysicalPlaybackItem = memo(function PhysicalPlaybackItem({
|
||||
/** Inner visual content of an item (shared by kinematic and physics drivers). */
|
||||
export function ItemVisualContent({
|
||||
caseData,
|
||||
elapsedMs,
|
||||
slotIndex = 0,
|
||||
jitter,
|
||||
phase,
|
||||
surface,
|
||||
isSettled,
|
||||
castShadow = false,
|
||||
verifySku = null,
|
||||
}: {
|
||||
caseData: PlaylistCase;
|
||||
elapsedMs: number;
|
||||
slotIndex?: number;
|
||||
jitter?: { x: number; z: number; yaw: number };
|
||||
phase: string;
|
||||
surface: string;
|
||||
isSettled: boolean;
|
||||
castShadow?: boolean;
|
||||
/** Stage 1 verification: SKU to overlay (null = off, 'follow' handled by caller passing current SKU). */
|
||||
verifySku?: string | null;
|
||||
}) {
|
||||
const itemData = useMemo(() => resolveItem(caseData.itemId), [caseData.itemId]);
|
||||
@@ -80,25 +80,12 @@ export const PhysicalPlaybackItem = memo(function PhysicalPlaybackItem({
|
||||
const asset = getModelAsset(itemId);
|
||||
const dims = getRenderedItemDimensions(itemData.dimensionsMm);
|
||||
|
||||
const pose = getPhysicalItemPose({
|
||||
caseId: caseData.id,
|
||||
slotIndex,
|
||||
dimensionsMm: itemData.dimensionsMm,
|
||||
targetCategory: classification.category,
|
||||
elapsedMs,
|
||||
faultType: caseData.faultType,
|
||||
jitter,
|
||||
});
|
||||
|
||||
const { position, rotation, phase, surface, isSettled } = pose;
|
||||
const isRouting = phase === 'routing';
|
||||
const onTransport = surface === 'main_belt'
|
||||
|| surface === 'inspection_station'
|
||||
|| surface === 'routing_junction'
|
||||
|| surface === 'b_transfer';
|
||||
|
||||
if (elapsedMs < 0) return null;
|
||||
|
||||
const routeAccent = COLORS[classification.category] ?? COLORS.sensorAccent;
|
||||
const material = ITEM_MATERIALS[itemId] ?? { color: '#d8c3a5', roughness: 0.75 };
|
||||
const bodyColor = phase === 'fault' ? '#ef4444' : material.color;
|
||||
@@ -137,7 +124,7 @@ export const PhysicalPlaybackItem = memo(function PhysicalPlaybackItem({
|
||||
const verifying = verifySku != null && verifySku === itemId && asset != null;
|
||||
|
||||
return (
|
||||
<group position={position} rotation={rotation}>
|
||||
<>
|
||||
{useReal && asset ? (
|
||||
<group position={[0, pivotOffsetY, 0]}>
|
||||
<RealItemModel
|
||||
@@ -179,6 +166,53 @@ export const PhysicalPlaybackItem = memo(function PhysicalPlaybackItem({
|
||||
<meshStandardMaterial color="#475569" transparent opacity={0.15} />
|
||||
</mesh>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const PhysicalPlaybackItem = memo(function PhysicalPlaybackItem({
|
||||
caseData,
|
||||
elapsedMs,
|
||||
slotIndex = 0,
|
||||
jitter,
|
||||
castShadow = false,
|
||||
verifySku = null,
|
||||
}: {
|
||||
caseData: PlaylistCase;
|
||||
elapsedMs: number;
|
||||
slotIndex?: number;
|
||||
jitter?: { x: number; z: number; yaw: number };
|
||||
castShadow?: boolean;
|
||||
/** Stage 1 verification: SKU to overlay (null = off, 'follow' handled by caller passing current SKU). */
|
||||
verifySku?: string | null;
|
||||
}) {
|
||||
const itemData = useMemo(() => resolveItem(caseData.itemId), [caseData.itemId]);
|
||||
const classification = useMemo(() => classifyItem(itemData), [itemData]);
|
||||
|
||||
const pose = getPhysicalItemPose({
|
||||
caseId: caseData.id,
|
||||
slotIndex,
|
||||
dimensionsMm: itemData.dimensionsMm,
|
||||
targetCategory: classification.category,
|
||||
elapsedMs,
|
||||
faultType: caseData.faultType,
|
||||
jitter,
|
||||
});
|
||||
|
||||
const { position, rotation, phase, surface, isSettled } = pose;
|
||||
|
||||
if (elapsedMs < 0) return null;
|
||||
|
||||
return (
|
||||
<group position={position} rotation={rotation}>
|
||||
<ItemVisualContent
|
||||
caseData={caseData}
|
||||
phase={phase}
|
||||
surface={surface}
|
||||
isSettled={isSettled}
|
||||
castShadow={castShadow}
|
||||
verifySku={verifySku}
|
||||
/>
|
||||
</group>
|
||||
);
|
||||
});
|
||||
|
||||
218
src/components/ThreeD/PhysicalPlaybackItemPhysics.tsx
Normal file
218
src/components/ThreeD/PhysicalPlaybackItemPhysics.tsx
Normal file
@@ -0,0 +1,218 @@
|
||||
/**
|
||||
* Stage 2 — item with hybrid kinematic/dynamic authority (Rapier).
|
||||
*
|
||||
* Authority flow (see docs/stage2_real_sorter/physics-architecture.md):
|
||||
* 1. kinematicPosition — follows getPhysicalItemPose exactly (domain truth);
|
||||
* 2. at getDropHandoffTimeMs → dynamic with deterministic initial velocity
|
||||
* (B: belt edge carry-over; C/D: pusher impulse, scaled per SKU profile);
|
||||
* 3. gravity/collision/friction/restitution/angular velocity govern the drop;
|
||||
* 4. on sleep (or controlled 4.5 s timeout) the final position is verified
|
||||
* against the DOMAIN-decided receiver volume and the body is frozen
|
||||
* (kinematic) — no drift, clean replay, no teleportation at any point.
|
||||
*/
|
||||
import { memo, useEffect, useMemo, useRef } from 'react';
|
||||
import * as THREE from 'three';
|
||||
import { useFrame } from '@react-three/fiber';
|
||||
import {
|
||||
RigidBody,
|
||||
CuboidCollider,
|
||||
CapsuleCollider,
|
||||
CylinderCollider,
|
||||
type RapierRigidBody,
|
||||
} from '@react-three/rapier';
|
||||
import { RigidBodyType } from '@dimforge/rapier3d-compat';
|
||||
import { getPhysicalItemPose, getDropHandoffTimeMs } from '../../domain/physicalItemMotion';
|
||||
import { getVisualPhysicsProfile } from '../../domain/visualPhysicsProfiles';
|
||||
import { resolveItem } from '../../data/resolveItem';
|
||||
import { classifyItem } from '../../domain/classifier';
|
||||
import { receiverContains } from '../../domain/receiverVolumes';
|
||||
import type { PlaylistCase } from '../../domain/demoPlaylist';
|
||||
import { ItemVisualContent } from './PhysicalPlaybackItem';
|
||||
import { recordDropResult } from './SorterPhysics';
|
||||
|
||||
type Authority = 'kinematic' | 'dynamic' | 'frozen';
|
||||
|
||||
/** Controlled settle budget after handoff (ms of case time). */
|
||||
const SETTLE_BUDGET_MS = 4500;
|
||||
|
||||
function colliderDensity(profile: ReturnType<typeof getVisualPhysicsProfile>): number {
|
||||
if (profile.collider === 'cuboid' && profile.cuboidHalfExtents) {
|
||||
const [hx, hy, hz] = profile.cuboidHalfExtents;
|
||||
return profile.approximateMassKg / (8 * hx * hy * hz);
|
||||
}
|
||||
const [r, hh] = profile.capsule ?? [0.05, 0.1];
|
||||
const volume = profile.collider === 'capsule'
|
||||
? Math.PI * r * r * (2 * hh + (4 / 3) * r)
|
||||
: Math.PI * r * r * 2 * hh;
|
||||
return profile.approximateMassKg / volume;
|
||||
}
|
||||
|
||||
export const PhysicalPlaybackItemPhysics = memo(function PhysicalPlaybackItemPhysics({
|
||||
caseData,
|
||||
elapsedMs,
|
||||
slotIndex = 0,
|
||||
jitter,
|
||||
castShadow = false,
|
||||
verifySku = null,
|
||||
}: {
|
||||
caseData: PlaylistCase;
|
||||
elapsedMs: number;
|
||||
slotIndex?: number;
|
||||
jitter?: { x: number; z: number; yaw: number };
|
||||
castShadow?: boolean;
|
||||
verifySku?: string | null;
|
||||
}) {
|
||||
const itemData = useMemo(() => resolveItem(caseData.itemId), [caseData.itemId]);
|
||||
const classification = useMemo(() => classifyItem(itemData), [itemData]);
|
||||
const category = classification.category as 'B' | 'C' | 'D';
|
||||
const itemId = itemData.id.replace('-LC', '');
|
||||
const profile = getVisualPhysicsProfile(itemId);
|
||||
const handoffMs = getDropHandoffTimeMs(classification.category, caseData.faultType);
|
||||
|
||||
const bodyRef = useRef<RapierRigidBody>(null);
|
||||
const authority = useRef<Authority>('kinematic');
|
||||
const frozenPose = useRef<{ p: [number, number, number]; q: THREE.Quaternion } | null>(null);
|
||||
const handedOffAtMs = useRef<number | null>(null);
|
||||
const verified = useRef(false);
|
||||
|
||||
const pose = getPhysicalItemPose({
|
||||
caseId: caseData.id,
|
||||
slotIndex,
|
||||
dimensionsMm: itemData.dimensionsMm,
|
||||
targetCategory: classification.category,
|
||||
elapsedMs,
|
||||
faultType: caseData.faultType,
|
||||
jitter,
|
||||
});
|
||||
|
||||
const handoffPose = useMemo(() => {
|
||||
if (handoffMs == null) return null;
|
||||
return getPhysicalItemPose({
|
||||
caseId: caseData.id,
|
||||
slotIndex,
|
||||
dimensionsMm: itemData.dimensionsMm,
|
||||
targetCategory: classification.category,
|
||||
elapsedMs: handoffMs,
|
||||
faultType: caseData.faultType,
|
||||
jitter,
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [handoffMs, caseData.id]);
|
||||
|
||||
// Reset authority whenever a new case mounts this body.
|
||||
useEffect(() => {
|
||||
authority.current = 'kinematic';
|
||||
frozenPose.current = null;
|
||||
handedOffAtMs.current = null;
|
||||
verified.current = false;
|
||||
}, [caseData.id]);
|
||||
|
||||
useFrame(() => {
|
||||
const body = bodyRef.current;
|
||||
if (!body) return;
|
||||
|
||||
if (authority.current === 'kinematic') {
|
||||
// Kinematic drive: domain pose is truth (belt travel, inspection dwell).
|
||||
const p = pose.position;
|
||||
const e = new THREE.Euler(pose.rotation[0], pose.rotation[1], pose.rotation[2]);
|
||||
const q = new THREE.Quaternion().setFromEuler(e);
|
||||
body.setNextKinematicTranslation({ x: p[0], y: p[1], z: p[2] });
|
||||
body.setNextKinematicRotation({ x: q.x, y: q.y, z: q.z, w: q.w });
|
||||
|
||||
// Physics handoff at pusher contact / belt edge — never for fault cases.
|
||||
if (handoffMs != null && handoffPose && elapsedMs >= handoffMs) {
|
||||
const hp = handoffPose.position;
|
||||
body.setTranslation({ x: hp[0], y: hp[1], z: hp[2] }, true);
|
||||
const he = new THREE.Euler(handoffPose.rotation[0], handoffPose.rotation[1], handoffPose.rotation[2]);
|
||||
const hq = new THREE.Quaternion().setFromEuler(he);
|
||||
body.setRotation({ x: hq.x, y: hq.y, z: hq.z, w: hq.w }, true);
|
||||
body.setBodyType(RigidBodyType.Dynamic, true);
|
||||
// Deterministic initial velocity: belt carry-over + pusher impulse.
|
||||
const dirZ = category === 'D' ? -1 : 1;
|
||||
const v = category === 'B'
|
||||
? { x: 1.0, y: 0, z: 0 }
|
||||
: { x: 0.55, y: 0, z: dirZ * 1.35 * profile.pusherImpulseScale };
|
||||
body.setLinvel(v, true);
|
||||
if (profile.canRoll) {
|
||||
body.setAngvel({ x: category === 'B' ? 2.0 : 0.8, y: 0.4, z: 0 }, true);
|
||||
} else {
|
||||
body.setAngvel({ x: 0, y: 0.25, z: 0 }, true);
|
||||
}
|
||||
authority.current = 'dynamic';
|
||||
handedOffAtMs.current = elapsedMs;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (authority.current === 'dynamic') {
|
||||
const slept = body.isSleeping();
|
||||
const timedOut = handedOffAtMs.current != null && elapsedMs - handedOffAtMs.current > SETTLE_BUDGET_MS;
|
||||
if ((slept || timedOut) && !verified.current) {
|
||||
verified.current = true;
|
||||
const t = body.translation();
|
||||
const p: [number, number, number] = [t.x, t.y, t.z];
|
||||
recordDropResult({
|
||||
caseId: caseData.id,
|
||||
itemId,
|
||||
expectedZone: category,
|
||||
finalPosition: p,
|
||||
insideExpectedReceiver: receiverContains(category, p),
|
||||
settledByTimeout: !slept,
|
||||
timestampMs: Date.now(),
|
||||
});
|
||||
const r = body.rotation();
|
||||
frozenPose.current = { p, q: new THREE.Quaternion(r.x, r.y, r.z, r.w) };
|
||||
body.setBodyType(RigidBodyType.KinematicPositionBased, false);
|
||||
body.setLinvel({ x: 0, y: 0, z: 0 }, false);
|
||||
body.setAngvel({ x: 0, y: 0, z: 0 }, false);
|
||||
authority.current = 'frozen';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// frozen: hold the verified rest pose (no drift across replays).
|
||||
if (frozenPose.current) {
|
||||
const { p, q } = frozenPose.current;
|
||||
body.setNextKinematicTranslation({ x: p[0], y: p[1], z: p[2] });
|
||||
body.setNextKinematicRotation({ x: q.x, y: q.y, z: q.z, w: q.w });
|
||||
}
|
||||
});
|
||||
|
||||
if (elapsedMs < 0) return null;
|
||||
|
||||
const density = colliderDensity(profile);
|
||||
const ccd = itemId === 'SKU-009'; // pen: small + fast → continuous collision
|
||||
|
||||
return (
|
||||
<RigidBody
|
||||
ref={bodyRef}
|
||||
type="kinematicPosition"
|
||||
colliders={false}
|
||||
friction={profile.friction}
|
||||
restitution={profile.restitution}
|
||||
linearDamping={profile.linearDamping}
|
||||
angularDamping={profile.angularDamping}
|
||||
ccd={ccd}
|
||||
enabledRotations={[true, true, true]}
|
||||
position={pose.position}
|
||||
>
|
||||
{profile.collider === 'cuboid' && profile.cuboidHalfExtents && (
|
||||
<CuboidCollider args={profile.cuboidHalfExtents} density={density} />
|
||||
)}
|
||||
{profile.collider === 'capsule' && profile.capsule && (
|
||||
<CapsuleCollider args={[profile.capsule[1], profile.capsule[0]]} density={density} />
|
||||
)}
|
||||
{profile.collider === 'cylinder' && profile.capsule && (
|
||||
<CylinderCollider args={[profile.capsule[1], profile.capsule[0]]} density={density} />
|
||||
)}
|
||||
<ItemVisualContent
|
||||
caseData={caseData}
|
||||
phase={pose.phase}
|
||||
surface={pose.surface}
|
||||
isSettled={authority.current === 'frozen' ? true : pose.isSettled}
|
||||
castShadow={castShadow}
|
||||
verifySku={verifySku}
|
||||
/>
|
||||
</RigidBody>
|
||||
);
|
||||
});
|
||||
@@ -26,6 +26,13 @@ interface CageInstances {
|
||||
wheels: THREE.Matrix4[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stage 2: roll cages are 3-sided with an OPEN FRONT on the conveyor-facing
|
||||
* side (real roll-container design) plus a 40mm sill — items enter through
|
||||
* the opening from the gravity chute. Matches physicsWorldLayout colliders.
|
||||
*/
|
||||
export type CageOpenSide = 'z-' | 'z+' | 'none';
|
||||
|
||||
function boxInstance(x: number, y: number, z: number, sx: number, sy: number, sz: number): THREE.Matrix4 {
|
||||
return new THREE.Matrix4().compose(
|
||||
new THREE.Vector3(x, y, z),
|
||||
@@ -34,11 +41,12 @@ function boxInstance(x: number, y: number, z: number, sx: number, sy: number, sz
|
||||
);
|
||||
}
|
||||
|
||||
/** Deterministic instance layout for the cage (built once). */
|
||||
function buildInstances(): CageInstances {
|
||||
/** Deterministic instance layout for the cage (built once per open side). */
|
||||
function buildInstances(openSide: CageOpenSide): CageInstances {
|
||||
const boxes: THREE.Matrix4[] = [];
|
||||
const yBot = WHEEL_D; // bottom of frame body
|
||||
const yTop = H; // top of frame body (exterior top)
|
||||
const openSign = openSide === 'z-' ? -1 : openSide === 'z+' ? 1 : 0;
|
||||
|
||||
// 4 corner posts
|
||||
for (const sx of [-1, 1]) {
|
||||
@@ -46,13 +54,19 @@ function buildInstances(): CageInstances {
|
||||
boxes.push(boxInstance(sx * (W / 2 - FT / 2), yBot + BODY_H / 2, sz * (D / 2 - FT / 2), FT, BODY_H, FT));
|
||||
}
|
||||
}
|
||||
// bottom + top frame rectangles
|
||||
// bottom + top frame rectangles (skip the open side's tubes; sill added below)
|
||||
for (const y of [yBot + FT / 2, yTop - FT / 2]) {
|
||||
boxes.push(boxInstance(0, y, D / 2 - FT / 2, W, FT, FT));
|
||||
boxes.push(boxInstance(0, y, -(D / 2 - FT / 2), W, FT, FT));
|
||||
for (const sz of [-1, 1]) {
|
||||
if (sz === openSign && y === yTop - FT / 2) continue; // open front: no top tube
|
||||
boxes.push(boxInstance(0, y, sz * (D / 2 - FT / 2), W, FT, FT));
|
||||
}
|
||||
boxes.push(boxInstance(W / 2 - FT / 2, y, 0, FT, FT, D - FT * 2));
|
||||
boxes.push(boxInstance(-(W / 2 - FT / 2), y, 0, FT, FT, D - FT * 2));
|
||||
}
|
||||
// 40mm sill across the open front (matches entry-sill collider)
|
||||
if (openSign !== 0) {
|
||||
boxes.push(boxInstance(0, yBot + 0.02, openSign * (D / 2 - FT / 2), W, 0.04, FT));
|
||||
}
|
||||
|
||||
// grid walls between frames (interior span)
|
||||
const yGridBot = yBot + FT;
|
||||
@@ -66,6 +80,7 @@ function buildInstances(): CageInstances {
|
||||
const vCols = Math.floor((xInner * 2) / GRID_STEP) - 1; // exclude corners (posts)
|
||||
const hRows = Math.max(1, Math.round(gridH / GRID_STEP) - 1);
|
||||
for (const sz of [-1, 1]) {
|
||||
if (sz === openSign) continue; // open front: no grid wall
|
||||
const z = sz * (D / 2 - ROD / 2);
|
||||
for (let i = 1; i <= vCols; i++) {
|
||||
const x = -xInner + (i * (xInner * 2)) / (vCols + 1);
|
||||
@@ -106,12 +121,13 @@ function buildInstances(): CageInstances {
|
||||
return { boxes, wheels };
|
||||
}
|
||||
|
||||
export default function RollCageMesh({ color, active = false, shadows = false }: {
|
||||
export default function RollCageMesh({ color, active = false, shadows = false, openSide = 'none' }: {
|
||||
color: string;
|
||||
active?: boolean;
|
||||
shadows?: boolean;
|
||||
openSide?: CageOpenSide;
|
||||
}) {
|
||||
const instances = useMemo(buildInstances, []);
|
||||
const instances = useMemo(() => buildInstances(openSide), [openSide]);
|
||||
const boxGeo = useMemo(() => new THREE.BoxGeometry(1, 1, 1), []);
|
||||
const wheelGeo = useMemo(() => new THREE.CylinderGeometry(WR, WR, 0.03, 12), []);
|
||||
const boxesRef = useRef<THREE.InstancedMesh>(null);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
import { Canvas, useFrame, useThree } from '@react-three/fiber';
|
||||
import { Grid, OrbitControls, Html, Line } from '@react-three/drei';
|
||||
import { Grid, OrbitControls, Html, Line, Environment, Lightformer } from '@react-three/drei';
|
||||
import { Suspense, lazy, useRef, useMemo, useState, useEffect } from 'react';
|
||||
import type { Mesh, Group } from 'three';
|
||||
import * as THREE from 'three';
|
||||
@@ -21,6 +21,10 @@ import { getMeasurementData, shouldShowLaserBeam, shouldShowStepperPulse, should
|
||||
import { ITEMS } from '../../data/items';
|
||||
import type { Category } from '../../domain/types';
|
||||
import { PhysicalPlaybackItem } from './PhysicalPlaybackItem';
|
||||
import { PhysicalPlaybackItemPhysics } from './PhysicalPlaybackItemPhysics';
|
||||
import { ConveyorCadModel, CONVEYOR_CAD_SPAN_X, preloadConveyorCad } from './ConveyorCadModel';
|
||||
import { SorterPhysicsWorld } from './SorterPhysics';
|
||||
import { deriveSorterVisualState } from '../../domain/sorterVisualState';
|
||||
import { DEMO_PLAYLIST, PLAYLIST_LENGTH } from '../../domain/demoPlaylist';
|
||||
import { cumulativePlaylistDurationMs, getPlaylistCaseDurationMs } from '../../domain/continuousPlayback';
|
||||
import { INDUSTRIAL_PALETTE } from '../../domain/industrialTheme';
|
||||
@@ -55,6 +59,7 @@ import {
|
||||
CAGE_FLOOR_Y,
|
||||
CONVEYOR_SPEED_MPS,
|
||||
} from '../../domain/physicalLayout';
|
||||
import { CHUTE_PITCH, CHUTE_LENGTH, CHUTE_MID_Y, CHUTE_MID_Z, CHUTE_X, CHUTE_HALF_W } from '../../domain/physicsWorldLayout';
|
||||
import PerfCollector from './PerfCollector';
|
||||
import PerfOverlay from './PerfOverlay';
|
||||
import RollCageMesh from './RollCageMesh';
|
||||
@@ -131,7 +136,7 @@ const MAX_VISIBLE_ITEMS = 6;
|
||||
/** Heavy animated overlays off by default for smooth demo. */
|
||||
const ENABLE_DEMO_EFFECTS = false;
|
||||
const CONVEYOR_LENGTH = CONVEYOR_END_X - CONVEYOR_START_X;
|
||||
const CONVEYOR_CENTER_X = (CONVEYOR_START_X + CONVEYOR_END_X) / 2;
|
||||
void CONVEYOR_LENGTH;
|
||||
|
||||
/** Cinematic camera controller - smoothly transitions between camera angles */
|
||||
function CinematicCameraController({
|
||||
@@ -524,89 +529,110 @@ function SupportLeg({ x }: { x: number }) {
|
||||
* Conveyor belt - realistic roller conveyor
|
||||
* Belt top surface at 0.7m (BELT_TOP_Y)
|
||||
*/
|
||||
function ConveyorBelt({ pulseActive, elapsedMs, simplified, shadows = false }: { pulseActive: boolean; elapsedMs: number; simplified: boolean; shadows?: boolean }) {
|
||||
/**
|
||||
* Belt extension segment (SPEC_DERIVED) — entry/exit sections flanking the
|
||||
* CAD conveyor module. Same 500 mm width / 700 mm belt top as the real unit.
|
||||
*/
|
||||
function BeltSection({ startX, endX, simplified, shadows }: { startX: number; endX: number; simplified: boolean; shadows: boolean }) {
|
||||
const spacing = simplified ? ROLLER_SPACING_M * 2 : ROLLER_SPACING_M;
|
||||
const rollerCount = Math.floor(CONVEYOR_LENGTH / spacing);
|
||||
const stripeOffsets = simplified ? [-2, 0, 2] : [-3, -1, 0.5, 2];
|
||||
|
||||
const length = endX - startX;
|
||||
const centerX = (startX + endX) / 2;
|
||||
const rollerCount = Math.max(1, Math.floor(length / spacing));
|
||||
|
||||
const rollerPositions = useMemo(() => {
|
||||
const positions: [number, number, number][] = [];
|
||||
for (let i = 0; i < rollerCount; i++) {
|
||||
positions.push([CONVEYOR_START_X + spacing / 2 + i * spacing, ROLLER_Y, 0]);
|
||||
positions.push([startX + spacing / 2 + i * spacing, ROLLER_Y, 0]);
|
||||
}
|
||||
return positions;
|
||||
}, [rollerCount, spacing]);
|
||||
}, [rollerCount, spacing, startX]);
|
||||
|
||||
const legPositions = useMemo(() => {
|
||||
const positions: number[] = [];
|
||||
for (let x = CONVEYOR_START_X + 0.5; x < CONVEYOR_END_X - 0.3; x += 2.0) {
|
||||
for (let x = startX + 0.5; x < endX - 0.3; x += 2.0) {
|
||||
positions.push(x);
|
||||
}
|
||||
return positions;
|
||||
}, []);
|
||||
}, [startX, endX]);
|
||||
|
||||
return (
|
||||
<group>
|
||||
{/* Main belt surface - matte PVC/tarpaulin look at 0.7m */}
|
||||
<mesh position={[CONVEYOR_CENTER_X, BELT_Y - BELT_THICKNESS_M / 2, 0]} receiveShadow={shadows}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, BELT_THICKNESS_M, CONVEYOR_WIDTH_M]} />
|
||||
<meshStandardMaterial
|
||||
color={COLORS.belt}
|
||||
roughness={0.85}
|
||||
metalness={0.05}
|
||||
/>
|
||||
<mesh position={[centerX, BELT_Y - BELT_THICKNESS_M / 2, 0]} receiveShadow={shadows}>
|
||||
<boxGeometry args={[length, BELT_THICKNESS_M, CONVEYOR_WIDTH_M]} />
|
||||
<meshStandardMaterial color={COLORS.belt} roughness={0.85} metalness={0.05} />
|
||||
</mesh>
|
||||
|
||||
<mesh position={[centerX, BELT_Y + SIDE_GUARD_HEIGHT_M / 2, CONVEYOR_WIDTH_M / 2 + 0.02]}>
|
||||
<boxGeometry args={[length, SIDE_GUARD_HEIGHT_M, 0.025]} />
|
||||
<meshStandardMaterial color={COLORS.sideGuards} metalness={0.4} roughness={0.5} />
|
||||
</mesh>
|
||||
<mesh position={[centerX, BELT_Y + SIDE_GUARD_HEIGHT_M / 2, -CONVEYOR_WIDTH_M / 2 - 0.02]}>
|
||||
<boxGeometry args={[length, SIDE_GUARD_HEIGHT_M, 0.025]} />
|
||||
<meshStandardMaterial color={COLORS.sideGuards} metalness={0.4} roughness={0.5} />
|
||||
</mesh>
|
||||
<mesh position={[centerX, FRAME_TOP_Y + 0.025, CONVEYOR_WIDTH_M / 2 + 0.01]} castShadow={shadows}>
|
||||
<boxGeometry args={[length, 0.05, 0.04]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
<mesh position={[centerX, FRAME_TOP_Y + 0.025, -CONVEYOR_WIDTH_M / 2 - 0.01]} castShadow={shadows}>
|
||||
<boxGeometry args={[length, 0.05, 0.04]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
{rollerPositions.map((pos, i) => (
|
||||
<StaticRoller key={i} position={pos} />
|
||||
))}
|
||||
{legPositions.map((x, i) => (
|
||||
<SupportLeg key={i} x={x} />
|
||||
))}
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conveyor: CAD module (REAL_CAD) + entry/exit belt extensions (SPEC_DERIVED).
|
||||
* Gate/roller/belt motion is driven by the domain visual-state adapter.
|
||||
*/
|
||||
function ConveyorBelt({ pulseActive, elapsedMs, simplified, shadows = false, gateOpen = false, beltVelocityMps = 0, rollerOmega = 0 }: { pulseActive: boolean; elapsedMs: number; simplified: boolean; shadows?: boolean; gateOpen?: boolean; beltVelocityMps?: number; rollerOmega?: number }) {
|
||||
const stripeOffsets = simplified ? [-2, 0, 2] : [-3, -1, 0.5, 2];
|
||||
const [cadStart, cadEnd] = CONVEYOR_CAD_SPAN_X;
|
||||
|
||||
return (
|
||||
<group>
|
||||
{/* CAD-derived conveyor module (real machine: frame, belt, rollers,
|
||||
drive, metering gates, servo diverters, camera arch) */}
|
||||
<Suspense fallback={null}>
|
||||
<ConveyorCadModel
|
||||
gateOpen={gateOpen}
|
||||
beltVelocityMps={beltVelocityMps}
|
||||
rollerOmegaRadPerSec={rollerOmega}
|
||||
shadows={shadows}
|
||||
/>
|
||||
</Suspense>
|
||||
|
||||
{/* Entry extension: zone A feed into the CAD module */}
|
||||
<BeltSection startX={CONVEYOR_START_X} endX={cadStart} simplified={simplified} shadows={shadows} />
|
||||
{/* Exit extension: CAD module discharge to the B spur */}
|
||||
<BeltSection startX={cadEnd} endX={CONVEYOR_END_X} simplified={simplified} shadows={shadows} />
|
||||
|
||||
{/* Belt stripes — deterministic movement synced to item (offset = time * 1 m/s) */}
|
||||
{stripeOffsets.map((offset, i) => (
|
||||
<BeltStripe key={i} baseOffset={offset} elapsedMs={elapsedMs} />
|
||||
))}
|
||||
|
||||
{/* Side guards - brushed metal above belt */}
|
||||
<mesh position={[CONVEYOR_CENTER_X, BELT_Y + SIDE_GUARD_HEIGHT_M / 2, CONVEYOR_WIDTH_M / 2 + 0.02]}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, SIDE_GUARD_HEIGHT_M, 0.025]} />
|
||||
<meshStandardMaterial color={COLORS.sideGuards} metalness={0.4} roughness={0.5} />
|
||||
</mesh>
|
||||
<mesh position={[CONVEYOR_CENTER_X, BELT_Y + SIDE_GUARD_HEIGHT_M / 2, -CONVEYOR_WIDTH_M / 2 - 0.02]}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, SIDE_GUARD_HEIGHT_M, 0.025]} />
|
||||
<meshStandardMaterial color={COLORS.sideGuards} metalness={0.4} roughness={0.5} />
|
||||
</mesh>
|
||||
|
||||
{/* Frame rails - industrial metal */}
|
||||
<mesh position={[CONVEYOR_CENTER_X, FRAME_TOP_Y + 0.025, CONVEYOR_WIDTH_M / 2 + 0.01]} castShadow={shadows}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, 0.05, 0.04]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
<mesh position={[CONVEYOR_CENTER_X, FRAME_TOP_Y + 0.025, -CONVEYOR_WIDTH_M / 2 - 0.01]} castShadow={shadows}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, 0.05, 0.04]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
|
||||
{/* Rollers — static geometry (no per-frame rotation hooks) */}
|
||||
{rollerPositions.map((pos, i) => (
|
||||
<StaticRoller key={i} position={pos} />
|
||||
))}
|
||||
|
||||
|
||||
{/* Drive roller at end (larger) */}
|
||||
<mesh position={[CONVEYOR_END_X - 0.1, ROLLER_Y, 0]} rotation={[0, 0, Math.PI / 2]}>
|
||||
<cylinderGeometry args={[DRIVE_ROLLER_RADIUS_M, DRIVE_ROLLER_RADIUS_M, CONVEYOR_WIDTH_M - 0.02, 16]} />
|
||||
<meshStandardMaterial color="#64748b" metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
|
||||
|
||||
{/* Tension roller at start (larger) */}
|
||||
<mesh position={[CONVEYOR_START_X + 0.1, ROLLER_Y, 0]} rotation={[0, 0, Math.PI / 2]}>
|
||||
<cylinderGeometry args={[DRIVE_ROLLER_RADIUS_M * 0.9, DRIVE_ROLLER_RADIUS_M * 0.9, CONVEYOR_WIDTH_M - 0.02, 16]} />
|
||||
<meshStandardMaterial color="#64748b" metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
|
||||
{/* Support legs from floor */}
|
||||
{legPositions.map((x, i) => (
|
||||
<SupportLeg key={i} x={x} />
|
||||
))}
|
||||
|
||||
|
||||
{/* Stepper motor at drive end */}
|
||||
<StepperMotor position={[CONVEYOR_END_X - 0.1, ROLLER_Y, 0]} pulseActive={pulseActive} />
|
||||
|
||||
|
||||
{/* End caps / guards */}
|
||||
<mesh position={[CONVEYOR_START_X, BELT_Y - 0.05, 0]}>
|
||||
<boxGeometry args={[0.05, 0.12, CONVEYOR_WIDTH_M + 0.1]} />
|
||||
@@ -680,10 +706,10 @@ function BReceiverBin({ active }: { active: boolean }) {
|
||||
</mesh>
|
||||
))}
|
||||
|
||||
{/* Drop chute into bin */}
|
||||
{/* Drop chute into bin — descends toward +X (sign matches collider) */}
|
||||
<mesh
|
||||
position={[(transferEndX + entryX) / 2, (BELT_Y + floorY) / 2 + 0.02, centerZ]}
|
||||
rotation={[0, 0, Math.atan2(BELT_Y - floorY, entryX - transferEndX)]}
|
||||
rotation={[0, 0, -Math.atan2(BELT_Y - floorY, entryX - transferEndX)]}
|
||||
>
|
||||
<boxGeometry args={[Math.hypot(entryX - transferEndX, BELT_Y - floorY), 0.015, CONVEYOR_WIDTH_M - 0.08]} />
|
||||
<meshStandardMaterial color="#4ade80" transparent opacity={0.5} emissive={COLORS.routeB} emissiveIntensity={emissive} side={THREE.DoubleSide} />
|
||||
@@ -765,7 +791,7 @@ function RollCage({ position, label, color, active, shadows = false }: {
|
||||
<meshStandardMaterial color={color} transparent opacity={active ? 0.25 : 0.08} />
|
||||
</mesh>
|
||||
|
||||
<RollCageMesh color={color} active={active} shadows={shadows} />
|
||||
<RollCageMesh color={color} active={active} shadows={shadows} openSide={label === 'C' ? 'z-' : 'z+'} />
|
||||
|
||||
{/* Label */}
|
||||
<Html position={[0, height + 0.15, 0]} center>
|
||||
@@ -784,41 +810,45 @@ function RollCage({ position, label, color, active, shadows = false }: {
|
||||
}
|
||||
|
||||
|
||||
/** Chute/deflector for routing items to C/D */
|
||||
/** Chute/deflector for routing items to C/D.
|
||||
* Visual geometry matches the physics collider and the domain kinematic
|
||||
* chute line: steep gravity chute (~0.394 rad) from belt edge (y 0.66)
|
||||
* down to the open cage front (y 0.14) — see domain/physicsWorldLayout. */
|
||||
function RouteChute({ gateX, targetZ, color, active }: {
|
||||
gateX: number;
|
||||
targetZ: number;
|
||||
color: string;
|
||||
active: boolean;
|
||||
}) {
|
||||
const chuteLength = Math.abs(targetZ) - CONVEYOR_WIDTH_M / 2 - 0.1;
|
||||
const chuteWidth = 0.4;
|
||||
const chuteWidth = CHUTE_HALF_W * 2;
|
||||
const direction = targetZ > 0 ? 1 : -1;
|
||||
const midZ = (CONVEYOR_WIDTH_M / 2 + 0.1) * direction + (chuteLength / 2) * direction;
|
||||
|
||||
const midZ = direction * CHUTE_MID_Z;
|
||||
const rot: [number, number, number] = [direction * CHUTE_PITCH, 0, 0];
|
||||
void gateX;
|
||||
|
||||
return (
|
||||
<group>
|
||||
{/* Chute surface - angled slightly down */}
|
||||
<mesh
|
||||
position={[gateX + 0.3, BELT_TOP_Y - 0.02, midZ]}
|
||||
rotation={[direction * -0.1, 0, 0]}
|
||||
{/* Chute surface — steep gravity chute toward the cage open front */}
|
||||
<mesh
|
||||
position={[CHUTE_X, CHUTE_MID_Y - 0.015, midZ]}
|
||||
rotation={rot}
|
||||
>
|
||||
<boxGeometry args={[chuteWidth, 0.02, chuteLength]} />
|
||||
<meshStandardMaterial
|
||||
color={color}
|
||||
transparent
|
||||
<boxGeometry args={[chuteWidth, 0.02, CHUTE_LENGTH]} />
|
||||
<meshStandardMaterial
|
||||
color={color}
|
||||
transparent
|
||||
opacity={active ? 0.7 : 0.3}
|
||||
emissive={color}
|
||||
emissiveIntensity={active ? 0.2 : 0}
|
||||
/>
|
||||
</mesh>
|
||||
{/* Side rails */}
|
||||
<mesh position={[gateX + 0.3 - chuteWidth / 2 - 0.015, BELT_TOP_Y + 0.02, midZ]}>
|
||||
<boxGeometry args={[0.02, 0.06, chuteLength]} />
|
||||
{/* Side rails — follow the chute pitch */}
|
||||
<mesh position={[CHUTE_X - CHUTE_HALF_W - 0.01, CHUTE_MID_Y + 0.03, midZ]} rotation={rot}>
|
||||
<boxGeometry args={[0.02, 0.07, CHUTE_LENGTH]} />
|
||||
<meshStandardMaterial color={color} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
<mesh position={[gateX + 0.3 + chuteWidth / 2 + 0.015, BELT_TOP_Y + 0.02, midZ]}>
|
||||
<boxGeometry args={[0.02, 0.06, chuteLength]} />
|
||||
<mesh position={[CHUTE_X + CHUTE_HALF_W + 0.01, CHUTE_MID_Y + 0.03, midZ]} rotation={rot}>
|
||||
<boxGeometry args={[0.02, 0.07, CHUTE_LENGTH]} />
|
||||
<meshStandardMaterial color={color} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
</group>
|
||||
@@ -1148,6 +1178,7 @@ function ContinuousScene({
|
||||
stage0,
|
||||
stage1,
|
||||
maxVisibleItems = MAX_VISIBLE_ITEMS,
|
||||
shadowsEnabled = false,
|
||||
}: {
|
||||
playback: ContinuousPlaybackState;
|
||||
simplified: boolean;
|
||||
@@ -1156,6 +1187,8 @@ function ContinuousScene({
|
||||
stage0?: Stage0Config;
|
||||
stage1?: Stage1Config;
|
||||
maxVisibleItems?: number;
|
||||
/** Stage 2 visual pass: PCF shadows + studio environment on capable quality modes. */
|
||||
shadowsEnabled?: boolean;
|
||||
}) {
|
||||
const category = playback.targetCategory;
|
||||
const phase = playback.currentPhase;
|
||||
@@ -1164,14 +1197,18 @@ function ContinuousScene({
|
||||
|
||||
// Stage 0 prototype flags (inert when stage0 is absent — default route unchanged)
|
||||
const proto = stage0?.enabled ?? false;
|
||||
const protoShadows = proto && stage0!.shadows;
|
||||
const protoShadows = proto ? (proto && stage0!.shadows) : shadowsEnabled;
|
||||
const protoCamera = proto && stage0!.camera;
|
||||
const shotOverride = protoCamera && stage0!.shot ? shotToPhaseCategory(stage0!.shot) : null;
|
||||
const darkBg = proto && stage0!.darkBackground;
|
||||
// Stage 2: premium industrial dark environment is the default look.
|
||||
const darkBg = proto ? stage0!.darkBackground : true;
|
||||
|
||||
const cameraHighlight = shouldHighlightCamera(phase);
|
||||
const showScan = shouldShowScanEffect(phase);
|
||||
|
||||
// Stage 2: single domain -> visual/physics adapter (business logic stays truth)
|
||||
const visualState = deriveSorterVisualState(playback);
|
||||
|
||||
// Measurement system states
|
||||
const measurementData = getMeasurementData(playback);
|
||||
const showLaser = shouldShowLaserBeam(phase);
|
||||
@@ -1223,6 +1260,7 @@ function ContinuousScene({
|
||||
for (const asset of getPreloadAssets()) {
|
||||
if (asset.runtimePath) preloadRealItemModel(asset.runtimePath);
|
||||
}
|
||||
preloadConveyorCad();
|
||||
}, []);
|
||||
const itemScale = Math.max(dims.width, dims.depth, dims.height);
|
||||
|
||||
@@ -1248,9 +1286,9 @@ function ContinuousScene({
|
||||
: 'x';
|
||||
const itemColor = category ? COLORS[`route${category}` as keyof typeof COLORS] : COLORS.sensorAccent;
|
||||
|
||||
// Cinematic camera: heavy effects (legacy flag) OR stage0 prototype camera.
|
||||
// Manual shot override keeps the camera driving even while paused.
|
||||
const cinematicActive = (effectsEnabled || protoCamera) && autoCameraEnabled
|
||||
// Stage 2: cinematic auto-camera is the default presentation (§13.5 —
|
||||
// OrbitControls remain only as the manual/debug mode when auto cam is off).
|
||||
const cinematicActive = autoCameraEnabled
|
||||
&& (playback.status === 'running' || shotOverride !== null);
|
||||
|
||||
return (
|
||||
@@ -1284,11 +1322,34 @@ function ContinuousScene({
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{/* Soft natural lighting — no shadow maps (Canvas shadows=false for perf) */}
|
||||
<ambientLight intensity={0.7} />
|
||||
<hemisphereLight args={['#f8fafc', '#d0dae8', 0.5]} />
|
||||
<directionalLight position={[8, 12, 6]} intensity={0.9} />
|
||||
<directionalLight position={[-5, 8, -4]} intensity={0.35} />
|
||||
{/* Stage 2 default: premium industrial rig — low ambient, key with
|
||||
PCF shadows, soft fill, cool rim (Stage 0 proven values) */}
|
||||
<ambientLight intensity={0.28} />
|
||||
<hemisphereLight args={['#2a3c58', '#141c2a', 0.8]} />
|
||||
<directionalLight
|
||||
position={[6, 9, 4]}
|
||||
intensity={2.2}
|
||||
castShadow={protoShadows}
|
||||
shadow-mapSize-width={2048}
|
||||
shadow-mapSize-height={2048}
|
||||
shadow-camera-left={-7}
|
||||
shadow-camera-right={7}
|
||||
shadow-camera-top={7}
|
||||
shadow-camera-bottom={-7}
|
||||
shadow-camera-near={1}
|
||||
shadow-camera-far={25}
|
||||
shadow-bias={-0.0004}
|
||||
/>
|
||||
<directionalLight position={[-5, 6, -3]} intensity={0.35} />
|
||||
<directionalLight position={[2, 5, -8]} intensity={0.7} color="#bcd7ff" />
|
||||
{/* Procedural studio environment (no external HDRI — offline-safe) */}
|
||||
{protoShadows && (
|
||||
<Environment resolution={128} frames={1}>
|
||||
<Lightformer intensity={1.6} position={[0, 5, 0]} rotation-x={Math.PI / 2} scale={[8, 8, 1]} color="#dfe9ff" />
|
||||
<Lightformer intensity={0.7} position={[-5, 2, -4]} rotation-y={Math.PI / 3} scale={[4, 2, 1]} color="#b8c8e8" />
|
||||
<Lightformer intensity={0.5} position={[5, 1.5, 3]} rotation-y={-Math.PI / 4} scale={[3, 1.5, 1]} color="#ffe9c8" />
|
||||
</Environment>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1297,23 +1358,36 @@ function ContinuousScene({
|
||||
args={[16, 12]}
|
||||
cellSize={0.5}
|
||||
cellThickness={0.4}
|
||||
cellColor={COLORS.gridCell}
|
||||
cellColor={darkBg ? '#22303f' : COLORS.gridCell}
|
||||
sectionSize={2}
|
||||
sectionThickness={0.8}
|
||||
sectionColor={COLORS.gridSection}
|
||||
sectionColor={darkBg ? '#2f4256' : COLORS.gridSection}
|
||||
fadeDistance={12}
|
||||
infiniteGrid={false}
|
||||
position={[0, 0.001, 0]}
|
||||
/>
|
||||
|
||||
{/* Floor */}
|
||||
{/* Floor — dark polished concrete with soft reflections */}
|
||||
<mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, 0, 0]} receiveShadow={protoShadows}>
|
||||
<planeGeometry args={[16, 12]} />
|
||||
<meshStandardMaterial color={COLORS.floor} roughness={0.9} metalness={0} />
|
||||
<meshStandardMaterial
|
||||
color={darkBg ? '#1c2534' : COLORS.floor}
|
||||
roughness={darkBg ? 0.55 : 0.9}
|
||||
metalness={darkBg ? 0.25 : 0}
|
||||
envMapIntensity={0.8}
|
||||
/>
|
||||
</mesh>
|
||||
|
||||
{/* Conveyor - belt top at 0.7m */}
|
||||
<ConveyorBelt pulseActive={showPulse} elapsedMs={totalElapsedMs} simplified={liteScene} shadows={protoShadows} />
|
||||
{/* Conveyor: CAD module + SPEC_DERIVED extensions — belt top at 0.7m */}
|
||||
<ConveyorBelt
|
||||
pulseActive={showPulse}
|
||||
elapsedMs={totalElapsedMs}
|
||||
simplified={liteScene}
|
||||
shadows={protoShadows}
|
||||
gateOpen={visualState.gateOpen}
|
||||
beltVelocityMps={visualState.beltVelocityMps}
|
||||
rollerOmega={visualState.rollerOmegaRadPerSec}
|
||||
/>
|
||||
|
||||
{/* Zone A - spawn point */}
|
||||
<ZoneMarker
|
||||
@@ -1392,18 +1466,21 @@ function ContinuousScene({
|
||||
{/* Route arrows on belt surface */}
|
||||
<RouteArrows activeRoute={activeRoute} />
|
||||
|
||||
{/* Physically simulated items */}
|
||||
{sceneItems.map(item => (
|
||||
<PhysicalPlaybackItem
|
||||
key={item.id}
|
||||
caseData={item.caseData}
|
||||
elapsedMs={item.elapsedMs}
|
||||
slotIndex={item.slotIndex}
|
||||
verifySku={verifySku}
|
||||
jitter={item.slotIndex === currentCaseIndex ? positionJitter : undefined}
|
||||
castShadow={protoShadows}
|
||||
/>
|
||||
))}
|
||||
{/* Items: kinematic on the belt (domain truth), rigid-body physics
|
||||
after the drop handoff, verified against the domain receiver */}
|
||||
<SorterPhysicsWorld running={playback.status === 'running'} speed={playback.speed}>
|
||||
{sceneItems.map(item => (
|
||||
<PhysicalPlaybackItemPhysics
|
||||
key={item.id}
|
||||
caseData={item.caseData}
|
||||
elapsedMs={item.elapsedMs}
|
||||
slotIndex={item.slotIndex}
|
||||
verifySku={verifySku}
|
||||
jitter={item.slotIndex === currentCaseIndex ? positionJitter : undefined}
|
||||
castShadow={protoShadows}
|
||||
/>
|
||||
))}
|
||||
</SorterPhysicsWorld>
|
||||
|
||||
{/* Outline/BBox for the CURRENT item only */}
|
||||
<BoundingBoxVisual
|
||||
@@ -1430,16 +1507,14 @@ function ContinuousScene({
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Cinematic camera controller — opt-in (legacy effects flag or stage0 prototype) */}
|
||||
{(effectsEnabled || protoCamera) && (
|
||||
<CinematicCameraController
|
||||
playback={playback}
|
||||
enabled={cinematicActive}
|
||||
viewportType={viewportType}
|
||||
overridePhase={shotOverride?.phase ?? null}
|
||||
overrideCategory={shotOverride?.category ?? null}
|
||||
/>
|
||||
)}
|
||||
{/* Cinematic camera controller — default on; manual orbit = debug mode */}
|
||||
<CinematicCameraController
|
||||
playback={playback}
|
||||
enabled={cinematicActive}
|
||||
viewportType={viewportType}
|
||||
overridePhase={shotOverride?.phase ?? null}
|
||||
overrideCategory={shotOverride?.category ?? null}
|
||||
/>
|
||||
|
||||
{/* OrbitControls - enabled when not in cinematic mode */}
|
||||
<OrbitControls
|
||||
@@ -1541,11 +1616,13 @@ export default function SorterDigitalTwinContinuous({
|
||||
shadows={shadowsEnabled ? 'soft' : false}
|
||||
gl={{ antialias, powerPreference: 'high-performance' }}
|
||||
onCreated={({ gl }) => {
|
||||
if (proto) {
|
||||
gl.outputColorSpace = THREE.SRGBColorSpace;
|
||||
gl.toneMapping = stage0!.toneMapping ? THREE.ACESFilmicToneMapping : THREE.NoToneMapping;
|
||||
gl.toneMappingExposure = 1.0;
|
||||
gl.shadowMap.type = THREE.PCFSoftShadowMap;
|
||||
// Stage 2: premium industrial look is the default (ACES + PCFSoft).
|
||||
gl.outputColorSpace = THREE.SRGBColorSpace;
|
||||
gl.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
gl.toneMappingExposure = 1.15;
|
||||
gl.shadowMap.type = THREE.PCFSoftShadowMap;
|
||||
if (proto && !stage0!.toneMapping) {
|
||||
gl.toneMapping = THREE.NoToneMapping;
|
||||
}
|
||||
const canvas = gl.domElement;
|
||||
const handleLost = (event: Event) => {
|
||||
@@ -1570,6 +1647,7 @@ export default function SorterDigitalTwinContinuous({
|
||||
stage0={stage0}
|
||||
stage1={stage1}
|
||||
maxVisibleItems={quality.maxVisibleItems}
|
||||
shadowsEnabled={shadowsEnabled}
|
||||
/>
|
||||
{perfEnabled ? (
|
||||
<PerfCollector
|
||||
|
||||
117
src/components/ThreeD/SorterPhysics.tsx
Normal file
117
src/components/ThreeD/SorterPhysics.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Stage 2 — physics world for the sorter drop segment.
|
||||
*
|
||||
* Hybrid authority (docs/stage2_real_sorter/physics-architecture.md):
|
||||
* - items on the belt are KINEMATIC (domain pose is truth);
|
||||
* - at the drop handoff (pusher contact / belt edge) the body switches to
|
||||
* DYNAMIC with deterministic initial velocity;
|
||||
* - static colliders mirror the visible chute / receiver geometry
|
||||
* (documented hidden colliders, same dimensions as the visuals).
|
||||
*
|
||||
* Determinism: fixed dt = 1/60, max 4 substeps/frame, no unseeded randomness.
|
||||
* Physics freezes when the domain clock is paused (documented simulation
|
||||
* assumption — belt, gate and items halt together; EMERGENCY_STOP creates no
|
||||
* new impulses).
|
||||
*/
|
||||
import { useRef, type ReactNode } from 'react';
|
||||
import { useFrame } from '@react-three/fiber';
|
||||
import { Physics, RigidBody, CuboidCollider, useRapier } from '@react-three/rapier';
|
||||
import { getStaticColliders } from '../../domain/physicsWorldLayout';
|
||||
|
||||
export const PHYSICS_DT = 1 / 60;
|
||||
const MAX_SUBSTEPS = 4;
|
||||
|
||||
/** Drop verification record (debug/e2e introspection, no secrets). */
|
||||
export interface DropResult {
|
||||
caseId: string;
|
||||
itemId: string;
|
||||
expectedZone: 'B' | 'C' | 'D';
|
||||
finalPosition: [number, number, number];
|
||||
insideExpectedReceiver: boolean;
|
||||
settledByTimeout: boolean;
|
||||
timestampMs: number;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window { __DROP_RESULTS?: DropResult[] }
|
||||
}
|
||||
|
||||
export function recordDropResult(result: DropResult) {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.__DROP_RESULTS = [...(window.__DROP_RESULTS ?? []).slice(-49), result];
|
||||
}
|
||||
}
|
||||
|
||||
/** Steps the Rapier world with a fixed dt, scaled by domain playback speed. */
|
||||
function RapierStepper({ running, speed }: { running: boolean; speed: number }) {
|
||||
const { world } = useRapier();
|
||||
const accumulator = useRef(0);
|
||||
const perfEnabled = useRef(
|
||||
typeof window !== 'undefined'
|
||||
&& new URLSearchParams(window.location.search).get('perf') === '1',
|
||||
);
|
||||
const samples = useRef<number[]>([]);
|
||||
useFrame((_, delta) => {
|
||||
if (!running) return;
|
||||
accumulator.current += Math.min(delta, 0.1) * speed;
|
||||
let steps = 0;
|
||||
while (accumulator.current >= PHYSICS_DT && steps < MAX_SUBSTEPS) {
|
||||
if (perfEnabled.current) {
|
||||
const t0 = performance.now();
|
||||
world.step();
|
||||
const ms = performance.now() - t0;
|
||||
samples.current.push(ms);
|
||||
if (samples.current.length > 600) samples.current.shift();
|
||||
const sorted = [...samples.current].sort((a, b) => a - b);
|
||||
(window as unknown as { __PHYSICS_PERF__?: unknown }).__PHYSICS_PERF__ = {
|
||||
count: samples.current.length,
|
||||
avgMs: samples.current.reduce((s, v) => s + v, 0) / samples.current.length,
|
||||
p95Ms: sorted[Math.floor(sorted.length * 0.95)] ?? 0,
|
||||
maxMs: sorted[sorted.length - 1] ?? 0,
|
||||
};
|
||||
} else {
|
||||
world.step();
|
||||
}
|
||||
accumulator.current -= PHYSICS_DT;
|
||||
steps += 1;
|
||||
}
|
||||
if (steps === MAX_SUBSTEPS) accumulator.current = 0;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Static colliders for the whole working area (fixed bodies, cheap cuboids).
|
||||
* Layout data lives in domain/physicsWorldLayout — shared with headless tests. */
|
||||
export function SorterStaticColliders() {
|
||||
return (
|
||||
<RigidBody type="fixed" colliders={false}>
|
||||
{getStaticColliders().map((c) => (
|
||||
<CuboidCollider
|
||||
key={c.id}
|
||||
args={c.halfExtents}
|
||||
position={c.position}
|
||||
rotation={c.rotation}
|
||||
friction={c.friction}
|
||||
/>
|
||||
))}
|
||||
</RigidBody>
|
||||
);
|
||||
}
|
||||
|
||||
export function SorterPhysicsWorld({
|
||||
running,
|
||||
speed,
|
||||
children,
|
||||
}: {
|
||||
running: boolean;
|
||||
speed: number;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Physics updateLoop="independent" paused timeStep={PHYSICS_DT} gravity={[0, -9.81, 0]}>
|
||||
<RapierStepper running={running} speed={speed} />
|
||||
<SorterStaticColliders />
|
||||
{children}
|
||||
</Physics>
|
||||
);
|
||||
}
|
||||
87
src/domain/mobilePolicy.ts
Normal file
87
src/domain/mobilePolicy.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Stage 2 §16 — mobile capability policy.
|
||||
*
|
||||
* Decides what a mobile client gets, WITHOUT using viewport width alone:
|
||||
* - 'svg' — weak/unknown device or Telegram WebView → SVG fallback;
|
||||
* - 'mobile-low' — capable modern phone → 3D at Mobile Low quality
|
||||
* (DPR<=1.25, no post, LOD2-equivalent scene, 30 FPS target,
|
||||
* single active dynamic item);
|
||||
* - 'full' — not a mobile device (desktop policy applies elsewhere).
|
||||
*
|
||||
* Signals: UA class, Telegram WebView markers, hardwareConcurrency,
|
||||
* deviceMemory, WebGL renderer string. First-FPS watchdog is applied
|
||||
* separately at runtime (MobileFpsWatchdog).
|
||||
*/
|
||||
|
||||
export type MobileTier = 'svg' | 'mobile-low' | 'full';
|
||||
|
||||
export interface MobileSignals {
|
||||
userAgent: string;
|
||||
hardwareConcurrency: number | null;
|
||||
deviceMemoryGb: number | null;
|
||||
webglRenderer: string | null;
|
||||
hasTelegramProxy: boolean;
|
||||
}
|
||||
|
||||
const MOBILE_UA_RE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile/i;
|
||||
const TELEGRAM_UA_RE = /Telegram/i;
|
||||
const SOFTWARE_GL_RE = /swiftshader|llvmpipe|softpipe|software|basic render/i;
|
||||
|
||||
export function isMobileUa(userAgent: string): boolean {
|
||||
return MOBILE_UA_RE.test(userAgent);
|
||||
}
|
||||
|
||||
export function isTelegramWebView(signals: Pick<MobileSignals, 'userAgent' | 'hasTelegramProxy'>): boolean {
|
||||
return TELEGRAM_UA_RE.test(signals.userAgent) || signals.hasTelegramProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Telegram WebView policy (Stage 2 §16): forced SVG until verified on a real
|
||||
* Telegram WebView — conservative, honest (no 3D claims without a device).
|
||||
*/
|
||||
export function decideMobileTier(signals: MobileSignals): MobileTier {
|
||||
if (!isMobileUa(signals.userAgent)) return 'full';
|
||||
if (isTelegramWebView(signals)) return 'svg';
|
||||
if (signals.webglRenderer && SOFTWARE_GL_RE.test(signals.webglRenderer)) return 'svg';
|
||||
const cores = signals.hardwareConcurrency ?? 0;
|
||||
const mem = signals.deviceMemoryGb ?? 0;
|
||||
// Capable-device gate: enough cores and memory for Mobile Low.
|
||||
if (cores >= 8 && (mem === 0 || mem >= 4)) return 'mobile-low';
|
||||
if (cores >= 6 && mem >= 6) return 'mobile-low';
|
||||
return 'svg';
|
||||
}
|
||||
|
||||
/** Runtime signals collector (browser-only; SSR-safe). */
|
||||
export function collectMobileSignals(): MobileSignals {
|
||||
if (typeof navigator === 'undefined') {
|
||||
return { userAgent: '', hardwareConcurrency: null, deviceMemoryGb: null, webglRenderer: null, hasTelegramProxy: false };
|
||||
}
|
||||
let renderer: string | null = null;
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
const gl = (canvas.getContext('webgl2') ?? canvas.getContext('webgl')) as WebGLRenderingContext | null;
|
||||
if (gl) {
|
||||
const dbg = gl.getExtension('WEBGL_debug_renderer_info');
|
||||
renderer = dbg
|
||||
? String(gl.getParameter(dbg.UNMASKED_RENDERER_WEBGL))
|
||||
: String(gl.getParameter(gl.RENDERER));
|
||||
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
||||
}
|
||||
} catch {
|
||||
renderer = null;
|
||||
}
|
||||
const nav = navigator as Navigator & { deviceMemory?: number };
|
||||
const w = window as unknown as { TelegramWebviewProxy?: unknown };
|
||||
return {
|
||||
userAgent: navigator.userAgent,
|
||||
hardwareConcurrency: navigator.hardwareConcurrency ?? null,
|
||||
deviceMemoryGb: nav.deviceMemory ?? null,
|
||||
webglRenderer: renderer,
|
||||
hasTelegramProxy: typeof w !== 'undefined' && w.TelegramWebviewProxy != null,
|
||||
};
|
||||
}
|
||||
|
||||
/** First-FPS watchdog threshold: below this sustained FPS mobile drops to SVG. */
|
||||
export const MOBILE_MIN_FPS = 24;
|
||||
/** Watchdog sampling window (ms) after 3D mount. */
|
||||
export const MOBILE_FPS_SAMPLE_MS = 6000;
|
||||
@@ -90,6 +90,30 @@ function applyJitter(pos: Vec3, rotY: number, jitter?: PoseInput['jitter']): { p
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Stage 2 — case time (ms within case) at which the item is handed from
|
||||
* kinematic authority to rigid-body physics:
|
||||
* - B: fraction 0.35 of the B travel span (end of b_transfer spur, belt edge);
|
||||
* - C/D: fraction 0.12 of the C/D routing span — item fully past the belt
|
||||
* edge and ON the gravity chute (tall items must clear the belt slab);
|
||||
* - fault cases: null (no physics handoff — domain fault pose is truth).
|
||||
*/
|
||||
export function getDropHandoffTimeMs(
|
||||
targetCategory: Category | null,
|
||||
faultType?: FaultType,
|
||||
): number | null {
|
||||
if (faultType) return null;
|
||||
const category: 'B' | 'C' | 'D' = (targetCategory as 'B' | 'C' | 'D') || 'B';
|
||||
const { starts } = phaseStartsFrom(CASE_PHASES);
|
||||
const routingStart = starts['routing'];
|
||||
if (category === 'B') {
|
||||
const exitStart = starts['exit'];
|
||||
return routingStart + 0.35 * (exitStart - routingStart);
|
||||
}
|
||||
const clearStart = starts['clear_gap'];
|
||||
return routingStart + 0.12 * (clearStart - routingStart);
|
||||
}
|
||||
|
||||
/** Jam / E-stop motion: freeze at junction, then recover (no settle into bin). */
|
||||
function getFaultPose(input: PoseInput): PhysicalItemPose {
|
||||
const { dimensionsMm, elapsedMs, faultType, jitter } = input;
|
||||
|
||||
160
src/domain/physicsDrop.test.ts
Normal file
160
src/domain/physicsDrop.test.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* Stage 2 §18 — reproducible physics drop validation (headless Rapier).
|
||||
*
|
||||
* Runs the SAME world the runtime uses (physicsWorldLayout colliders,
|
||||
* visualPhysicsProfiles, identical handoff pose/velocities) and verifies:
|
||||
* deterministic, physically plausible, domain-receiver-correct drops.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import RAPIER from '@dimforge/rapier3d-compat';
|
||||
import { initRapier, simulateDrop, type DropSimResult } from './physicsDropSim';
|
||||
import { getStaticColliders } from './physicsWorldLayout';
|
||||
import { getDropHandoffTimeMs } from './physicalItemMotion';
|
||||
import { receiverContains } from './receiverVolumes';
|
||||
import { classifyItem } from './classifier';
|
||||
import { resolveItem } from '../data/resolveItem';
|
||||
|
||||
beforeAll(async () => {
|
||||
await initRapier();
|
||||
});
|
||||
|
||||
function repeatDrops(sku: string, zone: 'B' | 'C' | 'D', n: number): DropSimResult[] {
|
||||
return Array.from({ length: n }, () => simulateDrop(sku, zone));
|
||||
}
|
||||
|
||||
function expectDeterministic(results: DropSimResult[]) {
|
||||
const first = results[0];
|
||||
for (const r of results) {
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
expect(Math.abs(r.finalPosition[i] - first.finalPosition[i])).toBeLessThan(1e-9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function expectPhysicallyPlausible(r: DropSimResult) {
|
||||
// Ballistic flight actually happened (not teleport): real speed, real fall time
|
||||
expect(r.maxSpeedMps).toBeGreaterThan(0.8);
|
||||
expect(r.stepsSimulated).toBeGreaterThan(30); // > 0.5 s of simulated fall
|
||||
// Never passed through the belt/floor (translation-based clearance guard)
|
||||
expect(r.minClearanceM).toBeGreaterThan(-0.03);
|
||||
}
|
||||
|
||||
describe('Stage 2 §18.1–4 — route correctness, 10/10 per route', () => {
|
||||
it('box route B — 10 repeats all in B, deterministic', () => {
|
||||
const results = repeatDrops('SKU-001', 'B', 10);
|
||||
for (const r of results) {
|
||||
expect(r.insideExpectedReceiver).toBe(true);
|
||||
expectPhysicallyPlausible(r);
|
||||
}
|
||||
expectDeterministic(results);
|
||||
});
|
||||
|
||||
it('oversized carton route C — 10/10 in C', () => {
|
||||
const results = repeatDrops('SKU-004', 'C', 10);
|
||||
for (const r of results) {
|
||||
expect(r.insideExpectedReceiver).toBe(true);
|
||||
expectPhysicallyPlausible(r);
|
||||
}
|
||||
expectDeterministic(results);
|
||||
});
|
||||
|
||||
it('plate route D — 10/10 in D, no floor penetration', () => {
|
||||
const results = repeatDrops('SKU-006', 'D', 10);
|
||||
for (const r of results) {
|
||||
expect(r.insideExpectedReceiver).toBe(true);
|
||||
expectPhysicallyPlausible(r);
|
||||
}
|
||||
expectDeterministic(results);
|
||||
});
|
||||
|
||||
it('bottle route D — 10/10 in D, rotates during fall', () => {
|
||||
const results = repeatDrops('SKU-007', 'D', 10);
|
||||
for (const r of results) {
|
||||
expect(r.insideExpectedReceiver).toBe(true);
|
||||
expectPhysicallyPlausible(r);
|
||||
expect(r.totalRotationRad).toBeGreaterThan(0.5); // distinguishable from box slide
|
||||
}
|
||||
expectDeterministic(results);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Stage 2 §18.5–6 — distinct item behaviors', () => {
|
||||
it('cylinder rolls (large integrated rotation) but stays in D receiver', () => {
|
||||
const r = simulateDrop('SKU-008', 'D');
|
||||
expect(r.insideExpectedReceiver).toBe(true);
|
||||
expect(r.totalRotationRad).toBeGreaterThan(1.5);
|
||||
});
|
||||
|
||||
it('pen (light, fast-spinning) never tunnels through colliders', () => {
|
||||
const r = simulateDrop('SKU-009', 'C');
|
||||
expect(r.insideExpectedReceiver).toBe(true);
|
||||
expect(r.minClearanceM).toBeGreaterThan(-0.03);
|
||||
expect(r.totalRotationRad).toBeGreaterThan(0.3);
|
||||
});
|
||||
|
||||
it('pouf (large, heavy) rotates slower than the pen', () => {
|
||||
const pouf = simulateDrop('SKU-011', 'C');
|
||||
const pen = simulateDrop('SKU-009', 'C');
|
||||
expect(pouf.insideExpectedReceiver).toBe(true);
|
||||
expect(pouf.totalRotationRad).toBeLessThan(pen.totalRotationRad + 2.0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Stage 2 §18.7–8 — fault scenarios create no physics impulses', () => {
|
||||
it('jam case: no physics handoff (item held at junction by domain)', () => {
|
||||
expect(getDropHandoffTimeMs('C', 'jam')).toBeNull();
|
||||
});
|
||||
|
||||
it('emergency stop case: no physics handoff (no new impulses)', () => {
|
||||
expect(getDropHandoffTimeMs('B', 'emergency_stop')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Stage 2 §18.9–10 — replay reset and no body leaks', () => {
|
||||
it('fresh worlds give bit-identical drops (replay determinism)', () => {
|
||||
const a = simulateDrop('SKU-001', 'B');
|
||||
const b = simulateDrop('SKU-001', 'B');
|
||||
expect(a.finalPosition).toEqual(b.finalPosition);
|
||||
expect(a.finalQuaternion).toEqual(b.finalQuaternion);
|
||||
});
|
||||
|
||||
it('10 drop cycles in one world leave no body/collider leak', () => {
|
||||
const world = new RAPIER.World({ x: 0, y: -9.81, z: 0 });
|
||||
try {
|
||||
const baseline = world.bodies.len();
|
||||
for (let i = 0; i < 10; i += 1) {
|
||||
const body = world.createRigidBody(
|
||||
RAPIER.RigidBodyDesc.dynamic().setTranslation(0, 2, 0),
|
||||
);
|
||||
world.createCollider(RAPIER.ColliderDesc.cuboid(0.1, 0.1, 0.1), body);
|
||||
for (let s = 0; s < 30; s += 1) world.step();
|
||||
world.removeRigidBody(body);
|
||||
expect(world.bodies.len()).toBe(baseline);
|
||||
}
|
||||
// Static layout colliders can be created and freed cleanly too
|
||||
for (const c of getStaticColliders()) {
|
||||
world.createCollider(
|
||||
RAPIER.ColliderDesc.cuboid(...c.halfExtents).setTranslation(...c.position),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
world.free();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Stage 2 §18.11–12 — domain result authority', () => {
|
||||
it('classifier result is unchanged by the physics layer', () => {
|
||||
expect(classifyItem(resolveItem('SKU-001')).category).toBe('B');
|
||||
expect(classifyItem(resolveItem('SKU-004')).category).toBe('C');
|
||||
expect(classifyItem(resolveItem('SKU-006')).category).toBe('D');
|
||||
});
|
||||
|
||||
it('wrong-receiver drops are detected, never silently "fixed"', () => {
|
||||
// Deliberately reversed pusher direction: bottle aimed away from D.
|
||||
const bad = simulateDrop('SKU-007', 'D', { linvelScale: -1 });
|
||||
expect(bad.insideExpectedReceiver).toBe(false);
|
||||
expect(receiverContains('D', bad.finalPosition)).toBe(false);
|
||||
});
|
||||
});
|
||||
184
src/domain/physicsDropSim.ts
Normal file
184
src/domain/physicsDropSim.ts
Normal file
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* Stage 2 §11/§18 — headless drop simulator (Node / vitest, no React).
|
||||
*
|
||||
* Reproduces EXACTLY the runtime physics handoff from
|
||||
* PhysicalPlaybackItemPhysics:
|
||||
* same static colliders (domain/physicsWorldLayout),
|
||||
* same per-SKU colliders + density + friction + restitution (visualPhysicsProfiles),
|
||||
* same handoff pose (getPhysicalItemPose at the same handoff fraction),
|
||||
* same deterministic initial velocities,
|
||||
* same settle rule (sleep or controlled timeout) and the same
|
||||
* domain-receiver verification (receiverVolumes).
|
||||
*
|
||||
* Deterministic: fixed timestep 1/60, identical initial conditions, no RNG.
|
||||
*/
|
||||
|
||||
import RAPIER from '@dimforge/rapier3d-compat';
|
||||
import { getStaticColliders } from './physicsWorldLayout';
|
||||
import { getVisualPhysicsProfile, type VisualPhysicsProfile } from './visualPhysicsProfiles';
|
||||
import { getPhysicalItemPose, getDropHandoffTimeMs } from './physicalItemMotion';
|
||||
import { receiverContains, type ReceiverZone } from './receiverVolumes';
|
||||
import { resolveItem } from '../data/resolveItem';
|
||||
import { BELT_TOP_Y } from './physicalLayout';
|
||||
|
||||
export const SIM_DT = 1 / 60;
|
||||
export const SIM_SETTLE_SECONDS = 6.0;
|
||||
|
||||
let rapierReady = false;
|
||||
export async function initRapier(): Promise<void> {
|
||||
if (!rapierReady) {
|
||||
await RAPIER.init();
|
||||
rapierReady = true;
|
||||
}
|
||||
}
|
||||
|
||||
type Quat = { x: number; y: number; z: number; w: number };
|
||||
|
||||
/** three.js Euler XYZ order → quaternion (same math as THREE.Quaternion.setFromEuler). */
|
||||
function quatFromEuler(x: number, y: number, z: number): Quat {
|
||||
const c1 = Math.cos(x / 2); const c2 = Math.cos(y / 2); const c3 = Math.cos(z / 2);
|
||||
const s1 = Math.sin(x / 2); const s2 = Math.sin(y / 2); const s3 = Math.sin(z / 2);
|
||||
return {
|
||||
x: s1 * c2 * c3 + c1 * s2 * s3,
|
||||
y: c1 * s2 * c3 - s1 * c2 * s3,
|
||||
z: c1 * c2 * s3 + s1 * s2 * c3,
|
||||
w: c1 * c2 * c3 - s1 * s2 * s3,
|
||||
};
|
||||
}
|
||||
|
||||
function colliderDescFor(profile: VisualPhysicsProfile): RAPIER.ColliderDesc {
|
||||
let desc: RAPIER.ColliderDesc;
|
||||
if (profile.collider === 'cuboid' && profile.cuboidHalfExtents) {
|
||||
const [hx, hy, hz] = profile.cuboidHalfExtents;
|
||||
desc = RAPIER.ColliderDesc.cuboid(hx, hy, hz);
|
||||
desc.setDensity(profile.approximateMassKg / (8 * hx * hy * hz));
|
||||
} else if (profile.collider === 'capsule' && profile.capsule) {
|
||||
const [r, hh] = profile.capsule;
|
||||
desc = RAPIER.ColliderDesc.capsule(hh, r);
|
||||
desc.setDensity(profile.approximateMassKg / (Math.PI * r * r * (2 * hh + (4 / 3) * r)));
|
||||
} else {
|
||||
const [r, hh] = profile.capsule ?? [0.05, 0.1];
|
||||
desc = RAPIER.ColliderDesc.cylinder(hh, r);
|
||||
desc.setDensity(profile.approximateMassKg / (Math.PI * r * r * 2 * hh));
|
||||
}
|
||||
desc.setFriction(profile.friction);
|
||||
desc.setRestitution(profile.restitution);
|
||||
return desc;
|
||||
}
|
||||
|
||||
/** Handoff state mirroring PhysicalPlaybackItemPhysics: same pose, same velocities. */
|
||||
function handoffState(skuId: string, category: ReceiverZone) {
|
||||
const profile = getVisualPhysicsProfile(skuId);
|
||||
const item = resolveItem(skuId);
|
||||
const handoffMs = getDropHandoffTimeMs(category, undefined);
|
||||
if (handoffMs == null) throw new Error(`no handoff for ${skuId}/${category}`);
|
||||
const pose = getPhysicalItemPose({
|
||||
caseId: `sim_${skuId}_${category}`,
|
||||
slotIndex: 0,
|
||||
dimensionsMm: item.dimensionsMm,
|
||||
targetCategory: category,
|
||||
elapsedMs: handoffMs,
|
||||
faultType: undefined,
|
||||
});
|
||||
const h = item.dimensionsMm.height / 1000;
|
||||
const dirZ = category === 'D' ? -1 : 1;
|
||||
const linvel = category === 'B'
|
||||
? { x: 1.0, y: 0, z: 0 }
|
||||
: { x: 0.55, y: 0, z: dirZ * 1.35 * profile.pusherImpulseScale };
|
||||
const angvel = profile.canRoll
|
||||
? { x: category === 'B' ? 2.0 : 0.8, y: 0.4, z: 0 }
|
||||
: { x: 0, y: 0.25, z: 0 };
|
||||
return { profile, pose, linvel, angvel, itemHeightM: h };
|
||||
}
|
||||
|
||||
export interface DropSimResult {
|
||||
skuId: string;
|
||||
expectedZone: ReceiverZone;
|
||||
finalPosition: [number, number, number];
|
||||
finalQuaternion: [number, number, number, number];
|
||||
insideExpectedReceiver: boolean;
|
||||
settledBySleep: boolean;
|
||||
settledByTimeout: boolean;
|
||||
stepsSimulated: number;
|
||||
/** Lowest belt/floor clearance observed (translation.y - itemHalfHeight). */
|
||||
minClearanceM: number;
|
||||
/** Integrated |angvel| over the drop — distinguishes rolling from teleport-like slides. */
|
||||
totalRotationRad: number;
|
||||
/** Max speed during flight — proves ballistic motion, not teleportation. */
|
||||
maxSpeedMps: number;
|
||||
}
|
||||
|
||||
export function simulateDrop(
|
||||
skuId: string,
|
||||
category: ReceiverZone,
|
||||
overrides?: { linvelScale?: number },
|
||||
): DropSimResult {
|
||||
const { profile, pose, linvel, angvel, itemHeightM } = handoffState(skuId, category);
|
||||
const scale = overrides?.linvelScale ?? 1;
|
||||
|
||||
const world = new RAPIER.World({ x: 0, y: -9.81, z: 0 });
|
||||
world.timestep = SIM_DT;
|
||||
try {
|
||||
for (const c of getStaticColliders()) {
|
||||
const q = quatFromEuler(c.rotation[0], c.rotation[1], c.rotation[2]);
|
||||
const desc = RAPIER.ColliderDesc.cuboid(c.halfExtents[0], c.halfExtents[1], c.halfExtents[2])
|
||||
.setTranslation(c.position[0], c.position[1], c.position[2])
|
||||
.setRotation(q)
|
||||
.setFriction(c.friction);
|
||||
world.createCollider(desc);
|
||||
}
|
||||
|
||||
const q = quatFromEuler(pose.rotation[0], pose.rotation[1], pose.rotation[2]);
|
||||
const bodyDesc = RAPIER.RigidBodyDesc.dynamic()
|
||||
.setTranslation(pose.position[0], pose.position[1], pose.position[2])
|
||||
.setRotation(q)
|
||||
.setLinvel(linvel.x * scale, linvel.y * scale, linvel.z * scale)
|
||||
.setAngvel(angvel)
|
||||
.setLinearDamping(profile.linearDamping)
|
||||
.setAngularDamping(profile.angularDamping)
|
||||
.setCcdEnabled(profile.approximateMassKg < 0.05); // same rule as runtime (pen)
|
||||
const body = world.createRigidBody(bodyDesc);
|
||||
world.createCollider(colliderDescFor(profile), body);
|
||||
|
||||
const halfH = itemHeightM / 2;
|
||||
let minClearance = Infinity;
|
||||
let totalRotation = 0;
|
||||
let maxSpeed = 0;
|
||||
let steps = 0;
|
||||
let slept = false;
|
||||
const maxSteps = Math.round(SIM_SETTLE_SECONDS / SIM_DT);
|
||||
for (let i = 0; i < maxSteps; i += 1) {
|
||||
world.step();
|
||||
steps += 1;
|
||||
const t = body.translation();
|
||||
const v = body.linvel();
|
||||
const w = body.angvel();
|
||||
minClearance = Math.min(minClearance, t.y - halfH);
|
||||
totalRotation += Math.hypot(w.x, w.y, w.z) * SIM_DT;
|
||||
maxSpeed = Math.max(maxSpeed, Math.hypot(v.x, v.y, v.z));
|
||||
if (i > 12 && body.isSleeping()) { slept = true; break; }
|
||||
}
|
||||
|
||||
const t = body.translation();
|
||||
const r = body.rotation();
|
||||
const p: [number, number, number] = [t.x, t.y, t.z];
|
||||
return {
|
||||
skuId,
|
||||
expectedZone: category,
|
||||
finalPosition: p,
|
||||
finalQuaternion: [r.x, r.y, r.z, r.w],
|
||||
insideExpectedReceiver: receiverContains(category, p),
|
||||
settledBySleep: slept,
|
||||
settledByTimeout: !slept,
|
||||
stepsSimulated: steps,
|
||||
minClearanceM: minClearance,
|
||||
totalRotationRad: totalRotation,
|
||||
maxSpeedMps: maxSpeed,
|
||||
};
|
||||
} finally {
|
||||
world.free();
|
||||
}
|
||||
}
|
||||
|
||||
/** Drop starting height above the belt (for reporting). */
|
||||
export { BELT_TOP_Y };
|
||||
128
src/domain/physicsWorldLayout.ts
Normal file
128
src/domain/physicsWorldLayout.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Stage 2 — single source of truth for static physics colliders.
|
||||
*
|
||||
* Pure data (no React, no Rapier): consumed by
|
||||
* - SorterStaticColliders (runtime, @react-three/rapier CuboidColliders);
|
||||
* - physicsDropSim (headless Node validation with rapier3d-compat).
|
||||
*
|
||||
* Geometry contract (visual == collider == domain kinematic surface):
|
||||
* - C/D gravity chutes follow the domain chute line (conveyorNetwork
|
||||
* CHUTE_C/D_ENTRY -> EXIT): from belt edge y=0.66 down to cage front edge
|
||||
* y=0.14 — real gravity-chute pitch ~0.39 rad (smooth coated steel,
|
||||
* friction 0.2), not a gentle ramp where items would stall.
|
||||
* - Cage C/D entry side is OPEN (real roll cages are 3-sided + open front)
|
||||
* with a 40mm sill; the chute deposits items through the open front.
|
||||
* - B drop chute descends from spur end (2.15, 0.70) into the open front of
|
||||
* the B receiver bin (past its low entry lip).
|
||||
* Every collider mirrors VISIBLE scene geometry — no fake guides (§11.6).
|
||||
*/
|
||||
|
||||
import { ZONES, B_RECEIVER, ROLL_CAGE, CONVEYOR_WIDTH_M, BELT_TOP_Y, CAGE_FLOOR_Y } from './physicalLayout';
|
||||
|
||||
export interface StaticColliderDef {
|
||||
id: string;
|
||||
halfExtents: [number, number, number];
|
||||
position: [number, number, number];
|
||||
/** Euler XYZ radians. */
|
||||
rotation: [number, number, number];
|
||||
friction: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* C/D chute pitch: line from (z=±0.35, y=0.66) to (z=±1.6, y=0.14).
|
||||
* tan = 0.52/1.25 ≈ 0.416 > μ_combined for every SKU profile -> items slide.
|
||||
*/
|
||||
export const CHUTE_PITCH = Math.atan2(0.52, 1.25); // ≈ 0.394 rad
|
||||
export const CHUTE_LENGTH = Math.hypot(1.25, 0.52); // ≈ 1.354 m
|
||||
export const CHUTE_MID_Y = 0.40;
|
||||
export const CHUTE_MID_Z = 0.975;
|
||||
/** Chute plate center X (gate exit) and plate half width. */
|
||||
export const CHUTE_X = ZONES.GATE.x + 0.3;
|
||||
export const CHUTE_HALF_W = 0.25;
|
||||
/** B drop chute: line from (2.15, 0.70) to (2.85, 0.13), pitch ≈ 0.684 rad. */
|
||||
export const B_CHUTE_PITCH = Math.atan2(BELT_TOP_Y - (CAGE_FLOOR_Y + 0.05), 0.7);
|
||||
|
||||
function chuteColliders(targetZ: number, label: 'C' | 'D'): StaticColliderDef[] {
|
||||
const dir = targetZ > 0 ? 1 : -1;
|
||||
const midZ = dir * CHUTE_MID_Z;
|
||||
const rot: [number, number, number] = [dir * CHUTE_PITCH, 0, 0];
|
||||
return [
|
||||
{
|
||||
id: `chute-${label}-floor`,
|
||||
halfExtents: [CHUTE_HALF_W, 0.01, CHUTE_LENGTH / 2],
|
||||
// top surface: y≈0.655 at belt edge (z 0.35) -> 0.135 at cage edge (z 1.6)
|
||||
position: [CHUTE_X, CHUTE_MID_Y - 0.015, midZ],
|
||||
rotation: rot,
|
||||
friction: 0.2, // smooth coated steel — gravity chute (VISUAL_PHYSICS_ESTIMATE)
|
||||
},
|
||||
{
|
||||
id: `chute-${label}-rail-left`,
|
||||
halfExtents: [0.01, 0.035, CHUTE_LENGTH / 2],
|
||||
position: [CHUTE_X - CHUTE_HALF_W - 0.01, CHUTE_MID_Y + 0.03, midZ],
|
||||
rotation: rot,
|
||||
friction: 0.3,
|
||||
},
|
||||
{
|
||||
id: `chute-${label}-rail-right`,
|
||||
halfExtents: [0.01, 0.035, CHUTE_LENGTH / 2],
|
||||
position: [CHUTE_X + CHUTE_HALF_W + 0.01, CHUTE_MID_Y + 0.03, midZ],
|
||||
rotation: rot,
|
||||
friction: 0.3,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function receiverColliders(): StaticColliderDef[] {
|
||||
const bin = B_RECEIVER;
|
||||
const hx = bin.width / 2;
|
||||
const hz = bin.depth / 2;
|
||||
const cage = ROLL_CAGE;
|
||||
const chx = cage.width / 2;
|
||||
const chz = cage.depth / 2;
|
||||
const defs: StaticColliderDef[] = [
|
||||
// B bin: floor + 3 walls + low entry lip (mirrors BReceiverBin visuals —
|
||||
// open front on the chute side, no hidden wall)
|
||||
{ id: 'b-bin-floor', halfExtents: [hx, 0.02, hz], position: [bin.centerX, bin.floorY - 0.02, bin.centerZ], rotation: [0, 0, 0], friction: 0.8 },
|
||||
{ id: 'b-bin-wall-z+', halfExtents: [hx, bin.wallHeight / 2, 0.015], position: [bin.centerX, bin.floorY + bin.wallHeight / 2, bin.centerZ + hz], rotation: [0, 0, 0], friction: 0.6 },
|
||||
{ id: 'b-bin-wall-z-', halfExtents: [hx, bin.wallHeight / 2, 0.015], position: [bin.centerX, bin.floorY + bin.wallHeight / 2, bin.centerZ - hz], rotation: [0, 0, 0], friction: 0.6 },
|
||||
{ id: 'b-bin-wall-x+', halfExtents: [0.015, bin.wallHeight / 2, hz], position: [bin.centerX + hx, bin.floorY + bin.wallHeight / 2, bin.centerZ], rotation: [0, 0, 0], friction: 0.6 },
|
||||
{ id: 'b-bin-entry-lip', halfExtents: [0.015, 0.04, hz], position: [bin.centerX - hx, bin.floorY + 0.04, bin.centerZ], rotation: [0, 0, 0], friction: 0.6 },
|
||||
];
|
||||
const entryX = bin.centerX - hx + 0.1;
|
||||
const chuteLen = Math.hypot(entryX - bin.transferEndX, BELT_TOP_Y - bin.floorY);
|
||||
defs.push({
|
||||
id: 'b-drop-chute',
|
||||
halfExtents: [chuteLen / 2, 0.008, (CONVEYOR_WIDTH_M - 0.08) / 2],
|
||||
// top surface runs (2.15, 0.696) -> (2.85, 0.126): flush with spur end
|
||||
position: [(bin.transferEndX + entryX) / 2, 0.395, bin.centerZ],
|
||||
rotation: [0, 0, -B_CHUTE_PITCH], // descends toward +X (into the bin)
|
||||
friction: 0.25,
|
||||
});
|
||||
for (const [label, zone] of [['C', ZONES.C], ['D', ZONES.D]] as const) {
|
||||
const entrySide = label === 'C' ? -1 : 1; // open front faces the conveyor
|
||||
defs.push(
|
||||
{ id: `cage-${label}-floor`, halfExtents: [chx, 0.04, chz], position: [zone.x, 0.04, zone.z], rotation: [0, 0, 0], friction: 0.8 },
|
||||
{ id: `cage-${label}-wall-x-`, halfExtents: [0.02, cage.height / 2, chz], position: [zone.x - chx, cage.height / 2, zone.z], rotation: [0, 0, 0], friction: 0.5 },
|
||||
{ id: `cage-${label}-wall-x+`, halfExtents: [0.02, cage.height / 2, chz], position: [zone.x + chx, cage.height / 2, zone.z], rotation: [0, 0, 0], friction: 0.5 },
|
||||
// closed back wall (far side from the conveyor)
|
||||
{ id: `cage-${label}-wall-back`, halfExtents: [chx, cage.height / 2, 0.02], position: [zone.x, cage.height / 2, zone.z - entrySide * chz], rotation: [0, 0, 0], friction: 0.5 },
|
||||
// 40mm sill on the open entry side (mirrors RollCageMesh openSide sill)
|
||||
{ id: `cage-${label}-entry-sill`, halfExtents: [chx, 0.02, 0.015], position: [zone.x, CAGE_FLOOR_Y + 0.02, zone.z + entrySide * chz], rotation: [0, 0, 0], friction: 0.5 },
|
||||
);
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
export function getStaticColliders(): StaticColliderDef[] {
|
||||
return [
|
||||
{ id: 'world-floor', halfExtents: [8, 0.05, 6], position: [0, -0.05, 0], rotation: [0, 0, 0], friction: 0.8 },
|
||||
// Belt safety slab — items never pass through the belt surface.
|
||||
// Ends at the B spur end (2.15): beyond it the B drop chute takes over.
|
||||
{ id: 'belt-slab', halfExtents: [(2.15 + 4.2) / 2, 0.012, CONVEYOR_WIDTH_M / 2], position: [(2.15 - 4.2) / 2, BELT_TOP_Y - 0.014, 0], rotation: [0, 0, 0], friction: 0.7 },
|
||||
// B transfer spur
|
||||
{ id: 'b-spur', halfExtents: [0.325, 0.02, (CONVEYOR_WIDTH_M - 0.06) / 2], position: [1.825, BELT_TOP_Y - 0.02, 0], rotation: [0, 0, 0], friction: 0.4 },
|
||||
...chuteColliders(ZONES.C.z, 'C'),
|
||||
...chuteColliders(ZONES.D.z, 'D'),
|
||||
...receiverColliders(),
|
||||
];
|
||||
}
|
||||
@@ -51,7 +51,7 @@ const PRESETS: Record<QualityMode, QualitySettings> = {
|
||||
mode: 'demo',
|
||||
dprMax: 1.5,
|
||||
antialias: true,
|
||||
shadows: false, // contact shadows via mesh only — stable demo FPS
|
||||
shadows: true, // Stage 2: PCFSoft contact shadows in the default premium look
|
||||
maxVisibleItems: 6,
|
||||
effectsEnabled: false,
|
||||
rollerDetail: 'full',
|
||||
|
||||
24
src/domain/receiverVolumes.ts
Normal file
24
src/domain/receiverVolumes.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Stage 2 — domain-decided receiver volumes (single source of truth).
|
||||
*
|
||||
* Used by the runtime physics handoff (PhysicalPlaybackItemPhysics) and the
|
||||
* headless validation sim (physicsDropSim) to verify that a settled body
|
||||
* landed in the receiver the DOMAIN classifier chose (Stage 2 §11.7).
|
||||
* The classifier result is never influenced by physics — this only verifies.
|
||||
*/
|
||||
|
||||
import { ZONES, B_RECEIVER, ROLL_CAGE } from './physicalLayout';
|
||||
|
||||
export type ReceiverZone = 'B' | 'C' | 'D';
|
||||
|
||||
export function receiverContains(zone: ReceiverZone, p: [number, number, number]): boolean {
|
||||
const [x, y, z] = p;
|
||||
if (y < 0.01 || y > 1.2) return false;
|
||||
if (zone === 'B') {
|
||||
const b = B_RECEIVER;
|
||||
return Math.abs(x - b.centerX) <= b.width / 2 + 0.05 && Math.abs(z - b.centerZ) <= b.depth / 2 + 0.05;
|
||||
}
|
||||
const cage = zone === 'C' ? ZONES.C : ZONES.D;
|
||||
return Math.abs(x - cage.x) <= ROLL_CAGE.width / 2 + 0.05
|
||||
&& Math.abs(z - cage.z) <= ROLL_CAGE.depth / 2 + 0.05;
|
||||
}
|
||||
99
src/domain/sorterVisualState.ts
Normal file
99
src/domain/sorterVisualState.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Stage 2 — sorterVisualState adapter.
|
||||
*
|
||||
* Single mapping layer: domain playback state -> visual mechanism commands +
|
||||
* physics handoff. Business logic (classifier, playlist, phase machine) stays
|
||||
* the only source of truth; this adapter NEVER decides categories or routes —
|
||||
* it projects domain decisions into beltVelocity / gate / pusher / physics
|
||||
* authority for the 3D layer (mirrors the playbackToSimulation pattern).
|
||||
*/
|
||||
|
||||
import type { Category } from './types';
|
||||
import type { CasePhase, ContinuousPlaybackState } from './continuousPlayback';
|
||||
import { CONVEYOR_SPEED_MPS } from './physicalLayout';
|
||||
|
||||
export type GatePhase = 'closed' | 'hold-open';
|
||||
export type ScanState = 'idle' | 'detecting' | 'measuring';
|
||||
export type AlarmState = 'none' | 'fault' | 'estop';
|
||||
export type ItemAuthority = 'domain' | 'physics';
|
||||
|
||||
export interface SorterVisualState {
|
||||
/** Belt linear velocity m/s (0 when paused/fault/e-stop). */
|
||||
beltVelocityMps: number;
|
||||
/** Roller angular velocity rad/s = v / r (r = 25 mm CAD roller). */
|
||||
rollerOmegaRadPerSec: number;
|
||||
/** Stop-gate / metering barrier state (CAD barriers on the junction). */
|
||||
gatePhase: GatePhase;
|
||||
gateOpen: boolean;
|
||||
/** Pusher/diverter servo command. */
|
||||
pusher: { active: boolean; category: Category | null };
|
||||
/** Measurement rig state for camera/laser visualization. */
|
||||
scanState: ScanState;
|
||||
alarmState: AlarmState;
|
||||
/** Domain-decided target (never physics-decided). */
|
||||
targetZone: Category | null;
|
||||
expectedLandingZone: 'B' | 'C' | 'D' | null;
|
||||
/**
|
||||
* Item authority: 'domain' while the item pose is kinematic
|
||||
* (getPhysicalItemPose), 'physics' after the drop handoff
|
||||
* (routing phase, on chute surface).
|
||||
*/
|
||||
itemAuthority: ItemAuthority;
|
||||
/**
|
||||
* Case-time fraction within the routing phase at which authority
|
||||
* transfers to physics (pusher contact / belt edge). B: 0.35 (end of
|
||||
* b_transfer spur); C/D: 0.06 (pusher contact at gate exit).
|
||||
*/
|
||||
dropHandoffFraction: number;
|
||||
}
|
||||
|
||||
/** Phases in which the post-inspection metering gate is open (item released from inspection). */
|
||||
const GATE_OPEN_PHASES: ReadonlySet<CasePhase> = new Set([
|
||||
'measurement', 'classification', 'command_sent', 'routing', 'exit', 'clear_gap', 'recover',
|
||||
]);
|
||||
const FAULT_PHASES: ReadonlySet<CasePhase> = new Set(['fault_hold', 'emergency_hold']);
|
||||
|
||||
export function deriveSorterVisualState(playback: ContinuousPlaybackState): SorterVisualState {
|
||||
const phase = playback.currentPhase;
|
||||
const category = playback.targetCategory;
|
||||
const running = playback.status === 'running';
|
||||
const fault = phase === 'fault_hold';
|
||||
const estop = phase === 'emergency_hold';
|
||||
const halted = !running || fault || estop || playback.currentCase.faultType != null && FAULT_PHASES.has(phase);
|
||||
|
||||
const beltVelocity = halted ? 0 : CONVEYOR_SPEED_MPS * playback.speed;
|
||||
const gateOpen = !fault && !estop && GATE_OPEN_PHASES.has(phase);
|
||||
|
||||
let itemAuthority: ItemAuthority = 'domain';
|
||||
let dropHandoffFraction = 1.1; // unreachable by default (no physics handoff)
|
||||
if (!playback.currentCase.faultType && phase === 'routing' && category) {
|
||||
dropHandoffFraction = category === 'B' ? 0.35 : 0.12;
|
||||
itemAuthority = 'physics';
|
||||
}
|
||||
|
||||
return {
|
||||
beltVelocityMps: beltVelocity,
|
||||
rollerOmegaRadPerSec: beltVelocity / 0.025,
|
||||
gatePhase: gateOpen ? 'hold-open' : 'closed',
|
||||
gateOpen,
|
||||
pusher: {
|
||||
active: !fault && !estop && (phase === 'routing' || phase === 'exit') && (category === 'C' || category === 'D'),
|
||||
category: category === 'C' || category === 'D' ? category : null,
|
||||
},
|
||||
scanState: phase === 'detection' ? 'detecting' : phase === 'measurement' ? 'measuring' : 'idle',
|
||||
alarmState: estop ? 'estop' : fault ? 'fault' : 'none',
|
||||
targetZone: category,
|
||||
expectedLandingZone: category,
|
||||
itemAuthority,
|
||||
dropHandoffFraction,
|
||||
};
|
||||
}
|
||||
|
||||
/** Case-time (ms) at which the current item is handed to physics, if any. */
|
||||
export function dropHandoffCaseTimeMs(playback: ContinuousPlaybackState, phaseStarts: Record<string, number>, routingDurationMs: number): number | null {
|
||||
const vs = deriveSorterVisualState(playback);
|
||||
if (vs.dropHandoffFraction > 1) return null;
|
||||
const routingStart = phaseStarts['routing'];
|
||||
if (routingStart == null) return null;
|
||||
return routingStart + vs.dropHandoffFraction * routingDurationMs;
|
||||
}
|
||||
98
src/domain/visualPhysicsProfiles.ts
Normal file
98
src/domain/visualPhysicsProfiles.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Stage 2 — visual physics profiles per SKU.
|
||||
*
|
||||
* ALL values are VISUAL_PHYSICS_ESTIMATE: they are tuned for physically
|
||||
* plausible drop/roll/rest behavior in the digital twin. They are NOT
|
||||
* certified masses or dynamics data from the manufacturer.
|
||||
*/
|
||||
|
||||
export type ColliderKind = 'cuboid' | 'capsule' | 'cylinder';
|
||||
|
||||
export interface VisualPhysicsProfile {
|
||||
sku: string;
|
||||
/** VISUAL_PHYSICS_ESTIMATE kg */
|
||||
approximateMassKg: number;
|
||||
friction: number;
|
||||
restitution: number;
|
||||
linearDamping: number;
|
||||
angularDamping: number;
|
||||
collider: ColliderKind;
|
||||
/**
|
||||
* Collider half-extents [x,y,z] for cuboid; [radius, halfHeight] for
|
||||
* capsule/cylinder. Derived from validated Stage 1 dimensions (m).
|
||||
*/
|
||||
cuboidHalfExtents?: [number, number, number];
|
||||
capsule?: [number, number];
|
||||
/** Vertical center-of-mass offset factor (-0.5..0.5 of height). */
|
||||
centerOfMassOffsetY: number;
|
||||
/** Multiplier on pusher impulse for C/D routing (light items fly further). */
|
||||
pusherImpulseScale: number;
|
||||
/** True for items expected to roll (cylinder/bottle). */
|
||||
canRoll: boolean;
|
||||
}
|
||||
|
||||
const PROFILES: Record<string, VisualPhysicsProfile> = {
|
||||
'SKU-001': { // cardboard box 300x200x200
|
||||
sku: 'SKU-001', approximateMassKg: 0.8, friction: 0.55, restitution: 0.15,
|
||||
linearDamping: 0.2, angularDamping: 0.4, collider: 'cuboid',
|
||||
cuboidHalfExtents: [0.15, 0.1, 0.1], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 1.0, canRoll: false,
|
||||
},
|
||||
'SKU-002': { // lunchbox 280x180x120 — rigid box behavior
|
||||
sku: 'SKU-002', approximateMassKg: 0.6, friction: 0.5, restitution: 0.2,
|
||||
linearDamping: 0.2, angularDamping: 0.4, collider: 'cuboid',
|
||||
cuboidHalfExtents: [0.14, 0.06, 0.09], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 1.05, canRoll: false,
|
||||
},
|
||||
'SKU-004': { // oversized carton 900x200x500
|
||||
sku: 'SKU-004', approximateMassKg: 3.2, friction: 0.6, restitution: 0.1,
|
||||
linearDamping: 0.25, angularDamping: 0.5, collider: 'cuboid',
|
||||
cuboidHalfExtents: [0.45, 0.25, 0.1], centerOfMassOffsetY: -0.05,
|
||||
pusherImpulseScale: 0.75, canRoll: false,
|
||||
},
|
||||
'SKU-006': { // ceramic plate d260 h30 — thin cuboid
|
||||
sku: 'SKU-006', approximateMassKg: 0.55, friction: 0.45, restitution: 0.25,
|
||||
linearDamping: 0.15, angularDamping: 0.25, collider: 'cuboid',
|
||||
cuboidHalfExtents: [0.13, 0.015, 0.13], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 1.1, canRoll: false,
|
||||
},
|
||||
'SKU-007': { // bottle d90 h280 — capsule, rolls/spins, falls to side
|
||||
sku: 'SKU-007', approximateMassKg: 0.45, friction: 0.5, restitution: 0.35,
|
||||
linearDamping: 0.1, angularDamping: 0.15, collider: 'capsule',
|
||||
capsule: [0.045, 0.095], centerOfMassOffsetY: -0.04,
|
||||
pusherImpulseScale: 1.15, canRoll: true,
|
||||
},
|
||||
'SKU-008': { // cylinder d120 h200 — rolls
|
||||
sku: 'SKU-008', approximateMassKg: 1.4, friction: 0.45, restitution: 0.3,
|
||||
linearDamping: 0.08, angularDamping: 0.12, collider: 'cylinder',
|
||||
capsule: [0.06, 0.1], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 0.9, canRoll: true,
|
||||
},
|
||||
'SKU-009': { // pen 12x145x12 — light, spins fast
|
||||
sku: 'SKU-009', approximateMassKg: 0.02, friction: 0.4, restitution: 0.25,
|
||||
linearDamping: 0.1, angularDamping: 0.8, collider: 'capsule',
|
||||
capsule: [0.006, 0.066], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 1.3, canRoll: true,
|
||||
},
|
||||
'SKU-011': { // pouf d450 h400 — big, slow rotation
|
||||
sku: 'SKU-011', approximateMassKg: 2.8, friction: 0.6, restitution: 0.2,
|
||||
linearDamping: 0.4, angularDamping: 0.6, collider: 'cylinder',
|
||||
capsule: [0.225, 0.175], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 0.85, canRoll: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const DEFAULT_PHYSICS_PROFILE: VisualPhysicsProfile = {
|
||||
sku: 'default', approximateMassKg: 1.0, friction: 0.8, restitution: 0.2,
|
||||
linearDamping: 0.2, angularDamping: 0.4, collider: 'cuboid',
|
||||
cuboidHalfExtents: [0.15, 0.1, 0.1], centerOfMassOffsetY: 0,
|
||||
pusherImpulseScale: 1.0, canRoll: false,
|
||||
};
|
||||
|
||||
export function getVisualPhysicsProfile(itemId: string): VisualPhysicsProfile {
|
||||
return PROFILES[itemId] ?? DEFAULT_PHYSICS_PROFILE;
|
||||
}
|
||||
|
||||
export function allVisualPhysicsProfiles(): VisualPhysicsProfile[] {
|
||||
return Object.values(PROFILES);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { getViewportType, type ViewportType } from '../domain/cinematicCamera';
|
||||
import { detectQualityMode } from '../domain/qualityMode';
|
||||
import { parseStage0Config, collectDeviceSignals, choosePrototypeQuality } from '../domain/stage0';
|
||||
import { parseStage1Config } from '../domain/stage1';
|
||||
import { decideMobileTier, collectMobileSignals, MOBILE_MIN_FPS, MOBILE_FPS_SAMPLE_MS, type MobileTier } from '../domain/mobilePolicy';
|
||||
import { playbackToSimulation } from '../domain/playbackAdapter';
|
||||
import SorterScene from '../components/SorterScene';
|
||||
import { resolveItem } from '../data/resolveItem';
|
||||
@@ -123,11 +124,46 @@ export default function MainPage({
|
||||
[],
|
||||
);
|
||||
|
||||
// Stage 2 §13.6: technical HUD (speed, case dots, hotkeys, command rows)
|
||||
// is opt-in via ?debug=1; the default HUD stays presentation-clean.
|
||||
const debugMode = useMemo(() => {
|
||||
if (typeof window === 'undefined') return false;
|
||||
return new URLSearchParams(window.location.search).get('debug') === '1';
|
||||
}, []);
|
||||
|
||||
// Stage 2 §16: mobile tier from capability signals (not viewport width).
|
||||
const mobileTier: MobileTier = useMemo(() => decideMobileTier(collectMobileSignals()), []);
|
||||
// First-FPS watchdog: sustained low FPS on mobile drops to SVG permanently.
|
||||
const [mobileFpsDead, setMobileFpsDead] = useState(false);
|
||||
useEffect(() => {
|
||||
if (mobileTier !== 'mobile-low') return;
|
||||
const started = performance.now();
|
||||
let frames = 0;
|
||||
let raf = 0;
|
||||
const tick = () => {
|
||||
frames += 1;
|
||||
const elapsed = performance.now() - started;
|
||||
if (elapsed >= MOBILE_FPS_SAMPLE_MS) {
|
||||
const fps = (frames / elapsed) * 1000;
|
||||
if (fps < MOBILE_MIN_FPS) setMobileFpsDead(true);
|
||||
return;
|
||||
}
|
||||
raf = requestAnimationFrame(tick);
|
||||
};
|
||||
raf = requestAnimationFrame(tick);
|
||||
return () => cancelAnimationFrame(raf);
|
||||
}, [mobileTier]);
|
||||
|
||||
// NOTE: contextLost must NOT flip show3D — the canvas stays mounted (hidden)
|
||||
// during the recovery window so `webglcontextrestored` can actually arrive.
|
||||
// Default route: 3D only on >= 640px with WebGL (unchanged heuristic).
|
||||
// Prototype mode: 3D forced on any width so mobile GPU profiles can be measured.
|
||||
const show3D = stage0.enabled ? webgl : prefer3DByDefault(width, webgl);
|
||||
// Mobile policy: svg tier never mounts 3D; mobile-low mounts 3D at low quality.
|
||||
const show3D = stage0.enabled
|
||||
? webgl
|
||||
: mobileTier === 'svg'
|
||||
? false
|
||||
: mobileTier === 'mobile-low'
|
||||
? webgl && !mobileFpsDead
|
||||
: prefer3DByDefault(width, webgl);
|
||||
|
||||
// WebGL context recovery: on loss the canvas stays mounted (hidden) so a
|
||||
// real `webglcontextrestored` can arrive; exactly one safe retry is allowed,
|
||||
@@ -174,7 +210,11 @@ export default function MainPage({
|
||||
const deviceSignals = useMemo(() => collectDeviceSignals(), []);
|
||||
const qualityMode =
|
||||
qualityOverride ??
|
||||
(stage0.enabled ? choosePrototypeQuality(width, deviceSignals) : detectQualityMode(width));
|
||||
(stage0.enabled
|
||||
? choosePrototypeQuality(width, deviceSignals)
|
||||
: mobileTier === 'mobile-low'
|
||||
? 'low' // Mobile Low: DPR<=1.25, no shadows/post, 30 FPS target
|
||||
: detectQualityMode(width));
|
||||
const simplified = width < 900 || qualityMode === 'low';
|
||||
const viewportType: ViewportType = getViewportType(width);
|
||||
|
||||
@@ -281,10 +321,12 @@ export default function MainPage({
|
||||
{category ?? '—'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="hud-row">
|
||||
<span className="hud-label">Command</span>
|
||||
<span className="hud-value" data-testid="demo-command">{command}</span>
|
||||
</div>
|
||||
{debugMode && (
|
||||
<div className="hud-row">
|
||||
<span className="hud-label">Command</span>
|
||||
<span className="hud-value" data-testid="demo-command">{command}</span>
|
||||
</div>
|
||||
)}
|
||||
{playback.classification && (
|
||||
<div className="hud-row hud-row-small" data-testid="demo-proof">
|
||||
<span className="hud-value proof-text">
|
||||
@@ -293,25 +335,29 @@ export default function MainPage({
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="hud-row">
|
||||
<span className="hud-label">Speed</span>
|
||||
<span className="hud-value">{playback.speed.toFixed(1)}× · 1.0 m/s</span>
|
||||
</div>
|
||||
{debugMode && (
|
||||
<>
|
||||
<div className="hud-row">
|
||||
<span className="hud-label">Speed</span>
|
||||
<span className="hud-value">{playback.speed.toFixed(1)}× · 1.0 m/s</span>
|
||||
</div>
|
||||
<div className="hud-divider" />
|
||||
<div className="hud-row">
|
||||
<span className="hud-label">Case</span>
|
||||
<span className="hud-value" data-testid="demo-case-label">
|
||||
{playback.currentCaseIndex + 1}/{PLAYLIST_LENGTH}
|
||||
</span>
|
||||
</div>
|
||||
<div className="hud-row hud-row-small">
|
||||
<span className="hud-value">{currentCase.description}</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{playback.warning && (
|
||||
<div className="hud-row hud-warning">
|
||||
<span className="hud-value warning-text">⚠ {playback.warning}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="hud-divider" />
|
||||
<div className="hud-row">
|
||||
<span className="hud-label">Case</span>
|
||||
<span className="hud-value" data-testid="demo-case-label">
|
||||
{playback.currentCaseIndex + 1}/{PLAYLIST_LENGTH}
|
||||
</span>
|
||||
</div>
|
||||
<div className="hud-row hud-row-small">
|
||||
<span className="hud-value">{currentCase.description}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -322,7 +368,7 @@ export default function MainPage({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!presentationMode && (
|
||||
{!presentationMode && debugMode && (
|
||||
<div className="main-progress">
|
||||
{DEMO_PLAYLIST.map((c, idx) => (
|
||||
<button
|
||||
@@ -389,7 +435,7 @@ export default function MainPage({
|
||||
</button>
|
||||
)}
|
||||
|
||||
{!presentationMode && (
|
||||
{!presentationMode && debugMode && (
|
||||
<div className="speed-controls" role="group" aria-label="Playback speed">
|
||||
{SPEEDS.map((s) => (
|
||||
<button
|
||||
@@ -458,7 +504,9 @@ export default function MainPage({
|
||||
<Link to="/details" className="details-link">
|
||||
Details →
|
||||
</Link>
|
||||
<div className="hotkey-hint">Space play · N/B seek · 1–0 jump · R reset · P present · E log · F fullscreen</div>
|
||||
{debugMode && (
|
||||
<div className="hotkey-hint">Space play · N/B seek · 1–0 jump · R reset · P present · E log · F fullscreen</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user