Prompt specification
Build or customize the Three.js 3D scene "Seasonal daylight reading room" 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: Seasonal daylight reading room
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/seasonal-daylight-reading-room-x0240
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a window seat. Build a reading room with several window niches and adjustable sun direction; compare illuminated seating areas with clear illustrative shadow controls and no claims about exact solar dates. Low-poly.
Working Three.js Starter (seasonal-daylight-reading-room-x0240):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Window Seat — Low-Poly Daylight Study</title>
<style>
:root {
color-scheme: light;
--ink: #27322f;
--muted: #68736e;
--panel: rgba(250, 248, 241, 0.94);
--line: rgba(55, 68, 63, 0.14);
--green: #3f9272;
--amber: #d69a32;
--slate: #748a94;
--accent: #e6a83e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e6e1d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 20px;
left: 20px;
z-index: 5;
max-width: min(440px, calc(100vw - 390px));
pointer-events: none;
text-shadow: 0 1px 18px rgba(255, 255, 255, 0.8);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 7px;
padding: 5px 9px;
border: 1px solid rgba(39, 50, 47, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.72);
color: #52605b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
content: "";
box-shadow: 0 0 0 3px rgba(230, 168, 62, 0.16);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 750;
}
.subtitle {
max-width: 400px;
margin: 9px 0 0;
color: #58645f;
font-size: 13px;
line-height: 1.45;
}
.panel {
position: fixed;
top: 18px;
right: 18px;
z-index: 10;
width: 342px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 19px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(62, 51, 36, 0.17),
inset 0 0 0 1px rgba(45, 57, 52, 0.04);
backdrop-filter: blur(16px) saturate(1.1);
scrollbar-width: thin;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.panel-head h2 {
margin: 0 0 3px;
font-size: 16px;
letter-spacing: -0.015em;
}
.panel-head p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.mini-button {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.72);
color: #42504b;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
.mini-button:hover {
background: white;
color: #1e2925;
}
.section {
padding: 13px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
border-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #3d4a45;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.105em;
text-transform: uppercase;
}
.section-title span {
color: #8a948f;
font-size: 9px;
font-weight: 650;
letter-spacing: 0;
text-transform: none;
}
.control {
margin-bottom: 13px;
}
.control:last-child {
margin-bottom: 0;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
font-size: 12px;
font-weight: 650;
}
output {
min-width: 44px;
color: #6b766f;
font-size: 11px;
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
accent-color: var(--accent);
cursor: ew-resize;
}
.range-note {
margin: 4px 0 0;
color: #89918d;
font-size: 9.5px;
line-height: 1.35;
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 10px;
}
.preset {
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: #53605b;
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
.preset:hover {
background: white;
transform: translateY(-1px);
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 7px 0;
color: #4a5752;
font-size: 11.5px;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 31px;
height: 17px;
margin: 0;
accent-color: var(--green);
cursor: pointer;
}
.toggle-description {
margin: -3px 0 6px;
color: #89928d;
font-size: 9.5px;
line-height: 1.35;
}
.zones {
display: grid;
gap: 8px;
}
.zone {
display: grid;
grid-template-columns: 25px 1fr;
gap: 9px;
align-items: center;
padding: 9px;
border: 1px solid rgba(55, 68, 63, 0.09);
border-radius: 11px;
background: rgba(255, 255, 255, 0.45);
}
.zone-letter {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 8px;
background: var(--zone-color, var(--slate));
color: white;
font-size: 11px;
font-weight: 850;
}
.zone-copy {
min-width: 0;
}
.zone-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 5px;
font-size: 10.5px;
font-weight: 750;
}
.zone-state {
color: var(--zone-color, var(--slate));
font-size: 9px;
white-space: nowrap;
}
.bar {
height: 4px;
overflow: hidden;
border-radius: 99px;
background: rgba(45, 57, 52, 0.09);
}
.bar i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--zone-color, var(--slate));
transition: width 220ms ease, background 220ms ease;
}
.proxy-note {
margin: 9px 0 0;
color: #8a938e;
font-size: 9.5px;
line-height: 1.4;
}
.disclaimer {
margin: 12px 0 0;
padding: 10px 11px;
border: 1px solid rgba(218, 154, 50, 0.24);
border-radius: 11px;
background: rgba(236, 190, 92, 0.09);
color: #77623d;
font-size: 9.5px;
line-height: 1.45;
}
.disclaimer strong {
color: #5c4a2d;
}
.legend {
position: fixed;
bottom: 18px;
left: 18px;
z-index: 6;
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
max-width: min(500px, calc(100vw - 390px));
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 12px;
background: rgba(250, 248, 241, 0.82);
color: #59645f;
box-shadow: 0 8px 25px rgba(64, 54, 40, 0.1);
backdrop-filter: blur(10px);
font-size: 9.5px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: #e6a83e;
}
.swatch.guide {
border: 1px solid #d89a36;
background: rgba(230, 168, 62, 0.18);
}
.swatch.green {
background: var(--green);
}
.hint {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 5;
color: rgba(54, 65, 60, 0.72);
font-size: 10px;
pointer-events: none;
text-shadow: 0 1px 10px white;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #e6e1d7;
color: #59645f;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
}
.brand h1 {
font-size: 28px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 52vh;
padding: 14px;
border-radius: 16px;
}
.legend {
display: none;
}
.hint {
top: 98px;
right: 14px;
bottom: auto;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly reading room with adjustable window light"></canvas>
<header class="brand">
<div class="eyebrow">Illustrative daylight study</div>
<h1>Window Seat</h1>
<p class="subtitle">
Explore how a manually chosen light direction falls across four reading-room niches.
</p>
</header>
<aside class="panel" aria-label="Daylight controls">
<div class="panel-head">
<div>
<h2>Light & shadow controls</h2>
<p>Change the direction of the directional light.</p>
</div>
<button id="resetView" class="mini-button" type="button">Reset view</button>
</div>
<section class="section">
<div class="section-title">
Sun direction
<span>manual geometry</span>
</div>
<div class="control">
<label class="control-label" for="azimuth">
Horizontal angle
<output id="azimuthOutput" for="azimuth">32°</output>
</label>
<input id="azimuth" type="range" min="-70" max="70" step="1" value="32" />
<p class="range-note">
0° points squarely through the window wall; positive angles turn toward the back.
</p>
</div>
<div class="control">
<label class="control-label" for="elevation">
Height above floor
<output id="elevationOutput" for="elevation">34°</output>
</label>
<input id="elevation" type="range" min="8" max="72" step="1" value="34" />
<p class="range-note">A visual angle only, not tied to a clock time or calendar date.</p>
</div>
<div class="control">
<label class="control-label" for="intensity">
Directional strength
<output id="intensityOutput" for="intensity">1.8</output>
</label>
<input id="intensity" type="range" min="0.5" max="2.8" step="0.1" value="1.8" />
</div>
<div class="presets" aria-label="Direction presets">
<button class="preset" type="button" data-preset="low">Low angle</button>
<button class="preset" type="button" data-preset="middle">Middle angle</button>
<button class="preset" type="button" data-preset="high">High angle</button>
</div>
</section>
<section class="section">
<div class="section-title">
Shadow display
<span>visual layers</span>
</div>
<label class="toggle">
<span>Cast directional shadows</span>
<input id="shadowsToggle" type="checkbox" checked />
</label>
<p class="toggle-description">
Keeps window frames, walls, furniture, and plants visible in the shadow map.
</p>
<label class="toggle">
<span>Window projection guides</span>
<input id="guidesToggle" type="checkbox" checked />
</label>
<p class="toggle-description">
Shows simplified floor footprints projected from each opening.
</p>
<label class="toggle">
<span>Seat access markers</span>
<input id="markersToggle" type="checkbox" checked />
</label>
</section>
<section class="section">
<div class="section-title">
Seat light comparison
<span>straight-line proxy</span>
</div>
<div class="zones">
<div class="zone" id="zoneA">
<div class="zone-letter">A</div>
<div class="zone-copy">
<div class="zone-heading">
<span>Window niche A</span>
<span class="zone-state">—</span>
</div>
<div class="bar"><i></i></div>
</div>
</div>
<div class="zone" id="zoneB">
<div class="zone-letter">B</div>
<div class="zone-copy">
<div class="zone-heading">
<span>Window niche B</span>
<span class="zone-state">—</span>
</div>
<div class="bar"><i></i></div>
</div>
</div>
<div class="zone" id="zoneC">
<div class="zone-letter">C</div>
<div class="zone-copy">
<div class="zone-heading">
<span>Window niche C</span>
<span class="zone-state">—</span>
</div>
<div class="bar"><i></i></div>
</div>
</div>
<div class="zone" id="zoneD">
<div class="zone-letter">D</div>
<div class="zone-copy">
<div class="zone-heading">
<span>Window niche D</span>
<span class="zone-state">—</span>
</div>
<div class="bar"><i></i></div>
</div>
</div>
</div>
<p class="proxy-note">
The bars compare whether a straight line from each seat reaches a window opening,
with a simplified edge-of-light fallback. They are not measured illumination values.
</p>
</section>
<p class="disclaimer">
<strong>Conceptual model.</strong> No solar dates, clock times, site coordinates,
glazing specifications, or exact solar-performance claims are used.
</p>
</aside>
<div class="legend" aria-label="Scene legend">
<span class="legend-item"><i class="swatch"></i>Directional light</span>
<span class="legend-item"><i class="swatch guide"></i>Projected opening</span>
<span class="legend-item"><i class="swatch green"></i>Direct opening proxy</span>
</div>
<div class="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<div id="loading">Building the reading room…</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 loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe6e1d7);
scene.fog = new THREE.Fog(0xe6e1d7, 25, 47);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraHome = {
target: new THREE.Vector3(-1.2, 1.45, 0),
radius: 17.5,
theta: 0.72,
phi: 1.03
};
const cameraState = {
target: cameraHome.target.clone(),
radius: cameraHome.radius,
theta: cameraHome.theta,
phi: cameraHome.phi
};
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
updateCamera();
const state = {
azimuth: 32,
elevation: 34,
intensity: 1.8,
shadows: true,
guides: true,
markers: true
};
const room = new THREE.Group();
const guideGroup = new THREE.Group();
const markerGroup = new THREE.Group();
scene.add(room, guideGroup, markerGroup);
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xeee7dc,
roughness: 0.92
}),
wallTrim: new THREE.MeshStandardMaterial({
color: 0xd8cdbd,
roughness: 0.86
}),
floor: new THREE.MeshStandardMaterial({
color: 0xc9ad86,
roughness: 0.94
}),
floorLine: new THREE.MeshStandardMaterial({
color: 0xae8d67,
roughness: 1
}),
frame: new THREE.MeshStandardMaterial({
color: 0x53625d,
roughness: 0.72
}),
wood: new THREE.MeshStandardMaterial({
color: 0x86694e,
roughness: 0.82
}),
dark: new THREE.MeshStandardMaterial({
color: 0x3f4845,
roughness: 0.78
}),
cream: new THREE.MeshStandardMaterial({
color: 0xeee4cf,
roughness: 0.85
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x53775b,
roughness: 0.9
}),
pot: new THREE.MeshStandardMaterial({
color: 0xb86f4d,
roughness: 0.9
})
};
function addBox(
width,
height,
depth,
x,
y,
z,
material,
options = {}
) {
const {
castShadow = true,
receiveShadow = true,
parent = room
} = options;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function addCylinder(
topRadius,
bottomRadius,
height,
x,
y,
z,
material,
segments = 10,
options = {}
) {
const {
castShadow = true,
receiveShadow = true,
parent = room
} = options;
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function addLabelSprite(text, background = "#f8f3e8", foreground = "#35433e") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.fillStyle = background;
context.beginPath();
context.roundRect(8, 8, 240, 112, 24);
context.fill();
context.fillStyle = foreground;
context.font = "800 52px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.15, 0.58, 1);
sprite.renderOrder = 20;
return sprite;
}
// Room shell: open front and low right wall for a dollhouse-like view.
addBox(14.3, 0.16, 12.3, 0, -0.09, 0, materials.floor);
addBox(14.2, 4.7, 0.22, 0, 2.35, -6.02, materials.wall);
addBox(0.22, 1.05, 12.1, 7.02, 0.525, 0, materials.wall);
addBox(14.1, 0.13, 0.09, 0, 0.12, -5.87, materials.wallTrim);
addBox(0.09, 0.13, 12, 6.87, 0.12, 0, materials.wallTrim);
addBox(14.15, 0.12, 0.16, 0, 4.64, -5.95, materials.wallTrim);
// Simple plank seams.
for (let z = -5.45; z < 6; z += 1.1) {
addBox(
13.9,
0.009,
0.018,
0,
0.004,
z,
materials.floorLine,
{ castShadow: false }
);
}
// Back-wall furniture and artwork.
addBox(2.35, 0.16, 0.52, 1.7, 1.65, -5.72, materials.wood);
addBox(2.2, 0.72, 0.42, 1.7, 2.08, -5.74, materials.cream);
const artMaterial = new THREE.MeshStandardMaterial({
color: 0xc77755,
roughness: 0.86
});
addBox(1.55, 1.2, 0.09, 1.7, 3.02, -5.83, materials.frame);
addBox(1.34, 0.99, 0.035, 1.7, 3.02, -5.76, artMaterial);
addBox(
0.16,
0.72,
0.04,
1.53,
2.98,
-5.72,
materials.cream,
{ castShadow: false }
);
const windowCenters = [-4.35, -1.45, 1.45, 4.35];
const windowWidth = 1.8;
const sillHeight = 0.95;
const windowTop = 3.65;
const wallX = -7.0;
const wallThickness = 0.24;
// Window wall assembled around real openings so the sun casts through them.
addBox(
wallThickness,
sillHeight,
12,
wallX,
sillHeight / 2,
0,
materials.wall
);
addBox(
wallThickness,
4.7 - windowTop,
12,
wallX,
(windowTop + 4.7) / 2,
0,
materials.wall
);
const solidIntervals = [
[-6, -5.25],
[-3.45, -2.35],
[-0.55, 0.55],
[2.35, 3.45],
[5.25, 6]
];
for (const [start, end] of solidIntervals) {
addBox(
wallThickness,
windowTop - sillHeight,
end - start,
wallX,
(sillHeight + windowTop) / 2,
(start + end) / 2,
materials.wall
);
}
const skyMaterial = new THREE.MeshBasicMaterial({
color: 0xc5dce3
});
windowCenters.forEach((center, index) => {
// A simple exterior sky card sits behind each opening but does not block light.
addBox(
0.025,
2.55,
1.66,
-7.17,
2.30,
center,
skyMaterial,
{ castShadow: false, receiveShadow: false }
);
// Frames.
for (const z of [center - 0.87, center + 0.87]) {
addBox(
0.18,
2.73,
0.075,
-6.86,
2.30,
z,
materials.frame
);
}
for (const y of [0.98, 3.62]) {
addBox(
0.18,
0.075,
1.82,
-6.86,
y,
center,
materials.frame
);
}
addBox(
0.13,
2.62,
0.055,
-6.84,
2.30,
center,
materials.frame
);
// Deep niche cheeks and header.
for (const z of [center - 0.98, center + 0.98]) {
addBox(
0.72,
2.78,
0.12,
-6.57,
2.30,
z,
materials.wallTrim
);
}
addBox(
0.72,
0.12,
2.07,
-6.57,
3.73,
center,
materials.wallTrim
);
// Sill.
addBox(
0.55,
0.12,
2.02,
-6.75,
0.91,
center,
materials.cream
);
// Small identification card above the frame.
const label = addLabelSprite(String.fromCharCode(65 + index));
label.position.set(-6.48, 4.08, center);
label.scale.set(0.58, 0.29, 1);
room.add(label);
});
const chairMaterials = [
new THREE.MeshStandardMaterial({ color: 0xc76f50, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0x5f8c86, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0xd0a148, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0x667e9c, roughness: 0.88 })
];
const rugMaterials = [
new THREE.MeshStandardMaterial({ color: 0xd9c8ac, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xb9c7b9, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xd5b7a5, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xb9c3cf, roughness: 1 })
];
const areaData = [
{ x: -5.52, zOffset: 0.22, depthOffset: 0.10 },
{ x: -5.42, zOffset: -0.42, depthOffset: 0.18 },
{ x: -5.55, zOffset: 0.40, depthOffset: 0.08 },
{ x: -5.38, zOffset: -0.45, depthOffset: 0.24 }
];
const areas = [];
function createChair(index, center, data) {
const chairX = data.x;
const chairZ = center + data.zOffset;
// Rug.
addBox(
2.55,
0.022,
2.15,
-4.82,
0.014,
chairZ,
rugMaterials[index]
);
// Low-poly chair facing the window.
addBox(
1.00,
0.22,
0.88,
chairX,
0.58,
chairZ,
chairMaterials[index]
);
addBox(
0.20,
0.98,
0.88,
chairX + 0.44,
1.05,
chairZ,
chairMaterials[index]
);
for (const z of [chairZ - 0.45, chairZ + 0.45]) {
addBox(
0.92,
0.10,
0.09,
chairX - 0.02,
0.94,
z,
materials.wood
);
}
for (const xOffset of [-0.32, 0.32]) {
for (const zOffset of [-0.29, 0.29]) {
addBox(
0.10,
0.47,
0.10,
chairX + xOffset,
0.25,
chairZ + zOffset,
materials.dark
);
}
}
// Open book on the chair.
const bookMaterial = new THREE.MeshStandardMaterial({
color: 0xf0e7d1,
roughness: 0.9
});
const book = addBox(
0.34,
0.045,
0.28,
chairX - 0.18,
0.72,
chairZ - 0.08,
bookMaterial
);
book.rotation.y = -0.16;
// Side table.
const tableX = chairX - 0.26;
const tableZ = chairZ + 0.88;
addCylinder(
0.34,
0.38,
0.10,
tableX,
0.66,
tableZ,
materials.wood,
10
);
addCylinder(
0.055,
0.08,
0.61,
tableX,
0.31,
tableZ,
materials.dark,
8
);
// Little reading lamp.
addCylinder(
0.025,
0.025,
0.48,
tableX,
0.94,
tableZ,
materials.dark,
7
);
const shadeMaterial = new THREE.MeshStandardMaterial({
color: 0xe8b65b,
emissive: 0x6a4217,
emissiveIntensity: 0.15,
roughness: 0.85
});
const shade = new THREE.Mesh(
new THREE.CylinderGeometry(0.10, 0.20, 0.27, 8, 1, true),
shadeMaterial
);
shade.position.set(tableX, 1.19, tableZ);
shade.castShadow = true;
room.add(shade);
// Floor marker and floating letter.
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x748a94,
transparent: true,
opacity: 0.85,
side: THREE.DoubleSide,
depthWrite: false
});
const marker = new THREE.Mesh(
new THREE.RingGeometry(0.58, 0.69, 32),
markerMaterial
);
marker.rotation.x = -Math.PI / 2;
marker.position.set(chairX, 0.032, chairZ);
marker.renderOrder = 3;
markerGroup.add(marker);
const label = addLabelSprite(String.fromCharCode(65 + index));
label.position.set(chairX + 0.15, 1.95, chairZ);
label.scale.set(0.60, 0.30, 1);
markerGroup.add(label);
areas.push({
index,
center,
x: chairX,
z: chairZ,
marker,
markerMaterial,
card: document.querySelector(`#zone${String.fromCharCode(65 + index)}`)
});
}
areaData.forEach((data, index) => {
createChair(index, windowCenters[index], data);
});
// A plant between the middle niches adds a small readable cast shadow.
function addPlant(x, z) {
addCylinder(0.26, 0.20, 0.42, x, 0.22, z, materials.pot, 8);
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x486348,
roughness: 0.95
});
addCylinder(
0.025,
0.035,
0.75,
x,
0.72,
z,
stemMaterial,
7
);
const leafGeometry = new THREE.IcosahedronGeometry(0.32, 0);
const leafPositions = [
[-0.22, 0.88, 0.03, 1.15],
[0.22, 1.03, -0.05, 1.0],
[-0.08, 1.24, 0.12, 0.82],
[0.16, 1.40, 0.08, 0.66]
];
for (const [lx, ly, lz, scale] of leafPositions) {
const leaf = new THREE.Mesh(leafGeometry, materials.leaf);
leaf.position.set(x + lx, ly, z + lz);
leaf.scale.set(scale, scale * 0.7, scale * 0.62);
leaf.rotation.set(lx, ly, lz);
leaf.castShadow = true;
leaf.receiveShadow = true;
room.add(leaf);
}
}
addPlant(-6.17, 0.02);
// Ambient fill keeps the shaded reading areas legible.
const hemisphere = new THREE.HemisphereLight(0xe7f1f4, 0x8a735a, 0.78);
scene.add(hemisphere);
const fill = new THREE.AmbientLight(0xfff3df, 0.16);
scene.add(fill);
const sunLight = new THREE.DirectionalLight(0xffd58f, state.intensity);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(
window.innerWidth < 760 ? 1024 : 2048,
window.innerWidth < 760 ? 1024 : 2048
);
sunLight.shadow.camera.left = -11;
sunLight.shadow.camera.right = 11;
sunLight.shadow.camera.top = 10;
sunLight.shadow.camera.bottom = -10;
sunLight.shadow.camera.near = 0.5;
sunLight.shadow.camera.far = 48;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.035;
scene.add(sunLight);
scene.add(sunLight.target);
// 3D sun-direction marker.
const sunMarker = new THREE.Group();
const sunSphere = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.32, 1),
new THREE.MeshBasicMaterial({ color: 0xf2b94c })
);
sunMarker.add(sunSphere);
const sunLabel = addLabelSprite("SUN", "#f1b84d", "#4c3817");
sunLabel.position.y = 0.58;
sunLabel.scale.set(0.72, 0.36, 1);
sunMarker.add(sunLabel);
const directionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
2.6,
0xe4a638,
0.52,
0.28
);
sunMarker.add(directionArrow);
scene.add(sunMarker);
const sunDirection = new THREE.Vector3();
const projectedPolygons = [];
function updateSunDirection() {
const horizontal = THREE.MathUtils.degToRad(state.azimuth);
const vertical = THREE.MathUtils.degToRad(state.elevation);
sunDirection.set(
-Math.cos(vertical) * Math.cos(horizontal),
Math.sin(vertical),
-Math.cos(vertical) * Math.sin(horizontal)
);
sunLight.position.copy(sunDirection).multiplyScalar(20);
sunLight.target.position.set(0, 0, 0);
sunLight.intensity = state.intensity;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
if (child.geometry) {
child.geometry.dispose();
}
if (child.material) {
const materialsToDispose = Array.isArray(child.material)
? child.material
: [child.material];
for (const material of materialsToDispose) {
if (material.map) {
material.map.dispose();
}
material.dispose();
}
}
}
}
function projectedWindowPolygon(center) {
const travel = sunDirection.clone().multiplyScalar(-1);
const corners = [
new THREE.Vector3(-6.88, 0.98, center - windowWidth / 2),
new THREE.Vector3(-6.88, 0.98, center + windowWidth / 2),
new THREE.Vector3(-6.88, 3.62, center + windowWidth / 2),
new THREE.Vector3(-6.88, 3.62, center - windowWidth / 2)
];
return corners.map((corner) => {
const t = (0.024 - corner.y) / travel.y;
return new THREE.Vector3(
corner.x + travel.x * t,
0.024,
corner.z + travel.z * t
);
});
}
function rebuildProjectionGuides() {
clearGroup(guideGroup);
projectedPolygons.length = 0;
const fillMaterial = new THREE.MeshBasicMaterial({
color: 0xf2b94d,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
});
const lineMaterial = new THREE.LineBasicMaterial({
color: 0xd89b38,
transparent: true,
opacity: 0.72,
depthWrite: false
});
for (const center of windowCenters) {
const polygon = projectedWindowPolygon(center);
projectedPolygons.push(polygon);
const positions = new Float32Array([
polygon[0].x, polygon[0].y, polygon[0].z,
polygon[1].x, polygon[1].y, polygon[1].z,
polygon[2].x, polygon[2].y, polygon[2].z,
polygon[0].x, polygon[0].y, polygon[0].z,
polygon[2].x, polygon[2].y, polygon[2].z,
polygon[3].x, polygon[3].y, polygon[3].z
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const fillMesh = new THREE.Mesh(geometry, fillMaterial);
fillMesh.renderOrder = 2;
guideGroup.add(fillMesh);
const lineGeometry = new THREE.BufferGeometry().setFromPoints(polygon);
const outline = new THREE.LineLoop(lineGeometry, lineMaterial);
outline.renderOrder = 4;
guideGroup.add(outline);
}
guideGroup.visible = state.guides;
}
function pointInPolygon(point, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const xi = polygon[i].x;
const zi = polygon[i].z;
const xj = polygon[j].x;
const zj = polygon[j].z;
const intersects =
zi > point.z !== zj > point.z &&
point.x <
((xj - xi) * (point.z - zi)) / (zj - zi) + xi;
if (intersects) {
inside = !inside;
}
}
return inside;
}
function distanceToSegment(point, a, b) {
const ab = new THREE.Vector2(b.x - a.x, b.z - a.z);
const ap = new THREE.Vector2(point.x - a.x, point.z - a.z);
const lengthSquared = ab.lengthSq();
const t = lengthSquared === 0
? 0
: THREE.MathUtils.clamp(ap.dot(ab) / lengthSquared, 0, 1);
const closest = new THREE.Vector2(
a.x + ab.x * t,
a.z + ab.y * t
);
return Math.hypot(point.x - closest.x, point.z - closest.y);
}
function distanceToPolygon(point, polygon) {
if (pointInPolygon(point, polygon)) {
return 0;
}
let minimum = Infinity;
for (let i = 0; i < polygon.length; i++) {
const next = (i + 1) % polygon.length;
minimum = Math.min(
minimum,
distanceToSegment(point, polygon[i], polygon[next])
);
}
return minimum;
}
function updateSeatComparison() {
const seatPoint = new THREE.Vector3();
const intersection = new THREE.Vector3();
for (const area of areas) {
seatPoint.set(area.x, 0.66, area.z);
let direct = false;
if (sunDirection.x < -0.025) {
const t = (-6.88 - area.x) / sunDirection.x;
intersection.copy(seatPoint).addScaledVector(sunDirection, t);
const inHeight =
intersection.y >= 0.98 &&
intersection.y <= 3.62;
const inOpening = windowCenters.some(
(center) =>
Math.abs(intersection.z - center) <= windowWidth / 2 - 0.04
);
direct = inHeight && inOpening;
}
let score = 0.08;
let label = "Shaded proxy";
let color = 0x748a94;
if (direct) {
score = 1;
label = "Direct opening";
color = 0x3f9272;
} else {
const floorPoint = new THREE.Vector3(area.x, 0.024, area.z);
let nearest = Infinity;
for (const polygon of projectedPolygons) {
nearest = Math.min(
nearest,
distanceToPolygon(floorPoint, polygon)
);
}
if (nearest < 0.95) {
score = 0.48;
label = "Edge / partial";
color = 0xd69a32;
}
}
area.markerMaterial.color.setHex(color);
const cssColor = `#${color.toString(16).padStart(6, "0")}`;
area.card.style.setProperty("--zone-color", cssColor);
area.card.querySelector(".zone-state").textContent = label;
area.card.querySelector(".bar i").style.width = `${score * 100}%`;
}
}
function updateSunGizmo() {
const origin = new THREE.Vector3(-0.7, 1.55, 0);
const markerPosition = origin.clone().addScaledVector(sunDirection, 5.4);
sunMarker.position.copy(markerPosition);
directionArrow.setDirection(sunDirection.clone().negate());
}
function applySunState() {
updateSunDirection();
rebuildProjectionGuides();
updateSeatComparison();
updateSunGizmo();
sunLight.castShadow = state.shadows;
renderer.shadowMap.enabled = state.shadows;
renderer.shadowMap.needsUpdate = true;
guideGroup.visible = state.guides;
markerGroup.visible = state.markers;
}
// UI synchronization.
const azimuthInput = document.querySelector("#azimuth");
const elevationInput = document.querySelector("#elevation");
const intensityInput = document.querySelector("#intensity");
const azimuthOutput = document.querySelector("#azimuthOutput");
const elevationOutput = document.querySelector("#elevationOutput");
const intensityOutput = document.querySelector("#intensityOutput");
function syncUI() {
azimuthInput.value = state.azimuth;
elevationInput.value = state.elevation;
intensityInput.value = state.intensity;
azimuthOutput.textContent = `${state.azimuth}°`;
elevationOutput.textContent = `${state.elevation}°`;
intensityOutput.textContent = Number(state.intensity).toFixed(1);
}
azimuthInput.addEventListener("input", () => {
state.azimuth = Number(azimuthInput.value);
syncUI();
applySunState();
});
elevationInput.addEventListener("input", () => {
state.elevation = Number(elevationInput.value);
syncUI();
applySunState();
});
intensityInput.addEventListener("input", () => {
state.intensity = Number(intensityInput.value);
syncUI();
applySunState();
});
const presets = {
low: { azimuth: 18, elevation: 12, intensity: 2.15 },
middle: { azimuth: 32, elevation: 34, intensity: 1.8 },
high: { azimuth: -10, elevation: 62, intensity: 1.55 }
};
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
Object.assign(state, presets[button.dataset.preset]);
syncUI();
applySunState();
});
});
document.querySelector("#shadowsToggle").addEventListener("change", (event) => {
state.shadows = event.target.checked;
applySunState();
});
document.querySelector("#guidesToggle").addEventListener("change", (event) => {
state.guides = event.target.checked;
guideGroup.visible = state.guides;
});
document.querySelector("#markersToggle").addEventListener("change", (event) => {
state.markers = event.target.checked;
markerGroup.visible = state.markers;
});
// Custom orbit, pan-free camera controls implemented without addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) {
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.38,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== activePointerId) {
return;
}
dragging = false;
activePointerId = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
28
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraState.target.copy(cameraHome.target);
cameraState.radius = cameraHome.radius;
cameraState.theta = cameraHome.theta;
cameraState.phi = cameraHome.phi;
updateCamera();
}
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#resetView").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
syncUI();
applySunState();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
loading.remove();
</script>
</body>
</html>
```