Prompt specification
Build or customize the Three.js 3D scene "Warehouse robot location scene" 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: Warehouse robot location scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/warehouse-robot-location-scene-x1691
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows coordinates relative to an origin and axes. Compose a bounded warehouse grid with shelf coordinates and a moving robot; show position updates and distinguish continuous coordinates from discrete aisle labels. Voxel style.
Working Three.js Starter (warehouse-robot-location-scene-x1691):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Warehouse Coordinate Grid</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(11, 18, 27, 0.88);
--border: rgba(157, 196, 218, 0.22);
--text: #e8f3fa;
--muted: #8da6b8;
--cyan: #39d9e8;
--green: #65e69a;
--yellow: #ffd166;
--red: #ff5d73;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101722;
font-family:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-card {
position: absolute;
top: 18px;
left: 18px;
padding: 14px 16px;
background: var(--panel);
border: 1px solid var(--border);
border-left: 4px solid var(--cyan);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 3px;
color: var(--text);
font-size: clamp(16px, 2vw, 22px);
line-height: 1.15;
letter-spacing: -0.03em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.axis-legend {
position: absolute;
top: 18px;
right: 18px;
display: flex;
gap: 14px;
padding: 11px 14px;
background: var(--panel);
border: 1px solid var(--border);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(10px);
}
.axis-legend span {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
box-shadow: 0 0 12px currentColor;
}
.swatch.x {
color: var(--red);
background: currentColor;
}
.swatch.y {
color: var(--green);
background: currentColor;
}
.swatch.z {
color: var(--cyan);
background: currentColor;
}
.telemetry {
position: absolute;
left: 18px;
bottom: 18px;
width: min(390px, calc(100vw - 36px));
overflow: hidden;
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.telemetry-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 11px 13px;
border-bottom: 1px solid var(--border);
background: rgba(255, 255, 255, 0.025);
}
.robot-id {
color: var(--text);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
}
.status {
display: flex;
align-items: center;
gap: 7px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.status.paused {
color: var(--yellow);
}
.status-dot {
width: 7px;
height: 7px;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.telemetry-grid {
display: grid;
grid-template-columns: 1fr 1fr;
}
.metric {
min-height: 88px;
padding: 12px 13px;
border-right: 1px solid var(--border);
border-bottom: 1px solid var(--border);
}
.metric:nth-child(2n) {
border-right: none;
}
.metric-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
color: var(--text);
font-size: 18px;
font-weight: 800;
letter-spacing: -0.05em;
white-space: nowrap;
}
.metric-value.continuous {
color: var(--cyan);
}
.metric-value.discrete {
color: var(--green);
}
.metric-value.shelf {
color: var(--yellow);
}
.metric-detail {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.coordinate-note {
padding: 10px 13px;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
.coordinate-note strong {
color: #c8d9e5;
}
.controls {
position: absolute;
right: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(470px, calc(100vw - 36px));
pointer-events: auto;
}
button {
padding: 10px 12px;
border: 1px solid var(--border);
background: rgba(14, 23, 33, 0.92);
color: #c9dce8;
font: 700 10px ui-monospace, monospace;
letter-spacing: 0.04em;
cursor: pointer;
transition:
border-color 120ms ease,
background 120ms ease,
color 120ms ease;
}
button:hover,
button:focus-visible {
color: #ffffff;
border-color: var(--cyan);
background: rgba(34, 67, 82, 0.95);
outline: none;
}
.help {
position: absolute;
right: 18px;
bottom: 66px;
max-width: 380px;
padding: 8px 10px;
color: rgba(190, 210, 224, 0.72);
font-size: 9px;
line-height: 1.5;
text-align: right;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--cyan);
background: #101722;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.axis-legend {
display: none;
}
.title-card {
top: 10px;
left: 10px;
right: 10px;
}
.telemetry {
left: 10px;
bottom: 65px;
width: calc(100vw - 20px);
}
.controls {
right: 10px;
bottom: 10px;
left: 10px;
max-width: none;
}
.help {
display: none;
}
.metric {
min-height: 76px;
padding: 10px;
}
.metric-value {
font-size: 15px;
}
}
</style>
</head>
<body>
<div id="loading">Loading voxel warehouse…</div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Spatial Systems / Grid 01</div>
<h1>Voxel Warehouse Coordinates</h1>
<p class="subtitle">
28 × 18 m mapped floor · origin at lower-left corner
</p>
</section>
<section class="axis-legend" aria-label="Axis legend">
<span><i class="swatch x"></i> X / EAST</span>
<span><i class="swatch y"></i> Y / UP</span>
<span><i class="swatch z"></i> Z / NORTH</span>
</section>
<section class="telemetry" aria-live="polite">
<header class="telemetry-header">
<span class="robot-id">AMR-07 / PATROL UNIT</span>
<span id="status" class="status">
<i class="status-dot"></i>
<span id="statusText">RUNNING</span>
</span>
</header>
<div class="telemetry-grid">
<div class="metric">
<div class="metric-title">Continuous Position</div>
<div id="continuousPosition" class="metric-value continuous">
X 00.00 / Z 00.00
</div>
<div id="motionDetail" class="metric-detail">
Heading 000° · Speed 0.00 m/s
</div>
</div>
<div class="metric">
<div class="metric-title">Discrete Location</div>
<div id="discreteLocation" class="metric-value discrete">
AISLE A
</div>
<div id="cellDetail" class="metric-detail">
Grid cell 00-00
</div>
</div>
<div class="metric">
<div class="metric-title">Nearest Shelf Coordinate</div>
<div id="shelfCoordinate" class="metric-value shelf">
R1-01
</div>
<div class="metric-detail">Shelf ID = ROW / BAY</div>
</div>
<div class="metric">
<div class="metric-title">Coordinate Frame</div>
<div class="metric-value">m / GRID</div>
<div class="metric-detail">Origin: X 0.00, Z 0.00</div>
</div>
</div>
<div class="coordinate-note">
<strong>Continuous</strong> X/Z values retain sub-meter precision.
<strong>Discrete</strong> aisle, cell, and shelf IDs are snapped
classifications derived from those coordinates.
</div>
</section>
<div class="help">
Drag: orbit · Shift/right drag: pan · Wheel/pinch: zoom · R: reset
</div>
<nav class="controls" aria-label="Scene controls">
<button id="pauseButton" type="button">Pause Robot</button>
<button id="gridButton" type="button">Hide Grid</button>
<button id="resetButton" type="button">Reset Camera</button>
</nav>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene and renderer
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101722);
scene.fog = new THREE.Fog(0x101722, 48, 88);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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.15;
renderer.domElement.setAttribute("aria-label", "Interactive 3D warehouse");
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
150
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xcce9ff, 0x25303a, 2.15));
const sun = new THREE.DirectionalLight(0xffffff, 3.1);
sun.position.set(14, 30, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x4cd6ef, 1.0);
rimLight.position.set(-20, 12, -18);
scene.add(rimLight);
// Warehouse coordinates are 0..28 in X and 0..18 in Z.
// The scene origin is placed at the lower-left corner.
const GRID_X = 28;
const GRID_Z = 18;
const WORLD_OFFSET_X = -14;
const WORLD_OFFSET_Z = -9;
function localPoint(x, y = 0, z = 0) {
return new THREE.Vector3(
x + WORLD_OFFSET_X,
y,
z + WORLD_OFFSET_Z
);
}
function addBox(parent, size, position, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.copy(position);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.05,
...options
});
}
// ------------------------------------------------------------
// Canvas-generated labels: no font or texture assets required
// ------------------------------------------------------------
function createTextSprite(text, options = {}) {
const {
foreground = "#eaf6ff",
background = "rgba(8,14,20,0.86)",
border = "rgba(158,202,224,0.28)",
width = 2.4,
fontSize = 48
} = options;
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
if (background) {
context.fillStyle = background;
context.fillRect(3, 3, canvas.width - 6, canvas.height - 6);
}
if (border) {
context.strokeStyle = border;
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
}
context.fillStyle = foreground;
context.font = `700 ${fontSize}px ui-monospace, Menlo, Consolas, monospace`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 20;
return sprite;
}
// ------------------------------------------------------------
// Floor, boundary, grid and coordinate labels
// ------------------------------------------------------------
const floorMaterial = standard(0x26343d, {
roughness: 0.94,
metalness: 0.02
});
addBox(
scene,
[GRID_X, 0.36, GRID_Z],
localPoint(GRID_X / 2, -0.22, GRID_Z / 2),
floorMaterial,
false,
true
);
// Darker bands make the four walkable aisles immediately readable.
const aisleBandMaterial = new THREE.MeshBasicMaterial({
color: 0x244552,
transparent: true,
opacity: 0.36,
depthWrite: false
});
const aisleCenters = [1.5, 6.5, 11.5, 16.5];
for (const z of aisleCenters) {
const band = new THREE.Mesh(
new THREE.PlaneGeometry(26, 1.75),
aisleBandMaterial
);
band.rotation.x = -Math.PI / 2;
band.position.copy(localPoint(14, 0.012, z));
scene.add(band);
}
const gridGroup = new THREE.Group();
scene.add(gridGroup);
const minorVertices = [];
const majorVertices = [];
for (let x = 0; x <= GRID_X; x++) {
const target = x % 4 === 0 ? majorVertices : minorVertices;
target.push(
...localPoint(x, 0.035, 0).toArray(),
...localPoint(x, 0.035, GRID_Z).toArray()
);
}
for (let z = 0; z <= GRID_Z; z++) {
const target = z % 3 === 0 ? majorVertices : minorVertices;
target.push(
...localPoint(0, 0.035, z).toArray(),
...localPoint(GRID_X, 0.035, z).toArray()
);
}
const minorGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(minorVertices, 3)
),
new THREE.LineBasicMaterial({
color: 0x86a6b6,
transparent: true,
opacity: 0.16
})
);
const majorGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(majorVertices, 3)
),
new THREE.LineBasicMaterial({
color: 0x9bc6d8,
transparent: true,
opacity: 0.34
})
);
gridGroup.add(minorGrid, majorGrid);
const borderMaterial = standard(0x60717c, {
metalness: 0.35,
roughness: 0.55
});
addBox(
scene,
[0.20, 0.30, GRID_Z],
localPoint(0, 0.09, GRID_Z / 2),
borderMaterial
);
addBox(
scene,
[0.20, 0.30, GRID_Z],
localPoint(GRID_X, 0.09, GRID_Z / 2),
borderMaterial
);
addBox(
scene,
[GRID_X, 0.30, 0.20],
localPoint(GRID_X / 2, 0.09, 0),
borderMaterial
);
addBox(
scene,
[GRID_X, 0.30, 0.20],
localPoint(GRID_X / 2, 0.09, GRID_Z),
borderMaterial
);
const cornerMaterial = standard(0xf0b54b, {
emissive: 0x5b3b08,
emissiveIntensity: 0.45
});
for (const [x, z] of [
[0, 0],
[GRID_X, 0],
[0, GRID_Z],
[GRID_X, GRID_Z]
]) {
addBox(
scene,
[0.52, 0.65, 0.52],
localPoint(x, 0.22, z),
cornerMaterial
);
}
// Numeric coordinate ticks.
for (let x = 0; x <= GRID_X; x += 4) {
const label = createTextSprite(String(x).padStart(2, "0"), {
foreground: "#ff9aa8",
background: "rgba(10,16,22,0.75)",
border: null,
width: 0.82,
fontSize: 56
});
label.position.copy(localPoint(x, 0.18, 0.32));
scene.add(label);
}
for (let z = 0; z <= GRID_Z; z += 3) {
const label = createTextSprite(String(z).padStart(2, "0"), {
foreground: "#76e8f3",
background: "rgba(10,16,22,0.75)",
border: null,
width: 0.82,
fontSize: 56
});
label.position.copy(localPoint(0.33, 0.18, z));
scene.add(label);
}
// ------------------------------------------------------------
// Pixel-style axes at the origin
// ------------------------------------------------------------
function addBlockArrow(axis, length, color) {
const group = new THREE.Group();
const material = standard(color, {
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.38
});
const shaftLength = length - 1.2;
if (axis === "x") {
addBox(
group,
[shaftLength, 0.07, 0.07],
new THREE.Vector3(shaftLength / 2, 0, 0),
material,
false
);
for (let i = 0; i < 3; i++) {
const size = 0.22 + i * 0.14;
addBox(
group,
[0.34, size, size],
new THREE.Vector3(length - 0.75 + i * 0.27, 0, 0),
material,
false
);
}
} else if (axis === "z") {
addBox(
group,
[0.07, 0.07, shaftLength],
new THREE.Vector3(0, 0, shaftLength / 2),
material,
false
);
for (let i = 0; i < 3; i++) {
const size = 0.22 + i * 0.14;
addBox(
group,
[size, size, 0.34],
new THREE.Vector3(0, 0, length - 0.75 + i * 0.27),
material,
false
);
}
} else {
addBox(
group,
[0.07, shaftLength, 0.07],
new THREE.Vector3(0, shaftLength / 2, 0),
material,
false
);
for (let i = 0; i < 3; i++) {
const size = 0.22 + i * 0.14;
addBox(
group,
[size, 0.34, size],
new THREE.Vector3(0, length - 0.75 + i * 0.27, 0),
material,
false
);
}
}
scene.add(group);
return group;
}
const xAxis = addBlockArrow("x", GRID_X, 0xff4d6d);
xAxis.position.copy(localPoint(0, 0.13, 0));
const zAxis = addBlockArrow("z", GRID_Z, 0x38d7e8);
zAxis.position.copy(localPoint(0, 0.14, 0));
const yAxis = addBlockArrow("y", 4.0, 0x65e69a);
yAxis.position.copy(localPoint(0, 0.12, 0));
const originMarker = standard(0xffd166, {
emissive: 0x8f5700,
emissiveIntensity: 0.7
});
addBox(
scene,
[0.42, 0.12, 0.42],
localPoint(0, 0.13, 0),
originMarker,
false
);
const originLabel = createTextSprite("ORIGIN 0,0", {
foreground: "#ffe29a",
background: "rgba(9,14,20,0.90)",
border: "rgba(255,209,102,0.55)",
width: 2.3,
fontSize: 43
});
originLabel.position.copy(localPoint(0, 0.75, 0));
scene.add(originLabel);
const xLabel = createTextSprite("X / m", {
foreground: "#ff7b8e",
background: null,
border: null,
width: 1.6,
fontSize: 52
});
xLabel.position.copy(localPoint(27.5, 0.85, 0));
scene.add(xLabel);
const zLabel = createTextSprite("Z / m", {
foreground: "#6ceaf4",
background: null,
border: null,
width: 1.6,
fontSize: 52
});
zLabel.position.copy(localPoint(0, 0.85, 17.5));
scene.add(zLabel);
const yLabel = createTextSprite("Y", {
foreground: "#7af0a8",
background: null,
border: null,
width: 0.9,
fontSize: 58
});
yLabel.position.copy(localPoint(0, 4.55, 0));
scene.add(yLabel);
// ------------------------------------------------------------
// Voxel shelves and shelf coordinate tags
// ------------------------------------------------------------
const shelfSteel = standard(0x60717b, {
metalness: 0.48,
roughness: 0.54
});
const shelfDeck = standard(0x7d8c94, {
metalness: 0.32,
roughness: 0.62
});
const cartonMaterials = [
standard(0xc88745),
standard(0xd6a75c),
standard(0x8e6f54),
standard(0x638d83),
standard(0xa85e52)
];
const rackRows = [
{ id: "R1", z: 4, accent: 0xf0a33b },
{ id: "R2", z: 9, accent: 0x3cb9d1 }
];
const moduleXs = [3, 7, 11, 15, 19, 23];
const shelfLevels = [0.34, 1.36, 2.38];
function pseudoRandom(seed) {
const value = Math.sin(seed * 127.1 + 311.7) * 43758.5453123;
return value - Math.floor(value);
}
let shelfSeed = 1;
for (const row of rackRows) {
const beamMaterial = standard(row.accent, {
metalness: 0.22,
roughness: 0.48
});
moduleXs.forEach((x, moduleIndex) => {
const group = new THREE.Group();
group.position.copy(localPoint(x, 0, row.z));
scene.add(group);
// Four upright posts.
for (const postX of [-1.58, 1.58]) {
for (const postZ of [-0.62, 0.62]) {
addBox(
group,
[0.16, 3.48, 0.16],
new THREE.Vector3(postX, 1.74, postZ),
shelfSteel
);
}
}
// Three shelf decks.
for (const y of shelfLevels) {
addBox(
group,
[3.15, 0.13, 1.25],
new THREE.Vector3(0, y, 0),
shelfDeck
);
addBox(
group,
[3.34, 0.17, 0.14],
new THREE.Vector3(0, y + 0.05, 0.68),
beamMaterial
);
}
// Top beam and voxel cartons.
addBox(
group,
[3.34, 0.17, 0.14],
new THREE.Vector3(0, 3.43, 0.68),
beamMaterial
);
for (let level = 0; level < shelfLevels.length; level++) {
for (let boxIndex = 0; boxIndex < 3; boxIndex++) {
const width = 0.65 + pseudoRandom(shelfSeed++) * 0.22;
const height = 0.38 + pseudoRandom(shelfSeed++) * 0.30;
const depth = 0.62 + pseudoRandom(shelfSeed++) * 0.30;
const offset = (pseudoRandom(shelfSeed++) - 0.5) * 0.17;
const zOffset = (pseudoRandom(shelfSeed++) - 0.5) * 0.26;
const material = cartonMaterials[
Math.floor(pseudoRandom(shelfSeed++) * cartonMaterials.length)
];
addBox(
group,
[width, height, depth],
new THREE.Vector3(
-1.00 + boxIndex * 0.98 + offset,
shelfLevels[level] + 0.07 + height / 2,
zOffset
),
material
);
}
}
const shelfTag = createTextSprite(
`${row.id}-${String(moduleIndex + 1).padStart(2, "0")}`,
{
foreground: row.id === "R1" ? "#ffd27f" : "#8beaff",
background: "rgba(8,14,20,0.91)",
border: row.id === "R1"
? "rgba(240,163,59,0.65)"
: "rgba(60,185,209,0.65)",
width: 1.75,
fontSize: 48
}
);
shelfTag.position.set(0, 3.82, 0.72);
group.add(shelfTag);
});
}
// Discrete aisle signs.
const aisleNames = ["A", "B", "C", "D"];
aisleCenters.forEach((z, index) => {
const sign = createTextSprite(`AISLE ${aisleNames[index]}`, {
foreground: "#d9f6ff",
background: "rgba(7,13,19,0.86)",
border: "rgba(75,190,210,0.45)",
width: 2.45,
fontSize: 44
});
sign.position.copy(localPoint(0.8, 0.22, z));
scene.add(sign);
});
// ------------------------------------------------------------
// Robot patrol route
// ------------------------------------------------------------
const route = [
new THREE.Vector2(1, 1.5),
new THREE.Vector2(27, 1.5),
new THREE.Vector2(27, 6.5),
new THREE.Vector2(1, 6.5),
new THREE.Vector2(1, 11.5),
new THREE.Vector2(27, 11.5),
new THREE.Vector2(27, 16.5),
new THREE.Vector2(1, 16.5),
new THREE.Vector2(1, 1.5)
];
const routeWorldPoints = route.map(
(point) => localPoint(point.x, 0.12, point.y)
);
const routeLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(routeWorldPoints),
new THREE.LineDashedMaterial({
color: 0xffc857,
dashSize: 0.55,
gapSize: 0.38,
transparent: true,
opacity: 0.58
})
);
routeLine.computeLineDistances();
scene.add(routeLine);
const routeMarkerMaterial = standard(0xffc857, {
emissive: 0x6f4900,
emissiveIntensity: 0.6
});
for (const point of route.slice(0, -1)) {
addBox(
scene,
[0.18, 0.08, 0.18],
localPoint(point.x, 0.13, point.y),
routeMarkerMaterial,
false
);
}
// ------------------------------------------------------------
// Voxel robot
// ------------------------------------------------------------
const robot = new THREE.Group();
robot.scale.setScalar(1.12);
scene.add(robot);
const robotDark = standard(0x17212b, {
roughness: 0.62,
metalness: 0.24
});
const robotBody = standard(0xdce8ec, {
roughness: 0.55,
metalness: 0.12
});
const robotCyan = standard(0x31d5e5, {
emissive: 0x087d8b,
emissiveIntensity: 0.55,
roughness: 0.38
});
const robotYellow = standard(0xffca58, {
emissive: 0x7f5100,
emissiveIntensity: 0.45
});
addBox(
robot,
[1.62, 0.28, 1.10],
new THREE.Vector3(0, 0.32, 0),
robotDark
);
addBox(
robot,
[1.52, 0.42, 1.00],
new THREE.Vector3(0, 0.63, 0),
robotBody
);
addBox(
robot,
[1.08, 0.28, 0.80],
new THREE.Vector3(-0.05, 0.97, 0),
robotCyan
);
addBox(
robot,
[0.14, 0.34, 0.88],
new THREE.Vector3(0.78, 0.63, 0),
robotYellow
);
addBox(
robot,
[0.15, 0.40, 0.15],
new THREE.Vector3(-0.10, 1.28, 0),
robotDark
);
addBox(
robot,
[0.34, 0.16, 0.34],
new THREE.Vector3(-0.10, 1.53, 0),
robotYellow
);
const ledMaterial = new THREE.MeshStandardMaterial({
color: 0x7bffb0,
emissive: 0x42ff8b,
emissiveIntensity: 2.1
});
addBox(
robot,
[0.08, 0.12, 0.28],
new THREE.Vector3(0.70, 0.91, 0),
ledMaterial,
false
);
for (const x of [-0.53, 0.53]) {
for (const z of [-0.55, 0.55]) {
addBox(
robot,
[0.43, 0.43, 0.20],
new THREE.Vector3(x, 0.31, z),
robotDark
);
}
}
// A tiny front marker makes the robot's heading immediately legible.
addBox(
robot,
[0.25, 0.10, 0.25],
new THREE.Vector3(0.92, 0.77, 0),
robotYellow,
false
);
// ------------------------------------------------------------
// Continuous marker and snapped discrete cell
// ------------------------------------------------------------
const cellGroup = new THREE.Group();
const cellFill = new THREE.Mesh(
new THREE.PlaneGeometry(1, 1),
new THREE.MeshBasicMaterial({
color: 0x4cf29a,
transparent: true,
opacity: 0.18,
depthWrite: false,
side: THREE.DoubleSide
})
);
cellFill.rotation.x = -Math.PI / 2;
cellGroup.add(cellFill);
const cellBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.PlaneGeometry(1, 1)),
new THREE.LineBasicMaterial({
color: 0x6dffad,
transparent: true,
opacity: 0.88
})
);
cellBorder.rotation.x = -Math.PI / 2;
cellGroup.add(cellBorder);
scene.add(cellGroup);
const exactPositionMarker = new THREE.Group();
addBox(
exactPositionMarker,
[0.14, 0.07, 0.14],
new THREE.Vector3(0, 0, 0),
standard(0xffffff, {
emissive: 0xffffff,
emissiveIntensity: 1.0
}),
false
);
addBox(
exactPositionMarker,
[0.42, 0.035, 0.045],
new THREE.Vector3(0, 0, 0),
standard(0xffffff, {
emissive: 0xffffff,
emissiveIntensity: 0.8
}),
false
);
addBox(
exactPositionMarker,
[0.045, 0.035, 0.42],
new THREE.Vector3(0, 0, 0),
standard(0xffffff, {
emissive: 0xffffff,
emissiveIntensity: 0.8
}),
false
);
scene.add(exactPositionMarker);
// ------------------------------------------------------------
// Route movement and coordinate classification
// ------------------------------------------------------------
const routeLengths = [];
let totalRouteLength = 0;
for (let i = 0; i < route.length - 1; i++) {
const length = route[i].distanceTo(route[i + 1]);
routeLengths.push(length);
totalRouteLength += length;
}
function sampleRoute(distance) {
let remaining =
((distance % totalRouteLength) + totalRouteLength) % totalRouteLength;
for (let i = 0; i < routeLengths.length; i++) {
const length = routeLengths[i];
if (remaining <= length || i === routeLengths.length - 1) {
const start = route[i];
const end = route[i + 1];
const alpha = Math.min(1, Math.max(0, remaining / length));
return {
x: THREE.MathUtils.lerp(start.x, end.x, alpha),
z: THREE.MathUtils.lerp(start.y, end.y, alpha),
heading: Math.atan2(end.y - start.y, end.x - start.x)
};
}
remaining -= length;
}
return {
x: route[0].x,
z: route[0].y,
heading: 0
};
}
function shortestAngleDifference(from, to) {
return Math.atan2(Math.sin(to - from), Math.cos(to - from));
}
function classifyAisle(z) {
if (z < 3.25) return "A";
if (z < 7.75) return "B";
if (z < 13.75) return "C";
return "D";
}
function nearestShelf(x, z) {
const row = z < 5.75 ? "R1" : "R2";
let nearestIndex = 0;
let nearestDistance = Infinity;
moduleXs.forEach((moduleX, index) => {
const distance = Math.abs(x - moduleX);
if (distance < nearestDistance) {
nearestDistance = distance;
nearestIndex = index;
}
});
return `${row}-${String(nearestIndex + 1).padStart(2, "0")}`;
}
const continuousPositionElement =
document.getElementById("continuousPosition");
const motionDetailElement = document.getElementById("motionDetail");
const discreteLocationElement =
document.getElementById("discreteLocation");
const cellDetailElement = document.getElementById("cellDetail");
const shelfCoordinateElement =
document.getElementById("shelfCoordinate");
const statusElement = document.getElementById("status");
const statusTextElement = document.getElementById("statusText");
const pauseButton = document.getElementById("pauseButton");
const gridButton = document.getElementById("gridButton");
const resetButton = document.getElementById("resetButton");
let paused = false;
let gridVisible = true;
let routeDistance = 16;
let elapsed = 0;
let currentSpeed = 3.25;
let robotLocalX = 0;
let robotLocalZ = 0;
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Resume Robot" : "Pause Robot";
statusElement.classList.toggle("paused", paused);
statusTextElement.textContent = paused ? "PAUSED" : "RUNNING";
}
pauseButton.addEventListener("click", togglePause);
gridButton.addEventListener("click", () => {
gridVisible = !gridVisible;
gridGroup.visible = gridVisible;
gridButton.textContent = gridVisible ? "Hide Grid" : "Show Grid";
});
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard and pinch
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.75, 0),
theta: 0.72,
phi: 0.84,
radius: 49
};
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(0, 0.75, 0);
cameraState.theta = 0.72;
cameraState.phi = 0.84;
cameraState.radius = 49;
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
const activePointers = new Map();
let dragState = null;
let pinchDistance = 0;
function getPinchDistance() {
const pointers = [...activePointers.values()];
if (pointers.length < 2) return 0;
return Math.hypot(
pointers[0].x - pointers[1].x,
pointers[0].y - pointers[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragState = {
x: event.clientX,
y: event.clientY,
mode:
event.button === 2 || event.shiftKey || event.altKey
? "pan"
: "orbit"
};
} else {
dragState = null;
pinchDistance = getPinchDistance();
}
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
const newDistance = getPinchDistance();
if (pinchDistance > 0 && newDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / newDistance),
28,
82
);
updateCamera();
}
pinchDistance = newDistance;
event.preventDefault();
return;
}
if (!dragState) return;
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
if (dragState.mode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.28,
1.36
);
} else {
const forward = camera.getWorldDirection(new THREE.Vector3());
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(new THREE.Vector3(0, 1, 0), forward)
.normalize();
const panScale = cameraState.radius * 0.00135;
cameraState.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(forward, -dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-20,
20
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-15,
15
);
}
updateCamera();
event.preventDefault();
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 1) {
const pointer = [...activePointers.values()][0];
dragState = {
x: pointer.x,
y: pointer.y,
mode: "orbit"
};
} else {
dragState = null;
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"contextmenu",
(event) => event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
28,
82
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.1;
break;
case "ArrowRight":
cameraState.theta -= 0.1;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.28, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.36, cameraState.phi + 0.06);
break;
case "+":
case "=":
cameraState.radius = Math.max(28, cameraState.radius * 0.9);
break;
case "-":
case "_":
cameraState.radius = Math.min(82, cameraState.radius * 1.1);
break;
case "r":
case "R":
resetCamera();
break;
case " ":
togglePause();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
let lastFrame = performance.now();
let hudAccumulator = 0;
function animate(now) {
const delta = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
elapsed += delta;
if (!paused) {
currentSpeed = 3.25 * (0.94 + Math.sin(elapsed * 0.85) * 0.06);
routeDistance += delta * currentSpeed;
} else {
currentSpeed = 0;
}
const sample = sampleRoute(routeDistance);
robotLocalX = sample.x;
robotLocalZ = sample.z;
robot.position.copy(localPoint(robotLocalX, 0, robotLocalZ));
// Three.js yaw is opposite to the conventional X/Z heading angle.
const desiredYaw = -sample.heading;
robot.rotation.y +=
shortestAngleDifference(robot.rotation.y, desiredYaw) *
Math.min(1, delta * 9);
// The green tile is snapped to a discrete floor cell.
const cellX = THREE.MathUtils.clamp(
Math.floor(robotLocalX),
0,
GRID_X - 1
);
const cellZ = THREE.MathUtils.clamp(
Math.floor(robotLocalZ),
0,
GRID_Z - 1
);
cellGroup.position.copy(
localPoint(cellX + 0.5, 0.065, cellZ + 0.5)
);
// The white cross remains at the exact continuous position.
exactPositionMarker.position.copy(
localPoint(robotLocalX, 0.095, robotLocalZ)
);
hudAccumulator += delta;
if (hudAccumulator >= 0.08) {
hudAccumulator = 0;
const aisle = classifyAisle(robotLocalZ);
const shelf = nearestShelf(robotLocalX, robotLocalZ);
let heading =
((-robot.rotation.y * THREE.MathUtils.RAD2DEG) % 360 + 360) % 360;
continuousPositionElement.textContent =
`X ${robotLocalX.toFixed(2).padStart(5, "0")} / ` +
`Z ${robotLocalZ.toFixed(2).padStart(5, "0")}`;
motionDetailElement.textContent =
`Heading ${Math.round(heading).toString().padStart(3, "0")}° · ` +
`Speed ${currentSpeed.toFixed(2)} m/s`;
discreteLocationElement.textContent = `AISLE ${aisle}`;
cellDetailElement.textContent =
`Grid cell ` +
`${String(cellX).padStart(2, "0")}-` +
`${String(cellZ).padStart(2, "0")}`;
shelfCoordinateElement.textContent = shelf;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
// ------------------------------------------------------------
// Resize and startup
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
document.getElementById("loading")?.remove();
requestAnimationFrame(animate);
</script>
</body>
</html>
```