Prompt specification
Build or customize the Three.js 3D scene "Warm and cold front comparison tray" 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: Warm and cold front comparison tray
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/warm-and-cold-front-comparison-tray-x1274
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring weather fronts. Arrange two sectional models with different boundary slopes; animate illustrative cloud placement and air motion while identifying the comparison as conceptual meteorology. Stylized solid forms.
Working Three.js Starter (warm-and-cold-front-comparison-tray-x1274):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Weather Fronts — Conceptual Meteorology</title>
<style>
:root {
color-scheme: dark;
--ink: #f5f4ef;
--muted: #aebbd0;
--panel: rgba(13, 24, 43, 0.78);
--panel-border: rgba(255, 255, 255, 0.13);
--cyan: #67e2e5;
--warm: #f25e61;
--cold: #4e8cff;
--cream: #fff5df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #243653 0%, #111d31 42%, #08111f 100%);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene,
#scene canvas,
#labels {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
pointer-events: none;
overflow: hidden;
}
.intro {
position: fixed;
z-index: 10;
top: 28px;
left: 32px;
width: min(430px, calc(100vw - 64px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.25);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
padding: 7px 11px;
border: 1px solid rgba(103, 226, 229, 0.32);
border-radius: 999px;
background: rgba(8, 19, 35, 0.64);
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
h1 {
margin: 16px 0 9px;
font-size: clamp(30px, 4.4vw, 58px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
}
h1 em {
color: var(--cream);
font-style: normal;
}
.intro p {
max-width: 390px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.legend {
position: fixed;
z-index: 10;
top: 28px;
right: 28px;
width: 224px;
padding: 16px 17px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(16px);
pointer-events: none;
}
.legend-title {
margin-bottom: 12px;
color: #dfe8f5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 28px 1fr;
align-items: center;
gap: 9px;
margin-top: 10px;
color: #cbd5e4;
font-size: 11px;
}
.legend-symbol {
position: relative;
height: 20px;
}
.warm-symbol {
position: absolute;
top: 6px;
left: 2px;
width: 20px;
height: 10px;
border-radius: 12px 12px 0 0;
background: var(--warm);
}
.warm-symbol::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: -2px;
height: 2px;
background: var(--warm);
}
.cold-symbol {
position: absolute;
top: 4px;
left: 3px;
width: 0;
height: 0;
border-top: 7px solid transparent;
border-bottom: 7px solid transparent;
border-left: 15px solid var(--cold);
filter: drop-shadow(5px 0 0 var(--cold));
}
.air-symbol {
position: absolute;
top: 9px;
left: 1px;
width: 24px;
height: 2px;
background: var(--cyan);
box-shadow: 8px 0 0 rgba(103, 226, 229, 0.55);
}
.air-symbol::after {
content: "";
position: absolute;
right: -1px;
top: -4px;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 7px solid var(--cyan);
}
.model-label {
position: absolute;
min-width: 238px;
padding: 12px 15px 13px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 13px;
background: rgba(10, 20, 37, 0.84);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
transform: translate(-50%, -100%);
backdrop-filter: blur(12px);
white-space: nowrap;
}
.model-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -12px;
width: 1px;
height: 12px;
background: rgba(255, 255, 255, 0.4);
}
.model-label .label-top {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 5px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.model-label .letter {
display: inline-grid;
width: 20px;
height: 20px;
place-items: center;
border-radius: 6px;
color: #0c1728;
background: var(--cream);
font-size: 10px;
}
.model-label strong {
display: block;
color: #f6f3eb;
font-size: 14px;
font-weight: 720;
letter-spacing: -0.01em;
}
.model-label small {
display: block;
margin-top: 3px;
color: #9fb0c7;
font-size: 10px;
}
#warm-label .label-top {
color: #ff9294;
}
#cold-label .label-top {
color: #7eabff;
}
.callout {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 999px;
background: rgba(9, 18, 33, 0.78);
color: #d9e3f1;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.controls {
position: fixed;
z-index: 20;
left: 50%;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
transform: translateX(-50%);
backdrop-filter: blur(18px);
}
.control-button {
min-height: 36px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.06);
color: #eaf0f8;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.control-button:hover {
background: rgba(255, 255, 255, 0.11);
border-color: rgba(255, 255, 255, 0.25);
}
.control-button:active {
transform: translateY(1px);
}
.control-button.primary {
border-color: rgba(103, 226, 229, 0.35);
background: rgba(103, 226, 229, 0.14);
color: #b9f7f7;
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
padding: 0 5px;
color: #aebbd0;
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
}
input[type="range"] {
width: 82px;
accent-color: var(--cyan);
cursor: pointer;
}
.concept-note {
position: fixed;
z-index: 10;
left: 28px;
bottom: 27px;
max-width: 280px;
color: #8294ad;
font-size: 10px;
line-height: 1.55;
pointer-events: none;
}
.concept-note strong {
color: #bac6d7;
}
.hint {
position: fixed;
z-index: 10;
right: 28px;
bottom: 31px;
color: #8294ad;
font-size: 10px;
pointer-events: none;
}
@media (max-width: 900px) {
.legend {
top: auto;
right: 18px;
bottom: 100px;
width: 190px;
}
.concept-note,
.hint {
display: none;
}
}
@media (max-width: 650px) {
.intro {
top: 17px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
margin-top: 11px;
font-size: 32px;
}
.intro p {
max-width: 310px;
font-size: 11px;
}
.legend {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: center;
transform: none;
}
.speed-control {
display: none;
}
.model-label {
min-width: 180px;
padding: 9px 11px;
}
.model-label strong {
font-size: 11px;
}
.model-label small,
.callout {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive conceptual weather-front comparison"></div>
<div id="labels" aria-hidden="true">
<div class="model-label" id="warm-label">
<div class="label-top">
<span class="letter">A</span>
Warm-front analogue
</div>
<strong>Shallow boundary · ~10°</strong>
<small>Gradual lift creates a broad, layered cloud deck</small>
</div>
<div class="model-label" id="cold-label">
<div class="label-top">
<span class="letter">B</span>
Cold-front analogue
</div>
<strong>Steep boundary · ~24°</strong>
<small>Rapid uplift creates a compact, towering cloud</small>
</div>
<div class="callout" id="warm-callout">Layered cloud deck</div>
<div class="callout" id="cold-callout">Towering uplift</div>
</div>
<header class="intro">
<div class="eyebrow">Conceptual meteorology</div>
<h1>Weather fronts,<br><em>side by side.</em></h1>
<p>
Two exaggerated sectional models compare how frontal slope shapes
cloud development and the movement of air.
</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Visual key</div>
<div class="legend-row">
<div class="legend-symbol"><span class="warm-symbol"></span></div>
<span>Warm-front boundary</span>
</div>
<div class="legend-row">
<div class="legend-symbol"><span class="cold-symbol"></span></div>
<span>Cold-front boundary</span>
</div>
<div class="legend-row">
<div class="legend-symbol"><span class="air-symbol"></span></div>
<span>Illustrative air motion</span>
</div>
</aside>
<div class="controls" aria-label="Animation controls">
<button class="control-button primary" id="pause-button" type="button">
Pause motion
</button>
<button class="control-button" id="flow-button" type="button">
Airflow on
</button>
<label class="speed-control" for="speed">
Speed
<input id="speed" type="range" min="0.35" max="2" value="1" step="0.05">
</label>
<button class="control-button" id="reset-button" type="button">
Reset view
</button>
</div>
<div class="concept-note">
<strong>Teaching model, not a forecast.</strong>
Frontal angles, cloud forms, colors, and motion are exaggerated and
simplified for conceptual comparison; the geometry is not to scale.
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys also work</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const container = document.querySelector("#scene");
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const state = {
running: true,
showFlow: true,
speed: 1,
time: 0
};
const animatedClouds = [];
const flowSystems = [];
const ambient = new THREE.HemisphereLight(0xdcecff, 0x1a2034, 2.4);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff5df, 3.5);
keyLight.position.set(4, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x67dce6, 1.25);
rimLight.position.set(-8, 5, -6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 40),
new THREE.MeshStandardMaterial({
color: 0x0c1728,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.34;
floor.receiveShadow = true;
scene.add(floor);
// ------------------------------------------------------------
// Direct camera controls: no addons are used
// ------------------------------------------------------------
class SceneControls {
constructor(camera, domElement, target) {
this.camera = camera;
this.domElement = domElement;
this.target = target.clone();
this.theta = 0.16;
this.phi = 1.08;
this.radius = 16.5;
this.narrow = window.innerWidth / window.innerHeight < 0.8;
this.pointers = new Map();
this.pinchDistance = 0;
this.onPointerDown = this.onPointerDown.bind(this);
this.onPointerMove = this.onPointerMove.bind(this);
this.onPointerUp = this.onPointerUp.bind(this);
this.onWheel = this.onWheel.bind(this);
domElement.addEventListener("pointerdown", this.onPointerDown);
domElement.addEventListener("pointermove", this.onPointerMove);
domElement.addEventListener("pointerup", this.onPointerUp);
domElement.addEventListener("pointercancel", this.onPointerUp);
domElement.addEventListener("wheel", this.onWheel, { passive: false });
domElement.addEventListener("dblclick", () => this.reset());
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
switch (event.key) {
case "ArrowLeft":
this.theta += 0.08;
break;
case "ArrowRight":
this.theta -= 0.08;
break;
case "ArrowUp":
this.phi = Math.max(0.42, this.phi - 0.06);
break;
case "ArrowDown":
this.phi = Math.min(1.42, this.phi + 0.06);
break;
case "+":
case "=":
this.radius = Math.max(10, this.radius * 0.9);
break;
case "-":
this.radius = Math.min(38, this.radius * 1.1);
break;
case "r":
case "R":
this.reset();
break;
}
});
this.update();
}
reset() {
this.theta = 0.16;
this.phi = 1.08;
this.radius = this.narrow ? 25 : 16.5;
this.update();
}
onPointerDown(event) {
if (event.pointerType === "mouse" && event.button !== 0) return;
this.domElement.setPointerCapture(event.pointerId);
this.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (this.pointers.size === 2) {
this.pinchDistance = this.getPinchDistance();
}
}
onPointerMove(event) {
const previous = this.pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
this.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (this.pointers.size === 1) {
this.theta -= dx * 0.006;
this.phi = THREE.MathUtils.clamp(
this.phi - dy * 0.005,
0.42,
1.42
);
} else if (this.pointers.size === 2) {
const distance = this.getPinchDistance();
if (this.pinchDistance > 0 && distance > 0) {
this.radius = THREE.MathUtils.clamp(
this.radius * (this.pinchDistance / distance),
10,
38
);
}
this.pinchDistance = distance;
}
this.update();
}
onPointerUp(event) {
this.pointers.delete(event.pointerId);
if (this.pointers.size === 2) {
this.pinchDistance = this.getPinchDistance();
} else {
this.pinchDistance = 0;
}
}
onWheel(event) {
event.preventDefault();
this.radius = THREE.MathUtils.clamp(
this.radius * Math.exp(event.deltaY * 0.001),
10,
38
);
this.update();
}
getPinchDistance() {
const values = [...this.pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
update() {
const sinPhi = Math.sin(this.phi);
const cosPhi = Math.cos(this.phi);
this.camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * cosPhi,
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
}
const controls = new SceneControls(
camera,
renderer.domElement,
new THREE.Vector3(0, 1.8, 0)
);
// ------------------------------------------------------------
// Geometry and material helpers
// ------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
/**
* Creates an eight-corner volume with independently sloping bottom
* and top surfaces. The shared frontal surface can be omitted to
* avoid duplicate transparent faces.
*/
function makeSlopedVolume({
x0,
x1,
z0,
z1,
bottom0,
bottom1,
top0,
top1,
material,
skipBottom = false,
skipTop = false
}) {
const positions = new Float32Array([
x0, bottom0, z1,
x1, bottom1, z1,
x1, top1, z1,
x0, top0, z1,
x0, bottom0, z0,
x1, bottom1, z0,
x1, top1, z0,
x0, top0, z0
]);
const indices = [
0, 1, 2, 0, 2, 3, // front
4, 6, 5, 4, 7, 6, // back
0, 3, 7, 0, 7, 4, // left
1, 5, 6, 1, 6, 2, // right
3, 2, 6, 3, 6, 7 // top
];
if (!skipBottom) {
indices.push(0, 4, 5, 0, 5, 1);
}
if (!skipTop) {
indices.push(3, 2, 6, 3, 6, 7);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
return mesh;
}
function makeTube(points, color, radius = 0.02) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(
curve,
Math.max(12, points.length * 10),
radius,
7,
false
),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92
})
);
return mesh;
}
function makeWarmSymbol(radius = 0.19) {
const shape = new THREE.Shape();
shape.moveTo(-radius, 0);
const segments = 18;
for (let i = 0; i <= segments; i++) {
const angle = Math.PI - (i / segments) * Math.PI;
shape.lineTo(
Math.cos(angle) * radius,
Math.sin(angle) * radius
);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.14,
bevelEnabled: false,
steps: 1
});
geometry.translate(0, 0, -0.07);
return new THREE.Mesh(
geometry,
standardMaterial(0xf25e61, {
emissive: 0x4d1016,
emissiveIntensity: 0.18,
roughness: 0.55
})
);
}
function makeColdSymbol() {
const shape = new THREE.Shape();
shape.moveTo(-0.18, -0.18);
shape.lineTo(0.22, 0);
shape.lineTo(-0.18, 0.18);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.14,
bevelEnabled: false,
steps: 1
});
geometry.translate(0, 0, -0.07);
return new THREE.Mesh(
geometry,
standardMaterial(0x4e8cff, {
emissive: 0x102f70,
emissiveIntensity: 0.22,
roughness: 0.55
})
);
}
function addPuff(group, position, scale, material, detail = 1) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, detail),
material
);
puff.position.set(...position);
puff.scale.set(...scale);
puff.castShadow = true;
puff.receiveShadow = true;
group.add(puff);
return puff;
}
function registerCloud(group, home, phase, drift = 0.12, bob = 0.035) {
group.position.set(...home);
group.userData.home = new THREE.Vector3(...home);
group.userData.phase = phase;
group.userData.drift = drift;
group.userData.bob = bob;
animatedClouds.push(group);
return group;
}
// ------------------------------------------------------------
// Airflow paths
// ------------------------------------------------------------
function addAirflow(parent, pointList, options = {}) {
const root = new THREE.Group();
parent.add(root);
const curve = new THREE.CatmullRomCurve3(
pointList.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.28
);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 70, 0.018, 6, false),
new THREE.MeshBasicMaterial({
color: options.color ?? 0x67e2e5,
transparent: true,
opacity: 0.52
})
);
root.add(tube);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: options.color ?? 0x8af3f3
});
for (const t of options.arrowPositions ?? [0.18, 0.5, 0.82]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.26, 8),
arrowMaterial
);
arrow.position.copy(curve.getPointAt(t));
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangentAt(t).normalize()
);
root.add(arrow);
}
const particles = [];
const particleMaterial = new THREE.MeshBasicMaterial({
color: options.particleColor ?? 0xc6ffff
});
const count = options.count ?? 7;
for (let i = 0; i < count; i++) {
const particle = new THREE.Mesh(
new THREE.SphereGeometry(0.052, 8, 6),
particleMaterial
);
particle.userData.offset = i / count;
particle.userData.rate = options.rate ?? 0.12;
root.add(particle);
particles.push(particle);
}
flowSystems.push({ curve, particles, root });
return root;
}
// ------------------------------------------------------------
// Model construction
// ------------------------------------------------------------
const models = [];
function buildModel(config) {
const group = new THREE.Group();
group.position.x = config.position;
scene.add(group);
const pedestalMaterial = standardMaterial(0x182740, {
roughness: 0.68
});
const capMaterial = standardMaterial(0xd7d9d6, {
roughness: 0.76
});
addBox(
group,
new THREE.Vector3(6.9, 0.34, 3.8),
new THREE.Vector3(0, -0.13, 0),
pedestalMaterial
);
addBox(
group,
new THREE.Vector3(6.72, 0.08, 3.62),
new THREE.Vector3(0, 0.075, 0),
capMaterial
);
const coldAirMaterial = standardMaterial(0x4b91da, {
transparent: true,
opacity: 0.34,
depthWrite: false,
side: THREE.DoubleSide
});
const warmAirMaterial = standardMaterial(0xf1a851, {
transparent: true,
opacity: 0.24,
depthWrite: false,
side: THREE.DoubleSide
});
const x0 = -3;
const x1 = 3;
const z0 = -1.43;
const z1 = 1.43;
const bottom = 0.12;
const top = 4.55;
const lowerAir = makeSlopedVolume({
x0,
x1,
z0,
z1,
bottom0: bottom,
bottom1: bottom,
top0: config.boundary(x0),
top1: config.boundary(x1),
material: coldAirMaterial
});
group.add(lowerAir);
const upperAir = makeSlopedVolume({
x0,
x1,
z0,
z1,
bottom0: config.boundary(x0),
bottom1: config.boundary(x1),
top0: top,
top1: top,
material: warmAirMaterial,
skipBottom: true
});
group.add(upperAir);
// Fine frame around the conceptual atmospheric section.
const frameMaterial = standardMaterial(0x8ca1bc, {
transparent: true,
opacity: 0.62,
roughness: 0.5
});
for (const x of [-3.25, 3.25]) {
for (const z of [-1.55, 1.55]) {
addBox(
group,
new THREE.Vector3(0.035, 4.5, 0.035),
new THREE.Vector3(x, 2.32, z),
frameMaterial
);
}
}
for (const z of [-1.55, 1.55]) {
addBox(
group,
new THREE.Vector3(6.5, 0.035, 0.035),
new THREE.Vector3(0, 4.57, z),
frameMaterial
);
}
// Colored frontal boundary, visible at the front and back.
const boundaryColor = config.kind === "warm" ? 0xf25e61 : 0x4e8cff;
for (const z of [-1.48, 1.48]) {
const boundaryLine = makeTube(
[
[x0, config.boundary(x0), z],
[x1, config.boundary(x1), z]
],
boundaryColor,
0.028
);
group.add(boundaryLine);
}
// Frontal symbols.
const symbolPositions =
config.kind === "warm"
? [-2.25, -0.8, 0.65, 2.1]
: [-2.25, -0.8, 0.65, 2.1];
for (const x of symbolPositions) {
const symbol =
config.kind === "warm"
? makeWarmSymbol()
: makeColdSymbol();
symbol.position.set(x, config.boundary(x), 1.54);
symbol.rotation.z = Math.atan(
config.boundary(x + 0.01) - config.boundary(x - 0.01)
);
symbol.castShadow = true;
group.add(symbol);
}
const cloudMaterial = standardMaterial(0xfff5df, {
roughness: 0.95
});
const cloudShadowMaterial = standardMaterial(0xa9bdd2, {
roughness: 1
});
let calloutAnchor;
if (config.kind === "warm") {
// A broad, gently sloping deck of low-poly cloud forms.
[-1.85, -0.1, 1.55].forEach((x, index) => {
const cloud = new THREE.Group();
addPuff(cloud, [0, 0, 0], [0.72, 0.32, 0.43], cloudMaterial);
addPuff(cloud, [-0.56, -0.04, 0], [0.5, 0.27, 0.36], cloudMaterial);
addPuff(cloud, [0.52, -0.04, 0], [0.53, 0.28, 0.37], cloudMaterial);
addPuff(cloud, [-0.06, 0.24, 0], [0.46, 0.38, 0.38], cloudMaterial);
addPuff(
cloud,
[-0.08, -0.15, 0.17],
[0.62, 0.12, 0.31],
cloudShadowMaterial
);
cloud.scale.setScalar(index === 1 ? 1.08 : 0.92);
registerCloud(
cloud,
[x, config.boundary(x) + 0.56, -0.08],
index * 1.7,
0.12 + index * 0.025,
0.028
);
group.add(cloud);
});
addAirflow(
group,
[
[-2.55, 0.55, 0.72],
[-1.55, 0.7, 0.72],
[-0.45, 1.02, 0.72],
[0.45, 1.52, 0.72],
[1.35, 2.2, 0.72],
[2.15, 3.02, 0.72],
[2.42, 3.76, 0.72]
],
{
rate: 0.115,
count: 8
}
);
calloutAnchor = new THREE.Object3D();
calloutAnchor.position.set(-0.6, 3.05, 0);
group.add(calloutAnchor);
} else {
// A compact vertical tower with a wider anvil-like top.
const tower = new THREE.Group();
addPuff(tower, [0, -0.4, 0], [0.78, 0.28, 0.5], cloudShadowMaterial);
addPuff(tower, [-0.35, -0.26, 0.03], [0.5, 0.32, 0.39], cloudMaterial);
addPuff(tower, [0.34, -0.2, -0.02], [0.52, 0.36, 0.4], cloudMaterial);
addPuff(tower, [-0.08, 0.02, 0], [0.62, 0.5, 0.46], cloudMaterial);
addPuff(tower, [0.08, 0.5, 0.01], [0.6, 0.53, 0.44], cloudMaterial);
addPuff(tower, [0.02, 0.86, 0], [1.03, 0.25, 0.57], cloudMaterial);
registerCloud(
tower,
[0.18, config.boundary(0.18) + 1.02, -0.05],
0.8,
0.045,
0.025
);
group.add(tower);
// A smaller low cloud emphasizes the sharp leading edge.
const lowCloud = new THREE.Group();
addPuff(lowCloud, [0, 0, 0], [0.52, 0.22, 0.32], cloudMaterial);
addPuff(lowCloud, [0.38, -0.03, 0], [0.42, 0.19, 0.29], cloudMaterial);
addPuff(lowCloud, [-0.32, -0.04, 0], [0.38, 0.18, 0.28], cloudMaterial);
registerCloud(
lowCloud,
[1.48, config.boundary(1.48) + 0.36, -0.08],
2.3,
0.075,
0.025
);
group.add(lowCloud);
// Warm air lifted rapidly along the steep frontal surface.
addAirflow(
group,
[
[1.95, 0.9, 0.7],
[1.1, 0.95, 0.7],
[0.48, 1.3, 0.7],
[-0.02, 2.05, 0.7],
[-0.48, 3.08, 0.7],
[-0.78, 4.03, 0.7]
],
{
rate: 0.14,
count: 7
}
);
// Cool air advancing along the ground.
addAirflow(
group,
[
[2.72, 0.43, -0.1],
[1.72, 0.44, -0.1],
[0.84, 0.52, -0.1],
[0.12, 0.68, -0.1],
[-0.46, 1.04, -0.1]
],
{
color: 0x8fbeff,
particleColor: 0xd5e7ff,
rate: 0.16,
count: 6
}
);
calloutAnchor = new THREE.Object3D();
calloutAnchor.position.set(0.18, 4.3, 0);
group.add(calloutAnchor);
}
const labelAnchor = new THREE.Object3D();
labelAnchor.position.set(0, 5.03, 0);
group.add(labelAnchor);
const model = {
group,
labelAnchor,
calloutAnchor,
kind: config.kind
};
models.push(model);
return model;
}
buildModel({
kind: "warm",
position: -4.08,
boundary: (x) => 1.18 + (x + 3) * 0.18
});
buildModel({
kind: "cold",
position: 4.08,
boundary: (x) => 3.72 - (x + 3) * 0.45
});
// ------------------------------------------------------------
// Interface and projected HTML labels
// ------------------------------------------------------------
const pauseButton = document.querySelector("#pause-button");
const flowButton = document.querySelector("#flow-button");
const speedInput = document.querySelector("#speed");
const resetButton = document.querySelector("#reset-button");
pauseButton.addEventListener("click", () => {
state.running = !state.running;
pauseButton.textContent = state.running ? "Pause motion" : "Resume motion";
pauseButton.setAttribute("aria-pressed", String(!state.running));
});
flowButton.addEventListener("click", () => {
state.showFlow = !state.showFlow;
for (const system of flowSystems) {
system.root.visible = state.showFlow;
}
flowButton.textContent = state.showFlow ? "Airflow on" : "Airflow off";
flowButton.setAttribute("aria-pressed", String(state.showFlow));
});
speedInput.addEventListener("input", () => {
state.speed = Number(speedInput.value);
});
resetButton.addEventListener("click", () => {
controls.reset();
});
const warmLabelElement = document.querySelector("#warm-label");
const coldLabelElement = document.querySelector("#cold-label");
const warmCalloutElement = document.querySelector("#warm-callout");
const coldCalloutElement = document.querySelector("#cold-callout");
const projectedPosition = new THREE.Vector3();
function positionLabel(element, anchor) {
anchor.getWorldPosition(projectedPosition);
projectedPosition.project(camera);
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1 &&
Math.abs(projectedPosition.x) < 1.15 &&
Math.abs(projectedPosition.y) < 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projectedPosition.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedPosition.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateProjectedLabels() {
const warmModel = models.find((model) => model.kind === "warm");
const coldModel = models.find((model) => model.kind === "cold");
positionLabel(warmLabelElement, warmModel.labelAnchor);
positionLabel(coldLabelElement, coldModel.labelAnchor);
positionLabel(warmCalloutElement, warmModel.calloutAnchor);
positionLabel(coldCalloutElement, coldModel.calloutAnchor);
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (state.running) {
state.time += delta * state.speed;
}
for (const cloud of animatedClouds) {
const { home, phase, drift, bob } = cloud.userData;
cloud.position.x =
home.x + Math.sin(state.time * 0.38 + phase) * drift;
cloud.position.y =
home.y + Math.sin(state.time * 0.56 + phase * 0.71) * bob;
cloud.rotation.z =
Math.sin(state.time * 0.23 + phase) * 0.008;
}
if (state.showFlow) {
for (const system of flowSystems) {
for (const particle of system.particles) {
const t =
(state.time * particle.userData.rate +
particle.userData.offset) %
1;
particle.position.copy(system.curve.getPointAt(t));
}
}
}
controls.update();
scene.updateMatrixWorld(true);
updateProjectedLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// ------------------------------------------------------------
// Responsive behavior
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const narrow = aspect < 0.8;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = aspect;
camera.fov = narrow ? 54 : 42;
camera.updateProjectionMatrix();
if (narrow !== controls.narrow) {
controls.narrow = narrow;
controls.reset();
}
}
window.addEventListener("resize", resize);
resize();
</script>
</body>
</html>
```