Prompt specification
Build or customize the Three.js 3D scene "Storage room packing diorama" 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: Storage room packing diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/storage-room-packing-diorama-x1759
Scene Description Prompt:
Storage room packing diorama. Compose shelves and rectangular containers with labeled internal dimensions; distinguish external box volume, usable interior volume, and actual packed-item volume. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (storage-room-packing-diorama-x1759):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Storage Room Packing Diorama</title>
<style>
:root {
color-scheme: light;
--ink: #17212b;
--muted: #5d6b78;
--paper: rgba(250, 252, 249, 0.93);
--line: rgba(23, 33, 43, 0.12);
--external: #f59e0b;
--usable: #0891b2;
--actual: #16a36a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ece7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.title-block {
position: fixed;
top: 24px;
left: 26px;
z-index: 10;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.eyebrow {
margin-bottom: 7px;
color: #63716e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 39px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin-top: 9px;
color: var(--muted);
font-size: 12px;
font-weight: 600;
letter-spacing: 0.02em;
}
.controls {
position: fixed;
top: 22px;
right: 22px;
z-index: 20;
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(23, 33, 43, 0.13);
border-radius: 11px;
padding: 10px 13px;
color: #26333d;
background: rgba(250, 252, 249, 0.92);
box-shadow: 0 7px 24px rgba(37, 50, 58, 0.09);
font: inherit;
font-size: 11px;
font-weight: 760;
letter-spacing: 0.04em;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
background: #fff;
transform: translateY(-1px);
}
button[aria-pressed="false"] {
color: #7c8790;
background: rgba(235, 239, 235, 0.9);
}
.inspector {
position: fixed;
top: 78px;
right: 22px;
z-index: 10;
width: min(322px, calc(100vw - 44px));
overflow: hidden;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 18px 55px rgba(37, 50, 58, 0.14);
backdrop-filter: blur(16px);
pointer-events: none;
}
.inspector-head {
padding: 18px 19px 15px;
border-bottom: 1px solid var(--line);
}
.inspector-code {
color: #73817f;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.inspector h2 {
margin: 5px 0 0;
font-size: 20px;
letter-spacing: -0.035em;
}
.metrics {
padding: 7px 19px 8px;
}
.metric {
padding: 13px 0 12px;
border-bottom: 1px solid var(--line);
}
.metric:last-child {
border-bottom: 0;
}
.metric-heading {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 760;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 3px;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}
.metric-value {
margin-top: 6px;
font-size: 21px;
font-weight: 780;
letter-spacing: -0.035em;
}
.metric-detail {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 580;
}
.bar-track {
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(23, 33, 43, 0.08);
}
.bar {
height: 100%;
border-radius: inherit;
transition: width 260ms ease;
}
.efficiency {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 14px 19px;
color: #e8fff3;
background: #1b7553;
}
.efficiency span:first-child {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.efficiency strong {
font-size: 21px;
letter-spacing: -0.04em;
}
.inspector-note {
padding: 12px 19px 14px;
border-top: 1px solid var(--line);
color: #697780;
font-size: 10px;
line-height: 1.5;
}
.hint {
position: fixed;
bottom: 20px;
left: 25px;
z-index: 10;
padding: 9px 12px;
border: 1px solid rgba(23, 33, 43, 0.11);
border-radius: 10px;
color: #53616b;
background: rgba(250, 252, 249, 0.84);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
backdrop-filter: blur(12px);
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #53616b;
background: #e8ece7;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title-block {
top: 18px;
left: 18px;
}
.subtitle,
.hint {
display: none;
}
.controls {
top: 88px;
right: 14px;
}
.inspector {
top: 135px;
right: 14px;
width: 278px;
}
.inspector-note {
display: none;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Building voxel storage room…</div>
<header class="title-block">
<div class="eyebrow">Inventory study · unit 04</div>
<h1>Storage Room<br>Packing Diorama</h1>
<div class="subtitle">Visible voxels · clear dimensions · occupied vs. available space</div>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="reset-view" type="button">RESET VIEW</button>
<button id="toggle-guides" type="button" aria-pressed="true">VOLUME GUIDES</button>
</nav>
<aside class="inspector" id="inspector">
<div class="inspector-head">
<div class="inspector-code" id="inspector-code">FEATURE CONTAINER · F-01</div>
<h2 id="inspector-title">Open-top packing bin</h2>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-heading">
<span class="swatch" style="background: var(--external)"></span>
External box volume
</div>
<div class="metric-value" id="external-value">89,600 cm³</div>
<div class="metric-detail" id="external-detail">Outer envelope · 56 × 40 × 40 cm</div>
<div class="bar-track">
<div class="bar" id="external-bar" style="width: 100%; background: var(--external)"></div>
</div>
</div>
<div class="metric">
<div class="metric-heading">
<span class="swatch" style="background: var(--usable)"></span>
Usable interior volume
</div>
<div class="metric-value" id="usable-value">49,152 cm³</div>
<div class="metric-detail" id="usable-detail">Clear internal space · 48 × 32 × 32 cm</div>
<div class="bar-track">
<div class="bar" id="usable-bar" style="width: 54.9%; background: var(--usable)"></div>
</div>
</div>
<div class="metric">
<div class="metric-heading">
<span class="swatch" style="background: var(--actual)"></span>
Actual packed-item volume
</div>
<div class="metric-value" id="actual-value">37,120 cm³</div>
<div class="metric-detail" id="actual-detail">580 × 4 cm voxel items</div>
<div class="bar-track">
<div class="bar" id="actual-bar" style="width: 41.4%; background: var(--actual)"></div>
</div>
</div>
</div>
<div class="efficiency">
<span>Interior utilization</span>
<strong id="efficiency-value">75.5%</strong>
</div>
<div class="inspector-note">
Click another labeled container to inspect it. Internal dimensions describe
clear space between walls; the actual volume counts only packed voxel items.
</div>
</aside>
<div class="hint">
Drag to orbit · right-drag to pan · scroll to zoom · click a bin to inspect
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ece7);
scene.fog = new THREE.Fog(0xe8ece7, 27, 52);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.appendChild(renderer.domElement);
const target = new THREE.Vector3(0.1, 3.25, -0.35);
const initialCameraPosition = new THREE.Vector3(17.2, 11.8, 18.8);
const spherical = new THREE.Spherical().setFromVector3(
initialCameraPosition.clone().sub(target)
);
const cameraOffset = new THREE.Vector3();
function applyCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.22, 1.46);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 10, 36);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(target).add(cameraOffset);
camera.lookAt(target);
camera.updateMatrixWorld();
}
applyCamera();
const hemi = new THREE.HemisphereLight(0xf8fbff, 0x526158, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d4, 3.15);
sun.position.set(-8, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fd9ef, 0.85);
fill.position.set(12, 8, -9);
scene.add(fill);
const frontFill = new THREE.DirectionalLight(0xffffff, 0.45);
frontFill.position.set(1, 5, 14);
scene.add(frontFill);
// One scene unit equals 10 cm.
const CM = 10;
const CELL = 0.4; // 4 cm visible voxel item.
const CELL_VOLUME_CM3 = 4 * 4 * 4;
const COLORS = {
external: 0xf59e0b,
usable: 0x06b6d4,
actual: 0x16a36a,
frame: 0x263b4a,
shelf: 0xa8784f,
wall: 0xdde3dc
};
const interactiveMeshes = [];
const bins = [];
// -------------------------------------------------------------------------
// Utility functions
// -------------------------------------------------------------------------
const formatNumber = new Intl.NumberFormat("en-US");
function formatVolume(value) {
return `${formatNumber.format(Math.round(value))} cm³`;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function hash3(x, y, z, seed = 0) {
let n =
Math.imul(x + 11, 374761393) ^
Math.imul(y + 17, 668265263) ^
Math.imul(z + 23, 2147483647) ^
Math.imul(seed + 29, 1274126177);
n = Math.imul(n ^ (n >>> 13), 1274126177);
return ((n ^ (n >>> 16)) >>> 0) / 4294967295;
}
function makePanelTexture(code, detail, accent = "#4f7cac") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 300;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 1008, 284, 24);
ctx.fillStyle = "rgba(18, 28, 37, 0.92)";
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 8, 8, 20, 284, 10);
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.13)";
ctx.lineWidth = 4;
roundedRect(ctx, 8, 8, 1008, 284, 24);
ctx.stroke();
ctx.textAlign = "left";
ctx.fillStyle = "#ffffff";
ctx.font = "800 68px system-ui, sans-serif";
ctx.fillText(code, 58, 113);
ctx.fillStyle = "#c9d7df";
ctx.font = "650 38px system-ui, sans-serif";
ctx.fillText(detail, 58, 185);
ctx.fillStyle = "#91a5b1";
ctx.font = "700 23px system-ui, sans-serif";
ctx.fillText("INTERNAL CLEAR DIMENSIONS", 58, 245);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeWallTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1200;
canvas.height = 260;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#253943";
ctx.fillRect(0, 0, 1200, 260);
ctx.fillStyle = "#f4b942";
ctx.fillRect(0, 0, 28, 260);
ctx.fillStyle = "#ffffff";
ctx.font = "850 76px system-ui, sans-serif";
ctx.fillText("STORAGE / PACKING LAB", 70, 108);
ctx.fillStyle = "#b9c9d0";
ctx.font = "650 31px system-ui, sans-serif";
ctx.fillText("VOXEL INVENTORY • CLEARANCE & OCCUPANCY", 72, 176);
ctx.fillStyle = "#6f8997";
ctx.fillRect(72, 207, 1050, 4);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeBillboardTexture(title, value, accent) {
const canvas = document.createElement("canvas");
canvas.width = 900;
canvas.height = 340;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 10, 10, 880, 320, 28);
ctx.fillStyle = "rgba(19, 29, 37, 0.94)";
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 10, 10, 16, 320, 8);
ctx.fill();
ctx.textAlign = "center";
ctx.fillStyle = "#d9e5e9";
ctx.font = "800 38px system-ui, sans-serif";
ctx.fillText(title, 450, 94);
ctx.fillStyle = accent;
ctx.font = "850 76px system-ui, sans-serif";
ctx.fillText(value, 450, 207);
ctx.fillStyle = "#8da3af";
ctx.font = "650 25px system-ui, sans-serif";
ctx.fillText("VOLUME LAYER", 450, 272);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeBadgeTexture(text, accent = "#22d3ee") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 624, 164, 24);
ctx.fillStyle = "rgba(10, 48, 62, 0.93)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
roundedRect(ctx, 8, 8, 624, 164, 24);
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#e7fbff";
ctx.font = "800 62px system-ui, sans-serif";
ctx.fillText(text, 320, 91);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeBillboard(title, value, accent, width = 2.75) {
const material = new THREE.SpriteMaterial({
map: makeBillboardTexture(title, value, accent),
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 340 / 900, 1);
sprite.renderOrder = 30;
return sprite;
}
function makeBadge(text, accent, width = 1.35) {
const material = new THREE.SpriteMaterial({
map: makeBadgeTexture(text, accent),
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 180 / 640, 1);
sprite.renderOrder = 30;
return sprite;
}
function addLabelPlane(group, texture, width, height, position) {
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthTest: true,
depthWrite: false,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.position.copy(position);
mesh.renderOrder = 12;
group.add(mesh);
return mesh;
}
function addGridLines(group, width, depth, height, wall, accent) {
const positions = [];
const frontZ = depth / 2 + 0.014;
for (let x = -width / 2 + wall; x <= width / 2 - wall + 0.001; x += CELL) {
positions.push(x, wall, frontZ, x, height - wall, frontZ);
}
for (let y = wall; y <= height - wall + 0.001; y += CELL) {
positions.push(-width / 2 + wall, y, frontZ, width / 2 - wall, y, frontZ);
}
const rightX = width / 2 + 0.014;
for (let z = -depth / 2 + wall; z <= depth / 2 - wall + 0.001; z += CELL) {
positions.push(rightX, wall, z, rightX, height - wall, z);
}
for (let y = wall; y <= height - wall + 0.001; y += CELL) {
positions.push(rightX, y, -depth / 2 + wall, rightX, y, depth / 2 - wall);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.46,
depthWrite: false
});
const lines = new THREE.LineSegments(geometry, material);
lines.renderOrder = 8;
group.add(lines);
}
function addDimension(group, a, b, tick, text, offset, color = 0x22d3ee) {
const points = [
a, b,
a.clone().sub(tick), a.clone().add(tick),
b.clone().sub(tick), b.clone().add(tick)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const lines = new THREE.LineSegments(geometry, material);
lines.renderOrder = 25;
group.add(lines);
const badge = makeBadge(text, "#22d3ee", 1.28);
badge.position.copy(a).add(b).multiplyScalar(0.5).add(offset);
group.add(badge);
}
// -------------------------------------------------------------------------
// Floor and room
// -------------------------------------------------------------------------
const floorGeometry = new THREE.BoxGeometry(0.965, 0.08, 0.965);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0
});
const floorTiles = [];
for (let x = 0; x < 22; x++) {
for (let z = 0; z < 16; z++) {
floorTiles.push({
x: -11 + x + 0.5,
z: -7.5 + z + 0.5,
shade: hash3(x, z, 2)
});
}
}
const floorMesh = new THREE.InstancedMesh(
floorGeometry,
floorMaterial,
floorTiles.length
);
const floorMatrix = new THREE.Matrix4();
const floorColor = new THREE.Color();
floorTiles.forEach((tile, index) => {
floorMatrix.makeTranslation(tile.x, 0, tile.z);
floorMesh.setMatrixAt(index, floorMatrix);
const c = new THREE.Color(0xcbd2c8).lerp(
new THREE.Color(0xe2e5dc),
tile.shade
);
floorMesh.setColorAt(index, c);
});
floorMesh.instanceMatrix.needsUpdate = true;
floorMesh.instanceColor.needsUpdate = true;
floorMesh.receiveShadow = true;
scene.add(floorMesh);
const wallMaterial = new THREE.MeshStandardMaterial({
color: COLORS.wall,
roughness: 0.95
});
const backWall = new THREE.Mesh(
new THREE.BoxGeometry(22.2, 11.5, 0.28),
wallMaterial
);
backWall.position.set(0, 5.65, -7.65);
backWall.receiveShadow = true;
scene.add(backWall);
const leftWall = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 11.5, 16),
wallMaterial
);
leftWall.position.set(-11.05, 5.65, 0.25);
leftWall.receiveShadow = true;
scene.add(leftWall);
const seamPositions = [];
for (let x = -10; x <= 10; x += 2) {
seamPositions.push(x, 0, -7.48, x, 11.4, -7.48);
}
for (let y = 2; y <= 10; y += 2) {
seamPositions.push(-11, y, -7.48, 11, y, -7.48);
}
const seamGeometry = new THREE.BufferGeometry();
seamGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(seamPositions, 3)
);
scene.add(
new THREE.LineSegments(
seamGeometry,
new THREE.LineBasicMaterial({
color: 0xc2cbc2,
transparent: true,
opacity: 0.55
})
)
);
const wallSign = new THREE.Mesh(
new THREE.PlaneGeometry(6.8, 1.48),
new THREE.MeshBasicMaterial({
map: makeWallTexture(),
toneMapped: false
})
);
wallSign.position.set(-6.15, 9.35, -7.47);
scene.add(wallSign);
// -------------------------------------------------------------------------
// Shelf rack
// -------------------------------------------------------------------------
const rack = new THREE.Group();
scene.add(rack);
const frameMaterial = new THREE.MeshStandardMaterial({
color: COLORS.frame,
roughness: 0.58,
metalness: 0.24
});
const shelfMaterials = [
new THREE.MeshStandardMaterial({ color: 0xa8784f, roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: 0xb78659, roughness: 0.78 })
];
const rackX = 1.8;
const rackZ = -4.65;
const shelfYs = [0.65, 4.0, 7.35];
const postXs = [-5.6, 1.8, 9.2];
const postZs = [-6.05, -3.25];
postXs.forEach((x) => {
postZs.forEach((z) => {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 10.45, 0.28),
frameMaterial
);
post.position.set(x, 5.22, z);
post.castShadow = true;
post.receiveShadow = true;
rack.add(post);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.66, 0.14, 0.66),
frameMaterial
);
foot.position.set(x, 0.07, z);
foot.castShadow = true;
rack.add(foot);
});
});
shelfYs.forEach((shelfY, shelfIndex) => {
for (let slat = 0; slat < 7; slat++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(2.08, 0.24, 3.4),
shelfMaterials[slat % 2]
);
plank.position.set(
rackX - 7.44 + slat * 2.12 + 1.04,
shelfY,
rackZ
);
plank.castShadow = true;
plank.receiveShadow = true;
rack.add(plank);
}
const frontBeam = new THREE.Mesh(
new THREE.BoxGeometry(15.25, 0.34, 0.22),
frameMaterial
);
frontBeam.position.set(rackX, shelfY - 0.04, rackZ + 1.75);
frontBeam.castShadow = true;
rack.add(frontBeam);
const tagTexture = makePanelTexture(
`S-${String(shelfIndex + 1).padStart(2, "0")}`,
"STORAGE BAY",
"#f2b84b"
);
const tag = new THREE.Mesh(
new THREE.PlaneGeometry(1.25, 0.36),
new THREE.MeshBasicMaterial({
map: tagTexture,
transparent: true,
toneMapped: false
})
);
tag.position.set(-5.25, shelfY - 0.04, rackZ + 1.87);
tag.renderOrder = 12;
rack.add(tag);
});
// -------------------------------------------------------------------------
// Voxel container construction
// -------------------------------------------------------------------------
const contentGeometry = new THREE.BoxGeometry(
CELL * 0.91,
CELL * 0.91,
CELL * 0.91
);
const contentMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.8,
metalness: 0.015
});
function createBin({
code,
title,
outer,
position,
shellColor,
palette,
fillRatio = 0.65,
seed = 1,
feature = false
}) {
const [width, depth, height] = outer;
const wall = 0.4;
const innerWidth = width - wall * 2;
const innerDepth = depth - wall * 2;
const innerHeight = height - wall * 2;
const group = new THREE.Group();
group.position.copy(position);
const bin = {
code,
title,
group,
outer: [width, depth, height],
inner: [innerWidth, innerDepth, innerHeight],
count: 0,
actualVolume: 0,
guides: null
};
const shellMaterial = new THREE.MeshStandardMaterial({
color: shellColor,
transparent: true,
opacity: feature ? 0.2 : 0.34,
roughness: 0.62,
metalness: 0.04,
depthWrite: false,
side: THREE.DoubleSide
});
const rimMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(shellColor).multiplyScalar(0.72),
roughness: 0.56,
metalness: 0.12
});
function addPanel(size, panelPosition, material = shellMaterial) {
const panel = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
panel.position.copy(panelPosition);
panel.castShadow = true;
panel.receiveShadow = true;
panel.renderOrder = 3;
panel.userData.bin = bin;
group.add(panel);
interactiveMeshes.push(panel);
return panel;
}
addPanel([width, wall, depth], new THREE.Vector3(0, wall / 2, 0));
addPanel(
[width, height, wall],
new THREE.Vector3(0, height / 2, depth / 2 - wall / 2)
);
addPanel(
[width, height, wall],
new THREE.Vector3(0, height / 2, -depth / 2 + wall / 2)
);
addPanel(
[wall, height, depth - wall * 2],
new THREE.Vector3(-width / 2 + wall / 2, height / 2, 0)
);
addPanel(
[wall, height, depth - wall * 2],
new THREE.Vector3(width / 2 - wall / 2, height / 2, 0)
);
// Reinforced top rim.
addPanel(
[width + 0.08, 0.17, 0.18],
new THREE.Vector3(0, height - 0.02, depth / 2 - 0.08),
rimMaterial
);
addPanel(
[width + 0.08, 0.17, 0.18],
new THREE.Vector3(0, height - 0.02, -depth / 2 + 0.08),
rimMaterial
);
addPanel(
[0.18, 0.17, depth],
new THREE.Vector3(-width / 2 + 0.08, height - 0.02, 0),
rimMaterial
);
addPanel(
[0.18, 0.17, depth],
new THREE.Vector3(width / 2 - 0.08, height - 0.02, 0),
rimMaterial
);
const gridAccent = new THREE.Color(shellColor).lerp(
new THREE.Color(0xffffff),
0.55
);
addGridLines(
group,
width,
depth,
height,
wall,
gridAccent
);
// Internal-dimension label on the front of every container.
const internalCM = [
Math.round(innerWidth * CM),
Math.round(innerDepth * CM),
Math.round(innerHeight * CM)
];
const labelTexture = makePanelTexture(
code,
`INTERNAL ${internalCM[0]} × ${internalCM[1]} × ${internalCM[2]} cm`,
`#${new THREE.Color(shellColor).getHexString()}`
);
const labelWidth = Math.min(innerWidth * 0.78, 3.35);
const label = addLabelPlane(
group,
labelTexture,
labelWidth,
labelWidth * 300 / 1024,
new THREE.Vector3(0, wall + innerHeight * 0.53, depth / 2 + 0.055)
);
label.userData.bin = bin;
interactiveMeshes.push(label);
// Build a voxel occupancy grid.
const nx = Math.round(innerWidth / CELL);
const ny = Math.round(innerHeight / CELL);
const nz = Math.round(innerDepth / CELL);
const cells = [];
if (feature) {
const candidates = [];
for (let iy = 0; iy < ny; iy++) {
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const lowerFullLayers = iy < 6;
const upperPartialLayer = iy === 6 && ix < 9 && iz < 6;
if (lowerFullLayers || upperPartialLayer) {
candidates.push({ ix, iy, iz });
}
}
}
}
// Remove exactly 50 cells, distributed by a deterministic score.
candidates.sort(
(a, b) =>
hash3(a.ix, a.iy, a.iz, 91) -
hash3(b.ix, b.iy, b.iz, 91)
);
const removed = new Set(
candidates.slice(0, 50).map((c) => `${c.ix},${c.iy},${c.iz}`)
);
candidates.forEach((c) => {
const key = `${c.ix},${c.iy},${c.iz}`;
if (!removed.has(key)) cells.push(c);
});
} else {
const targetLayers = Math.max(1, Math.floor(ny * fillRatio));
for (let iy = 0; iy < ny; iy++) {
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const score = hash3(ix, iy, iz, seed);
const core = iy < targetLayers && score > 0.025;
const top = iy === targetLayers && score < 0.18;
if (core || top) cells.push({ ix, iy, iz });
}
}
}
}
const content = new THREE.InstancedMesh(
contentGeometry,
contentMaterial,
cells.length
);
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
cells.forEach((cell, index) => {
const x = -innerWidth / 2 + CELL / 2 + cell.ix * CELL;
const y = wall + CELL / 2 + cell.iy * CELL;
const z = -innerDepth / 2 + CELL / 2 + cell.iz * CELL;
matrix.makeTranslation(x, y, z);
content.setMatrixAt(index, matrix);
const region =
(cell.ix > nx * 0.54 ? 1 : 0) +
(cell.iy > ny * 0.52 ? 2 : 0) +
(cell.iz > nz * 0.54 ? 4 : 0);
color.setHex(palette[region % palette.length]);
color.offsetHSL(
0,
0,
(hash3(cell.ix, cell.iy, cell.iz, seed + 11) - 0.5) * 0.055
);
content.setColorAt(index, color);
});
content.instanceMatrix.needsUpdate = true;
content.instanceColor.needsUpdate = true;
content.castShadow = true;
content.receiveShadow = true;
content.computeBoundingSphere();
group.add(content);
bin.count = cells.length;
bin.actualVolume = cells.length * CELL_VOLUME_CM3;
if (feature) {
createVolumeGuides(bin);
}
scene.add(group);
bins.push(bin);
return bin;
}
function createVolumeGuides(bin) {
const [width, depth, height] = bin.outer;
const [innerWidth, innerDepth, innerHeight] = bin.inner;
const wall = 0.4;
const guideGroup = new THREE.Group();
bin.group.add(guideGroup);
const outerMaterial = new THREE.MeshBasicMaterial({
color: COLORS.external,
transparent: true,
opacity: 0.035,
depthWrite: false,
side: THREE.DoubleSide
});
const outerEnvelope = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
outerMaterial
);
outerEnvelope.position.y = height / 2;
outerEnvelope.renderOrder = 2;
guideGroup.add(outerEnvelope);
const outerEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(outerEnvelope.geometry),
new THREE.LineBasicMaterial({
color: COLORS.external,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
outerEdges.position.copy(outerEnvelope.position);
outerEdges.renderOrder = 20;
guideGroup.add(outerEdges);
const innerMaterial = new THREE.MeshBasicMaterial({
color: COLORS.usable,
transparent: true,
opacity: 0.065,
depthWrite: false,
side: THREE.DoubleSide
});
const innerEnvelope = new THREE.Mesh(
new THREE.BoxGeometry(innerWidth, innerHeight, innerDepth),
innerMaterial
);
innerEnvelope.position.y = wall + innerHeight / 2;
innerEnvelope.renderOrder = 4;
guideGroup.add(innerEnvelope);
const innerEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(innerEnvelope.geometry),
new THREE.LineBasicMaterial({
color: COLORS.usable,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
innerEdges.position.copy(innerEnvelope.position);
innerEdges.renderOrder = 21;
guideGroup.add(innerEdges);
const externalVolume = width * depth * height * CM ** 3;
const usableVolume = innerWidth * innerDepth * innerHeight * CM ** 3;
const outerLabel = makeBillboard(
"EXTERNAL BOX",
formatVolume(externalVolume),
"#fbbf24",
2.8
);
outerLabel.position.set(width / 2 + 0.75, height + 0.7, 0.2);
guideGroup.add(outerLabel);
const usableLabel = makeBillboard(
"USABLE INTERIOR",
formatVolume(usableVolume),
"#22d3ee",
2.9
);
usableLabel.position.set(-width / 2 - 0.75, height * 0.52, depth / 2 + 0.25);
guideGroup.add(usableLabel);
const actualLabel = makeBillboard(
"ACTUAL PACKED ITEMS",
formatVolume(bin.actualVolume),
"#4ade80",
3.15
);
actualLabel.position.set(0.15, height + 0.05, depth / 2 + 0.95);
guideGroup.add(actualLabel);
function addCallout(targetPoint, labelObject, color) {
const geometry = new THREE.BufferGeometry().setFromPoints([
targetPoint,
labelObject.position
]);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.7,
depthTest: false
})
);
line.renderOrder = 18;
guideGroup.add(line);
}
addCallout(
new THREE.Vector3(width / 2, height * 0.55, 0),
outerLabel,
COLORS.external
);
addCallout(
new THREE.Vector3(0, wall + innerHeight * 0.5, 0),
usableLabel,
COLORS.usable
);
addCallout(
new THREE.Vector3(0, wall + innerHeight * 0.72, 0),
actualLabel,
COLORS.actual
);
// Internal dimensions of the featured container.
const cyan = 0x22d3ee;
addDimension(
guideGroup,
new THREE.Vector3(-innerWidth / 2, wall + 0.09, innerDepth / 2 + 0.28),
new THREE.Vector3(innerWidth / 2, wall + 0.09, innerDepth / 2 + 0.28),
new THREE.Vector3(0, 0.13, 0),
`${Math.round(innerWidth * CM)} cm`,
new THREE.Vector3(0, -0.34, 0),
cyan
);
addDimension(
guideGroup,
new THREE.Vector3(-innerWidth / 2 - 0.28, wall + 0.09, -innerDepth / 2),
new THREE.Vector3(-innerWidth / 2 - 0.28, wall + 0.09, innerDepth / 2),
new THREE.Vector3(0, 0.13, 0),
`${Math.round(innerDepth * CM)} cm`,
new THREE.Vector3(-0.38, 0, 0),
cyan
);
addDimension(
guideGroup,
new THREE.Vector3(innerWidth / 2 + 0.28, wall, innerDepth / 2 + 0.22),
new THREE.Vector3(innerWidth / 2 + 0.28, wall + innerHeight, innerDepth / 2 + 0.22),
new THREE.Vector3(0.13, 0, 0),
`${Math.round(innerHeight * CM)} cm`,
new THREE.Vector3(0.42, 0, 0),
cyan
);
bin.guides = guideGroup;
}
// -------------------------------------------------------------------------
// Featured foreground container
// -------------------------------------------------------------------------
const featureBin = createBin({
code: "F-01",
title: "Open-top packing bin",
outer: [5.6, 4.0, 4.0],
position: new THREE.Vector3(-3.8, 0.08, 3.05),
shellColor: 0x617b8c,
palette: [
0x3f8f6b,
0x55a982,
0xd0a64b,
0x4d87b5,
0xb96f50,
0x89bb72
],
seed: 42,
feature: true
});
// Packing-test boundary.
const zonePoints = [
new THREE.Vector3(-6.95, 0.13, 0.68),
new THREE.Vector3(-0.65, 0.13, 0.68),
new THREE.Vector3(-0.65, 0.13, 5.42),
new THREE.Vector3(-6.95, 0.13, 5.42),
new THREE.Vector3(-6.95, 0.13, 0.68)
];
const zoneLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(zonePoints),
new THREE.LineDashedMaterial({
color: COLORS.external,
dashSize: 0.28,
gapSize: 0.18,
transparent: true,
opacity: 0.8
})
);
zoneLine.computeLineDistances();
scene.add(zoneLine);
const floorLabelCanvas = document.createElement("canvas");
floorLabelCanvas.width = 900;
floorLabelCanvas.height = 220;
const floorLabelContext = floorLabelCanvas.getContext("2d");
floorLabelContext.clearRect(0, 0, 900, 220);
floorLabelContext.fillStyle = "rgba(245,158,11,0.88)";
floorLabelContext.font = "850 72px system-ui, sans-serif";
floorLabelContext.textAlign = "center";
floorLabelContext.fillText("PACK TEST ZONE", 450, 130);
const floorLabelTexture = new THREE.CanvasTexture(floorLabelCanvas);
floorLabelTexture.colorSpace = THREE.SRGBColorSpace;
const floorLabel = new THREE.Mesh(
new THREE.PlaneGeometry(3.65, 0.89),
new THREE.MeshBasicMaterial({
map: floorLabelTexture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
floorLabel.rotation.x = -Math.PI / 2;
floorLabel.position.set(-3.8, 0.135, 5.95);
scene.add(floorLabel);
// -------------------------------------------------------------------------
// Shelf containers
// -------------------------------------------------------------------------
const shelfBins = [
{
code: "A-01",
title: "Blue utility tote",
outer: [4.0, 3.2, 3.2],
x: -2.8,
color: 0x4f7cac,
palette: [0x4f7cac, 0x6998bd, 0xd5a04d, 0x6c9875]
},
{
code: "A-02",
title: "Wide parts tote",
outer: [4.8, 3.2, 3.2],
x: 1.8,
color: 0x4d8b73,
palette: [0x4d8b73, 0x71aa8d, 0x567fa0, 0xc79b53]
},
{
code: "A-03",
title: "Small stock tote",
outer: [4.0, 3.2, 3.2],
x: 6.5,
color: 0xb6764e,
palette: [0xb6764e, 0xd39a6e, 0x688f6c, 0x5e82a4]
},
{
code: "B-01",
title: "Blue utility tote",
outer: [4.0, 3.2, 3.2],
x: -2.8,
color: 0x667eae,
palette: [0x667eae, 0x839bc3, 0xb59b52, 0x669475]
},
{
code: "B-02",
title: "Green hardware tote",
outer: [4.8, 3.2, 3.2],
x: 1.8,
color: 0x548a78,
palette: [0x548a78, 0x79aa96, 0x647fa2, 0xc29651]
},
{
code: "B-03",
title: "Orange parts tote",
outer: [4.0, 3.2, 3.2],
x: 6.5,
color: 0xb66d46,
palette: [0xb66d46, 0xd18b60, 0x5b9272, 0x607ea0]
},
{
code: "C-01",
title: "Wide upper tote",
outer: [4.8, 3.2, 4.0],
x: -0.8,
color: 0x607f9e,
palette: [0x607f9e, 0x7e9bbb, 0x5f967a, 0xc49b50]
},
{
code: "C-02",
title: "Upper stock tote",
outer: [4.0, 3.2, 3.2],
x: 4.8,
color: 0x7b7652,
palette: [0x7b7652, 0x9a9569, 0x638d73, 0x6686a6]
}
];
shelfBins.forEach((definition, index) => {
const level = index < 3 ? 0 : index < 6 ? 1 : 2;
const shelfTop = shelfYs[level] + 0.13;
createBin({
code: definition.code,
title: definition.title,
outer: definition.outer,
position: new THREE.Vector3(
definition.x,
shelfTop,
rackZ + 0.02
),
shellColor: definition.color,
palette: definition.palette,
fillRatio: 0.57 + (index % 4) * 0.045,
seed: 100 + index * 17
});
});
// -------------------------------------------------------------------------
// Inspector
// -------------------------------------------------------------------------
const inspector = {
code: document.getElementById("inspector-code"),
title: document.getElementById("inspector-title"),
externalValue: document.getElementById("external-value"),
externalDetail: document.getElementById("external-detail"),
externalBar: document.getElementById("external-bar"),
usableValue: document.getElementById("usable-value"),
usableDetail: document.getElementById("usable-detail"),
usableBar: document.getElementById("usable-bar"),
actualValue: document.getElementById("actual-value"),
actualDetail: document.getElementById("actual-detail"),
actualBar: document.getElementById("actual-bar"),
efficiency: document.getElementById("efficiency-value")
};
function updateInspector(bin) {
const [w, d, h] = bin.outer;
const [iw, id, ih] = bin.inner;
const externalVolume = w * d * h * CM ** 3;
const usableVolume = iw * id * ih * CM ** 3;
const actualVolume = bin.actualVolume;
const efficiency = (actualVolume / usableVolume) * 100;
inspector.code.textContent =
bin === featureBin ? "FEATURE CONTAINER · F-01" : `STORAGE CONTAINER · ${bin.code}`;
inspector.title.textContent = bin.title;
inspector.externalValue.textContent = formatVolume(externalVolume);
inspector.externalDetail.textContent =
`Outer envelope · ${Math.round(w * CM)} × ${Math.round(d * CM)} × ${Math.round(h * CM)} cm`;
inspector.usableValue.textContent = formatVolume(usableVolume);
inspector.usableDetail.textContent =
`Clear internal space · ${Math.round(iw * CM)} × ${Math.round(id * CM)} × ${Math.round(ih * CM)} cm`;
inspector.actualValue.textContent = formatVolume(actualVolume);
inspector.actualDetail.textContent =
`${bin.count} × 4 cm voxel items`;
inspector.externalBar.style.width = "100%";
inspector.usableBar.style.width =
`${Math.min(100, (usableVolume / externalVolume) * 100)}%`;
inspector.actualBar.style.width =
`${Math.min(100, (actualVolume / externalVolume) * 100)}%`;
inspector.efficiency.textContent = `${efficiency.toFixed(1)}%`;
}
updateInspector(featureBin);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch
// -------------------------------------------------------------------------
const pointers = new Map();
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
let gestureDistance = 0;
let gestureMidpoint = null;
const canvas = renderer.domElement;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function pointerMidpoint() {
const values = [...pointers.values()];
if (values.length < 2) return null;
return {
x: (values[0].x + values[1].x) / 2,
y: (values[0].y + values[1].y) / 2
};
}
function panCamera(dx, dy) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const factor = spherical.radius * 0.00155;
target.addScaledVector(right, -dx * factor);
target.addScaledVector(up, dy * factor);
target.x = THREE.MathUtils.clamp(target.x, -8, 9);
target.y = THREE.MathUtils.clamp(target.y, 0.8, 7.2);
target.z = THREE.MathUtils.clamp(target.z, -7, 6);
}
function pickBin(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (hits.length) {
const bin = hits[0].object.userData.bin;
if (bin) {
updateInspector(bin);
return;
}
}
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
gestureDistance = 0;
if (pointers.size === 2) {
gestureMidpoint = pointerMidpoint();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) {
if (event.pointerType === "mouse" && event.buttons === 0) {
pickBin(event.clientX, event.clientY);
}
return;
}
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
gestureDistance += Math.hypot(dx, dy);
if (pointers.size === 1) {
if (previous.button === 2) {
panCamera(dx, dy);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.0055;
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
const midpoint = pointerMidpoint();
if (gestureMidpoint && distance > 0) {
spherical.radius *= gestureDistance / distance;
panCamera(
midpoint.x - gestureMidpoint.x,
midpoint.y - gestureMidpoint.y
);
}
gestureDistance = distance;
gestureMidpoint = midpoint;
}
applyCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (gestureDistance < 7 && event.button !== 2) {
pickBin(event.clientX, event.clientY);
}
pointers.delete(event.pointerId);
if (pointers.size < 2) {
gestureDistance = 0;
gestureMidpoint = null;
}
});
canvas.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
gestureMidpoint = null;
gestureDistance = 0;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
applyCamera();
},
{ passive: false }
);
document.getElementById("reset-view").addEventListener("click", () => {
target.set(0.1, 3.25, -0.35);
spherical.setFromVector3(initialCameraPosition.clone().sub(target));
applyCamera();
});
const guideButton = document.getElementById("toggle-guides");
guideButton.addEventListener("click", () => {
const visible = !featureBin.guides.visible;
featureBin.guides.visible = visible;
guideButton.setAttribute("aria-pressed", String(visible));
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.getElementById("loading")?.remove();
});
</script>
</body>
</html>
```