Prompt specification
Build or customize the Three.js 3D scene "Two Commands Different Order" 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: Two Commands Different Order
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-commands-different-order-x3386
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: two commands different order. Execute move-then-turn and turn-then-move from the same initial pose. Display both final positions so the noncommutativity of command order is directly visible.
Working Three.js Starter (two-commands-different-order-x3386):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#0b1020">
<title>Voxel Command Lab — Order Matters</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1020;
--panel: rgba(14, 20, 38, 0.88);
--border: rgba(157, 181, 224, 0.18);
--text: #eef5ff;
--muted: #97a8c4;
--cyan: #4de3ff;
--pink: #ff62cf;
--yellow: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
.panel,
.outcome,
.controls,
.legend {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.panel {
top: 18px;
left: 18px;
width: 370px;
padding: 18px;
border-radius: 18px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.definitions {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 14px;
}
.definition {
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 7px;
background: rgba(255, 255, 255, 0.035);
color: #c9d7ec;
font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.command-grid {
display: grid;
gap: 9px;
}
.sequence {
padding: 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.sequence.active {
transform: translateX(2px);
background: rgba(255, 255, 255, 0.055);
}
.sequence.cyan.active {
border-color: rgba(77, 227, 255, 0.58);
}
.sequence.pink.active {
border-color: rgba(255, 98, 207, 0.58);
}
.sequence.done {
border-color: rgba(255, 209, 102, 0.34);
}
.sequence-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.sequence-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
font-weight: 750;
}
.dot {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
.cyan .dot,
.dot.cyan {
color: var(--cyan);
background: var(--cyan);
}
.pink .dot,
.dot.pink {
color: var(--pink);
background: var(--pink);
}
.sequence-status {
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-transform: uppercase;
}
.steps {
display: flex;
align-items: center;
gap: 6px;
}
.step {
flex: 1;
padding: 7px 5px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 7px;
color: #8192ad;
background: rgba(0, 0, 0, 0.14);
font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: center;
transition: all 160ms ease;
}
.step.active {
color: #07101d;
font-weight: 800;
background: var(--cyan);
border-color: var(--cyan);
box-shadow: 0 0 18px rgba(77, 227, 255, 0.25);
}
.pink .step.active {
background: var(--pink);
border-color: var(--pink);
box-shadow: 0 0 18px rgba(255, 98, 207, 0.25);
}
.step.done {
color: #d8e5f7;
border-color: rgba(255, 209, 102, 0.34);
}
.arrow {
color: #64758f;
font-size: 12px;
}
.result {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.result strong {
color: var(--text);
}
.outcome {
top: 18px;
right: 18px;
width: 310px;
padding: 17px;
border-radius: 18px;
transition: border-color 220ms ease, box-shadow 220ms ease;
}
.outcome.complete {
border-color: rgba(255, 209, 102, 0.5);
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.28),
0 0 28px rgba(255, 209, 102, 0.08);
}
.outcome h2 {
margin: 0 0 12px;
font-size: 15px;
}
.result-table {
display: grid;
gap: 7px;
}
.result-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 9px 10px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
font-size: 12px;
}
.result-row b {
font: 700 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.result-row.cyan b {
color: var(--cyan);
}
.result-row.pink b {
color: var(--pink);
}
.equation {
margin-top: 11px;
padding: 10px;
border: 1px solid rgba(255, 209, 102, 0.2);
border-radius: 9px;
color: var(--yellow);
background: rgba(255, 209, 102, 0.055);
font: 700 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: center;
}
.outcome-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.controls {
bottom: 18px;
left: 18px;
width: 370px;
padding: 13px;
border-radius: 15px;
}
.buttons {
display: flex;
gap: 7px;
}
.controls button {
flex: 1;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.controls button:hover {
border-color: rgba(77, 227, 255, 0.45);
background: rgba(77, 227, 255, 0.1);
transform: translateY(-1px);
}
.controls button.primary {
color: #07101d;
background: var(--cyan);
border-color: var(--cyan);
}
.progress {
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--pink), var(--yellow));
box-shadow: 0 0 14px rgba(77, 227, 255, 0.4);
}
.status-line {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 8px;
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.legend {
right: 18px;
bottom: 18px;
padding: 12px 14px;
border-radius: 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.65;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.legend-swatch {
width: 18px;
height: 4px;
border-radius: 2px;
box-shadow: 0 0 8px currentColor;
}
.legend .camera-help {
margin-top: 5px;
padding-top: 6px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-tag {
position: absolute;
min-width: 125px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-top: 2px solid var(--tag-color, #dce9ff);
border-radius: 8px;
color: var(--text);
background: rgba(10, 15, 29, 0.9);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 220ms ease;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.world-tag.visible {
opacity: 1;
}
.world-tag.cyan {
--tag-color: var(--cyan);
}
.world-tag.pink {
--tag-color: var(--pink);
}
.world-tag.yellow {
--tag-color: var(--yellow);
}
.world-tag.start {
--tag-color: #dce9ff;
}
.world-tag.axis {
min-width: 0;
padding: 5px 7px;
color: #b9c7dc;
border-top-width: 1px;
font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tag-title {
display: block;
margin-bottom: 3px;
color: var(--tag-color);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-tag strong {
display: block;
font: 800 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.world-tag small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
@media (max-width: 820px) {
.panel {
top: 12px;
left: 12px;
width: min(370px, calc(100vw - 24px));
padding: 14px;
}
h1 {
font-size: 21px;
}
.intro {
margin-bottom: 10px;
}
.outcome {
top: auto;
right: 12px;
bottom: 92px;
width: min(290px, calc(100vw - 24px));
padding: 13px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
}
.legend {
display: none;
}
.world-tag {
min-width: 108px;
padding: 6px 8px;
}
.world-tag strong {
font-size: 12px;
}
}
@media (max-width: 520px) {
.definitions,
.outcome-note {
display: none;
}
.sequence {
padding: 9px;
}
.outcome {
width: 235px;
}
.result-row {
padding: 7px;
font-size: 10px;
}
.result-row b {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="panel" aria-label="Command sequences">
<div class="eyebrow">Voxel Command Lab</div>
<h1>Order changes the destination.</h1>
<p class="intro">
Both robots begin at the same pose: position <strong>(0, 0)</strong>,
heading <strong>+Z</strong>. Watch the two command orders diverge.
</p>
<div class="definitions">
<span class="definition">MOVE +3 = 3 blocks forward</span>
<span class="definition">TURN +90° = +Z → +X</span>
</div>
<div class="command-grid">
<article class="sequence cyan" id="mtCard">
<div class="sequence-head">
<div class="sequence-name">
<span class="dot cyan"></span>
Move → Turn
</div>
<span class="sequence-status" id="mtStatus">waiting</span>
</div>
<div class="steps">
<span class="step" id="mtMove">MOVE +3</span>
<span class="arrow">→</span>
<span class="step" id="mtTurn">TURN +90°</span>
</div>
<div class="result">
<span>Final position</span>
<strong>(x 0, z +3)</strong>
</div>
</article>
<article class="sequence pink" id="tmCard">
<div class="sequence-head">
<div class="sequence-name">
<span class="dot pink"></span>
Turn → Move
</div>
<span class="sequence-status" id="tmStatus">waiting</span>
</div>
<div class="steps">
<span class="step" id="tmTurn">TURN +90°</span>
<span class="arrow">→</span>
<span class="step" id="tmMove">MOVE +3</span>
</div>
<div class="result">
<span>Final position</span>
<strong>(x +3, z 0)</strong>
</div>
</article>
</div>
</section>
<aside class="outcome" id="outcome">
<h2>Same commands. Different result.</h2>
<div class="result-table">
<div class="result-row cyan">
<span>Move → Turn</span>
<b>(0, +3)</b>
</div>
<div class="result-row pink">
<span>Turn → Move</span>
<b>(+3, 0)</b>
</div>
</div>
<div class="equation">M · T ≠ T · M</div>
<p class="outcome-note">
Position is shown as (x, z). Both robots finish facing +X,
but their final positions are separated by 3 blocks on both axes.
</p>
</aside>
<div id="labels" aria-hidden="true">
<div class="world-tag start visible" id="startTag">
<span class="tag-title">Shared start</span>
<strong>(0, 0)</strong>
<small>heading +Z</small>
</div>
<div class="world-tag cyan" id="mtFinalTag">
<span class="tag-title">Move → Turn</span>
<strong>(0, +3)</strong>
<small>final position · heading +X</small>
</div>
<div class="world-tag pink" id="tmFinalTag">
<span class="tag-title">Turn → Move</span>
<strong>(+3, 0)</strong>
<small>final position · heading +X</small>
</div>
<div class="world-tag yellow" id="deltaTag">
<span class="tag-title">Position difference</span>
<strong>Δ = (3, −3)</strong>
</div>
<div class="world-tag axis visible" id="xAxisTag">+X</div>
<div class="world-tag axis visible" id="zAxisTag">+Z</div>
</div>
<section class="controls" aria-label="Playback controls">
<div class="buttons">
<button class="primary" id="replayButton" type="button">↻ Replay</button>
<button id="pauseButton" type="button">Pause</button>
<button id="cameraButton" type="button">Reset camera</button>
</div>
<div class="progress">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="status-line">
<span id="statusText">STARTING</span>
<span id="timeText">0.00 / 1.85 s</span>
</div>
</section>
<aside class="legend">
<div class="legend-row">
<span class="legend-swatch" style="color:var(--cyan);background:var(--cyan)"></span>
Move → Turn
</div>
<div class="legend-row">
<span class="legend-swatch" style="color:var(--pink);background:var(--pink)"></span>
Turn → Move
</div>
<div class="legend-row camera-help">
Drag to orbit · scroll to zoom
</div>
</aside>
<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 stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1020);
scene.fog = new THREE.Fog(0x0b1020, 22, 43);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
stage.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Voxel scene comparing move-then-turn with turn-then-move"
);
const hemisphere = new THREE.HemisphereLight(0xcbe9ff, 0x172033, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(7, 14, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x32dfff, 18, 14, 2);
cyanLight.position.set(-5, 3, 1);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff4fc7, 18, 14, 2);
pinkLight.position.set(5, 3, -1);
scene.add(pinkLight);
// Floor and grid.
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x121a2b,
roughness: 0.93,
metalness: 0.03
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(16, 0.3, 16),
floorMaterial
);
floor.position.y = -0.15;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
16,
16,
0x435570,
0x28354c
);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.72;
scene.add(grid);
// ---------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------
const clamp01 = (value) => Math.min(1, Math.max(0, value));
const ease = (value) => {
const t = clamp01(value);
return t * t * (3 - 2 * t);
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeVoxelRobot(color) {
const root = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.56,
metalness: 0.12,
emissive: color,
emissiveIntensity: 0.08
});
const lightMaterial = new THREE.MeshStandardMaterial({
color: 0xe8f5ff,
roughness: 0.62,
metalness: 0.04
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x111827,
roughness: 0.8,
metalness: 0.08
});
const visorMaterial = new THREE.MeshStandardMaterial({
color: 0x09111f,
roughness: 0.22,
metalness: 0.55
});
const glowMaterial = new THREE.MeshBasicMaterial({ color });
// Feet.
addBox(
root,
new THREE.Vector3(0.24, 0.2, 0.34),
new THREE.Vector3(-0.19, 0.1, 0.02),
darkMaterial
);
addBox(
root,
new THREE.Vector3(0.24, 0.2, 0.34),
new THREE.Vector3(0.19, 0.1, 0.02),
darkMaterial
);
// Legs.
addBox(
root,
new THREE.Vector3(0.19, 0.34, 0.22),
new THREE.Vector3(-0.19, 0.34, 0),
darkMaterial
);
addBox(
root,
new THREE.Vector3(0.19, 0.34, 0.22),
new THREE.Vector3(0.19, 0.34, 0),
darkMaterial
);
// Torso.
addBox(
root,
new THREE.Vector3(0.64, 0.58, 0.42),
new THREE.Vector3(0, 0.79, 0),
bodyMaterial
);
// Chest badge.
addBox(
root,
new THREE.Vector3(0.2, 0.2, 0.035),
new THREE.Vector3(0, 0.82, 0.226),
lightMaterial
);
// Head.
addBox(
root,
new THREE.Vector3(0.54, 0.48, 0.48),
new THREE.Vector3(0, 1.34, 0),
lightMaterial
);
// Visor, on the +Z/front side.
addBox(
root,
new THREE.Vector3(0.4, 0.16, 0.035),
new THREE.Vector3(0, 1.38, 0.257),
visorMaterial
);
// Eye pixels.
addBox(
root,
new THREE.Vector3(0.07, 0.055, 0.025),
new THREE.Vector3(-0.1, 1.39, 0.282),
glowMaterial,
false
);
addBox(
root,
new THREE.Vector3(0.07, 0.055, 0.025),
new THREE.Vector3(0.1, 1.39, 0.282),
glowMaterial,
false
);
// Antenna.
addBox(
root,
new THREE.Vector3(0.055, 0.25, 0.055),
new THREE.Vector3(0, 1.7, 0),
darkMaterial
);
addBox(
root,
new THREE.Vector3(0.13, 0.13, 0.13),
new THREE.Vector3(0, 1.87, 0),
glowMaterial,
false
);
// Direction marker on the floor, pointing toward local +Z.
addBox(
root,
new THREE.Vector3(0.07, 0.035, 0.32),
new THREE.Vector3(0, 0.035, 0.52),
glowMaterial,
false
);
addBox(
root,
new THREE.Vector3(0.07, 0.035, 0.2),
new THREE.Vector3(-0.09, 0.035, 0.67),
glowMaterial,
false
).rotation.y = Math.PI / 4;
addBox(
root,
new THREE.Vector3(0.07, 0.035, 0.2),
new THREE.Vector3(0.09, 0.035, 0.67),
glowMaterial,
false
).rotation.y = -Math.PI / 4;
return root;
}
function makePath(axis, color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.55,
roughness: 0.45
});
for (let distance = 0.28; distance < 3; distance += 0.48) {
const size =
axis === "z"
? new THREE.Vector3(0.11, 0.035, 0.3)
: new THREE.Vector3(0.3, 0.035, 0.11);
const position =
axis === "z"
? new THREE.Vector3(0, 0.035, distance)
: new THREE.Vector3(distance, 0.035, 0);
addBox(group, size, position, material, false);
}
scene.add(group);
return group;
}
function makeEndpointPad(x, z, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.52,
transparent: true,
opacity: 0.66,
roughness: 0.5
});
const center = new THREE.Mesh(
new THREE.BoxGeometry(0.86, 0.025, 0.86),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.09,
depthWrite: false
})
);
center.position.y = 0.025;
group.add(center);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
group,
new THREE.Vector3(0.25, 0.045, 0.1),
new THREE.Vector3(sx * 0.36, 0.04, sz * 0.43),
material,
false
);
addBox(
group,
new THREE.Vector3(0.1, 0.045, 0.25),
new THREE.Vector3(sx * 0.43, 0.04, sz * 0.36),
material,
false
);
}
}
scene.add(group);
return group;
}
// ---------------------------------------------------------------------
// Scene objects
// ---------------------------------------------------------------------
const CYAN = 0x4de3ff;
const PINK = 0xff62cf;
const moveThenTurn = makeVoxelRobot(CYAN);
const turnThenMove = makeVoxelRobot(PINK);
// Slight vertical separation prevents z-fighting while they overlap.
moveThenTurn.position.y = 0.025;
turnThenMove.position.y = 0.055;
scene.add(moveThenTurn, turnThenMove);
const cyanPath = makePath("z", CYAN);
const pinkPath = makePath("x", PINK);
const cyanPad = makeEndpointPad(0, 3, CYAN);
const pinkPad = makeEndpointPad(3, 0, PINK);
// Shared start marker.
const startMaterial = new THREE.MeshStandardMaterial({
color: 0xcbd8eb,
emissive: 0x9db4d4,
emissiveIntensity: 0.22,
roughness: 0.6
});
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
scene,
new THREE.Vector3(0.28, 0.045, 0.09),
new THREE.Vector3(sx * 0.38, 0.035, sz * 0.43),
startMaterial,
false
);
addBox(
scene,
new THREE.Vector3(0.09, 0.045, 0.28),
new THREE.Vector3(sx * 0.43, 0.035, sz * 0.38),
startMaterial,
false
);
}
}
// Decorative voxel structures, kept away from the command paths.
const decorMaterial = new THREE.MeshStandardMaterial({
color: 0x26334b,
roughness: 0.82,
metalness: 0.08
});
const decorLightMaterial = new THREE.MeshStandardMaterial({
color: 0x354760,
roughness: 0.75,
metalness: 0.08
});
const decorations = [
[-5.7, -5.2, 1.4, 0.8, 1.2],
[-5.2, -4.4, 0.8, 2.1, 0.9],
[-6.1, -3.7, 0.7, 1.4, 0.8],
[5.4, -5.5, 1.1, 1.8, 1.1],
[6.0, -4.8, 0.8, 0.9, 0.8],
[-5.7, 5.2, 1.0, 1.4, 1.0],
[-6.2, 4.6, 0.7, 0.8, 0.8],
[5.5, 5.3, 1.5, 1.1, 1.4],
[4.8, 5.8, 0.8, 2.0, 0.8]
];
decorations.forEach(([x, z, w, h, d], index) => {
addBox(
scene,
new THREE.Vector3(w, h, d),
new THREE.Vector3(x, h / 2, z),
index % 2 ? decorLightMaterial : decorMaterial
);
});
// ---------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom.
// ---------------------------------------------------------------------
const cameraState = {
theta: 0.72,
phi: 0.94,
radius: 18.5,
target: new THREE.Vector3(0, 0.55, 0.35)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
const horizontal = radius * Math.sin(phi);
camera.position.set(
target.x + horizontal * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + horizontal * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 0.94;
cameraState.radius = 18.5;
cameraState.target.set(0, 0.55, 0.35);
updateCamera();
}
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.35,
1.35
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
11,
28
);
updateCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Command execution
//
// Initial pose:
// position = (0, 0)
// heading = +Z
//
// MOVE +3 translates along the current heading.
// TURN +90° rotates around +Y, changing heading +Z to +X.
// ---------------------------------------------------------------------
const MOVE_MS = 1200;
const TURN_MS = 650;
const TOTAL_MS = MOVE_MS + TURN_MS;
let animationStart = performance.now() + 250;
let paused = false;
let elapsedBeforePause = 0;
const mtMoveStep = document.querySelector("#mtMove");
const mtTurnStep = document.querySelector("#mtTurn");
const tmTurnStep = document.querySelector("#tmTurn");
const tmMoveStep = document.querySelector("#tmMove");
const mtCard = document.querySelector("#mtCard");
const tmCard = document.querySelector("#tmCard");
const mtStatus = document.querySelector("#mtStatus");
const tmStatus = document.querySelector("#tmStatus");
const outcome = document.querySelector("#outcome");
const progressFill = document.querySelector("#progressFill");
const statusText = document.querySelector("#statusText");
const timeText = document.querySelector("#timeText");
const pauseButton = document.querySelector("#pauseButton");
const replayButton = document.querySelector("#replayButton");
const cameraButton = document.querySelector("#cameraButton");
function setStepState(element, state) {
element.classList.toggle("active", state === "active");
element.classList.toggle("done", state === "done");
}
function currentElapsed(now) {
if (paused) return elapsedBeforePause;
return Math.min(
TOTAL_MS,
Math.max(0, now - animationStart)
);
}
function applyActors(elapsed) {
const halfTurn = Math.PI / 2;
// MOVE -> TURN
if (elapsed < MOVE_MS) {
const movement = ease(elapsed / MOVE_MS);
moveThenTurn.position.set(0, 0.025, movement * 3);
moveThenTurn.rotation.y = 0;
} else {
const turn = ease((elapsed - MOVE_MS) / TURN_MS);
moveThenTurn.position.set(0, 0.025, 3);
moveThenTurn.rotation.y = turn * halfTurn;
}
// TURN -> MOVE
if (elapsed < TURN_MS) {
const turn = ease(elapsed / TURN_MS);
turnThenMove.position.set(0, 0.055, 0);
turnThenMove.rotation.y = turn * halfTurn;
} else {
const movement = ease((elapsed - TURN_MS) / MOVE_MS);
turnThenMove.position.set(movement * 3, 0.055, 0);
turnThenMove.rotation.y = halfTurn;
}
}
function updateSequenceUI(elapsed) {
const complete = elapsed >= TOTAL_MS;
setStepState(
mtMoveStep,
elapsed < MOVE_MS ? "active" : "done"
);
setStepState(
mtTurnStep,
elapsed >= TOTAL_MS ? "done" : elapsed >= MOVE_MS ? "active" : "idle"
);
setStepState(
tmTurnStep,
elapsed < TURN_MS ? "active" : "done"
);
setStepState(
tmMoveStep,
elapsed >= TOTAL_MS ? "done" : elapsed >= TURN_MS ? "active" : "idle"
);
mtCard.classList.toggle("active", elapsed < TOTAL_MS);
tmCard.classList.toggle("active", elapsed < TOTAL_MS);
mtCard.classList.toggle("done", complete);
tmCard.classList.toggle("done", complete);
mtStatus.textContent = complete ? "complete" : elapsed < MOVE_MS ? "moving" : "turning";
tmStatus.textContent = complete ? "complete" : elapsed < TURN_MS ? "turning" : "moving";
outcome.classList.toggle("complete", complete);
const progress = elapsed / TOTAL_MS;
progressFill.style.width = `${progress * 100}%`;
timeText.textContent = `${(elapsed / 1000).toFixed(2)} / ${(TOTAL_MS / 1000).toFixed(2)} s`;
if (paused) {
statusText.textContent = "PAUSED";
} else if (complete) {
statusText.textContent = "COMPLETE · FINAL POSITIONS DIFFER";
} else if (elapsed === 0) {
statusText.textContent = "STARTING";
} else {
statusText.textContent = "EXECUTING BOTH ORDERS";
}
}
pauseButton.addEventListener("click", () => {
if (currentElapsed(performance.now()) >= TOTAL_MS) return;
if (!paused) {
elapsedBeforePause = currentElapsed(performance.now());
paused = true;
pauseButton.textContent = "Resume";
} else {
animationStart = performance.now() - elapsedBeforePause;
paused = false;
pauseButton.textContent = "Pause";
}
});
replayButton.addEventListener("click", () => {
paused = false;
elapsedBeforePause = 0;
animationStart = performance.now() + 180;
pauseButton.textContent = "Pause";
});
cameraButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
replayButton.click();
}
});
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const startTag = document.querySelector("#startTag");
const mtFinalTag = document.querySelector("#mtFinalTag");
const tmFinalTag = document.querySelector("#tmFinalTag");
const deltaTag = document.querySelector("#deltaTag");
const xAxisTag = document.querySelector("#xAxisTag");
const zAxisTag = document.querySelector("#zAxisTag");
function positionTag(element, worldPosition, visible = true) {
const projected = worldPosition.clone().project(camera);
const inFront = projected.z > -1 && projected.z < 1;
element.style.visibility = inFront ? "visible" : "hidden";
if (!inFront) return;
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.classList.toggle("visible", visible);
}
function updateLabels(elapsed) {
const complete = elapsed >= TOTAL_MS;
positionTag(
startTag,
new THREE.Vector3(0, 0.12, -0.9),
true
);
positionTag(
mtFinalTag,
new THREE.Vector3(
moveThenTurn.position.x,
moveThenTurn.position.y + 2.15,
moveThenTurn.position.z
),
complete
);
positionTag(
tmFinalTag,
new THREE.Vector3(
turnThenMove.position.x,
turnThenMove.position.y + 2.15,
turnThenMove.position.z
),
complete
);
positionTag(
deltaTag,
new THREE.Vector3(1.5, 0.35, 1.5),
complete
);
positionTag(
xAxisTag,
new THREE.Vector3(5.35, 0.1, 0),
true
);
positionTag(
zAxisTag,
new THREE.Vector3(0, 0.1, 5.35),
true
);
}
// ---------------------------------------------------------------------
// Resize and animation loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
function animate(now) {
requestAnimationFrame(animate);
const elapsed = currentElapsed(now);
applyActors(elapsed);
updateSequenceUI(elapsed);
updateLabels(elapsed);
// A subtle pulse on the two final-position pads.
const pulse = 1 + Math.sin(now * 0.004) * 0.035;
cyanPad.scale.setScalar(pulse);
pinkPad.scale.setScalar(pulse);
renderer.render(scene, camera);
}
updateCamera();
resize();
requestAnimationFrame(animate);
</script>
</body>
</html>
```