Prompt specification
Build or customize the Three.js 3D scene "Clogged and clear drain comparison" 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: Clogged and clear drain comparison
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/clogged-and-clear-drain-comparison-x1262
Scene Description Prompt:
Compare stylized clear and leaf-clogged street drains under equal rain, with illustrative water pooling. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (clogged-and-clear-drain-comparison-x1262):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stormwater Drain Comparison</title>
<style>
:root {
--ink: #142a2d;
--muted: #617174;
--paper: #f5f3ea;
--line: rgba(20, 42, 45, 0.13);
--water: #159ca3;
--water-light: #76d3d0;
--leaf: #df7b42;
--leaf-dark: #6f582f;
--night: #102a31;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: #dce5e2;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: flex;
flex-direction: column;
width: 100%;
height: 100vh;
min-height: 650px;
}
.topbar {
position: relative;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
min-height: 72px;
padding: 0 28px;
border-bottom: 1px solid var(--line);
background: rgba(245, 243, 234, 0.96);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border-radius: 50%;
background: var(--ink);
color: #a8e4df;
}
.brand-mark svg {
width: 20px;
height: 20px;
}
.brand-copy {
display: flex;
flex-direction: column;
gap: 2px;
}
.brand-copy strong {
font-size: 14px;
letter-spacing: 0.02em;
}
.brand-copy span {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.equal-badge {
display: flex;
align-items: center;
gap: 10px;
padding: 9px 13px;
border: 1px solid rgba(21, 156, 163, 0.25);
border-radius: 999px;
background: rgba(21, 156, 163, 0.07);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
}
.equal-badge .pulse {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 5px rgba(21, 156, 163, 0.12);
}
.equal-badge output {
color: var(--water);
font-variant-numeric: tabular-nums;
}
main {
display: grid;
grid-template-columns: 320px minmax(0, 1fr);
flex: 1;
min-height: 0;
}
.control-panel {
position: relative;
z-index: 10;
display: flex;
flex-direction: column;
min-height: 0;
padding: 34px 28px 24px;
overflow-y: auto;
border-right: 1px solid var(--line);
background:
linear-gradient(rgba(20, 42, 45, 0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(20, 42, 45, 0.025) 1px, transparent 1px),
var(--paper);
background-size: 24px 24px;
}
.eyebrow {
margin-bottom: 12px;
color: var(--water);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
max-width: 250px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 4vw, 49px);
font-weight: 500;
line-height: 0.99;
letter-spacing: -0.04em;
}
.intro {
margin: 20px 0 30px;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.control-block {
padding: 20px 0;
border-top: 1px solid var(--line);
}
.control-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 13px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-title output {
color: var(--water);
font-size: 13px;
font-variant-numeric: tabular-nums;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 6px 0 12px;
border-radius: 10px;
outline: none;
appearance: none;
background: linear-gradient(
90deg,
var(--water) 0%,
var(--water) var(--range-fill, 58%),
rgba(20, 42, 45, 0.14) var(--range-fill, 58%),
rgba(20, 42, 45, 0.14) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 4px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--water);
box-shadow: 0 0 0 1px rgba(20, 42, 45, 0.2);
cursor: grab;
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 4px solid var(--paper);
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 1px rgba(20, 42, 45, 0.2);
cursor: grab;
}
.scale {
display: flex;
justify-content: space-between;
color: #8a9697;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.action-button,
.focus-button {
min-height: 39px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.38);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.action-button:hover,
.focus-button:hover {
border-color: rgba(21, 156, 163, 0.45);
background: rgba(255, 255, 255, 0.78);
transform: translateY(-1px);
}
.action-button.primary {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.action-button.primary:hover {
background: #1d3c40;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 14px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.switch {
position: relative;
width: 36px;
height: 20px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 999px;
background: rgba(20, 42, 45, 0.18);
cursor: pointer;
transition: background 160ms ease;
}
.switch span::after {
position: absolute;
top: 3px;
left: 3px;
width: 14px;
height: 14px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
content: "";
transition: transform 160ms ease;
}
.switch input:checked + span {
background: var(--water);
}
.switch input:checked + span::after {
transform: translateX(16px);
}
.legend {
display: grid;
gap: 10px;
margin-top: 3px;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 18px;
height: 8px;
border-radius: 999px;
background: var(--water);
}
.swatch.leaf {
background: var(--leaf);
}
.swatch.rain {
height: 18px;
background: repeating-linear-gradient(
90deg,
transparent 0 4px,
rgba(79, 135, 150, 0.7) 4px 5px
);
}
.note {
margin-top: auto;
padding-top: 24px;
color: #7c898a;
font-size: 10px;
line-height: 1.55;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 24%, rgba(255, 255, 255, 0.72), transparent 43%),
linear-gradient(180deg, #dce7e4 0%, #c8d5d1 100%);
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.viewport::after {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(90deg, rgba(15, 38, 43, 0.08), transparent 12%, transparent 88%, rgba(15, 38, 43, 0.08)),
linear-gradient(0deg, rgba(15, 38, 43, 0.16), transparent 24%);
content: "";
}
.scene-toolbar {
position: absolute;
z-index: 8;
top: 20px;
left: 22px;
display: flex;
align-items: center;
gap: 10px;
}
.live-pill,
.view-pill {
display: flex;
align-items: center;
gap: 8px;
min-height: 32px;
padding: 0 11px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 999px;
background: rgba(244, 247, 242, 0.76);
box-shadow: 0 8px 25px rgba(28, 52, 52, 0.08);
backdrop-filter: blur(12px);
color: #526568;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live-pill::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 4px rgba(21, 156, 163, 0.12);
content: "";
}
.view-pill {
border-color: transparent;
background: rgba(16, 42, 49, 0.82);
color: #e7f1ec;
}
.reset-view {
position: absolute;
z-index: 8;
top: 20px;
right: 22px;
display: grid;
width: 34px;
height: 34px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 50%;
background: rgba(244, 247, 242, 0.76);
box-shadow: 0 8px 25px rgba(28, 52, 52, 0.08);
cursor: pointer;
backdrop-filter: blur(12px);
}
.reset-view svg {
width: 15px;
height: 15px;
}
.station-label {
position: absolute;
z-index: 7;
display: flex;
align-items: center;
gap: 10px;
width: 184px;
padding: 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 9px;
background: rgba(244, 247, 242, 0.84);
box-shadow: 0 12px 30px rgba(19, 47, 51, 0.13);
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(12px);
}
.station-label .label-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 5px rgba(21, 156, 163, 0.12);
}
.station-label.clogged .label-dot {
background: var(--leaf);
box-shadow: 0 0 0 5px rgba(223, 123, 66, 0.13);
}
.station-label .label-copy {
display: flex;
flex: 1;
flex-direction: column;
gap: 2px;
}
.station-label b {
font-size: 11px;
letter-spacing: 0.015em;
}
.station-label small {
color: var(--muted);
font-size: 9px;
}
.station-label strong {
color: var(--water);
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.station-label.clogged strong {
color: var(--leaf);
}
.equal-marker {
position: absolute;
z-index: 5;
top: 84px;
left: 50%;
display: flex;
flex-direction: column;
align-items: center;
color: rgba(31, 72, 77, 0.68);
pointer-events: none;
transform: translateX(-50%);
}
.equal-marker span {
padding: 4px 8px;
border-radius: 999px;
background: rgba(239, 246, 241, 0.72);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.equal-marker i {
width: 1px;
height: 72px;
margin-top: 7px;
background: linear-gradient(rgba(21, 156, 163, 0.5), transparent);
}
.scene-legend {
position: absolute;
z-index: 7;
right: 22px;
bottom: 22px;
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 8px;
background: rgba(244, 247, 242, 0.72);
color: #536669;
font-size: 9px;
font-weight: 700;
backdrop-filter: blur(10px);
}
.scene-legend div {
display: flex;
align-items: center;
gap: 8px;
}
.scene-legend i {
display: block;
width: 15px;
height: 5px;
border-radius: 4px;
background: var(--water);
}
.scene-legend .leaf-key {
background: var(--leaf);
}
.scene-legend .rain-key {
width: 3px;
height: 14px;
border-radius: 0;
background: repeating-linear-gradient(
180deg,
#5d9dac 0 3px,
transparent 3px 6px
);
}
.readout {
position: absolute;
z-index: 7;
bottom: 22px;
left: 22px;
display: flex;
width: min(480px, calc(100% - 245px));
min-width: 360px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 10px;
background: rgba(244, 247, 242, 0.82);
box-shadow: 0 15px 35px rgba(19, 47, 51, 0.12);
backdrop-filter: blur(14px);
}
.readout-card {
flex: 1;
padding: 13px 16px;
}
.readout-card + .readout-card {
border-left: 1px solid var(--line);
}
.readout-title {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 8px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.readout-title::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--water);
content: "";
}
.readout-card.clog .readout-title::before {
background: var(--leaf);
}
.readout-values {
display: flex;
gap: 21px;
}
.readout-values strong {
display: block;
font-size: 21px;
font-weight: 550;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.readout-values small {
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #dce5e2;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1000px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
main {
display: block;
}
.control-panel {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0 28px;
padding: 25px 28px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.control-panel > .eyebrow,
.control-panel > h1,
.control-panel > .intro {
grid-column: 1 / -1;
}
.control-panel > h1 {
max-width: none;
font-size: 39px;
}
.intro {
max-width: 590px;
margin-bottom: 16px;
}
.control-block {
padding: 15px 0;
}
.note {
margin-top: 8px;
padding-top: 10px;
}
.viewport {
height: 72vh;
min-height: 590px;
}
}
@media (max-width: 680px) {
.topbar {
min-height: 64px;
padding: 0 16px;
}
.brand-copy span {
display: none;
}
.equal-badge {
padding: 8px 10px;
font-size: 9px;
}
.equal-badge .equal-copy {
display: none;
}
.control-panel {
display: block;
padding: 23px 20px;
}
h1 {
font-size: 39px;
}
.control-panel > .intro {
font-size: 12px;
}
.control-panel .legend,
.control-panel .note {
display: none;
}
.viewport {
height: 76vh;
min-height: 600px;
}
.scene-toolbar {
top: 14px;
left: 14px;
}
.view-pill {
display: none;
}
.reset-view {
top: 14px;
right: 14px;
}
.station-label {
width: 154px;
padding: 8px;
}
.station-label small {
display: none;
}
.equal-marker {
display: none;
}
.readout {
bottom: 14px;
left: 14px;
width: calc(100% - 28px);
min-width: 0;
}
.readout-card {
padding: 11px;
}
.readout-values {
gap: 12px;
}
.readout-values strong {
font-size: 18px;
}
.scene-legend {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path
d="M12 2.8C9.7 6 5.8 9.8 5.8 14.1A6.2 6.2 0 0 0 12 20.3a6.2 6.2 0 0 0 6.2-6.2C18.2 9.8 14.3 6 12 2.8Z"
stroke="currentColor"
stroke-width="1.8"
/>
<path
d="M9 15.1c.4 1.5 1.4 2.3 3 2.5"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
/>
</svg>
</div>
<div class="brand-copy">
<strong>Urban Water Lab</strong>
<span>Field study / 01</span>
</div>
</div>
<div class="equal-badge">
<span class="pulse"></span>
<span class="equal-copy">Equal rainfall</span>
<output id="rainBadge">113 mm/h</output>
</div>
</header>
<main>
<aside class="control-panel">
<div class="eyebrow">Stormwater comparison</div>
<h1>Same storm.<br />Different drain.</h1>
<p class="intro">
Two identical curb drains receive the same rainfall. One stays clear;
the other is covered by a wet leaf mat. Watch runoff and pooling diverge.
</p>
<section class="control-block">
<div class="control-title">
<span>Rain intensity</span>
<output id="rainOutput">113 mm/h</output>
</div>
<input
id="rainSlider"
type="range"
min="15"
max="100"
value="58"
aria-label="Rain intensity"
/>
<div class="scale">
<span>Light</span>
<span>Heavy</span>
</div>
<div class="button-row">
<button class="action-button primary" id="replayButton" type="button">
Replay storm
</button>
<button class="action-button" id="pauseButton" type="button">
Pause
</button>
</div>
<div class="toggle-row">
<span>Slow orbit</span>
<label class="switch">
<input id="orbitToggle" type="checkbox" />
<span aria-hidden="true"></span>
</label>
</div>
</section>
<section class="control-block">
<div class="control-title">
<span>Inspect</span>
<span id="stormTime">00:12</span>
</div>
<div class="button-row">
<button class="focus-button" type="button" data-focus="clear">
Clear drain
</button>
<button class="focus-button" type="button" data-focus="clogged">
Clogged drain
</button>
</div>
<div class="button-row">
<button class="focus-button" type="button" data-focus="compare">
Compare both
</button>
<button class="focus-button" id="leafButton" type="button">
Add / clear leaves
</button>
</div>
</section>
<section class="control-block">
<div class="control-title">
<span>Visual key</span>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
Pooled water / runoff
</div>
<div class="legend-item">
<span class="swatch leaf"></span>
Wet leaf obstruction
</div>
<div class="legend-item">
<span class="swatch rain"></span>
Identical rainfall field
</div>
</div>
</section>
<p class="note">
Concept visualization, not a hydraulic engineering model. Flow and
depth values are illustrative. Drag to orbit, shift-drag to pan,
and scroll to zoom.
</p>
</aside>
<section class="viewport" id="viewport" aria-label="3D drain comparison">
<canvas id="scene" tabindex="0"></canvas>
<div class="scene-toolbar">
<div class="live-pill">Live storm</div>
<div class="view-pill" id="viewName">Comparison view</div>
</div>
<button class="reset-view" id="resetView" type="button" aria-label="Reset view">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M5 8V4m0 0h4M5 4l3.1 3.1A7 7 0 1 1 5.5 13"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</button>
<div class="equal-marker" aria-hidden="true">
<span>Identical rain input</span>
<i></i>
</div>
<div class="station-label" id="clearLabel">
<span class="label-dot"></span>
<span class="label-copy">
<b>Clear drain</b>
<small>Runoff enters the grate</small>
</span>
<strong id="clearDepth">3 mm</strong>
</div>
<div class="station-label clogged" id="cloggedLabel">
<span class="label-dot"></span>
<span class="label-copy">
<b>Leaf-clogged drain</b>
<small>Surface flow is blocked</small>
</span>
<strong id="cloggedDepth">38 mm</strong>
</div>
<div class="readout" aria-label="Illustrative drain results">
<div class="readout-card">
<div class="readout-title">Clear / outflow</div>
<div class="readout-values">
<div>
<strong id="clearFlow">92</strong>
<small>L/min</small>
</div>
<div>
<strong id="clearPoolMetric">3</strong>
<small>mm pool</small>
</div>
</div>
</div>
<div class="readout-card clog">
<div class="readout-title">Clogged / outflow</div>
<div class="readout-values">
<div>
<strong id="cloggedFlow">15</strong>
<small>L/min</small>
</div>
<div>
<strong id="cloggedPoolMetric">38</strong>
<small>mm pool</small>
</div>
</div>
</div>
</div>
<div class="scene-legend" aria-hidden="true">
<div><i></i> Pooled water</div>
<div><i class="leaf-key"></i> Leaf obstruction</div>
<div><i class="rain-key"></i> Rainfall</div>
</div>
<div class="loading" id="loading">Preparing comparison</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const viewport = document.querySelector("#viewport");
const rainSlider = document.querySelector("#rainSlider");
const rainOutput = document.querySelector("#rainOutput");
const rainBadge = document.querySelector("#rainBadge");
const replayButton = document.querySelector("#replayButton");
const pauseButton = document.querySelector("#pauseButton");
const orbitToggle = document.querySelector("#orbitToggle");
const resetView = document.querySelector("#resetView");
const leafButton = document.querySelector("#leafButton");
const viewName = document.querySelector("#viewName");
const stormTime = document.querySelector("#stormTime");
const clearLabel = document.querySelector("#clearLabel");
const cloggedLabel = document.querySelector("#cloggedLabel");
const clearDepth = document.querySelector("#clearDepth");
const cloggedDepth = document.querySelector("#cloggedDepth");
const clearFlow = document.querySelector("#clearFlow");
const cloggedFlow = document.querySelector("#cloggedFlow");
const clearPoolMetric = document.querySelector("#clearPoolMetric");
const cloggedPoolMetric = document.querySelector("#cloggedPoolMetric");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd6e1de, 19, 35);
const camera = new THREE.PerspectiveCamera(
37,
1,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0, 0.35, 0.35),
goalTarget: new THREE.Vector3(0, 0.35, 0.35),
theta: 0,
goalTheta: 0,
phi: 0.83,
goalPhi: 0.83,
radius: 17.3,
goalRadius: 17.3,
dragging: false,
pointerX: 0,
pointerY: 0,
pan: false
};
const hemisphere = new THREE.HemisphereLight(0xe9f5f4, 0x53615c, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.1);
sun.position.set(-6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x9dd7dc, 0.8);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
function mulberry32(seed) {
return function random() {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makeNoiseTexture(base, spread, repeatX, repeatY) {
const c = document.createElement("canvas");
c.width = 256;
c.height = 256;
const ctx = c.getContext("2d");
const random = mulberry32(9137);
ctx.fillStyle = base;
ctx.fillRect(0, 0, 256, 256);
for (let i = 0; i < 12000; i++) {
const shade = Math.floor(95 + random() * 115);
const alpha = 0.025 + random() * 0.075;
ctx.fillStyle = `rgba(${shade},${shade},${shade},${alpha})`;
const size = random() * 2.1 + 0.35;
ctx.fillRect(random() * 256, random() * 256, size, size);
}
const texture = new THREE.CanvasTexture(c);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeatX, repeatY);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const asphaltTexture = makeNoiseTexture("#465052", 22, 7, 4);
const concreteTexture = makeNoiseTexture("#b7b8ae", 18, 3, 1);
const asphaltMaterial = new THREE.MeshStandardMaterial({
map: asphaltTexture,
color: 0x879092,
roughness: 0.97,
metalness: 0.02
});
const concreteMaterial = new THREE.MeshStandardMaterial({
map: concreteTexture,
color: 0xd4d4ca,
roughness: 0.94,
metalness: 0
});
const curbMaterial = new THREE.MeshStandardMaterial({
color: 0xc9c9bd,
roughness: 0.88
});
const road = new THREE.Mesh(
new THREE.BoxGeometry(18.7, 0.34, 8.4),
asphaltMaterial
);
road.position.set(0, -0.2, -0.1);
road.receiveShadow = true;
scene.add(road);
const roadEdge = new THREE.Mesh(
new THREE.BoxGeometry(18.8, 0.13, 0.16),
new THREE.MeshStandardMaterial({ color: 0x27383b, roughness: 0.95 })
);
roadEdge.position.set(0, -0.11, -4.26);
scene.add(roadEdge);
const gutterMaterial = new THREE.MeshStandardMaterial({
color: 0x2e3c3f,
roughness: 0.93
});
for (const x of [-4.35, 4.35]) {
const sidewalk = new THREE.Mesh(
new THREE.BoxGeometry(8.15, 0.24, 2.25),
concreteMaterial
);
sidewalk.position.set(x, 0.06, 3.12);
sidewalk.castShadow = true;
sidewalk.receiveShadow = true;
scene.add(sidewalk);
const curb = new THREE.Mesh(
new THREE.BoxGeometry(8.15, 0.29, 0.3),
curbMaterial
);
curb.position.set(x, 0.09, 2.03);
curb.castShadow = true;
curb.receiveShadow = true;
scene.add(curb);
const gutter = new THREE.Mesh(
new THREE.BoxGeometry(8.15, 0.028, 0.26),
gutterMaterial
);
gutter.position.set(x, 0.012, 1.84);
gutter.receiveShadow = true;
scene.add(gutter);
for (let j = 0; j < 4; j++) {
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.012, 2.1),
new THREE.MeshStandardMaterial({
color: 0x939990,
roughness: 1
})
);
seam.position.set(x - 2.7 + j * 1.8, 0.186, 3.12);
scene.add(seam);
}
}
const centerLineMaterial = new THREE.MeshStandardMaterial({
color: 0xe6c968,
roughness: 0.78
});
for (let i = 0; i < 7; i++) {
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.085, 0.018, 0.63),
centerLineMaterial
);
dash.position.set(0, 0.005, -3.45 + i * 0.76);
dash.receiveShadow = true;
scene.add(dash);
}
const whitePaint = new THREE.MeshStandardMaterial({
color: 0xd8dfd9,
roughness: 0.9
});
for (const x of [-4.35, 4.35]) {
const stopLine = new THREE.Mesh(
new THREE.BoxGeometry(5.6, 0.016, 0.11),
whitePaint
);
stopLine.position.set(x, 0.007, -1.05);
scene.add(stopLine);
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.12, 0);
arrowShape.lineTo(0.12, 0);
arrowShape.lineTo(0.12, 0.65);
arrowShape.lineTo(0.42, 0.65);
arrowShape.lineTo(0, 1.12);
arrowShape.lineTo(-0.42, 0.65);
arrowShape.lineTo(-0.12, 0.65);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
arrowGeometry.rotateX(-Math.PI / 2);
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshStandardMaterial({
color: 0xc7c9bb,
roughness: 0.9,
transparent: true,
opacity: 0.72
})
);
arrow.position.set(x + 1.7, 0.012, -2.45);
arrow.rotation.y = Math.PI;
scene.add(arrow);
}
const drainFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x28383a,
roughness: 0.58,
metalness: 0.65
});
const grateMaterial = new THREE.MeshStandardMaterial({
color: 0x718083,
roughness: 0.4,
metalness: 0.78
});
const openingMaterial = new THREE.MeshStandardMaterial({
color: 0x071416,
roughness: 0.95,
metalness: 0.05
});
function createDrain(x) {
const group = new THREE.Group();
group.position.set(x, 0, 1.36);
scene.add(group);
const opening = new THREE.Mesh(
new THREE.BoxGeometry(2.22, 0.065, 0.9),
openingMaterial
);
opening.position.y = 0.105;
opening.receiveShadow = true;
group.add(opening);
for (const side of [-1, 1]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 1.14),
drainFrameMaterial
);
rail.position.set(side * 1.17, 0.11, 0);
rail.castShadow = true;
group.add(rail);
}
for (const side of [-1, 1]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(2.43, 0.13, 0.13),
drainFrameMaterial
);
rail.position.set(0, 0.11, side * 0.53);
rail.castShadow = true;
group.add(rail);
}
for (let i = 0; i < 11; i++) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.09, 0.96),
grateMaterial
);
bar.position.set(-1.02 + i * 0.204, 0.175, 0);
bar.castShadow = true;
bar.receiveShadow = true;
group.add(bar);
}
return group;
}
createDrain(-4.35);
createDrain(4.35);
function makePuddleGeometry(radiusX, radiusZ, seed) {
const random = mulberry32(seed);
const shape = new THREE.Shape();
const count = 48;
for (let i = 0; i <= count; i++) {
const angle = (i / count) * Math.PI * 2;
const wobble = 0.88 + random() * 0.2;
const px = Math.cos(angle) * radiusX * wobble;
const py = Math.sin(angle) * radiusZ * wobble;
if (i === 0) shape.moveTo(px, py);
else shape.lineTo(px, py);
}
const geometry = new THREE.ShapeGeometry(shape, 12);
geometry.rotateX(-Math.PI / 2);
return geometry;
}
const clearWaterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x35b8ba,
emissive: 0x073f43,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.58,
roughness: 0.16,
metalness: 0.03,
clearcoat: 0.85,
clearcoatRoughness: 0.12,
side: THREE.DoubleSide,
depthWrite: false
});
const cloggedWaterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x249fbd,
emissive: 0x063d53,
emissiveIntensity: 0.21,
transparent: true,
opacity: 0.68,
roughness: 0.13,
metalness: 0.02,
clearcoat: 0.9,
clearcoatRoughness: 0.1,
side: THREE.DoubleSide,
depthWrite: false
});
const clearPuddleGroup = new THREE.Group();
scene.add(clearPuddleGroup);
for (const config of [
{ x: -5.7, z: 1.25, rx: 0.84, rz: 0.67, seed: 22 },
{ x: -3.0, z: 1.3, rx: 0.76, rz: 0.65, seed: 28 },
{ x: -4.35, z: 0.6, rx: 0.93, rz: 0.42, seed: 31 }
]) {
const mesh = new THREE.Mesh(
makePuddleGeometry(config.rx, config.rz, config.seed),
clearWaterMaterial
);
mesh.position.set(config.x, 0.036, config.z);
mesh.renderOrder = 2;
clearPuddleGroup.add(mesh);
}
const cloggedPool = new THREE.Mesh(
makePuddleGeometry(2.75, 1.7, 83),
cloggedWaterMaterial
);
cloggedPool.position.set(4.35, 0.24, 1.25);
cloggedPool.renderOrder = 3;
scene.add(cloggedPool);
const poolEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x86e0dd,
transparent: true,
opacity: 0.48
});
function addPoolEdge(mesh, color) {
const edgeGeometry = new THREE.EdgesGeometry(mesh.geometry, 25);
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.48
});
const edge = new THREE.LineSegments(edgeGeometry, edgeMaterial);
edge.position.copy(mesh.position);
edge.position.y += 0.003;
edge.renderOrder = 4;
scene.add(edge);
return edge;
}
const cloggedPoolEdge = addPoolEdge(cloggedPool, 0x87e0dc);
const leafShape = new THREE.Shape();
leafShape.moveTo(0, -0.5);
leafShape.bezierCurveTo(0.34, -0.25, 0.33, 0.23, 0, 0.52);
leafShape.bezierCurveTo(-0.33, 0.23, -0.34, -0.25, 0, -0.5);
const leafGeometry = new THREE.ExtrudeGeometry(leafShape, {
depth: 0.025,
bevelEnabled: false,
curveSegments: 6
});
leafGeometry.rotateX(-Math.PI / 2);
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x8b5d2f,
roughness: 0.84
}),
new THREE.MeshStandardMaterial({
color: 0xb77534,
roughness: 0.83
}),
new THREE.MeshStandardMaterial({
color: 0x6d6732,
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
color: 0xd09248,
roughness: 0.8
}),
new THREE.MeshStandardMaterial({
color: 0x75523a,
roughness: 0.92
})
];
const leafGroup = new THREE.Group();
leafGroup.position.set(4.35, 0, 1.36);
scene.add(leafGroup);
const leafRandom = mulberry32(717);
for (let i = 0; i < 27; i++) {
const leaf = new THREE.Mesh(
leafGeometry,
leafMaterials[i % leafMaterials.length]
);
const radial = Math.sqrt(leafRandom());
leaf.position.set(
(leafRandom() - 0.5) * 1.95,
0.222 + leafRandom() * 0.018,
(radial - 0.5) * 0.7
);
leaf.rotation.set(
(leafRandom() - 0.5) * 0.15,
leafRandom() * Math.PI,
(leafRandom() - 0.5) * 0.13
);
leaf.scale.setScalar(0.72 + leafRandom() * 0.42);
leaf.castShadow = true;
leaf.receiveShadow = true;
leafGroup.add(leaf);
}
const twigMaterial = new THREE.MeshStandardMaterial({
color: 0x5b492c,
roughness: 1
});
for (let i = 0; i < 4; i++) {
const twig = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.025, 1.25, 5),
twigMaterial
);
twig.rotation.set(Math.PI / 2, 0, leafRandom() * Math.PI);
twig.position.set(
(leafRandom() - 0.5) * 1.3,
0.245,
(leafRandom() - 0.5) * 0.4
);
twig.castShadow = true;
leafGroup.add(twig);
}
function createFlowArrow(origin, direction, length) {
const arrow = new THREE.ArrowHelper(
direction,
origin,
length,
0x2aa7aa,
0.18,
0.11
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.65;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.78;
scene.add(arrow);
return arrow;
}
createFlowArrow(
new THREE.Vector3(-5.95, 0.12, 1.2),
new THREE.Vector3(1, 0, 0.08).normalize(),
0.85
);
createFlowArrow(
new THREE.Vector3(-4.5, 0.13, 0.35),
new THREE.Vector3(0.1, 0, 1).normalize(),
0.55
);
const flowParticles = [];
const flowParticleGeometry = new THREE.SphereGeometry(0.052, 8, 6);
const flowParticleMaterial = new THREE.MeshBasicMaterial({
color: 0x6ce1d8,
transparent: true,
opacity: 0.86
});
for (let i = 0; i < 12; i++) {
const particle = new THREE.Mesh(
flowParticleGeometry,
flowParticleMaterial
);
scene.add(particle);
flowParticles.push(particle);
}
const ripples = [];
function createRipple(x, z, y, color, maxScale, speed = 0.42) {
const geometry = new THREE.RingGeometry(0.19, 0.215, 48);
geometry.rotateX(-Math.PI / 2);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.35,
side: THREE.DoubleSide,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.renderOrder = 5;
scene.add(mesh);
ripples.push({ mesh, maxScale, speed, phase: Math.random() });
}
createRipple(-4.35, 1.36, 0.205, 0x79e3dc, 2.7, 0.5);
createRipple(-4.35, 1.36, 0.207, 0x79e3dc, 2.1, 0.38);
createRipple(-4.35, 1.36, 0.209, 0x79e3dc, 1.6, 0.3);
createRipple(3.72, 0.78, 0.255, 0x8de8e0, 3.2, 0.27);
createRipple(5.05, 1.05, 0.257, 0x8de8e0, 2.5, 0.23);
createRipple(4.38, 1.92, 0.259, 0x8de8e0, 2.0, 0.2);
const MAX_RAIN_DROPS = 360;
function createRainStation(centerX) {
const random = mulberry32(481516);
const drops = [];
const positions = new Float32Array(MAX_RAIN_DROPS * 6);
for (let i = 0; i < MAX_RAIN_DROPS; i++) {
drops.push({
x: (random() - 0.5) * 5.6,
y: random() * 6.8,
z: -1.8 + random() * 4.7
});
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color: 0x6faebc,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const lines = new THREE.LineSegments(geometry, material);
lines.position.x = centerX;
lines.renderOrder = 6;
scene.add(lines);
return { drops, positions, geometry, lines };
}
const clearRain = createRainStation(-4.35);
const cloggedRain = createRainStation(4.35);
let intensity = Number(rainSlider.value);
let rainRate = Math.round(20 + intensity * 1.6);
let stormElapsed = 12;
let paused = false;
let leavesVisible = true;
function setRainCount() {
const count = Math.round(
80 + ((intensity - 15) / 85) * (MAX_RAIN_DROPS - 80)
);
clearRain.geometry.setDrawRange(0, count * 2);
cloggedRain.geometry.setDrawRange(0, count * 2);
}
function updateRainUI() {
intensity = Number(rainSlider.value);
rainRate = Math.round(20 + intensity * 1.6);
rainOutput.textContent = `${rainRate} mm/h`;
rainBadge.textContent = `${rainRate} mm/h`;
rainSlider.style.setProperty(
"--range-fill",
`${((intensity - 15) / 85) * 100}%`
);
setRainCount();
}
updateRainUI();
rainSlider.addEventListener("input", updateRainUI);
replayButton.addEventListener("click", () => {
stormElapsed = 0;
paused = false;
pauseButton.textContent = "Pause";
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
leafButton.addEventListener("click", () => {
leavesVisible = !leavesVisible;
leafGroup.visible = leavesVisible;
leafButton.textContent = leavesVisible
? "Add / clear leaves"
: "Restore leaves";
});
function setFocus(name) {
orbitToggle.checked = false;
if (name === "clear") {
cameraState.goalTarget.set(-4.3, 0.38, 1.0);
cameraState.goalRadius = 8.6;
cameraState.goalTheta = 0.12;
cameraState.goalPhi = 0.79;
viewName.textContent = "Clear drain";
} else if (name === "clogged") {
cameraState.goalTarget.set(4.3, 0.5, 1.0);
cameraState.goalRadius = 8.6;
cameraState.goalTheta = -0.12;
cameraState.goalPhi = 0.78;
viewName.textContent = "Leaf-clogged drain";
} else {
cameraState.goalTarget.set(0, 0.35, 0.35);
cameraState.goalRadius = 17.3;
cameraState.goalTheta = 0;
cameraState.goalPhi = 0.83;
viewName.textContent = "Comparison view";
}
}
document.querySelectorAll("[data-focus]").forEach((button) => {
button.addEventListener("click", () => {
setFocus(button.dataset.focus);
});
});
resetView.addEventListener("click", () => setFocus("compare"));
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
cameraState.pan = event.shiftKey || event.button === 2;
orbitToggle.checked = false;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = cameraState.pan ? "grabbing" : "move";
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.pointerX;
const dy = event.clientY - cameraState.pointerY;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
if (cameraState.pan) {
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
cameraState.goalTarget.addScaledVector(right, -dx * 0.012);
cameraState.goalTarget.addScaledVector(forward, dy * 0.012);
} else {
cameraState.goalTheta -= dx * 0.006;
cameraState.goalPhi = THREE.MathUtils.clamp(
cameraState.goalPhi + dy * 0.005,
0.32,
1.28
);
}
});
function endPointer() {
cameraState.dragging = false;
cameraState.pan = false;
canvas.style.cursor = "grab";
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.goalRadius = THREE.MathUtils.clamp(
cameraState.goalRadius + event.deltaY * 0.012,
6.5,
26
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => setFocus("compare"));
canvas.style.cursor = "grab";
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
resize();
const labelPointClear = new THREE.Vector3(-4.35, 3.05, 0.9);
const labelPointClogged = new THREE.Vector3(4.35, 3.05, 0.9);
const projected = new THREE.Vector3();
function positionLabel(element, worldPoint) {
projected.copy(worldPoint).project(camera);
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
const visible = projected.z < 1 && projected.z > -1;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = visible ? "1" : "0";
}
function updateRain(station, dt, speed, length) {
const { drops, positions, geometry } = station;
for (let i = 0; i < MAX_RAIN_DROPS; i++) {
const drop = drops[i];
drop.y -= speed * dt;
if (drop.y < 0.08) {
drop.y = 6.5;
}
const index = i * 6;
positions[index] = drop.x;
positions[index + 1] = drop.y;
positions[index + 2] = drop.z;
positions[index + 3] = drop.x + 0.025;
positions[index + 4] = drop.y - length;
positions[index + 5] = drop.z + 0.01;
}
geometry.attributes.position.needsUpdate = true;
}
function updateSimulation(dt, elapsed) {
const progress = THREE.MathUtils.clamp(elapsed / 14, 0, 1);
const clearDepthValue = 2 + Math.round(intensity * 0.015 * progress);
const cloggedDepthValue = Math.round(
4 + intensity * 0.59 * progress
);
const clearFlowValue = Math.round(
88 + intensity * 0.08 - (1 - progress) * 3
);
const cloggedFlowValue = Math.round(
23 - progress * 9 - (intensity - 50) * 0.025
);
clearDepth.textContent = `${clearDepthValue} mm`;
cloggedDepth.textContent = `${cloggedDepthValue} mm`;
clearFlow.textContent = clearFlowValue;
cloggedFlow.textContent = Math.max(7, cloggedFlowValue);
clearPoolMetric.textContent = clearDepthValue;
cloggedPoolMetric.textContent = cloggedDepthValue;
const poolY = 0.065 + (cloggedDepthValue / 100) * 0.48;
cloggedPool.position.y = poolY;
cloggedPool.scale.set(
0.42 + progress * 0.58,
1,
0.42 + progress * 0.58
);
cloggedPool.material.opacity = 0.44 + progress * 0.27;
cloggedPoolEdge.position.y = poolY + 0.004;
cloggedPoolEdge.scale.copy(cloggedPool.scale);
clearPuddleGroup.scale.set(
0.84 + progress * 0.16,
1,
0.84 + progress * 0.16
);
const minutes = Math.floor(elapsed / 60);
const seconds = Math.floor(elapsed % 60);
stormTime.textContent = `${String(minutes).padStart(2, "0")}:${String(
seconds
).padStart(2, "0")}`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (!paused) {
stormElapsed += dt;
}
if (orbitToggle.checked && !cameraState.dragging) {
cameraState.goalTheta += dt * 0.075;
}
const damping = 1 - Math.exp(-dt * 7);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.goalTheta,
damping
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.goalPhi,
damping
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.goalRadius,
damping
);
cameraState.target.lerp(
cameraState.goalTarget,
damping
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
const rainSpeed = 6.6 + intensity * 0.055;
const rainLength = 0.28 + intensity * 0.004;
updateRain(clearRain, dt, rainSpeed, rainLength);
updateRain(cloggedRain, dt, rainSpeed, rainLength);
flowParticles.forEach((particle, index) => {
const phase = (time * 0.72 + index / flowParticles.length) % 1;
const angle = index * 2.399 + time * 0.13;
const radius = (1 - phase) * 1.22;
particle.position.set(
-4.35 + Math.cos(angle) * radius,
0.105 - phase * 0.16,
1.36 + Math.sin(angle) * radius * 0.68
);
particle.material.opacity = 0.9;
});
ripples.forEach((ripple, index) => {
const phase = (time * ripple.speed + ripple.phase) % 1;
const scale = 0.45 + phase * ripple.maxScale;
ripple.mesh.scale.set(scale, scale, scale);
ripple.mesh.material.opacity = (1 - phase) * 0.34;
ripple.mesh.position.y += Math.sin(time * 1.4 + index) * 0.0003;
});
if (leavesVisible) {
leafGroup.children.forEach((leaf, index) => {
if (leaf.isMesh) {
leaf.rotation.z += Math.sin(time * 0.9 + index) * 0.00008;
}
});
}
updateSimulation(dt, stormElapsed);
positionLabel(clearLabel, labelPointClear);
positionLabel(cloggedLabel, labelPointClogged);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```