Prompt specification
Build or customize the Three.js 3D scene "Miniature Packaging Robot Cell" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Miniature Packaging Robot Cell
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/miniature-packaging-robot-cell-x2063
Scene Description Prompt:
Use Three.js from cdnjs to build an original compact cell with feeder, robot, box, and inspection station. Use a deterministic task sequence and show waiting when an upstream or downstream station is unavailable. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (miniature-packaging-robot-cell-x2063):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Block Relay — Deterministic Voxel Cell</title>
<style>
:root {
--bg: #08131f;
--panel: rgba(11, 24, 39, 0.88);
--panel-border: rgba(155, 198, 232, 0.17);
--text: #edf6ff;
--muted: #91a9bd;
--cyan: #32e0cd;
--blue: #6ca8ff;
--orange: #ffb454;
--red: #ff5f73;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 15px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#header {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 20px 16px;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 3px;
font-size: 27px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
color: var(--muted);
font-size: 12px;
}
.state-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
#stateDot {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 15px currentColor;
}
#stateName {
font-size: 14px;
font-weight: 800;
letter-spacing: 0.03em;
}
#stateDetail {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.cycle {
margin-left: auto;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
text-transform: uppercase;
letter-spacing: 0.1em;
}
#availability {
top: 18px;
right: 18px;
width: 244px;
padding: 13px 15px;
}
.availability-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.availability-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 0;
font-size: 11px;
}
.station-name {
display: flex;
align-items: center;
gap: 8px;
}
.mini-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 10px currentColor;
}
.station-state {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
}
#controls {
display: flex;
gap: 7px;
margin-top: 11px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
button {
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 8px;
padding: 8px 11px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 150ms, transform 150ms;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
}
button:active {
transform: translateY(1px);
}
#waitBanner {
position: fixed;
z-index: 9;
top: 18px;
left: 50%;
max-width: min(410px, calc(100vw - 36px));
padding: 12px 17px;
border: 1px solid rgba(255, 180, 84, 0.42);
border-radius: 12px;
background: rgba(54, 32, 13, 0.92);
color: #ffd49a;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.025em;
text-align: center;
opacity: 0;
transform: translate(-50%, -12px);
transition: opacity 180ms, transform 180ms;
pointer-events: none;
}
#waitBanner.show {
opacity: 1;
transform: translate(-50%, 0);
}
#timeline {
left: 50%;
bottom: 18px;
width: min(1120px, calc(100vw - 36px));
padding: 12px 14px 13px;
transform: translateX(-50%);
}
.timeline-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 9px;
}
.timeline-title {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.timeline-hint {
color: #647e93;
font-size: 9px;
}
#steps {
display: grid;
grid-template-columns: repeat(10, minmax(92px, 1fr));
gap: 5px;
overflow-x: auto;
padding-bottom: 1px;
}
.step {
min-width: 0;
padding: 7px 8px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 7px;
background: rgba(255, 255, 255, 0.035);
color: #6f879b;
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.035em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transition: 160ms;
}
.step.done {
color: #91adbf;
border-color: rgba(50, 224, 205, 0.13);
}
.step.current {
color: #071b20;
border-color: var(--cyan);
background: var(--cyan);
box-shadow: 0 0 18px rgba(50, 224, 205, 0.18);
}
#cameraHint {
position: fixed;
z-index: 8;
right: 19px;
bottom: 145px;
color: rgba(202, 224, 241, 0.54);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 760px) {
#header {
width: calc(100vw - 36px);
}
#availability {
top: auto;
right: 18px;
bottom: 145px;
width: 205px;
}
#timeline {
bottom: 12px;
width: calc(100vw - 24px);
}
#waitBanner {
top: 190px;
}
#cameraHint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<section id="header" class="panel">
<div class="eyebrow">Voxel Cell / 07</div>
<h1>Block Relay</h1>
<div class="subtitle">Feeder → Robot → Inspection → Dispatch</div>
<div class="state-row" aria-live="polite">
<div id="stateDot"></div>
<div>
<div id="stateName">INITIALIZING</div>
<div id="stateDetail">Preparing the deterministic task cycle.</div>
</div>
<div class="cycle">Cycle <span id="cycleNumber">01</span></div>
</div>
</section>
<section id="availability" class="panel">
<div class="availability-title">Station availability</div>
<div class="availability-row">
<div class="station-name">
<span id="feederDot" class="mini-dot"></span>
<span>Upstream feeder</span>
</div>
<span id="feederState" class="station-state">PAUSED</span>
</div>
<div class="availability-row">
<div class="station-name">
<span id="inspectionDot" class="mini-dot"></span>
<span>Downstream inspection</span>
</div>
<span id="inspectionState" class="station-state">AVAILABLE</span>
</div>
<div id="controls">
<button id="pauseButton" type="button">Pause</button>
<button id="speedButton" type="button">Speed 1×</button>
</div>
</section>
<div id="waitBanner" role="status"></div>
<section id="timeline" class="panel">
<div class="timeline-head">
<div class="timeline-title">Deterministic task sequence</div>
<div class="timeline-hint">Fixed repeat · no random timing</div>
</div>
<div id="steps"></div>
</section>
<div id="cameraHint">DRAG TO ORBIT · WHEEL TO ZOOM · DOUBLE-CLICK TO RESET</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
DOM and renderer
-------------------------------------------------------------------------- */
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08131f);
scene.fog = new THREE.Fog(0x08131f, 19, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.65, 0);
let cameraYaw = 0.72;
let cameraPitch = 0.61;
let cameraDistance = 16.7;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
/* --------------------------------------------------------------------------
Lighting
-------------------------------------------------------------------------- */
scene.add(new THREE.HemisphereLight(0xb9d9ff, 0x18202b, 1.8));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(4, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x35d9d0, 1.35);
rimLight.position.set(-8, 5, -7);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa452, 16, 9, 2);
warmLight.position.set(-4, 3.4, 2.8);
scene.add(warmLight);
/* --------------------------------------------------------------------------
Geometry and material helpers
-------------------------------------------------------------------------- */
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.08,
flatShading: true
}));
}
return materialCache.get(color);
}
function block(parent, size, position, color, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, getMaterial(color));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function createLabel(initialLines, width = 3, accent = "#32e0cd") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 160;
const ctx = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 160 / 512, 1);
sprite.renderOrder = 20;
function setText(lines) {
ctx.clearRect(0, 0, 512, 160);
roundedRect(ctx, 8, 8, 496, 144, 22);
ctx.fillStyle = "rgba(7, 19, 31, 0.88)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 4;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
if (lines.length === 1) {
ctx.fillStyle = accent;
ctx.font = "800 40px system-ui, sans-serif";
ctx.fillText(lines[0], 256, 80);
} else {
ctx.fillStyle = "#8fa9bc";
ctx.font = "800 25px system-ui, sans-serif";
ctx.fillText(lines[0], 256, 52);
ctx.fillStyle = accent;
ctx.font = "800 42px system-ui, sans-serif";
ctx.fillText(lines[1], 256, 107);
}
texture.needsUpdate = true;
}
setText(initialLines);
return { sprite, setText };
}
function makeBeacon(parent, position, color = 0x32e0cd) {
block(parent, [0.08, 0.35, 0.08],
[position[0], position[1] - 0.08, position[2]], 0x142131, false);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.8,
roughness: 0.35
});
const lamp = block(parent, [0.18, 0.19, 0.18], position, material, false);
return { lamp, material };
}
/* --------------------------------------------------------------------------
Voxel floor and cell decoration
-------------------------------------------------------------------------- */
block(scene, [15.5, 0.36, 9.7], [0, -0.48, 0], 0x172534, false);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
metalness: 0.03
});
const tileCountX = 15;
const tileCountZ = 9;
const floorTiles = new THREE.InstancedMesh(
unitBox,
tileMaterial,
tileCountX * tileCountZ
);
const dummy = new THREE.Object3D();
let tileIndex = 0;
for (let x = 0; x < tileCountX; x++) {
for (let z = 0; z < tileCountZ; z++) {
const px = (x - (tileCountX - 1) / 2) * 0.98;
const pz = (z - (tileCountZ - 1) / 2) * 0.98;
dummy.position.set(px, -0.22, pz);
dummy.scale.set(0.92, 0.18, 0.92);
dummy.updateMatrix();
floorTiles.setMatrixAt(tileIndex, dummy.matrix);
const alternate = (x + z) % 2 === 0;
floorTiles.setColorAt(
tileIndex,
new THREE.Color(alternate ? 0x2c4050 : 0x243746)
);
tileIndex++;
}
}
floorTiles.instanceMatrix.needsUpdate = true;
floorTiles.instanceColor.needsUpdate = true;
floorTiles.receiveShadow = true;
scene.add(floorTiles);
// Low rear wall made from visible blocks.
for (let x = -7; x <= 7; x++) {
block(scene, [0.93, 0.85, 0.24], [x, 0.24, -4.42], 0x263b4b);
block(scene, [0.93, 0.10, 0.27], [x, 0.72, -4.42], 0x3c596d);
}
// Safety dashes around the robot work area.
for (let i = 0; i < 9; i++) {
block(scene, [0.38, 0.035, 0.08],
[-3.35 + i * 0.67, -0.105, 1.92], 0xe7ad42, false);
block(scene, [0.38, 0.035, 0.08],
[-3.35 + i * 0.67, -0.105, -1.92], 0xe7ad42, false);
}
// Directional voxel arrows on the floor.
for (let i = 0; i < 5; i++) {
block(scene, [0.30, 0.035, 0.08], [-4.7 + i * 0.45, -0.105, 0], 0x315c78, false);
}
block(scene, [0.12, 0.04, 0.42], [-2.55, -0.10, 0], 0x315c78, false);
block(scene, [0.12, 0.04, 0.24], [-2.55, -0.095, 0.19], 0x315c78, false);
block(scene, [0.12, 0.04, 0.24], [-2.55, -0.095, -0.19], 0x315c78, false);
/* --------------------------------------------------------------------------
Feeder station
-------------------------------------------------------------------------- */
const feeder = new THREE.Group();
feeder.position.set(-5, 0, 0);
scene.add(feeder);
block(feeder, [1.65, 1.08, 1.48], [0, 0.53, 0], 0x355a7a);
block(feeder, [1.78, 0.16, 1.60], [0, 1.12, 0], 0x517da3);
block(feeder, [1.32, 0.34, 1.12], [0, 0.48, 0.76], 0x172a3c);
block(feeder, [0.58, 0.32, 0.035], [0, 0.58, 1.01], 0x68b4ff);
block(feeder, [0.20, 0.06, 0.05], [0, 0.42, 1.04], 0x32e0cd);
// Chute toward the robot.
block(feeder, [1.45, 0.17, 0.86], [1.28, 1.03, 0], 0x1b2d3f);
block(feeder, [1.45, 0.20, 0.10], [1.28, 1.12, 0.45], 0x7592aa);
block(feeder, [1.45, 0.20, 0.10], [1.28, 1.12, -0.45], 0x7592aa);
// Hopper assembled from separate voxel blocks.
for (let x = 0; x < 3; x++) {
for (let y = 0; y < 2; y++) {
for (let z = 0; z < 2; z++) {
block(feeder, [0.27, 0.27, 0.27],
[-0.57 + x * 0.29, 1.33 + y * 0.29, -0.28 + z * 0.29],
(x + y + z) % 2 ? 0xf3b649 : 0xffcf72);
}
}
}
const feederBeacon = makeBeacon(feeder, [-0.52, 2.02, 0.52], 0xff5f73);
const feederLabel = createLabel(["01 FEEDER", "UPSTREAM"], 2.65, "#6ca8ff");
feederLabel.sprite.position.set(-4.85, 2.63, 0);
scene.add(feederLabel.sprite);
/* --------------------------------------------------------------------------
Inspection and dispatch station
-------------------------------------------------------------------------- */
const inspection = new THREE.Group();
inspection.position.set(1.9, 0, 0);
scene.add(inspection);
block(inspection, [1.75, 0.18, 1.55], [0, 0.86, 0], 0x3a6672);
block(inspection, [1.55, 0.09, 1.35], [0, 0.98, 0], 0x5a8994);
for (const x of [-0.66, 0.66]) {
for (const z of [-0.59, 0.59]) {
block(inspection, [0.13, 0.78, 0.13], [x, 0.43, z], 0x253e4d);
}
}
// Scanner arch.
block(inspection, [0.22, 1.38, 0.22], [0, 1.52, -0.70], 0x4a8190);
block(inspection, [0.22, 1.38, 0.22], [0, 1.52, 0.70], 0x4a8190);
block(inspection, [0.24, 0.23, 1.62], [0, 2.22, 0], 0x5b94a0);
block(inspection, [0.08, 0.62, 0.44], [0.14, 1.55, 0.62], 0x172b38);
const scannerMaterial = new THREE.MeshBasicMaterial({
color: 0x49f4df,
transparent: true,
opacity: 0.20,
depthWrite: false
});
const scanBeam = block(inspection, [1.45, 1.38, 0.045], [0, 1.52, 0], scannerMaterial, false);
scanBeam.visible = false;
const inspectionBeacon = makeBeacon(inspection, [0.72, 2.50, 0.48], 0x32e0cd);
const inspectionLabel = createLabel(["02 INSPECTION", "DOWNSTREAM"], 3.1, "#32e0cd");
inspectionLabel.sprite.position.set(1.9, 2.92, 0);
scene.add(inspectionLabel.sprite);
// Outbound conveyor.
block(inspection, [3.25, 0.22, 1.15], [2.12, 0.72, 0], 0x1b2c3c);
block(inspection, [3.25, 0.10, 0.12], [2.12, 0.88, 0.56], 0x607d8f);
block(inspection, [3.25, 0.10, 0.12], [2.12, 0.88, -0.56], 0x607d8f);
const beltBlocks = [];
for (let i = 0; i < 8; i++) {
const strip = block(inspection, [0.12, 0.07, 0.94],
[0.66 + i * 0.35, 0.90, 0], 0x89a4af, false);
beltBlocks.push(strip);
}
// Output collection bin.
block(inspection, [0.95, 0.18, 1.20], [3.52, 0.46, 0], 0x30495b);
block(inspection, [0.12, 0.64, 1.20], [3.96, 0.76, 0], 0x4b687a);
block(inspection, [0.95, 0.64, 0.12], [3.52, 0.76, 0.54], 0x4b687a);
block(inspection, [0.95, 0.64, 0.12], [3.52, 0.76, -0.54], 0x4b687a);
/* --------------------------------------------------------------------------
Robot
-------------------------------------------------------------------------- */
const robot = new THREE.Group();
robot.position.set(-0.8, 0, 0);
scene.add(robot);
block(robot, [1.02, 0.22, 1.02], [0, 0.12, 0], 0x162637);
block(robot, [0.80, 0.20, 0.80], [0, 0.33, 0], 0x334b5d);
block(robot, [0.61, 0.55, 0.61], [0, 0.70, 0], 0xe97c3d);
const robotYaw = new THREE.Group();
robot.add(robotYaw);
block(robotYaw, [0.88, 0.65, 0.78], [0, 1.12, 0], 0xf28a42);
block(robotYaw, [0.68, 0.36, 0.62], [0, 1.62, 0], 0xffb064);
block(robotYaw, [0.13, 0.10, 0.04], [0.15, 1.66, 0.33], 0x132636);
block(robotYaw, [0.13, 0.10, 0.04], [-0.15, 1.66, 0.33], 0x132636);
const robotBeacon = makeBeacon(robotYaw, [0, 2.02, 0], 0x32e0cd);
// Arm geometry.
const L1 = 1.45;
const L2 = 1.35;
const shoulder = new THREE.Group();
shoulder.position.set(0, 1.25, 0.12);
robotYaw.add(shoulder);
block(shoulder, [0.30, 0.30, 0.30], [0, 0, 0], 0x263e50);
block(shoulder, [L1, 0.21, 0.22], [L1 / 2, 0, 0], 0xf5a35f);
const elbow = new THREE.Group();
elbow.position.x = L1;
shoulder.add(elbow);
block(elbow, [0.29, 0.29, 0.29], [0, 0, 0], 0x243c4d);
block(elbow, [L2, 0.18, 0.19], [L2 / 2, 0, 0], 0xffb66e);
const wrist = new THREE.Group();
wrist.position.x = L2;
elbow.add(wrist);
block(wrist, [0.25, 0.24, 0.30], [0.03, 0, 0], 0x263e50);
const leftFinger = block(wrist, [0.28, 0.35, 0.08], [0.18, -0.20, 0.17], 0xaac0cd);
const rightFinger = block(wrist, [0.28, 0.35, 0.08], [0.18, -0.20, -0.17], 0xaac0cd);
const heldAnchor = new THREE.Object3D();
heldAnchor.position.set(0.25, -0.58, 0);
wrist.add(heldAnchor);
const robotLabel = createLabel(["ROBOT", "READY"], 2.55, "#ffb454");
robotLabel.sprite.position.set(-0.8, 2.72, 0);
scene.add(robotLabel.sprite);
/* --------------------------------------------------------------------------
The voxel box traveling through the cell
-------------------------------------------------------------------------- */
const part = new THREE.Group();
scene.add(part);
const partMaterial = new THREE.MeshStandardMaterial({
color: 0xf3b649,
roughness: 0.65,
metalness: 0.03,
flatShading: true
});
for (let x = -1; x <= 1; x++) {
for (let y = 0; y < 1; y++) {
for (let z = -1; z <= 1; z++) {
block(part, [0.205, 0.205, 0.205],
[x * 0.215, (y - 0.5) * 0.215, z * 0.215], partMaterial);
}
}
}
// A small darker voxel band keeps the box visually readable.
block(part, [0.035, 0.43, 0.67], [0.01, 0, 0], 0x29404b);
const feedStart = new THREE.Vector3(-4.48, 1.38, 0);
const feedTarget = new THREE.Vector3(-3.35, 1.15, 0);
const inspectTarget = new THREE.Vector3(1.90, 1.15, 0);
const dispatchTarget = new THREE.Vector3(5.30, 0.78, 0);
const partPalette = [0xf3b649, 0xff786a, 0xa98aff, 0x61d7b0, 0xff9f52];
/* --------------------------------------------------------------------------
Deterministic state machine
-------------------------------------------------------------------------- */
const sequence = [
{
id: "waitFeeder",
label: "Wait feeder",
duration: 2.4,
detail: "Upstream feeder is unavailable. The robot holds position and waits."
},
{
id: "feed",
label: "Feed",
duration: 1.1,
detail: "The feeder releases one voxel box onto the pickup chute."
},
{
id: "pick",
label: "Pick",
duration: 1.3,
detail: "The robot reaches to the feeder and closes its gripper."
},
{
id: "transfer",
label: "Transfer",
duration: 1.8,
detail: "The robot rotates and carries the box to the inspection cell."
},
{
id: "place",
label: "Place",
duration: 1.2,
detail: "The robot places the box on the inspection platform."
},
{
id: "scan",
label: "Scan",
duration: 1.6,
detail: "The downstream inspection scanner checks the box."
},
{
id: "waitInspection",
label: "Wait inspect",
duration: 2.2,
detail: "The downstream inspection station is unavailable. The robot waits."
},
{
id: "resumeScan",
label: "Resume",
duration: 1.3,
detail: "Inspection is available again and completes the scan."
},
{
id: "dispatch",
label: "Dispatch",
duration: 1.4,
detail: "The accepted box travels along the outbound conveyor."
},
{
id: "reset",
label: "Reset",
duration: 1.0,
detail: "The cell clears the output and prepares the next deterministic cycle."
}
];
let currentState = 0;
let stateStart = 0;
let simulationTime = 0;
let cycle = 1;
let paused = false;
let playbackSpeed = 1;
let lastFrame = performance.now();
const stepsElement = document.getElementById("steps");
const stepElements = sequence.map((state, index) => {
const element = document.createElement("div");
element.className = "step";
element.textContent = String(index + 1).padStart(2, "0") + " " + state.label;
stepsElement.appendChild(element);
return element;
});
function setPartColor() {
partMaterial.color.setHex(partPalette[(cycle - 1) % partPalette.length]);
}
function isFeederAvailable() {
const id = sequence[currentState].id;
return id !== "waitFeeder" && id !== "reset";
}
function isInspectionAvailable() {
return sequence[currentState].id !== "waitInspection";
}
function updateUI() {
const state = sequence[currentState];
const feederAvailable = isFeederAvailable();
const inspectionAvailable = isInspectionAvailable();
const waiting = state.id === "waitFeeder" || state.id === "waitInspection";
document.getElementById("stateName").textContent = state.label.toUpperCase();
document.getElementById("stateDetail").textContent = state.detail;
document.getElementById("cycleNumber").textContent = String(cycle).padStart(2, "0");
const stateDot = document.getElementById("stateDot");
stateDot.style.background = waiting ? "#ffb454" : "#32e0cd";
stateDot.style.color = waiting ? "#ffb454" : "#32e0cd";
document.getElementById("feederState").textContent = feederAvailable ? "AVAILABLE" : "PAUSED";
document.getElementById("feederState").style.color = feederAvailable ? "#32e0cd" : "#ff5f73";
document.getElementById("feederDot").style.background = feederAvailable ? "#32e0cd" : "#ff5f73";
document.getElementById("feederDot").style.color = feederAvailable ? "#32e0cd" : "#ff5f73";
document.getElementById("inspectionState").textContent = inspectionAvailable ? "AVAILABLE" : "PAUSED";
document.getElementById("inspectionState").style.color = inspectionAvailable ? "#32e0cd" : "#ff5f73";
document.getElementById("inspectionDot").style.background = inspectionAvailable ? "#32e0cd" : "#ff5f73";
document.getElementById("inspectionDot").style.color = inspectionAvailable ? "#32e0cd" : "#ff5f73";
stepElements.forEach((element, index) => {
element.classList.toggle("current", index === currentState);
element.classList.toggle("done", index < currentState);
});
const banner = document.getElementById("waitBanner");
banner.classList.toggle("show", waiting);
if (state.id === "waitFeeder") {
banner.textContent = "UPSTREAM PAUSED — waiting for the feeder to become available";
robotLabel.setText(["ROBOT", "WAIT: FEEDER"]);
} else if (state.id === "waitInspection") {
banner.textContent = "DOWNSTREAM PAUSED — waiting for inspection to become available";
robotLabel.setText(["ROBOT", "WAIT: INSPECTION"]);
} else {
const robotText = {
feed: "FEEDING",
pick: "PICKING",
transfer: "TRANSFERRING",
place: "PLACING",
scan: "INSPECTING",
resumeScan: "RESUMING",
dispatch: "DISPATCHING",
reset: "CYCLE READY"
}[state.id] || "READY";
robotLabel.setText(["ROBOT", robotText]);
}
}
/* --------------------------------------------------------------------------
Two-link arm IK and animation helpers
-------------------------------------------------------------------------- */
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smooth(value) {
const t = clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function setIK(localX, localY) {
const distance = clamp(Math.hypot(localX, localY), 0.15, L1 + L2 - 0.001);
const cosine = clamp(
(distance * distance - L1 * L1 - L2 * L2) / (2 * L1 * L2),
-1,
1
);
const elbowAngle = Math.acos(cosine);
const targetAngle = Math.atan2(localY, localX);
const shoulderAngle = targetAngle - Math.atan2(
L2 * Math.sin(elbowAngle),
L1 + L2 * Math.cos(elbowAngle)
);
shoulder.rotation.z = shoulderAngle;
elbow.rotation.z = elbowAngle;
}
const armHome = new THREE.Vector2(1.15, 0.50);
const armPick = new THREE.Vector2(2.21, 0.48);
const armPlace = new THREE.Vector2(2.36, 0.48);
function setRobotPose(yaw, reach, destination) {
robotYaw.rotation.y = yaw;
const target = destination === "pick"
? armPick
: destination === "place"
? armPlace
: armHome;
const localX = THREE.MathUtils.lerp(armHome.x, target.x, reach);
const localY = THREE.MathUtils.lerp(armHome.y, target.y, reach);
setIK(localX, localY);
}
const anchorWorld = new THREE.Vector3();
function copyHeldPosition() {
robot.updateMatrixWorld(true);
heldAnchor.getWorldPosition(anchorWorld);
part.position.copy(anchorWorld);
}
/* --------------------------------------------------------------------------
Per-state animation
-------------------------------------------------------------------------- */
function updateSimulation() {
const state = sequence[currentState];
const progress = clamp((simulationTime - stateStart) / state.duration, 0, 1);
part.visible = state.id !== "waitFeeder" && state.id !== "reset";
switch (state.id) {
case "waitFeeder":
setRobotPose(0, 0, "home");
break;
case "feed": {
setRobotPose(0, 0, "home");
part.position.lerpVectors(feedStart, feedTarget, smooth(progress));
part.rotation.y = progress * 0.55;
break;
}
case "pick": {
setRobotPose(Math.PI, smooth(progress), "pick");
robot.updateMatrixWorld(true);
heldAnchor.getWorldPosition(anchorWorld);
if (progress < 0.58) {
part.position.copy(feedTarget);
} else {
part.position.lerpVectors(
feedTarget,
anchorWorld,
smooth((progress - 0.58) / 0.42)
);
}
const grip = smooth((progress - 0.58) / 0.35);
leftFinger.position.z = 0.17 - grip * 0.075;
rightFinger.position.z = -0.17 + grip * 0.075;
part.rotation.y *= 1 - progress;
break;
}
case "transfer": {
if (progress < 0.38) {
const turn = smooth(progress / 0.38);
setRobotPose(THREE.MathUtils.lerp(Math.PI, 0, turn), 0, "home");
} else {
const reach = smooth((progress - 0.38) / 0.62);
setRobotPose(0, reach, "place");
}
copyHeldPosition();
part.rotation.y = 0;
leftFinger.position.z = 0.095;
rightFinger.position.z = -0.095;
break;
}
case "place": {
const release = smooth((progress - 0.72) / 0.25);
const reach = progress < 0.78
? smooth(progress / 0.78)
: 1 - smooth((progress - 0.78) / 0.22) * 0.30;
setRobotPose(0, reach, "place");
robot.updateMatrixWorld(true);
heldAnchor.getWorldPosition(anchorWorld);
if (progress < 0.72) {
part.position.copy(anchorWorld);
} else {
part.position.lerpVectors(anchorWorld, inspectTarget, release);
}
const opening = smooth((progress - 0.65) / 0.25);
leftFinger.position.z = 0.095 + opening * 0.075;
rightFinger.position.z = -0.095 - opening * 0.075;
part.rotation.y = 0;
break;
}
case "scan":
case "waitInspection":
case "resumeScan":
setRobotPose(0, 0, "home");
part.position.copy(inspectTarget);
part.rotation.y = 0;
leftFinger.position.z = 0.17;
rightFinger.position.z = -0.17;
break;
case "dispatch": {
setRobotPose(0, 0, "home");
part.position.lerpVectors(inspectTarget, dispatchTarget, smooth(progress));
part.position.y -= smooth((progress - 0.80) / 0.20) * 0.20;
part.rotation.y = progress * 0.16;
break;
}
case "reset":
setRobotPose(0, 0, "home");
break;
}
// Feeder beacon: red while paused, amber while feeding, green otherwise.
const feederColor = !isFeederAvailable()
? 0xff5f73
: state.id === "feed"
? 0xffb454
: 0x32e0cd;
feederBeacon.material.color.setHex(feederColor);
feederBeacon.material.emissive.setHex(feederColor);
feederBeacon.material.emissiveIntensity =
state.id === "feed" ? 1.3 + Math.sin(simulationTime * 12) * 0.7 : 1.8;
// Inspection beacon: red during its deterministic unavailable interval.
const inspectionColor = isInspectionAvailable() ? 0x32e0cd : 0xff5f73;
inspectionBeacon.material.color.setHex(inspectionColor);
inspectionBeacon.material.emissive.setHex(inspectionColor);
inspectionBeacon.material.emissiveIntensity = isInspectionAvailable() ? 1.8 : 2.4;
// Robot status beacon.
const robotColor = state.id === "waitFeeder" || state.id === "waitInspection"
? 0xffb454
: state.id === "scan" || state.id === "resumeScan"
? 0x32e0cd
: 0x6ca8ff;
robotBeacon.material.color.setHex(robotColor);
robotBeacon.material.emissive.setHex(robotColor);
robotBeacon.material.emissiveIntensity = 1.8;
// Scanner sweep.
const scanning = state.id === "scan" || state.id === "resumeScan";
scanBeam.visible = scanning;
if (scanning) {
const speed = state.id === "scan" ? 4.5 : 7.0;
const phase = (Math.sin(simulationTime * speed) + 1) * 0.5;
scanBeam.position.z = THREE.MathUtils.lerp(-0.63, 0.63, phase);
scannerMaterial.opacity = 0.15 + phase * 0.13;
}
// Outbound conveyor blocks move continuously.
beltBlocks.forEach((strip, index) => {
const offset = (index * 0.35 + simulationTime * 0.58) % 2.65;
strip.position.x = 0.66 + offset;
});
}
/* --------------------------------------------------------------------------
Input and playback controls
-------------------------------------------------------------------------- */
const pauseButton = document.getElementById("pauseButton");
const speedButton = document.getElementById("speedButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
speedButton.addEventListener("click", () => {
const speeds = [0.5, 1, 1.5];
playbackSpeed = speeds[(speeds.indexOf(playbackSpeed) + 1) % speeds.length];
speedButton.textContent = `Speed ${playbackSpeed}×`;
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
cameraYaw = 0.72;
cameraPitch = 0.61;
cameraDistance = 16.7;
}
});
// Custom camera controls implemented without Three.js addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = clamp(cameraPitch + dy * 0.005, 0.28, 1.16);
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraDistance = clamp(cameraDistance + event.deltaY * 0.012, 10, 24);
}, { passive: false });
canvas.addEventListener("dblclick", () => {
cameraYaw = 0.72;
cameraPitch = 0.61;
cameraDistance = 16.7;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
/* --------------------------------------------------------------------------
Main loop
-------------------------------------------------------------------------- */
setPartColor();
updateUI();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
if (!paused) {
simulationTime += delta * playbackSpeed;
}
// Advance through the fixed state sequence.
while (
simulationTime - stateStart >=
sequence[currentState].duration
) {
stateStart += sequence[currentState].duration;
currentState += 1;
if (currentState >= sequence.length) {
currentState = 0;
cycle += 1;
setPartColor();
}
updateUI();
}
updateSimulation();
updateCamera();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```