Prompt specification
Build or customize the Three.js 3D scene "Unseen Command Combination Puzzle" 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: Unseen Command Combination Puzzle
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/unseen-command-combination-puzzle-x3388
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a small warehouse task combining familiar move, rotate, and place operations in a new sequence. Assess the final arrangement rather than matching one memorized command string. Low-poly.
Working Three.js Starter (unseen-command-combination-puzzle-x3388):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Warehouse Flow — Move / Place / Rotate</title>
<style>
:root {
--ink: #eef8f7;
--muted: #9eb6b7;
--panel: rgba(13, 34, 39, 0.92);
--panel-light: rgba(24, 52, 57, 0.86);
--line: rgba(224, 246, 244, 0.13);
--mint: #72e0c5;
--yellow: #f4ca62;
--coral: #f18473;
--teal: #56c8d5;
--shadow: 0 18px 60px rgba(8, 24, 29, 0.25);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #d9e4e7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
position: absolute;
top: 18px;
left: 18px;
width: 320px;
padding: 17px 18px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--mint);
border-radius: 2px;
box-shadow: 0 0 15px rgba(114, 224, 197, 0.65);
}
h1 {
margin: 7px 0 4px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.task-panel {
position: absolute;
top: 132px;
left: 18px;
width: 320px;
padding: 16px;
border-radius: 16px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.01em;
}
.sequence {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.steps {
display: grid;
gap: 8px;
}
.step {
width: 100%;
display: grid;
grid-template-columns: 31px 1fr auto;
gap: 10px;
align-items: center;
padding: 11px 10px;
color: var(--ink);
text-align: left;
background: rgba(255, 255, 255, 0.035);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.step:hover {
transform: translateX(2px);
background: rgba(255, 255, 255, 0.075);
border-color: rgba(255, 255, 255, 0.16);
}
.step[data-state="done"] {
background: rgba(114, 224, 197, 0.08);
border-color: rgba(114, 224, 197, 0.24);
}
.step-number {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 8px;
color: #10272b;
background: var(--yellow);
font-size: 10px;
font-weight: 900;
}
.step:nth-child(2) .step-number { background: var(--coral); }
.step:nth-child(3) .step-number { background: var(--teal); }
.step-title {
display: block;
font-size: 12px;
font-weight: 800;
}
.step-copy {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.step-state {
color: var(--muted);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
white-space: nowrap;
}
.step[data-state="done"] .step-state {
color: var(--mint);
}
.assessment-note {
margin: 13px 2px 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.assessment-note strong {
color: var(--ink);
font-weight: 750;
}
.check-panel {
position: absolute;
top: 18px;
right: 18px;
width: 286px;
padding: 16px;
border-radius: 16px;
transition: transform 180ms ease, border-color 180ms ease;
}
.check-panel.flash {
transform: scale(1.025);
border-color: rgba(114, 224, 197, 0.55);
}
.check-list {
display: grid;
gap: 8px;
}
.check-row {
display: grid;
grid-template-columns: 11px 1fr auto;
align-items: center;
gap: 8px;
padding: 8px 9px;
border-radius: 9px;
color: var(--muted);
background: rgba(255, 255, 255, 0.03);
font-size: 10px;
}
.check-row.ok {
color: var(--ink);
background: rgba(114, 224, 197, 0.08);
}
.check-dot {
width: 8px;
height: 8px;
border: 1px solid #789094;
border-radius: 50%;
}
.check-row.ok .check-dot {
background: var(--mint);
border-color: var(--mint);
box-shadow: 0 0 10px rgba(114, 224, 197, 0.55);
}
.check-row b {
color: inherit;
font-size: 8px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.verdict {
min-height: 35px;
margin: 12px 1px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.verdict.success { color: var(--mint); }
.verdict.failed { color: #ffd69a; }
.toolbar {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border-radius: 15px;
}
.tool {
min-width: 76px;
height: 42px;
padding: 0 14px;
color: var(--ink);
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.10);
border-radius: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
.tool:hover {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.10);
}
.tool.active {
color: #10272b;
background: var(--mint);
border-color: var(--mint);
box-shadow: 0 5px 20px rgba(114, 224, 197, 0.22);
}
.tool.check {
color: #10272b;
background: var(--yellow);
border-color: var(--yellow);
}
.tool.secondary {
min-width: 42px;
padding: 0 11px;
color: var(--muted);
}
.key {
display: inline-grid;
place-items: center;
min-width: 17px;
height: 17px;
margin-right: 5px;
padding: 0 3px;
color: inherit;
border: 1px solid currentColor;
border-radius: 4px;
opacity: 0.65;
font-size: 8px;
vertical-align: 1px;
}
.camera-hint {
position: absolute;
right: 18px;
bottom: 19px;
color: rgba(25, 49, 54, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.025em;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
#toast {
position: absolute;
left: 50%;
bottom: 86px;
transform: translate(-50%, 10px);
max-width: min(560px, calc(100vw - 32px));
padding: 10px 15px;
color: var(--ink);
background: rgba(13, 34, 39, 0.94);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 650;
text-align: center;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.visible {
transform: translate(-50%, 0);
opacity: 1;
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 15px;
}
.brand h1 { font-size: 20px; }
.brand p { display: none; }
.task-panel {
top: auto;
bottom: 82px;
left: 10px;
width: calc(100% - 20px);
max-height: 42vh;
overflow: auto;
padding: 12px;
}
.steps { grid-template-columns: repeat(3, 1fr); }
.step { grid-template-columns: 1fr; gap: 6px; }
.step-state { display: none; }
.step-copy { font-size: 9px; }
.assessment-note { display: none; }
.check-panel {
top: 82px;
right: 10px;
width: 210px;
padding: 11px;
}
.check-row { padding: 6px; font-size: 9px; }
.check-panel .panel-heading { margin-bottom: 8px; }
.toolbar {
bottom: 10px;
gap: 4px;
padding: 6px;
}
.tool {
min-width: 56px;
height: 39px;
padding: 0 8px;
font-size: 9px;
}
.tool.secondary { display: none; }
.camera-hint { display: none; }
#toast { bottom: 73px; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="hud">
<header class="brand panel">
<div class="eyebrow">Warehouse / Flow 04</div>
<h1>Cross-dock arrangement</h1>
<p>Three familiar operations, sequenced in a new order.</p>
</header>
<section class="task-panel panel" aria-label="Warehouse task">
<div class="panel-heading">
<h2>Today’s sequence</h2>
<span class="sequence">Move → Place → Rotate</span>
</div>
<div class="steps">
<button class="step" data-action="move" data-state="pending" type="button">
<span class="step-number">01</span>
<span>
<span class="step-title">Move amber carton</span>
<span class="step-copy">Take carton A to the yellow staging square.</span>
</span>
<span class="step-state">Move</span>
</button>
<button class="step" data-action="place" data-state="pending" type="button">
<span class="step-number">02</span>
<span>
<span class="step-title">Place coral carton</span>
<span class="step-copy">Set carton C onto the green dispatch pallet.</span>
</span>
<span class="step-state">Place</span>
</button>
<button class="step" data-action="rotate" data-state="pending" type="button">
<span class="step-number">03</span>
<span>
<span class="step-title">Rotate teal carton</span>
<span class="step-copy">Turn carton B 90° clockwise on the turntable.</span>
</span>
<span class="step-state">Rotate</span>
</button>
</div>
<p class="assessment-note">
<strong>Final-state assessment:</strong> the checker inspects where each carton
is and how it is oriented. It does not require a particular command history.
</p>
</section>
<aside id="checkPanel" class="check-panel panel" aria-label="Arrangement checker">
<div class="panel-heading">
<h2>Arrangement checker</h2>
<span class="sequence">Live state</span>
</div>
<div class="check-list">
<div id="checkMoved" class="check-row">
<span class="check-dot"></span>
<span>Amber in yellow bay</span>
<b>Waiting</b>
</div>
<div id="checkPlaced" class="check-row">
<span class="check-dot"></span>
<span>Coral on green pallet</span>
<b>Waiting</b>
</div>
<div id="checkRotated" class="check-row">
<span class="check-dot"></span>
<span>Teal aligned clockwise</span>
<b>Waiting</b>
</div>
</div>
<p id="verdict" class="verdict">
Arrange all three cartons, then check the scene.
</p>
</aside>
<nav class="toolbar panel" aria-label="Operations">
<button class="tool" data-action="move" type="button">
<span class="key">M</span>Move
</button>
<button class="tool" data-action="place" type="button">
<span class="key">P</span>Place
</button>
<button class="tool" data-action="rotate" type="button">
<span class="key">R</span>Rotate
</button>
<button class="tool check" data-action="check" type="button">
<span class="key">C</span>Check
</button>
<button class="tool secondary" data-action="reset-view" title="Reset camera" type="button">⌂</button>
<button class="tool secondary" data-action="reset" title="Reset arrangement" type="button">↺</button>
</nav>
<div class="camera-hint">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<div id="toast" role="status" aria-live="polite"></div>
</div>
<script type="module">
import * as THREE from
'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const viewport = document.querySelector('#viewport');
const toastElement = document.querySelector('#toast');
const verdictElement = document.querySelector('#verdict');
const checkPanel = document.querySelector('#checkPanel');
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e4e7);
scene.fog = new THREE.Fog(0xd9e4e7, 24, 48);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Camera controls are implemented here directly, without examples/addons.
const cameraState = {
target: new THREE.Vector3(0, 0.45, 0),
theta: 0.62,
phi: 0.88,
radius: window.innerWidth < 760 ? 25 : 20
};
function updateCamera() {
const horizontal = cameraState.radius * Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + horizontal * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + horizontal * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xeafcff, 0x7b8175, 2.2));
const sun = new THREE.DirectionalLight(0xfff4dc, 3.2);
sun.position.set(7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 36;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb8e6ff, 0.8);
fillLight.position.set(-8, 7, 2);
scene.add(fillLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xb8c8c8,
roughness: 0.92,
metalness: 0.02
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(22, 0.28, 15),
floorMaterial
);
floor.position.y = -0.14;
floor.receiveShadow = true;
scene.add(floor);
// Floor grid.
const gridVertices = [];
for (let x = -11; x <= 11; x += 1) {
gridVertices.push(x, 0.012, -7.5, x, 0.012, 7.5);
}
for (let z = -7.5; z <= 7.5; z += 1) {
gridVertices.push(-11, 0.012, z, 11, 0.012, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x879b9c,
transparent: true,
opacity: 0.26
})
);
scene.add(grid);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
flatShading: true,
...options
});
}
function addBox(
width, height, depth, color,
x = 0, y = 0, z = 0,
parent = scene,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radius, height, color,
x = 0, y = 0, z = 0,
parent = scene,
segments = 10
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, accent = '#72e0c5', scale = 2.8) {
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext('2d');
context.fillStyle = 'rgba(13, 34, 39, 0.92)';
context.beginPath();
context.roundRect(4, 4, 504, 120, 18);
context.fill();
context.strokeStyle = accent;
context.lineWidth = 5;
context.stroke();
context.fillStyle = '#eef8f7';
context.font = '800 45px system-ui, sans-serif';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(scale, scale * 0.25, 1);
sprite.renderOrder = 30;
return sprite;
}
// -------------------------------------------------------------------------
// Warehouse architecture and low-poly props
// -------------------------------------------------------------------------
addBox(22, 4.6, 0.28, 0xcbd6d4, 0, 2.3, -7.62);
addBox(0.28, 4.6, 15, 0xc4d1d0, -11.13, 2.3, 0);
// Back wall ribs.
for (let x = -10.5; x <= 10.5; x += 1.5) {
addBox(0.07, 4.35, 0.07, 0xaebdbc, x, 2.25, -7.44);
}
// Loading door.
addBox(4.2, 3.65, 0.12, 0x8ea4a5, 3.65, 1.83, -7.40);
for (let y = 0.38; y < 3.5; y += 0.42) {
addBox(4.05, 0.045, 0.07, 0x738b8d, 3.65, y, -7.30);
}
addBox(0.12, 3.85, 0.18, 0x40585b, 1.48, 1.92, -7.28);
addBox(0.12, 3.85, 0.18, 0x40585b, 5.82, 1.92, -7.28);
addBox(4.46, 0.16, 0.18, 0x40585b, 3.65, 3.83, -7.28);
// Shelf structure.
const shelf = new THREE.Group();
shelf.position.set(-5.25, 0, -6.55);
scene.add(shelf);
for (const x of [-3.7, -1.25, 1.25, 3.7]) {
addBox(0.13, 4.1, 0.75, 0x536b6d, x, 2.05, 0, shelf);
}
for (const y of [0.18, 1.48, 2.78, 4.02]) {
addBox(7.55, 0.13, 1.35, 0x607779, 0, y, 0, shelf);
}
const shelfColors = [0x789da1, 0xd19a64, 0x9cb9a4, 0xc98172, 0xb5a672];
let shelfIndex = 0;
for (const y of [0.72, 2.02, 3.25]) {
for (const x of [-3.0, -1.8, -0.55, 0.8, 2.2, 3.15]) {
const width = 0.7 + (shelfIndex % 2) * 0.22;
const height = 0.65 + (shelfIndex % 3) * 0.12;
addBox(
width, height, 0.78,
shelfColors[shelfIndex % shelfColors.length],
x, y + height / 2, 0.08,
shelf
);
shelfIndex++;
}
}
// Conveyor.
const conveyor = new THREE.Group();
conveyor.position.set(-5.15, 0, 0.9);
scene.add(conveyor);
addBox(5.8, 0.32, 1.55, 0x465c5f, 0, 0.47, 0, conveyor);
for (let x = -2.65; x <= 2.65; x += 0.53) {
const roller = addCylinder(
0.11, 1.42, 0xa7b6b3,
x, 0.70, 0, conveyor, 10
);
roller.rotation.x = Math.PI / 2;
}
for (const x of [-2.45, 2.45]) {
for (const z of [-0.52, 0.52]) {
addBox(0.13, 0.55, 0.13, 0x536b6d, x, 0.22, z, conveyor);
}
}
// Small pallet truck for scale.
const truck = new THREE.Group();
truck.position.set(-8.2, 0, 3.0);
truck.rotation.y = -0.35;
scene.add(truck);
addBox(0.85, 0.38, 1.0, 0xe3a548, 0, 0.32, 0, truck);
addBox(0.12, 1.45, 0.12, 0x40585b, -0.32, 1.08, -0.43, truck);
addBox(0.12, 1.45, 0.12, 0x40585b, 0.32, 1.08, -0.43, truck);
addBox(0.75, 0.12, 0.12, 0x40585b, 0, 1.80, -0.43, truck);
addBox(1.75, 0.12, 0.18, 0xd3953e, 0, 0.19, 0.88, truck);
addBox(0.13, 0.15, 1.6, 0xd3953e, -0.36, 0.19, 1.40, truck);
addBox(0.13, 0.15, 1.6, 0xd3953e, 0.36, 0.19, 1.40, truck);
// -------------------------------------------------------------------------
// Goal targets
// -------------------------------------------------------------------------
const interactive = [];
function rectangleOutline(width, depth, color, y = 0.04) {
const points = [
new THREE.Vector3(-width / 2, y, -depth / 2),
new THREE.Vector3(width / 2, y, -depth / 2),
new THREE.Vector3(width / 2, y, depth / 2),
new THREE.Vector3(-width / 2, y, depth / 2)
];
const line = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
line.renderOrder = 8;
return line;
}
// Yellow move bay.
const moveTarget = new THREE.Group();
moveTarget.position.set(6, 0, -3.45);
moveTarget.userData.pickType = 'moveTarget';
scene.add(moveTarget);
const movePad = new THREE.Mesh(
new THREE.PlaneGeometry(2.65, 2.65),
new THREE.MeshBasicMaterial({
color: 0xf4ca62,
transparent: true,
opacity: 0.18,
depthWrite: false,
side: THREE.DoubleSide
})
);
movePad.rotation.x = -Math.PI / 2;
movePad.position.y = 0.028;
moveTarget.add(movePad);
const moveOutline = rectangleOutline(2.65, 2.65, 0xf4ca62);
moveTarget.add(moveOutline);
const moveLabel = makeLabel('A / MOVE', '#f4ca62', 2.65);
moveLabel.position.set(0, 1.85, 0);
moveTarget.add(moveLabel);
// Directional floor chevrons.
for (let i = 0; i < 3; i++) {
const arrow = new THREE.Group();
arrow.position.set(0, 0.05, -0.52 + i * 0.45);
const material = new THREE.MeshBasicMaterial({
color: 0xf4ca62,
transparent: true,
opacity: 0.72
});
addBox(0.13, 0.025, 0.52, 0xf4ca62, -0.22, 0, 0, arrow, {
transparent: true,
opacity: 0.72
});
addBox(0.13, 0.025, 0.52, 0xf4ca62, 0.22, 0, 0, arrow, {
transparent: true,
opacity: 0.72
});
arrow.rotation.y = Math.PI / 4;
moveTarget.add(arrow);
}
// Green placement pallet.
const placeTarget = new THREE.Group();
placeTarget.position.set(6, 0, 2.8);
placeTarget.userData.pickType = 'placeTarget';
scene.add(placeTarget);
addBox(2.35, 0.30, 2.35, 0x4c9d78, 0, 0.15, 0, placeTarget);
addBox(2.12, 0.07, 2.12, 0x70c79a, 0, 0.335, 0, placeTarget);
const placeOutline = rectangleOutline(2.15, 2.15, 0x9af0bd, 0.38);
placeTarget.add(placeOutline);
const placeLabel = makeLabel('C / PLACE', '#9af0bd', 2.65);
placeLabel.position.set(0, 1.85, 0);
placeTarget.add(placeLabel);
// Teal turntable.
const turntable = new THREE.Group();
turntable.position.set(0, 0, 1.2);
scene.add(turntable);
addCylinder(1.65, 0.18, 0x40595d, 0, 0.09, 0, turntable, 12);
addCylinder(1.43, 0.08, 0x55b9c3, 0, 0.22, 0, turntable, 12);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const marker = addBox(
0.13, 0.08, 0.25,
i === 0 ? 0xf4ca62 : 0x8bd9df,
Math.cos(angle) * 1.5,
0.20,
Math.sin(angle) * 1.5,
turntable
);
marker.rotation.y = -angle;
}
const turnLabel = makeLabel('B / ROTATE', '#73dce3', 2.85);
turnLabel.position.set(0, 1.85, 0);
turntable.add(turnLabel);
// -------------------------------------------------------------------------
// Interactive cartons
// -------------------------------------------------------------------------
const items = {};
function createCrate(key, color, accent, home, labelText) {
const group = new THREE.Group();
group.position.copy(home);
group.userData.pickType = 'crate';
group.userData.key = key;
scene.add(group);
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.2, 1.05, 1.2),
standardMaterial(color)
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.23
})
);
group.add(edges);
// Packing bands and a conspicuous orientation stripe.
addBox(0.18, 0.035, 1.225, accent, 0, 0.54, 0, group);
addBox(0.18, 1.075, 0.035, accent, 0, 0, 0.615, group);
addBox(
0.72, 0.13, 0.045, 0xf4eee0,
0, 0.22, 0.625, group
);
// Low-poly corner protectors.
for (const x of [-0.5, 0.5]) {
for (const z of [-0.5, 0.5]) {
addBox(0.14, 0.16, 0.14, accent, x, 0.43, z, group);
}
}
const label = makeLabel(labelText, accent, 0.72);
label.position.set(0, 1.08, 0);
group.add(label);
interactive.push(group);
items[key] = {
key,
group,
home: home.clone(),
halfHeight: 0.525,
animation: null
};
}
createCrate(
'amber',
0xd59a38,
0xf7d77d,
new THREE.Vector3(-3.8, 0.56, 4.0),
'A'
);
createCrate(
'coral',
0xd96f62,
0xf4a093,
new THREE.Vector3(-5.7, 0.56, -2.35),
'C'
);
createCrate(
'teal',
0x3c9eac,
0x8fe2e5,
new THREE.Vector3(0, 0.79, 1.2),
'B'
);
// Selection ring.
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.035, 6, 32),
new THREE.MeshBasicMaterial({
color: 0xfff0a0,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.renderOrder = 20;
scene.add(selectionRing);
// -------------------------------------------------------------------------
// State, operations, and final-state assessment
// -------------------------------------------------------------------------
const GOAL = {
move: new THREE.Vector3(6, 0.56, -3.45),
place: new THREE.Vector3(6, 0.87, 2.8),
turntable: new THREE.Vector3(0, 0.79, 1.2),
rotation: -Math.PI / 2
};
let activeMode = 'none';
let selectedKey = 'amber';
let hasChecked = false;
let toastTimer;
function toast(message) {
toastElement.textContent = message;
toastElement.classList.add('visible');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove('visible');
}, 2800);
}
function angleDifference(a, b) {
return Math.atan2(Math.sin(a - b), Math.cos(a - b));
}
function getCriteria() {
const amber = items.amber.group.position;
const coral = items.coral.group.position;
const teal = items.teal.group.position;
const moved = Math.hypot(
amber.x - GOAL.move.x,
amber.z - GOAL.move.z
) < 0.24 && Math.abs(amber.y - GOAL.move.y) < 0.12;
const placed = Math.hypot(
coral.x - GOAL.place.x,
coral.z - GOAL.place.z
) < 0.20 && Math.abs(coral.y - GOAL.place.y) < 0.12;
const rotated =
Math.abs(angleDifference(items.teal.group.rotation.y, GOAL.rotation)) < 0.08 &&
Math.hypot(
teal.x - GOAL.turntable.x,
teal.z - GOAL.turntable.z
) < 0.25;
return [
{ id: 'checkMoved', ok: moved, label: 'Amber in yellow bay' },
{ id: 'checkPlaced', ok: placed, label: 'Coral on green pallet' },
{ id: 'checkRotated', ok: rotated, label: 'Teal aligned clockwise' }
];
}
function updateUI() {
const criteria = getCriteria();
const stepStates = {
move: criteria[0].ok,
place: criteria[1].ok,
rotate: criteria[2].ok
};
document.querySelectorAll('.step').forEach(step => {
const done = stepStates[step.dataset.action];
step.dataset.state = done ? 'done' : 'pending';
step.querySelector('.step-state').textContent = done ? 'Done' : step.dataset.action;
});
criteria.forEach(criterion => {
const row = document.getElementById(criterion.id);
row.classList.toggle('ok', criterion.ok);
row.querySelector('b').textContent = criterion.ok ? 'Ready' : 'Waiting';
});
document.querySelectorAll('.tool[data-action="move"]').forEach(button => {
button.classList.toggle('active', activeMode === 'move');
button.setAttribute('aria-pressed', activeMode === 'move');
});
document.querySelectorAll('.tool[data-action="place"]').forEach(button => {
button.classList.toggle('active', activeMode === 'place');
button.setAttribute('aria-pressed', activeMode === 'place');
});
if (hasChecked) {
renderVerdict(criteria);
}
}
function renderVerdict(criteria) {
const completed = criteria.filter(criterion => criterion.ok).length;
if (completed === criteria.length) {
verdictElement.textContent =
'Approved — the final warehouse arrangement satisfies all three goals.';
verdictElement.className = 'verdict success';
} else {
verdictElement.textContent =
`${completed} of 3 final-state checks satisfied. Adjust the remaining carton${
completed === 2 ? '' : 's'
} and check again.`;
verdictElement.className = 'verdict failed';
}
}
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function animatePosition(item, destination, duration = 720) {
item.animation = {
kind: 'position',
start: performance.now(),
duration,
from: item.group.position.clone(),
to: destination.clone()
};
}
function animateRotation(item, delta, duration = 650) {
item.animation = {
kind: 'rotation',
start: performance.now(),
duration,
from: item.group.rotation.y,
to: item.group.rotation.y + delta
};
}
function activateMove() {
selectedKey = 'amber';
activeMode = 'move';
updateUI();
toast('Move armed: click the glowing yellow staging square.');
}
function activatePlace() {
selectedKey = 'coral';
activeMode = 'place';
updateUI();
toast('Place armed: click the green dispatch pallet.');
}
function activateRotate() {
selectedKey = 'teal';
activeMode = 'none';
animateRotation(items.teal, -Math.PI / 2);
updateUI();
toast('Rotated carton B 90° clockwise on the turntable.');
}
function performMove() {
selectedKey = 'amber';
animatePosition(items.amber, GOAL.move);
activeMode = 'none';
updateUI();
toast('Amber carton moved into the yellow staging square.');
}
function performPlace() {
selectedKey = 'coral';
animatePosition(items.coral, GOAL.place);
activeMode = 'none';
updateUI();
toast('Coral carton placed on the green dispatch pallet.');
}
function checkArrangement() {
hasChecked = true;
const criteria = getCriteria();
updateUI();
renderVerdict(criteria);
checkPanel.classList.add('flash');
setTimeout(() => checkPanel.classList.remove('flash'), 220);
if (criteria.every(criterion => criterion.ok)) {
toast('Arrangement approved. All final-state checks passed.');
} else {
toast('Arrangement checked. Follow the remaining highlighted goals.');
}
}
function resetArrangement() {
for (const item of Object.values(items)) {
item.animation = null;
item.group.position.copy(item.home);
item.group.rotation.set(0, 0, 0);
}
activeMode = 'none';
selectedKey = 'amber';
hasChecked = false;
verdictElement.textContent = 'Arrange all three cartons, then check the scene.';
verdictElement.className = 'verdict';
updateUI();
toast('Warehouse arrangement reset.');
}
function resetCamera() {
cameraState.target.set(0, 0.45, 0);
cameraState.theta = 0.62;
cameraState.phi = 0.88;
cameraState.radius = window.innerWidth < 760 ? 25 : 20;
updateCamera();
}
document.querySelectorAll('[data-action]').forEach(button => {
button.addEventListener('click', () => {
switch (button.dataset.action) {
case 'move': activateMove(); break;
case 'place': activatePlace(); break;
case 'rotate': activateRotate(); break;
case 'check': checkArrangement(); break;
case 'reset': resetArrangement(); break;
case 'reset-view': resetCamera(); break;
}
});
});
// -------------------------------------------------------------------------
// Picking and custom camera interaction
// -------------------------------------------------------------------------
interactive.push(moveTarget, placeTarget);
const raycaster = new THREE.Raycaster();
raycaster.params.Line.threshold = 0.05;
const pointer = new THREE.Vector2();
function resolveUserData(object) {
let current = object;
while (current) {
if (current.userData && current.userData.pickType) {
return current.userData;
}
current = current.parent;
}
return null;
}
function pickAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(interactive, true);
for (const intersection of intersections) {
const data = resolveUserData(intersection.object);
if (data) return data;
}
return null;
}
function handleSceneClick(event) {
const hit = pickAt(event.clientX, event.clientY);
if (!hit) {
if (activeMode !== 'none') {
toast(activeMode === 'move'
? 'Click the yellow square to move carton A.'
: 'Click the green pallet to place carton C.');
}
return;
}
if (hit.pickType === 'crate') {
selectedKey = hit.key;
updateUI();
return;
}
if (activeMode === 'move' && hit.pickType === 'moveTarget') {
performMove();
return;
}
if (activeMode === 'place' && hit.pickType === 'placeTarget') {
performPlace();
return;
}
if (activeMode === 'move') {
toast('That is not the yellow staging square.');
} else if (activeMode === 'place') {
toast('That is not the green dispatch pallet.');
}
}
let pointerDown = null;
renderer.domElement.addEventListener('pointerdown', event => {
if (event.button !== 0) return;
pointerDown = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (!pointerDown || pointerDown.id !== event.pointerId) return;
const totalDistance = Math.hypot(
event.clientX - pointerDown.x,
event.clientY - pointerDown.y
);
if (totalDistance > 4) pointerDown.moved = true;
if (!pointerDown.moved) return;
const dx = event.clientX - pointerDown.lastX;
const dy = event.clientY - pointerDown.lastY;
pointerDown.lastX = event.clientX;
pointerDown.lastY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const forward = new THREE.Vector3(
Math.sin(cameraState.theta),
0,
Math.cos(cameraState.theta)
);
const panScale = cameraState.radius * 0.0016;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(forward, -dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -8, 8);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -6, 6);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.36,
1.25
);
}
updateCamera();
});
renderer.domElement.addEventListener('pointerup', event => {
if (!pointerDown || pointerDown.id !== event.pointerId) return;
if (!pointerDown.moved) {
handleSceneClick(event);
}
pointerDown = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener('pointercancel', () => {
pointerDown = null;
});
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
11,
34
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener('contextmenu', event => {
event.preventDefault();
});
window.addEventListener('keydown', event => {
if (event.ctrlKey || event.metaKey || event.altKey) return;
switch (event.key.toLowerCase()) {
case 'm': activateMove(); break;
case 'p': activatePlace(); break;
case 'r': activateRotate(); break;
case 'c': checkArrangement(); break;
case 'escape':
activeMode = 'none';
updateUI();
toast('Operation cancelled.');
break;
}
});
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
for (const item of Object.values(items)) {
const animation = item.animation;
if (!animation) continue;
const progress = THREE.MathUtils.clamp(
(now - animation.start) / animation.duration,
0,
1
);
const eased = easeOutCubic(progress);
if (animation.kind === 'position') {
item.group.position.lerpVectors(animation.from, animation.to, eased);
} else if (animation.kind === 'rotation') {
item.group.rotation.y = THREE.MathUtils.lerp(
animation.from,
animation.to,
eased
);
}
if (progress >= 1) {
if (animation.kind === 'position') {
item.group.position.copy(animation.to);
} else {
item.group.rotation.y = animation.to;
}
item.animation = null;
updateUI();
}
}
const selected = items[selectedKey];
if (selected) {
selectionRing.position.set(
selected.group.position.x,
Math.max(0.055, selected.group.position.y - selected.halfHeight + 0.045),
selected.group.position.z
);
selectionRing.material.opacity = 0.72 + Math.sin(now * 0.004) * 0.18;
}
const pulse = Math.sin(now * 0.0032);
movePad.material.opacity = 0.15 + (pulse + 1) * 0.045;
moveOutline.material.opacity = 0.72 + (pulse + 1) * 0.12;
placeOutline.material.opacity = 0.68 + (pulse + 1) * 0.12;
renderer.render(scene, camera);
}
updateUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```