Prompt specification
Build or customize the Three.js 3D scene "Window recess seating section" 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: Window recess seating section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/window-recess-seating-section-x0237
Scene Description Prompt:
A voxel window-seat section showing cushion, sill, lower storage, wall thickness, and glazing. Make one HTML file with Three.js from cdnjs.
Working Three.js Starter (window-recess-seating-section-x0237):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Window Seat — Sectional Study</title>
<style>
:root {
--ink: #313936;
--muted: #737a75;
--paper: #f7f5ef;
--stage: #e9e4da;
--line: #cbc7bd;
--accent: #cf7548;
--accent-soft: #f0d8c9;
--glass: #77b9c2;
--wood: #a96143;
--cushion: #dc9357;
--wall: #c9a987;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
header {
position: relative;
z-index: 10;
height: 76px;
padding: 0 28px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
background: rgba(247, 245, 239, 0.96);
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
width: 36px;
height: 36px;
flex: 0 0 auto;
display: grid;
place-items: center;
color: white;
background: var(--accent);
box-shadow: 5px 5px 0 #ead8c9;
font-size: 18px;
font-weight: 800;
}
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1.1;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
}
.project-meta {
display: flex;
align-items: center;
gap: 22px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.live {
display: flex;
align-items: center;
gap: 8px;
}
.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #72a16f;
box-shadow: 0 0 0 4px rgba(114, 161, 111, 0.13);
}
main {
height: calc(100vh - 76px);
display: grid;
grid-template-columns: minmax(0, 1fr) 306px;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
isolation: isolate;
background: var(--stage);
}
#stage canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.stage-heading {
position: absolute;
z-index: 4;
top: 22px;
left: 24px;
pointer-events: none;
}
.stage-heading .eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.stage-heading strong {
display: block;
margin-top: 5px;
font-size: 13px;
font-weight: 650;
letter-spacing: 0.03em;
}
#leaders,
.callout {
transition: opacity 180ms ease;
}
#leaders {
position: absolute;
inset: 0;
z-index: 2;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: #6f7772;
stroke-width: 1;
stroke-dasharray: 3 3;
opacity: 0.62;
}
#leaders circle {
fill: var(--paper);
stroke: #707873;
stroke-width: 1.4;
}
.callout {
position: absolute;
z-index: 3;
left: var(--x);
top: var(--y);
width: 158px;
min-height: 51px;
padding: 9px 10px 9px 11px;
display: flex;
align-items: flex-start;
gap: 9px;
transform: translate(-50%, -50%);
color: var(--ink);
background: rgba(249, 247, 241, 0.9);
border: 1px solid rgba(98, 105, 99, 0.25);
box-shadow: 0 5px 16px rgba(67, 62, 54, 0.08);
backdrop-filter: blur(8px);
pointer-events: none;
}
.callout .number {
width: 21px;
height: 21px;
flex: 0 0 auto;
display: grid;
place-items: center;
color: white;
background: var(--accent);
font-size: 9px;
font-weight: 800;
}
.callout b {
display: block;
font-size: 10px;
line-height: 1.15;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.callout span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.annotations-off #leaders,
.annotations-off .callout {
opacity: 0;
}
.controls {
position: absolute;
z-index: 5;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 6px;
padding: 5px;
background: rgba(249, 247, 241, 0.9);
border: 1px solid rgba(98, 105, 99, 0.23);
box-shadow: 0 5px 18px rgba(67, 62, 54, 0.08);
backdrop-filter: blur(8px);
}
.controls button {
height: 31px;
min-width: 32px;
padding: 0 10px;
border: 0;
color: var(--ink);
background: transparent;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
cursor: pointer;
}
.controls button:hover,
.controls button.active {
color: white;
background: var(--ink);
}
.control-divider {
width: 1px;
height: 20px;
margin: 0 2px;
background: var(--line);
}
.hint {
position: absolute;
z-index: 4;
right: 22px;
bottom: 25px;
color: rgba(49, 57, 54, 0.6);
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: absolute;
inset: 0;
z-index: 8;
display: grid;
place-items: center;
color: var(--muted);
background: var(--stage);
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.is-hidden {
opacity: 0;
pointer-events: none;
}
aside {
position: relative;
z-index: 6;
padding: 26px 24px;
overflow-y: auto;
background: var(--paper);
border-left: 1px solid var(--line);
}
.aside-kicker {
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
aside h2 {
margin: 8px 0 8px;
font-size: 23px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.aside-intro {
margin: 0 0 24px;
color: var(--muted);
font-size: 11px;
line-height: 1.65;
}
.component-list {
border-top: 1px solid var(--line);
}
.component {
display: grid;
grid-template-columns: 27px 1fr;
gap: 8px;
padding: 14px 0;
border-bottom: 1px solid var(--line);
}
.component .index {
color: #999c95;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.component strong {
display: block;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.component p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.swatch {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 6px;
vertical-align: 1px;
background: var(--color);
}
.dimensions {
margin-top: 26px;
padding: 16px;
background: #ece8df;
border: 1px solid #ddd8cd;
}
.dimensions h3 {
margin: 0 0 12px;
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.dimension-row {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 7px 0;
border-top: 1px solid rgba(98, 105, 99, 0.12);
color: var(--muted);
font-size: 9px;
}
.dimension-row b {
color: var(--ink);
font-weight: 750;
}
.note {
margin-top: 20px;
padding-left: 12px;
border-left: 2px solid var(--accent);
color: var(--muted);
font-size: 9px;
line-height: 1.65;
}
@media (max-width: 980px) {
main {
grid-template-columns: minmax(0, 1fr) 270px;
}
aside {
padding: 24px 19px;
}
.project-meta .detail {
display: none;
}
.callout {
width: 143px;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
header {
height: 68px;
padding: 0 18px;
}
.brand p,
.project-meta {
display: none;
}
main {
height: auto;
display: block;
}
#stage {
height: 68vh;
min-height: 510px;
}
aside {
padding: 24px 20px 32px;
border-top: 1px solid var(--line);
border-left: 0;
}
.stage-heading {
top: 17px;
left: 18px;
}
.callout {
width: 125px;
min-height: 43px;
padding: 7px;
gap: 6px;
}
.callout .number {
width: 18px;
height: 18px;
font-size: 8px;
}
.callout b {
font-size: 8px;
}
.callout span {
display: none;
}
.hint {
display: none;
}
.controls {
left: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-mark">▦</div>
<div>
<h1>Window Seat / Section 01</h1>
<p>Voxel construction study · built-in reading nook</p>
</div>
</div>
<div class="project-meta">
<span class="detail">Scale 1:20</span>
<span class="detail">Detail A–A</span>
<span class="live">Interactive model</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive 3D voxel window-seat section">
<div id="loading">Building voxel section…</div>
<div class="stage-heading">
<div class="eyebrow">Exploded clarity / solid construction</div>
<strong>Cutaway window-seat assembly</strong>
</div>
<svg id="leaders" aria-hidden="true">
<g id="leader-cushion">
<line x1="0" y1="0" x2="0" y2="0"></line>
<circle cx="0" cy="0" r="3.3"></circle>
</g>
<g id="leader-sill">
<line x1="0" y1="0" x2="0" y2="0"></line>
<circle cx="0" cy="0" r="3.3"></circle>
</g>
<g id="leader-storage">
<line x1="0" y1="0" x2="0" y2="0"></line>
<circle cx="0" cy="0" r="3.3"></circle>
</g>
<g id="leader-wall">
<line x1="0" y1="0" x2="0" y2="0"></line>
<circle cx="0" cy="0" r="3.3"></circle>
</g>
<g id="leader-glazing">
<line x1="0" y1="0" x2="0" y2="0"></line>
<circle cx="0" cy="0" r="3.3"></circle>
</g>
</svg>
<div class="callout" id="callout-cushion" style="--x: 77%; --y: 59%;">
<span class="number">01</span>
<div>
<b>Cushion</b>
<span>Modular foam blocks</span>
</div>
</div>
<div class="callout" id="callout-sill" style="--x: 22%; --y: 29%;">
<span class="number">02</span>
<div>
<b>Sill</b>
<span>Deep tiled ledge</span>
</div>
</div>
<div class="callout" id="callout-storage" style="--x: 22%; --y: 75%;">
<span class="number">03</span>
<div>
<b>Lower storage</b>
<span>Open shelf + drawers</span>
</div>
</div>
<div class="callout" id="callout-wall" style="--x: 82%; --y: 20%;">
<span class="number">04</span>
<div>
<b>Wall thickness</b>
<span>Exposed layered section</span>
</div>
</div>
<div class="callout" id="callout-glazing" style="--x: 80%; --y: 40%;">
<span class="number">05</span>
<div>
<b>Glazing</b>
<span>Double-pane assembly</span>
</div>
</div>
<div class="controls" aria-label="Model controls">
<button id="zoom-in" aria-label="Zoom in">+</button>
<button id="zoom-out" aria-label="Zoom out">−</button>
<span class="control-divider"></span>
<button id="reset-view">Reset</button>
<button id="toggle-labels" class="active" aria-pressed="true">Labels</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</section>
<aside>
<div class="aside-kicker">Component schedule</div>
<h2>Five layers,<br />one compact nook.</h2>
<p class="aside-intro">
A cutaway assembly showing how the seat, storage, masonry opening,
sill and glazing fit together.
</p>
<div class="component-list">
<div class="component">
<div class="index">01</div>
<div>
<strong><span class="swatch" style="--color: var(--cushion)"></span>Cushion</strong>
<p>Separate square foam blocks create a simple, replaceable top pad.</p>
</div>
</div>
<div class="component">
<div class="index">02</div>
<div>
<strong><span class="swatch" style="--color: #d4c3a7"></span>Sill</strong>
<p>A deep segmented ledge bridges the wall face and window frame.</p>
</div>
</div>
<div class="component">
<div class="index">03</div>
<div>
<strong><span class="swatch" style="--color: var(--wood)"></span>Lower storage</strong>
<p>Open cubbies sit beside two drawers within the timber base.</p>
</div>
</div>
<div class="component">
<div class="index">04</div>
<div>
<strong><span class="swatch" style="--color: var(--wall)"></span>Wall thickness</strong>
<p>The right-hand cut exposes the core and both surface finishes.</p>
</div>
</div>
<div class="component">
<div class="index">05</div>
<div>
<strong><span class="swatch" style="--color: var(--glass)"></span>Glazing</strong>
<p>Two offset panes sit inside a deep charcoal window frame.</p>
</div>
</div>
</div>
<div class="dimensions">
<h3>Indicative dimensions</h3>
<div class="dimension-row"><span>Seat run</span><b>6,100 mm</b></div>
<div class="dimension-row"><span>Cushion height</span><b>380 mm</b></div>
<div class="dimension-row"><span>Sill projection</span><b>1,050 mm</b></div>
<div class="dimension-row"><span>Wall build-up</span><b>640 mm</b></div>
</div>
<div class="note">
Concept detail only. Dimensions and materials are illustrative and
should be coordinated with site measurements.
</div>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Orbitable voxel window-seat model");
stage.insertBefore(renderer.domElement, stage.firstChild);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4da);
const camera = new THREE.OrthographicCamera(-6, 6, 5, -5, 0.1, 100);
const target = new THREE.Vector3(0, 2.75, 0.35);
const orbitRadius = 15;
let targetAzimuth = 0.68;
let targetElevation = 0.43;
let targetZoom = 1;
let currentAzimuth = targetAzimuth;
let currentElevation = targetElevation;
let currentZoom = targetZoom;
const hemisphere = new THREE.HemisphereLight(0xe9f3f0, 0x8d7562, 2.3);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffedcf, 4.2);
sunlight.position.set(-5, 10, 7);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -9;
sunlight.shadow.camera.right = 9;
sunlight.shadow.camera.top = 10;
sunlight.shadow.camera.bottom = -7;
sunlight.shadow.camera.near = 0.5;
sunlight.shadow.camera.far = 30;
sunlight.shadow.bias = -0.00035;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight);
scene.add(sunlight.target);
const fillLight = new THREE.DirectionalLight(0xc6e7ee, 1.25);
fillLight.position.set(7, 5, -5);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
const materials = {
wallCore: material(0xc8a582),
wallCoreAlt: material(0xb99573),
wallSkin: material(0xeee6d9),
floor: material(0xffffff),
frame: material(0x35423f, { roughness: 0.48 }),
wood: material(0xa85f41),
woodLight: material(0xc27b55),
woodDark: material(0x75412f),
interior: material(0x754735),
cushionA: material(0xda8b50),
cushionB: material(0xe19c61),
cushionTuft: material(0xa8643d),
stoneA: material(0xd4c2a5),
stoneB: material(0xcbb694),
blanketA: material(0x789b94),
blanketB: material(0xd8d2bd),
blanketC: material(0xbb7659),
bookA: material(0x526c70),
bookB: material(0xd0a65f),
bookC: material(0xa85d48),
handle: material(0x303936, { roughness: 0.4, metalness: 0.28 })
};
function box(size, position, mat, options = {}) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
mesh.name = options.name || "";
scene.add(mesh);
return mesh;
}
// Ground plane and pixel-style floor.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
material(0xe4dfd5)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.105;
ground.receiveShadow = true;
scene.add(ground);
const floorSpecs = [];
const floorColors = [0xd8d3c9, 0xd1ccc2, 0xded9cf, 0xccc7bd];
for (let x = -7; x <= 7; x += 0.78) {
for (let z = -1; z <= 6; z += 0.78) {
floorSpecs.push({
x: x + 0.39,
z: z + 0.39,
color: floorColors[Math.floor(Math.random() * floorColors.length)]
});
}
}
const floorTiles = new THREE.InstancedMesh(
unitBox,
material(0xffffff),
floorSpecs.length
);
const dummy = new THREE.Object3D();
floorSpecs.forEach((tile, i) => {
dummy.position.set(tile.x, -0.05, tile.z);
dummy.scale.set(0.745, 0.08, 0.745);
dummy.updateMatrix();
floorTiles.setMatrixAt(i, dummy.matrix);
floorTiles.setColorAt(i, new THREE.Color(tile.color));
});
floorTiles.instanceMatrix.needsUpdate = true;
floorTiles.instanceColor.needsUpdate = true;
floorTiles.receiveShadow = true;
scene.add(floorTiles);
// Procedural pixel sky visible through the window.
const skyCanvas = document.createElement("canvas");
skyCanvas.width = 768;
skyCanvas.height = 512;
const skyContext = skyCanvas.getContext("2d");
const skyGradient = skyContext.createLinearGradient(0, 0, 0, 512);
skyGradient.addColorStop(0, "#79aebe");
skyGradient.addColorStop(0.58, "#b8d4d3");
skyGradient.addColorStop(1, "#f0d6ad");
skyContext.fillStyle = skyGradient;
skyContext.fillRect(0, 0, 768, 512);
skyContext.fillStyle = "#f8df9f";
skyContext.fillRect(585, 56, 38, 38);
skyContext.fillRect(571, 70, 66, 10);
const cloudColor = "#edf0e7";
[
[80, 95, 115, 17], [104, 79, 87, 20], [188, 124, 15, 22],
[343, 83, 128, 15], [385, 68, 91, 17], [520, 168, 96, 12],
[590, 151, 90, 13]
].forEach(([x, y, w, h]) => {
skyContext.fillStyle = cloudColor;
skyContext.fillRect(x, y, w, h);
skyContext.fillRect(x + 13, y - 11, w - 26, 12);
});
const buildings = [
[0, 330, 92, 182, "#718b88"],
[72, 286, 80, 226, "#839a94"],
[137, 350, 104, 162, "#657f7e"],
[222, 308, 69, 204, "#849994"],
[276, 250, 93, 262, "#718986"],
[350, 345, 108, 167, "#8b9d94"],
[437, 300, 73, 212, "#6c8583"],
[493, 340, 115, 172, "#80948e"],
[590, 278, 82, 234, "#718885"],
[650, 333, 118, 179, "#879b93"]
];
buildings.forEach(([x, y, w, h, color]) => {
skyContext.fillStyle = color;
skyContext.fillRect(x, y, w, h);
});
skyContext.fillStyle = "#f0d5a0";
skyContext.fillRect(0, 468, 768, 44);
const skyTexture = new THREE.CanvasTexture(skyCanvas);
skyTexture.colorSpace = THREE.SRGBColorSpace;
skyTexture.magFilter = THREE.NearestFilter;
skyTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sky = new THREE.Mesh(
new THREE.PlaneGeometry(9.4, 6.6),
new THREE.MeshBasicMaterial({
map: skyTexture,
toneMapped: false
})
);
sky.position.set(0, 3.3, -0.78);
scene.add(sky);
// Wall core around the opening.
box([1.65, 6.4, 0.55], [-3.675, 3.3, -0.34], materials.wallCore, {
name: "Left wall core"
});
box([1.65, 6.4, 0.55], [3.675, 3.3, -0.34], materials.wallCore, {
name: "Right wall core"
});
box([5.7, 2.25, 0.55], [0, 1.225, -0.34], materials.wallCore, {
name: "Wall below opening"
});
box([5.7, 0.95, 0.55], [0, 6.025, -0.34], materials.wallCore, {
name: "Wall above opening"
});
// Pixelated interior wall finish.
const tileSpecs = [];
const wallTileColors = [0xeee6d9, 0xe8dfd1, 0xf0e9dd, 0xe3d9ca];
function addWallTiles(x0, x1, y0, y1) {
const step = 0.43;
const gap = 0.018;
for (let x = x0; x < x1; x += step) {
for (let y = y0; y < y1; y += step) {
const width = Math.min(x + step, x1) - x;
const height = Math.min(y + step, y1) - y;
if (width < 0.02 || height < 0.02) continue;
tileSpecs.push({
x: x + width / 2,
y: y + height / 2,
width: width - gap,
height: height - gap,
color: wallTileColors[Math.floor(Math.random() * wallTileColors.length)]
});
}
}
}
addWallTiles(-4.5, -2.85, 0.1, 6.5);
addWallTiles(2.85, 4.5, 0.1, 6.5);
addWallTiles(-2.85, 2.85, 0.1, 2.35);
addWallTiles(-2.85, 2.85, 5.55, 6.5);
const wallTiles = new THREE.InstancedMesh(
unitBox,
material(0xffffff),
tileSpecs.length
);
tileSpecs.forEach((tile, i) => {
dummy.position.set(tile.x, tile.y, -0.005);
dummy.scale.set(tile.width, tile.height, 0.12);
dummy.updateMatrix();
wallTiles.setMatrixAt(i, dummy.matrix);
wallTiles.setColorAt(i, new THREE.Color(tile.color));
});
wallTiles.instanceMatrix.needsUpdate = true;
wallTiles.instanceColor.needsUpdate = true;
wallTiles.receiveShadow = true;
scene.add(wallTiles);
// Exposed right-hand wall section.
for (let y = 0.12; y < 6.5; y += 0.42) {
box(
[0.026, 0.395, 0.51],
[4.513, y + 0.19, -0.35],
Math.random() > 0.5 ? materials.wallCore : materials.wallCoreAlt,
{ name: "Exposed masonry block" }
);
}
box([0.035, 6.4, 0.075], [4.52, 3.3, -0.035], materials.wallSkin);
box([0.035, 6.4, 0.065], [4.52, 3.3, -0.64], materials.wallCoreAlt);
// Window frame.
box([0.16, 3.35, 0.20], [-2.87, 3.95, 0.09], materials.frame);
box([0.16, 3.35, 0.20], [2.87, 3.95, 0.09], materials.frame);
box([5.88, 0.16, 0.20], [0, 2.35, 0.09], materials.frame);
box([5.88, 0.16, 0.20], [0, 5.55, 0.09], materials.frame);
box([0.105, 3.2, 0.17], [0.15, 3.95, 0.075], materials.frame);
// Two glass panes.
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8acbd3,
roughness: 0.08,
metalness: 0.02,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const rearGlassMaterial = glassMaterial.clone();
rearGlassMaterial.opacity = 0.1;
rearGlassMaterial.color.set(0xa9dce0);
box([5.64, 3.05, 0.012], [0, 3.95, -0.23], rearGlassMaterial, {
cast: false
});
box([5.64, 3.05, 0.012], [0, 3.95, -0.015], glassMaterial, {
cast: false
});
// Graphic reflections on the front pane.
const reflectionMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const reflectionA = box(
[0.035, 1.8, 0.008],
[-1.25, 4.05, 0.004],
reflectionMaterial,
{ cast: false, receive: false }
);
reflectionA.rotation.z = -0.34;
const reflectionB = box(
[0.026, 1.3, 0.008],
[-0.78, 4.05, 0.005],
reflectionMaterial,
{ cast: false, receive: false }
);
reflectionB.rotation.z = -0.34;
// Deep voxel sill.
for (let i = 0; i < 8; i++) {
const width = 0.735;
box(
[width, 0.28, 1.05],
[-2.94 + i * 0.75, 2.24, 0.12],
i % 3 === 0 ? materials.stoneB : materials.stoneA,
{ name: "Sill block" }
);
}
// Lower storage carcass.
box([6.15, 0.16, 1.78], [0, 0.34, 0.91], materials.woodDark, {
name: "Storage base"
});
box([6.20, 0.16, 1.84], [0, 1.38, 0.92], materials.woodLight, {
name: "Seat support"
});
box([0.14, 1.04, 1.78], [-3.03, 0.87, 0.91], materials.wood);
box([0.14, 1.04, 1.78], [3.03, 0.87, 0.91], materials.wood);
box([6.04, 1.04, 0.11], [0, 0.87, 0.075], materials.interior);
box([0.13, 1.03, 1.72], [0.17, 0.87, 0.92], materials.wood);
box([5.95, 0.14, 0.13], [0, 0.13, 1.66], materials.woodDark);
// Open shelf.
box([2.87, 0.12, 1.63], [-1.41, 0.82, 0.94], materials.woodLight);
// Two drawer fronts.
box([2.70, 0.45, 0.11], [1.61, 0.61, 1.80], materials.woodLight);
box([2.70, 0.45, 0.11], [1.61, 1.11, 1.80], materials.woodLight);
box([0.48, 0.055, 0.075], [1.61, 0.68, 1.89], materials.handle);
box([0.48, 0.055, 0.075], [1.61, 1.18, 1.89], materials.handle);
// Folded contents in the lower cubby.
box([0.75, 0.22, 0.72], [-2.34, 0.53, 1.03], materials.blanketA);
box([0.70, 0.20, 0.69], [-1.57, 0.52, 1.03], materials.blanketB);
box([0.72, 0.18, 0.68], [-2.31, 0.73, 1.03], materials.blanketC);
box([0.61, 0.16, 0.64], [-1.55, 0.71, 1.05], materials.blanketA);
// Books and blocks on the open upper shelf.
box([0.15, 0.48, 0.46], [-2.62, 1.12, 0.85], materials.bookA);
box([0.16, 0.43, 0.46], [-2.43, 1.095, 0.85], materials.bookB);
box([0.14, 0.50, 0.46], [-2.23, 1.13, 0.85], materials.bookC);
box([0.56, 0.25, 0.57], [-1.38, 1.00, 0.92], materials.blanketC);
box([0.44, 0.18, 0.48], [-1.38, 1.21, 0.92], materials.blanketB);
// Modular cushion blocks.
const cushionColumns = 7;
const cushionRows = 2;
const cushionWidth = 0.84;
const cushionDepth = 0.80;
const cushionGap = 0.035;
const cushionStartX = -3.045;
const cushionStartZ = 0.10;
for (let row = 0; row < cushionRows; row++) {
for (let col = 0; col < cushionColumns; col++) {
const x = cushionStartX + col * (cushionWidth + cushionGap) + cushionWidth / 2;
const z = cushionStartZ + row * (cushionDepth + cushionGap) + cushionDepth / 2;
box(
[cushionWidth, 0.38, cushionDepth],
[x, 1.66, z],
(col + row) % 3 === 0 ? materials.cushionB : materials.cushionA,
{ name: "Cushion block" }
);
box(
[0.065, 0.018, 0.065],
[x, 1.859, z],
materials.cushionTuft,
{ cast: false }
);
}
}
// Light technical dimension marks on the floor.
const dimensionMaterial = new THREE.LineBasicMaterial({
color: 0x707873,
transparent: true,
opacity: 0.58
});
const dimensionGeometry = new THREE.BufferGeometry();
dimensionGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-3.20, 0.045, 2.42, 3.20, 0.045, 2.42,
-3.20, -0.06, 2.42, -3.20, 0.15, 2.42,
3.20, -0.06, 2.42, 3.20, 0.15, 2.42,
3.52, 0.05, 2.20, 3.52, 1.84, 2.20,
3.43, 0.05, 2.20, 3.61, 0.05, 2.20,
3.43, 1.84, 2.20, 3.61, 1.84, 2.20
], 3)
);
scene.add(new THREE.LineSegments(dimensionGeometry, dimensionMaterial));
// Annotation anchors.
const annotations = {
cushion: {
element: document.getElementById("callout-cushion"),
leader: document.getElementById("leader-cushion"),
anchor: new THREE.Vector3(1.55, 1.86, 1.14)
},
sill: {
element: document.getElementById("callout-sill"),
leader: document.getElementById("leader-sill"),
anchor: new THREE.Vector3(1.35, 2.40, 0.48)
},
storage: {
element: document.getElementById("callout-storage"),
leader: document.getElementById("leader-storage"),
anchor: new THREE.Vector3(-1.55, 0.82, 1.48)
},
wall: {
element: document.getElementById("callout-wall"),
leader: document.getElementById("leader-wall"),
anchor: new THREE.Vector3(4.55, 4.18, -0.34)
},
glazing: {
element: document.getElementById("callout-glazing"),
leader: document.getElementById("leader-glazing"),
anchor: new THREE.Vector3(0.35, 4.72, 0.01)
}
};
function updateAnnotations() {
const stageRect = stage.getBoundingClientRect();
const projected = new THREE.Vector3();
Object.values(annotations).forEach((annotation) => {
projected.copy(annotation.anchor).project(camera);
const endX = (projected.x * 0.5 + 0.5) * stageRect.width;
const endY = (-projected.y * 0.5 + 0.5) * stageRect.height;
const rect = annotation.element.getBoundingClientRect();
const left = rect.left - stageRect.left;
const top = rect.top - stageRect.top;
const centerX = left + rect.width / 2;
const centerY = top + rect.height / 2;
const startX = endX < centerX ? left : left + rect.width;
const startY = Math.max(top + 8, Math.min(top + rect.height - 8, endY));
const line = annotation.leader.querySelector("line");
const circle = annotation.leader.querySelector("circle");
line.setAttribute("x1", startX.toFixed(1));
line.setAttribute("y1", startY.toFixed(1));
line.setAttribute("x2", endX.toFixed(1));
line.setAttribute("y2", endY.toFixed(1));
circle.setAttribute("cx", endX.toFixed(1));
circle.setAttribute("cy", endY.toFixed(1));
});
}
function updateCamera(delta = 1) {
const smoothing = 1 - Math.pow(0.0008, delta);
currentAzimuth += (targetAzimuth - currentAzimuth) * smoothing;
currentElevation += (targetElevation - currentElevation) * smoothing;
currentZoom += (targetZoom - currentZoom) * smoothing;
const horizontalRadius = Math.cos(currentElevation) * orbitRadius;
camera.position.set(
target.x + Math.sin(currentAzimuth) * horizontalRadius,
target.y + Math.sin(currentElevation) * orbitRadius,
target.z + Math.cos(currentAzimuth) * horizontalRadius
);
camera.lookAt(target);
camera.zoom = currentZoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const halfHeight = Math.max(4.8, 5.3 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
// Direct orbit controls: no addons or external examples are used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
targetAzimuth -= dx * 0.006;
targetElevation = THREE.MathUtils.clamp(
targetElevation + dy * 0.005,
0.16,
1.05
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetZoom = THREE.MathUtils.clamp(
targetZoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
},
{ passive: false }
);
function resetView() {
targetAzimuth = 0.68;
targetElevation = 0.43;
targetZoom = 1;
}
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("zoom-in").addEventListener("click", () => {
targetZoom = Math.min(1.65, targetZoom * 1.12);
});
document.getElementById("zoom-out").addEventListener("click", () => {
targetZoom = Math.max(0.68, targetZoom / 1.12);
});
const labelsButton = document.getElementById("toggle-labels");
labelsButton.addEventListener("click", () => {
const enabled = stage.classList.toggle("annotations-off");
labelsButton.classList.toggle("active", !enabled);
labelsButton.setAttribute("aria-pressed", String(!enabled));
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "+" || event.key === "=") {
targetZoom = Math.min(1.65, targetZoom * 1.1);
}
if (event.key === "-") {
targetZoom = Math.max(0.68, targetZoom / 1.1);
}
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera(delta);
renderer.render(scene, camera);
updateAnnotations();
if (firstFrame) {
loading.classList.add("is-hidden");
firstFrame = false;
}
}
animate();
</script>
</body>
</html>
```