Prompt specification
Build or customize the Three.js 3D scene "Cold-front wedge sectional model" 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: Cold-front wedge sectional model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cold-front-wedge-sectional-model-x1273
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows weather fronts. Build a schematic dense air wedge beneath a warmer layer, with sloped boundary and rising arrows; use transparent volumes so the overlap remains readable. Low-poly.
Working Three.js Starter (cold-front-wedge-sectional-model-x1273):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Weather Fronts — Warm Air Over a Dense Cold Wedge</title>
<style>
:root {
color-scheme: dark;
--cold: #72d7ff;
--cold-deep: #287ca8;
--warm: #ff9b69;
--warm-light: #ffd08a;
--ink: #eff9ff;
--muted: #9fb7c6;
--panel: rgba(7, 20, 30, 0.68);
--line: rgba(190, 231, 255, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 70% 28%, rgba(28, 73, 92, 0.34), transparent 34%),
radial-gradient(circle at 20% 75%, rgba(104, 42, 46, 0.18), transparent 32%),
linear-gradient(145deg, #06131d 0%, #0a1c28 50%, #07111a 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene,
#labels {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
pointer-events: none;
z-index: 4;
transition: opacity 180ms ease;
}
#labels.labels-off {
opacity: 0;
}
.label {
position: absolute;
left: 0;
top: 0;
min-width: 116px;
padding: 9px 11px;
border: 1px solid rgba(202, 237, 255, 0.2);
border-left: 3px solid var(--cold);
border-radius: 7px;
background: rgba(6, 19, 28, 0.76);
box-shadow: 0 9px 30px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(9px);
transform: translate(-999px, -999px);
white-space: nowrap;
}
.label.warm {
border-left-color: var(--warm);
}
.label.front {
border-left-color: #c8f6ff;
}
.label.rain {
border-left-color: #8ee7ff;
}
.label strong {
display: block;
font-size: 10px;
line-height: 1.15;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.label span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
}
.hud {
position: fixed;
z-index: 8;
pointer-events: none;
}
.header {
top: 28px;
left: 30px;
max-width: 470px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: #9cc9da;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: var(--warm);
box-shadow: 0 0 12px rgba(255, 155, 105, 0.65);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
font-weight: 620;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 410px;
margin: 16px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.temperature {
top: 30px;
right: 30px;
display: flex;
gap: 9px;
pointer-events: auto;
}
.temperature div {
min-width: 118px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel);
backdrop-filter: blur(12px);
}
.temperature b {
display: block;
font-size: 12px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.temperature span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 11px;
}
.cold-chip b {
color: var(--cold);
}
.warm-chip b {
color: var(--warm);
}
.legend {
left: 30px;
bottom: 28px;
display: flex;
align-items: center;
gap: 20px;
padding: 11px 14px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #b9ccd8;
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.swatch {
width: 18px;
height: 5px;
border-radius: 10px;
background: var(--cold);
box-shadow: 0 0 12px rgba(114, 215, 255, 0.45);
}
.swatch.warm {
background: var(--warm);
box-shadow: 0 0 12px rgba(255, 155, 105, 0.45);
}
.swatch.front {
background: #e5fbff;
box-shadow: 0 0 12px rgba(229, 251, 255, 0.45);
}
.controls {
right: 30px;
bottom: 28px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 10px 12px;
background: rgba(8, 22, 32, 0.76);
color: #c7dbe7;
font: inherit;
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease;
}
button:hover,
button[aria-pressed="true"] {
border-color: rgba(114, 215, 255, 0.45);
background: rgba(17, 43, 56, 0.88);
color: #fff;
}
.hint {
margin-right: 8px;
color: #7893a3;
font-size: 10px;
letter-spacing: 0.04em;
}
@media (max-width: 760px) {
.header {
top: 20px;
left: 20px;
max-width: calc(100vw - 40px);
}
.subtitle {
max-width: 330px;
font-size: 12px;
}
.temperature {
top: auto;
right: 20px;
bottom: 78px;
}
.temperature div {
min-width: 96px;
padding: 9px 10px;
}
.legend {
left: 20px;
bottom: 20px;
gap: 12px;
}
.legend-item {
font-size: 8px;
}
.controls {
right: 20px;
bottom: 20px;
}
.hint,
#labels {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels"></div>
<header class="hud header">
<div class="eyebrow">Atmospheric science / warm front</div>
<h1>Two air masses.<br />One sloping boundary.</h1>
<p class="subtitle">
Moist warm air rides over a dense cold-air wedge. The frontal surface tilts
upward, forcing the warm air to rise and cool.
</p>
</header>
<aside class="hud temperature">
<div class="cold-chip">
<b>Cold air</b>
<span>Dense · 4°C</span>
</div>
<div class="warm-chip">
<b>Warm air</b>
<span>Moist · 14°C</span>
</div>
</aside>
<aside class="hud legend">
<div class="legend-item"><span class="swatch"></span>Cold wedge</div>
<div class="legend-item"><span class="swatch warm"></span>Warm layer</div>
<div class="legend-item"><span class="swatch front"></span>Frontal surface</div>
</aside>
<nav class="hud controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="labelsButton" aria-pressed="true">Labels</button>
<button id="flowButton" aria-pressed="true">Flow</button>
<button id="resetButton">Reset</button>
</nav>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const labelsHost = document.getElementById("labels");
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.15;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07131d, 0.026);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.1, 0);
const view = {
theta: 0.56,
phi: 1.17,
radius: 16
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.sin(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xbce9ff, 0x173342, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.2);
keyLight.position.set(5, 11, 8);
scene.add(keyLight);
const warmLight = new THREE.DirectionalLight(0xff9b69, 1.4);
warmLight.position.set(-7, 5, 6);
scene.add(warmLight);
const coldLight = new THREE.DirectionalLight(0x5fd7ff, 1.2);
coldLight.position.set(7, 1, -7);
scene.add(coldLight);
const world = new THREE.Group();
scene.add(world);
const flowGroup = new THREE.Group();
world.add(flowGroup);
const animatedParticles = [];
const rainDrops = [];
const cloudGroup = new THREE.Group();
world.add(cloudGroup);
const coldColor = 0x55c8f3;
const warmColor = 0xff9566;
// Reference geometry for the sloping frontal surface.
const coldLeftX = -5.8;
const coldRightX = 3.3;
const coldBottomY = -2.4;
const coldLeftTopY = -1.25;
const coldRightTopY = 2.378;
const coldSlope = (coldRightTopY - coldLeftTopY) / (coldRightX - coldLeftX);
const depth = 2.35;
function coldTop(x) {
return coldLeftTopY + (x - coldLeftX) * coldSlope;
}
function makePrism(points, material) {
const contour = points.map((p) => new THREE.Vector2(p[0], p[1]));
const triangles = THREE.ShapeUtils.triangulateShape(contour, []);
const positions = [];
for (const p of points) positions.push(p[0], p[1], depth);
for (const p of points) positions.push(p[0], p[1], -depth);
const indices = [];
const n = points.length;
for (const tri of triangles) {
indices.push(tri[0], tri[1], tri[2]);
indices.push(n + tri[2], n + tri[1], n + tri[0]);
}
for (let i = 0; i < n; i++) {
const next = (i + 1) % n;
indices.push(i, n + i, next);
indices.push(next, n + i, n + next);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 1;
return mesh;
}
function addEdges(mesh, color, opacity = 0.4) {
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 15),
edgeMaterial
);
edges.renderOrder = 5;
mesh.add(edges);
}
// Dense cold-air wedge.
const coldPoints = [
[coldLeftX, coldBottomY],
[coldRightX, coldBottomY],
[coldRightX, coldRightTopY],
[coldLeftX, coldLeftTopY]
];
const coldMaterial = new THREE.MeshStandardMaterial({
color: coldColor,
transparent: true,
opacity: 0.29,
roughness: 0.82,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
});
const coldWedge = makePrism(coldPoints, coldMaterial);
world.add(coldWedge);
addEdges(coldWedge, 0x9eeaff, 0.42);
// Warm, moist layer riding over and slightly overlapping the cold wedge.
const warmLowerLeft = -0.2;
const warmLowerRight = 2.08;
const warmPoints = [
[-1.8, warmLowerLeft],
[3.3, warmLowerRight],
[6.8, warmLowerRight],
[6.8, 5.15],
[-1.8, 5.15]
];
const warmMaterial = new THREE.MeshStandardMaterial({
color: warmColor,
transparent: true,
opacity: 0.16,
roughness: 0.9,
side: THREE.DoubleSide,
depthWrite: false
});
const warmLayer = makePrism(warmPoints, warmMaterial);
warmLayer.renderOrder = 2;
world.add(warmLayer);
addEdges(warmLayer, 0xffbd8a, 0.3);
// Low-poly faceting on the cold wedge's sloping upper surface.
const coldFacetMaterials = [
new THREE.MeshBasicMaterial({
color: 0x7ddcff,
transparent: true,
opacity: 0.19,
side: THREE.DoubleSide,
depthWrite: false
}),
new THREE.MeshBasicMaterial({
color: 0x42a9d5,
transparent: true,
opacity: 0.24,
side: THREE.DoubleSide,
depthWrite: false
}),
new THREE.MeshBasicMaterial({
color: 0x9cecff,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
];
const coldFacetXs = [
-5.8, -4.7, -3.5, -2.25, -1.0, 0.35, 1.75, 3.3
];
function addTriangle(points, material, renderOrder = 3) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(points.flat(), 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = renderOrder;
return mesh;
}
for (let i = 0; i < coldFacetXs.length - 1; i++) {
const x0 = coldFacetXs[i];
const x1 = coldFacetXs[i + 1];
const y0 = coldTop(x0);
const y1 = coldTop(x1);
world.add(
addTriangle(
[
[x0, y0, depth + 0.025],
[x1, y1, depth + 0.025],
[x1, y1, -depth - 0.025]
],
coldFacetMaterials[i % coldFacetMaterials.length]
)
);
world.add(
addTriangle(
[
[x0, y0, depth + 0.025],
[x1, y1, -depth - 0.025],
[x0, y0, -depth - 0.025]
],
coldFacetMaterials[(i + 1) % coldFacetMaterials.length]
)
);
}
// A faceted front section makes the wedge shape legible.
const coldFacePoints = [
[-5.8, -2.4],
[-2.0, -2.4],
[1.2, -2.4],
[3.3, -2.4],
[3.3, 2.378],
[1.2, 1.17],
[-1.0, -0.36],
[-3.2, -0.89],
[-5.8, -1.25]
];
const coldFaceMaterials = [
new THREE.MeshBasicMaterial({
color: 0x4cbbe8,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
}),
new THREE.MeshBasicMaterial({
color: 0x8be6ff,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false
})
];
const coldCenter = new THREE.Vector2(-1.25, -0.5);
for (let i = 0; i < coldFacePoints.length; i++) {
const a = coldFacePoints[i];
const b = coldFacePoints[(i + 1) % coldFacePoints.length];
world.add(
addTriangle(
[
[a[0], a[1], depth + 0.04],
[b[0], b[1], depth + 0.04],
[coldCenter.x, coldCenter.y, depth + 0.04]
],
coldFaceMaterials[i % 2],
4
)
);
}
// Faceted warm-air roof.
const warmRoofMaterials = [
new THREE.MeshBasicMaterial({
color: 0xffb17f,
transparent: true,
opacity: 0.07,
side: THREE.DoubleSide,
depthWrite: false
}),
new THREE.MeshBasicMaterial({
color: 0xffd394,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false
})
];
const warmRoofXs = [-1.8, 0.2, 2.3, 4.5, 6.8];
for (let i = 0; i < warmRoofXs.length - 1; i++) {
const x0 = warmRoofXs[i];
const x1 = warmRoofXs[i + 1];
world.add(
addTriangle(
[
[x0, 5.15, depth],
[x1, 5.15, depth],
[x1, 5.15, -depth]
],
warmRoofMaterials[i % 2],
4
)
);
world.add(
addTriangle(
[
[x0, 5.15, depth],
[x1, 5.15, -depth],
[x0, 5.15, -depth]
],
warmRoofMaterials[(i + 1) % 2],
4
)
);
}
// Grid and reference lines.
const gridPositions = [];
for (let x = -6.5; x <= 7; x += 1) {
gridPositions.push(x, -2.39, -3.5, x, -2.39, 3.6);
}
for (let z = -3.5; z <= 3.5; z += 1) {
gridPositions.push(-6.5, -2.39, z, 7, -2.39, z);
}
for (let x = -6; x <= 7; x += 1) {
gridPositions.push(x, -2.39, -3.25, x, 5.45, -3.25);
}
for (let y = -2; y <= 5; y += 1) {
gridPositions.push(-6.5, y, -3.25, 7, y, -3.25);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x78a8bd,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
world.add(grid);
// Bright frontal-surface traces at the front and rear of the volume.
function addLine(points, color, opacity = 1, renderOrder = 7) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
depthTest: false
})
);
line.renderOrder = renderOrder;
world.add(line);
return line;
}
addLine(
[
[coldLeftX, coldLeftTopY, depth + 0.09],
[coldRightX, coldRightTopY, depth + 0.09]
],
0xdcfaff,
0.9
);
addLine(
[
[coldLeftX, coldLeftTopY, -depth - 0.09],
[coldRightX, coldRightTopY, -depth - 0.09]
],
0xa7eaff,
0.32
);
addLine(
[
[-1.8, warmLowerLeft, depth + 0.1],
[3.3, warmLowerRight, depth + 0.1]
],
0xffb47f,
0.72
);
// Surface-front marker.
const surfaceFront = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.055, 6.8),
new THREE.MeshBasicMaterial({
color: 0xff8b5d,
transparent: true,
opacity: 0.82
})
);
surfaceFront.position.set(coldRightX, -2.36, 0);
world.add(surfaceFront);
// Flow arrow helper.
function makeArrow(points, color, radius = 0.035) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"catmullrom",
0.35
);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 38, radius, 5, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.76,
depthWrite: false
})
);
flowGroup.add(tube);
const head = new THREE.Mesh(
new THREE.ConeGeometry(radius * 3.8, radius * 10, 5),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
head.position.copy(curve.getPointAt(1));
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangentAt(1).normalize()
);
flowGroup.add(head);
return curve;
}
function addParticles(curve, count, color, speed) {
const geometry = new THREE.IcosahedronGeometry(0.105, 0);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
for (let i = 0; i < count; i++) {
const particle = new THREE.Mesh(geometry, material);
flowGroup.add(particle);
animatedParticles.push({
mesh: particle,
curve,
offset: i / count,
speed
});
}
}
const coldFlow = makeArrow(
[
[-5.25, -1.83, depth + 0.24],
[-3.7, -1.85, depth + 0.24],
[-1.7, -1.84, depth + 0.24],
[1.9, -1.72, depth + 0.24]
],
0x8ee9ff,
0.042
);
addParticles(coldFlow, 5, 0xb8f4ff, 0.07);
const warmFlow = makeArrow(
[
[6.45, 3.08, depth + 0.28],
[4.7, 3.45, depth + 0.28],
[2.7, 3.92, depth + 0.28],
[0.5, 4.35, depth + 0.28],
[-1.25, 4.57, depth + 0.28]
],
0xffad7c,
0.045
);
addParticles(warmFlow, 6, 0xffd092, 0.075);
// Explicit rising arrows at the sloping frontal boundary.
[-1.05, 0.35, 1.75].forEach((x, index) => {
const y = coldTop(x);
const curve = makeArrow(
[
[x, y + 0.08, depth + 0.38],
[x - 0.08, y + 0.72, depth + 0.38],
[x - 0.22, y + 1.35, depth + 0.38],
[x - 0.34, y + 1.82, depth + 0.38]
],
index === 1 ? 0xffd09a : 0xff9c6d,
0.033
);
addParticles(curve, 2, 0xffd09a, 0.14 + index * 0.01);
});
// Low-poly cloud clusters.
const cloudGeometry = new THREE.IcosahedronGeometry(1, 0);
const cloudMaterials = [
new THREE.MeshStandardMaterial({
color: 0xd9eff6,
transparent: true,
opacity: 0.25,
roughness: 1,
flatShading: true,
depthWrite: false
}),
new THREE.MeshStandardMaterial({
color: 0xaacbd7,
transparent: true,
opacity: 0.2,
roughness: 1,
flatShading: true,
depthWrite: false
})
];
const cloudPieces = [
[-0.8, 5.35, 0.0, 1.25],
[-0.05, 5.52, 0.1, 1.38],
[0.82, 5.42, -0.1, 1.18],
[1.55, 5.28, 0.15, 0.92],
[0.42, 5.91, -0.2, 1.05]
];
cloudPieces.forEach((piece, index) => {
const cloud = new THREE.Mesh(
cloudGeometry,
cloudMaterials[index % cloudMaterials.length]
);
cloud.position.set(piece[0], piece[1], piece[2]);
cloud.scale.set(piece[3], piece[3] * 0.62, piece[3] * 0.7);
cloud.rotation.set(index * 0.19, index * 0.37, index * 0.13);
cloudGroup.add(cloud);
});
// Precipitation falling on the cold side of the front.
const rainMaterial = new THREE.LineBasicMaterial({
color: 0x8ee7ff,
transparent: true,
opacity: 0.42,
depthWrite: false
});
for (let i = 0; i < 34; i++) {
const x = -3.6 + Math.random() * 4.2;
const y = 2.8 + Math.random() * 2.2;
const z = -1.8 + Math.random() * 3.5;
const length = 0.18 + Math.random() * 0.24;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, y, z),
new THREE.Vector3(x - 0.04, y - length, z)
]);
const drop = new THREE.Line(geometry, rainMaterial);
cloudGroup.add(drop);
rainDrops.push({
mesh: drop,
speed: 2.1 + Math.random() * 1.8,
resetY: 5.0 + Math.random() * 0.7
});
}
// Small suspended particles emphasize the denser cold-air volume.
const densityGeometry = new THREE.TetrahedronGeometry(0.11, 0);
const densityMaterial = new THREE.MeshBasicMaterial({
color: 0xb5efff,
transparent: true,
opacity: 0.42,
depthWrite: false
});
for (let i = 0; i < 22; i++) {
const x = -5.2 + Math.random() * 7.8;
const upper = coldTop(x) - 0.25;
const lower = coldBottomY + 0.22;
const y = lower + Math.random() * Math.max(0.2, upper - lower);
const z = -2.05 + Math.random() * 4.1;
const particle = new THREE.Mesh(densityGeometry, densityMaterial);
particle.position.set(x, y, z);
particle.rotation.set(Math.random() * 3, Math.random() * 3, Math.random() * 3);
world.add(particle);
}
// HTML annotations projected directly from Three.js coordinates.
const labels = [];
function addLabel(className, title, detail, point) {
const element = document.createElement("div");
element.className = `label ${className}`;
element.innerHTML = `<strong>${title}</strong><span>${detail}</span>`;
labelsHost.appendChild(element);
labels.push({
element,
point: new THREE.Vector3(...point)
});
}
addLabel(
"cold",
"Cold air wedge",
"denser · advancing slowly",
[-3.6, -0.75, depth + 0.55]
);
addLabel(
"warm",
"Warm moist layer",
"lighter · rising over cold air",
[4.45, 3.65, depth + 0.55]
);
addLabel(
"front",
"Frontal surface",
"sloped density boundary",
[1.15, 1.58, depth + 0.6]
);
addLabel(
"warm",
"Rising air",
"cooling as it ascends",
[0.05, 4.25, depth + 0.55]
);
addLabel(
"rain",
"Precipitation",
"forming in the lifted moist air",
[-2.65, 3.15, depth + 0.55]
);
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.point).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.opacity = "1";
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
}
// Direct camera controls, implemented without external addons.
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi + dy * 0.005, 0.4, 1.42);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.012,
10,
24
);
updateCamera();
},
{ passive: false }
);
document.getElementById("resetButton").addEventListener("click", () => {
view.theta = 0.56;
view.phi = 1.17;
view.radius = window.innerWidth < 760 ? 18 : 16;
updateCamera();
});
document.getElementById("labelsButton").addEventListener("click", (event) => {
const enabled = event.currentTarget.getAttribute("aria-pressed") !== "true";
event.currentTarget.setAttribute("aria-pressed", String(enabled));
labelsHost.classList.toggle("labels-off", !enabled);
});
document.getElementById("flowButton").addEventListener("click", (event) => {
const enabled = event.currentTarget.getAttribute("aria-pressed") !== "true";
event.currentTarget.setAttribute("aria-pressed", String(enabled));
flowGroup.visible = enabled;
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
view.theta = 0.56;
view.phi = 1.17;
view.radius = 16;
updateCamera();
}
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = camera.aspect < 0.8 ? 48 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let previousTime = 0;
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const delta = Math.min(elapsed - previousTime, 0.05);
previousTime = elapsed;
for (const particle of animatedParticles) {
const t = (elapsed * particle.speed + particle.offset) % 1;
particle.mesh.position.copy(particle.curve.getPointAt(t));
particle.mesh.rotation.x += delta * 1.8;
particle.mesh.rotation.y += delta * 2.1;
}
for (const drop of rainDrops) {
drop.mesh.position.y -= drop.speed * delta;
if (drop.mesh.position.y < -2.15) {
drop.mesh.position.y = drop.resetY;
}
}
cloudGroup.position.x = Math.sin(elapsed * 0.13) * 0.075;
cloudGroup.position.y = Math.sin(elapsed * 0.35) * 0.035;
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```