Prompt specification
Build or customize the Three.js 3D scene "Classroom with shaded daylight openings" 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: Classroom with shaded daylight openings
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/classroom-with-shaded-daylight-openings-x2239
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: classroom with shaded daylight openings. Create a cutaway classroom with windows, desks, and an exterior overhang. Move the sun through a short arc and keep direct sunlight distinct from simplified ambient illumination. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (classroom-with-shaded-daylight-openings-x2239):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sunlit Cutaway Classroom</title>
<style>
:root {
--ink: #19313a;
--muted: #60727a;
--panel: rgba(250, 248, 239, 0.88);
--line: rgba(25, 49, 58, 0.14);
--sun: #f5bc55;
--ambient: #a8c7db;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8dce3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.title {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
pointer-events: none;
text-shadow: 0 1px 18px rgba(255,255,255,0.55);
}
.eyebrow {
margin: 0 0 7px;
color: #45616b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 38px);
line-height: 0.95;
letter-spacing: -0.045em;
font-weight: 850;
}
.subtitle {
margin: 10px 0 0;
color: #526a72;
font-size: 12px;
max-width: 360px;
line-height: 1.45;
}
.help {
position: fixed;
right: 24px;
top: 25px;
z-index: 5;
padding: 8px 11px;
border: 1px solid rgba(255,255,255,0.45);
border-radius: 999px;
background: rgba(248,246,238,0.64);
color: #536a72;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.panel {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 6;
width: min(720px, calc(100% - 28px));
transform: translateX(-50%);
padding: 13px 15px;
border: 1px solid rgba(255,255,255,0.68);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 45px rgba(31, 53, 58, 0.16);
backdrop-filter: blur(14px);
}
.panel-row {
display: flex;
align-items: center;
gap: 13px;
}
button {
border: 0;
border-radius: 10px;
background: var(--ink);
color: #fffdf5;
min-width: 86px;
height: 38px;
padding: 0 14px;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover { background: #284852; }
button:active { transform: translateY(1px); }
button.secondary {
min-width: 42px;
padding: 0 12px;
color: var(--ink);
background: rgba(25,49,58,0.09);
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(245,188,85,0.7);
outline-offset: 2px;
}
.timeline {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 11px;
min-width: 0;
flex: 1;
}
.timeline label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(90deg, #e3b65a, #f4d895 45%, #e3b65a);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #fffdf5;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 7px rgba(20,40,48,0.25);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #fffdf5;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 7px rgba(20,40,48,0.25);
}
#angle {
min-width: 57px;
color: #7c5a20;
font-size: 11px;
font-variant-numeric: tabular-nums;
font-weight: 850;
text-align: right;
}
.legend {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.legend-items {
display: flex;
gap: 16px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.swatch.sun { background: var(--sun); }
.swatch.ambient { background: var(--ambient); }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c8dce3;
color: #48626b;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.title { top: 18px; left: 18px; }
.subtitle { max-width: 245px; font-size: 11px; }
.help { display: none; }
.panel { bottom: 12px; padding: 11px; }
.panel-row { gap: 8px; }
.timeline { grid-template-columns: 1fr auto; }
.timeline label { display: none; }
button { min-width: 72px; height: 36px; padding: 0 10px; }
.legend { font-size: 9px; }
.legend-items { gap: 10px; }
}
</style>
</head>
<body>
<div id="app"></div>
<header class="title">
<p class="eyebrow">Low-poly daylight study</p>
<h1>Sunlit classroom</h1>
<p class="subtitle">A cutaway room with deep window reveals, a shaded exterior overhang, and sunlight sweeping through the openings.</p>
</header>
<div class="help">Drag to orbit · Scroll to zoom</div>
<section class="panel" aria-label="Sunlight controls">
<div class="panel-row">
<button id="play" type="button" aria-label="Pause sun animation">Ⅱ Pause</button>
<div class="timeline">
<label for="sun-position">Sun arc</label>
<input id="sun-position" type="range" min="0" max="100" value="18" aria-label="Sun position along its arc">
<output id="angle" aria-live="polite">AZ −35°</output>
</div>
<button id="reset" class="secondary" type="button" title="Reset camera view" aria-label="Reset camera view">↺</button>
</div>
<div class="legend">
<div class="legend-items">
<span class="legend-item"><i class="swatch sun"></i> Direct sun + cast shadows</span>
<span class="legend-item"><i class="swatch ambient"></i> Simplified cool ambient</span>
</div>
<span>8:30 AM — 11:30 AM</span>
</div>
</section>
<div id="loading">Building the classroom…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("app");
const loading = document.getElementById("loading");
const playButton = document.getElementById("play");
const resetButton = document.getElementById("reset");
const slider = document.getElementById("sun-position");
const angleOutput = document.getElementById("angle");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
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", "Interactive cutaway classroom scene");
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8dce3);
scene.fog = new THREE.Fog(0xc8dce3, 27, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Camera controls are implemented locally without external controls modules.
const view = {
target: new THREE.Vector3(0, 1.05, -0.45),
theta: 0.69,
phi: 1.10,
radius: 20.5,
targetTheta: 0.69,
targetPhi: 1.10,
targetRadius: 20.5
};
function updateCamera() {
view.theta += (view.targetTheta - view.theta) * 0.12;
view.phi += (view.targetPhi - view.phi) * 0.12;
view.radius += (view.targetRadius - view.radius) * 0.12;
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function resetCamera() {
view.targetTheta = 0.69;
view.targetPhi = 1.10;
view.targetRadius = 20.5;
}
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
view.targetTheta -= dx * 0.0055;
view.targetPhi = THREE.MathUtils.clamp(
view.targetPhi - dy * 0.0045,
0.58,
1.36
);
});
function endDrag(event) {
dragging = false;
if (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();
view.targetRadius = THREE.MathUtils.clamp(
view.targetRadius * Math.exp(event.deltaY * 0.001),
13,
30
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
function matte(color, options = {}) {
return new THREE.MeshLambertMaterial({
color,
flatShading: true,
...options
});
}
const materials = {
wall: matte(0xeee7d7),
sideWall: matte(0xdce4d8),
trim: matte(0xfffaf0),
wood: matte(0xc58b59),
woodEdge: matte(0x7b5139),
floor: matte(0xd4bc94),
floorEdge: matte(0x9b7352),
metal: matte(0x3f5559),
chair: matte(0x658a86),
chairAlt: matte(0xbd765d),
frame: matte(0xfff7e8),
darkFrame: matte(0x315158),
board: matte(0x355f61),
boardInset: matte(0xe8eee5),
accent: matte(0xe4a845),
blue: matte(0x5e8ca3),
red: matte(0xc86855),
green: matte(0x7a9b68),
paper: matte(0xf4efdf),
ground: matte(0xa7b7a2),
exterior: matte(0xbec8b5),
foliage: matte(0x789168),
foliageLight: matte(0x91a978),
trunk: matte(0x8c684a)
};
function box(parent, w, h, d, material, x = 0, y = 0, z = 0, cast = true, receive = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radius, height, material, x = 0, y = 0, z = 0, segments = 6) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Lighting: a warm shadow-casting source is deliberately separate from
// the broad, cool ambient approximation.
const ambient = new THREE.HemisphereLight(0xcbe3f2, 0x78634d, 0.72);
scene.add(ambient);
const sunLight = new THREE.DirectionalLight(0xffd483, 3.8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -12;
sunLight.shadow.camera.right = 12;
sunLight.shadow.camera.top = 12;
sunLight.shadow.camera.bottom = -12;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 40;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.025;
sunLight.target.position.set(0, 0.25, -0.4);
scene.add(sunLight, sunLight.target);
// Exterior ground and distant low-poly landscape.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.22;
ground.receiveShadow = true;
scene.add(ground);
box(scene, 15.5, 0.08, 7.2, materials.exterior, 0, -0.17, -8.0, false, true);
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.16, z);
group.scale.setScalar(scale);
cylinder(group, 0.16, 1.7, materials.trunk, 0, 0.85, 0, 6);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.15, 0),
materials.foliage
);
crown.position.set(0, 2.05, 0);
crown.scale.set(1, 1.2, 0.95);
crown.rotation.set(0.2, 0.4, 0.1);
crown.castShadow = true;
crown.receiveShadow = true;
group.add(crown);
const crownTop = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 0),
materials.foliageLight
);
crownTop.position.set(0.28, 2.85, -0.05);
crownTop.rotation.set(0.5, 0.2, 0.15);
crownTop.castShadow = true;
group.add(crownTop);
scene.add(group);
}
makeTree(-7.5, -10.2, 1.12);
makeTree(6.3, -10.8, 0.92);
makeTree(1.8, -14.0, 1.35);
// Classroom slab and subtle floor grid.
box(scene, 13.25, 0.3, 9.25, materials.floorEdge, 0, -0.15, 0);
box(scene, 13.0, 0.08, 9.0, materials.floor, 0, 0.0, 0, false, true);
const gridPositions = [];
for (let x = -6; x <= 6; x += 1.2) {
gridPositions.push(x, 0.046, -4.45, x, 0.046, 4.45);
}
for (let z = -4.2; z <= 4.2; z += 1.2) {
gridPositions.push(-6.45, 0.046, z, 6.45, 0.046, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x876e52,
transparent: true,
opacity: 0.2
})
);
scene.add(grid);
// Cutaway room: full rear and left walls; front and right walls removed.
box(scene, 13.0, 1.05, 0.26, materials.wall, 0, 0.525, -4.5);
box(scene, 13.0, 0.80, 0.26, materials.wall, 0, 3.45, -4.5);
box(scene, 0.26, 3.85, 9.2, materials.sideWall, -6.5, 1.925, 0);
const windowWidth = 2.55;
const windowBottom = 1.05;
const windowTop = 3.05;
const windowHeight = windowTop - windowBottom;
const windowCenters = [-4.1, 0, 4.1];
// Solid piers between the three actual openings.
const pierRanges = [
[-6.5, -5.375],
[-2.825, -1.275],
[1.275, 2.825],
[5.375, 6.5]
];
for (const [left, right] of pierRanges) {
box(
scene,
right - left,
windowHeight,
0.26,
materials.wall,
(left + right) / 2,
(windowBottom + windowTop) / 2,
-4.5
);
}
// Trim around the cutaway edges.
box(scene, 13.0, 0.13, 0.08, materials.trim, 0, 0.12, -4.34);
box(scene, 0.08, 0.13, 9.0, materials.trim, -6.34, 0.12, 0);
box(scene, 0.18, 0.11, 9.0, materials.floorEdge, -6.46, 3.86, 0);
const glassMaterial = new THREE.MeshBasicMaterial({
color: 0xb9e1e7,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
depthWrite: false
});
windowCenters.forEach((center) => {
const left = center - windowWidth / 2;
const right = center + windowWidth / 2;
const glass = new THREE.Mesh(
new THREE.PlaneGeometry(windowWidth - 0.12, windowHeight - 0.12),
glassMaterial
);
glass.position.set(center, (windowBottom + windowTop) / 2, -4.49);
scene.add(glass);
// Window jambs.
box(scene, 0.11, windowHeight, 0.14, materials.frame, left + 0.055, 2.05, -4.35);
box(scene, 0.11, windowHeight, 0.14, materials.frame, right - 0.055, 2.05, -4.35);
// Header and sill.
box(scene, windowWidth, 0.11, 0.14, materials.frame, center, windowTop - 0.055, -4.35);
box(scene, windowWidth, 0.11, 0.14, materials.frame, center, windowBottom + 0.055, -4.35);
// Slender mullions create crisp shadows within each opening.
box(scene, 0.065, windowHeight - 0.14, 0.13, materials.frame, center, 2.05, -4.34);
box(scene, windowWidth - 0.14, 0.065, 0.13, materials.frame, center, 2.02, -4.34);
// Deep interior sill.
box(scene, windowWidth + 0.18, 0.11, 0.45, materials.trim, center, 1.01, -4.29);
});
// Exterior overhang and supports.
box(scene, 14.2, 0.22, 3.15, materials.darkFrame, 0, 3.48, -6.02);
box(scene, 14.25, 0.28, 0.16, materials.metal, 0, 3.32, -7.55);
box(scene, 0.20, 3.35, 0.20, materials.darkFrame, -6.05, 1.60, -7.18);
box(scene, 0.20, 3.35, 0.20, materials.darkFrame, 6.05, 1.60, -7.18);
const brace = box(scene, 0.15, 1.25, 0.15, materials.metal, -6.05, 2.95, -6.83);
brace.rotation.x = -0.72;
const brace2 = box(scene, 0.15, 1.25, 0.15, materials.metal, 6.05, 2.95, -6.83);
brace2.rotation.x = -0.72;
// Whiteboard on the left wall.
box(scene, 0.12, 1.48, 3.15, materials.board, -6.31, 2.08, 0.55);
box(scene, 0.045, 1.28, 2.94, materials.boardInset, -6.235, 2.08, 0.55);
box(scene, 0.18, 0.07, 2.85, materials.metal, -6.18, 1.43, 0.55);
const noteColors = [materials.accent, materials.blue, materials.red, materials.green];
for (let i = 0; i < 4; i++) {
const note = box(
scene,
0.025,
0.28,
0.28,
noteColors[i],
-6.195,
2.28 + (i % 2) * 0.10,
-0.45 + i * 0.56
);
note.rotation.x = (i % 2 ? -1 : 1) * 0.05;
}
// Small wall clock.
const clock = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.07, 12),
materials.trim
);
clock.rotation.z = Math.PI / 2;
clock.position.set(-6.29, 2.85, -2.55);
clock.castShadow = true;
scene.add(clock);
const clockFace = new THREE.Mesh(
new THREE.CircleGeometry(0.21, 12),
materials.paper
);
clockFace.rotation.y = Math.PI / 2;
clockFace.position.set(-6.245, 2.85, -2.55);
scene.add(clockFace);
// Low-poly student desks and chairs.
const bookMaterials = [materials.red, materials.blue, materials.green, materials.accent];
function makeDesk(x, z, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = ((index % 3) - 1) * 0.018;
scene.add(group);
const chairMaterial = index % 4 === 0 ? materials.chairAlt : materials.chair;
// Desktop and underside.
box(group, 1.68, 0.11, 0.82, materials.wood, 0, 0.80, 0);
box(group, 1.52, 0.18, 0.09, materials.woodEdge, 0, 0.66, 0.26);
// Four legs.
for (const lx of [-0.68, 0.68]) {
for (const lz of [-0.28, 0.28]) {
box(group, 0.075, 0.74, 0.075, materials.metal, lx, 0.37, lz);
}
}
// Books and loose paper.
const book = box(
group,
0.40,
0.055,
0.48,
bookMaterials[index % bookMaterials.length],
-0.34,
0.885,
-0.05
);
book.rotation.y = 0.10;
box(group, 0.33, 0.018, 0.42, materials.paper, 0.25, 0.868, -0.08);
// Pencil cup.
cylinder(group, 0.075, 0.17, materials.blue, 0.58, 0.935, -0.18, 6);
const pencil = box(group, 0.025, 0.22, 0.025, materials.accent, 0.58, 1.06, -0.18);
pencil.rotation.z = -0.13;
// Chair behind the desk.
const chair = new THREE.Group();
chair.position.set(0, 0, 0.86);
group.add(chair);
box(chair, 0.65, 0.10, 0.60, chairMaterial, 0, 0.44, 0);
box(chair, 0.65, 0.42, 0.09, chairMaterial, 0, 0.72, 0.27);
for (const lx of [-0.24, 0.24]) {
for (const lz of [-0.20, 0.20]) {
box(chair, 0.055, 0.39, 0.055, materials.metal, lx, 0.195, lz);
}
}
}
let deskIndex = 0;
for (const z of [-2.35, -0.25, 1.85]) {
for (const x of [-3.8, 0, 3.8]) {
makeDesk(x, z, deskIndex++);
}
}
// A small teacher's console beneath the middle window.
box(scene, 1.85, 0.13, 0.78, materials.wood, 0, 0.92, -3.65);
box(scene, 1.62, 0.18, 0.10, materials.woodEdge, 0, 0.78, -3.42);
for (const x of [-0.74, 0.74]) {
box(scene, 0.09, 0.86, 0.62, materials.metal, x, 0.43, -3.65);
}
const teacherBook = box(scene, 0.52, 0.07, 0.38, materials.blue, -0.38, 1.02, -3.65);
teacherBook.rotation.y = -0.10;
// Visible short solar arc and a non-lighting sun marker.
const arcPoints = [];
for (let i = 0; i <= 64; i++) {
const u = i / 64;
arcPoints.push(
new THREE.Vector3(
THREE.MathUtils.lerp(-8.5, 8.5, u),
4.35 + 0.60 * Math.sin(Math.PI * u),
-11.5
)
);
}
const arcLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineBasicMaterial({
color: 0xf2bf58,
transparent: true,
opacity: 0.42
})
);
scene.add(arcLine);
const sunMarker = new THREE.Group();
const sunDisk = new THREE.Mesh(
new THREE.SphereGeometry(0.38, 10, 7),
new THREE.MeshBasicMaterial({ color: 0xffd66f })
);
const sunHalo = new THREE.Mesh(
new THREE.SphereGeometry(0.66, 10, 7),
new THREE.MeshBasicMaterial({
color: 0xffd66f,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
sunMarker.add(sunDisk, sunHalo);
scene.add(sunMarker);
function placeSun(u) {
const x = THREE.MathUtils.lerp(-8.5, 8.5, u);
const y = 4.35 + 0.60 * Math.sin(Math.PI * u);
sunLight.position.set(x, y, -11.5);
sunMarker.position.copy(sunLight.position);
const azimuth = Math.round(-58 + u * 116);
angleOutput.textContent = `AZ ${azimuth < 0 ? "−" : "+"}${Math.abs(azimuth)}°`;
slider.value = String(Math.round(u * 100));
}
let playing = true;
let elapsed = 0;
const cycleDuration = 16;
let scrubbing = false;
function updatePlaybackButton() {
playButton.textContent = playing ? "Ⅱ Pause" : "▶ Play";
playButton.setAttribute(
"aria-label",
playing ? "Pause sun animation" : "Play sun animation"
);
}
playButton.addEventListener("click", () => {
playing = !playing;
updatePlaybackButton();
});
slider.addEventListener("pointerdown", () => {
scrubbing = true;
});
slider.addEventListener("input", () => {
const u = Number(slider.value) / 100;
const raw = u <= 0.5 ? u / 2 : 1 - u / 2;
elapsed = raw * cycleDuration;
placeSun(u);
});
window.addEventListener("pointerup", () => {
scrubbing = false;
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
playing = !playing;
updatePlaybackButton();
}
if (event.key.toLowerCase() === "r") resetCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.fov = camera.aspect < 0.8 ? 55 : 42;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
placeSun(0.18);
const animationClock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(animationClock.getDelta(), 0.05);
if (playing && !scrubbing) {
elapsed = (elapsed + delta) % cycleDuration;
const raw = elapsed / cycleDuration;
const u = raw < 0.5 ? raw * 2 : (1 - raw) * 2;
placeSun(u);
}
updateCamera();
renderer.render(scene, camera);
if (!loading.classList.contains("hidden")) {
loading.classList.add("hidden");
}
});
</script>
</body>
</html>
```