Prompt specification
Build or customize the Three.js 3D scene "Library entrance and quiet reading court" 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: Library entrance and quiet reading court
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/library-entrance-and-quiet-reading-court-x2211
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts thresholds between public and private spaces. Build a library cutaway linking street, lobby, staffed desk, and reading court. Show how increasingly quiet spaces remain connected through clearly placed thresholds and circulation. Low-poly.
Working Three.js Starter (library-entrance-and-quiet-reading-court-x2211):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Library Thresholds</title>
<style>
:root {
--ink: #263b3d;
--muted: #637173;
--paper: #f4f1e9;
--glass: rgba(247, 244, 236, 0.86);
--line: rgba(38, 59, 61, 0.16);
--public: #238d87;
--staff: #dc8b3f;
--quiet: #527a9b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#scene {
position: absolute;
inset: 0;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.header {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
max-width: 370px;
pointer-events: none;
}
.eyebrow {
display: block;
margin-bottom: 9px;
color: var(--public);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 48px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.035em;
}
.header p {
max-width: 310px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 20;
top: 24px;
right: 24px;
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--glass);
box-shadow: 0 12px 35px rgba(42, 55, 54, 0.09);
backdrop-filter: blur(12px);
}
.controls button {
min-height: 34px;
padding: 0 11px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: 160ms ease;
}
.controls button:hover,
.controls button.active {
border-color: rgba(35, 141, 135, 0.18);
background: rgba(35, 141, 135, 0.1);
color: var(--ink);
}
.legend {
position: fixed;
z-index: 10;
left: 30px;
bottom: 26px;
width: 255px;
padding: 15px 17px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--glass);
box-shadow: 0 12px 35px rgba(42, 55, 54, 0.07);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--muted);
}
.legend-row {
display: grid;
grid-template-columns: 11px 1fr auto;
align-items: center;
gap: 9px;
margin-top: 8px;
font-size: 11px;
}
.legend-row strong {
font-weight: 750;
}
.legend-row span:last-child {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.swatch.public {
background: var(--public);
}
.swatch.staff {
background: var(--staff);
}
.swatch.quiet {
background: var(--quiet);
}
.hint {
position: fixed;
right: 27px;
bottom: 29px;
z-index: 10;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
.hint strong {
color: var(--ink);
font-weight: 750;
}
#labels {
position: fixed;
inset: 0;
z-index: 8;
overflow: hidden;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.hidden {
opacity: 0;
}
.label {
position: absolute;
display: flex;
align-items: center;
gap: 9px;
min-width: 145px;
padding: 8px 11px 8px 8px;
border: 1px solid rgba(38, 59, 61, 0.13);
border-radius: 9px;
background: rgba(249, 247, 240, 0.91);
box-shadow: 0 8px 25px rgba(38, 59, 61, 0.1);
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
will-change: left, top;
}
.label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: rgba(38, 59, 61, 0.3);
}
.label-index {
display: grid;
flex: 0 0 auto;
place-items: center;
width: 29px;
height: 29px;
border-radius: 7px;
color: white;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.04em;
}
.label.public .label-index {
background: var(--public);
}
.label.staff .label-index {
background: var(--staff);
}
.label.quiet .label-index {
background: var(--quiet);
}
.label strong,
.label small {
display: block;
white-space: nowrap;
}
.label strong {
font-size: 11px;
line-height: 1.15;
}
.label small {
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #e9e5dc;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.header {
top: 19px;
left: 19px;
}
.header p {
display: none;
}
.controls {
top: 16px;
right: 16px;
}
.controls button {
padding: 0 8px;
font-size: 10px;
}
.legend {
left: 16px;
bottom: 17px;
width: 205px;
padding: 12px 13px;
}
.legend-title {
margin-bottom: 8px;
}
.legend-row {
margin-top: 6px;
}
.hint {
right: 16px;
bottom: 20px;
max-width: 120px;
text-align: right;
line-height: 1.5;
}
.label {
min-width: auto;
padding: 6px;
}
.label div:last-child {
display: none;
}
.label::after {
height: 12px;
}
}
</style>
</head>
<body>
<main id="app"></main>
<header class="header">
<span class="eyebrow">Spatial study / public to private</span>
<h1>Library<br />thresholds</h1>
<p>
A cutaway sequence connecting the street, civic lobby, staffed service desk,
and increasingly quiet reading court.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="oblique" class="active" type="button">3D</button>
<button id="plan" type="button">Plan</button>
<button id="route" class="active" type="button" aria-pressed="true">Route</button>
<button id="labels-toggle" class="active" type="button" aria-pressed="true">Labels</button>
<button id="reset" type="button">Reset</button>
</nav>
<section class="legend" aria-label="Space legend">
<div class="legend-title">Gradients of access</div>
<div class="legend-row">
<i class="swatch public"></i>
<strong>Street + lobby</strong>
<span>Public</span>
</div>
<div class="legend-row">
<i class="swatch staff"></i>
<strong>Staffed desk</strong>
<span>Supervised</span>
</div>
<div class="legend-row">
<i class="swatch quiet"></i>
<strong>Reading court</strong>
<span>Quiet</span>
</div>
</section>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom<br />
<strong>Double-click</strong> to reset
</div>
<div id="labels" aria-hidden="true"></div>
<div id="loading">Building the library…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const labelLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
// -----------------------------------------------------------------------
// Renderer, camera, and lighting
// -----------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5dc);
scene.fog = new THREE.Fog(0xe9e5dc, 42, 78);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.id = "scene";
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfffcf2, 0x837c70, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(-13, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -27;
sun.shadow.camera.right = 27;
sun.shadow.camera.top = 27;
sun.shadow.camera.bottom = -27;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7e4e3, 0.85);
fill.position.set(16, 10, -15);
scene.add(fill);
// -----------------------------------------------------------------------
// Materials and geometry helpers
// -----------------------------------------------------------------------
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const basic = (color, options = {}) =>
new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide,
...options
});
const M = {
ground: standard(0xd9d5cb),
plinth: standard(0x526366),
wall: standard(0xeee8dc),
wallEdge: standard(0xd8d0c1),
wood: standard(0xb98650),
woodLight: standard(0xd4aa72),
woodDark: standard(0x72543d),
lobby: standard(0xd7bd91),
staffFloor: standard(0xc7c9b9),
court: standard(0x91aaa5),
street: standard(0x465459),
sidewalk: standard(0xc9c5ba),
white: standard(0xf5f2e9),
charcoal: standard(0x2f4446),
teal: standard(0x2e807c),
public: standard(0x26958d),
staff: standard(0xd98a3d),
quiet: standard(0x527c9d),
route: standard(0x65b6aa, {
emissive: 0x164d48,
emissiveIntensity: 0.16
}),
glass: standard(0x8fb8bd, {
roughness: 0.35,
metalness: 0.05
}),
leaf: standard(0x527b58),
leafLight: standard(0x769267),
soil: standard(0x625346),
red: standard(0xc65f4b),
mustard: standard(0xd8a83c),
blue: standard(0x547d9b),
purple: standard(0x7b6687),
black: standard(0x293132)
};
const bookMaterials = [
M.teal,
M.staff,
M.blue,
M.red,
M.mustard,
M.purple,
M.woodLight,
M.quiet
];
function box(size, material, position, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
position,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function polygon(radius, material, position, parent = scene, detail = 0) {
const mesh = new THREE.Mesh(
new THREE.DodecahedronGeometry(radius, detail),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(position, parent = scene) {
const group = new THREE.Group();
group.position.set(position[0], position[1], position[2]);
parent.add(group);
return group;
}
let randomSeed = 1347;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// -----------------------------------------------------------------------
// Ground, street, and sidewalk
// -----------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
M.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.28;
ground.receiveShadow = true;
scene.add(ground);
box([18, 0.5, 18], M.plinth, [0, 0, 0]);
box([30, 0.13, 7], M.street, [0, -0.025, 15.1], scene, false);
box([30, 0.3, 2.8], M.sidewalk, [0, 0.13, 10.2], scene, false);
// Building floor fields.
box([17.5, 0.12, 7.45], M.lobby, [0, 0.31, 4.95], scene, false);
box([17.5, 0.12, 3.6], M.staffFloor, [0, 0.31, -0.3], scene, false);
box([17.5, 0.12, 6.3], M.court, [0, 0.31, -5.25], scene, false);
// Curb and road markings.
box([30, 0.13, 0.22], M.wallEdge, [0, 0.13, 11.62], scene, false);
for (let i = 0; i < 5; i++) {
box(
[3.15, 0.025, 0.46],
M.white,
[0, 0.057, 12.45 + i * 1.03],
scene,
false
);
}
for (let x = -13; x < 14; x += 3.3) {
box(
[1.45, 0.022, 0.12],
M.white,
[x, 0.057, 17.05],
scene,
false
);
}
// -----------------------------------------------------------------------
// Cutaway architecture
// -----------------------------------------------------------------------
// Tall rear and left walls define the cut section.
box([17.7, 4.7, 0.34], M.wall, [0, 2.6, -8.82]);
box([17.7, 0.12, 0.42], M.wallEdge, [0, 5.0, -8.82]);
box([0.34, 4.7, 17.55], M.wall, [-8.82, 2.6, -0.05]);
box([0.42, 0.12, 17.55], M.wallEdge, [-8.82, 5.0, -0.05]);
// Low cut walls on the open viewing sides.
box([0.3, 0.9, 17.55], M.wall, [8.82, 0.7, -0.05]);
box([6.95, 0.9, 0.3], M.wall, [-5.25, 0.7, 8.82]);
box([6.95, 0.9, 0.3], M.wall, [5.25, 0.7, 8.82]);
box([18, 0.1, 0.4], M.wallEdge, [0, 1.2, 8.82]);
box([0.4, 0.1, 17.6], M.wallEdge, [8.82, 1.2, -0.05]);
// Clerestory panels above the rear shelves.
[-6.7, -2.3, 2.1, 6.5].forEach((x) => {
box([2.65, 1.0, 0.06], M.glass, [x, 4.15, -8.62], scene, false);
box([0.08, 1.0, 0.09], M.charcoal, [x - 1.3, 4.15, -8.57]);
box([0.08, 1.0, 0.09], M.charcoal, [x + 1.3, 4.15, -8.57]);
});
// Lobby floor joints.
for (let x = -7; x <= 7; x += 1.75) {
box([0.018, 0.008, 7.1], M.woodLight, [x, 0.377, 4.95], scene, false);
}
for (let z = 2; z <= 8; z += 1.5) {
box([17.1, 0.008, 0.018], M.woodLight, [0, 0.377, z], scene, false);
}
// Entrance portal and threshold.
box([0.26, 3.25, 0.3], M.charcoal, [-1.55, 2.0, 8.82]);
box([0.26, 3.25, 0.3], M.charcoal, [1.55, 2.0, 8.82]);
box([3.36, 0.28, 0.3], M.charcoal, [0, 3.6, 8.82]);
box([3.22, 0.06, 0.34], M.staff, [0, 0.41, 8.83], scene, false);
box([2.65, 0.025, 1.1], M.charcoal, [0, 0.385, 7.95], scene, false);
// Street-edge threshold.
box([3.45, 0.055, 0.16], M.staff, [0, 0.315, 11.52], scene, false);
cylinder(0.13, 0.16, 0.82, 8, M.charcoal, [-1.75, 0.7, 11.5]);
cylinder(0.13, 0.16, 0.82, 8, M.charcoal, [1.75, 0.7, 11.5]);
// -----------------------------------------------------------------------
// Circulation inlay
// -----------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
// Sidewalk segment.
box([1.65, 0.035, 2.75], M.route, [0, 0.298, 10.2], routeGroup, false);
// Lobby sequence.
box([1.65, 0.035, 7.3], M.route, [0, 0.397, 4.95], routeGroup, false);
// Turn around the staffed desk.
box([5.6, 0.035, 1.65], M.route, [2.8, 0.397, 1.45], routeGroup, false);
box([1.65, 0.035, 3.6], M.route, [5.6, 0.397, -0.35], routeGroup, false);
// Quiet-court aisle.
box([1.65, 0.035, 6.2], M.route, [5.6, 0.397, -5.3], routeGroup, false);
function floorArrow(x, z, angle = 0, y = 0.427) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.23, 0, 0.19,
0.23, 0, 0.19,
0, 0, -0.29
],
3
)
);
geometry.computeVertexNormals();
const arrow = new THREE.Mesh(geometry, basic(0xf8f4df));
arrow.position.set(x, y, z);
arrow.rotation.y = angle;
routeGroup.add(arrow);
}
floorArrow(0, 14.1, 0, 0.075);
floorArrow(0, 10.55, 0, 0.33);
floorArrow(0, 7.4);
floorArrow(0, 4.7);
floorArrow(0, 2.3);
floorArrow(2.8, 1.45, -Math.PI / 2);
floorArrow(5.6, -0.2);
floorArrow(5.6, -3.7);
floorArrow(5.6, -6.7);
// Animated circulation marker.
const movingMarker = new THREE.Group();
const markerCore = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.14, 1),
basic(0xe9fff3)
);
const markerHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.035, 6, 18),
basic(0x80e3cc, { transparent: true, opacity: 0.85 })
);
markerHalo.rotation.x = Math.PI / 2;
movingMarker.add(markerCore, markerHalo);
routeGroup.add(movingMarker);
const routePoints = [
new THREE.Vector3(0, 0.2, 16.3),
new THREE.Vector3(0, 0.49, 11.55),
new THREE.Vector3(0, 0.51, 8.75),
new THREE.Vector3(0, 0.51, 1.45),
new THREE.Vector3(5.6, 0.51, 1.45),
new THREE.Vector3(5.6, 0.51, -2.15),
new THREE.Vector3(5.6, 0.51, -8.0)
];
const routeLengths = [];
let totalRouteLength = 0;
for (let i = 0; i < routePoints.length - 1; i++) {
const length = routePoints[i].distanceTo(routePoints[i + 1]);
routeLengths.push(length);
totalRouteLength += length;
}
function placeRouteMarker(distance) {
let remaining = distance;
for (let i = 0; i < routeLengths.length; i++) {
if (remaining <= routeLengths[i]) {
const amount = remaining / routeLengths[i];
movingMarker.position.lerpVectors(
routePoints[i],
routePoints[i + 1],
amount
);
return;
}
remaining -= routeLengths[i];
}
movingMarker.position.copy(routePoints.at(-1));
}
// -----------------------------------------------------------------------
// Staffed threshold and service desk
// -----------------------------------------------------------------------
// Low partition separates the staff strip from the quiet court.
box([12.2, 1.22, 0.24], M.woodDark, [-2.45, 0.99, -2.12]);
box([1.25, 1.22, 0.24], M.woodDark, [7.98, 0.99, -2.12]);
// Slatted upper screen preserves visual connection.
for (let x = -7.9; x < 3.45; x += 0.82) {
box([0.11, 1.05, 0.16], M.woodLight, [x, 2.14, -2.12]);
}
// Quiet portal.
box([0.18, 2.5, 0.24], M.quiet, [3.75, 1.62, -2.12]);
box([0.18, 2.5, 0.24], M.quiet, [7.35, 1.62, -2.12]);
box([3.78, 0.22, 0.24], M.quiet, [5.55, 2.87, -2.12]);
box([3.45, 0.055, 0.28], M.quiet, [5.55, 0.41, -2.12], scene, false);
// Staff desk.
box([5.8, 0.82, 1.15], M.teal, [0, 0.78, 0.25]);
box([6.05, 0.13, 1.35], M.woodLight, [0, 1.255, 0.25]);
box([6.0, 0.055, 0.15], M.staff, [0, 0.405, 0.91], scene, false);
// Desk equipment.
box([0.18, 0.4, 0.18], M.charcoal, [0.8, 1.5, 0.12]);
const monitor = box(
[1.12, 0.64, 0.12],
M.charcoal,
[0.8, 1.88, 0.12]
);
monitor.rotation.x = -0.08;
box([0.93, 0.43, 0.025], M.glass, [0.8, 1.89, 0.196]);
cylinder(0.18, 0.22, 0.06, 8, M.charcoal, [-1.75, 1.325, 0.22]);
cylinder(0.035, 0.035, 0.58, 6, M.charcoal, [-1.75, 1.62, 0.22]);
const deskLamp = cylinder(
0.04,
0.22,
0.22,
8,
M.staff,
[-1.75, 1.92, 0.22]
);
deskLamp.rotation.z = -0.45;
for (let i = 0; i < 3; i++) {
box(
[0.72 - i * 0.06, 0.08, 0.48],
bookMaterials[i],
[1.9, 1.37 + i * 0.085, 0.2]
);
}
// -----------------------------------------------------------------------
// People
// -----------------------------------------------------------------------
function createPerson(x, z, shirt, rotation = 0, scale = 1) {
const person = groupAt([x, 0.37, z]);
person.rotation.y = rotation;
person.scale.setScalar(scale);
cylinder(0.1, 0.12, 0.55, 6, M.charcoal, [-0.13, 0.28, 0], person);
cylinder(0.1, 0.12, 0.55, 6, M.charcoal, [0.13, 0.28, 0], person);
cylinder(0.27, 0.32, 0.62, 6, standard(shirt), [0, 0.84, 0], person);
polygon(0.235, standard(0xc8916c), [0, 1.37, 0], person);
cylinder(0.085, 0.085, 0.56, 6, standard(shirt), [-0.35, 0.82, 0], person);
cylinder(0.085, 0.085, 0.56, 6, standard(shirt), [0.35, 0.82, 0], person);
return person;
}
createPerson(0, -0.75, 0xc66e56, 0, 0.92);
createPerson(2.35, 10.35, 0xd2a53b, Math.PI, 0.94);
createPerson(-3.5, 3.0, 0x547d9b, 0.6, 0.9);
// -----------------------------------------------------------------------
// Lobby furniture and planting
// -----------------------------------------------------------------------
function createSofa(x, z, rotation = 0) {
const sofa = groupAt([x, 0.37, z]);
sofa.rotation.y = rotation;
box([3.5, 0.45, 1.05], M.teal, [0, 0.25, 0], sofa);
box([3.5, 0.7, 0.24], M.teal, [0, 0.78, -0.43], sofa);
box([0.25, 0.62, 1.05], M.teal, [-1.68, 0.56, 0], sofa);
box([0.25, 0.62, 1.05], M.teal, [1.68, 0.56, 0], sofa);
box([0.68, 0.46, 0.18], M.staff, [-0.92, 0.69, -0.27], sofa);
box([0.68, 0.46, 0.18], M.mustard, [0.88, 0.69, -0.27], sofa);
box([2.8, 0.12, 0.68], M.woodLight, [0, 0.53, 0.72], sofa);
box([0.18, 0.45, 0.18], M.charcoal, [-1.05, 0.22, 0.72], sofa);
box([0.18, 0.45, 0.18], M.charcoal, [1.05, 0.22, 0.72], sofa);
}
createSofa(-5.15, 5.05, 0);
// Small public table and chairs.
cylinder(0.72, 0.72, 0.11, 12, M.woodLight, [-4.7, 1.12, 7.0]);
cylinder(0.08, 0.13, 0.72, 8, M.charcoal, [-4.7, 0.72, 7.0]);
function createChair(x, z, rotation = 0, material = M.charcoal) {
const chair = groupAt([x, 0.37, z]);
chair.rotation.y = rotation;
box([0.72, 0.12, 0.72], material, [0, 0.52, 0], chair);
box([0.72, 0.78, 0.12], material, [0, 0.95, -0.3], chair);
box([0.08, 0.48, 0.08], M.woodDark, [-0.27, 0.24, -0.25], chair);
box([0.08, 0.48, 0.08], M.woodDark, [0.27, 0.24, -0.25], chair);
box([0.08, 0.48, 0.08], M.woodDark, [-0.27, 0.24, 0.25], chair);
box([0.08, 0.48, 0.08], M.woodDark, [0.27, 0.24, 0.25], chair);
}
createChair(-5.65, 7.0, Math.PI / 2, M.mustard);
createChair(-3.75, 7.0, -Math.PI / 2, M.mustard);
// Information kiosk.
cylinder(0.42, 0.52, 0.12, 8, M.charcoal, [4.7, 0.44, 4.55]);
cylinder(0.08, 0.1, 1.05, 8, M.charcoal, [4.7, 0.98, 4.55]);
const kiosk = box(
[0.92, 0.66, 0.15],
M.charcoal,
[4.7, 1.67, 4.55]
);
kiosk.rotation.x = -0.2;
box([0.74, 0.48, 0.02], M.glass, [4.7, 1.69, 4.64]);
function createPlant(x, z, scale = 1) {
const plant = groupAt([x, 0.37, z]);
plant.scale.setScalar(scale);
cylinder(0.38, 0.28, 0.68, 8, M.woodLight, [0, 0.34, 0], plant);
cylinder(0.055, 0.075, 1.05, 6, M.woodDark, [0, 1.18, 0], plant);
const leaf1 = polygon(0.57, M.leaf, [0, 1.55, 0], plant);
leaf1.scale.set(0.75, 1.25, 0.75);
leaf1.rotation.z = 0.35;
const leaf2 = polygon(0.48, M.leafLight, [0.2, 1.85, 0.05], plant);
leaf2.scale.set(0.8, 1.15, 0.7);
leaf2.rotation.z = -0.55;
const leaf3 = polygon(0.4, M.leaf, [-0.18, 1.75, 0.08], plant);
leaf3.scale.set(0.7, 1.05, 0.72);
leaf3.rotation.z = 0.7;
}
createPlant(-7.25, 7.2, 1.05);
createPlant(7.15, 6.15, 0.9);
createPlant(7.75, -7.55, 0.92);
// Library symbol near the entrance.
cylinder(0.065, 0.08, 1.5, 6, M.charcoal, [-3.05, 1.13, 8.25]);
box([1.5, 0.85, 0.14], M.charcoal, [-3.05, 1.96, 8.25]);
const pageLeft = box(
[0.56, 0.48, 0.07],
M.white,
[-3.32, 1.98, 8.34]
);
pageLeft.rotation.z = 0.2;
const pageRight = box(
[0.56, 0.48, 0.07],
M.white,
[-2.78, 1.98, 8.34]
);
pageRight.rotation.z = -0.2;
// -----------------------------------------------------------------------
// Reading court: shelving, books, tables, and seated readers
// -----------------------------------------------------------------------
function createShelf(x, z, rotation = 0, width = 3.15) {
const shelf = groupAt([x, 0.37, z]);
shelf.rotation.y = rotation;
box([width, 3.35, 0.12], M.woodDark, [0, 1.68, -0.36], shelf);
box([0.13, 3.35, 0.78], M.woodDark, [-width / 2, 1.68, 0], shelf);
box([0.13, 3.35, 0.78], M.woodDark, [width / 2, 1.68, 0], shelf);
[0.15, 1.16, 2.17, 3.18].forEach((y) => {
box([width, 0.12, 0.78], M.wood, [0, y, 0], shelf);
});
for (let row = 0; row < 3; row++) {
let cursor = -width / 2 + 0.18;
while (cursor < width / 2 - 0.25) {
const bookWidth = 0.15 + random() * 0.13;
const bookHeight = 0.48 + random() * 0.37;
const depth = 0.4 + random() * 0.09;
const material = bookMaterials[Math.floor(random() * bookMaterials.length)];
box(
[bookWidth, bookHeight, depth],
material,
[
cursor + bookWidth / 2,
0.21 + row + bookHeight / 2,
0.04
],
shelf
);
cursor += bookWidth + 0.025 + random() * 0.045;
}
}
return shelf;
}
createShelf(-6.0, -7.95, 0, 3.15);
createShelf(-2.2, -7.95, 0, 3.15);
createShelf(1.6, -7.95, 0, 3.15);
createShelf(-7.98, -5.95, Math.PI / 2, 2.45);
function createReadingTable(x, z) {
const table = groupAt([x, 0.37, z]);
box([2.4, 0.12, 1.25], M.woodLight, [0, 0.88, 0], table);
box([0.12, 0.82, 0.12], M.charcoal, [-0.91, 0.41, -0.43], table);
box([0.12, 0.82, 0.12], M.charcoal, [0.91, 0.41, -0.43], table);
box([0.12, 0.82, 0.12], M.charcoal, [-0.91, 0.41, 0.43], table);
box([0.12, 0.82, 0.12], M.charcoal, [0.91, 0.41, 0.43], table);
box([0.72, 0.065, 0.48], M.blue, [-0.3, 0.975, 0.04], table);
box([0.66, 0.05, 0.43], M.white, [-0.3, 1.03, 0.04], table);
cylinder(0.09, 0.11, 0.22, 8, M.staff, [0.62, 1.05, 0.12], table);
createChair(x, z + 1.08, Math.PI, M.quiet);
createChair(x, z - 1.08, 0, M.quiet);
}
createReadingTable(-5.25, -5.35);
createReadingTable(-1.65, -5.35);
createReadingTable(1.95, -5.35);
// A seated reader at the middle table.
const reader = groupAt([-1.65, 0.37, -4.27]);
cylinder(0.24, 0.28, 0.6, 6, M.red, [0, 0.9, 0], reader);
polygon(0.22, standard(0xc98e68), [0, 1.38, 0], reader);
cylinder(0.08, 0.08, 0.5, 6, M.red, [-0.28, 0.91, 0.13], reader).rotation.x = -0.7;
cylinder(0.08, 0.08, 0.5, 6, M.red, [0.28, 0.91, 0.13], reader).rotation.x = -0.7;
// Quiet reading nook near the portal.
box([1.65, 0.38, 1.65], M.quiet, [2.3, 0.58, -3.25]);
box([1.65, 0.9, 0.23], M.quiet, [2.3, 1.0, -3.94]);
// -----------------------------------------------------------------------
// Street furniture, trees, and low-poly cars
// -----------------------------------------------------------------------
function createTree(x, z, scale = 1) {
const tree = groupAt([x, 0.28, z]);
tree.scale.setScalar(scale);
box([1.45, 0.42, 1.45], M.wallEdge, [0, 0.21, 0], tree);
box([1.22, 0.07, 1.22], M.soil, [0, 0.44, 0], tree);
cylinder(0.14, 0.21, 1.75, 7, M.woodDark, [0, 1.3, 0], tree);
const crown1 = polygon(0.92, M.leaf, [0, 2.5, 0], tree);
crown1.scale.set(0.95, 1.18, 0.9);
const crown2 = polygon(0.68, M.leafLight, [0.42, 3.0, 0.08], tree);
crown2.scale.set(0.95, 1.0, 0.85);
const crown3 = polygon(0.58, M.leaf, [-0.42, 2.9, -0.08], tree);
crown3.scale.set(0.9, 1.0, 0.8);
}
createTree(-6.9, 10.3, 0.92);
createTree(6.8, 10.25, 0.88);
function createLamp(x, z) {
cylinder(0.06, 0.09, 4.1, 8, M.charcoal, [x, 2.3, z]);
box([0.85, 0.09, 0.09], M.charcoal, [x + 0.35, 4.3, z]);
box([0.52, 0.16, 0.3], M.staff, [x + 0.68, 4.2, z]);
}
createLamp(-8.45, 10.65);
createLamp(8.4, 10.65);
function createBench(x, z, rotation = 0) {
const bench = groupAt([x, 0.28, z]);
bench.rotation.y = rotation;
box([2.25, 0.14, 0.55], M.wood, [0, 0.62, 0], bench);
box([2.25, 0.55, 0.12], M.wood, [0, 0.98, -0.23], bench);
box([0.12, 0.55, 0.45], M.charcoal, [-0.82, 0.3, 0], bench);
box([0.12, 0.55, 0.45], M.charcoal, [0.82, 0.3, 0], bench);
}
createBench(4.55, 9.45, 0);
createBench(-8.05, 9.45, 0);
function createCar(x, z, rotation, color) {
const car = groupAt([x, 0.04, z]);
car.rotation.y = rotation;
const bodyMaterial = standard(color);
box([3.9, 0.52, 1.62], bodyMaterial, [0, 0.48, 0], car);
box([2.05, 0.48, 1.42], M.glass, [-0.15, 0.96, 0], car);
box([3.95, 0.12, 1.68], M.charcoal, [0, 0.31, 0], car);
[-1.25, 1.25].forEach((wheelX) => {
[-0.84, 0.84].forEach((wheelZ) => {
const wheel = cylinder(
0.31,
0.31,
0.19,
10,
M.black,
[wheelX, 0.3, wheelZ],
car
);
wheel.rotation.x = Math.PI / 2;
});
});
box([0.08, 0.16, 0.42], M.white, [1.98, 0.58, 0.48], car);
box([0.08, 0.16, 0.42], M.white, [1.98, 0.58, -0.48], car);
}
createCar(-7.6, 15.1, 0, 0xc86450);
createCar(8.25, 14.8, Math.PI, 0x5e8390);
// -----------------------------------------------------------------------
// Projected HTML labels
// -----------------------------------------------------------------------
const labelDefinitions = [
{
id: "street",
number: "01",
title: "Street",
subtitle: "Public threshold",
type: "public",
position: new THREE.Vector3(0, 3.25, 12.75),
marker: new THREE.Vector3(0, 0.62, 11.52),
markerColor: M.public
},
{
id: "lobby",
number: "02",
title: "Lobby",
subtitle: "Open civic space",
type: "public",
position: new THREE.Vector3(-5.15, 2.8, 5.05),
marker: new THREE.Vector3(-5.15, 0.56, 5.05),
markerColor: M.public
},
{
id: "desk",
number: "03",
title: "Staffed desk",
subtitle: "Supervised threshold",
type: "staff",
position: new THREE.Vector3(0, 2.72, 0.22),
marker: new THREE.Vector3(0, 0.56, 0.9),
markerColor: M.staff
},
{
id: "court",
number: "04",
title: "Reading court",
subtitle: "Quiet threshold",
type: "quiet",
position: new THREE.Vector3(1.55, 2.75, -6.2),
marker: new THREE.Vector3(1.55, 0.56, -5.35),
markerColor: M.quiet
}
];
const projectedLabels = [];
labelDefinitions.forEach((definition) => {
const element = document.createElement("div");
element.className = `label ${definition.type}`;
element.innerHTML = `
<span class="label-index">${definition.number}</span>
<div>
<strong>${definition.title}</strong>
<small>${definition.subtitle}</small>
</div>
`;
labelLayer.appendChild(element);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.18, 0),
definition.markerColor
);
marker.position.copy(definition.marker);
marker.castShadow = true;
scene.add(marker);
projectedLabels.push({ element, position: definition.position });
});
// -----------------------------------------------------------------------
// Custom orbit controls — no external controls addon
// -----------------------------------------------------------------------
const orbit = {
goalTheta: 0.72,
goalPhi: 1.0,
goalRadius: 31,
theta: 0.72,
phi: 1.0,
radius: 31,
goalTarget: new THREE.Vector3(0, 1.0, 1.0),
target: new THREE.Vector3(0, 1.0, 1.0)
};
const pointerMap = new Map();
let dragging = false;
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 1) {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.classList.add("dragging");
} else if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerMap.has(event.pointerId)) return;
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * (pinchDistance / distance),
18,
44
);
}
return;
}
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
orbit.goalTheta -= dx * 0.006;
orbit.goalPhi = THREE.MathUtils.clamp(
orbit.goalPhi - dy * 0.005,
0.1,
1.36
);
lastX = event.clientX;
lastY = event.clientY;
});
function endPointer(event) {
pointerMap.delete(event.pointerId);
if (pointerMap.size === 0) {
dragging = false;
pinchDistance = 0;
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * Math.exp(event.deltaY * 0.001),
18,
44
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key === "ArrowLeft") orbit.goalTheta += 0.08;
if (event.key === "ArrowRight") orbit.goalTheta -= 0.08;
if (event.key === "ArrowUp") orbit.goalPhi -= 0.06;
if (event.key === "ArrowDown") orbit.goalPhi += 0.06;
if (event.key === "+" || event.key === "=") orbit.goalRadius -= 1;
if (event.key === "-") orbit.goalRadius += 1;
});
function updateCamera() {
orbit.theta += (orbit.goalTheta - orbit.theta) * 0.1;
orbit.phi += (orbit.goalPhi - orbit.phi) * 0.1;
orbit.radius += (orbit.goalRadius - orbit.radius) * 0.1;
orbit.target.lerp(orbit.goalTarget, 0.1);
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function setViewButton(activeId) {
document.querySelectorAll(".controls button").forEach((button) => {
button.classList.toggle("view-active", button.id === activeId);
});
}
function resetCamera() {
orbit.goalTheta = 0.72;
orbit.goalPhi = 1.0;
orbit.goalRadius = 31;
orbit.goalTarget.set(0, 1.0, 1.0);
setViewButton("oblique");
}
document.querySelector("#reset").addEventListener("click", resetCamera);
document.querySelector("#oblique").addEventListener("click", () => {
orbit.goalTheta = 0.72;
orbit.goalPhi = 1.0;
orbit.goalRadius = 31;
orbit.goalTarget.set(0, 1.0, 1.0);
setViewButton("oblique");
});
document.querySelector("#plan").addEventListener("click", () => {
orbit.goalTheta = 0;
orbit.goalPhi = 0.1;
orbit.goalRadius = 34;
orbit.goalTarget.set(0, 0, 1.5);
setViewButton("plan");
});
document.querySelector("#route").addEventListener("click", (event) => {
routeGroup.visible = !routeGroup.visible;
event.currentTarget.classList.toggle("active", routeGroup.visible);
event.currentTarget.setAttribute("aria-pressed", String(routeGroup.visible));
});
document.querySelector("#labels-toggle").addEventListener("click", (event) => {
const hidden = labelLayer.classList.toggle("hidden");
event.currentTarget.classList.toggle("active", !hidden);
event.currentTarget.setAttribute("aria-pressed", String(!hidden));
});
// -----------------------------------------------------------------------
// Resize and animation
// -----------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const projectionVector = new THREE.Vector3();
function updateLabels() {
projectedLabels.forEach(({ element, position }) => {
projectionVector.copy(position).project(camera);
const visible =
projectionVector.z > -1 &&
projectionVector.z < 1 &&
Math.abs(projectionVector.x) < 1.15 &&
Math.abs(projectionVector.y) < 1.15;
element.style.opacity = visible ? "1" : "0";
if (visible) {
element.style.left = `${(projectionVector.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projectionVector.y * 0.5 + 0.5) * innerHeight}px`;
}
});
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
updateLabels();
placeRouteMarker((elapsed * 1.85) % totalRouteLength);
markerHalo.rotation.z += 0.015;
markerHalo.scale.setScalar(1 + Math.sin(elapsed * 3) * 0.09);
renderer.render(scene, camera);
}
updateCamera();
renderer.render(scene, camera);
loading.classList.add("done");
setTimeout(() => loading.remove(), 350);
animate();
</script>
</body>
</html>
```