Prompt specification
Build or customize the Three.js 3D scene "Summer Courtyard Shade Planning" 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: Summer Courtyard Shade Planning
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/summer-courtyard-shade-planning-x3971
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: summer courtyard shade planning. Build an original courtyard with trees, pergolas, and seating under a stated sun path. Compare shade availability across times without assuming shade alone defines comfort.
Working Three.js Starter (summer-courtyard-shade-planning-x3971):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Juniper Court — Summer Shade Planning</title>
<style>
:root {
--ink: #17352f;
--muted: #667b73;
--paper: rgba(248, 247, 239, 0.94);
--paper-solid: #f8f7ef;
--line: rgba(31, 68, 58, 0.16);
--green: #257e6d;
--green-light: #dceee6;
--gold: #e7a84c;
--coral: #d86f56;
--shadow: 0 18px 55px rgba(29, 54, 47, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dce9e4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
#sceneCanvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 16px;
left: 18px;
right: 18px;
height: 58px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand, .top-actions { pointer-events: auto; }
.brand {
display: flex;
align-items: center;
gap: 12px;
padding: 9px 14px 9px 10px;
border: 1px solid rgba(255,255,255,0.6);
border-radius: 15px;
background: rgba(248,247,239,0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.brand-mark {
width: 36px;
height: 36px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 2px;
transform: rotate(-4deg);
}
.brand-mark i {
display: block;
border-radius: 2px;
background: var(--green);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6) { background: #e5ad58; }
.brand-mark i:nth-child(3),
.brand-mark i:nth-child(7) { opacity: .45; }
.brand strong {
display: block;
font-size: 14px;
letter-spacing: .08em;
text-transform: uppercase;
}
.brand small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.top-actions {
display: flex;
gap: 8px;
align-items: center;
}
.chip, .icon-button {
border: 1px solid rgba(255,255,255,0.62);
background: rgba(248,247,239,0.9);
box-shadow: 0 8px 25px rgba(29,54,47,0.12);
backdrop-filter: blur(14px);
}
.chip {
padding: 10px 13px;
border-radius: 999px;
font-size: 11px;
font-weight: 750;
letter-spacing: .04em;
}
.icon-button {
height: 38px;
padding: 0 14px;
border-radius: 999px;
cursor: pointer;
font-size: 12px;
font-weight: 700;
}
.icon-button:hover { background: #fffdf6; }
.panel {
position: fixed;
z-index: 12;
border: 1px solid rgba(255,255,255,0.66);
border-radius: 20px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
#leftPanel {
top: 88px;
left: 18px;
width: 342px;
max-height: calc(100vh - 108px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(37,126,109,.35) transparent;
}
#rightPanel {
top: 88px;
right: 18px;
width: 276px;
}
.panel-inner { padding: 19px; }
.eyebrow {
margin: 0 0 7px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 500;
line-height: 1.04;
letter-spacing: -.02em;
}
.intro {
margin: 10px 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section {
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.section-title {
margin: 0 0 10px;
font-size: 11px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.time-main {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
#timeDisplay {
font-family: Georgia, "Times New Roman", serif;
font-size: 38px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
#sunReadout {
color: var(--muted);
font-size: 10px;
line-height: 1.5;
text-align: right;
}
.slider-row {
display: flex;
gap: 10px;
align-items: center;
margin: 14px 0 10px;
}
input[type="range"] {
width: 100%;
height: 5px;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(90deg, #e8b45e, #f3d89e 50%, #e8b45e);
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
appearance: none;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 8px rgba(0,0,0,.25);
cursor: grab;
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 8px rgba(0,0,0,.25);
cursor: grab;
}
#playButton {
flex: 0 0 36px;
width: 36px;
height: 36px;
border: 0;
border-radius: 50%;
background: var(--green);
color: white;
cursor: pointer;
font-size: 13px;
}
.quick-times {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.quick-times button {
padding: 7px 4px;
border: 1px solid var(--line);
border-radius: 8px;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
}
.quick-times button:hover,
.quick-times button.active {
border-color: var(--green);
background: var(--green-light);
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 12px;
font-weight: 700;
}
.switch {
position: relative;
width: 38px;
height: 21px;
}
.switch input {
position: absolute;
opacity: 0;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 999px;
background: #c9d1cc;
cursor: pointer;
transition: .2s;
}
.switch span::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 15px;
height: 15px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 4px rgba(0,0,0,.2);
transition: .2s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(17px); }
.metric-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
.metric-tabs button {
padding: 8px 5px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.metric-tabs button.active {
border-color: var(--green);
background: var(--green);
color: white;
}
.legend {
display: flex;
align-items: center;
gap: 8px;
margin-top: 10px;
color: var(--muted);
font-size: 9px;
}
.legend-bar {
flex: 1;
height: 6px;
border-radius: 999px;
background: linear-gradient(90deg, #319b88, #f0c568);
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.stat {
min-height: 70px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.45);
}
.stat-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .04em;
text-transform: uppercase;
}
.stat-value {
display: block;
margin-top: 6px;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
line-height: 1;
}
.stat-note {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.table-wrap { overflow-x: auto; }
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
th, td {
padding: 7px 4px;
border-bottom: 1px solid var(--line);
text-align: right;
}
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 800; }
th button {
padding: 0;
border: 0;
background: none;
cursor: pointer;
color: var(--green);
font-weight: 850;
}
.chart-wrap {
margin-top: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.42);
}
#dayChart { display: block; width: 100%; height: 122px; }
.chart-key {
display: flex;
gap: 14px;
padding: 0 9px 8px;
color: var(--muted);
font-size: 9px;
}
.chart-key i {
display: inline-block;
width: 15px;
height: 2px;
margin-right: 4px;
vertical-align: middle;
background: var(--green);
}
.chart-key .comfort-key i { background: var(--gold); }
.caveat {
margin: 11px 0 0;
padding: 10px;
border-left: 3px solid var(--gold);
border-radius: 0 8px 8px 0;
background: rgba(231,168,76,.10);
color: #685e4e;
font-size: 10px;
line-height: 1.5;
}
.spot-heading {
display: flex;
align-items: center;
gap: 12px;
}
#scoreRing {
--score: 0deg;
position: relative;
flex: 0 0 62px;
width: 62px;
height: 62px;
border-radius: 50%;
background: conic-gradient(var(--green) var(--score), #dbe2dc 0);
display: grid;
place-items: center;
}
#scoreRing::before {
content: "";
position: absolute;
inset: 7px;
border-radius: 50%;
background: var(--paper-solid);
}
#scoreValue {
position: relative;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
}
#pointName {
margin: 3px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 500;
}
#pointMeta {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.factor { margin-top: 13px; }
.factor-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font-size: 10px;
}
.factor-label span:last-child {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.factor-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: #dce3dd;
}
.factor-track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--green);
transition: width .25s ease;
}
#insightText {
margin: 13px 0 0;
padding: 11px;
border-radius: 10px;
background: var(--green-light);
color: #315a50;
font-size: 11px;
line-height: 1.45;
}
.compass-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.compass {
position: relative;
flex: 0 0 46px;
width: 46px;
height: 46px;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(255,255,255,.4);
}
.compass::after {
content: "N";
position: absolute;
top: 2px;
left: 0;
right: 0;
text-align: center;
color: var(--green);
font-size: 8px;
font-weight: 900;
}
#northNeedle {
position: absolute;
top: 12px;
left: 20px;
width: 2px;
height: 21px;
background: linear-gradient(var(--coral) 0 50%, #526b63 50% 100%);
transform-origin: 50% 11px;
}
#northNeedle::before {
content: "";
position: absolute;
top: -1px;
left: -3px;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 7px solid var(--coral);
}
.help-text {
margin-top: 12px;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
#labelsLayer {
position: fixed;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
padding: 5px 8px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 7px;
background: rgba(25,55,47,.76);
color: white;
white-space: nowrap;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
transform: translate(-50%, -50%);
box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.hour-label {
padding: 2px 5px;
border: 0;
background: rgba(248,247,239,.86);
color: #425e55;
box-shadow: none;
font-size: 8px;
}
dialog {
width: min(560px, calc(100vw - 32px));
padding: 0;
border: 0;
border-radius: 20px;
background: var(--paper-solid);
color: var(--ink);
box-shadow: 0 30px 90px rgba(20,40,35,.32);
}
dialog::backdrop {
background: rgba(24,48,41,.38);
backdrop-filter: blur(5px);
}
.dialog-body { padding: 24px; }
.dialog-body h2 {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 500;
}
.dialog-body p,
.dialog-body li {
color: #52675f;
font-size: 12px;
line-height: 1.55;
}
.dialog-body li { margin: 6px 0; }
.dialog-actions {
display: flex;
justify-content: flex-end;
margin-top: 18px;
}
.primary-button {
padding: 10px 16px;
border: 0;
border-radius: 10px;
background: var(--green);
color: white;
cursor: pointer;
font-weight: 800;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #dce9e4;
transition: opacity .35s ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
.loading-card {
padding: 18px 22px;
border-radius: 14px;
background: rgba(255,255,255,.8);
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 750;
}
@media (max-width: 1000px) {
#rightPanel { display: none; }
}
@media (max-width: 680px) {
.topbar { top: 10px; left: 10px; right: 10px; }
.brand { padding-right: 10px; }
.brand small, .chip { display: none; }
#leftPanel {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 48vh;
}
.panel-inner { padding: 15px; }
h1 { font-size: 23px; }
.intro { margin-bottom: 10px; }
}
</style>
</head>
<body>
<canvas id="sceneCanvas" aria-label="Interactive voxel courtyard shade study"></canvas>
<div id="labelsLayer"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div>
<strong>Juniper Court</strong>
<small>Summer shade & comfort planning</small>
</div>
</div>
<div class="top-actions">
<div class="chip">21 JULY · 40.7° N</div>
<button class="icon-button" id="methodButton">Method & assumptions</button>
</div>
</header>
<aside class="panel" id="leftPanel">
<div class="panel-inner">
<p class="eyebrow">Courtyard study 01</p>
<h1>Shade is useful.<br>Comfort is contextual.</h1>
<p class="intro">
Compare the courtyard at several solar times. Shade coverage is paired with
radiant load, warm-air, breeze, and humidity assumptions.
</p>
<section class="section">
<div class="section-title">Solar time</div>
<div class="time-main">
<div id="timeDisplay">12:00</div>
<div id="sunReadout">Loading sun path…</div>
</div>
<div class="slider-row">
<input id="timeSlider" type="range" min="6" max="19" step="0.25" value="12"
aria-label="Solar time">
<button id="playButton" title="Play through the day" aria-label="Play through the day">▶</button>
</div>
<div class="quick-times">
<button data-time="9">09:00</button>
<button data-time="12" class="active">12:00</button>
<button data-time="15">15:00</button>
<button data-time="18">18:00</button>
</div>
</section>
<section class="section">
<div class="section-title">Ground overlay</div>
<div class="toggle-row">
<span>Show analysis tiles</span>
<label class="switch">
<input id="heatmapToggle" type="checkbox" checked>
<span></span>
</label>
</div>
<div class="metric-tabs" aria-label="Overlay metric">
<button class="active" data-metric="shade">Shade</button>
<button data-metric="radiant">Radiant load</button>
<button data-metric="comfort">Comfort index</button>
</div>
<div class="legend">
<span id="legendLow">Shaded</span>
<div class="legend-bar" id="legendBar"></div>
<span id="legendHigh">Sunlit</span>
</div>
</section>
<section class="section">
<div class="section-title">At the selected time</div>
<div class="stats">
<div class="stat">
<span class="stat-label">Floor shaded</span>
<strong class="stat-value" id="shadeValue">—</strong>
<span class="stat-note">sampled paving area</span>
</div>
<div class="stat">
<span class="stat-label">Seats shaded</span>
<strong class="stat-value" id="seatShadeValue">—</strong>
<span class="stat-note">occupied seat height</span>
</div>
<div class="stat">
<span class="stat-label">Radiant load</span>
<strong class="stat-value" id="radiantValue">—</strong>
<span class="stat-note">mean absorbed W/m²</span>
</div>
<div class="stat">
<span class="stat-label">Comfort index</span>
<strong class="stat-value" id="comfortValue">—</strong>
<span class="stat-note">screening, not a standard</span>
</div>
</div>
</section>
<section class="section">
<div class="section-title">Compare across the day</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Metric</th>
<th><button data-comp-time="9">09</button></th>
<th><button data-comp-time="12">12</button></th>
<th><button data-comp-time="15">15</button></th>
<th><button data-comp-time="18">18</button></th>
</tr>
</thead>
<tbody>
<tr><td>Floor shade</td><td data-table="shade" data-time="9">—</td><td data-table="shade" data-time="12">—</td><td data-table="shade" data-time="15">—</td><td data-table="shade" data-time="18">—</td></tr>
<tr><td>Seat shade</td><td data-table="seat" data-time="9">—</td><td data-table="seat" data-time="12">—</td><td data-table="seat" data-time="15">—</td><td data-table="seat" data-time="18">—</td></tr>
<tr><td>Comfort</td><td data-table="comfort" data-time="9">—</td><td data-table="comfort" data-time="12">—</td><td data-table="comfort" data-time="15">—</td><td data-table="comfort" data-time="18">—</td></tr>
</tbody>
</table>
</div>
<div class="chart-wrap">
<svg id="dayChart" viewBox="0 0 300 112" role="img" aria-label="Daily shade and comfort comparison chart">
<path d="M18 18H288 M18 53H288 M18 88H288" fill="none" stroke="rgba(30,70,58,.12)" stroke-width="1"/>
<path id="shadePath" fill="none" stroke="#257e6d" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
<path id="comfortPath" fill="none" stroke="#e0a149" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 3"/>
<line id="chartNow" x1="160" x2="160" y1="12" y2="92" stroke="#17352f" stroke-width="1" opacity=".45"/>
<g fill="#71847d" font-size="8" font-family="system-ui">
<text x="13" y="93">06</text>
<text x="148" y="106">12</text>
<text x="281" y="93">18</text>
</g>
</svg>
<div class="chart-key">
<span><i></i>Floor shade %</span>
<span class="comfort-key"><i></i>Comfort index %</span>
</div>
</div>
</section>
<p class="caveat">
<strong>Planning screen, not a verdict.</strong> The comfort index uses an
illustrative warm-air profile, 55–60% relative humidity, light breeze,
and solar exposure. Validate final decisions with site measurements and
a standard model such as UTCI or PET.
</p>
</div>
</aside>
<aside class="panel" id="rightPanel">
<div class="panel-inner">
<p class="eyebrow">Place check</p>
<div class="spot-heading">
<div id="scoreRing"><span id="scoreValue">—</span></div>
<div>
<h2 id="pointName">West pergola</h2>
<div id="pointMeta">Select any point on the courtyard floor</div>
</div>
</div>
<div class="factor">
<div class="factor-label"><span>Direct-load reduction</span><span id="shadeFactorText">—</span></div>
<div class="factor-track"><i id="shadeFactor"></i></div>
</div>
<div class="factor">
<div class="factor-label"><span>Air-temperature comfort</span><span id="airFactorText">—</span></div>
<div class="factor-track"><i id="airFactor"></i></div>
</div>
<div class="factor">
<div class="factor-label"><span>Breeze adequacy</span><span id="windFactorText">—</span></div>
<div class="factor-track"><i id="windFactor"></i></div>
</div>
<div class="factor">
<div class="factor-label"><span>Humidity comfort</span><span id="humidityFactorText">—</span></div>
<div class="factor-track"><i id="humidityFactor"></i></div>
</div>
<p id="insightText">Shade reduces direct solar exposure, but it does not remove heat already stored in paving and furniture.</p>
<div class="compass-row">
<div class="compass"><div id="northNeedle"></div></div>
<div>
<strong>Sun path stated</strong><br>
July 21 at 40.7° N, solar time.<br>
North is −Z; east is +X.
</div>
</div>
<button class="icon-button" id="resetButton" style="width:100%; margin-top:13px;">Reset camera</button>
<div class="help-text">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom<br>
Click the ground to inspect a specific place.
</div>
</div>
</aside>
<dialog id="methodDialog">
<div class="dialog-body">
<p class="eyebrow">Method note</p>
<h2>How this study works</h2>
<p>
The scene represents an original courtyard at <strong>40.7° N on July 21</strong>.
Time is local solar time, so solar noon is fixed at 12:00.
</p>
<ul>
<li><strong>Sun:</strong> solar altitude and azimuth are calculated from latitude, solar declination, and hour angle.</li>
<li><strong>Shade:</strong> rays are cast from a 1 m paving grid and occupied seat points toward the sun. Pergola slats, walls, and voxel tree canopies are tested as occluders.</li>
<li><strong>Radiant load:</strong> direct normal solar exposure is reduced by sampled shade and by an assumed paving absorptance of 0.66.</li>
<li><strong>Comfort index:</strong> a comparative screen combining radiant load, a sinusoidal 22.4–29.4°C air profile, 55–60% RH, and a light 1.2–1.8 m/s breeze.</li>
<li><strong>Limits:</strong> foliage movement, sky radiation, thermal mass, wind shelter, and material temperatures are not fully simulated.</li>
</ul>
<p>
The index is deliberately not labeled UTCI or PET. Use it to compare design
options, then verify promising locations with calibrated field data.
</p>
<div class="dialog-actions">
<button class="primary-button" id="closeMethod">Back to courtyard</button>
</div>
</div>
</dialog>
<div id="loading"><div class="loading-card">Building the courtyard and sampling the sun path…</div></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* -------------------------------------------------------------------------- */
/* DOM and basic utilities */
/* -------------------------------------------------------------------------- */
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const canvas = $("#sceneCanvas");
const labelsLayer = $("#labelsLayer");
const timeSlider = $("#timeSlider");
const timeDisplay = $("#timeDisplay");
const sunReadout = $("#sunReadout");
const heatmapToggle = $("#heatmapToggle");
const currentMetric = { value: "shade" };
let currentTime = 12;
let isPlaying = false;
let playTimer = null;
/* -------------------------------------------------------------------------- */
/* Renderer, camera, lighting */
/* -------------------------------------------------------------------------- */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e4);
scene.fog = new THREE.Fog(0xdce9e4, 31, 67);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 120);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const world = new THREE.Group();
scene.add(world);
const hemi = new THREE.HemisphereLight(0xeaf6ff, 0x817966, 1.55);
scene.add(hemi);
const sunLight = new THREE.DirectionalLight(0xfff0d0, 3.2);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -16;
sunLight.shadow.camera.right = 16;
sunLight.shadow.camera.top = 16;
sunLight.shadow.camera.bottom = -16;
sunLight.shadow.camera.near = 0.5;
sunLight.shadow.camera.far = 80;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.025;
sunLight.target.position.set(0, 0, 0);
scene.add(sunLight, sunLight.target);
/* -------------------------------------------------------------------------- */
/* Materials and voxel construction */
/* -------------------------------------------------------------------------- */
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
}));
}
return materialCache.get(color);
}
const blockers = [];
function addBlocker(name, w, h, d, x, y, z) {
blockers.push({
name,
box: new THREE.Box3(
new THREE.Vector3(x - w / 2, y - h / 2, z - d / 2),
new THREE.Vector3(x + w / 2, y + h / 2, z + d / 2)
)
});
}
function box(w, h, d, x, y, z, color, parent = world, options = {}) {
const mesh = new THREE.Mesh(unitBox, getMaterial(color));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
(parent || scene).add(mesh);
if (options.blocker) {
addBlocker(options.blocker, w, h, d, x, y, z);
}
return mesh;
}
function seededRandom(seed) {
let state = seed >>> 0;
return () => {
state = (1664525 * state + 1013904223) >>> 0;
return state / 4294967296;
};
}
/* -------------------------------------------------------------------------- */
/* Courtyard geometry */
/* -------------------------------------------------------------------------- */
const courtyardGround = box(18.8, 0.36, 14.8, 0, -0.205, 0, 0xc8c0ae, world, {
castShadow: false
});
// Quiet surrounding ground.
box(70, 0.25, 70, 0, -0.58, 0, 0xaebfae, null, { castShadow: false });
// Fine paving bands and central paths.
for (let x = -8; x <= 8; x += 2) {
box(0.035, 0.012, 13.6, x, -0.012, 0, 0xaaa593, world, {
castShadow: false,
receiveShadow: false
});
}
for (let z = -6; z <= 6; z += 2) {
box(17.7, 0.012, 0.035, 0, -0.011, z, 0xaaa593, world, {
castShadow: false,
receiveShadow: false
});
}
// Perimeter walls. The north wall is tall; the right/front sides remain open for view.
box(20, 3.15, 0.46, 0, 1.48, -7.35, 0xe5dfce, world, { blocker: "North wall" });
box(0.46, 3.15, 14.7, -9.72, 1.48, 0, 0xded7c6, world, { blocker: "West wall" });
box(0.42, 1.05, 5.6, 9.72, 0.42, -4.25, 0xded7c6, world, { blocker: "East low wall" });
box(0.42, 0.78, 3.3, 9.72, 0.29, 5.65, 0xded7c6, world, { blocker: "East low wall" });
// Wall cap and recessed blue-green panels.
box(20.15, 0.18, 0.62, 0, 3.09, -7.35, 0xc7b89d);
box(0.62, 0.18, 14.9, -9.72, 3.09, 0, 0xc7b89d);
const windowMat = new THREE.MeshStandardMaterial({
color: 0x527b76,
roughness: 0.34,
metalness: 0.05
});
[-6.6, -3.3, 0, 3.3, 6.6].forEach((x) => {
box(2.15, 1.05, 0.055, x, 1.72, -7.10, windowMat);
box(0.08, 1.14, 0.08, x, 1.72, -7.04, 0xb6a98f);
});
// Voxel planting beds.
const soilMat = new THREE.MeshStandardMaterial({ color: 0x665846, roughness: 1 });
box(3.0, 0.34, 7.6, -7.65, 0.14, 1.2, 0xbcae91);
box(3.0, 0.14, 7.6, -7.65, 0.36, 1.2, soilMat);
box(2.4, 0.34, 2.7, 7.2, 0.14, 4.1, 0xbcae91);
box(2.4, 0.14, 2.7, 7.2, 0.36, 4.1, soilMat);
const leafColors = [0x477b58, 0x5f9365, 0x739d6b, 0x3e7053, 0x86a96e];
const plantRandom = seededRandom(817);
for (let z = -2.1; z <= 4.3; z += 0.52) {
for (let x = -8.6; x <= -6.7; x += 0.48) {
const h = 0.28 + plantRandom() * 0.42;
box(
0.36 + plantRandom() * 0.18,
h,
0.36 + plantRandom() * 0.18,
x + (plantRandom() - .5) * .15,
.40 + h / 2,
z + (plantRandom() - .5) * .15,
leafColors[Math.floor(plantRandom() * leafColors.length)]
);
}
}
for (let x = 6.35; x <= 8.05; x += .48) {
for (let z = 3.15; z <= 5.1; z += .48) {
const h = .3 + plantRandom() * .38;
box(.4, h, .4, x, .4 + h / 2, z,
leafColors[Math.floor(plantRandom() * leafColors.length)]);
}
}
// Ivy on the north wall.
for (let i = 0; i < 32; i++) {
const x = -9.25 + plantRandom() * 18.5;
const y = .22 + plantRandom() * 2.6;
box(.3 + plantRandom()*.25, .3 + plantRandom()*.3, .2, x, y, -7.03,
leafColors[i % leafColors.length]);
}
/* Pergolas */
function makePergola(cx, cz, w, d, label) {
const timber = 0x8b684a;
const timberLight = 0xa17c59;
[-w/2, w/2].forEach((ox) => {
[-d/2, d/2].forEach((oz) => {
box(.24, 2.7, .24, cx + ox, 1.35, cz + oz, timber, world, {
blocker: `${label} post`
});
});
});
[-d/2, d/2].forEach((oz) => {
box(w + .42, .24, .26, cx, 2.72, cz + oz, timberLight, world, {
blocker: `${label} beam`
});
});
[-w/2, w/2].forEach((ox) => {
box(.26, .24, d + .35, cx + ox, 2.72, cz, timberLight, world, {
blocker: `${label} beam`
});
});
// Closely spaced roof slats: regular, but not complete, shade.
const count = Math.floor(w / .43) + 1;
for (let i = 0; i < count; i++) {
const x = cx - w/2 + i * (w / (count - 1));
box(.235, .17, d + .2, x, 2.87, cz, timber, world, {
blocker: `${label} roof slat`
});
}
// Two upper cross members.
[-w/6, w/6].forEach((ox) => {
box(.18, .18, d + .35, cx + ox, 3.02, cz, timberLight, world, {
blocker: `${label} cross member`
});
});
// Small end caps in a contrasting accent.
box(.32, .32, .32, cx - w/2, 2.72, cz - d/2, 0xd69b55);
box(.32, .32, .32, cx + w/2, 2.72, cz - d/2, 0xd69b55);
}
makePergola(-4.15, 0.8, 5.4, 4.0, "West pergola");
makePergola(4.55, -1.25, 5.15, 3.8, "East pergola");
/* Trees */
function makeTree(x, z, scale, seed) {
const random = seededRandom(seed);
const trunk = 0x70543b;
const trunkHeight = 2.75 * scale;
box(.48 * scale, trunkHeight, .48 * scale, x, trunkHeight / 2, z, trunk, world, {
blocker: "Tree trunk"
});
box(1.35 * scale, .32 * scale, .34 * scale, x + .43 * scale, 1.75 * scale, z, trunk, world, {
blocker: "Tree branch"
});
box(.34 * scale, 1.45 * scale, .32 * scale, x - .25 * scale, 2.1 * scale, z + .16 * scale, trunk, world, {
blocker: "Tree branch"
});
const clusters = [
[0, 3.15, 0, 1.75, 1.42, 1.68],
[-1.05, 2.85, .15, 1.28, 1.23, 1.38],
[1.05, 2.88, -.05, 1.32, 1.25, 1.38],
[.05, 3.95, .1, 1.38, 1.22, 1.40],
[-.72, 3.74, -.68, 1.10, 1.05, 1.10],
[.78, 3.65, .67, 1.14, 1.06, 1.10],
[0, 2.52, .12, 1.40, 1.05, 1.35]
];
clusters.forEach((c, i) => {
const color = leafColors[(i + seed) % leafColors.length];
const w = c[3] * scale;
const h = c[4] * scale;
const d = c[5] * scale;
const cx = x + c[0] * scale;
const cy = c[1] * scale;
const cz = z + c[2] * scale;
box(w, h, d, cx, cy, cz, color, world, {
blocker: "Tree canopy"
});
// Small edge cubes make the silhouette more voxel-like.
for (let j = 0; j < 3; j++) {
const s = (.28 + random() * .28) * scale;
box(
s, s, s,
cx + (random() - .5) * w,
cy + (random() - .5) * h,
cz + (random() - .5) * d,
leafColors[(i + j + 1) % leafColors.length]
);
}
});
}
makeTree(-7.15, -4.65, 1.08, 71);
makeTree(7.15, -4.85, 1.13, 113);
makeTree(7.35, 4.95, .78, 167);
/* Furniture */
function makeBench(x, z, width, cushionColor) {
const wood = 0x75563e;
box(width, .16, .72, x, .68, z, wood);
box(width, .68, .15, x, 1.02, z - .35, wood);
[-width*.38, width*.38].forEach((dx) => {
box(.16, .58, .56, x + dx, .31, z, 0x5f4936);
});
const cushionMat = new THREE.MeshStandardMaterial({
color: cushionColor,
roughness: .95
});
box(width * .86, .13, .64, x, .82, z + .02, cushionMat);
}
function makeTable(x, z, color = 0xb8a27f) {
box(1.45, .12, 1.15, x, .88, z, color);
box(.2, .8, .2, x, .44, z, 0x72553f);
box(.8, .1, .7, x, .16, z, 0x72553f);
}
function makeChair(x, z, color = 0x2f7f74) {
box(.64, .14, .64, x, .48, z, color);
box(.64, .78, .14, x, .82, z - .28, color);
[-.22, .22].forEach((dx) => {
[-.22, .22].forEach((dz) => {
box(.10, .45, .10, x + dx, .23, z + dz, 0x6b513b);
});
});
}
makeBench(-4.15, 1.70, 3.5, 0x3f8f83);
makeBench(4.55, -2.30, 3.2, 0xc47b54);
makeTable(-3.9, -.25);
makeTable(4.6, -.20, 0x9b8c73);
makeChair(-2.45, -.35);
makeChair(-5.65, -.35, 0xd39a56);
makeChair(2.75, -.15);
makeChair(6.30, -.15, 0xd39a56);
// Central shallow water planter.
box(3.45, .38, 2.25, 0, .16, 3.75, 0xc4b99c);
box(3.16, .12, 1.96, 0, .39, 3.75, soilMat);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x5ca4a2,
roughness: .2,
metalness: .08,
transparent: true,
opacity: .92
});
box(2.86, .075, 1.68, 0, .49, 3.75, waterMaterial);
box(3.0, .16, .20, 0, .53, 3.75, 0x998a70);
box(.20, .16, 1.55, 0, .53, 3.75, 0x998a70);
// Stepping stones toward the seating garden.
[-5.9, -4.2, -2.5, -0.8].forEach((x, i) => {
box(1.08, .13, .78, x, .045, 5.45 - i * .13, 0xbdb3a1);
});
/* Seats sampled at occupied height */
const seatPoints = [
new THREE.Vector3(-4.15, 1.05, 1.70),
new THREE.Vector3(-4.15, 1.05, .70),
new THREE.Vector3(-2.45, .78, -.35),
new THREE.Vector3(-5.65, .78, -.35),
new THREE.Vector3(4.55, 1.05, -2.30),
new THREE.Vector3(4.55, 1.05, -1.35),
new THREE.Vector3(2.75, .78, -.15),
new THREE.Vector3(6.30, .78, -.15)
];
/* -------------------------------------------------------------------------- */
/* Sun path and sun marker */
/* -------------------------------------------------------------------------- */
const LATITUDE = THREE.MathUtils.degToRad(40.7);
const DAY_OF_YEAR = 202; // July 21
const DECLINATION = THREE.MathUtils.degToRad(
23.44 * Math.sin(2 * Math.PI * (284 + DAY_OF_YEAR) / 365)
);
const sunPathGroup = new THREE.Group();
scene.add(sunPathGroup);
const sunPathPoints = [];
for (let t = 5.5; t <= 19.5; t += .05) {
const s = getSun(t);
sunPathPoints.push(new THREE.Vector3(s.x * 13.2, s.y * 13.2, s.z * 13.2));
}
const pathGeometry = new THREE.BufferGeometry().setFromPoints(sunPathPoints);
const pathMaterial = new THREE.LineDashedMaterial({
color: 0xe8a94c,
dashSize: .28,
gapSize: .18,
transparent: true,
opacity: .78,
depthWrite: false
});
const sunPathLine = new THREE.Line(pathGeometry, pathMaterial);
sunPathLine.computeLineDistances();
sunPathGroup.add(sunPathLine);
const sunMarker = new THREE.Mesh(
new THREE.SphereGeometry(.38, 20, 14),
new THREE.MeshBasicMaterial({ color: 0xffc04d })
);
sunMarker.castShadow = false;
sunPathGroup.add(sunMarker);
const sunGlow = new THREE.Mesh(
new THREE.SphereGeometry(.72, 20, 14),
new THREE.MeshBasicMaterial({
color: 0xffd889,
transparent: true,
opacity: .18,
depthWrite: false
})
);
sunPathGroup.add(sunGlow);
const sunRayLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]),
new THREE.LineBasicMaterial({
color: 0xe6a54b,
transparent: true,
opacity: .32
})
);
sunPathGroup.add(sunRayLine);
/* Labels */
const sceneLabels = [];
function addSceneLabel(text, anchor, className = "") {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.textContent = text;
labelsLayer.appendChild(element);
sceneLabels.push({ element, anchor });
}
addSceneLabel("West pergola", new THREE.Vector3(-4.15, 3.45, .8));
addSceneLabel("East pergola", new THREE.Vector3(4.55, 3.45, -1.25));
addSceneLabel("Shallow basin", new THREE.Vector3(0, .8, 3.75));
for (let hour = 7; hour <= 18; hour++) {
const s = getSun(hour);
const anchor = new THREE.Vector3(s.x * 13.2, s.y * 13.2, s.z * 13.2);
addSceneLabel(`${hour}:00`, anchor, "hour-label");
const marker = new THREE.Mesh(
new THREE.SphereGeometry(.075, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xf4bd64 })
);
marker.position.copy(anchor);
sunPathGroup.add(marker);
}
/* -------------------------------------------------------------------------- */
/* Sampling grid and heat map */
/* -------------------------------------------------------------------------- */
const gridPoints = [];
const gridPositions = [];
const columns = 18;
const rows = 14;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const x = -8.5 + col;
const z = -6.5 + row;
gridPoints.push(new THREE.Vector3(x, .035, z));
gridPositions.push({ x, z });
}
}
const heatmap = new THREE.InstancedMesh(
new THREE.BoxGeometry(.93, .025, .93),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: .46,
depthWrite: false
}),
gridPoints.length
);
heatmap.renderOrder = 2;
const dummy = new THREE.Object3D();
gridPoints.forEach((p, i) => {
dummy.position.set(p.x, .012, p.z);
dummy.updateMatrix();
heatmap.setMatrixAt(i, dummy.matrix);
});
heatmap.instanceMatrix.needsUpdate = true;
scene.add(heatmap);
const selectionMarker = new THREE.Mesh(
new THREE.TorusGeometry(.44, .055, 8, 32),
new THREE.MeshBasicMaterial({ color: 0x173f36 })
);
selectionMarker.rotation.x = Math.PI / 2;
selectionMarker.position.y = .085;
scene.add(selectionMarker);
const selectedPoint = { x: -4.15, z: .80 };
/* -------------------------------------------------------------------------- */
/* Solar geometry and screening model */
/* -------------------------------------------------------------------------- */
function getSun(time) {
const hourAngle = THREE.MathUtils.degToRad(15 * (time - 12));
const east = -Math.cos(DECLINATION) * Math.sin(hourAngle);
const north =
Math.cos(LATITUDE) * Math.sin(DECLINATION) -
Math.sin(LATITUDE) * Math.cos(DECLINATION) * Math.cos(hourAngle);
const up =
Math.sin(LATITUDE) * Math.sin(DECLINATION) +
Math.cos(LATITUDE) * Math.cos(DECLINATION) * Math.cos(hourAngle);
const altitude = Math.asin(clamp(up, -1, 1)) * THREE.MathUtils.RAD2DEG;
const azimuth = (Math.atan2(east, north) * THREE.MathUtils.RAD2DEG + 360) % 360;
// World orientation: +X east, -Z north, +Y up.
return {
x: east,
y: up,
z: -north,
altitude,
azimuth,
direction: new THREE.Vector3(east, up, -north).normalize()
};
}
function airTemperature(time) {
const phase = clamp((time - 6) / 13, 0, 1);
return 22.4 + 7.0 * Math.sin(Math.PI * phase);
}
function relativeHumidity(time) {
const phase = clamp((time - 6) / 13, 0, 1);
return 54 + 5 * Math.sin(Math.PI * phase);
}
function windSpeed(time) {
const phase = clamp((time - 6) / 13, 0, 1);
return 1.2 + .5 * Math.sin(Math.PI * phase) + .1 * Math.cos(phase * Math.PI * 2);
}
const testRay = new THREE.Ray();
const hitPoint = new THREE.Vector3();
function isShaded(point, sunDirection) {
testRay.set(point, sunDirection);
for (const blocker of blockers) {
if (testRay.intersectBox(blocker.box, hitPoint)) return true;
}
return false;
}
function radiantLoad(shaded, directNormal) {
return directNormal * (shaded ? 0 : 1) * .66;
}
function comfortScore(shaded, directNormal, time) {
const air = airTemperature(time);
const wind = windSpeed(time);
const load = radiantLoad(shaded, directNormal);
const radiantPenalty = Math.min(56, load / 14);
const heatPenalty = Math.min(25, Math.max(0, air - 25.5) * 8);
const humidityPenalty = 4;
const breezePenalty =
Math.max(0, 1.35 - wind) * 9 +
Math.max(0, wind - 4) * 5;
return clamp(Math.round(
100 - radiantPenalty - heatPenalty - humidityPenalty - breezePenalty
), 0, 100);
}
function analyze(time) {
const sun = getSun(time);
const directNormal = 900 * Math.pow(Math.max(0, sun.y), .72);
const gridShades = gridPoints.map(p => isShaded(p, sun.direction));
const seatShades = seatPoints.map(p => isShaded(p, sun.direction));
const shadeFraction = gridShades.filter(Boolean).length / gridShades.length;
const seatFraction = seatShades.filter(Boolean).length / seatShades.length;
let totalLoad = 0;
let totalScore = 0;
gridShades.forEach(shaded => {
totalLoad += radiantLoad(shaded, directNormal);
totalScore += comfortScore(shaded, directNormal, time);
});
return {
time,
sun,
directNormal,
gridShades,
seatShades,
shadeFraction,
seatFraction,
meanLoad: totalLoad / gridShades.length,
meanScore: totalScore / gridShades.length
};
}
const analysisCache = new Map();
for (let t = 6; t <= 19.001; t += .25) {
const time = Math.round(t * 100) / 100;
analysisCache.set(time.toFixed(2), analyze(time));
}
function analysisAt(time) {
const key = (Math.round(time * 100) / 100).toFixed(2);
return analysisCache.get(key) || analyze(Math.round(time * 100) / 100);
}
/* -------------------------------------------------------------------------- */
/* Color ramps and UI updates */
/* -------------------------------------------------------------------------- */
function rampColor(value, stops) {
const t = clamp(value, 0, 1);
const scaled = t * (stops.length - 1);
const index = Math.min(stops.length - 2, Math.floor(scaled));
const fraction = scaled - index;
return new THREE.Color(stops[index]).lerp(new THREE.Color(stops[index + 1]), fraction);
}
const shadeRamp = ["#319b88", "#8ebc86", "#f0c568"];
const loadRamp = ["#4ca58d", "#f0c568", "#d9664f"];
const comfortRamp = ["#4c9d83", "#efd06e", "#d86c58"];
function formatTime(time) {
const rounded = Math.round(time * 4) / 4;
const hours = Math.floor(rounded);
const minutes = Math.round((rounded - hours) * 60);
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
}
function compassName(azimuth) {
const names = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
return names[Math.round(azimuth / 45) % 8];
}
function updateHeatmap(analysis) {
heatmap.visible = heatmapToggle.checked;
if (!heatmap.visible) return;
gridPoints.forEach((_, i) => {
let color;
if (currentMetric.value === "shade") {
color = rampColor(analysis.gridShades[i] ? 0 : 1, shadeRamp);
} else if (currentMetric.value === "radiant") {
const load = radiantLoad(analysis.gridShades[i], analysis.directNormal);
color = rampColor(load / 600, loadRamp);
} else {
const score = comfortScore(analysis.gridShades[i], analysis.directNormal, currentTime);
color = rampColor(1 - score / 100, comfortRamp);
}
heatmap.setColorAt(i, color);
});
heatmap.instanceColor.needsUpdate = true;
}
function updateLegend() {
const legendBar = $("#legendBar");
if (currentMetric.value === "shade") {
$("#legendLow").textContent = "Shaded";
$("#legendHigh").textContent = "Sunlit";
legendBar.style.background = `linear-gradient(90deg, ${shadeRamp.join(",")})`;
} else if (currentMetric.value === "radiant") {
$("#legendLow").textContent = "Lower load";
$("#legendHigh").textContent = "Higher load";
legendBar.style.background = `linear-gradient(90deg, ${loadRamp.join(",")})`;
} else {
$("#legendLow").textContent = "More suitable";
$("#legendHigh").textContent = "Less suitable";
legendBar.style.background = `linear-gradient(90deg, ${comfortRamp.join(",")})`;
}
}
function selectedIndex() {
let best = 0;
let bestDistance = Infinity;
gridPositions.forEach((p, i) => {
const distance = (p.x - selectedPoint.x) ** 2 + (p.z - selectedPoint.z) ** 2;
if (distance < bestDistance) {
bestDistance = distance;
best = i;
}
});
return best;
}
function pointName(x, z) {
if (x > -6.95 && x < -1.35 && z > -1.3 && z < 2.9) return "West pergola";
if (x > 1.8 && x < 7.3 && z > -3.3 && z < .8) return "East pergola";
if (x > -2.2 && x < 2.2 && z > 2.4 && z < 5.1) return "Shallow basin";
if (x < -6.2 && z > -2.4) return "Raised planting";
if (x > 6.2 && z > 2.5) return "East garden";
if (z < -5.2) return "North wall edge";
return "Open courtyard";
}
function updateSelectedPoint(analysis) {
const index = selectedIndex();
const shaded = analysis.gridShades[index];
const load = radiantLoad(shaded, analysis.directNormal);
const score = comfortScore(shaded, analysis.directNormal, currentTime);
const air = airTemperature(currentTime);
const rh = relativeHumidity(currentTime);
const wind = windSpeed(currentTime);
const airComfort = clamp(100 - Math.max(0, air - 22) * 8 - Math.max(0, 19 - air) * 5, 0, 100);
const breezeComfort = clamp(100 - Math.abs(wind - 1.55) * 36, 0, 100);
const humidityComfort = clamp(100 - Math.max(0, rh - 45) * 1.55, 0, 100);
const shadeReduction = shaded ? 100 : 0;
selectionMarker.position.x = gridPositions[index].x;
selectionMarker.position.z = gridPositions[index].z;
$("#pointName").textContent = pointName(selectedPoint.x, selectedPoint.z);
$("#pointMeta").textContent =
`X ${selectedPoint.x.toFixed(1)} m · Z ${selectedPoint.z.toFixed(1)} m · occupied-height sample`;
$("#scoreValue").textContent = score;
$("#scoreRing").style.setProperty("--score", `${score * 3.6}deg`);
$("#shadeFactor").style.width = `${shadeReduction}%`;
$("#airFactor").style.width = `${airComfort}%`;
$("#windFactor").style.width = `${breezeComfort}%`;
$("#humidityFactor").style.width = `${humidityComfort}%`;
$("#shadeFactorText").textContent = shaded ? "Direct sun blocked" : "Exposed to direct sun";
$("#airFactorText").textContent = `${air.toFixed(1)}°C`;
$("#windFactorText").textContent = `${wind.toFixed(1)} m/s`;
$("#humidityFactorText").textContent = `${rh.toFixed(0)}% RH`;
let insight;
if (shaded && score >= 60) {
insight = "Shade removes much of the direct load here. The remaining risk is warm air and heat retained by the paving.";
} else if (shaded) {
insight = "This spot is shaded, but warm air still limits comfort. A breeze or lighter paving would matter more than additional shade alone.";
} else if (wind < 1.45) {
insight = "The seat is sunlit and the breeze is light. Shade, a breeze corridor, or a cooler material would be more useful here.";
} else {
insight = "The seat receives direct sun. The breeze helps, but radiant load remains the dominant screening factor.";
}
$("#insightText").textContent = insight;
}
function updateComparisonTable() {
[9, 12, 15, 18].forEach(time => {
const a = analysisAt(time);
$$(`[data-table="shade"][data-time="${time}"]`).forEach(el => {
el.textContent = `${Math.round(a.shadeFraction * 100)}%`;
});
$$(`[data-table="seat"][data-time="${time}"]`).forEach(el => {
el.textContent = `${Math.round(a.seatFraction * 100)}%`;
});
$$(`[data-table="comfort"][data-time="${time}"]`).forEach(el => {
el.textContent = `${a.meanScore}`;
});
});
}
function updateDayChart() {
const shade = [];
const comfort = [];
for (let hour = 6; hour <= 19; hour++) {
const a = analysisAt(hour);
const x = 18 + ((hour - 6) / 13) * 270;
const shadeY = 88 - a.shadeFraction * 68;
const comfortY = 88 - (a.meanScore / 100) * 68;
shade.push(`${shade.length ? "L" : "M"}${x.toFixed(1)},${shadeY.toFixed(1)}`);
comfort.push(`${comfort.length ? "L" : "M"}${x.toFixed(1)},${comfortY.toFixed(1)}`);
}
$("#shadePath").setAttribute("d", shade.join(" "));
$("#comfortPath").setAttribute("d", comfort.join(" "));
}
function applyTime(time) {
currentTime = Math.round(time * 4) / 4;
const analysis = analysisAt(currentTime);
const sun = analysis.sun;
timeSlider.value = currentTime;
timeDisplay.textContent = formatTime(currentTime);
sunReadout.innerHTML =
`Altitude ${sun.altitude.toFixed(0)}°<br>Azimuth ${sun.azimuth.toFixed(0)}° ${compassName(sun.azimuth)}`;
const sunPosition = new THREE.Vector3(sun.x * 34, sun.y * 34, sun.z * 34);
sunLight.position.copy(sunPosition);
sunLight.intensity = .22 + 3.25 * Math.pow(Math.max(0, sun.y), .65);
sunLight.color.copy(
new THREE.Color(0xffb76d).lerp(new THREE.Color(0xfff4d7), clamp(sun.y * 1.4, 0, 1))
);
sunMarker.position.set(sun.x * 13.2, sun.y * 13.2, sun.z * 13.2);
sunGlow.position.copy(sunMarker.position);
const rayPositions = sunRayLine.geometry.attributes.position;
rayPositions.setXYZ(0, 0, 0, 0);
rayPositions.setXYZ(1, sun.x * 13.2, sun.y * 13.2, sun.z * 13.2);
rayPositions.needsUpdate = true;
$("#shadeValue").textContent = `${Math.round(analysis.shadeFraction * 100)}%`;
$("#seatShadeValue").textContent = `${Math.round(analysis.seatFraction * 100)}%`;
$("#radiantValue").textContent = `${Math.round(analysis.meanLoad)}`;
$("#comfortValue").textContent = `${analysis.meanScore}`;
updateHeatmap(analysis);
updateSelectedPoint(analysis);
const chartX = 18 + ((currentTime - 6) / 13) * 270;
$("#chartNow").setAttribute("x1", chartX);
$("#chartNow").setAttribute("x2", chartX);
$$(".quick-times button").forEach(button => {
button.classList.toggle("active", Math.abs(Number(button.dataset.time) - currentTime) < .1);
});
}
/* -------------------------------------------------------------------------- */
/* Custom camera controls */
/* -------------------------------------------------------------------------- */
const orbit = {
target: new THREE.Vector3(0, .8, 0),
goalTarget: new THREE.Vector3(0, .8, 0),
radius: 29,
goalRadius: 29,
theta: .72,
goalTheta: .72,
phi: .86,
goalPhi: .86
};
function updateCamera() {
orbit.theta = lerp(orbit.theta, orbit.goalTheta, .11);
orbit.phi = lerp(orbit.phi, orbit.goalPhi, .11);
orbit.radius = lerp(orbit.radius, orbit.goalRadius, .11);
orbit.target.lerp(orbit.goalTarget, .11);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.goalTarget.set(0, .8, 0);
orbit.goalRadius = 29;
orbit.goalTheta = .72;
orbit.goalPhi = .86;
}
const pointerState = {
active: false,
id: -1,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: 0,
panning: false
};
canvas.addEventListener("contextmenu", e => e.preventDefault());
canvas.addEventListener("pointerdown", e => {
if (pointerState.active) return;
pointerState.active = true;
pointerState.id = e.pointerId;
pointerState.startX = e.clientX;
pointerState.startY = e.clientY;
pointerState.lastX = e.clientX;
pointerState.lastY = e.clientY;
pointerState.moved = 0;
pointerState.panning = e.button === 2 || e.shiftKey;
canvas.setPointerCapture(e.pointerId);
});
canvas.addEventListener("pointermove", e => {
if (!pointerState.active || e.pointerId !== pointerState.id) return;
const dx = e.clientX - pointerState.lastX;
const dy = e.clientY - pointerState.lastY;
pointerState.lastX = e.clientX;
pointerState.lastY = e.clientY;
pointerState.moved += Math.abs(dx) + Math.abs(dy);
if (pointerState.panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = orbit.radius * .0015;
orbit.goalTarget.addScaledVector(right, -dx * scale);
orbit.goalTarget.addScaledVector(up, dy * scale);
orbit.goalTarget.x = clamp(orbit.goalTarget.x, -12, 12);
orbit.goalTarget.z = clamp(orbit.goalTarget.z, -10, 10);
orbit.goalTarget.y = clamp(orbit.goalTarget.y, 0, 4);
} else {
orbit.goalTheta -= dx * .0055;
orbit.goalPhi = clamp(orbit.goalPhi - dy * .0045, .32, 1.32);
}
});
canvas.addEventListener("pointerup", e => {
if (e.pointerId !== pointerState.id) return;
const wasClick = pointerState.moved < 6;
pointerState.active = false;
pointerState.id = -1;
if (canvas.hasPointerCapture(e.pointerId)) canvas.releasePointerCapture(e.pointerId);
if (wasClick) selectGroundPoint(e);
});
canvas.addEventListener("pointercancel", () => {
pointerState.active = false;
pointerState.id = -1;
});
canvas.addEventListener("wheel", e => {
e.preventDefault();
orbit.goalRadius = clamp(orbit.goalRadius * Math.exp(e.deltaY * .001), 12, 47);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function selectGroundPoint(event) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hit = raycaster.intersectObject(courtyardGround, false)[0];
if (!hit) return;
selectedPoint.x = clamp(hit.point.x, -8.5, 8.5);
selectedPoint.z = clamp(hit.point.z, -6.5, 6.5);
updateSelectedPoint(analysisAt(currentTime));
}
/* -------------------------------------------------------------------------- */
/* UI events */
/* -------------------------------------------------------------------------- */
timeSlider.addEventListener("input", e => applyTime(Number(e.target.value)));
$$(".quick-times button").forEach(button => {
button.addEventListener("click", () => {
stopPlayback();
applyTime(Number(button.dataset.time));
});
});
$$("[data-comp-time]").forEach(button => {
button.addEventListener("click", () => {
stopPlayback();
applyTime(Number(button.dataset.compTime));
});
});
$$(".metric-tabs button").forEach(button => {
button.addEventListener("click", () => {
currentMetric.value = button.dataset.metric;
$$(".metric-tabs button").forEach(b => b.classList.toggle("active", b === button));
updateLegend();
updateHeatmap(analysisAt(currentTime));
});
});
heatmapToggle.addEventListener("change", () => {
updateHeatmap(analysisAt(currentTime));
});
function stopPlayback() {
isPlaying = false;
clearInterval(playTimer);
playTimer = null;
$("#playButton").textContent = "▶";
$("#playButton").setAttribute("aria-label", "Play through the day");
}
$("#playButton").addEventListener("click", () => {
if (isPlaying) {
stopPlayback();
return;
}
isPlaying = true;
$("#playButton").textContent = "Ⅱ";
$("#playButton").setAttribute("aria-label", "Pause time animation");
playTimer = setInterval(() => {
let next = currentTime + .25;
if (next > 19) next = 6;
applyTime(next);
}, 150);
});
$("#resetButton").addEventListener("click", resetCamera);
$("#methodButton").addEventListener("click", () => {
$("#methodDialog").showModal();
});
$("#closeMethod").addEventListener("click", () => {
$("#methodDialog").close();
});
$("#methodDialog").addEventListener("click", e => {
if (e.target === $("#methodDialog")) $("#methodDialog").close();
});
/* -------------------------------------------------------------------------- */
/* Labels, compass, resize, and render loop */
/* -------------------------------------------------------------------------- */
const projected = new THREE.Vector3();
function updateLabels() {
sceneLabels.forEach(label => {
projected.copy(label.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
Math.abs(projected.x) < 1.1 && Math.abs(projected.y) < 1.1;
label.element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * .5 + .5) * innerWidth;
const y = (-projected.y * .5 + .5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
function updateCompass() {
const origin = new THREE.Vector3(0, 0, 0).project(camera);
const north = new THREE.Vector3(0, 0, -2).project(camera);
const dx = north.x - origin.x;
const screenDy = -(north.y - origin.y);
const angle = Math.atan2(dx, -screenDy) * THREE.MathUtils.RAD2DEG;
$("#northNeedle").style.transform = `rotate(${angle}deg)`;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
updateCompass();
renderer.render(scene, camera);
}
/* Initial state */
updateComparisonTable();
updateDayChart();
updateLegend();
applyTime(12);
updateCamera();
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hide");
setTimeout(() => $("#loading").remove(), 400);
});
</script>
</body>
</html>
```