Prompt specification
Build or customize the Three.js 3D scene "Accessible lending-library arrangement" 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: Accessible lending-library arrangement
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/accessible-lending-library-arrangement-x0468
Scene Description Prompt:
Arrange a voxel lending library to improve shared shelf reach while preserving sightlines and entrance-to-desk access. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (accessible-lending-library-arrangement-x0468):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Common Ground — Voxel Lending Library</title>
<style>
:root {
--ink: #183238;
--muted: #687b7d;
--paper: #f5f3ec;
--panel: #fffef9;
--line: #dfe4dc;
--lime: #c9ef72;
--teal: #4ea49a;
--red: #dc6d5e;
--gold: #e7b85c;
--navy: #294b4d;
--shadow: 0 12px 35px rgba(25, 47, 49, .12);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
#app {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
header {
height: 68px;
flex: 0 0 68px;
display: flex;
align-items: center;
gap: 18px;
padding: 0 22px;
background: var(--panel);
border-bottom: 1px solid var(--line);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3px;
transform: rotate(-5deg);
}
.brand-mark span {
display: block;
border-radius: 3px;
background: var(--navy);
}
.brand-mark span:nth-child(2) { background: var(--lime); }
.brand-mark span:nth-child(3) { background: var(--teal); }
.brand-mark span:nth-child(4) { background: var(--gold); }
.brand strong {
display: block;
font-size: 14px;
letter-spacing: .08em;
text-transform: uppercase;
}
.brand small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.project {
padding-left: 18px;
border-left: 1px solid var(--line);
color: var(--muted);
font-size: 12px;
}
.project b { color: var(--ink); }
.header-actions {
margin-left: auto;
display: flex;
gap: 9px;
}
.button {
border: 1px solid var(--line);
background: #fff;
border-radius: 9px;
padding: 9px 13px;
font-size: 12px;
font-weight: 700;
transition: .18s ease;
}
.button:hover {
border-color: #aebbb3;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(25, 47, 49, .08);
}
.button.primary {
border-color: var(--navy);
background: var(--navy);
color: white;
}
#workspace {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: 292px minmax(0, 1fr) 280px;
}
aside {
min-height: 0;
overflow-y: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #cbd3cc transparent;
}
#left-panel {
border-right: 1px solid var(--line);
padding: 28px 22px;
}
#right-panel {
border-left: 1px solid var(--line);
padding: 24px 20px;
}
.eyebrow {
margin-bottom: 10px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 230px;
font-size: 29px;
line-height: 1.04;
letter-spacing: -.045em;
}
.intro {
margin: 13px 0 22px;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 22px;
}
.metric {
min-height: 82px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: #fafaf6;
}
.metric.wide { grid-column: 1 / -1; }
.metric-label {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.metric-value {
display: block;
margin-top: 7px;
font-size: 20px;
font-weight: 800;
letter-spacing: -.04em;
}
.metric-value.good { color: #337f73; }
.metric-value.bad { color: var(--red); }
.metric-note {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.section-title {
margin: 22px 0 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
.preset {
width: 100%;
display: grid;
grid-template-columns: 38px 1fr 18px;
align-items: center;
gap: 10px;
padding: 10px;
margin-bottom: 7px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
text-align: left;
transition: .18s ease;
}
.preset:hover {
border-color: #afbbb4;
background: #fafcf7;
}
.preset.active {
border-color: var(--navy);
box-shadow: inset 0 0 0 1px var(--navy);
background: #f7faef;
}
.preset-icon {
width: 34px;
height: 30px;
position: relative;
background:
linear-gradient(90deg, var(--navy) 0 17%, transparent 17% 30%,
var(--navy) 30% 47%, transparent 47% 60%, var(--navy) 60% 77%,
transparent 77% 90%, var(--navy) 90% 100%);
opacity: .8;
}
.preset-icon::after {
content: "";
position: absolute;
left: 0;
right: 0;
top: 13px;
height: 3px;
background: var(--teal);
transform: rotate(-8deg);
}
.preset strong {
display: block;
font-size: 11px;
}
.preset small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.preset-check {
color: var(--teal);
font-size: 15px;
opacity: 0;
}
.preset.active .preset-check { opacity: 1; }
.toggle {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 0;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.toggle input {
appearance: none;
width: 31px;
height: 18px;
margin: 0;
border-radius: 20px;
background: #cdd5cf;
position: relative;
cursor: pointer;
transition: .2s ease;
}
.toggle input::after {
content: "";
position: absolute;
width: 12px;
height: 12px;
top: 3px;
left: 3px;
border-radius: 50%;
background: white;
transition: .2s ease;
}
.toggle input:checked { background: var(--teal); }
.toggle input:checked::after { transform: translateX(13px); }
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
.instruction {
margin-top: 17px;
padding: 13px;
border-radius: 10px;
background: #eef4e6;
color: #4f675b;
font-size: 10px;
line-height: 1.55;
}
#stage {
min-width: 0;
min-height: 0;
position: relative;
overflow: hidden;
background: #ecebe4;
}
canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.stage-top {
position: absolute;
z-index: 3;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.scene-label {
padding: 8px 10px;
border: 1px solid rgba(67, 84, 80, .13);
border-radius: 8px;
background: rgba(255, 254, 249, .84);
backdrop-filter: blur(8px);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: .07em;
text-transform: uppercase;
}
.view-buttons {
display: flex;
gap: 4px;
padding: 4px;
border-radius: 9px;
background: rgba(255, 254, 249, .88);
box-shadow: var(--shadow);
pointer-events: auto;
}
.view-buttons button {
border: 0;
border-radius: 6px;
padding: 6px 9px;
background: transparent;
color: var(--muted);
font-size: 10px;
font-weight: 800;
}
.view-buttons button.active {
background: var(--navy);
color: white;
}
.stage-bottom {
position: absolute;
z-index: 3;
left: 18px;
right: 18px;
bottom: 16px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
pointer-events: none;
}
.hint {
padding: 8px 10px;
border-radius: 8px;
background: rgba(24, 50, 56, .84);
color: #eef4ed;
font-size: 9px;
letter-spacing: .02em;
}
.scale {
color: #536765;
font-size: 9px;
font-weight: 700;
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
border-radius: 9px;
background: #e6f3e9;
color: #33745e;
font-size: 10px;
font-weight: 800;
}
.status::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #4aad7d;
box-shadow: 0 0 0 4px rgba(74, 173, 125, .12);
}
.status.bad {
background: #f9e7e3;
color: #a34d43;
}
.status.bad::before {
background: var(--red);
box-shadow: 0 0 0 4px rgba(220, 109, 94, .13);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18px;
}
.panel-heading h2 {
margin: 0;
font-size: 14px;
letter-spacing: -.02em;
}
.selection-empty {
padding: 24px 12px;
border: 1px dashed #ccd5cd;
border-radius: 12px;
color: var(--muted);
text-align: center;
font-size: 11px;
line-height: 1.55;
}
.selection-icon {
width: 52px;
height: 52px;
margin: 0 auto 13px;
border-radius: 14px;
background:
linear-gradient(var(--navy), var(--navy)) 10px 14px / 9px 28px no-repeat,
linear-gradient(var(--navy), var(--navy)) 34px 14px / 9px 28px no-repeat,
linear-gradient(var(--teal), var(--teal)) 10px 43px / 33px 7px no-repeat;
opacity: .8;
}
.detail-card {
padding: 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fafaf6;
}
.fixture-code {
color: var(--teal);
font-size: 9px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.detail-card h3 {
margin: 6px 0 3px;
font-size: 18px;
letter-spacing: -.03em;
}
.detail-card p {
margin: 0;
color: var(--muted);
font-size: 10px;
}
.detail-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.detail-stat {
padding: 9px;
border-radius: 8px;
background: white;
}
.detail-stat span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
.detail-stat b {
display: block;
margin-top: 4px;
font-size: 13px;
}
.nudge-label {
margin: 21px 0 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.nudge {
display: grid;
grid-template-columns: repeat(3, 38px);
grid-template-rows: repeat(2, 36px);
justify-content: center;
gap: 5px;
}
.nudge button {
border: 1px solid var(--line);
border-radius: 8px;
background: white;
font-size: 16px;
transition: .15s ease;
}
.nudge button:hover {
background: var(--lime);
border-color: #b2d95d;
transform: translateY(-1px);
}
.nudge button:nth-child(1) { grid-column: 2; }
.nudge button:nth-child(2) { grid-column: 1; grid-row: 2; }
.nudge button:nth-child(3) { grid-column: 2; grid-row: 2; }
.nudge button:nth-child(4) { grid-column: 3; grid-row: 2; }
.recommendation {
margin-top: 20px;
padding: 13px;
border-left: 3px solid var(--lime);
border-radius: 0 9px 9px 0;
background: #f0f5e7;
color: #52655b;
font-size: 10px;
line-height: 1.55;
}
.recommendation strong {
display: block;
margin-bottom: 4px;
color: var(--ink);
font-size: 10px;
}
.microcopy {
margin-top: 18px;
color: #93a09b;
font-size: 9px;
line-height: 1.55;
}
@media (max-width: 1080px) {
#workspace { grid-template-columns: 250px minmax(0, 1fr) 245px; }
#left-panel { padding: 22px 17px; }
#right-panel { padding: 20px 16px; }
h1 { font-size: 25px; }
.project { display: none; }
}
@media (max-width: 820px) {
html, body { height: auto; overflow: auto; }
#app { min-height: 100%; height: auto; }
header { position: sticky; top: 0; }
.brand { min-width: 0; }
.brand small { display: none; }
#workspace {
display: grid;
grid-template-columns: 1fr 1fr;
overflow: visible;
}
#stage {
grid-column: 1 / -1;
grid-row: 1;
height: 62vh;
min-height: 440px;
}
#left-panel { grid-column: 1; }
#right-panel { grid-column: 2; }
.header-actions .button:first-child { display: none; }
}
@media (max-width: 540px) {
header { padding: 0 13px; }
.brand strong { font-size: 12px; }
.header-actions .button { padding: 8px 9px; }
#workspace { display: block; }
#left-panel, #right-panel { border: 0; border-top: 1px solid var(--line); }
.stage-bottom { align-items: flex-end; }
.scale { display: none; }
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<strong>Common Ground</strong>
<small>Neighborhood lending library</small>
</div>
</div>
<div class="project"><b>Plan 03</b> / Voxel reach study</div>
<div class="header-actions">
<button class="button" id="reset-plan">Reset plan</button>
<button class="button primary" id="auto-arrange">Auto-arrange</button>
</div>
</header>
<div id="workspace">
<aside id="left-panel">
<div class="eyebrow">Library planner</div>
<h1>More books.<br>Clear paths.</h1>
<p class="intro">
A compact shared-shelf plan keeps browsing easy, preserves the entrance
view, and maintains an uninterrupted route to the service desk.
</p>
<div class="metric-grid">
<div class="metric wide">
<span class="metric-label">Shared shelf reach</span>
<span class="metric-value good" id="reach-metric">100%</span>
<span class="metric-note">Fixtures within the shared approach zone</span>
</div>
<div class="metric">
<span class="metric-label">Sightlines</span>
<span class="metric-value good" id="sight-metric">100%</span>
<span class="metric-note">Entry to desk</span>
</div>
<div class="metric">
<span class="metric-label">Entry route</span>
<span class="metric-value good" id="route-metric">2.4 m</span>
<span class="metric-note">Clear minimum width</span>
</div>
</div>
<div class="section-title">Arrangement</div>
<button class="preset active" data-preset="optimized">
<span class="preset-icon" aria-hidden="true"></span>
<span>
<strong>Shared spine</strong>
<small>Compact rows with open cross-aisles</small>
</span>
<span class="preset-check">✓</span>
</button>
<button class="preset" data-preset="grid">
<span class="preset-icon" aria-hidden="true"></span>
<span>
<strong>Open grid</strong>
<small>Balanced aisles and a calmer center</small>
</span>
<span class="preset-check">✓</span>
</button>
<button class="preset" data-preset="original">
<span class="preset-icon" aria-hidden="true"></span>
<span>
<strong>Original plan</strong>
<small>Baseline layout for comparison</small>
</span>
<span class="preset-check">✓</span>
</button>
<div class="section-title">Plan overlays</div>
<label class="toggle">
<input id="show-reach" type="checkbox" checked>
<span class="swatch" style="background:#91b95e"></span>
Shared approach zones
</label>
<label class="toggle">
<input id="show-sight" type="checkbox" checked>
<span class="swatch" style="background:#3e8f98"></span>
Entrance sightline
</label>
<label class="toggle">
<input id="show-route" type="checkbox" checked>
<span class="swatch" style="background:#5eb7a5"></span>
Accessible entry route
</label>
<div class="instruction">
<strong>Try it:</strong> drag a shelf across the floor, or select it and
use the arrow controls. The plan checks the route and sightline live.
</div>
</aside>
<main id="stage">
<div class="stage-top">
<div class="scene-label">Axonometric · Conceptual plan</div>
<div class="view-buttons">
<button id="view-3d" class="active">3D</button>
<button id="view-plan">Plan</button>
</div>
</div>
<div class="stage-bottom">
<div class="hint">Drag empty space to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="scale">1 square = 1 metre</div>
<div id="layout-status" class="status">All checks passed</div>
</div>
</main>
<aside id="right-panel">
<div class="panel-heading">
<h2>Fixture inspector</h2>
<span class="eyebrow" style="margin:0">Live</span>
</div>
<div id="selection-empty" class="selection-empty">
<div class="selection-icon"></div>
Select a shelf in the plan to inspect its shared reach and adjust its position.
</div>
<div id="selection-info" hidden>
<div class="detail-card">
<span class="fixture-code" id="fixture-code">B2 · Double sided</span>
<h3 id="fixture-name">Shared stories</h3>
<p id="fixture-type">Four bays · natural oak finish</p>
<div class="detail-stats">
<div class="detail-stat">
<span>Approach</span>
<b id="fixture-approach">1.8 m</b>
</div>
<div class="detail-stat">
<span>Shared zone</span>
<b id="fixture-zone">Optimal</b>
</div>
</div>
</div>
<div class="nudge-label">Move fixture · 0.5 m</div>
<div class="nudge">
<button data-move="up" title="Move away from entrance">↑</button>
<button data-move="left" title="Move left">←</button>
<button data-move="down" title="Move toward entrance">↓</button>
<button data-move="right" title="Move right">→</button>
</div>
<div class="recommendation" id="recommendation">
<strong>Planning note</strong>
This fixture sits inside the shared approach zone and leaves the
entrance-to-desk sightline open.
</div>
</div>
<div class="microcopy">
The lime circles represent a 2.5 m shared approach zone. They are a
planning aid rather than a code-compliance measurement.
</div>
</aside>
</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.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#ecebe4");
scene.fog = new THREE.Fog("#ecebe4", 48, 85);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-16, 16, 16, -16, 0.1, 120);
const target = new THREE.Vector3(0, 0.7, 0);
const spherical = new THREE.Spherical(38, 0.92, 0.69);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
camera.zoom = 0.94;
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x6c8179, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.2);
sun.position.set(13, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d9e4, 0.75);
fill.position.set(-15, 10, 8);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
}));
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material(color));
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radius, height, color, x = 0, y = 0, z = 0, segments = 16) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextTexture(text, subtitle = "", bg = "#294b4d", fg = "#fffef9") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, 512, 128);
ctx.fillStyle = fg;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 48px system-ui, sans-serif";
ctx.fillText(text, 256, subtitle ? 48 : 66);
if (subtitle) {
ctx.globalAlpha = 0.72;
ctx.font = "500 21px system-ui, sans-serif";
ctx.fillText(subtitle, 256, 91);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeSprite(text, subtitle, x, y, z, scale = 2.8, bg = "#294b4d") {
const texture = makeTextTexture(text, subtitle, bg);
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.position.set(x, y, z);
sprite.scale.set(scale, scale * 0.25, 1);
scene.add(sprite);
return sprite;
}
let randomSeed = 813;
function random() {
randomSeed |= 0;
randomSeed = randomSeed + 0x6D2B79F5 | 0;
let t = Math.imul(randomSeed ^ randomSeed >>> 15, 1 | randomSeed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
// ---------------------------------------------------------------------
// Architectural shell
// ---------------------------------------------------------------------
const architecture = new THREE.Group();
scene.add(architecture);
box(architecture, 23, 0.32, 17.4, "#d8d6cb", 0, -0.18, 0, false);
box(architecture, 23.3, 0.18, 17.7, "#b7b5aa", 0, -0.39, 0, false);
box(architecture, 23, 5.2, 0.38, "#eee9dc", 0, 2.42, -8.45);
box(architecture, 0.38, 5.2, 17, "#e4e0d3", -11.45, 2.42, 0);
box(architecture, 23, 0.22, 0.18, "#365b59", 0, 0.12, -8.21);
box(architecture, 0.18, 0.22, 17, "#365b59", -11.21, 0.12, 0);
const gridVertices = [];
for (let x = -11; x <= 11; x++) {
gridVertices.push(x, 0.012, -8.1, x, 0.012, 8.1);
}
for (let z = -8; z <= 8; z++) {
gridVertices.push(-11.1, 0.012, z, 11.1, 0.012, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute("position", new THREE.Float32BufferAttribute(gridVertices, 3));
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({ color: 0x687775, transparent: true, opacity: 0.13 })
);
scene.add(grid);
// Voxel windows on the back wall.
for (const x of [-7.1, -1.2, 5.5]) {
box(architecture, 3.4, 2.1, 0.12, "#315c62", x, 3.05, -8.20, false);
box(architecture, 3.05, 1.76, 0.08, "#8fc2c3", x, 3.05, -8.10, false);
box(architecture, 0.12, 1.85, 0.14, "#eee9dc", x, 3.05, -8.01, false);
box(architecture, 3.15, 0.12, 0.14, "#eee9dc", x, 3.05, -8.00, false);
box(architecture, 3.65, 0.18, 0.35, "#315c62", x, 2.0, -8.12);
}
const wallSign = new THREE.Mesh(
new THREE.PlaneGeometry(4.5, 1.13),
new THREE.MeshBasicMaterial({
map: makeTextTexture("COMMON GROUND", "BORROW · READ · RETURN"),
transparent: true
})
);
wallSign.position.set(-1.2, 4.63, -8.22);
scene.add(wallSign);
// ---------------------------------------------------------------------
// Shelves
// ---------------------------------------------------------------------
const shelfRoot = new THREE.Group();
scene.add(shelfRoot);
const shelves = [];
const shelfMeshes = [];
const bookColors = ["#d76f5f", "#e3b758", "#4e9289", "#46677b", "#788e5a", "#b88a62", "#c6d9cf"];
function makeShelf(config) {
const group = new THREE.Group();
group.position.set(config.x, 0, config.z);
group.rotation.y = THREE.MathUtils.degToRad(config.rotation || 0);
group.userData.shelf = null;
shelfRoot.add(group);
const frame = config.frame || "#315653";
const wood = config.wood || "#bf865b";
const width = config.width || 3.4;
const depth = config.depth || 1.12;
const levels = [.28, .95, 1.62, 2.29, 2.96];
box(group, width, .18, depth, frame, 0, .11, 0);
for (const x of [-width / 2 + .11, width / 2 - .11]) {
for (const z of [-depth * .38, depth * .38]) {
box(group, .14, 2.92, .14, frame, x, 1.49, z);
}
}
for (const y of levels) {
box(group, width, .12, depth, wood, 0, y, 0);
}
box(group, width - .22, 2.55, .10, wood, 0, 1.57, -depth * .39);
for (let level = 0; level < 4; level++) {
let x = -width / 2 + .26;
while (x < width / 2 - .34) {
const bookWidth = .13 + random() * .11;
const bookHeight = .37 + random() * .19;
const gap = random() * .08;
if (x + bookWidth > width / 2 - .18) break;
const book = box(
group,
bookWidth,
bookHeight,
.66,
bookColors[Math.floor(random() * bookColors.length)],
x + bookWidth / 2,
levels[level] + .06 + bookHeight / 2,
.06
);
if (random() > .62) {
box(group, bookWidth * .62, .035, .68, "#f0dda8",
x + bookWidth / 2, levels[level] + .10 + bookHeight * .72, .055, false);
}
x += bookWidth + gap;
}
}
const label = new THREE.Mesh(
new THREE.PlaneGeometry(Math.min(width - .4, 2.55), .53),
new THREE.MeshBasicMaterial({
map: makeTextTexture(config.code, config.category, config.labelColor || frame),
transparent: true
})
);
label.position.set(0, 2.69, depth / 2 + .015);
group.add(label);
const footprint = new THREE.Mesh(
new THREE.BoxGeometry(width + .18, .025, depth + .18),
new THREE.MeshBasicMaterial({
color: 0xa6d95c,
transparent: true,
opacity: .34,
depthWrite: false
})
);
footprint.position.y = .035;
footprint.visible = false;
group.add(footprint);
const shelf = {
id: config.id,
code: config.code,
category: config.category,
width,
depth,
group,
footprint,
labelColor: config.labelColor || frame
};
group.userData.shelf = shelf;
group.traverse(object => {
if (object.isMesh) {
object.userData.shelf = shelf;
shelfMeshes.push(object);
}
});
shelves.push(shelf);
return shelf;
}
const shelfDefinitions = [
{ id: "a1", code: "A1", category: "NEW ARRIVALS", x: -7, z: -4.7 },
{ id: "a2", code: "A2", category: "FICTION", x: -2, z: -4.7 },
{ id: "a3", code: "A3", category: "GRAPHIC NOVELS", x: 4, z: -4.7, frame: "#647b52" },
{ id: "b1", code: "B1", category: "BIOGRAPHY", x: -7, z: 0, frame: "#735c6f" },
{ id: "b2", code: "B2", category: "SHARED STORIES", x: -1.2, z: 0, frame: "#b75e50", labelColor: "#b75e50" },
{ id: "b3", code: "B3", category: "LANGUAGES", x: 5.3, z: 0, frame: "#3e7473" },
{ id: "c1", code: "C1", category: "COMMUNITY", x: -7, z: 4.6, frame: "#657b7e" },
{ id: "c2", code: "C2", category: "CHILDREN", x: -2.7, z: 4.6, frame: "#c28a48" }
];
shelfDefinitions.forEach(makeShelf);
// ---------------------------------------------------------------------
// Service desk, entrance and reading corner
// ---------------------------------------------------------------------
const desk = new THREE.Group();
desk.position.set(7.25, 0, 5.45);
scene.add(desk);
box(desk, 3.4, 1.08, 1.55, "#3d716d", 0, .53, 0);
box(desk, 3.65, .14, 1.75, "#d19a65", 0, 1.13, 0);
box(desk, 1.85, .76, .15, "#315b58", -.35, 1.58, -.48);
box(desk, .88, .54, .08, "#244b4c", -.35, 1.65, -.56);
box(desk, .56, .07, .42, "#244b4c", -.35, 1.35, -.23);
box(desk, .48, .10, .32, "#eee7d6", .84, 1.26, .08);
box(desk, .18, .28, .18, "#d16d5d", .92, 1.42, .08);
box(desk, 1.1, .73, .65, "#c68759", -1.08, .36, .86);
function makePerson(parent, x, z, shirt, skin = "#c98e69") {
const person = new THREE.Group();
person.position.set(x, 0, z);
parent.add(person);
box(person, .22, .58, .24, "#354e52", -.16, .29, 0);
box(person, .22, .58, .24, "#354e52", .16, .29, 0);
box(person, .70, .72, .38, shirt, 0, .94, 0);
box(person, .20, .66, .22, shirt, -.46, .91, 0);
box(person, .20, .66, .22, shirt, .46, .91, 0);
box(person, .48, .48, .45, skin, 0, 1.54, 0);
box(person, .51, .18, .48, "#493b35", 0, 1.78, -.02);
return person;
}
makePerson(desk, -.05, -1.25, "#d67d63");
const entryMat = box(scene, 2.55, .045, 1.15, "#5b8f83", -1, .055, 7.35, false);
box(scene, .34, .72, .34, "#c47855", -2.48, .36, 7.36);
box(scene, .34, .72, .34, "#c47855", .46, .36, 7.36);
for (const x of [-2.48, .46]) {
box(scene, .24, 1.7, .24, "#577e68", x, 1.25, 7.36);
box(scene, .75, .70, .70, "#587c66", x, 1.86, 7.36);
box(scene, .55, .62, .55, "#6f9577", x - .12, 2.38, 7.36);
box(scene, .58, .52, .58, "#7da27d", x + .15, 2.35, 7.31);
}
const entryLabel = makeSprite("ENTRY", "WELCOME", -1, .27, 7.95, 2.2, "#3e756d");
entryLabel.material.opacity = .92;
const deskLabel = makeSprite("SERVICE", "ASK · BORROW · RETURN", 7.3, 3.18, 5.2, 3.2, "#315653");
// Reading nook.
box(scene, 4.5, .04, 3.65, "#d8b978", 7.3, .035, -1.25, false);
box(scene, 2.85, .48, .72, "#b96755", 7.5, .48, -2.45);
box(scene, 2.85, .73, .25, "#a9584b", 7.5, .88, -2.77);
box(scene, .68, .25, .62, "#e3c889", 6.7, .82, -2.36);
box(scene, .68, .25, .62, "#86a7a0", 8.2, .82, -2.36);
box(scene, 1.65, .16, 1.15, "#ead9b8", 7.3, .71, -.55);
box(scene, .22, .70, .22, "#8b644e", 6.72, .36, -.55);
box(scene, .22, .70, .22, "#8b644e", 7.88, .36, -.55);
box(scene, .38, .06, .30, "#537a6b", 7.15, .83, -.55);
box(scene, .42, .05, .32, "#d77d62", 7.55, .83, -.48);
// A few potted plants.
for (const plant of [
[-9.55, 6.75], [9.5, 2.7], [9.55, -6.2], [-9.7, -6.6]
]) {
const [x, z] = plant;
box(scene, .72, .68, .72, "#c87855", x, .34, z);
box(scene, .58, 1.05, .58, "#547c5e", x, 1.08, z);
box(scene, .72, .62, .72, "#6c9168", x + .16, 1.55, z - .08);
box(scene, .60, .55, .60, "#83a676", x - .20, 1.78, z + .06);
}
// ---------------------------------------------------------------------
// Planning overlays
// ---------------------------------------------------------------------
const reachGroup = new THREE.Group();
const sightGroup = new THREE.Group();
const routeGroup = new THREE.Group();
scene.add(reachGroup, sightGroup, routeGroup);
const reachMarkers = shelves.map(shelf => {
const marker = new THREE.Mesh(
new THREE.CircleGeometry(2.5, 48),
new THREE.MeshBasicMaterial({
color: 0x94b95d,
transparent: true,
opacity: .10,
depthWrite: false,
side: THREE.DoubleSide
})
);
marker.rotation.x = -Math.PI / 2;
marker.position.y = .025;
marker.renderOrder = 1;
reachGroup.add(marker);
const ring = new THREE.Mesh(
new THREE.RingGeometry(2.46, 2.51, 48),
new THREE.MeshBasicMaterial({
color: 0x87aa51,
transparent: true,
opacity: .40,
depthWrite: false,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = .028;
ring.renderOrder = 2;
reachGroup.add(ring);
return { shelf, marker, ring };
});
const routeStart = new THREE.Vector2(-1, 7.55);
const routeEnd = new THREE.Vector2(6.25, 5.55);
const routeDirection = routeEnd.clone().sub(routeStart);
const routeLength = routeDirection.length();
const routeMid = routeStart.clone().add(routeEnd).multiplyScalar(.5);
const routeRibbon = new THREE.Mesh(
new THREE.BoxGeometry(2.4, .035, routeLength),
new THREE.MeshBasicMaterial({
color: 0x62b6a4,
transparent: true,
opacity: .23,
depthWrite: false
})
);
routeRibbon.position.set(routeMid.x, .045, routeMid.y);
routeRibbon.rotation.y = Math.atan2(routeDirection.x, routeDirection.y);
routeRibbon.renderOrder = 1;
routeGroup.add(routeRibbon);
for (const p of [routeStart, routeEnd]) {
const dot = new THREE.Mesh(
new THREE.CircleGeometry(.22, 24),
new THREE.MeshBasicMaterial({ color: 0x438f82, transparent: true, opacity: .75 })
);
dot.rotation.x = -Math.PI / 2;
dot.position.set(p.x, .07, p.y);
routeGroup.add(dot);
}
const sightGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(routeStart.x, 1.65, routeStart.y),
new THREE.Vector3(routeEnd.x, 1.65, routeEnd.y)
]);
const sightMaterial = new THREE.LineDashedMaterial({
color: 0x398e99,
dashSize: .28,
gapSize: .17,
transparent: true,
opacity: .82,
depthTest: false
});
const sightLine = new THREE.Line(sightGeometry, sightMaterial);
sightLine.computeLineDistances();
sightLine.renderOrder = 4;
sightGroup.add(sightLine);
const sightStart = new THREE.Mesh(
new THREE.SphereGeometry(.10, 12, 8),
new THREE.MeshBasicMaterial({ color: 0x398e99 })
);
sightStart.position.set(routeStart.x, 1.65, routeStart.y);
sightGroup.add(sightStart);
const selectedBox = new THREE.BoxHelper(shelves[4].group, 0xa5d85b);
selectedBox.visible = false;
selectedBox.material.depthTest = false;
selectedBox.material.transparent = true;
selectedBox.material.opacity = .9;
selectedBox.renderOrder = 10;
scene.add(selectedBox);
// ---------------------------------------------------------------------
// Layouts and selection
// ---------------------------------------------------------------------
const layouts = {
optimized: [
[-7, -4.7], [-2, -4.7], [4, -4.7], [-7, 0],
[-1.2, 0], [5.3, 0], [-7, 4.6], [-2.7, 4.6]
],
grid: [
[-7, -5], [-1, -5], [5, -5], [-7, 0],
[0, 0], [7, 0], [-7, 5], [0, 5]
],
original: [
[-8, -6], [-.5, -6], [6, -6], [-8, 0],
[1, 6], [8, 0], [-8, 4], [-4, 4]
]
};
let activePreset = "optimized";
let selectedShelf = null;
let tweens = [];
const selectionEmpty = document.getElementById("selection-empty");
const selectionInfo = document.getElementById("selection-info");
function selectShelf(shelf) {
selectedShelf = shelf;
selectionEmpty.hidden = !!shelf;
selectionInfo.hidden = !shelf;
shelves.forEach(item => item.footprint.visible = false);
selectedBox.visible = !!shelf;
if (!shelf) return;
shelf.footprint.visible = true;
selectedBox.setFromObject(shelf.group);
document.getElementById("fixture-code").textContent = `${shelf.code} · ${shelf.id === "b2" ? "Double sided" : "Shared shelf"}`;
document.getElementById("fixture-name").textContent = shelf.category.toLowerCase().replace(/\b\w/g, c => c.toUpperCase());
document.getElementById("fixture-type").textContent = `${shelf.width.toFixed(1)} m wide · ${shelf.depth.toFixed(1)} m deep · voxel oak finish`;
updateMetrics();
}
function applyPreset(name, animate = true) {
activePreset = name;
document.querySelectorAll("[data-preset]").forEach(button => {
button.classList.toggle("active", button.dataset.preset === name);
});
const positions = layouts[name];
shelves.forEach((shelf, index) => {
const [x, z] = positions[index];
if (!animate) {
shelf.group.position.set(x, 0, z);
} else {
tweens.push({
shelf,
from: shelf.group.position.clone(),
to: new THREE.Vector3(x, 0, z),
start: performance.now(),
duration: 720 + index * 22
});
}
});
selectShelf(null);
updateMetrics();
}
function clampShelf(shelf) {
const rotated = Math.abs(Math.sin(shelf.group.rotation.y)) > .5;
const halfWidth = rotated ? shelf.depth / 2 : shelf.width / 2;
const halfDepth = rotated ? shelf.width / 2 : shelf.depth / 2;
shelf.group.position.x = THREE.MathUtils.clamp(
shelf.group.position.x, -10.7 + halfWidth, 10.7 - halfWidth
);
shelf.group.position.z = THREE.MathUtils.clamp(
shelf.group.position.z, -7.5 + halfDepth, 7.6 - halfDepth
);
}
function moveSelected(dx, dz) {
if (!selectedShelf) return;
selectedShelf.group.position.x += dx;
selectedShelf.group.position.z += dz;
clampShelf(selectedShelf);
updateMetrics();
}
document.querySelectorAll("[data-preset]").forEach(button => {
button.addEventListener("click", () => applyPreset(button.dataset.preset));
});
document.getElementById("auto-arrange").addEventListener("click", () => applyPreset("optimized"));
document.getElementById("reset-plan").addEventListener("click", () => {
applyPreset("optimized");
setView(false);
});
document.querySelectorAll("[data-move]").forEach(button => {
button.addEventListener("click", () => {
const moves = {
left: [-.5, 0],
right: [.5, 0],
up: [0, -.5],
down: [0, .5]
};
moveSelected(...moves[button.dataset.move]);
});
});
document.getElementById("show-reach").addEventListener("change", event => {
reachGroup.visible = event.target.checked;
});
document.getElementById("show-sight").addEventListener("change", event => {
sightGroup.visible = event.target.checked;
});
document.getElementById("show-route").addEventListener("change", event => {
routeGroup.visible = event.target.checked;
});
window.addEventListener("keydown", event => {
if (!selectedShelf) return;
if (["INPUT", "TEXTAREA", "BUTTON"].includes(document.activeElement?.tagName)) return;
const moves = {
ArrowLeft: [-.5, 0],
ArrowRight: [.5, 0],
ArrowUp: [0, -.5],
ArrowDown: [0, .5]
};
if (moves[event.key]) {
event.preventDefault();
moveSelected(...moves[event.key]);
}
});
// ---------------------------------------------------------------------
// Planning calculations
// ---------------------------------------------------------------------
function distancePointToSegment(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
if (lengthSquared === 0) return Math.hypot(px - ax, pz - az);
const t = THREE.MathUtils.clamp(((px - ax) * dx + (pz - az) * dz) / lengthSquared, 0, 1);
return Math.hypot(px - (ax + t * dx), pz - (az + t * dz));
}
const approachNetwork = [
[-9.5, -2.2, 8.7, -2.2],
[-9.5, 2.2, 8.7, 2.2],
[0, -6.5, 0, 7.1]
];
function shelfAabb(shelf) {
const rotated = Math.abs(Math.sin(shelf.group.rotation.y)) > .5;
const halfWidth = (rotated ? shelf.depth : shelf.width) / 2;
const halfDepth = (rotated ? shelf.width : shelf.depth) / 2;
return {
minX: shelf.group.position.x - halfWidth,
maxX: shelf.group.position.x + halfWidth,
minZ: shelf.group.position.z - halfDepth,
maxZ: shelf.group.position.z + halfDepth
};
}
function pathHitsShelf(shelf) {
const box = shelfAabb(shelf);
for (let i = 0; i <= 100; i++) {
const t = i / 100;
const x = THREE.MathUtils.lerp(routeStart.x, routeEnd.x, t);
const z = THREE.MathUtils.lerp(routeStart.y, routeEnd.y, t);
if (x >= box.minX && x <= box.maxX && z >= box.minZ && z <= box.maxZ) return true;
}
return false;
}
function shelfApproach(shelf) {
let distance = Infinity;
for (const segment of approachNetwork) {
distance = Math.min(
distance,
distancePointToSegment(
shelf.group.position.x,
shelf.group.position.z,
segment[0], segment[1], segment[2], segment[3]
)
);
}
return distance;
}
function updateMetrics() {
const blockedShelves = shelves.filter(pathHitsShelf);
const blocked = blockedShelves.length > 0;
const reachCount = shelves.filter(shelf => shelfApproach(shelf) <= 2.55).length;
const reachScore = Math.round(reachCount / shelves.length * 100);
document.getElementById("reach-metric").textContent = `${reachScore}%`;
document.getElementById("sight-metric").textContent = blocked ? "62%" : "100%";
document.getElementById("route-metric").textContent = blocked ? "Blocked" : "2.4 m";
document.getElementById("reach-metric").className = `metric-value ${reachScore >= 90 ? "good" : "bad"}`;
document.getElementById("sight-metric").className = `metric-value ${blocked ? "bad" : "good"}`;
document.getElementById("route-metric").className = `metric-value ${blocked ? "bad" : "good"}`;
const status = document.getElementById("layout-status");
status.className = `status${blocked ? " bad" : ""}`;
status.textContent = blocked
? `${blockedShelves.length} route conflict${blockedShelves.length > 1 ? "s" : ""}`
: "All checks passed";
routeRibbon.material.color.set(blocked ? 0xdc6d5e : 0x62b6a4);
routeRibbon.material.opacity = blocked ? .34 : .23;
sightMaterial.color.set(blocked ? 0xdc6d5e : 0x398e99);
reachMarkers.forEach(({ shelf, marker, ring }) => {
marker.position.x = shelf.group.position.x;
marker.position.z = shelf.group.position.z;
ring.position.x = shelf.group.position.x;
ring.position.z = shelf.group.position.z;
});
if (selectedShelf) {
const approach = shelfApproach(selectedShelf);
document.getElementById("fixture-approach").textContent = `${approach.toFixed(1)} m`;
document.getElementById("fixture-zone").textContent = approach <= 2.55 ? "Optimal" : "Too far";
const recommendation = document.getElementById("recommendation");
if (pathHitsShelf(selectedShelf)) {
recommendation.innerHTML = "<strong>Route conflict</strong>This shelf interrupts the entrance-to-desk route. Move it away from the teal corridor.";
} else if (approach > 2.55) {
recommendation.innerHTML = "<strong>Improve shared reach</strong>This shelf sits beyond the lime approach zone. Moving it toward a cross-aisle reduces browsing travel.";
} else {
recommendation.innerHTML = "<strong>Well positioned</strong>This fixture sits inside the shared approach zone and leaves the entrance-to-desk sightline open.";
}
}
if (selectedShelf) selectedBox.setFromObject(selectedShelf.group);
}
// ---------------------------------------------------------------------
// Direct camera controls and shelf dragging
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const dragPoint = new THREE.Vector3();
const dragOffset = new THREE.Vector3();
let pointerState = null;
let pointerStart = { x: 0, y: 0 };
let lastPointer = { x: 0, y: 0 };
let activeView = "3d";
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function findShelfHit() {
const hits = raycaster.intersectObjects(shelfMeshes, false);
return hits.length ? hits[0].object.userData.shelf : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
updatePointer(event);
pointerStart = { x: event.clientX, y: event.clientY };
lastPointer = { ...pointerStart };
renderer.domElement.setPointerCapture(event.pointerId);
const hit = findShelfHit();
if (event.button === 0 && hit && !event.shiftKey) {
selectShelf(hit);
const point = raycaster.ray.intersectPlane(dragPlane, dragPoint);
if (point) {
dragOffset.copy(dragPoint).sub(hit.group.position);
pointerState = "maybe-drag";
}
} else if (event.button === 2 || event.button === 1 || event.shiftKey) {
pointerState = "pan";
} else {
pointerState = "orbit";
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerState) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
const totalDistance = Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
);
if (pointerState === "maybe-drag" && totalDistance > 4) {
pointerState = "drag";
}
if (pointerState === "orbit") {
spherical.theta -= dx * .006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * .005, .10, 1.43);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
} else if (pointerState === "pan") {
const scale = (camera.right - camera.left) / camera.zoom / renderer.domElement.clientHeight;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const up = new THREE.Vector3().crossVectors(right, forward).normalize();
target.addScaledVector(right, -dx * scale);
target.addScaledVector(up, dy * scale);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
} else if (pointerState === "drag" && selectedShelf) {
updatePointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
selectedShelf.group.position.copy(dragPoint).sub(dragOffset);
selectedShelf.group.position.x = Math.round(selectedShelf.group.position.x * 2) / 2;
selectedShelf.group.position.z = Math.round(selectedShelf.group.position.z * 2) / 2;
clampShelf(selectedShelf);
updateMetrics();
}
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerState === "maybe-drag") selectShelf(selectedShelf);
if (pointerState === "orbit" && !findShelfHit()) {
// Keep the current selection for convenient inspection.
}
pointerState = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState = null;
});
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(camera.zoom * Math.exp(-event.deltaY * .001), .55, 2.4);
camera.updateProjectionMatrix();
}, { passive: false });
function setView(plan) {
activeView = plan ? "plan" : "3d";
document.getElementById("view-3d").classList.toggle("active", !plan);
document.getElementById("view-plan").classList.toggle("active", plan);
if (plan) {
spherical.set(38, .08, 0);
camera.zoom = .92;
target.set(0, 0, 0);
} else {
spherical.set(38, .92, .69);
camera.zoom = .94;
target.set(0, .7, 0);
}
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
camera.updateProjectionMatrix();
}
document.getElementById("view-3d").addEventListener("click", () => setView(false));
document.getElementById("view-plan").addEventListener("click", () => setView(true));
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
const aspect = width / height;
const horizontalSpan = 29;
const verticalSpan = horizontalSpan / aspect;
camera.left = -horizontalSpan / 2;
camera.right = horizontalSpan / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function animate(now) {
requestAnimationFrame(animate);
if (tweens.length) {
tweens.forEach(tween => {
const progress = THREE.MathUtils.clamp((now - tween.start) / tween.duration, 0, 1);
tween.shelf.group.position.lerpVectors(tween.from, tween.to, easeOutCubic(progress));
});
tweens = tweens.filter(tween => now - tween.start < tween.duration);
updateMetrics();
}
renderer.render(scene, camera);
}
applyPreset("optimized", false);
updateMetrics();
requestAnimationFrame(animate);
</script>
</body>
</html>
```