Prompt specification
Build or customize the Three.js 3D scene "Community reading corner organization" 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: Community reading corner organization
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-reading-corner-organization-x0467
Scene Description Prompt:
Community reading corner organization. Compose a library corner with low browsing shelves, seats, table, and tall archive storage; frequently used items occupy visibly approachable positions along the main route. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (community-reading-corner-organization-x0467):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Community Reading Corner</title>
<style>
:root {
--ink: #263b3b;
--paper: rgba(255, 251, 242, 0.94);
--sage: #9eb8a5;
--coral: #df7f65;
--teal: #477c78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 18px 20px;
border: 1px solid rgba(38, 59, 59, 0.1);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(51, 59, 52, 0.12);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 31px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 14px;
color: #5e6b66;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
padding-top: 12px;
border-top: 1px solid rgba(38, 59, 59, 0.1);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--sage);
}
.dot.coral {
background: var(--coral);
}
.dot.teal {
background: var(--teal);
}
.controls {
position: absolute;
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.controls button {
width: 38px;
height: 38px;
border: 1px solid rgba(38, 59, 59, 0.12);
border-radius: 12px;
background: var(--paper);
color: var(--ink);
cursor: pointer;
font-size: 18px;
font-weight: 800;
box-shadow: 0 8px 24px rgba(51, 59, 52, 0.1);
}
.controls button:hover {
transform: translateY(-1px);
background: #fffdf8;
}
.hint {
position: absolute;
right: 20px;
bottom: 68px;
padding: 8px 11px;
border-radius: 10px;
background: rgba(255, 251, 242, 0.82);
color: #63706b;
font-size: 11px;
font-weight: 650;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8e1d6;
color: var(--ink);
font-size: 14px;
font-weight: 700;
letter-spacing: 0.04em;
}
@media (max-width: 650px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
.legend {
padding-top: 9px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the reading corner…</div>
<div class="hud">
<section class="title-card">
<p class="eyebrow">Community library / spatial planning</p>
<h1>Community Reading Corner</h1>
<p class="subtitle">
Frequently borrowed books stay low and directly beside the sage-colored
main route. Quiet reference storage is grouped at the rear.
</p>
<div class="legend" aria-label="Organization legend">
<span><i class="dot"></i> Main route</span>
<span><i class="dot coral"></i> Frequent use</span>
<span><i class="dot teal"></i> Tall archive</span>
</div>
</section>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</div>
<div class="controls" aria-label="Camera controls">
<button id="zoom-out" title="Zoom out">−</button>
<button id="reset" title="Reset camera">↺</button>
<button id="zoom-in" title="Zoom in">+</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d6);
scene.fog = new THREE.Fog(0xe8e1d6, 20, 36);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional community library reading corner"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const target = new THREE.Vector3(0, 1.05, 0);
const home = {
target: target.clone(),
theta: 0.67,
phi: 1.03,
zoom: 1
};
let theta = home.theta;
let phi = home.phi;
let zoom = home.zoom;
let currentViewHeight = 8;
scene.add(new THREE.HemisphereLight(0xfff8ea, 0x87938a, 2.2));
const keyLight = new THREE.DirectionalLight(0xfff0d5, 3.2);
keyLight.position.set(5.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbdd6d5, 1.25);
fillLight.position.set(-6, 4, 1);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Reusable solid-shape helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, roughness = 0.78, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, roughness, metalness })
);
}
return materialCache.get(key);
}
function solid(geometry, color, parent = scene) {
const mat =
color && color.isMaterial ? color : material(color);
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, color, x = 0, y = 0, z = 0, parent = scene) {
const mesh = solid(new THREE.BoxGeometry(w, h, d), color, parent);
mesh.position.set(x, y, z);
return mesh;
}
function cylinder(
topRadius,
bottomRadius,
height,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
segments = 32
) {
const mesh = solid(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
color,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function sphere(radius, color, x = 0, y = 0, z = 0, parent = scene) {
const mesh = solid(
new THREE.SphereGeometry(radius, 18, 12),
color,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function rod(a, b, radius, color, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = solid(
new THREE.CylinderGeometry(radius, radius, length, 12),
color,
parent
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
let seed = 8137;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const palette = {
cream: 0xf2eadb,
floor: 0xd8cbb8,
wall: 0xeee7d9,
wood: 0xa96f49,
lightWood: 0xc89567,
darkWood: 0x76513c,
sage: 0x9eb8a5,
deepSage: 0x718f7e,
teal: 0x477c78,
darkTeal: 0x315d5b,
coral: 0xdf7f65,
mustard: 0xe2b75c,
blue: 0x6f98ad,
plum: 0x8c7183,
ink: 0x314a47,
paper: 0xfffaf0
};
const bookColors = [
0x477c78,
0xdf7f65,
0xe2b75c,
0x6f98ad,
0x8c7183,
0x9aaf82,
0xc77f55,
0x536a74
];
// -------------------------------------------------------------------------
// Canvas-generated signage; no external fonts or image assets
// -------------------------------------------------------------------------
function labelPlane(
text,
width,
height,
x,
y,
z,
background = "#fffaf0",
foreground = "#314a47",
parent = scene,
fontSize = 64
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const lines = text.split("\n");
let size = fontSize;
do {
ctx.font = `800 ${size}px Arial, Helvetica, sans-serif`;
const widest = Math.max(
...lines.map((line) => ctx.measureText(line).width)
);
if (widest < 900 || size <= 22) break;
size -= 2;
} while (true);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.fillText(
lines.join("\n"),
canvas.width / 2,
canvas.height / 2
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function sign(
parent,
text,
width,
height,
x,
y,
z,
background = "#fffaf0",
foreground = "#314a47",
fontSize = 64
) {
box(
width + 0.055,
height + 0.055,
0.05,
palette.darkTeal,
x,
y,
z,
parent
);
return labelPlane(
text,
width,
height,
x,
y,
z + 0.031,
background,
foreground,
parent,
fontSize
);
}
// -------------------------------------------------------------------------
// Architecture and circulation
// -------------------------------------------------------------------------
box(12.2, 0.2, 9.2, palette.floor, 0, -0.12, 0);
box(12.2, 3.7, 0.2, palette.wall, 0, 1.74, -4.48);
box(12.2, 0.13, 0.09, palette.deepSage, 0, 0.08, -4.34);
// Main circulation runner.
box(
1.35,
0.035,
7.55,
palette.sage,
-0.25,
0.015,
0.45
);
// A branch makes the archive approachable from either side.
box(
4.2,
0.036,
1.15,
palette.sage,
-2.65,
0.017,
-2.55
);
// Directional chevrons on the runner.
for (const z of [3.45, 2.55, 1.65, -2.55]) {
const left = box(
0.11,
0.025,
0.48,
palette.coral,
-0.38,
0.047,
z
);
left.rotation.y = 0.53;
const right = box(
0.11,
0.025,
0.48,
palette.coral,
-0.12,
0.047,
z
);
right.rotation.y = -0.53;
}
function roundedRectangle(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(
x,
y + height,
x,
y + height - radius
);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const rugOuter = solid(
new THREE.ShapeGeometry(roundedRectangle(4.25, 4.45, 0.35), 16),
palette.coral
);
rugOuter.geometry.rotateX(-Math.PI / 2);
rugOuter.position.set(2.85, 0.018, 0.72);
const rugInner = solid(
new THREE.ShapeGeometry(roundedRectangle(3.98, 4.18, 0.3), 16),
0xe6b49a
);
rugInner.geometry.rotateX(-Math.PI / 2);
rugInner.position.set(2.85, 0.026, 0.72);
// -------------------------------------------------------------------------
// Books and low browsing shelves
// -------------------------------------------------------------------------
function makeBook(parent, options) {
const {
x = 0,
y = 0,
z = 0,
w = 0.16,
h = 0.36,
d = 0.36,
color = palette.teal,
accent = null,
tilt = 0
} = options;
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.z = tilt;
parent.add(group);
box(w, h, d, color, 0, h / 2, 0, group);
// Colored spine band.
box(
w * 0.72,
0.035,
0.012,
accent || palette.paper,
0,
h * 0.72,
d / 2 + 0.007,
group
);
// Bookmark on frequently selected books.
if (accent === palette.mustard || accent === palette.coral) {
box(
w * 0.2,
0.13,
0.012,
accent,
w * 0.22,
h * 0.33,
d / 2 + 0.012,
group
);
}
return group;
}
function fillShelfBay(parent, centerX, baseY, frequent) {
const colors = frequent
? [palette.coral, palette.mustard, palette.teal, palette.blue, palette.plum]
: bookColors;
let cursor = centerX - 0.27;
const end = centerX + 0.27;
while (cursor < end - 0.07) {
const width = 0.105 + random() * 0.07;
const height = 0.27 + random() * 0.12;
const color = colors[Math.floor(random() * colors.length)];
makeBook(parent, {
x: cursor + width / 2,
y: baseY,
z: 0.02,
w: width,
h: height,
d: 0.38,
color,
accent: frequent ? palette.mustard : palette.paper,
tilt: random() > 0.92 ? (random() - 0.5) * 0.12 : 0
});
cursor += width + 0.018;
}
}
function createLowShelf(z, title, subtitle, frequent = false) {
const group = new THREE.Group();
group.position.set(-2.15, 0, z);
group.rotation.y = Math.PI / 2;
scene.add(group);
const width = 2.15;
const depth = 0.74;
const height = 1.12;
box(width, 0.09, depth, palette.lightWood, 0, 0.12, 0, group);
box(width, 0.09, depth, palette.lightWood, 0, 0.59, 0, group);
box(width, 0.10, depth, palette.lightWood, 0, 1.08, 0, group);
box(
0.09,
height,
depth,
palette.wood,
-width / 2,
0.58,
0,
group
);
box(
0.09,
height,
depth,
palette.wood,
width / 2,
0.58,
0,
group
);
box(
width - 0.12,
0.95,
0.05,
palette.cream,
0,
0.59,
-depth / 2 + 0.025,
group
);
for (const x of [-0.36, 0.36]) {
box(
0.065,
0.89,
depth - 0.05,
palette.wood,
x,
0.59,
0,
group
);
}
const bays = [-0.73, 0, 0.73];
for (const bay of bays) {
fillShelfBay(group, bay, 0.18, frequent);
fillShelfBay(group, bay, 0.65, frequent);
}
// Horizontal stack creates variety and avoids an overly uniform shelf.
for (let i = 0; i < 3; i++) {
makeBook(group, {
x: 0.73,
y: 0.66 + i * 0.055,
z: 0.02,
w: 0.43,
h: 0.05,
d: 0.35,
color: bookColors[(i + 2) % bookColors.length],
accent: frequent ? palette.mustard : palette.paper
});
}
const boardColor = frequent ? palette.coral : palette.paper;
const textColor = frequent ? palette.paper : palette.darkTeal;
sign(
group,
title,
1.34,
0.19,
0,
1.075,
depth / 2 + 0.025,
boardColor,
textColor,
58
);
sign(
group,
subtitle,
1.18,
0.12,
0,
0.61,
depth / 2 + 0.022,
frequent ? palette.mustard : palette.paper,
palette.darkTeal,
45
);
return group;
}
createLowShelf(
-1.15,
"NEW THIS MONTH",
"RECENTLY ADDED",
false
);
createLowShelf(
0.95,
"COMMUNITY FAVOURITES",
"MOST BORROWED",
true
);
createLowShelf(
3.05,
"QUICK PICKS",
"GRAB SOMETHING TO READ",
true
);
// Small entrance-side display: no reaching or crossing the route.
const quickDisplay = new THREE.Group();
quickDisplay.position.set(-1.08, 0, 3.92);
quickDisplay.rotation.y = Math.PI / 2;
scene.add(quickDisplay);
box(0.9, 0.09, 0.48, palette.lightWood, 0, 0.74, 0, quickDisplay);
box(0.9, 0.75, 0.07, palette.cream, 0, 0.37, -0.2, quickDisplay);
box(0.08, 0.78, 0.44, palette.wood, -0.43, 0.38, 0, quickDisplay);
box(0.08, 0.78, 0.44, palette.wood, 0.43, 0.38, 0, quickDisplay);
for (let i = 0; i < 4; i++) {
makeBook(quickDisplay, {
x: -0.27 + i * 0.18,
y: 0.8,
z: 0.03,
w: 0.14,
h: 0.32,
d: 0.3,
color: bookColors[i],
accent: palette.mustard
});
}
sign(
quickDisplay,
"START HERE",
0.82,
0.16,
0,
0.55,
0.23,
palette.coral,
palette.paper,
58
);
// -------------------------------------------------------------------------
// Tall archive storage at the quiet rear wall
// -------------------------------------------------------------------------
const archive = new THREE.Group();
archive.position.set(0, 0, -3.76);
scene.add(archive);
const cabinetCount = 6;
const cabinetWidth = 0.9;
for (let i = 0; i < cabinetCount; i++) {
const x = -1.25 + i * cabinetWidth;
box(
0.84,
2.67,
0.72,
i % 2 ? palette.teal : palette.darkTeal,
x,
1.43,
0,
archive
);
// Upper and lower solid archive doors.
box(
0.73,
1.05,
0.055,
i % 2 ? palette.darkTeal : palette.teal,
x,
2.12,
0.388,
archive
);
box(
0.73,
1.38,
0.055,
i % 2 ? palette.darkTeal : palette.teal,
x,
0.89,
0.388,
archive
);
box(
0.035,
0.29,
0.045,
palette.mustard,
x + 0.22,
1.45,
0.44,
archive
);
box(
0.035,
0.29,
0.045,
palette.mustard,
x + 0.22,
0.66,
0.44,
archive
);
sign(
archive,
`A${String(i + 1).padStart(2, "0")}`,
0.29,
0.12,
x,
1.46,
0.423,
palette.paper,
palette.darkTeal,
55
);
}
sign(
scene,
"REFERENCE ARCHIVE • QUIET STORAGE",
4.9,
0.31,
1.42,
3.05,
-3.36,
palette.darkTeal,
palette.paper,
55
);
// Rolling library ladder beside the archive.
const ladder = new THREE.Group();
ladder.position.set(4.58, 0, -3.06);
scene.add(ladder);
rod([-0.23, 0.08, 0.25], [-0.23, 2.2, -0.24], 0.035, palette.darkWood, ladder);
rod([0.23, 0.08, 0.25], [0.23, 2.2, -0.24], 0.035, palette.darkWood, ladder);
for (let i = 0; i < 7; i++) {
const t = i / 6;
const y = 0.2 + t * 1.83;
const z = 0.25 - t * 0.49;
box(0.46, 0.055, 0.13, palette.lightWood, 0, y, z, ladder);
}
// -------------------------------------------------------------------------
// Community board, title, and clock
// -------------------------------------------------------------------------
box(
2.65,
1.45,
0.11,
palette.darkWood,
-4.25,
1.9,
-4.28
);
box(
2.48,
1.28,
0.06,
0xb99363,
-4.25,
1.9,
-4.205
);
const noteColors = [
palette.paper,
palette.mustard,
palette.coral,
palette.blue
];
for (let i = 0; i < 8; i++) {
const note = box(
0.3 + random() * 0.12,
0.28 + random() * 0.12,
0.018,
noteColors[i % noteColors.length],
-5.16 + (i % 4) * 0.58,
2.22 - Math.floor(i / 4) * 0.56,
-4.16
);
note.rotation.z = (random() - 0.5) * 0.14;
}
sign(
scene,
"COMMUNITY BOARD",
2.15,
0.25,
-4.25,
2.85,
-4.31,
palette.paper,
palette.darkTeal,
55
);
sign(
scene,
"READ TOGETHER",
2.48,
0.3,
-4.25,
3.25,
-4.31,
palette.coral,
palette.paper,
60
);
const clock = cylinder(
0.34,
0.34,
0.08,
palette.paper,
5.16,
2.75,
-4.25,
scene,
40
);
clock.rotation.x = Math.PI / 2;
const clockRim = cylinder(
0.39,
0.39,
0.07,
palette.darkTeal,
5.16,
2.75,
-4.29,
scene,
40
);
clockRim.rotation.x = Math.PI / 2;
const handA = box(
0.035,
0.23,
0.025,
palette.ink,
5.16,
2.81,
-4.185
);
handA.rotation.z = -0.35;
const handB = box(
0.035,
0.16,
0.025,
palette.ink,
5.21,
2.72,
-4.182
);
handB.rotation.z = 0.8;
// -------------------------------------------------------------------------
// Reading table and chairs
// -------------------------------------------------------------------------
const table = new THREE.Group();
table.position.set(2.65, 0, 0.72);
scene.add(table);
cylinder(1.1, 1.1, 0.13, palette.lightWood, 0, 0.82, 0, table, 48);
cylinder(0.91, 0.91, 0.11, palette.wood, 0, 0.72, 0, table, 40);
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2 + 0.4;
cylinder(
0.075,
0.095,
0.68,
palette.darkWood,
Math.cos(angle) * 0.66,
0.36,
Math.sin(angle) * 0.66,
table,
16
);
}
function createChair(color, x, z, rotation) {
const chair = new THREE.Group();
chair.position.set(x, 0, z);
chair.rotation.y = rotation;
scene.add(chair);
box(0.7, 0.15, 0.68, color, 0, 0.47, 0, chair);
const back = box(
0.7,
0.64,
0.12,
color,
0,
0.85,
-0.3,
chair
);
back.rotation.x = -0.08;
for (const lx of [-0.27, 0.27]) {
for (const lz of [-0.25, 0.25]) {
cylinder(
0.035,
0.045,
0.4,
palette.darkWood,
lx,
0.2,
lz,
chair,
12
);
}
}
box(
0.52,
0.055,
0.48,
palette.paper,
0,
0.565,
0.02,
chair
);
return chair;
}
createChair(palette.teal, 2.65, -0.94, 0);
createChair(palette.coral, 2.65, 2.4, Math.PI);
createChair(palette.mustard, 4.12, 0.72, -Math.PI / 2);
// Additional upholstered bench.
const bench = new THREE.Group();
bench.position.set(3.9, 0, 3.05);
scene.add(bench);
box(1.55, 0.18, 0.65, palette.cream, 0, 0.46, 0, bench);
box(1.55, 0.13, 0.55, palette.coral, 0, 0.59, 0.02, bench);
const benchBack = box(
1.55,
0.62,
0.12,
palette.cream,
0,
0.87,
-0.3,
bench
);
benchBack.rotation.x = -0.08;
for (const x of [-0.62, 0.62]) {
for (const z of [-0.22, 0.22]) {
cylinder(
0.045,
0.055,
0.38,
palette.darkWood,
x,
0.2,
z,
bench,
12
);
}
}
// -------------------------------------------------------------------------
// Tabletop objects
// -------------------------------------------------------------------------
// Open book.
const openBook = new THREE.Group();
openBook.position.set(-0.24, 0.905, 0.05);
openBook.rotation.y = -0.22;
table.add(openBook);
const leftCover = box(
0.4,
0.035,
0.5,
palette.teal,
-0.2,
0,
0,
openBook
);
leftCover.rotation.z = 0.11;
const rightCover = box(
0.4,
0.035,
0.5,
palette.teal,
0.2,
0,
0,
openBook
);
rightCover.rotation.z = -0.11;
const leftPages = box(
0.37,
0.045,
0.46,
palette.paper,
-0.2,
0.04,
0,
openBook
);
leftPages.rotation.z = 0.11;
const rightPages = box(
0.37,
0.045,
0.46,
palette.paper,
0.2,
0.04,
0,
openBook
);
rightPages.rotation.z = -0.11;
// Stack of books.
makeBook(table, {
x: 0.55,
y: 0.9,
z: 0.22,
w: 0.48,
h: 0.075,
d: 0.37,
color: palette.coral,
accent: palette.mustard
});
makeBook(table, {
x: 0.53,
y: 0.975,
z: 0.2,
w: 0.43,
h: 0.07,
d: 0.34,
color: palette.blue,
accent: palette.paper
});
// Mug.
cylinder(0.13, 0.11, 0.22, palette.mustard, 0.48, 1.01, -0.37, table, 24);
cylinder(0.105, 0.105, 0.014, 0x49362f, 0.48, 1.126, -0.37, table, 24);
const handle = solid(
new THREE.TorusGeometry(0.09, 0.025, 10, 24),
palette.mustard,
table
);
handle.position.set(0.62, 1.02, -0.37);
// Small table lamp.
cylinder(0.18, 0.2, 0.05, palette.darkTeal, -0.02, 0.92, -0.55, table, 28);
cylinder(0.025, 0.025, 0.45, palette.darkTeal, -0.02, 1.14, -0.55, table, 12);
cylinder(
0.16,
0.31,
0.36,
palette.mustard,
-0.02,
1.42,
-0.55,
table,
32
);
// -------------------------------------------------------------------------
// Floor lamp, plant, and small wayfinding sign
// -------------------------------------------------------------------------
const floorLamp = new THREE.Group();
floorLamp.position.set(4.85, 0, -1.55);
scene.add(floorLamp);
cylinder(0.28, 0.32, 0.08, palette.darkTeal, 0, 0.06, 0, floorLamp, 32);
cylinder(0.025, 0.025, 1.68, palette.darkTeal, 0, 0.91, 0, floorLamp, 12);
cylinder(
0.24,
0.42,
0.52,
palette.mustard,
0,
1.85,
0,
floorLamp,
32
);
const lampLight = new THREE.PointLight(0xffd99b, 12, 5, 2);
lampLight.position.set(4.85, 1.7, -1.55);
scene.add(lampLight);
const plant = new THREE.Group();
plant.position.set(5.25, 0, 3.63);
scene.add(plant);
cylinder(
0.34,
0.26,
0.48,
palette.coral,
0,
0.25,
0,
plant,
28
);
cylinder(0.3, 0.3, 0.035, 0x665345, 0, 0.5, 0, plant, 28);
rod([0, 0.5, 0], [0.04, 1.55, 0], 0.025, palette.darkTeal, plant);
rod([-0.03, 0.54, 0], [-0.28, 1.25, 0.02], 0.02, palette.darkTeal, plant);
rod([0.02, 0.58, 0], [0.31, 1.33, -0.02], 0.02, palette.darkTeal, plant);
const leafColors = [0x557f66, 0x75966f, 0x3f725d];
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2;
const y = 0.78 + (i % 3) * 0.25;
const radius = 0.24 + random() * 0.08;
const leaf = sphere(
0.2,
leafColors[i % leafColors.length],
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius,
plant
);
leaf.scale.set(0.55, 1.55, 0.34);
leaf.rotation.z = Math.cos(angle) * 0.5;
leaf.rotation.y = -angle;
}
const startSign = new THREE.Group();
startSign.position.set(0.72, 0, 3.78);
scene.add(startSign);
cylinder(
0.045,
0.055,
1.1,
palette.darkWood,
0,
0.55,
0,
startSign,
14
);
sign(
startSign,
"READ • SHARE • RETURN",
1.12,
0.3,
0,
1.16,
0,
palette.paper,
palette.darkTeal,
45
);
// -------------------------------------------------------------------------
// Custom orthographic camera controls
// -------------------------------------------------------------------------
function updateCamera() {
const radius = 14;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
currentViewHeight = Math.max(7.4, 11.6 / aspect);
camera.left = (-currentViewHeight * aspect) / 2;
camera.right = (currentViewHeight * aspect) / 2;
camera.top = currentViewHeight / 2;
camera.bottom = -currentViewHeight / 2;
camera.zoom = zoom;
camera.updateProjectionMatrix();
updateCamera();
}
function resetCamera() {
target.copy(home.target);
theta = home.theta;
phi = home.phi;
zoom = home.zoom;
resize();
}
const pointers = new Map();
let pinchDistance = 0;
let interactionMode = "rotate";
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
interactionMode =
event.button === 2 || event.shiftKey ? "pan" : "rotate";
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
zoom = THREE.MathUtils.clamp(
zoom * (distance / pinchDistance),
0.65,
2.4
);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
pinchDistance = distance;
return;
}
if (interactionMode === "pan") {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const scale =
currentViewHeight / (camera.zoom * window.innerHeight);
target.addScaledVector(right, -dx * scale);
target.addScaledVector(up, dy * scale);
} else {
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.48, 1.42);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
remaining.x = remaining.x;
interactionMode = "rotate";
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.4
);
camera.zoom = zoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "+" || event.key === "=") {
zoom = Math.min(2.4, zoom * 1.1);
} else if (event.key === "-" || event.key === "_") {
zoom = Math.max(0.65, zoom / 1.1);
} else if (event.key.toLowerCase() === "r") {
resetCamera();
return;
} else {
if (event.key === "ArrowLeft") theta -= 0.08;
if (event.key === "ArrowRight") theta += 0.08;
if (event.key === "ArrowUp") phi -= 0.06;
if (event.key === "ArrowDown") phi += 0.06;
}
phi = THREE.MathUtils.clamp(phi, 0.48, 1.42);
camera.zoom = zoom;
camera.updateProjectionMatrix();
updateCamera();
});
document.getElementById("zoom-in").addEventListener("click", () => {
zoom = Math.min(2.4, zoom * 1.12);
camera.zoom = zoom;
camera.updateProjectionMatrix();
});
document.getElementById("zoom-out").addEventListener("click", () => {
zoom = Math.max(0.65, zoom / 1.12);
camera.zoom = zoom;
camera.updateProjectionMatrix();
});
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("resize", resize);
resize();
updateCamera();
loading.remove();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```