Prompt specification
Build or customize the Three.js 3D scene "Shared Shelf With Personal Compartments" 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: Shared Shelf With Personal Compartments
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-shelf-with-personal-compartments-x3237
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build one shared shelf divided into marked personal compartments and a common tray. Make boundaries clear through partitions and symbols rather than assumptions about ownership.
Working Three.js Starter (shared-shelf-with-personal-compartments-x3237):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shared Shelf — Marked Personal Compartments</title>
<style>
:root {
--ink: #24312c;
--muted: #66736d;
--paper: rgba(250, 247, 239, 0.88);
--line: rgba(36, 49, 44, 0.14);
--common: #249989;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8dfd8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.58);
background: var(--paper);
box-shadow:
0 18px 50px rgba(35, 48, 42, 0.12),
inset 0 0 0 1px rgba(36, 49, 44, 0.05);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.brand {
top: 24px;
left: 24px;
width: 300px;
padding: 19px 21px 18px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 27px;
font-weight: 800;
letter-spacing: -0.045em;
line-height: 1;
}
h1 span {
color: var(--common);
}
.brand p:last-child {
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
top: 24px;
right: 24px;
width: 265px;
padding: 17px 18px;
border-radius: 18px;
}
.legend-title {
margin: 0 0 13px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 10px;
font-size: 12px;
}
.legend-row strong {
display: block;
font-size: 12px;
}
.legend-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.symbol {
position: relative;
flex: 0 0 29px;
width: 29px;
height: 29px;
border-radius: 50%;
background: #eef0eb;
border: 1px solid rgba(36, 49, 44, 0.16);
}
.symbol.person::before {
content: "";
position: absolute;
width: 7px;
height: 7px;
left: 10px;
top: 5px;
border-radius: 50%;
background: var(--ink);
}
.symbol.person::after {
content: "";
position: absolute;
width: 13px;
height: 8px;
left: 7px;
top: 14px;
border-radius: 9px 9px 4px 4px;
background: var(--ink);
}
.symbol.nodes span {
position: absolute;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--common);
z-index: 2;
}
.symbol.nodes span:nth-child(1) {
left: 5px;
top: 11px;
}
.symbol.nodes span:nth-child(2) {
left: 17px;
top: 5px;
}
.symbol.nodes span:nth-child(3) {
right: 4px;
top: 16px;
}
.symbol.nodes::before,
.symbol.nodes::after {
content: "";
position: absolute;
height: 2px;
background: var(--common);
transform-origin: left center;
}
.symbol.nodes::before {
width: 13px;
left: 8px;
top: 12px;
transform: rotate(-30deg);
}
.symbol.nodes::after {
width: 13px;
left: 10px;
top: 15px;
transform: rotate(35deg);
}
.legend-note {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.inspector {
left: 24px;
bottom: 24px;
width: 340px;
padding: 18px;
border-radius: 18px;
}
.zone-tabs {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin: 13px 0 15px;
}
.zone-tab {
height: 34px;
padding: 0;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.48);
color: var(--muted);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
cursor: pointer;
transition:
background 150ms ease,
color 150ms ease,
transform 150ms ease;
}
.zone-tab:hover {
transform: translateY(-1px);
}
.zone-tab.active {
border-color: transparent;
background: var(--ink);
color: #fffdf7;
}
#zone-title {
margin: 0;
font-size: 18px;
letter-spacing: -0.025em;
}
#zone-type {
margin: 4px 0 9px;
color: var(--common);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#zone-description {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.controls {
right: 24px;
bottom: 24px;
padding: 10px;
border-radius: 16px;
}
.controls-row {
display: flex;
gap: 7px;
}
.controls button {
min-width: 64px;
height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.52);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
.controls button:hover {
background: #fffdf8;
transform: translateY(-1px);
}
.controls button.active {
border-color: transparent;
background: var(--ink);
color: #fffdf8;
}
.hint {
position: fixed;
z-index: 5;
left: 50%;
bottom: 26px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
background: rgba(36, 49, 44, 0.74);
color: rgba(255, 255, 255, 0.88);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 900px) {
.legend {
display: none;
}
.brand {
top: 14px;
left: 14px;
width: 260px;
}
.inspector {
left: 14px;
bottom: 14px;
width: min(330px, calc(100vw - 28px));
}
.controls {
right: 14px;
top: 14px;
}
.hint {
display: none;
}
}
@media (max-width: 560px) {
.brand {
width: calc(100vw - 28px);
padding: 14px 16px;
}
.brand p:last-child {
display: none;
}
h1 {
font-size: 23px;
}
.controls {
top: 102px;
}
.controls button {
min-width: 52px;
padding: 0 9px;
}
.inspector {
padding: 14px;
}
#zone-description {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="panel brand">
<p class="eyebrow">Low-poly spatial study</p>
<h1>Shared <span>/</span> Shelf</h1>
<p>One continuous shelf, divided into explicitly marked use zones.</p>
</header>
<section class="panel legend" aria-label="Zone legend">
<p class="legend-title">Boundary key</p>
<div class="legend-row">
<div class="symbol person" aria-hidden="true"></div>
<div>
<strong>Personal compartment</strong>
<small>Numbered bay + person symbol</small>
</div>
</div>
<div class="legend-row">
<div class="symbol nodes" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<strong>Common tray</strong>
<small>Linked nodes + raised tray rim</small>
</div>
</div>
<div class="legend-note">
Solid partitions, labels, and symbols define the boundaries.
Color is supplementary and does not determine ownership.
</div>
</section>
<aside class="panel inspector" aria-live="polite">
<p class="eyebrow">Boundary map</p>
<div class="zone-tabs" aria-label="Select a shelf zone">
<button class="zone-tab active" data-zone="shelf">ALL</button>
<button class="zone-tab" data-zone="p1">01</button>
<button class="zone-tab" data-zone="p2">02</button>
<button class="zone-tab" data-zone="p3">03</button>
</div>
<h2 id="zone-title">One shelf. Four explicit zones.</h2>
<p id="zone-type">Continuous shared structure</p>
<p id="zone-description">
Solid dividers separate three numbered personal bays. A linked-node
symbol and raised rim identify the common tray. The top and bottom
boards remain continuous, making the structure one shared shelf.
</p>
</aside>
<nav class="panel controls" aria-label="Camera controls">
<div class="controls-row">
<button class="active" data-view="front">FRONT</button>
<button data-view="top">TOP</button>
<button data-view="angle">ANGLE</button>
<button data-view="reset">RESET</button>
</div>
</nav>
<div class="hint">
DRAG TO ORBIT · RIGHT-DRAG TO PAN · SCROLL TO ZOOM · CLICK A ZONE
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const inspectorTitle = document.getElementById("zone-title");
const inspectorType = document.getElementById("zone-type");
const inspectorDescription = document.getElementById("zone-description");
const zoneButtons = [...document.querySelectorAll(".zone-tab")];
const viewButtons = [...document.querySelectorAll("[data-view]")];
// ------------------------------------------------------------------
// Renderer, camera, and lighting
// ------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly shared shelf with four explicitly marked zones"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d8dfd8");
scene.fog = new THREE.Fog("#d8dfd8", 18, 38);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight("#fff9ec", "#8e9b92", 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff4dc", 3.2);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#b8d8e8", 1.25);
fillLight.position.set(8, 5, 4);
scene.add(fillLight);
// ------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: "#d4ddd5",
roughness: 0.96,
flatShading: true
}),
floor: new THREE.MeshStandardMaterial({
color: "#bfc9c1",
roughness: 1,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: "#c9a574",
roughness: 0.82,
flatShading: true
}),
woodEdge: new THREE.MeshStandardMaterial({
color: "#e1bd8d",
roughness: 0.78,
flatShading: true
}),
partition: new THREE.MeshStandardMaterial({
color: "#eee8dd",
roughness: 0.88,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: "#f3eee4",
roughness: 0.8,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: "#34443d",
roughness: 0.72,
flatShading: true
}),
green: new THREE.MeshStandardMaterial({
color: "#4e8b62",
roughness: 0.9,
flatShading: true
}),
greenLight: new THREE.MeshStandardMaterial({
color: "#79aa6e",
roughness: 0.92,
flatShading: true
}),
soil: new THREE.MeshStandardMaterial({
color: "#685747",
roughness: 1,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: "#75827e",
roughness: 0.6,
metalness: 0.22,
flatShading: true
})
};
function addMesh(geometry, material, x, y, z, cast = true, receive = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
function addBox(width, height, depth, material, x, y, z, cast = true) {
return addMesh(
new THREE.BoxGeometry(width, height, depth),
material,
x,
y,
z,
cast,
true
);
}
// ------------------------------------------------------------------
// Canvas-based labels and symbols
// ------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeZoneLabel(title, subtitle, accent, kind) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 1014, 246, 38);
ctx.fillStyle = "#faf6ed";
ctx.fill();
ctx.lineWidth = 7;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(91, 128, 59, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#fffdf8";
ctx.strokeStyle = "#fffdf8";
if (kind === "personal") {
ctx.beginPath();
ctx.arc(91, 103, 13, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.ellipse(91, 151, 24, 21, 0, Math.PI, 0);
ctx.fill();
} else {
ctx.lineWidth = 6;
ctx.beginPath();
ctx.moveTo(68, 130);
ctx.lineTo(91, 100);
ctx.lineTo(116, 148);
ctx.stroke();
[[68, 130], [91, 100], [116, 148]].forEach(([x, y]) => {
ctx.beginPath();
ctx.arc(x, y, 10, 0, Math.PI * 2);
ctx.fill();
});
}
ctx.fillStyle = "#26332d";
ctx.font = "800 68px system-ui, sans-serif";
ctx.textBaseline = "alphabetic";
ctx.fillText(title, 180, 118);
ctx.fillStyle = "#66736d";
ctx.font = "700 27px system-ui, sans-serif";
ctx.fillText(subtitle, 182, 172);
return canvasTexture(canvas);
}
function makeTitleLabel() {
const canvas = document.createElement("canvas");
canvas.width = 1200;
canvas.height = 320;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 1184, 304, 48);
ctx.fillStyle = "rgba(250,247,239,0.96)";
ctx.fill();
ctx.lineWidth = 6;
ctx.strokeStyle = "#d7c6a8";
ctx.stroke();
ctx.fillStyle = "#26332d";
ctx.font = "800 78px system-ui, sans-serif";
ctx.fillText("ONE SHARED SHELF", 300, 140);
ctx.fillStyle = "#68746e";
ctx.font = "700 30px system-ui, sans-serif";
ctx.fillText("BOUNDARIES ARE MARKED — NOT ASSUMED", 303, 205);
ctx.fillStyle = "#249989";
ctx.beginPath();
ctx.arc(175, 144, 55, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#fffdf8";
ctx.fillStyle = "#fffdf8";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(150, 150);
ctx.lineTo(175, 115);
ctx.lineTo(203, 169);
ctx.stroke();
[[150, 150], [175, 115], [203, 169]].forEach(([x, y]) => {
ctx.beginPath();
ctx.arc(x, y, 11, 0, Math.PI * 2);
ctx.fill();
});
return canvasTexture(canvas);
}
function addLabel(texture, width, height, x, y, z) {
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false,
side: THREE.DoubleSide
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
label.position.set(x, y, z);
scene.add(label);
return label;
}
// ------------------------------------------------------------------
// Wall, floor, and continuous shelf structure
// ------------------------------------------------------------------
addBox(34, 14, 0.3, materials.wall, 0, 6.7, -1.36, false);
const floor = addMesh(
new THREE.PlaneGeometry(40, 40),
materials.floor,
0,
0,
0,
false,
true
);
floor.rotation.x = -Math.PI / 2;
const shelfWidth = 10.4;
const shelfDepth = 2.15;
const shelfLeft = -5.2;
const shelfRight = 5.2;
// Continuous top and bottom boards make this one shared shelf.
addBox(
shelfWidth,
0.28,
shelfDepth,
materials.woodEdge,
0,
3.72,
0
);
addBox(shelfWidth, 0.28, shelfDepth, materials.wood, 0, 1.55, 0);
addBox(shelfWidth, 2.2, 0.14, materials.partition, 0, 2.64, -1.01);
// Outer walls and the physical dividers.
const dividerPositions = [-5.13, -3.45, -1.8, -0.15, 5.13];
dividerPositions.forEach((x, index) => {
const dividerMaterial = index === 3
? materials.cream
: materials.partition;
addBox(
0.14,
2.08,
2.02,
dividerMaterial,
x,
2.64,
0
);
// A narrow color-coded top cap helps identify each boundary.
const capColors = ["#b9685b", "#5c84c6", "#c4a341", "#249989"];
const cap = new THREE.MeshStandardMaterial({
color: capColors[Math.min(index, capColors.length - 1)],
roughness: 0.78,
flatShading: true
});
addBox(0.155, 0.055, 2.04, cap, x, 3.66, 0);
});
// Wall brackets.
[-3.7, 3.7].forEach((x) => {
addBox(0.18, 1.48, 0.18, materials.metal, x, 0.78, -0.93);
addBox(0.18, 0.18, 1.72, materials.metal, x, 1.42, -0.16);
});
addLabel(makeTitleLabel(), 5.65, 1.05, 0, 4.55, -1.19);
// ------------------------------------------------------------------
// Zone data and selectable meshes
// ------------------------------------------------------------------
const zones = [];
const hitMeshes = [];
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
function createZone({
id,
title,
subtitle,
type,
description,
accent,
centerX,
width,
isCommon = false
}) {
const backMaterial = new THREE.MeshStandardMaterial({
color: accent,
roughness: 0.92,
flatShading: true,
emissive: "#000000",
emissiveIntensity: 0
});
const baseMaterial = new THREE.MeshStandardMaterial({
color: accent,
roughness: 0.88,
flatShading: true,
emissive: "#000000",
emissiveIntensity: 0
});
const back = addBox(
width - 0.15,
1.92,
0.055,
backMaterial,
centerX,
2.64,
-0.91,
false
);
let base;
if (isCommon) {
// A visibly raised common tray.
base = addBox(
width - 0.18,
0.08,
1.76,
baseMaterial,
centerX,
1.73,
0.03,
false
);
addBox(
width - 0.15,
0.42,
0.13,
baseMaterial,
centerX,
1.91,
0.91
);
addBox(
0.13,
0.42,
1.76,
baseMaterial,
centerX - width / 2 + 0.08,
1.91,
0.03
);
addBox(
0.13,
0.42,
1.76,
baseMaterial,
centerX + width / 2 - 0.08,
1.91,
0.03
);
} else {
base = addBox(
width - 0.17,
0.055,
1.76,
baseMaterial,
centerX,
1.715,
0.03,
false
);
addBox(
width - 0.15,
0.17,
0.1,
baseMaterial,
centerX,
1.79,
0.94
);
}
const labelWidth = isCommon ? 3.65 : width - 0.15;
const label = addLabel(
makeZoneLabel(title, subtitle, accent, isCommon ? "common" : "personal"),
labelWidth,
0.46,
centerX,
3.47,
1.092
);
const hit = new THREE.Mesh(
new THREE.BoxGeometry(width - 0.15, 1.78, 1.82),
hitMaterial
);
hit.position.set(centerX, 2.62, 0.04);
hit.userData.zoneId = id;
scene.add(hit);
hitMeshes.push(hit);
const zone = {
id,
title,
type,
description,
accent,
back,
base,
label,
hit,
backMaterial,
baseMaterial,
isCommon
};
zones.push(zone);
return zone;
}
createZone({
id: "p1",
title: "PERSONAL 01",
subtitle: "NUMBERED COMPARTMENT",
type: "Personal compartment",
description:
"A person pictogram, number, colored base marker, and solid side partitions define this personal bay. The generic objects are illustrative and do not identify an owner.",
accent: "#d77c6d",
centerX: -4.29,
width: 1.68
});
createZone({
id: "p2",
title: "PERSONAL 02",
subtitle: "NUMBERED COMPARTMENT",
type: "Personal compartment",
description:
"The second numbered bay is physically separated from its neighbors. Its identity comes from the displayed marker rather than from assumptions about the objects inside.",
accent: "#6f94cf",
centerX: -2.625,
width: 1.65
});
createZone({
id: "p3",
title: "PERSONAL 03",
subtitle: "NUMBERED COMPARTMENT",
type: "Personal compartment",
description:
"A dedicated personal compartment with its own number, pictogram, floor marker, and enclosing partitions. Numbering avoids assigning a specific person or ownership.",
accent: "#d0ad4d",
centerX: -0.975,
width: 1.65
});
createZone({
id: "common",
title: "COMMON TRAY",
subtitle: "SHARED-USE TRAY",
type: "Common tray",
description:
"The linked-node symbol and raised tray rim explicitly mark shared use. Its large undivided interior contrasts with the smaller personal compartments.",
accent: "#249989",
centerX: 2.49,
width: 5.28,
isCommon: true
});
// ------------------------------------------------------------------
// Low-poly illustrative objects
// ------------------------------------------------------------------
function addBookStack(x, z, coverColor, rotation = 0) {
const group = new THREE.Group();
const cover = new THREE.MeshStandardMaterial({
color: coverColor,
roughness: 0.8,
flatShading: true
});
const colors = ["#526f77", "#bc765c", "#788a5c"];
for (let i = 0; i < 3; i++) {
const width = 0.68 - i * 0.055;
const depth = 0.42 - i * 0.025;
const book = new THREE.Group();
const pages = new THREE.Mesh(
new THREE.BoxGeometry(width - 0.035, 0.1, depth - 0.025),
materials.cream
);
pages.castShadow = true;
book.add(pages);
const topCover = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.022, depth),
cover
);
topCover.position.y = 0.06;
topCover.castShadow = true;
book.add(topCover);
const bottomCover = topCover.clone();
bottomCover.position.y = -0.06;
book.add(bottomCover);
book.position.set((i - 1) * 0.045, 0.09 + i * 0.14, 0);
book.rotation.y = (i - 1) * 0.08;
group.add(book);
}
group.position.set(x, 1.78, z);
group.rotation.y = rotation;
scene.add(group);
}
function addPlant(x, z, scale = 1) {
const group = new THREE.Group();
const pot = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.17, 0.34, 7),
new THREE.MeshStandardMaterial({
color: "#c77f62",
roughness: 0.92,
flatShading: true
})
);
pot.position.y = 0.17;
pot.castShadow = true;
group.add(pot);
const soil = new THREE.Mesh(
new THREE.CylinderGeometry(0.205, 0.205, 0.025, 7),
materials.soil
);
soil.position.y = 0.345;
group.add(soil);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, 0.52, 6),
materials.green
);
stem.position.y = 0.62;
stem.castShadow = true;
group.add(stem);
const leafGeometry = new THREE.DodecahedronGeometry(0.2, 0);
const leaves = [
[-0.12, 0.65, 0, 0.55],
[0.12, 0.78, 0.03, -0.4],
[-0.03, 0.94, 0.02, 0.15],
[0.12, 0.62, -0.08, 0.85]
];
leaves.forEach(([lx, ly, lz, rot], index) => {
const leaf = new THREE.Mesh(
leafGeometry,
index % 2 ? materials.greenLight : materials.green
);
leaf.position.set(lx, ly, lz);
leaf.scale.set(1, 1.35, 0.58);
leaf.rotation.set(0.3, rot, -0.25);
leaf.castShadow = true;
group.add(leaf);
});
group.position.set(x, 1.78, z);
group.scale.setScalar(scale);
scene.add(group);
}
function addMug(x, z, color = "#577e88") {
const group = new THREE.Group();
const mugMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
flatShading: true
});
const mug = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.16, 0.35, 10),
mugMaterial
);
mug.position.y = 0.175;
mug.castShadow = true;
group.add(mug);
const coffee = new THREE.Mesh(
new THREE.CylinderGeometry(0.165, 0.165, 0.012, 10),
materials.soil
);
coffee.position.y = 0.352;
group.add(coffee);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.035, 6, 12),
mugMaterial
);
handle.position.set(0.19, 0.19, 0);
handle.castShadow = true;
group.add(handle);
group.position.set(x, 1.78, z);
scene.add(group);
}
function addPencilCup(x, z) {
const group = new THREE.Group();
const cup = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.16, 0.34, 8),
materials.dark
);
cup.position.y = 0.17;
cup.castShadow = true;
group.add(cup);
const pencilColors = ["#d17a60", "#d5b04b", "#6f94cf", "#5c9a76"];
pencilColors.forEach((color, index) => {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.75,
flatShading: true
});
const pencil = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.022, 0.55, 6),
material
);
pencil.position.set(
(index - 1.5) * 0.055,
0.57,
(index % 2 - 0.5) * 0.055
);
pencil.rotation.z = (index - 1.5) * 0.07;
pencil.castShadow = true;
group.add(pencil);
});
group.position.set(x, 1.78, z);
scene.add(group);
}
function addSupplyCaddy(x, z) {
const group = new THREE.Group();
const caddyMaterial = new THREE.MeshStandardMaterial({
color: "#d9a95f",
roughness: 0.82,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.1, 0.76),
caddyMaterial
);
base.position.y = 0.05;
base.castShadow = true;
group.add(base);
[-0.68, 0.68].forEach((x) => {
const side = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.43, 0.76),
caddyMaterial
);
side.position.set(x, 0.25, 0);
side.castShadow = true;
group.add(side);
});
[-0.34, 0.34].forEach((z) => {
const side = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.43, 0.1),
caddyMaterial
);
side.position.set(0, 0.25, z);
side.castShadow = true;
group.add(side);
});
const cardColors = ["#faf4e9", "#79a9a1", "#e58d73"];
cardColors.forEach((color, index) => {
const cardMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
flatShading: true
});
const card = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.52, 0.07),
cardMaterial
);
card.position.set(-0.36 + index * 0.24, 0.46, -0.06 + index * 0.04);
card.rotation.z = (index - 1) * 0.12;
card.castShadow = true;
group.add(card);
});
group.position.set(x, 1.78, z);
scene.add(group);
}
// Personal bay contents are deliberately generic.
addBookStack(-4.48, 0.28, "#6b8f9d", -0.12);
addPlant(-3.91, 0.24, 0.86);
addMug(-2.87, 0.38, "#6f94cf");
addBookStack(-2.37, 0.2, "#c78364", 0.08);
addPencilCup(-1.21, 0.36);
addBookStack(-0.74, 0.2, "#c7a44a", -0.08);
// Shared tray contents.
addSupplyCaddy(1.17, 0.12);
addMug(2.55, 0.43, "#3f8c81");
addMug(2.96, 0.39, "#d77c6d");
addPlant(4.22, 0.18, 1.02);
// ------------------------------------------------------------------
// Zone selection
// ------------------------------------------------------------------
let activeZoneId = "shelf";
const zoneDescriptions = {
shelf: {
title: "One shelf. Four explicit zones.",
type: "Continuous shared structure",
description:
"Solid dividers separate three numbered personal bays. A linked-node symbol and raised rim identify the common tray. The top and bottom boards remain continuous, making the structure one shared shelf."
},
p1: {
title: "Personal 01",
type: "Personal compartment",
description:
"A person pictogram, number, colored base marker, and solid side partitions define this personal bay. The generic objects are illustrative and do not identify an owner."
},
p2: {
title: "Personal 02",
type: "Personal compartment",
description:
"The second numbered bay is physically separated from its neighbors. Its identity comes from the displayed marker rather than from assumptions about the objects inside."
},
p3: {
title: "Personal 03",
type: "Personal compartment",
description:
"A dedicated personal compartment with its own number, pictogram, floor marker, and enclosing partitions. Numbering avoids assigning a specific person or ownership."
},
common: {
title: "Common Tray",
type: "Shared-use tray",
description:
"The linked-node symbol and raised tray rim explicitly mark shared use. Its large undivided interior contrasts with the smaller personal compartments."
}
};
function selectZone(id) {
activeZoneId = id;
zoneButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.zone === id);
});
zones.forEach((zone) => {
const selected = zone.id === id;
zone.backMaterial.emissive.set(selected ? zone.accent : "#000000");
zone.baseMaterial.emissive.set(selected ? zone.accent : "#000000");
});
const copy = zoneDescriptions[id];
inspectorTitle.textContent = copy.title;
inspectorType.textContent = copy.type;
inspectorDescription.textContent = copy.description;
}
zoneButtons.forEach((button) => {
button.addEventListener("click", () => selectZone(button.dataset.zone));
});
// ------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, and presets
// ------------------------------------------------------------------
function fittedDistance() {
const halfFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
return Math.max(
12.6,
6.15 / (Math.tan(halfFov) * camera.aspect)
);
}
const desired = {
yaw: 0.12,
pitch: 0.08,
radius: fittedDistance(),
target: new THREE.Vector3(0, 2.65, 0)
};
const actual = {
yaw: desired.yaw,
pitch: desired.pitch,
radius: desired.radius,
target: desired.target.clone()
};
let previousFitDistance = desired.radius;
let userZoomed = false;
function setView(name) {
userZoomed = false;
if (name === "front") {
desired.yaw = 0;
desired.pitch = 0.08;
desired.target.set(0, 2.65, 0);
desired.radius = fittedDistance();
}
if (name === "top") {
desired.yaw = 0;
desired.pitch = 0.85;
desired.target.set(0, 2.35, 0);
desired.radius = fittedDistance() * 1.02;
}
if (name === "angle") {
desired.yaw = 0.58;
desired.pitch = 0.24;
desired.target.set(0, 2.55, 0);
desired.radius = fittedDistance();
}
if (name === "reset") {
desired.yaw = 0.12;
desired.pitch = 0.08;
desired.target.set(0, 2.65, 0);
desired.radius = fittedDistance();
selectZone("shelf");
}
viewButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
viewButtons.forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragState = null;
let dragDistance = 0;
function setPointerFromEvent(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;
}
function pickZone(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(hitMeshes, false);
if (intersections.length) {
selectZone(intersections[0].object.userData.zoneId);
}
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
dragState = {
id: event.pointerId,
button: event.button,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY
};
dragDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragState || dragState.id !== event.pointerId) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hovering = raycaster.intersectObjects(hitMeshes, false).length > 0;
renderer.domElement.style.cursor = hovering ? "pointer" : "grab";
return;
}
const dx = event.clientX - dragState.lastX;
const dy = event.clientY - dragState.lastY;
dragState.lastX = event.clientX;
dragState.lastY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
if (dragState.button === 2) {
const panScale = desired.radius * 0.0012;
const right = new THREE.Vector3(
Math.cos(desired.yaw),
0,
-Math.sin(desired.yaw)
);
desired.target.addScaledVector(right, -dx * panScale);
desired.target.y += dy * panScale;
desired.target.x = THREE.MathUtils.clamp(
desired.target.x,
-5,
5
);
desired.target.y = THREE.MathUtils.clamp(
desired.target.y,
0.6,
5.5
);
} else {
desired.yaw = THREE.MathUtils.clamp(
desired.yaw - dx * 0.005,
-1.05,
1.05
);
desired.pitch = THREE.MathUtils.clamp(
desired.pitch + dy * 0.004,
-0.08,
0.98
);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragState || dragState.id !== event.pointerId) return;
const wasClick = dragDistance < 6 && dragState.button === 0;
if (wasClick) {
pickZone(event);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
dragState = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
dragState = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
userZoomed = true;
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
7.5,
34
);
},
{ passive: false }
);
// ------------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
const nextFitDistance = fittedDistance();
if (!userZoomed) {
const scale = nextFitDistance / previousFitDistance;
desired.radius *= scale;
actual.radius *= scale;
}
previousFitDistance = nextFitDistance;
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-dt * 9);
actual.yaw = THREE.MathUtils.lerp(actual.yaw, desired.yaw, smoothing);
actual.pitch = THREE.MathUtils.lerp(
actual.pitch,
desired.pitch,
smoothing
);
actual.radius = THREE.MathUtils.lerp(
actual.radius,
desired.radius,
smoothing
);
actual.target.lerp(desired.target, smoothing);
const cosPitch = Math.cos(actual.pitch);
camera.position.set(
actual.target.x +
actual.radius * Math.sin(actual.yaw) * cosPitch,
actual.target.y + actual.radius * Math.sin(actual.pitch),
actual.target.z +
actual.radius * Math.cos(actual.yaw) * cosPitch
);
camera.lookAt(actual.target);
const pulse = 0.18 + Math.sin(clock.elapsedTime * 2.2) * 0.035;
zones.forEach((zone) => {
const selected = zone.id === activeZoneId;
zone.backMaterial.emissiveIntensity = selected ? pulse : 0;
zone.baseMaterial.emissiveIntensity = selected ? pulse * 0.65 : 0;
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```