Prompt specification
Build or customize the Three.js 3D scene "Cooling air toward condensation" 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: Cooling air toward condensation
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cooling-air-toward-condensation-x1242
Scene Description Prompt:
Keep a synthetic vapor amount fixed while lowering chamber temperature; show relative humidity rising toward saturation and only then add schematic condensate on a surface. Use Three.js from cdnjs in a single HTML file, with stylized solid shapes.
Working Three.js Starter (cooling-air-toward-condensation-x1242):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fixed Vapor Load — Relative Humidity and Condensation</title>
<style>
:root {
color-scheme: dark;
--bg: #07101d;
--panel: rgba(13, 26, 43, 0.82);
--panel-strong: rgba(10, 21, 36, 0.94);
--border: rgba(164, 211, 232, 0.16);
--text: #edf8ff;
--muted: #91aabd;
--cyan: #58e0d4;
--blue: #58a9ff;
--cold: #72baff;
--warm: #64e2cc;
--rh-angle: 0deg;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #172c42 0%, #091421 46%, #050b14 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: var(--text);
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px 21px 19px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
top: 22px;
right: 22px;
width: 302px;
padding: 17px;
pointer-events: none;
}
.metric-row {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
}
.metric-label {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
margin-top: 3px;
font-size: 30px;
font-weight: 760;
letter-spacing: -0.045em;
}
.metric-value small {
color: var(--muted);
font-size: 13px;
font-weight: 600;
letter-spacing: 0;
}
.rh-block {
margin-top: 16px;
}
.rh-number {
display: flex;
align-items: baseline;
gap: 5px;
}
.rh-number strong {
font-size: 42px;
line-height: 1;
letter-spacing: -0.055em;
}
.rh-number span {
color: var(--muted);
font-size: 18px;
font-weight: 700;
}
.rh-track {
position: relative;
height: 8px;
margin-top: 13px;
overflow: hidden;
border-radius: 999px;
background: rgba(116, 151, 181, 0.16);
}
.rh-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #4bd8ca, #62b7ff);
box-shadow: 0 0 15px rgba(88, 174, 255, 0.35);
transition: width 100ms linear;
}
.rh-scale {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #718ba1;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.chart-wrap {
margin-top: 16px;
padding-top: 13px;
border-top: 1px solid var(--border);
}
.chart-title {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#rhChart {
display: block;
width: 100%;
height: 116px;
margin-top: 6px;
overflow: visible;
}
.phase-card {
bottom: 146px;
left: 22px;
width: 302px;
padding: 16px 17px;
pointer-events: none;
}
.phase-heading {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 760;
}
.phase-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px rgba(88, 224, 212, 0.7);
}
.phase-card[data-state="saturation"] .phase-dot {
background: #ffd66b;
box-shadow: 0 0 14px rgba(255, 214, 107, 0.75);
}
.phase-card[data-state="condensing"] .phase-dot {
background: var(--blue);
box-shadow: 0 0 14px rgba(88, 169, 255, 0.8);
}
.phase-detail {
margin: 7px 0 0 18px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.inventory {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.inventory > div {
padding: 10px;
border: 1px solid rgba(151, 202, 227, 0.11);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.inventory span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.inventory strong {
display: block;
margin-top: 4px;
font-size: 16px;
}
.controls {
bottom: 22px;
left: 50%;
width: min(760px, calc(100vw - 44px));
padding: 16px 18px 15px;
transform: translateX(-50%);
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.temperature-readout {
min-width: 145px;
}
.temperature-readout strong {
font-size: 26px;
letter-spacing: -0.04em;
}
.temperature-readout span {
margin-left: 8px;
color: var(--muted);
font-size: 11px;
}
.button-row {
display: flex;
gap: 8px;
}
.button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(157, 208, 231, 0.17);
border-radius: 11px;
background: rgba(255, 255, 255, 0.055);
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.button:hover {
border-color: rgba(104, 220, 214, 0.45);
background: rgba(88, 224, 212, 0.1);
}
.button:active {
transform: translateY(1px);
}
.button.primary {
border-color: rgba(88, 224, 212, 0.36);
background: linear-gradient(135deg, rgba(67, 211, 196, 0.2), rgba(74, 145, 235, 0.16));
color: #eafffb;
}
.slider-wrap {
margin-top: 13px;
}
#temperature {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
border-radius: 999px;
outline: none;
background:
linear-gradient(
90deg,
#4fdaca 0%,
#62aef8 100%
);
cursor: pointer;
}
#temperature::-webkit-slider-thumb {
width: 19px;
height: 19px;
appearance: none;
border: 3px solid #dffdfa;
border-radius: 50%;
background: #42cfc2;
box-shadow: 0 0 0 5px rgba(66, 207, 194, 0.12);
}
#temperature::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #dffdfa;
border-radius: 50%;
background: #42cfc2;
box-shadow: 0 0 0 5px rgba(66, 207, 194, 0.12);
}
.slider-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #718ba1;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.utility {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 20;
}
.utility .button {
background: var(--panel-strong);
backdrop-filter: blur(16px);
}
.interaction-hint {
position: fixed;
right: 23px;
bottom: 72px;
z-index: 9;
color: rgba(188, 216, 231, 0.58);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.05em;
pointer-events: none;
}
.status-line {
margin-top: 9px;
color: #6f899e;
font-size: 10px;
line-height: 1.45;
}
@media (max-width: 900px) {
.intro {
width: 290px;
}
.intro p,
.chart-wrap {
display: none;
}
.metrics {
width: 260px;
}
.phase-card {
bottom: 155px;
width: 260px;
}
.interaction-hint {
display: none;
}
}
@media (max-width: 650px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro h1 {
font-size: 24px;
}
.metrics {
top: 104px;
right: 12px;
width: 210px;
padding: 13px;
}
.metric-row {
display: none;
}
.rh-number strong {
font-size: 34px;
}
.phase-card {
display: none;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.control-top {
align-items: flex-start;
flex-direction: column;
gap: 9px;
}
.button-row,
.button {
width: 100%;
}
.utility {
right: 12px;
bottom: 126px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive three-dimensional vapor chamber"></div>
<header class="panel intro">
<div class="eyebrow">Phase behavior / fixed vapor load</div>
<h1>Vapor → Condensate</h1>
<p>
Lower the chamber temperature while keeping the total synthetic vapor
load fixed. Relative humidity approaches saturation first; excess vapor
becomes visible as condensate only after the dew point is crossed.
</p>
</header>
<section class="panel metrics" aria-label="Simulation measurements">
<div class="metric-row">
<div>
<div class="metric-label">Chamber temperature</div>
<div class="metric-value">
<span id="temperatureValue">22.0</span><small> °C</small>
</div>
</div>
<div>
<div class="metric-label">Dew point</div>
<div class="metric-value">
<span id="dewPointValue">12.0</span><small> °C</small>
</div>
</div>
</div>
<div class="rh-block">
<div class="metric-label">Relative humidity</div>
<div class="rh-number">
<strong id="rhValue">54</strong><span>%</span>
</div>
<div class="rh-track">
<div class="rh-fill" id="rhFill"></div>
</div>
<div class="rh-scale">
<span>Dry</span>
<span>Saturation</span>
</div>
</div>
<div class="chart-wrap">
<div class="chart-title">
<span>RH response</span>
<span>Cooling →</span>
</div>
<svg id="rhChart" viewBox="0 0 270 116" role="img"
aria-label="Relative humidity versus chamber temperature">
<defs>
<linearGradient id="chartGradient" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stop-color="#50dccc" />
<stop offset="100%" stop-color="#63aaff" />
</linearGradient>
</defs>
<line x1="14" y1="25" x2="255" y2="25"
stroke="#5d89ad" stroke-width="1"
stroke-dasharray="3 4" opacity=".45" />
<line x1="14" y1="92" x2="255" y2="92"
stroke="#7596ae" stroke-width="1" opacity=".16" />
<path id="chartPath" fill="none"
stroke="url(#chartGradient)" stroke-width="2.5"
stroke-linecap="round" stroke-linejoin="round" />
<circle id="chartMarkerHalo" r="7" fill="#67b8ff" opacity=".15" />
<circle id="chartMarker" r="3.5" fill="#dffbff"
stroke="#5dc7df" stroke-width="2" />
<text x="14" y="108" fill="#718ba1" font-size="8">30°C</text>
<text x="255" y="108" text-anchor="end"
fill="#718ba1" font-size="8">5°C</text>
<text x="3" y="28" fill="#718ba1" font-size="8">100</text>
<text x="9" y="95" fill="#718ba1" font-size="8">0</text>
</svg>
</div>
</section>
<section class="panel phase-card" id="phaseCard" data-state="vapor">
<div class="phase-heading">
<span class="phase-dot"></span>
<span id="phaseTitle">Vapor-only chamber</span>
</div>
<div class="phase-detail" id="phaseDetail">
The sampling plate remains dry below saturation.
</div>
<div class="inventory">
<div>
<span>Gas vapor</span>
<strong id="gasUnits">160 units</strong>
</div>
<div>
<span>Condensed</span>
<strong id="condensedUnits">0 units</strong>
</div>
<div>
<span>Fixed total load</span>
<strong>160 units</strong>
</div>
<div>
<span>Surface</span>
<strong id="surfaceState">Dry</strong>
</div>
</div>
<div class="status-line" id="statusLine">
1.44 kPa equivalent vapor load at constant chamber volume.
</div>
</section>
<section class="panel controls" aria-label="Temperature controls">
<div class="control-top">
<div class="temperature-readout">
<div class="metric-label">Chamber temperature</div>
<strong id="sliderTemperature">22.0 °C</strong>
<span id="motionStatus">cooling slowly</span>
</div>
<div class="button-row">
<button class="button primary" id="playButton" type="button">
Pause cooling
</button>
<button class="button" id="resetButton" type="button">Reset</button>
</div>
</div>
<div class="slider-wrap">
<input id="temperature" type="range" min="30" max="5" step="0.1"
value="22" aria-label="Chamber temperature" />
<div class="slider-labels">
<span>30°C · warm</span>
<span>Dew point · 12°C</span>
<span>5°C · cold</span>
</div>
</div>
</section>
<button class="button utility" id="cameraReset" type="button">
Reset camera
</button>
<div class="interaction-hint">Drag to orbit · wheel to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const stage = $("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#07101d");
scene.fog = new THREE.Fog("#07101d", 13, 28);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
// ------------------------------------------------------------
// Physics: fixed total vapor load at a fixed chamber volume.
// ------------------------------------------------------------
const TOTAL_VAPOR_UNITS = 160;
const MIN_TEMPERATURE = 5;
const MAX_TEMPERATURE = 30;
const INITIAL_TEMPERATURE = 22;
// Magnus-form saturation vapor pressure, in hPa.
function saturationPressure(temperature) {
return 6.112 *
Math.exp((17.62 * temperature) / (243.12 + temperature));
}
// A fixed load equal to 60% RH at 20°C.
const FIXED_VAPOR_PRESSURE =
saturationPressure(20) * 0.60;
function findDewPoint() {
let low = -50;
let high = 50;
for (let i = 0; i < 70; i++) {
const middle = (low + high) * 0.5;
if (saturationPressure(middle) < FIXED_VAPOR_PRESSURE) {
low = middle;
} else {
high = middle;
}
}
return (low + high) * 0.5;
}
const DEW_POINT = findDewPoint();
const state = {
temperature: INITIAL_TEMPERATURE,
playing: !matchMedia("(prefers-reduced-motion: reduce)").matches,
visualCondensed: 0
};
// ------------------------------------------------------------
// Lighting and stylized chamber.
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight("#c5efff", "#152235", 1.55);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#d7f6ff", 2.6);
keyLight.position.set(4.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.PointLight("#62e4d2", 30, 13, 2);
rimLight.position.set(-4.2, 2.2, -2.8);
scene.add(rimLight);
const frontLight = new THREE.PointLight("#70baff", 19, 10, 2);
frontLight.position.set(4, 0.5, 4);
scene.add(frontLight);
const floor = new THREE.Mesh(
new THREE.CircleGeometry(14, 64),
new THREE.MeshStandardMaterial({
color: "#0b1725",
roughness: 0.88,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.38;
floor.receiveShadow = true;
scene.add(floor);
const baseMaterial = new THREE.MeshStandardMaterial({
color: "#25384b",
roughness: 0.34,
metalness: 0.72
});
const darkMetal = new THREE.MeshStandardMaterial({
color: "#17283a",
roughness: 0.42,
metalness: 0.68
});
const accentMetal = new THREE.MeshStandardMaterial({
color: "#5bbebd",
emissive: "#174d54",
emissiveIntensity: 0.38,
roughness: 0.28,
metalness: 0.7
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(3.22, 3.32, 0.42, 64),
baseMaterial
);
base.position.y = -2.16;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseInset = new THREE.Mesh(
new THREE.CylinderGeometry(2.82, 2.82, 0.08, 64),
darkMetal
);
baseInset.position.y = -1.91;
baseInset.receiveShadow = true;
scene.add(baseInset);
const lid = new THREE.Mesh(
new THREE.CylinderGeometry(3.16, 3.08, 0.22, 64),
baseMaterial
);
lid.position.y = 2.48;
lid.castShadow = true;
scene.add(lid);
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(3, 3, 4.4, 64, 1, true),
new THREE.MeshPhysicalMaterial({
color: "#9bd8ed",
transparent: true,
opacity: 0.055,
roughness: 0.2,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
shell.position.y = 0.25;
scene.add(shell);
const ringGeometry = new THREE.TorusGeometry(3.01, 0.055, 10, 80);
for (const y of [-1.88, 0.1, 2.32]) {
const ring = new THREE.Mesh(ringGeometry, accentMetal);
ring.rotation.x = Math.PI / 2;
ring.position.y = y;
ring.castShadow = true;
scene.add(ring);
}
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const strut = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 4.28, 0.065),
darkMetal
);
strut.position.set(
Math.cos(angle) * 3.01,
0.24,
Math.sin(angle) * 3.01
);
strut.rotation.y = -angle;
strut.castShadow = true;
scene.add(strut);
}
// Sampling plate, kept at chamber temperature so condensation begins
// only when the chamber itself reaches the saturation condition.
const plateGroup = new THREE.Group();
plateGroup.position.set(0.63, 0.35, -0.58);
plateGroup.rotation.y = -0.13;
scene.add(plateGroup);
const plateMaterial = new THREE.MeshStandardMaterial({
color: "#91a2b2",
roughness: 0.28,
metalness: 0.62
});
const plate = new THREE.Mesh(
new THREE.BoxGeometry(2.25, 2.4, 0.16),
plateMaterial
);
plate.castShadow = true;
plate.receiveShadow = true;
plateGroup.add(plate);
const plateInset = new THREE.Mesh(
new THREE.BoxGeometry(1.94, 2.08, 0.025),
new THREE.MeshStandardMaterial({
color: "#73879a",
roughness: 0.38,
metalness: 0.48
})
);
plateInset.position.z = 0.09;
plateInset.receiveShadow = true;
plateGroup.add(plateInset);
const wetOverlayMaterial = new THREE.MeshBasicMaterial({
color: "#55bfff",
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const wetOverlay = new THREE.Mesh(
new THREE.PlaneGeometry(1.94, 2.08),
wetOverlayMaterial
);
wetOverlay.position.z = 0.108;
plateGroup.add(wetOverlay);
const mount = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.18, 0.78),
darkMetal
);
mount.position.set(0.63, -1.05, -0.34);
mount.castShadow = true;
scene.add(mount);
// ------------------------------------------------------------
// Fixed inventory of synthetic vapor units.
// Before saturation, every unit is airborne. After saturation,
// excess units transfer to the plate.
// ------------------------------------------------------------
function mulberry32(seed) {
return function () {
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;
};
}
const random = mulberry32(271828);
const vaporPositions = [];
const vaporPhases = [];
const vaporSizes = [];
for (let i = 0; i < TOTAL_VAPOR_UNITS; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 2.66;
const y = -1.69 + random() * 3.64;
vaporPositions.push(
new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
)
);
vaporPhases.push(random() * Math.PI * 2);
vaporSizes.push(0.032 + random() * 0.025);
}
const vaporGeometry = new THREE.SphereGeometry(1, 10, 7);
const vaporMaterial = new THREE.MeshStandardMaterial({
color: "#65e6da",
emissive: "#1f8b8a",
emissiveIntensity: 0.85,
roughness: 0.38,
metalness: 0.05
});
const vaporMesh = new THREE.InstancedMesh(
vaporGeometry,
vaporMaterial,
TOTAL_VAPOR_UNITS
);
vaporMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
vaporMesh.frustumCulled = false;
vaporMesh.castShadow = true;
scene.add(vaporMesh);
const particleColor = new THREE.Color();
for (let i = 0; i < TOTAL_VAPOR_UNITS; i++) {
particleColor.setHSL(
0.47 + random() * 0.055,
0.64,
0.55 + random() * 0.13
);
vaporMesh.setColorAt(i, particleColor);
}
vaporMesh.instanceColor.needsUpdate = true;
const dropRandom = mulberry32(314159);
const dropPositions = [];
const dropSizes = [];
for (let i = 0; i < TOTAL_VAPOR_UNITS; i++) {
dropPositions.push(
new THREE.Vector3(
-0.88 + dropRandom() * 1.76,
-0.92 + dropRandom() * 1.84,
0.14 + dropRandom() * 0.012
)
);
dropSizes.push(0.04 + dropRandom() * 0.037);
}
const dropGeometry = new THREE.SphereGeometry(1, 12, 8);
const dropMaterial = new THREE.MeshPhysicalMaterial({
color: "#66c7ff",
emissive: "#165e9c",
emissiveIntensity: 0.45,
roughness: 0.14,
metalness: 0.02,
transmission: 0.08,
transparent: true,
opacity: 0.92
});
const dropMesh = new THREE.InstancedMesh(
dropGeometry,
dropMaterial,
TOTAL_VAPOR_UNITS
);
dropMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
dropMesh.count = 0;
dropMesh.frustumCulled = false;
dropMesh.castShadow = true;
scene.add(dropMesh);
// A handful of stylized rivulets reinforce the surface response.
const streakMaterial = new THREE.MeshStandardMaterial({
color: "#5bbcff",
emissive: "#164f83",
emissiveIntensity: 0.4,
roughness: 0.2,
transparent: true,
opacity: 0
});
const streaks = [];
for (let i = 0; i < 7; i++) {
const length = 0.22 + dropRandom() * 0.38;
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.022, 1, 7),
streakMaterial
);
const x = -0.8 + dropRandom() * 1.6;
const y = -0.18 + dropRandom() * 0.95;
mesh.position.set(x, y, 0.145);
mesh.scale.set(1, 0.001, 1);
plateGroup.add(mesh);
streaks.push({ mesh, x, y, length });
}
// ------------------------------------------------------------
// Custom camera controls: orbit, zoom, and reset.
// ------------------------------------------------------------
const cameraState = {
azimuth: 0.82,
polar: 1.08,
radius: 10.5,
targetAzimuth: 0.82,
targetPolar: 1.08,
targetRadius: 10.5
};
function updateCamera() {
cameraState.azimuth +=
(cameraState.targetAzimuth - cameraState.azimuth) * 0.1;
cameraState.polar +=
(cameraState.targetPolar - cameraState.polar) * 0.1;
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * 0.1;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.radius * Math.cos(cameraState.polar),
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(0, 0.05, 0);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.targetAzimuth -= dx * 0.0055;
cameraState.targetPolar = THREE.MathUtils.clamp(
cameraState.targetPolar - dy * 0.0045,
0.55,
1.47
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.008,
6.2,
15
);
}, { passive: false });
$("cameraReset").addEventListener("click", () => {
cameraState.targetAzimuth = 0.82;
cameraState.targetPolar = 1.08;
cameraState.targetRadius = 10.5;
});
// ------------------------------------------------------------
// UI and controls.
// ------------------------------------------------------------
const playButton = $("playButton");
const resetButton = $("resetButton");
const temperatureSlider = $("temperature");
function setPlaying(playing) {
state.playing = playing;
playButton.textContent = state.playing ? "Pause cooling" : "Start cooling";
$("motionStatus").textContent = state.playing
? "cooling slowly"
: "temperature held";
}
playButton.addEventListener("click", () => {
if (state.temperature <= MIN_TEMPERATURE + 0.01) {
state.temperature = INITIAL_TEMPERATURE;
setPlaying(true);
} else {
setPlaying(!state.playing);
}
});
resetButton.addEventListener("click", () => {
state.temperature = INITIAL_TEMPERATURE;
state.visualCondensed = 0;
setPlaying(false);
});
temperatureSlider.addEventListener("input", (event) => {
state.temperature = Number(event.target.value);
setPlaying(false);
});
setPlaying(state.playing);
// Static RH curve for the chart.
const chartPathPoints = [];
for (let temperature = MAX_TEMPERATURE;
temperature >= MIN_TEMPERATURE;
temperature -= 0.25) {
const saturation = saturationPressure(temperature);
const rh = temperature >= DEW_POINT
? Math.min(100, FIXED_VAPOR_PRESSURE / saturation * 100)
: 100;
const x = 14 +
(MAX_TEMPERATURE - temperature) /
(MAX_TEMPERATURE - MIN_TEMPERATURE) * 241;
const y = 92 - (rh / 100) * 67;
chartPathPoints.push(`${x.toFixed(2)},${y.toFixed(2)}`);
}
$("chartPath").setAttribute(
"d",
`M ${chartPathPoints.join(" L ")}`
);
const warmLight = new THREE.Color("#62e4d2");
const coldLight = new THREE.Color("#55a9ff");
const dummy = new THREE.Object3D();
const worldPosition = new THREE.Vector3();
function updateUI(rh, gasUnits, condensedUnits) {
const temperature = state.temperature;
const belowDewPoint = temperature < DEW_POINT - 0.08;
const atDewPoint = Math.abs(temperature - DEW_POINT) <= 0.08;
$("temperatureValue").textContent = temperature.toFixed(1);
$("sliderTemperature").textContent = `${temperature.toFixed(1)} °C`;
$("dewPointValue").textContent = DEW_POINT.toFixed(1);
$("rhValue").textContent = Math.round(rh);
$("rhFill").style.width = `${rh.toFixed(2)}%`;
$("gasUnits").textContent = `${gasUnits} units`;
$("condensedUnits").textContent = `${condensedUnits} units`;
$("surfaceState").textContent = condensedUnits > 0 ? "Wet" : "Dry";
temperatureSlider.value = temperature.toFixed(1);
const phaseCard = $("phaseCard");
if (belowDewPoint) {
phaseCard.dataset.state = "condensing";
$("phaseTitle").textContent = "Condensation active";
$("phaseDetail").textContent =
"The chamber is saturated; excess vapor is transferring to the plate.";
} else if (atDewPoint) {
phaseCard.dataset.state = "saturation";
$("phaseTitle").textContent = "Saturation threshold";
$("phaseDetail").textContent =
"Relative humidity has reached 100%; cooling further initiates condensation.";
} else {
phaseCard.dataset.state = "vapor";
$("phaseTitle").textContent = "Vapor-only chamber";
$("phaseDetail").textContent =
"The sampling plate remains dry below saturation.";
}
const chartX = 14 +
(MAX_TEMPERATURE - temperature) /
(MAX_TEMPERATURE - MIN_TEMPERATURE) * 241;
const chartY = 92 - (rh / 100) * 67;
$("chartMarker").setAttribute("cx", chartX);
$("chartMarker").setAttribute("cy", chartY);
$("chartMarkerHalo").setAttribute("cx", chartX);
$("chartMarkerHalo").setAttribute("cy", chartY);
const fixedKPa = FIXED_VAPOR_PRESSURE / 10;
$("statusLine").textContent =
`${fixedKPa.toFixed(2)} kPa equivalent fixed load at constant volume. ` +
`Below ${DEW_POINT.toFixed(1)}°C, gas vapor stays saturated while the ` +
`excess becomes condensate.`;
}
// ------------------------------------------------------------
// Animation.
// ------------------------------------------------------------
let previousTime = performance.now();
let elapsed = 0;
function animate(now) {
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
elapsed += dt;
if (state.playing) {
state.temperature = Math.max(
MIN_TEMPERATURE,
state.temperature - dt * 0.65
);
if (state.temperature <= MIN_TEMPERATURE) {
setPlaying(false);
}
}
const saturation = saturationPressure(state.temperature);
let relativeHumidity;
let equilibriumCondensedFraction;
if (state.temperature >= DEW_POINT) {
relativeHumidity = Math.min(
100,
FIXED_VAPOR_PRESSURE / saturation * 100
);
equilibriumCondensedFraction = 0;
} else {
relativeHumidity = 100;
equilibriumCondensedFraction = Math.max(
0,
1 - saturation / FIXED_VAPOR_PRESSURE
);
}
// Smoothly transfer visual units between gas and surface phases.
const smoothing = 1 - Math.exp(-dt * 7);
state.visualCondensed = THREE.MathUtils.lerp(
state.visualCondensed,
equilibriumCondensedFraction,
smoothing
);
if (equilibriumCondensedFraction === 0 &&
state.temperature > DEW_POINT + 0.1) {
state.visualCondensed = 0;
}
const condensedUnits = Math.round(
equilibriumCondensedFraction * TOTAL_VAPOR_UNITS
);
const gasUnits = TOTAL_VAPOR_UNITS - condensedUnits;
const visualCondensedUnits = Math.round(
state.visualCondensed * TOTAL_VAPOR_UNITS
);
const visualGasUnits = TOTAL_VAPOR_UNITS - visualCondensedUnits;
vaporMesh.count = visualGasUnits;
for (let i = 0; i < visualGasUnits; i++) {
const base = vaporPositions[i];
const phase = vaporPhases[i];
const size = vaporSizes[i];
dummy.position.set(
base.x + Math.sin(elapsed * 0.52 + phase) * 0.022,
base.y + Math.sin(elapsed * 0.82 + phase) * 0.048,
base.z + Math.cos(elapsed * 0.46 + phase) * 0.018
);
dummy.rotation.set(0, 0, 0);
dummy.scale.setScalar(size);
dummy.updateMatrix();
vaporMesh.setMatrixAt(i, dummy.matrix);
}
vaporMesh.instanceMatrix.needsUpdate = true;
dropMesh.count = visualCondensedUnits;
for (let i = 0; i < visualCondensedUnits; i++) {
const local = dropPositions[i];
const size = dropSizes[i];
worldPosition
.copy(local)
.applyQuaternion(plateGroup.quaternion)
.add(plateGroup.position);
const emergence = THREE.MathUtils.clamp(
(state.visualCondensed * TOTAL_VAPOR_UNITS - i) * 1.35,
0,
1
);
dummy.position.copy(worldPosition);
dummy.quaternion.copy(plateGroup.quaternion);
dummy.scale.set(
size * emergence,
size * 1.55 * emergence,
size * 0.55 * emergence
);
dummy.updateMatrix();
dropMesh.setMatrixAt(i, dummy.matrix);
}
dropMesh.instanceMatrix.needsUpdate = true;
const wetStrength = THREE.MathUtils.clamp(
equilibriumCondensedFraction / 0.12,
0,
1
);
wetOverlayMaterial.opacity = wetStrength * 0.12;
streakMaterial.opacity = wetStrength * 0.72;
for (let i = 0; i < streaks.length; i++) {
const streak = streaks[i];
const streakProgress = THREE.MathUtils.clamp(
(state.visualCondensed * TOTAL_VAPOR_UNITS - i * 10) / 14,
0,
1
);
const length = streak.length * streakProgress;
streak.mesh.position.set(
streak.x,
streak.y - length * 0.5,
0.145
);
streak.mesh.scale.set(1, Math.max(0.001, length), 1);
}
const coolness =
(MAX_TEMPERATURE - state.temperature) /
(MAX_TEMPERATURE - MIN_TEMPERATURE);
rimLight.color.copy(warmLight).lerp(coldLight, coolness);
frontLight.color.copy(warmLight).lerp(coldLight, coolness);
accentMetal.emissive.set(coolness > 0.55 ? "#174c79" : "#174d54");
updateUI(relativeHumidity, gasUnits, condensedUnits);
updateCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```