perf(3d): static rollers, lite mode, B receiver bin timing, clean console
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Suspense, useMemo } from 'react';
|
||||
import { Suspense, memo, useEffect, useMemo } from 'react';
|
||||
import { getPhysicalItemPose } from '../../domain/physicalItemMotion';
|
||||
import { getModelAsset } from '../../data/modelAssets';
|
||||
import { ITEMS } from '../../data/items';
|
||||
@@ -25,7 +25,21 @@ const ITEM_MATERIALS: Record<string, { color: string; roughness: number; metalne
|
||||
'SKU-011': { color: '#cbd5e1', roughness: 0.35, metalness: 0.15 },
|
||||
};
|
||||
|
||||
function STLGeometry({ path, scale, color, accentColor, emissiveIntensity, roughness, metalness }: any) {
|
||||
interface RenderProps {
|
||||
color: string;
|
||||
accentColor: string;
|
||||
emissiveIntensity: number;
|
||||
roughness: number;
|
||||
metalness: number;
|
||||
}
|
||||
|
||||
// STL geometry is cached globally by useLoader (one geometry per URL, shared
|
||||
// across items). We only render the solid mesh — no per-item wireframe overlay,
|
||||
// which keeps draw calls and allocations low.
|
||||
function STLGeometry({ path, scale, color, accentColor, emissiveIntensity, roughness, metalness }: RenderProps & {
|
||||
path: string;
|
||||
scale: [number, number, number];
|
||||
}) {
|
||||
const geometry = useLoader(STLLoader, path) as THREE.BufferGeometry;
|
||||
useMemo(() => {
|
||||
if (geometry) {
|
||||
@@ -35,94 +49,118 @@ function STLGeometry({ path, scale, color, accentColor, emissiveIntensity, rough
|
||||
}, [geometry]);
|
||||
return (
|
||||
<group scale={scale}>
|
||||
<mesh geometry={geometry} castShadow>
|
||||
<mesh geometry={geometry}>
|
||||
<meshStandardMaterial color={color} emissive={accentColor} emissiveIntensity={emissiveIntensity} roughness={roughness} metalness={metalness} />
|
||||
</mesh>
|
||||
<lineSegments geometry={new THREE.EdgesGeometry(geometry, 35)}>
|
||||
<lineBasicMaterial color={accentColor} transparent opacity={0.28} />
|
||||
</lineSegments>
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
||||
function FallbackPrimitive({ type, color, accentColor, emissiveIntensity, roughness, metalness, w, h, d }: any) {
|
||||
if (type === 'cylinder' || type === 'sphere') {
|
||||
return (
|
||||
<group>
|
||||
<mesh castShadow>
|
||||
<cylinderGeometry args={[Math.max(w, d) / 2, Math.max(w, d) / 2, h, 16]} />
|
||||
<meshStandardMaterial color={color} emissive={accentColor} emissiveIntensity={emissiveIntensity} roughness={roughness} metalness={metalness} />
|
||||
</mesh>
|
||||
</group>
|
||||
);
|
||||
}
|
||||
function FallbackPrimitive({ type, color, accentColor, emissiveIntensity, roughness, metalness, w, h, d }: RenderProps & {
|
||||
type: 'box' | 'cylinder' | 'sphere';
|
||||
w: number; h: number; d: number;
|
||||
}) {
|
||||
// Memoize the geometry once per size so we don't allocate every render.
|
||||
const geometry = useMemo<THREE.BufferGeometry>(() => {
|
||||
if (type === 'cylinder' || type === 'sphere') {
|
||||
const r = Math.max(w, d) / 2;
|
||||
return new THREE.CylinderGeometry(r, r, h, 16);
|
||||
}
|
||||
return new THREE.BoxGeometry(w, h, d);
|
||||
}, [type, w, h, d]);
|
||||
useEffect(() => () => geometry.dispose(), [geometry]);
|
||||
|
||||
return (
|
||||
<group>
|
||||
<mesh castShadow>
|
||||
<boxGeometry args={[w, h, d]} />
|
||||
<meshStandardMaterial color={color} emissive={accentColor} emissiveIntensity={emissiveIntensity} roughness={roughness} metalness={metalness} />
|
||||
</mesh>
|
||||
<lineSegments>
|
||||
<edgesGeometry args={[new THREE.BoxGeometry(w, h, d), 35]} />
|
||||
<lineBasicMaterial color={accentColor} transparent opacity={0.35} />
|
||||
</lineSegments>
|
||||
</group>
|
||||
<mesh geometry={geometry}>
|
||||
<meshStandardMaterial color={color} emissive={accentColor} emissiveIntensity={emissiveIntensity} roughness={roughness} metalness={metalness} />
|
||||
</mesh>
|
||||
);
|
||||
}
|
||||
|
||||
export function PhysicalPlaybackItem({
|
||||
caseData,
|
||||
elapsedMs,
|
||||
slotIndex = 0
|
||||
}: {
|
||||
caseData: PlaylistCase;
|
||||
export const PhysicalPlaybackItem = memo(function PhysicalPlaybackItem({
|
||||
caseData,
|
||||
elapsedMs,
|
||||
slotIndex = 0,
|
||||
}: {
|
||||
caseData: PlaylistCase;
|
||||
elapsedMs: number;
|
||||
slotIndex?: number;
|
||||
}) {
|
||||
const itemId = caseData.itemId.replace('-LC', '');
|
||||
const itemData = useMemo(() => ITEMS.find(i => i.id === itemId) ?? ITEMS[0], [itemId]);
|
||||
const asset = getModelAsset(itemId);
|
||||
|
||||
|
||||
const dims = getRenderedItemDimensions(itemData.dimensionsMm);
|
||||
|
||||
|
||||
const pose = getPhysicalItemPose({
|
||||
caseId: caseData.id,
|
||||
slotIndex,
|
||||
dimensionsMm: itemData.dimensionsMm,
|
||||
targetCategory: caseData.expectedCategory,
|
||||
elapsedMs
|
||||
elapsedMs,
|
||||
});
|
||||
|
||||
const { position, rotation, isSettled, phase, surface } = pose;
|
||||
const { position, rotation, phase, surface, isSettled } = pose;
|
||||
const isRouting = phase === 'routing';
|
||||
// Item rests on a moving/transport surface (shadow makes sense there).
|
||||
const useSimplifiedMesh = phase === 'settled' || isSettled;
|
||||
// Contact shadow only while the item rides a flat transport surface.
|
||||
const onTransport = surface === 'main_belt'
|
||||
|| surface === 'inspection_station'
|
||||
|| surface === 'routing_junction'
|
||||
|| surface === 'b_receiver';
|
||||
|| surface === 'b_transfer';
|
||||
|
||||
// Before spawn, don't show
|
||||
if (elapsedMs < 0) return null;
|
||||
|
||||
const accentColor = COLORS[caseData.expectedCategory] ?? COLORS.sensorAccent;
|
||||
const routeAccent = COLORS[caseData.expectedCategory] ?? COLORS.sensorAccent;
|
||||
const material = ITEM_MATERIALS[itemId] ?? { color: '#d8c3a5', roughness: 0.75 };
|
||||
const emissiveIntensity = isRouting ? 0.16 : 0.03;
|
||||
|
||||
const useSTL = asset?.loaderType === 'stl' && asset?.frontendAssetPath;
|
||||
const bodyColor = useSimplifiedMesh ? (material.color ?? '#b8b2a8') : material.color;
|
||||
const accentColor = useSimplifiedMesh ? '#94a3b8' : routeAccent;
|
||||
const emissiveIntensity = useSimplifiedMesh ? 0.01 : (isRouting ? 0.12 : 0.03);
|
||||
const metalness = material.metalness ?? 0.05;
|
||||
|
||||
const useSTL = !useSimplifiedMesh && asset?.loaderType === 'stl' && asset?.frontendAssetPath;
|
||||
const stlPath = asset?.frontendAssetPath ?? '';
|
||||
const fallbackType = asset?.fallbackPrimitive ?? 'box';
|
||||
|
||||
const fallback = (
|
||||
<FallbackPrimitive
|
||||
type={fallbackType}
|
||||
color={bodyColor}
|
||||
accentColor={accentColor}
|
||||
emissiveIntensity={emissiveIntensity}
|
||||
roughness={material.roughness}
|
||||
metalness={metalness}
|
||||
w={dims.width}
|
||||
h={dims.height}
|
||||
d={dims.depth}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<group position={position} rotation={rotation}>
|
||||
{useSTL ? (
|
||||
<Suspense fallback={<FallbackPrimitive type={fallbackType} color={material.color} accentColor={accentColor} emissiveIntensity={emissiveIntensity} roughness={material.roughness} metalness={material.metalness ?? 0.05} w={dims.width} h={dims.height} d={dims.depth} />}>
|
||||
<STLGeometry path={stlPath} scale={[0.001, 0.001, 0.001]} color={material.color} accentColor={accentColor} emissiveIntensity={emissiveIntensity} roughness={material.roughness} metalness={material.metalness ?? 0.05} />
|
||||
<Suspense fallback={fallback}>
|
||||
<STLGeometry
|
||||
path={stlPath}
|
||||
scale={[0.001, 0.001, 0.001]}
|
||||
color={bodyColor}
|
||||
accentColor={accentColor}
|
||||
emissiveIntensity={emissiveIntensity}
|
||||
roughness={material.roughness}
|
||||
metalness={metalness}
|
||||
/>
|
||||
</Suspense>
|
||||
) : (
|
||||
<FallbackPrimitive type={fallbackType} color={material.color} accentColor={accentColor} emissiveIntensity={emissiveIntensity} roughness={material.roughness} metalness={material.metalness ?? 0.05} w={dims.width} h={dims.height} d={dims.depth} />
|
||||
fallback
|
||||
)}
|
||||
|
||||
{/* Contact shadow only while riding a transport surface */}
|
||||
|
||||
{useSimplifiedMesh && (
|
||||
<mesh position={[0, -dims.height / 2 + 0.003, 0]} rotation={[-Math.PI / 2, 0, 0]}>
|
||||
<ringGeometry args={[Math.max(dims.width, dims.depth) * 0.35, Math.max(dims.width, dims.depth) * 0.42, 20]} />
|
||||
<meshBasicMaterial color={routeAccent} transparent opacity={0.5} />
|
||||
</mesh>
|
||||
)}
|
||||
|
||||
{onTransport && (
|
||||
<mesh position={[0, -dims.height / 2 + 0.001, 0]} rotation={[-Math.PI / 2, 0, 0]}>
|
||||
<circleGeometry args={[Math.max(dims.width, dims.depth) / 2 + 0.01, 16]} />
|
||||
@@ -131,4 +169,4 @@ export function PhysicalPlaybackItem({
|
||||
)}
|
||||
</group>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -57,7 +57,9 @@ export default function STLModel({
|
||||
// Load STL geometry
|
||||
geometry = useLoader(STLLoader, path);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load STL model: ${path}`, error);
|
||||
if (import.meta.env.DEV) {
|
||||
console.warn(`Failed to load STL model: ${path}`, error);
|
||||
}
|
||||
return fallback ? <>{fallback}</> : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,19 +8,16 @@
|
||||
* - Items ride ON the belt surface
|
||||
*/
|
||||
|
||||
import { Canvas, useFrame, useLoader, useThree } from '@react-three/fiber';
|
||||
import { Canvas, useFrame, useThree } from '@react-three/fiber';
|
||||
import { Grid, OrbitControls, Html, Line } from '@react-three/drei';
|
||||
import { Suspense, useRef, useMemo, useState, useEffect } from 'react';
|
||||
import type { Mesh, Group, BufferGeometry } from 'three';
|
||||
import type { Mesh, Group } from 'three';
|
||||
import * as THREE from 'three';
|
||||
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
|
||||
import type { ContinuousPlaybackState, CasePhase } from '../../domain/continuousPlayback';
|
||||
import { isDetectionActive, isRoutingActive, getPhaseProgress } from '../../domain/continuousPlayback';
|
||||
import { getConveyorSpeedFactor } from '../../domain/conveyorPath';
|
||||
import { getPhysicalItemPose } from '../../domain/physicalItemMotion';
|
||||
import { shouldShowBoundingBox, shouldShowScanEffect, shouldShowShapeOutline, shouldHighlightCamera } from '../../domain/inspectionViewModel';
|
||||
import { getMeasurementData, shouldShowLaserBeam, shouldShowStepperPulse, shouldShowPointCloud, shouldShowActuator } from '../../domain/measurementSystem';
|
||||
import { getModelAsset } from '../../data/modelAssets';
|
||||
import { ITEMS } from '../../data/items';
|
||||
import type { Category } from '../../domain/types';
|
||||
import { PhysicalPlaybackItem } from './PhysicalPlaybackItem';
|
||||
@@ -52,7 +49,6 @@ import {
|
||||
STEREO_CAMERA,
|
||||
ROLL_CAGE,
|
||||
getRenderedItemDimensions,
|
||||
getItemYOnBelt,
|
||||
B_RECEIVER,
|
||||
CAGE_FLOOR_Y,
|
||||
CONVEYOR_SPEED_MPS,
|
||||
@@ -112,7 +108,11 @@ const BELT_UNDERSIDE_Y = BELT_TOP_Y - BELT_THICKNESS_M; // 0.685m
|
||||
const ROLLER_Y = BELT_UNDERSIDE_Y - ROLLER_RADIUS_M; // ~0.645m - roller center
|
||||
const FRAME_TOP_Y = ROLLER_Y - ROLLER_RADIUS_M - 0.02; // Top of frame structure
|
||||
const CONVEYOR_START_X = -4.2;
|
||||
const CONVEYOR_END_X = 4.3;
|
||||
const CONVEYOR_END_X = B_RECEIVER.transferEndX + 0.15; // main belt ends at short B spur tip
|
||||
/** Max items rendered simultaneously (perf cap). */
|
||||
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;
|
||||
|
||||
@@ -210,19 +210,11 @@ function MotionTrail({
|
||||
);
|
||||
}
|
||||
|
||||
/** Single animated roller that rotates around its own axis */
|
||||
function Roller({ position, speedFactor }: { position: [number, number, number]; speedFactor: number }) {
|
||||
const meshRef = useRef<Mesh>(null);
|
||||
|
||||
useFrame((_, delta) => {
|
||||
if (meshRef.current && speedFactor > 0) {
|
||||
meshRef.current.rotation.x += delta * speedFactor * 4;
|
||||
}
|
||||
});
|
||||
|
||||
/** Static roller cylinder — no per-frame rotation (belt stripes show movement). */
|
||||
function StaticRoller({ position }: { position: [number, number, number] }) {
|
||||
return (
|
||||
<mesh ref={meshRef} position={position} rotation={[0, 0, Math.PI / 2]}>
|
||||
<cylinderGeometry args={[ROLLER_RADIUS_M, ROLLER_RADIUS_M, CONVEYOR_WIDTH_M - 0.02, 12]} />
|
||||
<mesh position={position} rotation={[0, 0, Math.PI / 2]}>
|
||||
<cylinderGeometry args={[ROLLER_RADIUS_M, ROLLER_RADIUS_M, CONVEYOR_WIDTH_M - 0.02, 8]} />
|
||||
<meshStandardMaterial color={COLORS.rollers} metalness={0.4} roughness={0.5} />
|
||||
</mesh>
|
||||
);
|
||||
@@ -304,28 +296,18 @@ function StepperMotor({ position, pulseActive }: { position: [number, number, nu
|
||||
);
|
||||
}
|
||||
|
||||
/** Laser beam from rangefinder to item */
|
||||
/** Laser beam from rangefinder to item — static opacity, no useFrame. */
|
||||
function LaserBeam({ active, itemY }: { active: boolean; itemY: number }) {
|
||||
const beamRef = useRef<Mesh>(null);
|
||||
const opacityRef = useRef(0.6);
|
||||
|
||||
useFrame((_, delta) => {
|
||||
if (beamRef.current && active) {
|
||||
opacityRef.current = 0.4 + Math.sin(Date.now() / 100) * 0.3;
|
||||
}
|
||||
});
|
||||
|
||||
if (!active) return null;
|
||||
|
||||
|
||||
const beamLength = LASER_HEIGHT_M - itemY;
|
||||
const beamCenterY = itemY + beamLength / 2;
|
||||
|
||||
|
||||
return (
|
||||
<group position={[ZONES.CAMERA.x, 0, 0]}>
|
||||
{/* Main laser beam */}
|
||||
<mesh ref={beamRef} position={[0, beamCenterY, 0]}>
|
||||
<mesh position={[0, beamCenterY, 0]}>
|
||||
<cylinderGeometry args={[0.003, 0.003, beamLength, 8]} />
|
||||
<meshStandardMaterial
|
||||
<meshStandardMaterial
|
||||
color="#22d3ee"
|
||||
emissive="#22d3ee"
|
||||
emissiveIntensity={0.6}
|
||||
@@ -517,16 +499,18 @@ function SupportLeg({ x }: { x: number }) {
|
||||
* Conveyor belt - realistic roller conveyor
|
||||
* Belt top surface at 0.7m (BELT_TOP_Y)
|
||||
*/
|
||||
function ConveyorBelt({ speedFactor, pulseActive, elapsedMs }: { speedFactor: number; pulseActive: boolean; elapsedMs: number }) {
|
||||
const rollerCount = Math.floor(CONVEYOR_LENGTH / ROLLER_SPACING_M);
|
||||
function ConveyorBelt({ pulseActive, elapsedMs, simplified }: { pulseActive: boolean; elapsedMs: number; simplified: 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 rollerPositions = useMemo(() => {
|
||||
const positions: [number, number, number][] = [];
|
||||
for (let i = 0; i < rollerCount; i++) {
|
||||
positions.push([CONVEYOR_START_X + ROLLER_SPACING_M / 2 + i * ROLLER_SPACING_M, ROLLER_Y, 0]);
|
||||
positions.push([CONVEYOR_START_X + spacing / 2 + i * spacing, ROLLER_Y, 0]);
|
||||
}
|
||||
return positions;
|
||||
}, [rollerCount]);
|
||||
}, [rollerCount, spacing]);
|
||||
|
||||
const legPositions = useMemo(() => {
|
||||
const positions: number[] = [];
|
||||
@@ -539,7 +523,7 @@ function ConveyorBelt({ speedFactor, pulseActive, elapsedMs }: { speedFactor: nu
|
||||
return (
|
||||
<group>
|
||||
{/* Main belt surface - matte PVC/tarpaulin look at 0.7m */}
|
||||
<mesh position={[CONVEYOR_CENTER_X, BELT_Y - BELT_THICKNESS_M / 2, 0]} castShadow receiveShadow>
|
||||
<mesh position={[CONVEYOR_CENTER_X, BELT_Y - BELT_THICKNESS_M / 2, 0]}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, BELT_THICKNESS_M, CONVEYOR_WIDTH_M]} />
|
||||
<meshStandardMaterial
|
||||
color={COLORS.belt}
|
||||
@@ -549,33 +533,33 @@ function ConveyorBelt({ speedFactor, pulseActive, elapsedMs }: { speedFactor: nu
|
||||
</mesh>
|
||||
|
||||
{/* Belt stripes — deterministic movement synced to item (offset = time * 1 m/s) */}
|
||||
{[-4, -2.5, -1, 0.5, 2, 3.5].map((offset, i) => (
|
||||
{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]} castShadow>
|
||||
<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]} castShadow>
|
||||
<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>
|
||||
<mesh position={[CONVEYOR_CENTER_X, FRAME_TOP_Y + 0.025, CONVEYOR_WIDTH_M / 2 + 0.01]}>
|
||||
<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>
|
||||
<mesh position={[CONVEYOR_CENTER_X, FRAME_TOP_Y + 0.025, -CONVEYOR_WIDTH_M / 2 - 0.01]}>
|
||||
<boxGeometry args={[CONVEYOR_LENGTH, 0.05, 0.04]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
|
||||
{/* Rollers - rotating under the belt */}
|
||||
{/* Rollers — static geometry (no per-frame rotation hooks) */}
|
||||
{rollerPositions.map((pos, i) => (
|
||||
<Roller key={i} position={pos} speedFactor={speedFactor} />
|
||||
<StaticRoller key={i} position={pos} />
|
||||
))}
|
||||
|
||||
{/* Drive roller at end (larger) */}
|
||||
@@ -644,52 +628,91 @@ function ZoneMarker({ position, label, color, active }: {
|
||||
}
|
||||
|
||||
/**
|
||||
* B receiving zone — physical downstream receiving tray after the sorter.
|
||||
* A short 0.5m-wide tray at belt height (0.7m) with low side walls and an end
|
||||
* stop, so B items visibly land and remain instead of vanishing into thin air.
|
||||
* B receiving bin — отдельный промышленный контейнер на полу (не продолжение ленты).
|
||||
* Короткий transfer spur + drop chute в открытый bin 1.2×0.8 m.
|
||||
*/
|
||||
function BReceiver({ active }: { active: boolean }) {
|
||||
const { startX, endX, y, width, wallHeight } = B_RECEIVER;
|
||||
const len = endX - startX;
|
||||
const centerX = (startX + endX) / 2;
|
||||
const emissive = active ? 0.35 : 0.05;
|
||||
const legY = y / 2;
|
||||
function BReceiverBin({ active }: { active: boolean }) {
|
||||
const { centerX, centerZ, width, depth, wallHeight, floorY, transferEndX, transferStartX } = B_RECEIVER;
|
||||
const emissive = active ? 0.3 : 0.04;
|
||||
const hx = width / 2;
|
||||
const hz = depth / 2;
|
||||
const wall = 0.03;
|
||||
const entryX = centerX - hx + 0.1;
|
||||
const spurLen = transferEndX - transferStartX;
|
||||
|
||||
return (
|
||||
<group>
|
||||
{/* Tray floor at belt height */}
|
||||
<mesh position={[centerX, y - 0.02, 0]} receiveShadow>
|
||||
<boxGeometry args={[len, 0.04, width]} />
|
||||
<meshStandardMaterial color="#334155" metalness={0.3} roughness={0.7} />
|
||||
{/* Short B-only transfer spur (not a full belt extension) */}
|
||||
<mesh position={[(transferStartX + transferEndX) / 2, BELT_Y - 0.02, 0]}>
|
||||
<boxGeometry args={[spurLen, 0.04, CONVEYOR_WIDTH_M - 0.06]} />
|
||||
<meshStandardMaterial color="#64748b" roughness={0.85} metalness={0.15} />
|
||||
</mesh>
|
||||
{/* Side walls */}
|
||||
{/* Spur side rails */}
|
||||
{[-1, 1].map((s) => (
|
||||
<mesh key={s} position={[centerX, y + wallHeight / 2, s * (width / 2)]}>
|
||||
<boxGeometry args={[len, wallHeight, 0.02]} />
|
||||
<meshStandardMaterial color={COLORS.routeB} transparent opacity={0.55} emissive={COLORS.routeB} emissiveIntensity={emissive} />
|
||||
<mesh key={`spur${s}`} position={[(transferStartX + transferEndX) / 2, BELT_Y + 0.04, s * (CONVEYOR_WIDTH_M / 2 - 0.02)]}>
|
||||
<boxGeometry args={[spurLen, 0.06, 0.02]} />
|
||||
<meshStandardMaterial color={COLORS.routeB} transparent opacity={0.55} />
|
||||
</mesh>
|
||||
))}
|
||||
{/* End stop wall */}
|
||||
<mesh position={[endX, y + wallHeight / 2, 0]}>
|
||||
<boxGeometry args={[0.03, wallHeight, width]} />
|
||||
<meshStandardMaterial color={COLORS.routeB} transparent opacity={0.6} emissive={COLORS.routeB} emissiveIntensity={emissive} />
|
||||
|
||||
{/* Drop chute into bin */}
|
||||
<mesh
|
||||
position={[(transferEndX + entryX) / 2, (BELT_Y + floorY) / 2 + 0.02, centerZ]}
|
||||
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} />
|
||||
</mesh>
|
||||
{/* Support legs */}
|
||||
{[startX + 0.2, endX - 0.2].map((lx) => (
|
||||
[-1, 1].map((s) => (
|
||||
<mesh key={`${lx}-${s}`} position={[lx, legY, s * (width / 2 - 0.05)]}>
|
||||
<boxGeometry args={[0.04, y, 0.04]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
))
|
||||
|
||||
{/* Floor pad under bin */}
|
||||
<mesh rotation={[-Math.PI / 2, 0, 0]} position={[centerX, 0.001, centerZ]}>
|
||||
<planeGeometry args={[width + 0.25, depth + 0.25]} />
|
||||
<meshStandardMaterial color={COLORS.routeB} transparent opacity={active ? 0.18 : 0.06} />
|
||||
</mesh>
|
||||
|
||||
{/* Bin interior floor */}
|
||||
<mesh position={[centerX, floorY - 0.01, centerZ]}>
|
||||
<boxGeometry args={[width - 0.06, 0.025, depth - 0.06]} />
|
||||
<meshStandardMaterial color="#334155" roughness={0.8} metalness={0.2} />
|
||||
</mesh>
|
||||
|
||||
{/* Bin walls — 3 sides + low front lip */}
|
||||
{[-1, 1].map((s) => (
|
||||
<mesh key={`w${s}`} position={[centerX, floorY + wallHeight / 2, centerZ + s * hz]}>
|
||||
<boxGeometry args={[width, wallHeight, wall]} />
|
||||
<meshStandardMaterial color="#3f6f52" roughness={0.7} metalness={0.25} emissive={COLORS.routeB} emissiveIntensity={emissive} />
|
||||
</mesh>
|
||||
))}
|
||||
{/* Label */}
|
||||
<Html position={[centerX, y + wallHeight + 0.18, 0]} center>
|
||||
<mesh position={[centerX + hx, floorY + wallHeight / 2, centerZ]}>
|
||||
<boxGeometry args={[wall, wallHeight, depth]} />
|
||||
<meshStandardMaterial color="#3f6f52" roughness={0.7} metalness={0.25} emissive={COLORS.routeB} emissiveIntensity={emissive} />
|
||||
</mesh>
|
||||
<mesh position={[entryX, floorY + wallHeight / 4, centerZ]}>
|
||||
<boxGeometry args={[wall, wallHeight / 3, depth - 0.1]} />
|
||||
<meshStandardMaterial color="#3f6f52" roughness={0.7} metalness={0.25} transparent opacity={0.85} />
|
||||
</mesh>
|
||||
|
||||
{/* Corner posts */}
|
||||
{[[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([sx, sz], i) => (
|
||||
<mesh key={`post${i}`} position={[centerX + sx * (hx - 0.04), floorY + wallHeight / 2, centerZ + sz * (hz - 0.04)]}>
|
||||
<boxGeometry args={[0.04, wallHeight, 0.04]} />
|
||||
<meshStandardMaterial color="#3f6f52" metalness={0.4} roughness={0.5} />
|
||||
</mesh>
|
||||
))}
|
||||
|
||||
{/* Legs to floor */}
|
||||
{[[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([sx, sz], i) => (
|
||||
<mesh key={`leg${i}`} position={[centerX + sx * (hx - 0.08), floorY / 2, centerZ + sz * (hz - 0.08)]}>
|
||||
<boxGeometry args={[0.05, floorY, 0.05]} />
|
||||
<meshStandardMaterial color={COLORS.conveyorFrame} metalness={0.5} roughness={0.4} />
|
||||
</mesh>
|
||||
))}
|
||||
|
||||
<Html position={[centerX, floorY + wallHeight + 0.25, centerZ]} center>
|
||||
<div style={{
|
||||
color: active ? COLORS.routeB : '#64748b',
|
||||
fontSize: '20px',
|
||||
fontSize: '22px',
|
||||
fontWeight: 800,
|
||||
textShadow: active ? `0 0 8px ${COLORS.routeB}` : 'none',
|
||||
userSelect: 'none',
|
||||
}}>
|
||||
B
|
||||
@@ -719,7 +742,7 @@ function RollCage({ position, label, color, active }: {
|
||||
</mesh>
|
||||
|
||||
{/* Solid interior floor where items rest */}
|
||||
<mesh position={[0, CAGE_FLOOR_Y - 0.005, 0]} receiveShadow>
|
||||
<mesh position={[0, CAGE_FLOOR_Y - 0.005, 0]}>
|
||||
<boxGeometry args={[width - frameThickness, 0.01, depth - frameThickness]} />
|
||||
<meshStandardMaterial color="#1e293b" metalness={0.3} roughness={0.7} />
|
||||
</mesh>
|
||||
@@ -1159,105 +1182,6 @@ function RouteArrows({ activeRoute }: { activeRoute: Category | null }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** STL geometry loader - always loads the geometry */
|
||||
function STLGeometry({
|
||||
path,
|
||||
scale,
|
||||
color,
|
||||
accentColor,
|
||||
emissiveIntensity,
|
||||
roughness,
|
||||
metalness,
|
||||
}: {
|
||||
path: string;
|
||||
scale: [number, number, number];
|
||||
color: string;
|
||||
accentColor: string;
|
||||
emissiveIntensity: number;
|
||||
roughness: number;
|
||||
metalness: number;
|
||||
}) {
|
||||
const geometry = useLoader(STLLoader, path);
|
||||
|
||||
// Center and compute normals on first render
|
||||
useMemo(() => {
|
||||
if (geometry) {
|
||||
geometry.center();
|
||||
geometry.computeVertexNormals();
|
||||
}
|
||||
}, [geometry]);
|
||||
|
||||
return (
|
||||
<group scale={scale}>
|
||||
<mesh geometry={geometry} castShadow>
|
||||
<meshStandardMaterial
|
||||
color={color}
|
||||
emissive={accentColor}
|
||||
emissiveIntensity={emissiveIntensity}
|
||||
roughness={roughness}
|
||||
metalness={metalness}
|
||||
/>
|
||||
</mesh>
|
||||
<lineSegments geometry={new THREE.EdgesGeometry(geometry, 35)}>
|
||||
<lineBasicMaterial color={accentColor} transparent opacity={0.28} />
|
||||
</lineSegments>
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
||||
/** Fallback primitive when STL is not available */
|
||||
function FallbackPrimitive({
|
||||
type,
|
||||
color,
|
||||
accentColor,
|
||||
emissiveIntensity,
|
||||
roughness,
|
||||
metalness,
|
||||
w, h, d,
|
||||
}: {
|
||||
type: 'box' | 'cylinder' | 'sphere';
|
||||
color: string;
|
||||
accentColor: string;
|
||||
emissiveIntensity: number;
|
||||
roughness: number;
|
||||
metalness: number;
|
||||
w: number; h: number; d: number;
|
||||
}) {
|
||||
if (type === 'cylinder' || type === 'sphere') {
|
||||
return (
|
||||
<mesh castShadow>
|
||||
<cylinderGeometry args={[Math.max(w, d) / 2, Math.max(w, d) / 2, h, 16]} />
|
||||
<meshStandardMaterial
|
||||
color={color}
|
||||
emissive={accentColor}
|
||||
emissiveIntensity={emissiveIntensity}
|
||||
roughness={roughness}
|
||||
metalness={metalness}
|
||||
/>
|
||||
</mesh>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<group>
|
||||
<mesh castShadow>
|
||||
<boxGeometry args={[w, h, d]} />
|
||||
<meshStandardMaterial
|
||||
color={color}
|
||||
emissive={accentColor}
|
||||
emissiveIntensity={emissiveIntensity}
|
||||
roughness={roughness}
|
||||
metalness={metalness}
|
||||
/>
|
||||
</mesh>
|
||||
<lineSegments>
|
||||
<edgesGeometry args={[new THREE.BoxGeometry(w, h, d), 35]} />
|
||||
<lineBasicMaterial color={accentColor} transparent opacity={0.35} />
|
||||
</lineSegments>
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
||||
/** Main continuous scene - light warehouse style with correct physical dimensions */
|
||||
function ContinuousScene({
|
||||
playback,
|
||||
@@ -1270,9 +1194,10 @@ function ContinuousScene({
|
||||
autoCameraEnabled: boolean;
|
||||
viewportType: ViewportType;
|
||||
}) {
|
||||
const speedFactor = getConveyorSpeedFactor(playback);
|
||||
const category = playback.targetCategory;
|
||||
const phase = playback.currentPhase;
|
||||
const liteScene = simplified || !ENABLE_DEMO_EFFECTS;
|
||||
const effectsEnabled = ENABLE_DEMO_EFFECTS && !simplified;
|
||||
|
||||
const cameraHighlight = shouldHighlightCamera(phase);
|
||||
const showScan = shouldShowScanEffect(phase);
|
||||
@@ -1284,10 +1209,11 @@ function ContinuousScene({
|
||||
const showCloud = shouldShowPointCloud(phase);
|
||||
const showActuator = shouldShowActuator(phase);
|
||||
|
||||
// Compute all physical items based on elapsed time to keep them in roll-cages
|
||||
// Compute physical items based on elapsed time. Cap the number of
|
||||
// simultaneously rendered items to keep the scene lightweight.
|
||||
const { totalElapsedMs, currentCase, currentCaseIndex } = playback;
|
||||
const casesSpawned = Math.floor(totalElapsedMs / CASE_DURATION_MS) + 1;
|
||||
const startIndex = Math.max(0, casesSpawned - 20); // Keep last 20 items
|
||||
const startIndex = Math.max(0, casesSpawned - MAX_VISIBLE_ITEMS);
|
||||
|
||||
const sceneItems = useMemo(() => {
|
||||
const items = [];
|
||||
@@ -1332,32 +1258,18 @@ function ContinuousScene({
|
||||
: 'x';
|
||||
const itemColor = category ? COLORS[`route${category}` as keyof typeof COLORS] : COLORS.sensorAccent;
|
||||
|
||||
// Cinematic camera active only when running and enabled
|
||||
const cinematicActive = autoCameraEnabled && playback.status === 'running';
|
||||
// Cinematic camera active only when heavy effects enabled
|
||||
const cinematicActive = effectsEnabled && autoCameraEnabled && playback.status === 'running';
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Light background */}
|
||||
<color attach="background" args={[COLORS.background]} />
|
||||
|
||||
{/* Soft natural lighting - warehouse aesthetic */}
|
||||
{/* Soft natural lighting — no shadow maps (Canvas shadows=false for perf) */}
|
||||
<ambientLight intensity={0.7} />
|
||||
<hemisphereLight args={['#f8fafc', '#d0dae8', 0.5]} />
|
||||
{/* Main directional light with soft shadow */}
|
||||
<directionalLight
|
||||
position={[8, 12, 6]}
|
||||
intensity={0.9}
|
||||
castShadow
|
||||
shadow-mapSize-width={1024}
|
||||
shadow-mapSize-height={1024}
|
||||
shadow-camera-far={30}
|
||||
shadow-camera-left={-10}
|
||||
shadow-camera-right={10}
|
||||
shadow-camera-top={10}
|
||||
shadow-camera-bottom={-10}
|
||||
shadow-bias={-0.0001}
|
||||
/>
|
||||
{/* Fill light from opposite side */}
|
||||
<directionalLight position={[8, 12, 6]} intensity={0.9} />
|
||||
<directionalLight position={[-5, 8, -4]} intensity={0.35} />
|
||||
|
||||
{/* Grid */}
|
||||
@@ -1374,14 +1286,14 @@ function ContinuousScene({
|
||||
position={[0, 0.001, 0]}
|
||||
/>
|
||||
|
||||
{/* Floor with shadow receiving */}
|
||||
<mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, 0, 0]} receiveShadow>
|
||||
{/* Floor */}
|
||||
<mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, 0, 0]}>
|
||||
<planeGeometry args={[16, 12]} />
|
||||
<meshStandardMaterial color={COLORS.floor} roughness={0.9} metalness={0} />
|
||||
</mesh>
|
||||
|
||||
{/* Conveyor - belt top at 0.7m */}
|
||||
<ConveyorBelt speedFactor={speedFactor} pulseActive={showPulse} elapsedMs={totalElapsedMs} />
|
||||
<ConveyorBelt pulseActive={showPulse} elapsedMs={totalElapsedMs} simplified={liteScene} />
|
||||
|
||||
{/* Zone A - spawn point */}
|
||||
<ZoneMarker
|
||||
@@ -1391,8 +1303,8 @@ function ContinuousScene({
|
||||
active={playback.currentPhase === 'spawn'}
|
||||
/>
|
||||
|
||||
{/* Zone B - physical receiving tray at end of sorter */}
|
||||
<BReceiver active={activeRoute === 'B'} />
|
||||
{/* Zone B - physical receiving bin at end of sorter */}
|
||||
<BReceiverBin active={activeRoute === 'B'} />
|
||||
|
||||
{/* Zone C - roll cage for oversized items */}
|
||||
<RollCage
|
||||
@@ -1433,19 +1345,21 @@ function ContinuousScene({
|
||||
{/* Laser beam for height measurement */}
|
||||
<LaserBeam active={showLaser} itemY={itemPos[1]} />
|
||||
|
||||
{/* Point cloud for stereo analysis */}
|
||||
<PointCloud
|
||||
active={showCloud}
|
||||
itemPosition={itemPos}
|
||||
scale={itemScale}
|
||||
isRound={isRound}
|
||||
/>
|
||||
{/* Point cloud for stereo analysis — opt-in only */}
|
||||
{effectsEnabled && (
|
||||
<PointCloud
|
||||
active={showCloud}
|
||||
itemPosition={itemPos}
|
||||
scale={itemScale}
|
||||
isRound={isRound}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Inspection zone on belt surface */}
|
||||
<InspectionZone active={cameraHighlight} />
|
||||
|
||||
{/* Animated scan line on belt */}
|
||||
<ScanLine active={showScan} />
|
||||
{/* Animated scan line on belt — opt-in only */}
|
||||
{effectsEnabled && <ScanLine active={showScan} />}
|
||||
|
||||
{/* Gate/diverter */}
|
||||
<GateZone category={category} />
|
||||
@@ -1481,20 +1395,24 @@ function ContinuousScene({
|
||||
category={category}
|
||||
/>
|
||||
|
||||
{/* Motion trail for visual movement feedback */}
|
||||
<MotionTrail
|
||||
position={itemPos}
|
||||
visible={showMotionTrail}
|
||||
color={itemColor}
|
||||
direction={trailDirection as 'x' | 'z'}
|
||||
/>
|
||||
{/* Motion trail — opt-in only */}
|
||||
{effectsEnabled && (
|
||||
<MotionTrail
|
||||
position={itemPos}
|
||||
visible={showMotionTrail}
|
||||
color={itemColor}
|
||||
direction={trailDirection as 'x' | 'z'}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Cinematic camera controller */}
|
||||
<CinematicCameraController
|
||||
playback={playback}
|
||||
enabled={cinematicActive}
|
||||
viewportType={viewportType}
|
||||
/>
|
||||
{/* Cinematic camera controller — opt-in only */}
|
||||
{effectsEnabled && (
|
||||
<CinematicCameraController
|
||||
playback={playback}
|
||||
enabled={cinematicActive}
|
||||
viewportType={viewportType}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* OrbitControls - enabled when not in cinematic mode */}
|
||||
<OrbitControls
|
||||
@@ -1523,8 +1441,8 @@ export default function SorterDigitalTwinContinuous({
|
||||
<div className="digital-twin-canvas continuous-canvas">
|
||||
<Canvas
|
||||
camera={{ position: [4.5, 3.5, 5.0], fov: 45 }}
|
||||
dpr={simplified ? [1, 1.25] : [1, 1.75]}
|
||||
shadows={!simplified}
|
||||
dpr={simplified ? [1, 1.25] : [1, 1.5]}
|
||||
shadows={false}
|
||||
gl={{ antialias: !simplified, powerPreference: 'high-performance' }}
|
||||
onCreated={({ gl }) => {
|
||||
const canvas = gl.domElement;
|
||||
|
||||
@@ -12,7 +12,9 @@ const ALL: SurfaceName[] = [
|
||||
'main_belt',
|
||||
'inspection_station',
|
||||
'routing_junction',
|
||||
'b_receiver',
|
||||
'b_transfer',
|
||||
'chute_b',
|
||||
'b_bin_floor',
|
||||
'chute_c',
|
||||
'chute_d',
|
||||
'c_cage_floor',
|
||||
@@ -56,11 +58,17 @@ describe('conveyorNetwork', () => {
|
||||
});
|
||||
|
||||
it('provides an ordered path per category', () => {
|
||||
expect(pathForCategory('B')).toEqual(['main_belt', 'inspection_station', 'routing_junction', 'b_receiver']);
|
||||
expect(pathForCategory('B')).toEqual(['main_belt', 'inspection_station', 'routing_junction', 'b_transfer', 'chute_b', 'b_bin_floor']);
|
||||
expect(pathForCategory('C')).toEqual(['main_belt', 'inspection_station', 'routing_junction', 'chute_c', 'c_cage_floor']);
|
||||
expect(pathForCategory('D')).toEqual(['main_belt', 'inspection_station', 'routing_junction', 'chute_d', 'd_cage_floor']);
|
||||
});
|
||||
|
||||
it('B bin floor and cages are on the ground (not floating)', () => {
|
||||
expect(SURFACES.b_bin_floor.surfaceY).toBeLessThan(0.2);
|
||||
expect(SURFACES.c_cage_floor.surfaceY).toBeLessThan(0.2);
|
||||
expect(SURFACES.d_cage_floor.surfaceY).toBeLessThan(0.2);
|
||||
});
|
||||
|
||||
it('bounds check works', () => {
|
||||
const c = SURFACES.c_cage_floor.bounds;
|
||||
const cx = (c.minX + c.maxX) / 2;
|
||||
@@ -69,6 +77,14 @@ describe('conveyorNetwork', () => {
|
||||
expect(isWithinBounds('c_cage_floor', c.maxX + 1, cz)).toBe(false);
|
||||
});
|
||||
|
||||
it('every surface has a kind', () => {
|
||||
for (const name of ALL) {
|
||||
expect(SURFACES[name].kind).toBeTruthy();
|
||||
}
|
||||
expect(SURFACES.b_bin_floor.kind).toBe('bin_floor');
|
||||
expect(SURFACES.b_transfer.kind).toBe('conveyor');
|
||||
});
|
||||
|
||||
it('chutes have real length (item slides, does not teleport)', () => {
|
||||
expect(surfaceLength('chute_c')).toBeGreaterThan(0.5);
|
||||
expect(surfaceLength('chute_d')).toBeGreaterThan(0.5);
|
||||
|
||||
@@ -27,12 +27,16 @@ export type SurfaceName =
|
||||
| 'main_belt'
|
||||
| 'inspection_station'
|
||||
| 'routing_junction'
|
||||
| 'b_receiver'
|
||||
| 'b_transfer'
|
||||
| 'chute_b'
|
||||
| 'b_bin_floor'
|
||||
| 'chute_c'
|
||||
| 'chute_d'
|
||||
| 'c_cage_floor'
|
||||
| 'd_cage_floor';
|
||||
|
||||
export type SurfaceKind = 'conveyor' | 'station' | 'junction' | 'chute' | 'bin_floor' | 'cage_floor';
|
||||
|
||||
export type Vec3 = [number, number, number];
|
||||
|
||||
export interface SurfaceBounds {
|
||||
@@ -44,6 +48,7 @@ export interface SurfaceBounds {
|
||||
|
||||
export interface Surface {
|
||||
name: SurfaceName;
|
||||
kind: SurfaceKind;
|
||||
/** Entry point of the surface (item enters here). */
|
||||
start: Vec3;
|
||||
/** Exit point of the surface (item leaves here). */
|
||||
@@ -70,6 +75,13 @@ const D = ZONES.D; // cage D center
|
||||
const CAGE_HALF_X = ROLL_CAGE.width / 2; // 0.6
|
||||
const CAGE_HALF_Z = ROLL_CAGE.depth / 2; // 0.4
|
||||
|
||||
/** B bin geometry — separate floor-standing container. */
|
||||
const B_BIN_HALF_X = B_RECEIVER.width / 2; // 0.6
|
||||
const B_BIN_HALF_Z = B_RECEIVER.depth / 2; // 0.4
|
||||
const B_BIN_ENTRY_X = B_RECEIVER.centerX - B_BIN_HALF_X + 0.12;
|
||||
const CHUTE_B_ENTRY: Vec3 = [B_RECEIVER.transferEndX, BELT_TOP_Y, 0];
|
||||
const CHUTE_B_EXIT: Vec3 = [B_BIN_ENTRY_X, CHUTE_END_Y, B_RECEIVER.centerZ];
|
||||
|
||||
/** Chute entry sits at the junction on the belt edge toward the cage. */
|
||||
const CHUTE_C_ENTRY: Vec3 = [GATE.x, BELT_TOP_Y, MAIN_BELT_WIDTH_M / 2];
|
||||
const CHUTE_C_EXIT: Vec3 = [C.x, CHUTE_END_Y, C.z - CAGE_HALF_Z]; // front edge of cage C
|
||||
@@ -82,6 +94,7 @@ export const CHUTE_SPEED_MPS = 0.5;
|
||||
export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
main_belt: {
|
||||
name: 'main_belt',
|
||||
kind: 'conveyor',
|
||||
start: [A.x, BELT_TOP_Y, 0],
|
||||
end: [CAMERA.x, BELT_TOP_Y, 0],
|
||||
surfaceY: BELT_TOP_Y,
|
||||
@@ -91,6 +104,7 @@ export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
},
|
||||
inspection_station: {
|
||||
name: 'inspection_station',
|
||||
kind: 'station',
|
||||
start: [CAMERA.x, BELT_TOP_Y, 0],
|
||||
end: [CAMERA.x, BELT_TOP_Y, 0],
|
||||
surfaceY: BELT_TOP_Y,
|
||||
@@ -100,6 +114,7 @@ export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
},
|
||||
routing_junction: {
|
||||
name: 'routing_junction',
|
||||
kind: 'junction',
|
||||
start: [CAMERA.x, BELT_TOP_Y, 0],
|
||||
end: [GATE.x, BELT_TOP_Y, 0],
|
||||
surfaceY: BELT_TOP_Y,
|
||||
@@ -107,23 +122,57 @@ export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
speedMps: CONVEYOR_SPEED_MPS,
|
||||
bounds: { minX: CAMERA.x, maxX: GATE.x, minZ: -MAIN_BELT_WIDTH_M / 2, maxZ: MAIN_BELT_WIDTH_M / 2 },
|
||||
},
|
||||
b_receiver: {
|
||||
name: 'b_receiver',
|
||||
b_transfer: {
|
||||
name: 'b_transfer',
|
||||
kind: 'conveyor',
|
||||
start: [GATE.x, BELT_TOP_Y, 0],
|
||||
end: [B_RECEIVER.restX, BELT_TOP_Y, 0],
|
||||
surfaceY: B_RECEIVER.y,
|
||||
width: B_RECEIVER.width,
|
||||
end: [B_RECEIVER.transferEndX, BELT_TOP_Y, 0],
|
||||
surfaceY: BELT_TOP_Y,
|
||||
width: MAIN_BELT_WIDTH_M,
|
||||
speedMps: CONVEYOR_SPEED_MPS,
|
||||
bounds: {
|
||||
minX: B_RECEIVER.startX,
|
||||
maxX: B_RECEIVER.endX,
|
||||
minZ: -B_RECEIVER.width / 2,
|
||||
maxZ: B_RECEIVER.width / 2,
|
||||
minX: GATE.x,
|
||||
maxX: B_RECEIVER.transferEndX,
|
||||
minZ: -MAIN_BELT_WIDTH_M / 2,
|
||||
maxZ: MAIN_BELT_WIDTH_M / 2,
|
||||
},
|
||||
targetCategory: 'B',
|
||||
},
|
||||
chute_b: {
|
||||
name: 'chute_b',
|
||||
kind: 'chute',
|
||||
start: CHUTE_B_ENTRY,
|
||||
end: CHUTE_B_EXIT,
|
||||
surfaceY: BELT_TOP_Y,
|
||||
width: MAIN_BELT_WIDTH_M,
|
||||
speedMps: CHUTE_SPEED_MPS,
|
||||
bounds: {
|
||||
minX: Math.min(CHUTE_B_ENTRY[0], CHUTE_B_EXIT[0]) - 0.1,
|
||||
maxX: Math.max(CHUTE_B_ENTRY[0], CHUTE_B_EXIT[0]) + 0.1,
|
||||
minZ: -MAIN_BELT_WIDTH_M / 2,
|
||||
maxZ: MAIN_BELT_WIDTH_M / 2,
|
||||
},
|
||||
targetCategory: 'B',
|
||||
},
|
||||
b_bin_floor: {
|
||||
name: 'b_bin_floor',
|
||||
kind: 'bin_floor',
|
||||
start: [B_RECEIVER.centerX, B_RECEIVER.floorY, B_RECEIVER.centerZ],
|
||||
end: [B_RECEIVER.centerX, B_RECEIVER.floorY, B_RECEIVER.centerZ],
|
||||
surfaceY: B_RECEIVER.floorY,
|
||||
width: B_RECEIVER.width,
|
||||
speedMps: 0,
|
||||
bounds: {
|
||||
minX: B_RECEIVER.centerX - B_BIN_HALF_X,
|
||||
maxX: B_RECEIVER.centerX + B_BIN_HALF_X,
|
||||
minZ: B_RECEIVER.centerZ - B_BIN_HALF_Z,
|
||||
maxZ: B_RECEIVER.centerZ + B_BIN_HALF_Z,
|
||||
},
|
||||
targetCategory: 'B',
|
||||
},
|
||||
chute_c: {
|
||||
name: 'chute_c',
|
||||
kind: 'chute',
|
||||
start: CHUTE_C_ENTRY,
|
||||
end: CHUTE_C_EXIT,
|
||||
surfaceY: BELT_TOP_Y,
|
||||
@@ -139,6 +188,7 @@ export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
},
|
||||
chute_d: {
|
||||
name: 'chute_d',
|
||||
kind: 'chute',
|
||||
start: CHUTE_D_ENTRY,
|
||||
end: CHUTE_D_EXIT,
|
||||
surfaceY: BELT_TOP_Y,
|
||||
@@ -154,6 +204,7 @@ export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
},
|
||||
c_cage_floor: {
|
||||
name: 'c_cage_floor',
|
||||
kind: 'cage_floor',
|
||||
start: [C.x, CAGE_FLOOR_Y, C.z],
|
||||
end: [C.x, CAGE_FLOOR_Y, C.z],
|
||||
surfaceY: CAGE_FLOOR_Y,
|
||||
@@ -169,6 +220,7 @@ export const SURFACES: Record<SurfaceName, Surface> = {
|
||||
},
|
||||
d_cage_floor: {
|
||||
name: 'd_cage_floor',
|
||||
kind: 'cage_floor',
|
||||
start: [D.x, CAGE_FLOOR_Y, D.z],
|
||||
end: [D.x, CAGE_FLOOR_Y, D.z],
|
||||
surfaceY: CAGE_FLOOR_Y,
|
||||
@@ -227,5 +279,5 @@ export function pathForCategory(category: Category): SurfaceName[] {
|
||||
if (category === 'D') {
|
||||
return ['main_belt', 'inspection_station', 'routing_junction', 'chute_d', 'd_cage_floor'];
|
||||
}
|
||||
return ['main_belt', 'inspection_station', 'routing_junction', 'b_receiver'];
|
||||
return ['main_belt', 'inspection_station', 'routing_junction', 'b_transfer', 'chute_b', 'b_bin_floor'];
|
||||
}
|
||||
|
||||
42
src/domain/performanceStatic.test.ts
Normal file
42
src/domain/performanceStatic.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import sceneSource from '../components/ThreeD/SorterDigitalTwinContinuous.tsx?raw';
|
||||
|
||||
const srcModules = import.meta.glob(
|
||||
['../**/*.{ts,tsx}', '!../**/*.test.{ts,tsx}'],
|
||||
{ query: '?raw', import: 'default', eager: true },
|
||||
) as Record<string, string>;
|
||||
|
||||
describe('performance and production hygiene', () => {
|
||||
it('has no console.log in production src', () => {
|
||||
const offenders: string[] = [];
|
||||
for (const [path, text] of Object.entries(srcModules)) {
|
||||
if (/console\.log\s*\(/.test(text)) offenders.push(path);
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it('caps MAX_VISIBLE_ITEMS at 6', () => {
|
||||
const match = sceneSource.match(/MAX_VISIBLE_ITEMS\s*=\s*(\d+)/);
|
||||
expect(match).not.toBeNull();
|
||||
expect(Number(match![1])).toBeLessThanOrEqual(6);
|
||||
});
|
||||
|
||||
it('disables heavy demo effects by default', () => {
|
||||
expect(sceneSource).toMatch(/ENABLE_DEMO_EFFECTS\s*=\s*false/);
|
||||
expect(sceneSource).toMatch(/shadows=\{false\}/);
|
||||
});
|
||||
|
||||
it('keeps console.error only in error boundaries', () => {
|
||||
const allowed = new Set([
|
||||
'../components/ThreeD/ThreeErrorBoundary.tsx',
|
||||
'../pages/MainPage.tsx',
|
||||
'../components/ProductDemoSection.tsx',
|
||||
]);
|
||||
const offenders: string[] = [];
|
||||
for (const [path, text] of Object.entries(srcModules)) {
|
||||
if (!/console\.error\s*\(/.test(text)) continue;
|
||||
if (!allowed.has(path)) offenders.push(path);
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -41,17 +41,49 @@ describe('physicalItemMotion', () => {
|
||||
expect(a).toEqual(b);
|
||||
});
|
||||
|
||||
it('B final pose is inside the b_receiver bounds', () => {
|
||||
it('B final pose is inside the b_receiver bin bounds', () => {
|
||||
const pose = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 20000 });
|
||||
expect(pose.surface).toBe('b_receiver');
|
||||
expect(pose.surface).toBe('b_bin_floor');
|
||||
expect(pose.isSettled).toBe(true);
|
||||
const b = SURFACES.b_receiver.bounds;
|
||||
const b = SURFACES.b_bin_floor.bounds;
|
||||
expect(pose.position[0]).toBeGreaterThanOrEqual(b.minX);
|
||||
expect(pose.position[0]).toBeLessThanOrEqual(b.maxX);
|
||||
expect(pose.position[2]).toBeGreaterThanOrEqual(b.minZ);
|
||||
expect(pose.position[2]).toBeLessThanOrEqual(b.maxZ);
|
||||
});
|
||||
|
||||
it('settled B item is NOT on the active belt', () => {
|
||||
const pose = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 20000 });
|
||||
expect(['main_belt', 'b_transfer', 'inspection_station', 'routing_junction']).not.toContain(pose.surface);
|
||||
expect(pose.surface).toBe('b_bin_floor');
|
||||
});
|
||||
|
||||
it('settled B item sits on bin floor not belt height', () => {
|
||||
const pose = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 9200 });
|
||||
expect(pose.surface).toBe('b_bin_floor');
|
||||
expect(pose.position[1]).toBeLessThan(0.35); // well below belt (0.7m)
|
||||
expect(pose.position[0]).toBeGreaterThan(2.7); // inside B bin (center 3.35)
|
||||
});
|
||||
|
||||
it('settled B item remains fixed as time increases', () => {
|
||||
const t1 = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 11000 });
|
||||
const t2 = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 40000 });
|
||||
expect(t1.position).toEqual(t2.position);
|
||||
expect(t1.isSettled).toBe(true);
|
||||
expect(t2.isSettled).toBe(true);
|
||||
});
|
||||
|
||||
it('B travels via belt transfer then drop chute before settling', () => {
|
||||
const transfer = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 7200 });
|
||||
expect(transfer.surface).toBe('b_transfer');
|
||||
expect(transfer.phase).toBe('routing');
|
||||
const chute = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 8200 });
|
||||
expect(chute.surface).toBe('chute_b');
|
||||
const settled = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 9000 });
|
||||
expect(settled.surface).toBe('b_bin_floor');
|
||||
expect(settled.phase).toBe('settled');
|
||||
});
|
||||
|
||||
it('C final pose is inside the c_cage bounds', () => {
|
||||
const pose = getPhysicalItemPose({ ...defaultInput, targetCategory: 'C', elapsedMs: 20000 });
|
||||
expect(pose.surface).toBe('c_cage_floor');
|
||||
@@ -94,6 +126,26 @@ describe('physicalItemMotion', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('B final pose fixed after +1000 ms', () => {
|
||||
const t0 = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 10000 });
|
||||
const t1 = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 11000 });
|
||||
expect(t0.surface).toBe('b_bin_floor');
|
||||
expect(t0.position).toEqual(t1.position);
|
||||
});
|
||||
|
||||
it('no teleport between adjacent sampled poses', () => {
|
||||
let prev = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: 0 });
|
||||
for (let t = 100; t <= 10000; t += 100) {
|
||||
const cur = getPhysicalItemPose({ ...defaultInput, targetCategory: 'B', elapsedMs: t });
|
||||
const dx = cur.position[0] - prev.position[0];
|
||||
const dy = cur.position[1] - prev.position[1];
|
||||
const dz = cur.position[2] - prev.position[2];
|
||||
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
expect(dist).toBeLessThan(1.5); // max ~1m per 100ms at 1m/s
|
||||
prev = cur;
|
||||
}
|
||||
});
|
||||
|
||||
it('routes C down the chute before settling', () => {
|
||||
const pose = getPhysicalItemPose({ ...defaultInput, targetCategory: 'C', elapsedMs: 7000 });
|
||||
expect(pose.surface).toBe('chute_c');
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
type SurfaceName,
|
||||
type Vec3,
|
||||
} from './conveyorNetwork';
|
||||
import { B_RECEIVER, CAGE_FLOOR_Y, ROLL_CAGE } from './physicalLayout';
|
||||
|
||||
export type SurfaceType = SurfaceName;
|
||||
export type MotionPhase = 'feed' | 'inspection' | 'decision' | 'routing' | 'settled';
|
||||
@@ -59,30 +58,24 @@ function poseOnSurface(name: SurfaceName, t: number, itemHeightM: number): { pos
|
||||
};
|
||||
}
|
||||
|
||||
/** Deterministic slot position inside a cage (grid, stays within bounds). */
|
||||
function cageSlot(name: SurfaceName, slotIndex: number, itemHeightM: number): { pos: Vec3; rotY: number } {
|
||||
const b = SURFACES[name].bounds;
|
||||
/**
|
||||
* Deterministic settled slot inside any bin/cage floor surface.
|
||||
* Uses the surface's own bounds so items always stay contained (grid 3×2).
|
||||
*/
|
||||
function settledSlot(name: SurfaceName, slotIndex: number, itemHeightM: number): { pos: Vec3; rotY: number } {
|
||||
const s = SURFACES[name];
|
||||
const b = s.bounds;
|
||||
const cx = (b.minX + b.maxX) / 2;
|
||||
const cz = (b.minZ + b.maxZ) / 2;
|
||||
// 3 columns × 2 rows grid inside the cage footprint.
|
||||
const col = slotIndex % 3; // 0,1,2
|
||||
const spanX = b.maxX - b.minX;
|
||||
const spanZ = b.maxZ - b.minZ;
|
||||
const col = slotIndex % 3; // 0,1,2
|
||||
const row = Math.floor(slotIndex / 3) % 2; // 0,1
|
||||
const offsetX = (col - 1) * (ROLL_CAGE.width / 3.2); // ~±0.375
|
||||
const offsetZ = (row - 0.5) * (ROLL_CAGE.depth / 2.4); // ~±0.17
|
||||
const offsetX = (col - 1) * (spanX / 3.5); // stays well within bounds
|
||||
const offsetZ = (row - 0.5) * (spanZ / 3.0);
|
||||
return {
|
||||
pos: [cx + offsetX, CAGE_FLOOR_Y + itemHeightM / 2, cz + offsetZ],
|
||||
rotY: (slotIndex % 4) * (Math.PI / 8), // small fixed yaw variety, deterministic
|
||||
};
|
||||
}
|
||||
|
||||
/** Deterministic rest position inside the B receiver tray (stacks backwards). */
|
||||
function bReceiverSlot(slotIndex: number, itemHeightM: number): { pos: Vec3; rotY: number } {
|
||||
const spacing = 0.55;
|
||||
let x = B_RECEIVER.restX - (slotIndex % 4) * spacing;
|
||||
if (x < B_RECEIVER.startX + 0.3) x = B_RECEIVER.startX + 0.3;
|
||||
return {
|
||||
pos: [x, B_RECEIVER.y + itemHeightM / 2, 0],
|
||||
rotY: 0,
|
||||
pos: [cx + offsetX, s.surfaceY + itemHeightM / 2, cz + offsetZ],
|
||||
rotY: (slotIndex % 4) * (Math.PI / 8),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,15 +116,19 @@ export function getPhysicalItemPose(input: PoseInput): PhysicalItemPose {
|
||||
const r = poseOnSurface('routing_junction', t, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = 'routing_junction'; phase = 'decision';
|
||||
} else if (category === 'B') {
|
||||
// B: travel along the receiving tray, then rest inside it.
|
||||
const travelSpan = clearStart - routingStart;
|
||||
// B: short transfer spur → drop chute → settle inside floor bin.
|
||||
const exitStart = starts['exit'];
|
||||
const travelSpan = exitStart - routingStart;
|
||||
const t = (elapsedMs - routingStart) / travelSpan;
|
||||
if (t < 1) {
|
||||
const r = poseOnSurface('b_receiver', t, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = 'b_receiver'; phase = 'routing';
|
||||
if (t < 0.35) {
|
||||
const r = poseOnSurface('b_transfer', t / 0.35, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = 'b_transfer'; phase = 'routing';
|
||||
} else if (t < 0.88) {
|
||||
const r = poseOnSurface('chute_b', (t - 0.35) / 0.53, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = 'chute_b'; phase = 'routing';
|
||||
} else {
|
||||
const r = bReceiverSlot(slotIndex, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = 'b_receiver'; phase = 'settled';
|
||||
const r = settledSlot('b_bin_floor', slotIndex, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = 'b_bin_floor'; phase = 'settled';
|
||||
isSettled = elapsedMs >= total;
|
||||
}
|
||||
} else {
|
||||
@@ -144,7 +141,7 @@ export function getPhysicalItemPose(input: PoseInput): PhysicalItemPose {
|
||||
const r = poseOnSurface(chuteName, t, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = chuteName; phase = 'routing';
|
||||
} else {
|
||||
const r = cageSlot(cageName, slotIndex, itemHeightM);
|
||||
const r = settledSlot(cageName, slotIndex, itemHeightM);
|
||||
pos = r.pos; rotY = r.rotY; surface = cageName; phase = 'settled';
|
||||
isSettled = elapsedMs >= total;
|
||||
}
|
||||
|
||||
@@ -144,17 +144,19 @@ export const CHUTE_SLOPE_START_Y = BELT_TOP_Y; // 0.7m at junction
|
||||
export const CHUTE_END_Y = CAGE_FLOOR_Y + 0.05; // safe entry height into cage
|
||||
|
||||
// =========================================================
|
||||
// B receiving zone (short downstream receiving tray after sorter)
|
||||
// Physical tray at belt height with low side walls and an end stop,
|
||||
// so B items visibly land and remain instead of vanishing.
|
||||
// B receiving bin — отдельный промышленный контейнер на полу.
|
||||
// НЕ продолжение конвейера: короткий transfer spur → drop chute → bin floor.
|
||||
// Размер ~1.2×0.8×0.5 m (как C/D по footprint).
|
||||
// =========================================================
|
||||
export const B_RECEIVER = {
|
||||
startX: ZONES.GATE.x + 0.7, // 2.2m — begins after routing junction
|
||||
endX: ZONES.B.x + 0.4, // 4.4m — end stop
|
||||
y: BELT_TOP_Y, // 0.7m top surface
|
||||
width: CONVEYOR_WIDTH_M, // 0.5m
|
||||
wallHeight: 0.12, // 120mm side/end walls
|
||||
restX: ZONES.B.x, // 4.0m — where the item comes to rest
|
||||
centerX: 3.35, // отдельно после конца ленты
|
||||
centerZ: 0,
|
||||
width: 1.2, // 1200 mm
|
||||
depth: 0.8, // 800 mm
|
||||
wallHeight: 0.5, // 500 mm walls
|
||||
floorY: CAGE_FLOOR_Y, // 0.08 m interior floor
|
||||
transferStartX: ZONES.GATE.x, // 1.5 m — spur starts at junction
|
||||
transferEndX: 2.15, // 0.65 m short spur, NOT a long belt extension
|
||||
};
|
||||
|
||||
// =========================================================
|
||||
|
||||
Reference in New Issue
Block a user