Prompt specification
Build or customize the Three.js 3D scene "Shelf-facing depth model" 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: Shelf-facing depth model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shelf-facing-depth-model-x0533
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing shop shelf facings and reserve stock. Model a shop shelf with three rows of identical boxes and a rear stock crate; distinguish visible front facings from the total number stored behind them. Voxel style.
Working Three.js Starter (shelf-facing-depth-model-x0533):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shop Shelf Facings & Reserve Stock</title>
<style>
:root {
--ink: #203235;
--muted: #667476;
--paper: #f4efe4;
--teal: #249b89;
--teal-soft: #d6eee8;
--orange: #e87545;
--orange-soft: #f5dfd2;
--line: rgba(32, 50, 53, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4da;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title-card {
top: 22px;
left: 22px;
max-width: 360px;
}
.eyebrow {
display: inline-block;
margin-bottom: 8px;
padding: 5px 8px;
border: 1px solid var(--line);
background: rgba(244, 239, 228, 0.82);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 43px);
line-height: 0.98;
letter-spacing: -0.07em;
text-transform: uppercase;
}
.subtitle {
max-width: 340px;
margin: 12px 0 0;
color: #4f6062;
font-size: 12px;
line-height: 1.55;
}
.inventory-card {
top: 22px;
right: 22px;
width: 286px;
padding: 16px;
border: 1px solid var(--line);
background: rgba(244, 239, 228, 0.93);
box-shadow: 0 14px 35px rgba(39, 49, 48, 0.11);
}
.inventory-card h2 {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 13px;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.inventory-card h2::after {
content: "LIVE COUNT";
padding: 3px 5px;
background: var(--ink);
color: var(--paper);
font-size: 8px;
letter-spacing: 0.08em;
}
.stat {
display: grid;
grid-template-columns: 62px 1fr;
align-items: center;
min-height: 58px;
padding: 9px 0;
border-top: 1px solid var(--line);
}
.stat-number {
font-size: 31px;
font-weight: 900;
line-height: 1;
letter-spacing: -0.08em;
}
.stat-copy {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
.stat-copy small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 500;
letter-spacing: 0;
}
.stat.facings .stat-number {
color: var(--teal);
}
.stat.reserve .stat-number {
color: var(--orange);
}
.stat.total {
padding-bottom: 1px;
}
.stat.total .stat-number {
color: var(--ink);
}
.inventory-note {
margin: 10px 0 0;
padding: 10px;
border-left: 4px solid var(--orange);
background: var(--orange-soft);
font-size: 10px;
line-height: 1.45;
}
.controls {
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: 430px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(32, 50, 53, 0.3);
border-radius: 0;
padding: 10px 12px;
background: rgba(244, 239, 228, 0.94);
color: var(--ink);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition:
background 120ms ease,
color 120ms ease,
transform 120ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffdf7;
}
button:focus-visible {
outline: 3px solid rgba(36, 155, 137, 0.4);
outline-offset: 2px;
}
button.active {
border-color: var(--ink);
background: var(--ink);
color: var(--paper);
}
#reveal-button[aria-pressed="true"] {
border-color: var(--orange);
background: var(--orange);
color: #fffaf2;
}
.legend {
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 15px;
padding: 10px 12px;
border: 1px solid var(--line);
background: rgba(244, 239, 228, 0.9);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 12px;
height: 12px;
border: 1px solid rgba(32, 50, 53, 0.28);
}
.swatch.front {
background: var(--teal);
}
.swatch.back {
background: var(--orange);
}
.hint {
margin-left: 4px;
color: var(--muted);
font-weight: 500;
text-transform: none;
}
.scene-label {
position: fixed;
z-index: 8;
top: 0;
left: 0;
min-width: 145px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.22);
background: rgba(32, 50, 53, 0.9);
color: #fff9ed;
box-shadow: 0 8px 20px rgba(32, 50, 53, 0.17);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 21px;
background: rgba(32, 50, 53, 0.62);
}
.scene-label strong {
color: #7ee0ce;
font-size: 15px;
letter-spacing: -0.03em;
}
.scene-label.reserve strong {
color: #ffad87;
}
.scene-label small {
display: block;
margin-top: 2px;
color: rgba(255, 249, 237, 0.67);
font-size: 8px;
font-weight: 500;
letter-spacing: 0.03em;
}
#error-message {
position: fixed;
inset: 0;
z-index: 100;
display: none;
place-items: center;
padding: 30px;
background: #e9e4da;
color: var(--ink);
text-align: center;
}
@media (max-width: 760px) {
.title-card {
top: 14px;
left: 14px;
max-width: 245px;
}
.subtitle {
display: none;
}
.inventory-card {
top: 14px;
right: 14px;
width: 210px;
padding: 11px;
}
.inventory-card h2,
.inventory-note {
display: none;
}
.stat {
grid-template-columns: 48px 1fr;
min-height: 43px;
}
.stat-number {
font-size: 25px;
}
.stat-copy {
font-size: 9px;
}
.stat-copy small {
display: none;
}
.legend {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 28px);
}
.hint {
display: none;
}
.controls {
right: 14px;
bottom: 65px;
max-width: 240px;
}
button {
padding: 9px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel shop shelf inventory model"></div>
<header class="hud title-card">
<div class="eyebrow">Retail inventory / voxel study</div>
<h1>Shelf &<br>Reserve</h1>
<p class="subtitle">
Fifteen display units face the aisle. Eleven matching units remain
in the open stock crate directly behind the shelf.
</p>
</header>
<aside class="hud inventory-card" aria-label="Inventory summary">
<h2>Inventory split</h2>
<div class="stat facings">
<div class="stat-number">15</div>
<div class="stat-copy">
Visible front facings
<small>3 shelf rows × 5 boxes</small>
</div>
</div>
<div class="stat reserve">
<div class="stat-number">11</div>
<div class="stat-copy">
Units in rear reserve
<small>Stored in the orange crate</small>
</div>
</div>
<div class="stat total">
<div class="stat-number">26</div>
<div class="stat-copy">
Total units on hand
<small>Facings + reserve stock</small>
</div>
</div>
<p class="inventory-note">
The aisle-facing count is not the full stock count. The rear crate
contains the reserve inventory.
</p>
</aside>
<div id="facing-label" class="scene-label">
<strong>15</strong> front facings
<small>3 rows on the aisle shelf</small>
</div>
<div id="reserve-label" class="scene-label reserve">
<strong>11</strong> reserve units
<small>Open crate behind the shelf</small>
</div>
<nav class="hud controls" aria-label="Model controls">
<button type="button" data-view="overview" class="active">Overview</button>
<button type="button" data-view="front">Shelf front</button>
<button type="button" data-view="reserve">Reserve crate</button>
<button type="button" id="reveal-button" aria-pressed="false">
Reveal reserve
</button>
</nav>
<div class="hud legend">
<span class="legend-item">
<span class="swatch front"></span>
Display facings
</span>
<span class="legend-item">
<span class="swatch back"></span>
Rear reserve
</span>
<span class="hint">Drag to orbit · wheel to zoom</span>
</div>
<div id="error-message">
<div>
<h1>Unable to start WebGL</h1>
<p>Please open this file in a browser with WebGL enabled.</p>
</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 stage = document.querySelector("#stage");
const errorMessage = document.querySelector("#error-message");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
errorMessage.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4da);
scene.fog = new THREE.Fog(0xe9e4da, 24, 42);
const camera = new THREE.OrthographicCamera(-8, 8, 5.3, -5.3, 0.1, 80);
const hemisphere = new THREE.HemisphereLight(0xfff7e6, 0x7c8b83, 2.05);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d6, 3.25);
keyLight.position.set(9, 15, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e7df, 1.05);
fillLight.position.set(-8, 7, 3);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffb98e, 0.7);
rimLight.position.set(5, 5, -10);
scene.add(rimLight);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
...options
});
}
const materials = {
floor: standardMaterial(0xd8d1c5),
frame: standardMaterial(0x293b3e),
plank: standardMaterial(0xe8decc),
frontAccent: standardMaterial(0xef704d),
crate: standardMaterial(0xb46d42),
crateDark: standardMaterial(0x75452f),
facingBox: standardMaterial(0x249b89),
reserveBox: standardMaterial(0x249b89),
facingTape: standardMaterial(0xf6e8c9),
reserveTape: standardMaterial(0xf6e8c9),
labelBacking: standardMaterial(0x1f4b46)
};
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
const productTexture = makeCanvasTexture(256, 200, (ctx, width, height) => {
ctx.fillStyle = "#fbf3df";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = "#ef704d";
ctx.fillRect(0, 0, width, 22);
ctx.strokeStyle = "#244d47";
ctx.lineWidth = 10;
ctx.strokeRect(5, 5, width - 10, height - 10);
ctx.fillStyle = "#203b38";
ctx.font = "900 49px monospace";
ctx.textAlign = "center";
ctx.fillText("OAT+", width / 2, 94);
ctx.fillStyle = "#ef704d";
ctx.fillRect(35, 112, width - 70, 7);
ctx.fillStyle = "#425c58";
ctx.font = "700 18px monospace";
ctx.fillText("12 PACK", width / 2, 145);
ctx.font = "600 12px monospace";
ctx.fillText("100% / OAT", width / 2, 171);
});
const signTexture = makeCanvasTexture(1024, 180, (ctx, width, height) => {
ctx.fillStyle = "#203b38";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = "#ef704d";
ctx.fillRect(0, 0, 30, height);
ctx.fillStyle = "#fbf3df";
ctx.font = "900 70px monospace";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText("OAT BLOCKS", 70, 78);
ctx.fillStyle = "#7ee0ce";
ctx.font = "700 27px monospace";
ctx.textAlign = "right";
ctx.fillText("12 PACK", width - 45, 80);
});
const reservePlaqueTexture = makeCanvasTexture(1024, 100, (ctx, width, height) => {
ctx.fillStyle = "#ef704d";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = "#fff8e9";
ctx.font = "900 44px monospace";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText("RESERVE STOCK", 35, 49);
ctx.fillStyle = "#203b38";
ctx.font = "900 48px monospace";
ctx.textAlign = "right";
ctx.fillText("11", width - 35, 49);
});
const productLabelMaterial = new THREE.MeshBasicMaterial({
map: productTexture,
transparent: true
});
const reserveLabelMaterial = new THREE.MeshBasicMaterial({
map: productTexture,
transparent: true
});
const productLabelGeometry = new THREE.PlaneGeometry(0.84, 0.656);
const productBodyGeometry = new THREE.BoxGeometry(1.12, 1.04, 1.18);
const productTapeGeometry = new THREE.BoxGeometry(0.17, 0.018, 1.08);
function addMesh(parent, geometry, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addProductBox(parent, x, y, z, reserve = false) {
const bodyMaterial = reserve
? materials.reserveBox
: materials.facingBox;
const tapeMaterial = reserve
? materials.reserveTape
: materials.facingTape;
const labelMaterial = reserve
? reserveLabelMaterial
: productLabelMaterial;
addMesh(
parent,
productBodyGeometry,
bodyMaterial,
x,
y,
z
);
addMesh(
parent,
productTapeGeometry,
tapeMaterial,
x,
y + 0.529,
z,
false
);
const label = new THREE.Mesh(productLabelGeometry, labelMaterial);
label.position.set(x, y + 0.005, z + 0.596);
parent.add(label);
}
// Floor and a subtle voxel-like tile grid.
const floor = addMesh(
scene,
new THREE.BoxGeometry(30, 0.12, 30),
materials.floor,
0,
-0.07,
0,
false
);
floor.receiveShadow = true;
const grid = new THREE.GridHelper(30, 30, 0x8c9994, 0x8c9994);
grid.position.y = 0.001;
grid.material.transparent = true;
grid.material.opacity = 0.13;
scene.add(grid);
// Main display shelf.
const shelf = new THREE.Group();
shelf.position.x = -2;
scene.add(shelf);
addMesh(
shelf,
new THREE.BoxGeometry(8.65, 0.18, 2.18),
materials.plank,
0,
0.13,
0
);
const postGeometry = new THREE.BoxGeometry(0.2, 4.55, 0.2);
const shelfLevels = [0.45, 1.88, 3.31];
const shelfPlankGeometry = new THREE.BoxGeometry(8.4, 0.18, 2.0);
const frontRailGeometry = new THREE.BoxGeometry(8.08, 0.055, 0.065);
for (const x of [-4.12, 4.12]) {
for (const z of [-0.89, 0.89]) {
addMesh(shelf, postGeometry, materials.frame, x, 2.37, z);
}
}
for (const y of shelfLevels) {
addMesh(shelf, shelfPlankGeometry, materials.plank, 0, y, 0);
addMesh(
shelf,
frontRailGeometry,
materials.frontAccent,
0,
y + 0.16,
1.025,
false
);
}
addMesh(
shelf,
new THREE.BoxGeometry(8.4, 0.18, 0.18),
materials.frame,
0,
4.67,
-0.89
);
// Five identical facings on each of the three shelf rows.
const facingXPositions = [-3.2, -1.6, 0, 1.6, 3.2];
shelfLevels.forEach((shelfY) => {
const boxY = shelfY + 0.61;
for (const x of facingXPositions) {
addProductBox(shelf, x, boxY, 0.28, false);
}
});
// Header sign.
addMesh(
shelf,
new THREE.BoxGeometry(4.95, 0.65, 0.14),
materials.frame,
0,
4.78,
1.02
);
const shelfSign = new THREE.Mesh(
new THREE.PlaneGeometry(4.48, 0.48),
new THREE.MeshBasicMaterial({ map: signTexture })
);
shelfSign.position.set(0, 4.78, 1.097);
shelf.add(shelfSign);
// Rear stock crate, directly behind and slightly to the right.
const crate = new THREE.Group();
crate.position.set(3.15, 0, -1.9);
scene.add(crate);
addMesh(
crate,
new THREE.BoxGeometry(5.38, 0.18, 1.78),
materials.crateDark,
0,
0.14,
0
);
const crateCornerGeometry = new THREE.BoxGeometry(0.18, 3.36, 0.18);
for (const x of [-2.58, 2.58]) {
for (const z of [-0.78, 0.78]) {
addMesh(crate, crateCornerGeometry, materials.crate, x, 1.83, z);
}
}
const crateTopXGeometry = new THREE.BoxGeometry(5.35, 0.18, 0.18);
const crateTopZGeometry = new THREE.BoxGeometry(0.18, 0.18, 1.74);
for (const z of [-0.78, 0.78]) {
addMesh(crate, crateTopXGeometry, materials.crate, 0, 3.48, z);
}
for (const x of [-2.58, 2.58]) {
addMesh(crate, crateTopZGeometry, materials.crate, x, 3.48, 0);
addMesh(
crate,
new THREE.BoxGeometry(0.13, 0.13, 1.72),
materials.crate,
x,
1.27,
0
);
}
addMesh(
crate,
new THREE.BoxGeometry(5.28, 0.16, 0.16),
materials.crate,
0,
0.31,
0.78
);
// 11 matching reserve boxes: 4 + 4 + 3.
const reserveRows = [
{ y: 0.76, xs: [-1.875, -0.625, 0.625, 1.875] },
{ y: 1.80, xs: [-1.875, -0.625, 0.625, 1.875] },
{ y: 2.84, xs: [-1.25, 0, 1.25] }
];
for (const row of reserveRows) {
for (const x of row.xs) {
addProductBox(crate, x, row.y, 0, true);
}
}
const reservePlaque = new THREE.Mesh(
new THREE.PlaneGeometry(3.85, 0.375),
new THREE.MeshBasicMaterial({ map: reservePlaqueTexture })
);
reservePlaque.position.set(0, 3.47, 0.881);
crate.add(reservePlaque);
// Camera state and custom orbit controls.
const orbit = {
target: new THREE.Vector3(-0.2, 2.25, -0.2),
theta: 0.72,
phi: 1.12,
zoom: 1.0,
radius: 18
};
const presets = {
overview: {
target: new THREE.Vector3(-0.2, 2.25, -0.2),
theta: 0.72,
phi: 1.12,
zoom: 1.0
},
front: {
target: new THREE.Vector3(-2.0, 2.45, 0.25),
theta: 0.30,
phi: 1.15,
zoom: 1.43
},
reserve: {
target: new THREE.Vector3(3.15, 1.85, -1.35),
theta: 1.02,
phi: 1.10,
zoom: 1.52
}
};
let transition = null;
let pointerDown = false;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
previousX = event.clientX;
previousY = event.clientY;
transition = null;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.42,
1.42
);
updateCamera();
});
function endPointer(event) {
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
transition = null;
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.2
);
updateCamera();
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function choosePreset(name) {
const preset = presets[name];
transition = {
start: performance.now(),
duration: 700,
fromTarget: orbit.target.clone(),
toTarget: preset.target.clone(),
fromTheta: orbit.theta,
toTheta: preset.theta,
fromPhi: orbit.phi,
toPhi: preset.phi,
fromZoom: orbit.zoom,
toZoom: preset.zoom
};
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
choosePreset(button.dataset.view);
});
});
// Ghost the display shelf to make the reserve stock easier to inspect.
const revealButton = document.querySelector("#reveal-button");
function setMaterialGhost(material, enabled, opacity) {
material.opacity = enabled ? opacity : 1;
material.transparent = enabled;
material.depthWrite = !enabled;
material.needsUpdate = true;
}
revealButton.addEventListener("click", () => {
const enabled = revealButton.getAttribute("aria-pressed") !== "true";
revealButton.setAttribute("aria-pressed", String(enabled));
revealButton.textContent = enabled ? "Restore shelf" : "Reveal reserve";
setMaterialGhost(materials.facingBox, enabled, 0.16);
setMaterialGhost(materials.facingTape, enabled, 0.15);
setMaterialGhost(materials.frame, enabled, 0.23);
setMaterialGhost(materials.plank, enabled, 0.25);
setMaterialGhost(materials.frontAccent, enabled, 0.22);
productLabelMaterial.opacity = enabled ? 0.22 : 1;
productLabelMaterial.depthWrite = !enabled;
productLabelMaterial.needsUpdate = true;
});
// Responsive orthographic frustum.
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(5.3, 7.0 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// HTML annotations projected from 3D anchor points.
const facingLabelElement = document.querySelector("#facing-label");
const reserveLabelElement = document.querySelector("#reserve-label");
const facingAnchor = new THREE.Vector3(-3.8, 5.42, 0.72);
const reserveAnchor = new THREE.Vector3(3.6, 4.02, -1.05);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -150 &&
x < window.innerWidth + 150 &&
y > -100 &&
y < window.innerHeight + 100;
element.style.display = visible ? "block" : "none";
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function animate(now) {
requestAnimationFrame(animate);
if (transition) {
const progress = THREE.MathUtils.clamp(
(now - transition.start) / transition.duration,
0,
1
);
const eased = easeInOutCubic(progress);
orbit.target.lerpVectors(
transition.fromTarget,
transition.toTarget,
eased
);
orbit.theta = THREE.MathUtils.lerp(
transition.fromTheta,
transition.toTheta,
eased
);
orbit.phi = THREE.MathUtils.lerp(
transition.fromPhi,
transition.toPhi,
eased
);
orbit.zoom = THREE.MathUtils.lerp(
transition.fromZoom,
transition.toZoom,
eased
);
if (progress >= 1) transition = null;
}
updateCamera();
positionLabel(facingLabelElement, facingAnchor);
positionLabel(reserveLabelElement, reserveAnchor);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```