Prompt specification
Build or customize the Three.js 3D scene "Diagonal distance warehouse 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: Diagonal distance warehouse scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/diagonal-distance-warehouse-scene-x1727
Scene Description Prompt:
A voxel warehouse grid compares a straight Euclidean diagonal with the longer walkable aisle route. Three.js from cdnjs, one HTML file.
Working Three.js Starter (diagonal-distance-warehouse-scene-x1727):
```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 — Shortcut vs. Aisle Route</title>
<style>
:root {
--bg: #071018;
--panel: rgba(12, 25, 34, 0.82);
--panel-border: rgba(144, 205, 225, 0.16);
--text: #edf8fb;
--muted: #8da7b3;
--direct: #ff527d;
--aisle: #55e6a5;
--start: #59d8ff;
--end: #ffbd69;
}
* {
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;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 45%, rgba(1, 7, 12, 0.36) 100%),
linear-gradient(180deg, rgba(2, 8, 13, 0.2), transparent 25%);
}
.header {
position: fixed;
top: 24px;
left: 26px;
max-width: 520px;
pointer-events: none;
z-index: 5;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #9ec2d0;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--aisle);
box-shadow: 0 0 12px rgba(85, 230, 165, 0.65);
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 42px);
font-weight: 760;
line-height: 1.02;
letter-spacing: -0.045em;
text-shadow: 0 3px 25px rgba(0, 0, 0, 0.35);
}
.subtitle {
margin: 10px 0 0;
max-width: 470px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
position: fixed;
top: 24px;
right: 24px;
width: 294px;
padding: 16px;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
z-index: 6;
}
.metrics-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: #b7cbd4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: var(--aisle);
font-size: 9px;
letter-spacing: 0.08em;
}
.live::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--aisle);
box-shadow: 0 0 10px var(--aisle);
}
.metric {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 10px;
padding: 11px 0;
border-top: 1px solid rgba(157, 202, 219, 0.1);
}
.metric:first-of-type {
border-top: 0;
}
.metric-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.metric-dot.direct {
background: var(--direct);
box-shadow: 0 0 12px rgba(255, 82, 125, 0.75);
}
.metric-dot.aisle {
background: var(--aisle);
box-shadow: 0 0 12px rgba(85, 230, 165, 0.65);
}
.metric-name {
color: #a9bec8;
font-size: 12px;
line-height: 1.25;
}
.metric-value {
color: var(--text);
font-size: 18px;
font-weight: 760;
font-variant-numeric: tabular-nums;
letter-spacing: -0.03em;
}
.metric-value.direct {
color: var(--direct);
}
.metric-value.aisle {
color: var(--aisle);
}
.summary {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 7px;
}
.summary-card {
padding: 11px;
border: 1px solid rgba(151, 205, 224, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.summary-card span {
display: block;
color: #809aa6;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.summary-card strong {
display: block;
margin-top: 5px;
color: #d9e9ee;
font-size: 13px;
font-weight: 720;
}
.legend {
position: fixed;
bottom: 25px;
left: 26px;
display: flex;
flex-direction: column;
gap: 9px;
pointer-events: none;
z-index: 5;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #a9c0ca;
font-size: 11px;
}
.legend-line {
width: 27px;
height: 3px;
border-radius: 4px;
}
.legend-line.direct {
background: repeating-linear-gradient(
90deg,
var(--direct) 0 7px,
transparent 7px 11px
);
box-shadow: 0 0 8px rgba(255, 82, 125, 0.4);
}
.legend-line.aisle {
background: var(--aisle);
box-shadow: 0 0 8px rgba(85, 230, 165, 0.4);
}
.controls {
position: fixed;
bottom: 23px;
left: 50%;
display: flex;
gap: 7px;
padding: 7px;
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 14px;
background: rgba(11, 24, 33, 0.86);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(15px);
z-index: 8;
}
.controls button {
display: flex;
align-items: center;
gap: 7px;
min-height: 34px;
padding: 0 12px;
border: 1px solid transparent;
border-radius: 9px;
color: #91aab5;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition:
color 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.controls button:hover {
color: #e8f6fa;
background: rgba(255, 255, 255, 0.055);
}
.controls button.active {
color: #eafff6;
border-color: rgba(85, 230, 165, 0.26);
background: rgba(85, 230, 165, 0.1);
}
.controls button[data-route="direct"].active {
border-color: rgba(255, 82, 125, 0.3);
background: rgba(255, 82, 125, 0.1);
}
.button-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
opacity: 0.55;
}
.controls button.active .button-dot {
opacity: 1;
box-shadow: 0 0 9px currentColor;
}
.help {
position: fixed;
right: 26px;
bottom: 27px;
color: #718a96;
font-size: 10px;
pointer-events: none;
z-index: 5;
}
.world-label {
position: fixed;
top: 0;
left: 0;
padding: 7px 10px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 9px;
background: rgba(7, 17, 24, 0.86);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
color: #dcecf1;
font-size: 10px;
font-weight: 760;
letter-spacing: 0.035em;
pointer-events: none;
white-space: nowrap;
z-index: 4;
backdrop-filter: blur(8px);
}
.world-label.direct {
border-color: rgba(255, 82, 125, 0.38);
color: #ff91aa;
}
.world-label.aisle {
border-color: rgba(85, 230, 165, 0.38);
color: #8bf1c4;
}
.world-label.endpoint {
padding: 6px 9px;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.world-label.endpoint.start {
color: var(--start);
border-color: rgba(89, 216, 255, 0.32);
}
.world-label.endpoint.end {
color: var(--end);
border-color: rgba(255, 189, 105, 0.32);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #071018;
color: #b7d0da;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
z-index: 20;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
}
.loader::before {
width: 13px;
height: 13px;
content: "";
border: 2px solid rgba(85, 230, 165, 0.22);
border-top-color: var(--aisle);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 760px) {
.header {
top: 15px;
left: 15px;
max-width: calc(100vw - 30px);
}
.subtitle {
max-width: 390px;
font-size: 11px;
}
.metrics {
top: 132px;
right: 14px;
left: 14px;
width: auto;
padding: 12px;
}
.metric {
padding: 8px 0;
}
.metric-value {
font-size: 16px;
}
.summary {
margin-top: 3px;
}
.legend,
.help {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
transform: none;
}
.controls button {
flex: 1;
justify-content: center;
padding: 0 8px;
font-size: 10px;
}
.world-label {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene"></div>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Voxel logistics lab</div>
<h1>Shortcut vs. aisle route</h1>
<p class="subtitle">
A Euclidean diagonal cuts directly through the warehouse, but the
walkable aisle route must respect shelving and corridor boundaries.
</p>
</header>
<aside class="metrics">
<div class="metrics-title">
Route comparison
<span class="live">Live model</span>
</div>
<div class="metric">
<span class="metric-dot direct"></span>
<span class="metric-name">Euclidean diagonal</span>
<span id="direct-distance" class="metric-value direct">14.42 m</span>
</div>
<div class="metric">
<span class="metric-dot aisle"></span>
<span class="metric-name">Walkable aisle route</span>
<span id="aisle-distance" class="metric-value aisle">20.00 m</span>
</div>
<div class="summary">
<div class="summary-card">
<span>Extra distance</span>
<strong id="detour-distance">+5.58 m</strong>
</div>
<div class="summary-card">
<span>Detour cost</span>
<strong id="detour-percent">+38.7%</strong>
</div>
</div>
<div class="summary">
<div class="summary-card">
<span>Shortcut status</span>
<strong id="conflict-count">6 rack conflicts</strong>
</div>
<div class="summary-card">
<span>Grid unit</span>
<strong>1.00 meter</strong>
</div>
</div>
</aside>
<div class="legend">
<div class="legend-row">
<span class="legend-line direct"></span>
<span>Blocked Euclidean shortcut</span>
</div>
<div class="legend-row">
<span class="legend-line aisle"></span>
<span>Walkable aisle path</span>
</div>
</div>
<div class="controls">
<button
id="toggle-direct"
class="active"
data-route="direct"
aria-pressed="true"
>
<span class="button-dot"></span>
Shortcut
</button>
<button
id="toggle-aisle"
class="active"
data-route="aisle"
aria-pressed="true"
>
<span class="button-dot"></span>
Aisle
</button>
<button id="toggle-motion" aria-pressed="false">
<span class="button-dot"></span>
Auto orbit
</button>
<button id="reset-view">
<span class="button-dot"></span>
Reset
</button>
</div>
<div class="help">Drag to orbit · Scroll to zoom</div>
<div id="label-direct" class="world-label direct">
14.42 m · blocked diagonal
</div>
<div id="label-aisle" class="world-label aisle">
20.00 m · walkable route
</div>
<div id="label-start" class="world-label endpoint start">Start</div>
<div id="label-end" class="world-label endpoint end">Destination</div>
<div id="loading">
<div class="loader">Building warehouse</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
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.2;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D warehouse comparing a diagonal shortcut and an aisle route"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.FogExp2(0x071018, 0.016);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
const cameraState = {
theta: 0.68,
phi: 0.79,
radius: 18.2,
targetTheta: 0.68,
targetPhi: 0.79,
targetRadius: 18.2,
autoOrbit: false
};
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 9);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.targetTheta,
smoothing
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.targetPhi,
smoothing
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
smoothing
);
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * cosPhi,
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera(1);
// Lighting
scene.add(new THREE.HemisphereLight(0xc6ebff, 0x111820, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(8, 13, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x42d8ff, 18, 16, 2);
cyanLight.position.set(-6, 4, 4);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff9d56, 14, 15, 2);
warmLight.position.set(6, 3.5, -4);
scene.add(warmLight);
// Warehouse floor
const floorBase = new THREE.Mesh(
new THREE.BoxGeometry(13.4, 0.2, 9.4),
new THREE.MeshStandardMaterial({
color: 0x0b171f,
roughness: 0.86,
metalness: 0.12
})
);
floorBase.position.y = -0.1;
floorBase.receiveShadow = true;
scene.add(floorBase);
const tileGeometry = new THREE.PlaneGeometry(0.965, 0.965);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0.06
});
const tileCount = 13 * 9;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCount
);
const dummy = new THREE.Object3D();
const tileColors = [0x172832, 0x192b34, 0x14252e, 0x1b3038];
let tileIndex = 0;
for (let x = -6; x <= 6; x++) {
for (let z = -4; z <= 4; z++) {
dummy.position.set(x, 0.012, z);
dummy.rotation.set(-Math.PI / 2, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
tiles.setColorAt(
tileIndex,
new THREE.Color(tileColors[(x + z + 20) % tileColors.length])
);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// Fine one-meter grid
const gridPositions = [];
for (let x = -6.5; x <= 6.5; x += 1) {
gridPositions.push(x, 0.034, -4.5, x, 0.034, 4.5);
}
for (let z = -4.5; z <= 4.5; z += 1) {
gridPositions.push(-6.5, 0.034, z, 6.5, 0.034, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x4d7380,
transparent: true,
opacity: 0.23,
depthWrite: false
})
);
scene.add(grid);
// Low perimeter rails
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x31515e,
roughness: 0.55,
metalness: 0.42,
emissive: 0x07151b,
emissiveIntensity: 0.5
});
const perimeter = [
{ size: [13.3, 0.08, 0.07], pos: [0, 0.07, -4.52] },
{ size: [13.3, 0.08, 0.07], pos: [0, 0.07, 4.52] },
{ size: [0.07, 0.08, 9.1], pos: [-6.52, 0.07, 0] },
{ size: [0.07, 0.08, 9.1], pos: [6.52, 0.07, 0] }
];
perimeter.forEach(({ size, pos }) => {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(...size),
railMaterial
);
rail.position.set(...pos);
rail.castShadow = true;
scene.add(rail);
});
// Voxel-style rack layout.
// x = -2 is intentionally a clear vertical service aisle.
const rackRows = [-3, -1, 1, 3];
const rackColumns = [-5, -4, -3, 0, 1, 2, 4, 5];
const racks = [];
rackRows.forEach((z) => {
rackColumns.forEach((x) => {
racks.push({ x, z });
});
});
const postGeometry = new THREE.BoxGeometry(0.055, 1.5, 0.055);
const shelfGeometry = new THREE.BoxGeometry(0.88, 0.055, 0.76);
const cargoGeometry = new THREE.BoxGeometry(1, 1, 1);
const posts = new THREE.InstancedMesh(
postGeometry,
new THREE.MeshStandardMaterial({
color: 0x2a7280,
roughness: 0.42,
metalness: 0.65
}),
racks.length * 4
);
const shelves = new THREE.InstancedMesh(
shelfGeometry,
new THREE.MeshStandardMaterial({
color: 0x244b58,
roughness: 0.62,
metalness: 0.48
}),
racks.length * 3
);
const cargo = new THREE.InstancedMesh(
cargoGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.04
}),
racks.length * 6
);
let postIndex = 0;
let shelfIndex = 0;
let cargoIndex = 0;
let seed = 9182;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const cargoPalette = [
0xe98a42,
0xf0ad52,
0xcb6d38,
0x4e8c9c,
0x6ea7ad,
0xb75e45,
0xd9b16f
];
const shelfHeights = [0.12, 0.64, 1.16];
racks.forEach((rack) => {
const postOffsets = [
[-0.42, -0.35],
[0.42, -0.35],
[-0.42, 0.35],
[0.42, 0.35]
];
postOffsets.forEach(([dx, dz]) => {
dummy.position.set(rack.x + dx, 0.75, rack.z + dz);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
posts.setMatrixAt(postIndex++, dummy.matrix);
});
shelfHeights.forEach((height) => {
dummy.position.set(rack.x, height, rack.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
shelves.setMatrixAt(shelfIndex++, dummy.matrix);
[-0.215, 0.215].forEach((dx) => {
const boxWidth = 0.29 + random() * 0.075;
const boxHeight = 0.25 + random() * 0.12;
const boxDepth = 0.4 + random() * 0.16;
dummy.position.set(
rack.x + dx,
height + 0.03 + boxHeight / 2,
rack.z + (random() - 0.5) * 0.09
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(boxWidth, boxHeight, boxDepth);
dummy.updateMatrix();
cargo.setMatrixAt(cargoIndex, dummy.matrix);
cargo.setColorAt(
cargoIndex,
new THREE.Color(
cargoPalette[Math.floor(random() * cargoPalette.length)]
)
);
cargoIndex++;
});
});
});
posts.instanceMatrix.needsUpdate = true;
shelves.instanceMatrix.needsUpdate = true;
cargo.instanceMatrix.needsUpdate = true;
cargo.instanceColor.needsUpdate = true;
posts.castShadow = true;
shelves.castShadow = true;
shelves.receiveShadow = true;
cargo.castShadow = true;
cargo.receiveShadow = true;
scene.add(posts, shelves, cargo);
// Route coordinates, in one-meter grid units.
const start = new THREE.Vector2(-6, 4);
const end = new THREE.Vector2(6, -4);
const aislePoints = [
new THREE.Vector2(-6, 4),
new THREE.Vector2(-2, 4),
new THREE.Vector2(-2, -4),
new THREE.Vector2(6, -4)
];
const euclideanDistance = start.distanceTo(end);
let aisleDistance = 0;
for (let i = 0; i < aislePoints.length - 1; i++) {
aisleDistance += aislePoints[i].distanceTo(aislePoints[i + 1]);
}
const detour = aisleDistance - euclideanDistance;
const detourPercent = (detour / euclideanDistance) * 100;
document.getElementById("direct-distance").textContent =
`${euclideanDistance.toFixed(2)} m`;
document.getElementById("aisle-distance").textContent =
`${aisleDistance.toFixed(2)} m`;
document.getElementById("detour-distance").textContent =
`+${detour.toFixed(2)} m`;
document.getElementById("detour-percent").textContent =
`+${detourPercent.toFixed(1)}%`;
// Determine which rack bays the diagonal intersects.
const conflictingRacks = [];
racks.forEach((rack) => {
for (let i = 0; i <= 2000; i++) {
const t = i / 2000;
const x = THREE.MathUtils.lerp(start.x, end.x, t);
const z = THREE.MathUtils.lerp(start.y, end.y, t);
if (
Math.abs(x - rack.x) <= 0.44 &&
Math.abs(z - rack.z) <= 0.38
) {
conflictingRacks.push(rack);
break;
}
}
});
document.getElementById("conflict-count").textContent =
`${conflictingRacks.length} rack conflicts`;
// Red x-ray outlines identify the blocked rack footprints.
conflictingRacks.forEach((rack) => {
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(0.94, 0.025, 0.82)
),
new THREE.LineBasicMaterial({
color: 0xff527d,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
outline.position.set(rack.x, 0.085, rack.z);
outline.renderOrder = 12;
scene.add(outline);
});
// Direct Euclidean line, rendered as an x-ray dashed path.
const directGroup = new THREE.Group();
scene.add(directGroup);
const directStart = new THREE.Vector3(start.x, 0.105, start.y);
const directEnd = new THREE.Vector3(end.x, 0.105, end.y);
const directCurve = new THREE.LineCurve3(directStart, directEnd);
const directGlow = new THREE.Mesh(
new THREE.TubeGeometry(directCurve, 48, 0.026, 6, false),
new THREE.MeshBasicMaterial({
color: 0xff527d,
transparent: true,
opacity: 0.35,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
directGlow.renderOrder = 10;
directGroup.add(directGlow);
const directLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
directStart,
directEnd
]),
new THREE.LineDashedMaterial({
color: 0xff527d,
dashSize: 0.34,
gapSize: 0.18,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
directLine.computeLineDistances();
directLine.renderOrder = 11;
directGroup.add(directLine);
// Walkable aisle route.
const aisleGroup = new THREE.Group();
scene.add(aisleGroup);
const aisleMaterial = new THREE.MeshStandardMaterial({
color: 0x55e6a5,
emissive: 0x1aa66c,
emissiveIntensity: 1.1,
roughness: 0.36,
metalness: 0.22
});
const aisleGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x55e6a5,
transparent: true,
opacity: 0.13,
depthWrite: false,
toneMapped: false
});
function addAisleSegment(a, b) {
const dx = b.x - a.x;
const dz = b.y - a.y;
const length = Math.hypot(dx, dz);
const midpoint = new THREE.Vector2(
(a.x + b.x) / 2,
(a.y + b.y) / 2
);
const alongX = Math.abs(dx) > Math.abs(dz);
const geometry = alongX
? new THREE.BoxGeometry(length + 0.04, 0.035, 0.13)
: new THREE.BoxGeometry(0.13, 0.035, length + 0.04);
const segment = new THREE.Mesh(geometry, aisleMaterial);
segment.position.set(midpoint.x, 0.085, midpoint.y);
segment.castShadow = false;
segment.receiveShadow = true;
aisleGroup.add(segment);
const glowGeometry = alongX
? new THREE.BoxGeometry(length + 0.04, 0.012, 0.34)
: new THREE.BoxGeometry(0.34, 0.012, length + 0.04);
const glow = new THREE.Mesh(glowGeometry, aisleGlowMaterial);
glow.position.set(midpoint.x, 0.064, midpoint.y);
aisleGroup.add(glow);
}
for (let i = 0; i < aislePoints.length - 1; i++) {
addAisleSegment(aislePoints[i], aislePoints[i + 1]);
}
// Rounded route corners.
for (let i = 1; i < aislePoints.length - 1; i++) {
const corner = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.085, 0.038, 18),
aisleMaterial
);
corner.position.set(aislePoints[i].x, 0.085, aislePoints[i].y);
aisleGroup.add(corner);
}
// Direction arrows along the walkable route.
function addArrow(x, z, angle) {
const arrowGeometry = new THREE.BufferGeometry();
arrowGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.11, 0, 0.12,
0.11, 0, 0.12,
0, 0, -0.17
],
3
)
);
arrowGeometry.computeVertexNormals();
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshBasicMaterial({
color: 0xb9ffe0,
side: THREE.DoubleSide,
toneMapped: false
})
);
arrow.position.set(x, 0.125, z);
arrow.rotation.y = angle;
aisleGroup.add(arrow);
}
addArrow(-4.0, 4.0, -Math.PI / 2);
addArrow(-2.0, 0.2, Math.PI);
addArrow(3.0, -4.0, -Math.PI / 2);
// Endpoint pins.
function createEndpoint(color, x, z) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.9,
roughness: 0.35,
metalness: 0.3
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.31, 0.075, 24),
material
);
base.position.y = 0.07;
base.castShadow = true;
group.add(base);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.025, 8, 32),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.8,
toneMapped: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.115;
ring.userData.pulse = true;
group.add(ring);
group.userData.ring = ring;
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.9, 8),
material
);
pin.position.y = 0.55;
group.add(pin);
const top = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 16, 12),
material
);
top.position.y = 1.02;
group.add(top);
group.position.set(x, 0, z);
scene.add(group);
return group;
}
const startEndpoint = createEndpoint(0x59d8ff, start.x, start.y);
const endEndpoint = createEndpoint(0xffbd69, end.x, end.y);
// Moving route markers.
const directMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 18, 14),
new THREE.MeshBasicMaterial({
color: 0xff8ca8,
toneMapped: false
})
);
directMarker.renderOrder = 13;
directGroup.add(directMarker);
const aisleMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.11, 18, 14),
new THREE.MeshBasicMaterial({
color: 0xb8ffe1,
toneMapped: false
})
);
aisleGroup.add(aisleMarker);
// Subtle suspended dust.
const dustPositions = [];
for (let i = 0; i < 140; i++) {
dustPositions.push(
(Math.random() - 0.5) * 15,
1.8 + Math.random() * 5,
(Math.random() - 0.5) * 11
);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x8bb8c7,
size: 0.026,
transparent: true,
opacity: 0.27,
depthWrite: false
})
);
scene.add(dust);
// HTML labels projected from 3D anchors.
const labels = [
{
element: document.getElementById("label-direct"),
position: new THREE.Vector3(0, 2.25, 0),
group: directGroup
},
{
element: document.getElementById("label-aisle"),
position: new THREE.Vector3(-2, 0.48, -0.25),
group: aisleGroup
},
{
element: document.getElementById("label-start"),
position: new THREE.Vector3(start.x, 1.24, start.y),
group: null
},
{
element: document.getElementById("label-end"),
position: new THREE.Vector3(end.x, 1.24, end.y),
group: null
}
];
const projected = new THREE.Vector3();
function updateLabels() {
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
(!label.group || label.group.visible);
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// Manual orbit, zoom, and reset controls.
const canvas = renderer.domElement;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - dy * 0.005,
0.3,
1.35
);
});
function stopDragging(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius * Math.exp(event.deltaY * 0.001),
10.5,
29
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const directButton = document.getElementById("toggle-direct");
const aisleButton = document.getElementById("toggle-aisle");
const motionButton = document.getElementById("toggle-motion");
const resetButton = document.getElementById("reset-view");
function setButtonState(button, active) {
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
directButton.addEventListener("click", () => {
directGroup.visible = !directGroup.visible;
setButtonState(directButton, directGroup.visible);
});
aisleButton.addEventListener("click", () => {
aisleGroup.visible = !aisleGroup.visible;
setButtonState(aisleButton, aisleGroup.visible);
});
motionButton.addEventListener("click", () => {
cameraState.autoOrbit = !cameraState.autoOrbit;
setButtonState(motionButton, cameraState.autoOrbit);
});
resetButton.addEventListener("click", () => {
cameraState.targetTheta = 0.68;
cameraState.targetPhi = 0.79;
cameraState.targetRadius = 18.2;
cameraState.autoOrbit = false;
setButtonState(motionButton, false);
});
// Find a point at a given distance along the orthogonal aisle route.
function pointAlongAisle(distance) {
let remaining = distance;
for (let i = 0; i < aislePoints.length - 1; i++) {
const a = aislePoints[i];
const b = aislePoints[i + 1];
const segmentLength = a.distanceTo(b);
if (remaining <= segmentLength) {
const t = segmentLength === 0 ? 0 : remaining / segmentLength;
return new THREE.Vector3(
THREE.MathUtils.lerp(a.x, b.x, t),
0.18,
THREE.MathUtils.lerp(a.y, b.y, t)
);
}
remaining -= segmentLength;
}
const last = aislePoints[aislePoints.length - 1];
return new THREE.Vector3(last.x, 0.18, last.y);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (cameraState.autoOrbit) {
cameraState.targetTheta += dt * 0.13;
}
updateCamera(dt);
// Animate the direct marker at the same world-space speed.
const directTravel = (elapsed * 2.15) % euclideanDistance;
const directT = directTravel / euclideanDistance;
directMarker.position.lerpVectors(
directStart,
directEnd,
directT
);
directMarker.position.y = 0.17;
// Animate the aisle marker at the same speed.
const aisleTravel = (elapsed * 2.15) % aisleDistance;
aisleMarker.position.copy(pointAlongAisle(aisleTravel));
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.08;
[startEndpoint, endEndpoint].forEach((endpoint, index) => {
const offset = index === 0 ? 0 : Math.PI;
endpoint.userData.ring.scale.setScalar(
pulse + Math.sin(elapsed * 3.2 + offset) * 0.04
);
});
dust.rotation.y = elapsed * 0.012;
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => {
loading.remove();
}, 450);
});
</script>
</body>
</html>
```