Prompt specification
Build or customize the Three.js 3D scene "Apartment music practice nook" 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: Apartment music practice nook
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/apartment-music-practice-nook-x0163
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Compose a music corner with instrument stand, curtains, rug, and bookcase; toggles reveal labeled schematic sound paths through different surface arrangements without promising real acoustic performance.
Working Three.js Starter (apartment-music-practice-nook-x0163):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light" />
<title>The Listening Corner</title>
<style>
:root {
--ink: #24342f;
--muted: #6f7771;
--paper: #f7f2e9;
--panel: rgba(255, 253, 248, 0.92);
--line: rgba(36, 52, 47, 0.13);
--accent: #d7654d;
--teal: #257b72;
--gold: #d4a23f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e1d4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app {
position: fixed;
inset: 0;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.header {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
width: min(420px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #53615b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.wave {
display: inline-flex;
align-items: center;
gap: 3px;
height: 15px;
}
.wave span {
width: 2px;
border-radius: 2px;
background: var(--accent);
}
.wave span:nth-child(1) { height: 6px; }
.wave span:nth-child(2) { height: 13px; }
.wave span:nth-child(3) { height: 9px; }
.wave span:nth-child(4) { height: 15px; }
.wave span:nth-child(5) { height: 7px; }
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4vw, 54px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.header p {
max-width: 360px;
margin: 13px 0 0;
color: #5f6a64;
font-size: 13px;
line-height: 1.55;
}
.gesture {
margin-top: 10px;
color: #7b817d;
font-size: 10px;
letter-spacing: 0.04em;
}
.status-card {
position: fixed;
z-index: 5;
top: 28px;
right: 30px;
min-width: 168px;
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 14px;
background: rgba(255, 253, 248, 0.72);
box-shadow: 0 12px 35px rgba(61, 48, 34, 0.08);
backdrop-filter: blur(12px);
text-align: right;
pointer-events: none;
}
#status {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-card small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.04em;
}
.control-panel {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
width: min(920px, calc(100vw - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: minmax(300px, 1fr) auto;
gap: 18px 24px;
padding: 17px 19px 15px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(62, 47, 32, 0.16),
inset 0 0 0 1px rgba(46, 56, 51, 0.04);
backdrop-filter: blur(18px);
}
.panel-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 15px;
margin-bottom: 10px;
}
.panel-title strong {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-title span {
color: var(--muted);
font-size: 10px;
}
.arrangements {
display: flex;
gap: 7px;
}
.arrangement {
appearance: none;
flex: 1;
min-width: 0;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.55);
color: #59635e;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
color 160ms ease,
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.arrangement:hover {
transform: translateY(-1px);
border-color: rgba(36, 52, 47, 0.28);
}
.arrangement.active {
border-color: var(--ink);
background: var(--ink);
color: white;
}
#description {
min-height: 31px;
margin: 9px 2px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.panel-tools {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 14px;
padding-top: 2px;
}
.toggle {
position: relative;
display: flex;
align-items: center;
gap: 8px;
color: #4d5954;
cursor: pointer;
font-size: 10px;
font-weight: 750;
white-space: nowrap;
}
.toggle input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
pointer-events: none;
}
.switch {
position: relative;
width: 34px;
height: 19px;
border-radius: 20px;
background: #c9cbc6;
box-shadow: inset 0 0 0 1px rgba(30, 40, 36, 0.08);
transition: background 160ms ease;
}
.switch::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(30, 40, 36, 0.2);
transition: transform 160ms ease;
}
.toggle input:checked + .switch {
background: var(--teal);
}
.toggle input:checked + .switch::after {
transform: translateX(15px);
}
.toggle input:focus-visible + .switch {
outline: 2px solid var(--gold);
outline-offset: 3px;
}
.toggle input:disabled + .switch {
opacity: 0.4;
}
.reset {
appearance: none;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.55);
color: #59635e;
cursor: pointer;
font-size: 10px;
font-weight: 750;
transition: background 160ms ease;
}
.reset:hover {
background: white;
}
.disclaimer {
grid-column: 1 / -1;
display: flex;
align-items: center;
gap: 9px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #7c766d;
font-size: 9px;
line-height: 1.4;
}
.disclaimer::before {
content: "i";
display: grid;
flex: 0 0 auto;
width: 16px;
height: 16px;
place-items: center;
border: 1px solid #aaa49a;
border-radius: 50%;
color: #777168;
font-family: Georgia, serif;
font-size: 10px;
font-style: italic;
}
.path-label {
position: absolute;
left: 0;
top: 0;
padding: 6px 9px;
border-left: 3px solid var(--route, #257b72);
border-radius: 5px;
background: rgba(255, 253, 248, 0.93);
box-shadow: 0 5px 16px rgba(43, 42, 35, 0.12);
color: #34423d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
will-change: left, top;
}
.path-label.marker {
padding: 5px 7px;
border: 1px solid color-mix(in srgb, var(--route) 55%, transparent);
border-left-width: 1px;
border-radius: 20px;
background: rgba(255, 253, 248, 0.86);
font-size: 8px;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #eee7db;
color: #53615b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
font-size: 34px;
}
.header p {
max-width: 290px;
font-size: 11px;
}
.gesture {
display: none;
}
.status-card {
top: auto;
right: 14px;
bottom: 206px;
min-width: 132px;
padding: 9px 11px;
}
.control-panel {
bottom: 10px;
width: calc(100vw - 20px);
grid-template-columns: 1fr;
gap: 10px;
padding: 13px;
border-radius: 17px;
}
.panel-title {
margin-bottom: 7px;
}
.panel-title span {
display: none;
}
.arrangement {
padding: 8px 6px;
font-size: 9px;
}
#description {
min-height: 27px;
margin-top: 7px;
}
.panel-tools {
justify-content: space-between;
gap: 8px;
}
.disclaimer {
padding-top: 8px;
}
}
</style>
</head>
<body>
<div id="app">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional listening corner. Drag to orbit, scroll to zoom, and use arrow keys to move the camera."
></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="header">
<div class="eyebrow">
<span class="wave" aria-hidden="true">
<span></span><span></span><span></span><span></span><span></span>
</span>
Room sketch / 01
</div>
<h1>The Listening Corner</h1>
<p>
A small music room with books, drapes, a rug, and a guitar.
Switch the surface arrangement to compare schematic path ideas.
</p>
<div class="gesture">
Drag to orbit · Scroll to zoom · Shift-drag to pan · Double-click to reset
</div>
</header>
<aside class="status-card" aria-live="polite">
<div id="status">Drapes · Paths on</div>
<small>Illustrative geometry only</small>
</aside>
<section class="control-panel" aria-label="Scene controls">
<div>
<div class="panel-title">
<strong>Surface arrangement</strong>
<span>Choose a visual treatment</span>
</div>
<div class="arrangements" role="group" aria-label="Surface arrangements">
<button class="arrangement active" data-arrangement="drapes" type="button">
Drapes
</button>
<button class="arrangement" data-arrangement="reflectors" type="button">
Reflectors
</button>
<button class="arrangement" data-arrangement="diffuser" type="button">
Diffuser
</button>
<button class="arrangement" data-arrangement="bare" type="button">
Bare
</button>
</div>
<p id="description" aria-live="polite">
A return-path sketch toward a visually heavy, pleated drape.
</p>
</div>
<div class="panel-tools">
<label class="toggle">
<input id="pathsToggle" type="checkbox" checked />
<span class="switch" aria-hidden="true"></span>
Sound paths
</label>
<label class="toggle">
<input id="labelsToggle" type="checkbox" checked />
<span class="switch" aria-hidden="true"></span>
Labels
</label>
<button id="resetCamera" class="reset" type="button">
Reset view
</button>
</div>
<div class="disclaimer">
Schematic only. The colored routes are explanatory illustrations—not an
acoustic simulation, measurement, or prediction of real sound performance.
</div>
</section>
<div id="loading">Building the listening corner…</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const statusEl = document.querySelector("#status");
const descriptionEl = document.querySelector("#description");
const pathsToggle = document.querySelector("#pathsToggle");
const labelsToggle = document.querySelector("#labelsToggle");
const resetCameraButton = document.querySelector("#resetCamera");
const arrangementButtons = [
...document.querySelectorAll(".arrangement")
];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e1d4");
scene.fog = new THREE.Fog("#e9e1d4", 19, 33);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(
"#fff8e9",
"#84715d",
2.15
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff4dc", 3.3);
keyLight.position.set(6.5, 10.5, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#bad7d1", 1.15);
fillLight.position.set(-7, 5, 2);
scene.add(fillLight);
const lampLight = new THREE.PointLight("#ffd58a", 18, 7, 2);
lampLight.position.set(-5.15, 3.25, 1.55);
scene.add(lampLight);
const palette = {
ink: "#263b35",
dark: "#34443f",
wood: "#9a6947",
lightWood: "#c99a65",
paleWood: "#ddbd8c",
teal: "#347f75",
coral: "#cc674f",
gold: "#d5a743",
cream: "#eee2ca",
blue: "#517d98",
plum: "#8c6687",
creamWhite: "#f7efe0"
};
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
}
function addBox(
parent,
size,
position,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
standardMaterial(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
options.segments || 24
),
standardMaterial(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const yAxis = new THREE.Vector3(0, 1, 0);
function addCylinderBetween(parent, a, b, radius, color, options = {}) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
options.segments || 12
),
standardMaterial(color, options)
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
yAxis,
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRectShape(width, depth, radius) {
const w = width / 2;
const d = depth / 2;
const r = radius;
const shape = new THREE.Shape();
shape.moveTo(-w + r, -d);
shape.lineTo(w - r, -d);
shape.quadraticCurveTo(w, -d, w, -d + r);
shape.lineTo(w, d - r);
shape.quadraticCurveTo(w, d, w - r, d);
shape.lineTo(-w + r, d);
shape.quadraticCurveTo(-w, d, -w, d - r);
shape.lineTo(-w, -d + r);
shape.quadraticCurveTo(-w, -d, -w + r, -d);
return shape;
}
function addRoundedRug(width, depth, radius, y, color) {
const geometry = new THREE.ShapeGeometry(
roundedRectShape(width, depth, radius),
16
);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(
geometry,
standardMaterial(color, { roughness: 1 })
);
mesh.position.y = y;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Room shell.
addBox(scene, [12.5, 0.3, 9.4], [0, -0.19, 0], "#755c47");
const plankColors = [
"#bd8e60",
"#c69868",
"#b9875a",
"#cda172",
"#bb8b5d"
];
for (let i = 0; i < 16; i++) {
const x = -5.85 + i * 0.78;
addBox(
scene,
[0.75, 0.065, 9.15],
[x, -0.012, 0],
plankColors[i % plankColors.length],
{ roughness: 0.94 }
);
}
addBox(
scene,
[12.35, 7, 0.25],
[0, 3.4, -4.65],
"#e7dcc9",
{ roughness: 0.96 }
);
addBox(
scene,
[0.25, 7, 9.25],
[-6.02, 3.4, 0],
"#ddd1bd",
{ roughness: 0.96 }
);
addBox(
scene,
[12.1, 0.18, 0.12],
[0, 0.11, -4.47],
"#f2e9d8"
);
addBox(
scene,
[0.12, 0.18, 9.05],
[-5.84, 0.11, 0],
"#f2e9d8"
);
// Rug.
addRoundedRug(6.25, 4.45, 0.42, 0.045, "#a84f45");
addRoundedRug(5.78, 3.98, 0.33, 0.056, "#dfb86d");
addRoundedRug(5.30, 3.50, 0.28, 0.066, "#eee0bd");
for (let i = 0; i < 5; i++) {
const stripe = addBox(
scene,
[4.75, 0.014, 0.055],
[-0.45, 0.077, -0.55 + i * 0.38],
i % 2 ? "#c26050" : "#6d9a89",
{ roughness: 1 }
);
stripe.rotation.y = i % 2 ? 0.06 : -0.06;
}
for (let i = 0; i < 3; i++) {
const diamond = addBox(
scene,
[0.48, 0.017, 0.48],
[-2.15 + i * 1.68, 0.079, 0.35],
"#d48262",
{ roughness: 1 }
);
diamond.rotation.y = Math.PI / 4;
}
// Bookcase.
const bookcase = new THREE.Group();
bookcase.position.set(-4.16, 0, -4.02);
scene.add(bookcase);
addBox(bookcase, [3.08, 3.35, 0.13], [0, 1.68, -0.34], "#81563d");
addBox(bookcase, [0.15, 3.35, 0.78], [-1.47, 1.68, 0], "#a06b45");
addBox(bookcase, [0.15, 3.35, 0.78], [1.47, 1.68, 0], "#a06b45");
addBox(bookcase, [3.1, 0.15, 0.78], [0, 3.28, 0], "#b07a4f");
addBox(bookcase, [3.0, 0.18, 0.76], [0, 0.08, 0], "#95613f");
const shelfYs = [0.28, 1.08, 1.88, 2.68];
const bookColors = [
"#b75f4d",
"#d0a03e",
"#3d8074",
"#6f648f",
"#537b9b",
"#d7c8a9"
];
let seed = 371;
function seeded() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (const shelfY of shelfYs) {
addBox(
bookcase,
[2.93, 0.10, 0.76],
[0, shelfY, 0],
"#b37a50"
);
let cursor = -1.28;
while (cursor < 1.18) {
const width = 0.12 + seeded() * 0.13;
const height = 0.38 + seeded() * 0.23;
const depth = 0.43 + seeded() * 0.12;
const book = addBox(
bookcase,
[width, height, depth],
[
cursor + width / 2,
shelfY + 0.055 + height / 2,
0.09
],
bookColors[Math.floor(seeded() * bookColors.length)]
);
if (seeded() > 0.88) {
book.rotation.z = -0.12;
}
cursor += width + 0.025;
}
}
// Small plant on the bookcase.
const plant = new THREE.Group();
plant.position.set(0.85, 3.36, 0.03);
bookcase.add(plant);
addCylinder(
plant,
0.22,
0.17,
0.34,
[0, 0.17, 0],
"#c97657"
);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 12, 8),
standardMaterial(i % 2 ? "#4f8a65" : "#6f9b70")
);
leaf.scale.set(0.65, 1.55, 0.32);
leaf.position.set(
Math.cos(angle) * 0.16,
0.55 + seeded() * 0.18,
Math.sin(angle) * 0.14
);
leaf.rotation.z = Math.cos(angle) * 0.65;
leaf.rotation.x = Math.sin(angle) * 0.55;
leaf.castShadow = true;
plant.add(leaf);
}
// Window and frame.
const windowGroup = new THREE.Group();
windowGroup.position.set(1.02, 0, -4.42);
scene.add(windowGroup);
addBox(
windowGroup,
[3.85, 2.83, 0.07],
[0, 3.05, 0],
"#b8d6d4",
{ roughness: 0.45, metalness: 0 }
);
const sun = new THREE.Mesh(
new THREE.CircleGeometry(0.36, 32),
new THREE.MeshBasicMaterial({ color: "#f6d982" })
);
sun.position.set(1.05, 3.65, 0.055);
windowGroup.add(sun);
const hillMaterial = new THREE.MeshBasicMaterial({ color: "#7fa592" });
const hill = new THREE.Mesh(
new THREE.CircleGeometry(1.15, 32, 0, Math.PI),
hillMaterial
);
hill.rotation.z = Math.PI;
hill.position.set(-0.78, 1.64, 0.06);
windowGroup.add(hill);
addBox(windowGroup, [4.12, 0.14, 0.18], [0, 1.60, 0.08], "#f7eedf");
addBox(windowGroup, [4.12, 0.14, 0.18], [0, 4.50, 0.08], "#f7eedf");
addBox(windowGroup, [0.14, 2.94, 0.18], [-1.96, 3.05, 0.08], "#f7eedf");
addBox(windowGroup, [0.14, 2.94, 0.18], [1.96, 3.05, 0.08], "#f7eedf");
addBox(windowGroup, [0.10, 2.90, 0.14], [0, 3.05, 0.10], "#f7eedf");
addBox(windowGroup, [3.90, 0.09, 0.14], [0, 3.05, 0.10], "#f7eedf");
// Drapes.
const curtainGroup = new THREE.Group();
scene.add(curtainGroup);
const curtainRod = addCylinder(
curtainGroup,
0.055,
0.055,
5.35,
[1.02, 4.58, -4.04],
"#4a4036",
{ metalness: 0.38, roughness: 0.44 }
);
curtainRod.rotation.z = Math.PI / 2;
addBox(
curtainGroup,
[5.36, 0.09, 0.13],
[1.02, 4.61, -4.04],
"#5b5043"
);
function addCurtainPanel(centerX, side) {
const width = 1.12;
const height = 4.1;
const geometry = new THREE.PlaneGeometry(width, height, 36, 14);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
const wave = Math.sin((x / width + 0.5) * Math.PI * 12);
const lowerSoftening = THREE.MathUtils.smoothstep(
y,
-height / 2,
height / 2
);
position.setZ(
i,
wave * 0.105 * (0.88 + lowerSoftening * 0.12)
);
}
geometry.computeVertexNormals();
const curtain = new THREE.Mesh(
geometry,
standardMaterial("#bd654f", {
side: THREE.DoubleSide,
roughness: 1
})
);
curtain.position.set(centerX, 2.48, -4.05);
curtain.castShadow = true;
curtain.receiveShadow = true;
curtainGroup.add(curtain);
const tie = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.045, 10, 24),
standardMaterial("#d2a14a", { roughness: 0.82 })
);
tie.scale.set(1, 0.72, 1);
tie.position.set(centerX + side * 0.34, 2.04, -3.90);
tie.rotation.y = Math.PI / 2;
tie.castShadow = true;
curtainGroup.add(tie);
}
addCurtainPanel(-0.88, -1);
addCurtainPanel(3.0, 1);
// Diffuser arrangement.
const diffuserGroup = new THREE.Group();
scene.add(diffuserGroup);
const diffuser = new THREE.Group();
diffuser.position.set(1.02, 2.87, -4.08);
diffuserGroup.add(diffuser);
addBox(diffuser, [3.92, 2.77, 0.13], [0, 0, 0], "#8b6145");
addBox(diffuser, [4.08, 0.12, 0.28], [0, 1.43, 0.05], "#c79561");
addBox(diffuser, [4.08, 0.12, 0.28], [0, -1.43, 0.05], "#c79561");
for (let i = 0; i < 19; i++) {
const slat = addBox(
diffuser,
[0.115, 2.66, 0.46],
[-1.76 + i * 0.196, 0, 0.19],
i % 2 ? "#d1a46c" : "#b98458"
);
slat.rotation.y = i % 2 ? 0.17 : -0.17;
}
// Freestanding reflector arrangement.
const reflectorGroup = new THREE.Group();
scene.add(reflectorGroup);
function addReflector(x, z, rotation, faceColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
reflectorGroup.add(group);
addBox(group, [2.08, 2.38, 0.14], [0, 2.08, 0], faceColor);
addBox(group, [2.22, 0.12, 0.2], [0, 3.29, 0], "#a57850");
addBox(group, [2.22, 0.12, 0.2], [0, 0.87, 0], "#a57850");
addBox(group, [0.11, 2.48, 0.2], [-1.06, 2.08, 0], "#a57850");
addBox(group, [0.11, 2.48, 0.2], [1.06, 2.08, 0], "#a57850");
addCylinderBetween(
group,
new THREE.Vector3(-0.78, 0.06, 0.25),
new THREE.Vector3(-0.78, 1.15, 0),
0.045,
"#4a4640"
);
addCylinderBetween(
group,
new THREE.Vector3(0.78, 0.06, 0.25),
new THREE.Vector3(0.78, 1.15, 0),
0.045,
"#4a4640"
);
addCylinderBetween(
group,
new THREE.Vector3(-0.78, 1.15, 0),
new THREE.Vector3(0.78, 1.15, 0),
0.04,
"#4a4640"
);
return group;
}
const reflectorA = addReflector(
-0.48,
-1.72,
-0.42,
"#d8c9aa"
);
const reflectorB = addReflector(
2.65,
0.05,
0.65,
"#b8c8b9"
);
// Listening chair.
const chair = new THREE.Group();
chair.position.set(-1.55, 0, 1.05);
chair.rotation.y = -0.16;
scene.add(chair);
addBox(chair, [1.18, 0.24, 1.02], [0, 0.66, 0], "#527b71");
addBox(chair, [1.13, 1.02, 0.20], [0, 1.18, -0.43], "#638d80");
for (const x of [-0.43, 0.43]) {
for (const z of [-0.34, 0.34]) {
addCylinderBetween(
chair,
new THREE.Vector3(x * 1.08, 0.04, z * 1.08),
new THREE.Vector3(x, 0.58, z),
0.055,
"#4b4138"
);
}
}
const headphones = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.055, 12, 28, Math.PI),
standardMaterial("#303a37")
);
headphones.position.set(0, 1.83, -0.35);
headphones.rotation.z = Math.PI;
headphones.castShadow = true;
chair.add(headphones);
addBox(chair, [0.13, 0.24, 0.18], [-0.27, 1.68, -0.33], "#303a37");
addBox(chair, [0.13, 0.24, 0.18], [0.27, 1.68, -0.33], "#303a37");
// Side table, record player, and speaker.
const sideTable = new THREE.Group();
sideTable.position.set(3.91, 0, -3.12);
scene.add(sideTable);
addBox(sideTable, [2.48, 0.18, 1.23], [0, 1.0, 0], "#9d6a45");
for (const x of [-1.03, 1.03]) {
for (const z of [-0.42, 0.42]) {
addCylinderBetween(
sideTable,
new THREE.Vector3(x, 0.04, z),
new THREE.Vector3(x * 0.92, 0.92, z * 0.92),
0.055,
"#5b4738"
);
}
}
const turntable = new THREE.Group();
turntable.position.set(-0.55, 1.12, 0);
sideTable.add(turntable);
addBox(turntable, [1.18, 0.13, 0.86], [0, 0, 0], "#303c39");
addCylinder(
turntable,
0.38,
0.38,
0.055,
[-0.12, 0.09, 0],
"#222a28",
{ metalness: 0.25, roughness: 0.35 }
);
const record = addCylinder(
turntable,
0.35,
0.35,
0.016,
[-0.12, 0.126, 0],
"#171c1b",
{ metalness: 0.22, roughness: 0.28 }
);
addCylinder(
turntable,
0.075,
0.075,
0.019,
[-0.12, 0.14, 0],
"#d75a46"
);
const tonearm = addCylinderBetween(
turntable,
new THREE.Vector3(0.43, 0.16, 0.25),
new THREE.Vector3(0.12, 0.16, 0.08),
0.018,
"#d4d0c3",
{ metalness: 0.65, roughness: 0.25 }
);
tonearm.castShadow = true;
const speaker = new THREE.Group();
speaker.position.set(0.75, 1.57, 0.02);
sideTable.add(speaker);
addBox(speaker, [0.68, 1.02, 0.55], [0, 0, 0], "#3a514b");
addBox(speaker, [0.55, 0.78, 0.06], [0, 0, 0.29], "#263732");
for (const y of [-0.2, 0.22]) {
const cone = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.055, 24),
standardMaterial("#111d1a", { roughness: 0.72 })
);
cone.rotation.x = Math.PI / 2;
cone.position.set(0, y, 0.34);
speaker.add(cone);
}
// Guitar and instrument stand.
const guitar = new THREE.Group();
guitar.position.set(4.05, 0, 1.43);
guitar.rotation.set(0, -0.20, -0.045);
scene.add(guitar);
const lowerBody = new THREE.Mesh(
new THREE.SphereGeometry(0.62, 32, 20),
standardMaterial("#c76b3f", { roughness: 0.58 })
);
lowerBody.scale.set(0.88, 1.0, 0.29);
lowerBody.position.set(0, 1.08, 0);
lowerBody.castShadow = true;
guitar.add(lowerBody);
const upperBody = new THREE.Mesh(
new THREE.SphereGeometry(0.54, 32, 20),
standardMaterial("#c76b3f", { roughness: 0.58 })
);
upperBody.scale.set(0.83, 0.95, 0.28);
upperBody.position.set(0, 1.56, 0.005);
upperBody.castShadow = true;
guitar.add(upperBody);
addBox(guitar, [0.17, 1.83, 0.14], [0, 2.56, 0.02], "#5a3d2c");
addBox(guitar, [0.25, 0.39, 0.17], [0, 3.57, 0.02], "#4a3227");
for (let i = 0; i < 6; i++) {
addBox(
guitar,
[0.009, 2.52, 0.009],
[-0.038 + i * 0.015, 2.22, 0.181],
"#e8dfca",
{ metalness: 0.65, roughness: 0.3 }
);
}
const soundHole = new THREE.Mesh(
new THREE.CircleGeometry(0.16, 32),
standardMaterial("#2b241e")
);
soundHole.position.set(0, 1.54, 0.174);
guitar.add(soundHole);
addBox(guitar, [0.36, 0.08, 0.08], [0, 1.02, 0.19], "#4b3125");
for (let i = 0; i < 6; i++) {
const peg = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 10, 8),
standardMaterial("#d6c39c")
);
peg.position.set(
i < 3 ? -0.16 : 0.16,
3.43 + (i % 3) * 0.12,
0.02
);
guitar.add(peg);
}
const guitarStand = new THREE.Group();
guitarStand.position.set(4.05, 0, 1.21);
scene.add(guitarStand);
addCylinderBetween(
guitarStand,
new THREE.Vector3(0, 0.05, 0),
new THREE.Vector3(0, 1.58, 0),
0.037,
"#303a37",
{ metalness: 0.45, roughness: 0.38 }
);
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2 + 0.25;
addCylinderBetween(
guitarStand,
new THREE.Vector3(0, 0.56, 0),
new THREE.Vector3(
Math.cos(angle) * 0.57,
0.045,
Math.sin(angle) * 0.57
),
0.028,
"#303a37",
{ metalness: 0.45, roughness: 0.38 }
);
}
addCylinderBetween(
guitarStand,
new THREE.Vector3(-0.34, 1.38, 0.16),
new THREE.Vector3(0.34, 1.38, 0.16),
0.033,
"#303a37",
{ metalness: 0.45, roughness: 0.38 }
);
addCylinderBetween(
guitarStand,
new THREE.Vector3(-0.12, 2.88, -0.03),
new THREE.Vector3(0.12, 2.88, -0.03),
0.029,
"#303a37",
{ metalness: 0.45, roughness: 0.38 }
);
// Floor lamp.
const lamp = new THREE.Group();
lamp.position.set(-5.25, 0, 1.56);
scene.add(lamp);
addCylinder(lamp, 0.34, 0.40, 0.09, [0, 0.05, 0], "#4c443b");
addCylinder(lamp, 0.035, 0.035, 3.1, [0, 1.55, 0], "#4c443b");
const shade = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.58, 0.78, 32, 1, true),
standardMaterial("#e5b96c", {
side: THREE.DoubleSide,
roughness: 0.9
})
);
shade.position.set(0, 3.1, 0);
shade.castShadow = true;
lamp.add(shade);
// Schematic path layer.
const pathGroup = new THREE.Group();
scene.add(pathGroup);
const sourcePoint = new THREE.Vector3(4.66, 1.54, -2.62);
const listenerPoint = new THREE.Vector3(-1.55, 1.78, 1.08);
const arrangementInfo = {
drapes: {
group: curtainGroup,
label: "Active surface · drape",
description:
"A return-path sketch toward a visually heavy, pleated drape.",
surfaceAnchor: new THREE.Vector3(3.0, 3.72, -3.92)
},
reflectors: {
group: reflectorGroup,
label: "Active surfaces · panels",
description:
"An angled-panel arrangement with two illustrative reflection ideas.",
surfaceAnchor: new THREE.Vector3(-0.48, 3.45, -1.72)
},
diffuser: {
group: diffuserGroup,
label: "Active surface · fins",
description:
"A finned panel shown with a simplified, scattered-path sketch.",
surfaceAnchor: new THREE.Vector3(1.02, 4.31, -3.92)
},
bare: {
group: new THREE.Group(),
label: "No added surface",
description:
"A visually bare room with direct and floor-bounce path ideas.",
surfaceAnchor: new THREE.Vector3(0, 0.2, -3.7)
}
};
let activeArrangement = "drapes";
let pathsVisible = true;
let labelsVisible = true;
let routes = [];
let pathMaterials = [];
let labelItems = [];
let markerRings = [];
scene.updateMatrixWorld(true);
const reflectorHitA = reflectorA.localToWorld(
new THREE.Vector3(0, 0.15, 0.13)
);
const reflectorHitB = reflectorB.localToWorld(
new THREE.Vector3(0, 0.15, 0.13)
);
const routeSets = {
drapes: [
{
color: "#257b72",
label: "Direct route",
labelAnchor: sourcePoint.clone().lerp(listenerPoint, 0.52),
points: [sourcePoint, listenerPoint]
},
{
color: "#d7654d",
label: "Curtain return",
labelAnchor: new THREE.Vector3(3.0, 2.55, -3.84),
points: [
sourcePoint,
new THREE.Vector3(3.0, 2.42, -3.84),
new THREE.Vector3(0.35, 1.72, -1.30),
listenerPoint
]
}
],
reflectors: [
{
color: "#257b72",
label: "Direct route",
labelAnchor: sourcePoint.clone().lerp(listenerPoint, 0.52),
points: [sourcePoint, listenerPoint]
},
{
color: "#d7654d",
label: "Angled reflection",
labelAnchor: reflectorHitA.clone().add(new THREE.Vector3(0, 0.35, 0)),
points: [
sourcePoint,
reflectorHitA,
listenerPoint
]
},
{
color: "#8c6687",
label: "Second panel idea",
labelAnchor: reflectorHitB.clone().add(new THREE.Vector3(0, 0.34, 0)),
points: [
sourcePoint,
reflectorHitB,
listenerPoint
]
}
],
diffuser: [
{
color: "#257b72",
label: "Direct route",
labelAnchor: sourcePoint.clone().lerp(listenerPoint, 0.52),
points: [sourcePoint, listenerPoint]
},
{
color: "#517d98",
label: "Scattered sketch",
labelAnchor: new THREE.Vector3(0.93, 3.25, -3.80),
points: [
sourcePoint,
new THREE.Vector3(0.93, 2.90, -3.80),
new THREE.Vector3(0.10, 2.12, -2.18),
listenerPoint
]
}
],
bare: [
{
color: "#257b72",
label: "Direct route",
labelAnchor: sourcePoint.clone().lerp(listenerPoint, 0.52),
points: [sourcePoint, listenerPoint]
},
{
color: "#d5a743",
label: "Floor bounce idea",
labelAnchor: new THREE.Vector3(1.10, 0.34, -0.65),
points: [
sourcePoint,
new THREE.Vector3(1.10, 0.16, -0.65),
listenerPoint
]
},
{
color: "#8c6687",
label: "Back-wall idea",
labelAnchor: new THREE.Vector3(2.62, 2.68, -4.18),
points: [
sourcePoint,
new THREE.Vector3(2.62, 2.68, -4.18),
listenerPoint
]
}
]
};
function disposePaths() {
pathGroup.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
});
for (const material of pathMaterials) {
material.dispose();
}
pathMaterials = [];
pathGroup.clear();
routes = [];
markerRings = [];
labelItems = [];
labelLayer.replaceChildren();
}
function pointAlongRoute(route, distance) {
let remaining = Math.max(0, distance);
for (const segment of route.segments) {
if (remaining <= segment.length || segment === route.segments.at(-1)) {
const t = THREE.MathUtils.clamp(
remaining / segment.length,
0,
1
);
return segment.a.clone().lerp(segment.b, t);
}
remaining -= segment.length;
}
return route.points.at(-1).clone();
}
function makeRoute(data, index) {
const routeGroup = new THREE.Group();
pathGroup.add(routeGroup);
const material = new THREE.MeshBasicMaterial({
color: data.color,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false,
toneMapped: false
});
pathMaterials.push(material);
const route = {
...data,
segments: [],
totalLength: 0,
phase: index * 0.23,
bead: null
};
for (let i = 0; i < data.points.length - 1; i++) {
const a = data.points[i];
const b = data.points[i + 1];
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const segment = { a, b, length, start: route.totalLength };
route.totalLength += length;
route.segments.push(segment);
const line = new THREE.Mesh(
new THREE.CylinderGeometry(0.019, 0.019, length, 10),
material
);
line.position.copy(a).add(b).multiplyScalar(0.5);
line.quaternion.setFromUnitVectors(
yAxis,
direction.clone().normalize()
);
line.renderOrder = 20;
routeGroup.add(line);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.072, 0.19, 12),
material
);
arrow.position.copy(a).lerp(b, 0.64);
arrow.quaternion.setFromUnitVectors(
yAxis,
direction.clone().normalize()
);
arrow.renderOrder = 21;
routeGroup.add(arrow);
}
for (const point of data.points) {
const joint = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 12, 8),
material
);
joint.position.copy(point);
joint.renderOrder = 22;
routeGroup.add(joint);
}
route.bead = new THREE.Mesh(
new THREE.SphereGeometry(0.078, 16, 12),
material
);
route.bead.renderOrder = 23;
routeGroup.add(route.bead);
routes.push(route);
const label = document.createElement("div");
label.className = "path-label";
label.style.setProperty("--route", data.color);
label.textContent = data.label;
labelLayer.appendChild(label);
labelItems.push({
element: label,
anchor: data.labelAnchor.clone()
});
}
function buildPaths() {
disposePaths();
for (const [name, data] of Object.entries(routeSets)) {
if (name !== activeArrangement) continue;
data.forEach(makeRoute);
}
const sourceMaterial = new THREE.MeshBasicMaterial({
color: "#d7654d",
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const listenerMaterial = new THREE.MeshBasicMaterial({
color: "#257b72",
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false,
toneMapped: false
});
pathMaterials.push(sourceMaterial, listenerMaterial);
const sourceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.025, 10, 32),
sourceMaterial
);
sourceRing.position.copy(sourcePoint);
sourceRing.renderOrder = 24;
pathGroup.add(sourceRing);
const listenerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.025, 10, 32),
listenerMaterial
);
listenerRing.position.copy(listenerPoint);
listenerRing.renderOrder = 24;
pathGroup.add(listenerRing);
markerRings = [sourceRing, listenerRing];
const sourceLabel = document.createElement("div");
sourceLabel.className = "path-label marker";
sourceLabel.style.setProperty("--route", "#d7654d");
sourceLabel.textContent = "Source";
labelLayer.appendChild(sourceLabel);
labelItems.push({
element: sourceLabel,
anchor: sourcePoint.clone().add(new THREE.Vector3(0, 0.57, 0))
});
const listenerLabel = document.createElement("div");
listenerLabel.className = "path-label marker";
listenerLabel.style.setProperty("--route", "#257b72");
listenerLabel.textContent = "Listening point";
labelLayer.appendChild(listenerLabel);
labelItems.push({
element: listenerLabel,
anchor: listenerPoint.clone().add(new THREE.Vector3(0, 0.45, 0))
});
const surfaceLabel = document.createElement("div");
surfaceLabel.className = "path-label marker";
surfaceLabel.style.setProperty("--route", "#d5a743");
surfaceLabel.textContent = arrangementInfo[activeArrangement].label;
labelLayer.appendChild(surfaceLabel);
labelItems.push({
element: surfaceLabel,
anchor: arrangementInfo[activeArrangement].surfaceAnchor.clone()
});
pathGroup.visible = pathsVisible;
updateLabelVisibility();
}
function updateLabelVisibility() {
labelLayer.style.display =
pathsVisible && labelsVisible ? "block" : "none";
}
function setArrangement(name) {
activeArrangement = name;
for (const [key, info] of Object.entries(arrangementInfo)) {
info.group.visible = key === name;
}
for (const button of arrangementButtons) {
const active = button.dataset.arrangement === name;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
descriptionEl.textContent = arrangementInfo[name].description;
updateStatus();
buildPaths();
}
function updateStatus() {
statusEl.textContent =
`${activeArrangement.charAt(0).toUpperCase() + activeArrangement.slice(1)}` +
` · Paths ${pathsVisible ? "on" : "hidden"}`;
}
arrangementButtons.forEach((button) => {
button.addEventListener("click", () => {
setArrangement(button.dataset.arrangement);
});
});
pathsToggle.addEventListener("change", () => {
pathsVisible = pathsToggle.checked;
pathGroup.visible = pathsVisible;
updateLabelVisibility();
updateStatus();
});
labelsToggle.addEventListener("change", () => {
labelsVisible = labelsToggle.checked;
updateLabelVisibility();
});
// Direct orthographic camera controls.
const initialCamera = {
radius: 14.6,
theta: 0.68,
phi: 1.02,
target: new THREE.Vector3(0, 1.58, -0.45)
};
const desiredCamera = {
radius: initialCamera.radius,
theta: initialCamera.theta,
phi: initialCamera.phi,
target: initialCamera.target.clone()
};
const currentCamera = {
radius: initialCamera.radius,
theta: initialCamera.theta,
phi: initialCamera.phi,
target: initialCamera.target.clone()
};
function resetCamera() {
desiredCamera.radius = initialCamera.radius;
desiredCamera.theta = initialCamera.theta;
desiredCamera.phi = initialCamera.phi;
desiredCamera.target.copy(initialCamera.target);
}
resetCameraButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
let activePointer = null;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
activePointer = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.shiftKey || event.button === 2
};
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointer || activePointer.id !== event.pointerId) return;
const dx = event.clientX - activePointer.x;
const dy = event.clientY - activePointer.y;
activePointer.x = event.clientX;
activePointer.y = event.clientY;
if (activePointer.pan) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const forward = new THREE.Vector3(0, 0, -1).applyQuaternion(
camera.quaternion
);
forward.y = 0;
forward.normalize();
const scale = desiredCamera.radius * 0.00065;
desiredCamera.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, dy * scale);
} else {
desiredCamera.theta -= dx * 0.005;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.0045,
0.48,
1.38
);
}
});
function endPointer(event) {
if (!activePointer || activePointer.id !== event.pointerId) return;
activePointer = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
8.3,
20
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
desiredCamera.theta += 0.08;
break;
case "ArrowRight":
desiredCamera.theta -= 0.08;
break;
case "ArrowUp":
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - 0.06,
0.48,
1.38
);
break;
case "ArrowDown":
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi + 0.06,
0.48,
1.38
);
break;
case "+":
case "=":
desiredCamera.radius = Math.max(
8.3,
desiredCamera.radius - 0.7
);
break;
case "-":
desiredCamera.radius = Math.min(
20,
desiredCamera.radius + 0.7
);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
updateProjection();
}
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight =
currentCamera.radius * (aspect < 0.85 ? 0.72 : 0.52);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
if (!pathsVisible || !labelsVisible) return;
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of labelItems) {
projected.copy(item.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
currentCamera.radius = THREE.MathUtils.lerp(
currentCamera.radius,
desiredCamera.radius,
0.09
);
currentCamera.theta = THREE.MathUtils.lerp(
currentCamera.theta,
desiredCamera.theta,
0.11
);
currentCamera.phi = THREE.MathUtils.lerp(
currentCamera.phi,
desiredCamera.phi,
0.11
);
currentCamera.target.lerp(desiredCamera.target, 0.1);
const sinPhi = Math.sin(currentCamera.phi);
camera.position.set(
currentCamera.target.x +
currentCamera.radius * sinPhi * Math.sin(currentCamera.theta),
currentCamera.target.y +
currentCamera.radius * Math.cos(currentCamera.phi),
currentCamera.target.z +
currentCamera.radius * sinPhi * Math.cos(currentCamera.theta)
);
camera.lookAt(currentCamera.target);
updateProjection();
record.rotation.y = elapsed * 0.72;
if (pathsVisible) {
for (const route of routes) {
const distance =
(elapsed * 0.12 + route.phase * route.totalLength) %
route.totalLength;
route.bead.position.copy(pointAlongRoute(route, distance));
}
for (let i = 0; i < markerRings.length; i++) {
const ring = markerRings[i];
ring.quaternion.copy(camera.quaternion);
const pulse = 1 + Math.sin(elapsed * 2.5 + i) * 0.11;
ring.scale.setScalar(pulse);
}
}
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
setArrangement("drapes");
resize();
updateStatus();
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```