Prompt specification
Build or customize the Three.js 3D scene "Courtyard shade over a day" 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: Courtyard shade over a day
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-shade-over-a-day-x1254
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Arrange a wall, tree, bench, and paved courtyard under a moving light arc; show shadow positions at labeled illustrative times without claiming a location-specific solar ephemeris.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Define and initialize all resources used for the sun and halo before rendering. Show how the visible courtyard shadows change over the day.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (courtyard-shade-over-a-day-x1254):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Courtyard — Synthetic Light and Shadow Study</title>
<style>
:root {
--ink: #173b37;
--muted: #5e716d;
--paper: rgba(248, 246, 236, 0.88);
--panel: rgba(20, 52, 49, 0.91);
--panel-soft: rgba(255, 255, 255, 0.09);
--accent: #f2bd67;
--accent-2: #9ed3b0;
--line: rgba(255, 255, 255, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9d3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#viewport canvas.dragging { cursor: grabbing; }
.intro {
position: fixed;
z-index: 4;
top: 24px;
left: 28px;
width: min(390px, calc(100vw - 56px));
pointer-events: none;
text-shadow: 0 1px 18px rgba(246, 245, 233, 0.7);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 11px;
border: 1px solid rgba(23, 59, 55, 0.19);
border-radius: 999px;
background: rgba(248, 246, 236, 0.7);
color: #31534d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(242, 189, 103, 0.2);
}
h1 {
margin: 13px 0 7px;
max-width: 360px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.3vw, 47px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro p {
margin: 0;
max-width: 355px;
color: #405d57;
font-size: 13px;
line-height: 1.55;
}
.intro p strong { color: #244b45; }
.controls {
position: fixed;
z-index: 6;
right: 22px;
bottom: 22px;
width: 326px;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 19px;
background: var(--panel);
color: #f7f4e9;
box-shadow: 0 22px 60px rgba(22, 45, 41, 0.28);
backdrop-filter: blur(17px) saturate(1.1);
}
.control-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.control-heading strong {
display: block;
font-size: 12px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.control-heading span {
display: block;
margin-top: 4px;
color: #b9cac5;
font-size: 10px;
line-height: 1.35;
}
.synthetic-chip {
flex: none;
padding: 5px 7px;
border: 1px solid rgba(242, 189, 103, 0.35);
border-radius: 7px;
color: #ffd897;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.times {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.time-button {
min-height: 59px;
padding: 8px 5px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel-soft);
color: #dce7e2;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.time-button:hover {
background: rgba(255, 255, 255, 0.14);
transform: translateY(-1px);
}
.time-button.active {
border-color: rgba(242, 189, 103, 0.8);
background: rgba(242, 189, 103, 0.18);
color: #fff0cf;
}
.time-button b {
display: block;
font-size: 11px;
letter-spacing: 0.08em;
}
.time-button small {
display: block;
margin-top: 4px;
color: #a9beb7;
font-size: 9px;
}
.time-button.active small { color: #e8d4af; }
.slider-row {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
gap: 10px;
margin: 14px 0 11px;
color: #afc2bb;
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 3px;
border-radius: 3px;
background: linear-gradient(90deg, #e5b86e, #9bd3ae, #e5b86e);
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
margin-top: -6px;
appearance: none;
border: 3px solid #f9f1dc;
border-radius: 50%;
background: #345c55;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-track {
height: 3px;
border-radius: 3px;
background: linear-gradient(90deg, #e5b86e, #9bd3ae, #e5b86e);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #f9f1dc;
border-radius: 50%;
background: #345c55;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
.action-button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.08);
color: #f3f5eb;
cursor: pointer;
font-size: 11px;
font-weight: 700;
}
.action-button:hover { background: rgba(255, 255, 255, 0.14); }
.play-button {
border-color: rgba(242, 189, 103, 0.5);
background: rgba(242, 189, 103, 0.16);
color: #ffe0a8;
}
.status {
min-height: 17px;
margin: 10px 0 11px;
color: #d5e2dc;
font-size: 10px;
line-height: 1.4;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.metric {
min-height: 50px;
padding: 8px 9px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(0, 0, 0, 0.08);
}
.metric span {
display: block;
color: #9fb5ae;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 5px;
color: #f3f3e9;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 600;
}
.note {
margin: 11px 0 0;
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.12);
color: #adc0ba;
font-size: 9px;
line-height: 1.5;
}
.note b { color: #e7d2aa; }
.hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 24px;
padding: 8px 11px;
border: 1px solid rgba(23, 59, 55, 0.13);
border-radius: 999px;
background: rgba(248, 246, 236, 0.67);
color: #49655f;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #cbd9d3;
color: #294d47;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
[hidden] { display: none !important; }
@media (max-width: 760px) {
.intro {
top: 14px;
left: 15px;
width: calc(100vw - 30px);
}
h1 {
max-width: 270px;
font-size: 31px;
}
.intro p { max-width: 300px; font-size: 11px; }
.hint { display: none; }
.controls {
right: 11px;
bottom: 11px;
left: 11px;
width: auto;
padding: 13px;
border-radius: 15px;
}
.metrics { grid-template-columns: repeat(4, 1fr); }
.metric { min-height: 46px; padding: 6px; }
.metric strong { font-size: 9px; }
.note { font-size: 8px; }
}
@media (max-height: 680px) and (min-width: 761px) {
.controls { padding: 13px; }
.note { margin-top: 8px; padding-top: 7px; }
.metric { min-height: 44px; padding: 6px 8px; }
.time-button { min-height: 52px; }
}
</style>
</head>
<body>
<main id="app">
<div id="viewport" aria-label="Stylized courtyard with a moving synthetic light and live shadows"></div>
<header class="intro">
<div class="eyebrow">Synthetic light study</div>
<h1>Courtyard<br>Arc & Shadow</h1>
<p>
A wall, tree, bench, and paved court under a deliberately schematic light arc.
<strong>Times and angles are illustrative—not a solar ephemeris.</strong>
</p>
</header>
<section class="controls" aria-label="Synthetic light controls and live shadow data">
<div class="control-heading">
<div>
<strong>Illustrative time</strong>
<span>Select a labeled reference or sweep the arc.</span>
</div>
<div class="synthetic-chip">Synthetic</div>
</div>
<div class="times" role="group" aria-label="Labeled illustrative times">
<button type="button" class="time-button active" data-time="0" aria-pressed="true">
<b>T1 · 08:00</b>
<small>left / schematic</small>
</button>
<button type="button" class="time-button" data-time="0.5" aria-pressed="false">
<b>T2 · 12:00</b>
<small>high / schematic</small>
</button>
<button type="button" class="time-button" data-time="1" aria-pressed="false">
<b>T3 · 16:00</b>
<small>right / schematic</small>
</button>
</div>
<div class="slider-row">
<label for="timeSlider">Arc</label>
<input id="timeSlider" type="range" min="0" max="1" step="0.001" value="0"
aria-label="Position along the synthetic light arc">
</div>
<div class="actions">
<button type="button" id="playButton" class="action-button play-button">Pause sweep</button>
<button type="button" id="resetView" class="action-button">Reset view</button>
</div>
<div id="status" class="status" aria-live="polite">T1 · 08:00 — illustrative</div>
<div class="metrics">
<div class="metric">
<span>Live light X / Y / Z</span>
<strong id="lightPosition">—</strong>
</div>
<div class="metric">
<span>Ground axis</span>
<strong id="shadowAxis">—</strong>
</div>
<div class="metric">
<span>Tree ref. X / Z</span>
<strong id="treePosition">—</strong>
</div>
<div class="metric">
<span>Bench ref. X / Z</span>
<strong id="benchPosition">—</strong>
</div>
</div>
<p class="note">
<b>Reference dots are schematic projections</b> of live anchor points on the modeled tree and bench.
The soft shadows on the paving are rendered by the same directional light. No site, date,
latitude, or location-specific solar calculation is represented.
</p>
</section>
<div class="hint">Drag to orbit · wheel to zoom · double-click to reset</div>
<div id="loading">Preparing the schematic courtyard…</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const viewport = $("viewport");
// -------------------------------------------------------------------------
// Renderer, camera, and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9d3);
scene.fog = new THREE.Fog(0xcbd9d3, 31, 58);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.02;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive schematic courtyard. Drag to orbit and use the on-screen controls to change the illustrative light."
);
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.25, -0.8);
const defaultView = { theta: 0.56, phi: 1.23, radius: 25.5 };
let cameraTheta = defaultView.theta;
let cameraPhi = defaultView.phi;
let cameraRadius = defaultView.radius;
function updateCamera() {
camera.position.setFromSphericalCoords(
cameraRadius,
cameraPhi,
cameraTheta
).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff4d8, 0x60776c, 1.55);
scene.add(hemisphere);
const fill = new THREE.DirectionalLight(0xdbe8e5, 0.38);
fill.position.set(9, 7, 11);
scene.add(fill);
// -------------------------------------------------------------------------
// Procedural textures and labels
// -------------------------------------------------------------------------
function createHaloTexture() {
const size = 256;
const canvas = document.createElement("canvas");
canvas.width = size;
canvas.height = size;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
size * 0.5, size * 0.5, 0,
size * 0.5, size * 0.5, size * 0.5
);
gradient.addColorStop(0.00, "rgba(255,255,244,1)");
gradient.addColorStop(0.08, "rgba(255,241,190,0.98)");
gradient.addColorStop(0.20, "rgba(255,215,129,0.56)");
gradient.addColorStop(0.43, "rgba(255,196,94,0.19)");
gradient.addColorStop(0.72, "rgba(255,196,94,0.045)");
gradient.addColorStop(1.00, "rgba(255,196,94,0)");
context.clearRect(0, 0, size, size);
context.fillStyle = gradient;
context.fillRect(0, 0, size, size);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
return texture;
}
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width * 0.5, height * 0.5);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function createTextSprite(primary, secondary = "") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 7, 7, 498, 130, 25);
context.fillStyle = "rgba(247,244,229,0.94)";
context.fill();
context.lineWidth = 4;
context.strokeStyle = "rgba(34,67,61,0.34)";
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#214943";
context.font = "700 40px system-ui, sans-serif";
context.fillText(primary, 256, secondary ? 57 : 73);
if (secondary) {
context.fillStyle = "#6b7e76";
context.font = "700 23px system-ui, sans-serif";
context.fillText(secondary.toUpperCase(), 256, 103);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.0,
...options
});
}
function addBox(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(parent, start, end, bottomRadius, topRadius, material, sides = 9) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
topRadius,
bottomRadius,
length,
sides,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Courtyard paving and surrounding ground
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
standardMaterial(0x8da68c, { roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.28;
ground.receiveShadow = true;
scene.add(ground);
const courtBase = addBox(
scene, 16.2, 0.28, 12.5,
standardMaterial(0x9f998c),
0, -0.12, 0.15
);
courtBase.castShadow = false;
const borderMaterial = standardMaterial(0x857f73);
addBox(scene, 16.35, 0.18, 0.24, borderMaterial, 0, 0.02, -6.04);
addBox(scene, 16.35, 0.18, 0.24, borderMaterial, 0, 0.02, 6.34);
addBox(scene, 0.24, 0.18, 12.15, borderMaterial, -8.0, 0.02, 0.15);
addBox(scene, 0.24, 0.18, 12.15, borderMaterial, 8.0, 0.02, 0.15);
const tileGeometry = new THREE.BoxGeometry(1.43, 0.10, 1.27);
const tileMaterial = standardMaterial(0xffffff, { roughness: 0.96 });
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, 80);
tiles.castShadow = true;
tiles.receiveShadow = true;
const tileMatrix = new THREE.Object3D();
const tilePalette = [
0xc8c0b2, 0xd5ccba, 0xbdb8ac, 0xc2b7a4,
0xd9d0bf, 0xb7b8ae, 0xcfc5b2, 0xc0aa98
];
let randomSeed = 8127;
function seededRandom() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
let tileIndex = 0;
for (let row = 0; row < 8; row++) {
for (let column = 0; column < 10; column++) {
tileMatrix.position.set(
(column - 4.5) * 1.5,
0.055,
(row - 3.5) * 1.35 + 0.15
);
tileMatrix.rotation.set(0, 0, 0);
tileMatrix.updateMatrix();
tiles.setMatrixAt(tileIndex, tileMatrix.matrix);
const baseColor = new THREE.Color(
tilePalette[Math.floor(seededRandom() * tilePalette.length)]
);
baseColor.offsetHSL(0, 0, (seededRandom() - 0.5) * 0.035);
tiles.setColorAt(tileIndex, baseColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// -------------------------------------------------------------------------
// Stylized rear wall
// -------------------------------------------------------------------------
const wall = new THREE.Group();
scene.add(wall);
const wallMaterial = standardMaterial(0xe4dcc7);
const wallInsetMaterial = standardMaterial(0xd7ceba);
const wallCapMaterial = standardMaterial(0xc9bca4);
addBox(wall, 15.5, 3.35, 0.48, wallMaterial, 0, 1.67, -5.65);
addBox(wall, 15.82, 0.22, 0.66, wallCapMaterial, 0, 3.45, -5.65);
[-7.35, -3.68, 0, 3.68, 7.35].forEach((x) => {
addBox(wall, 0.36, 3.58, 0.62, wallCapMaterial, x, 1.79, -5.60);
});
[-5.5, -1.85, 1.85, 5.5].forEach((x) => {
addBox(wall, 2.92, 2.25, 0.065, wallInsetMaterial, x, 1.65, -5.375);
});
// -------------------------------------------------------------------------
// Low-poly tree
// -------------------------------------------------------------------------
const tree = new THREE.Group();
tree.position.set(-4.05, 0.10, -1.45);
scene.add(tree);
const trunkMaterial = standardMaterial(0x75563d, { roughness: 0.96 });
const branchMaterial = standardMaterial(0x6b513b, { roughness: 0.98 });
const leafMaterialA = standardMaterial(0x587d55, { flatShading: true });
const leafMaterialB = standardMaterial(0x72935f, { flatShading: true });
const leafMaterialC = standardMaterial(0x476e53, { flatShading: true });
addCylinderBetween(
tree,
[0, 0.10, 0],
[0.16, 2.75, 0.03],
0.29, 0.18,
trunkMaterial, 9
);
addCylinderBetween(
tree, [0.10, 2.35, 0], [-0.90, 3.42, 0.10],
0.13, 0.08, branchMaterial, 8
);
addCylinderBetween(
tree, [0.12, 2.55, 0], [0.82, 3.62, -0.18],
0.14, 0.08, branchMaterial, 8
);
addCylinderBetween(
tree, [0.10, 2.65, 0.02], [0.12, 4.15, 0.16],
0.11, 0.065, branchMaterial, 8
);
addCylinderBetween(
tree, [0.05, 2.55, 0], [-0.20, 3.55, 0.80],
0.11, 0.07, branchMaterial, 8
);
addCylinderBetween(
tree, [0.10, 2.70, 0], [0.55, 3.48, -0.70],
0.11, 0.07, branchMaterial, 8
);
const leafGeometry = new THREE.IcosahedronGeometry(1, 1);
const crown = [
{ p: [-0.92, 3.63, 0.12], s: [1.18, 1.02, 1.08], m: leafMaterialA },
{ p: [0.78, 3.75, -0.18], s: [1.16, 1.04, 1.05], m: leafMaterialB },
{ p: [0.05, 4.38, 0.16], s: [1.15, 1.15, 1.03], m: leafMaterialC },
{ p: [-0.25, 3.63, 0.86], s: [1.10, 0.93, 1.05], m: leafMaterialB },
{ p: [0.56, 3.47, -0.77], s: [1.02, 0.92, 0.98], m: leafMaterialA },
{ p: [-0.12, 3.15, -0.08], s: [1.12, 0.88, 1.08], m: leafMaterialC }
];
crown.forEach((cluster) => {
const leaf = new THREE.Mesh(leafGeometry, cluster.m);
leaf.position.set(...cluster.p);
leaf.scale.set(...cluster.s);
leaf.rotation.set(
seededRandom() * 0.4,
seededRandom() * Math.PI,
seededRandom() * 0.25
);
leaf.castShadow = true;
leaf.receiveShadow = true;
tree.add(leaf);
});
const treeAnchor = new THREE.Object3D();
treeAnchor.position.set(0.05, 4.38, 0.16);
tree.add(treeAnchor);
// -------------------------------------------------------------------------
// Terracotta bench
// -------------------------------------------------------------------------
const bench = new THREE.Group();
bench.position.set(2.55, 0.11, -2.15);
bench.rotation.y = -0.10;
scene.add(bench);
const benchWoodMaterial = standardMaterial(0xb86948, { roughness: 0.8 });
const benchDarkMaterial = standardMaterial(0x46514a, { roughness: 0.78, metalness: 0.12 });
[-0.36, -0.12, 0.12, 0.36].forEach((z) => {
addBox(bench, 3.45, 0.13, 0.18, benchWoodMaterial, 0, 0.76, z);
});
[1.12, 1.47, 1.82].forEach((y) => {
addBox(bench, 3.45, 0.22, 0.13, benchWoodMaterial, 0, y, -0.56);
});
[-1.38, 1.38].forEach((x) => {
addBox(bench, 0.13, 1.78, 0.14, benchDarkMaterial, x, 0.92, -0.57);
addBox(bench, 0.13, 0.73, 0.13, benchDarkMaterial, x, 0.39, 0.32);
addBox(bench, 0.13, 0.73, 0.13, benchDarkMaterial, x, 0.39, -0.30);
});
addBox(bench, 3.10, 0.12, 0.12, benchDarkMaterial, 0, 0.35, 0.32);
addBox(bench, 3.10, 0.12, 0.12, benchDarkMaterial, 0, 0.35, -0.30);
const benchAnchor = new THREE.Object3D();
benchAnchor.position.set(0, 1.82, -0.56);
bench.add(benchAnchor);
// -------------------------------------------------------------------------
// Synthetic light path, directional light, and visible halo
// -------------------------------------------------------------------------
const ARC_RADIUS = 8.6;
const ARC_BASE = 6.2;
const ARC_RISE = 5.5;
const ARC_Z = -7.3;
function lightPositionForT(t) {
const angle = Math.PI * THREE.MathUtils.clamp(t, 0, 1);
return new THREE.Vector3(
-ARC_RADIUS * Math.cos(angle),
ARC_BASE + ARC_RISE * Math.sin(angle),
ARC_Z
);
}
class ArcCurve extends THREE.Curve {
getPoint(t, target = new THREE.Vector3()) {
const angle = Math.PI * t;
return target.set(
-ARC_RADIUS * Math.cos(angle),
ARC_BASE + ARC_RISE * Math.sin(angle),
ARC_Z
);
}
}
const arcTube = new THREE.Mesh(
new THREE.TubeGeometry(new ArcCurve(), 128, 0.035, 6, false),
new THREE.MeshBasicMaterial({
color: 0xe7b96d,
transparent: true,
opacity: 0.72,
toneMapped: false
})
);
scene.add(arcTube);
const arcPoints = [];
for (let i = 0; i <= 100; i++) {
arcPoints.push(lightPositionForT(i / 100));
}
const arcGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineDashedMaterial({
color: 0xffdfa2,
dashSize: 0.22,
gapSize: 0.14,
transparent: true,
opacity: 0.55,
toneMapped: false
})
);
arcGuide.computeLineDistances();
scene.add(arcGuide);
const directionalLight = new THREE.DirectionalLight(0xffdfaa, 3.65);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.set(2048, 2048);
directionalLight.shadow.camera.left = -13;
directionalLight.shadow.camera.right = 13;
directionalLight.shadow.camera.top = 13;
directionalLight.shadow.camera.bottom = -13;
directionalLight.shadow.camera.near = 0.5;
directionalLight.shadow.camera.far = 42;
directionalLight.shadow.bias = -0.00025;
directionalLight.shadow.normalBias = 0.035;
scene.add(directionalLight);
const lightTargetPosition = new THREE.Vector3(0, 0, 0.1);
directionalLight.target.position.copy(lightTargetPosition);
scene.add(directionalLight.target);
const lightVisual = new THREE.Group();
scene.add(lightVisual);
const lightOrb = new THREE.Mesh(
new THREE.SphereGeometry(0.34, 24, 16),
new THREE.MeshBasicMaterial({ color: 0xfff0b8, toneMapped: false })
);
lightVisual.add(lightOrb);
const haloTexture = createHaloTexture();
const halo = new THREE.Sprite(
new THREE.SpriteMaterial({
map: haloTexture,
color: 0xffe4a7,
transparent: true,
opacity: 0.88,
blending: THREE.AdditiveBlending,
depthWrite: false,
fog: false,
toneMapped: false
})
);
halo.scale.set(3.8, 3.8, 1);
lightVisual.add(halo);
const referenceStates = [
{ id: "T1", clock: "08:00", t: 0.0 },
{ id: "T2", clock: "12:00", t: 0.5 },
{ id: "T3", clock: "16:00", t: 1.0 }
];
referenceStates.forEach((state, index) => {
const position = lightPositionForT(state.t);
const tick = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 14, 10),
new THREE.MeshBasicMaterial({ color: 0xf5c16d, toneMapped: false })
);
tick.position.copy(position);
scene.add(tick);
const label = createTextSprite(
`${state.id} · ${state.clock}`,
"illustrative"
);
label.scale.set(2.35, 0.66, 1);
label.position.copy(position);
label.position.y += index === 1 ? 1.05 : -0.92;
scene.add(label);
});
// -------------------------------------------------------------------------
// Live schematic projection markers
// -------------------------------------------------------------------------
function createReferenceMarker(color, labelText) {
const group = new THREE.Group();
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.13, 0.19, 32),
new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.95,
depthWrite: false,
toneMapped: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.renderOrder = 15;
group.add(ring);
const label = createTextSprite(labelText, "schematic ref.");
label.scale.set(1.25, 0.35, 1);
group.add(label);
scene.add(group);
return { group, ring, label };
}
const treeReference = createReferenceMarker(0x9fe0b6, "TREE REF.");
const benchReference = createReferenceMarker(0xffb36f, "BENCH REF.");
function createProjectionLine(color) {
const line = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color,
dashSize: 0.18,
gapSize: 0.12,
transparent: true,
opacity: 0.52,
toneMapped: false
})
);
line.renderOrder = 14;
scene.add(line);
return line;
}
const treeProjectionLine = createProjectionLine(0x91d9aa);
const benchProjectionLine = createProjectionLine(0xefaa6a);
const anchorWorld = new THREE.Vector3();
const projectedPoint = new THREE.Vector3();
const lightDirection = new THREE.Vector3();
function projectAnchorToGround(anchor) {
anchor.updateWorldMatrix(true, false);
anchor.getWorldPosition(anchorWorld);
lightDirection
.copy(lightTargetPosition)
.sub(directionalLight.position)
.normalize();
const distance = -anchorWorld.y / lightDirection.y;
projectedPoint
.copy(anchorWorld)
.addScaledVector(lightDirection, distance);
return projectedPoint;
}
function updateProjection(marker, line, anchor, color) {
const hit = projectAnchorToGround(anchor).clone();
marker.group.position.set(hit.x, 0.17, hit.z);
marker.label.position.set(0, 0.52, 0);
line.geometry.setFromPoints([anchorWorld.clone(), hit]);
line.computeLineDistances();
line.material.color.setHex(color);
}
// -------------------------------------------------------------------------
// State and interaction controls
// -------------------------------------------------------------------------
let currentT = 0;
let playing = true;
let playDirection = 1;
let transition = null;
let initialDelay = 1.15;
const slider = $("timeSlider");
const playButton = $("playButton");
const timeButtons = Array.from(document.querySelectorAll(".time-button"));
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Pause sweep" : "Play sweep";
}
function selectTime(t) {
transition = {
from: currentT,
to: THREE.MathUtils.clamp(t, 0, 1),
start: performance.now(),
duration: 850
};
initialDelay = 0;
setPlaying(false);
}
timeButtons.forEach((button) => {
button.addEventListener("click", () => {
selectTime(Number(button.dataset.time));
});
});
slider.addEventListener("input", () => {
currentT = Number(slider.value);
transition = null;
initialDelay = 0;
setPlaying(false);
});
playButton.addEventListener("click", () => {
transition = null;
initialDelay = 0;
setPlaying(!playing);
});
function resetCamera() {
cameraTheta = defaultView.theta;
cameraPhi = defaultView.phi;
cameraRadius = defaultView.radius;
updateCamera();
}
$("resetView").addEventListener("click", resetCamera);
// Direct, local camera controls; no addons and no pointer lock.
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.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= deltaX * 0.005;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + deltaY * 0.004, 0.56, 1.43);
updateCamera();
});
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("dblclick", resetCamera);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
17,
34
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraTheta -= 0.08;
else if (event.key === "ArrowRight") cameraTheta += 0.08;
else if (event.key === "ArrowUp") cameraPhi = THREE.MathUtils.clamp(cameraPhi - 0.06, 0.56, 1.43);
else if (event.key === "ArrowDown") cameraPhi = THREE.MathUtils.clamp(cameraPhi + 0.06, 0.56, 1.43);
else if (event.key.toLowerCase() === "r") resetCamera();
else return;
event.preventDefault();
updateCamera();
});
// -------------------------------------------------------------------------
// Live state updates and animation
// -------------------------------------------------------------------------
const statusElement = $("status");
const lightPositionElement = $("lightPosition");
const treePositionElement = $("treePosition");
const benchPositionElement = $("benchPosition");
const shadowAxisElement = $("shadowAxis");
let lastReadoutUpdate = 0;
let lastStatusText = "";
function nearestState(t) {
return referenceStates.reduce((nearest, state) =>
Math.abs(state.t - t) < Math.abs(nearest.t - t) ? state : nearest
);
}
function updateLightAndReferences(t) {
const lightPosition = lightPositionForT(t);
directionalLight.position.copy(lightPosition);
lightVisual.position.copy(lightPosition);
directionalLight.target.position.copy(lightTargetPosition);
directionalLight.target.updateMatrixWorld();
const treeHit = projectAnchorToGround(treeAnchor).clone();
treeReference.group.position.set(treeHit.x, 0.17, treeHit.z);
treeReference.label.position.set(0, 0.52, 0);
treeProjectionLine.geometry.setFromPoints([anchorWorld.clone(), treeHit]);
treeProjectionLine.computeLineDistances();
const benchHit = projectAnchorToGround(benchAnchor).clone();
benchReference.group.position.set(benchHit.x, 0.17, benchHit.z);
benchReference.label.position.set(0, 0.52, 0);
benchProjectionLine.geometry.setFromPoints([anchorWorld.clone(), benchHit]);
benchProjectionLine.computeLineDistances();
return { treeHit, benchHit };
}
function updateReadout(now, hits) {
if (now - lastReadoutUpdate < 75) return;
lastReadoutUpdate = now;
const p = directionalLight.position;
lightPositionElement.textContent =
`${p.x.toFixed(1)}, ${p.y.toFixed(1)}, ${p.z.toFixed(1)}`;
treePositionElement.textContent =
`${hits.treeHit.x.toFixed(1)}, ${hits.treeHit.z.toFixed(1)}`;
benchPositionElement.textContent =
`${hits.benchHit.x.toFixed(1)}, ${hits.benchHit.z.toFixed(1)}`;
const direction = lightTargetPosition.clone().sub(directionalLight.position).normalize();
const axis = THREE.MathUtils.radToDeg(Math.atan2(direction.x, direction.z));
shadowAxisElement.textContent = `${axis.toFixed(0)}° from +Z`;
slider.value = currentT.toFixed(3);
slider.setAttribute(
"aria-valuetext",
`${Math.round(currentT * 100)} percent along the synthetic arc`
);
const nearest = nearestState(currentT);
const exact = Math.abs(currentT - nearest.t) < 0.006;
timeButtons.forEach((button) => {
const active = exact && Number(button.dataset.time) === nearest.t;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
let statusText;
if (transition) {
statusText = `Moving to ${nearestState(transition.to).id} · ${nearestState(transition.to).clock} — illustrative`;
} else if (playing) {
statusText = "Continuous synthetic sweep — pause to inspect a labeled time";
} else if (exact) {
statusText = `${nearest.id} · ${nearest.clock} — illustrative`;
} else {
statusText = "Custom arc position — illustrative, not a solar time";
}
if (statusText !== lastStatusText) {
statusElement.textContent = statusText;
lastStatusText = statusText;
}
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", onResize);
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (initialDelay > 0) {
initialDelay = Math.max(0, initialDelay - delta);
} else if (playing) {
currentT += playDirection * delta / 18;
if (currentT >= 1) {
currentT = 1;
playDirection = -1;
} else if (currentT <= 0) {
currentT = 0;
playDirection = 1;
}
}
if (transition) {
const progress = THREE.MathUtils.clamp(
(now - transition.start) / transition.duration,
0,
1
);
const eased = progress < 0.5
? 4 * progress * progress * progress
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
currentT = THREE.MathUtils.lerp(transition.from, transition.to, eased);
if (progress >= 1) {
currentT = transition.to;
transition = null;
}
}
const hits = updateLightAndReferences(currentT);
updateReadout(now, hits);
renderer.render(scene, camera);
}
scene.updateMatrixWorld(true);
const initialHits = updateLightAndReferences(currentT);
updateReadout(performance.now(), initialHits);
$("loading").hidden = true;
requestAnimationFrame(animate);
</script>
</body>
</html>
```