Prompt specification
Build or customize the Three.js 3D scene "Skin heat-transfer concept controls" 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: Skin heat-transfer concept controls
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/skin-heat-transfer-concept-controls-x1024
Scene Description Prompt:
Adjust airflow and humidity above a voxel skin surface to explore qualitative evaporation in a toy model. Three.js from cdnjs, one HTML file.
Working Three.js Starter (skin-heat-transfer-concept-controls-x1024):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Evaporation Lab</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(10, 24, 33, 0.82);
--border: rgba(176, 226, 240, 0.17);
--text: #e9f6f8;
--muted: #91aab3;
--cyan: #78dff1;
--coral: #e49378;
--mint: #c7fff1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131b;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.header {
position: fixed;
z-index: 2;
top: 25px;
left: 28px;
max-width: min(590px, calc(100vw - 390px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 42px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1.02;
}
.subtitle {
max-width: 520px;
margin: 11px 0 0;
color: #a7bbc3;
font-size: 13px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 4;
top: 24px;
right: 24px;
width: 326px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 19px;
border: 1px solid var(--border);
border-radius: 19px;
background:
linear-gradient(145deg, rgba(22, 43, 53, 0.88), rgba(7, 19, 27, 0.88)),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(120, 223, 241, 0.35) transparent;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-heading h2 {
margin: 0;
font-size: 15px;
font-weight: 650;
letter-spacing: -0.015em;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(120, 223, 241, 0.16);
border-radius: 999px;
background: rgba(120, 223, 241, 0.07);
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
white-space: nowrap;
}
.status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
content: "";
}
.status[data-state="fast"] {
color: #ffc19e;
background: rgba(255, 145, 99, 0.08);
border-color: rgba(255, 145, 99, 0.2);
}
.status[data-state="still"] {
color: #a8bac1;
background: rgba(168, 186, 193, 0.07);
border-color: rgba(168, 186, 193, 0.14);
}
.control {
margin-top: 19px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control label {
font-size: 12px;
font-weight: 650;
}
.control output {
color: var(--cyan);
font-size: 12px;
font-variant-numeric: tabular-nums;
font-weight: 750;
}
.control-description {
min-height: 15px;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 5px;
margin: 4px 0;
border-radius: 999px;
outline: none;
appearance: none;
-webkit-appearance: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--fill),
rgba(157, 194, 205, 0.16) var(--fill),
rgba(157, 194, 205, 0.16) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #102a35;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(120, 223, 241, 0.6), 0 0 15px rgba(120, 223, 241, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #102a35;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(120, 223, 241, 0.6);
}
.metric {
margin-top: 21px;
padding: 14px;
border: 1px solid rgba(173, 224, 236, 0.12);
border-radius: 13px;
background: rgba(2, 13, 19, 0.31);
}
.metric-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.metric-top span {
color: #b8cbd2;
font-size: 11px;
font-weight: 650;
}
.metric-top strong {
color: var(--mint);
font-size: 21px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.meter {
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.meter > div {
width: 100%;
height: 100%;
transform: scaleX(0);
transform-origin: left center;
border-radius: inherit;
background: linear-gradient(90deg, #62cddd, #c7fff1, #ffd1ac);
box-shadow: 0 0 14px rgba(199, 255, 241, 0.42);
transition: transform 100ms linear;
}
.metric-bottom {
display: flex;
justify-content: space-between;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
}
.metric-bottom strong {
color: #d8e8ec;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 13px;
}
button {
min-height: 34px;
padding: 0 8px;
border: 1px solid rgba(169, 220, 233, 0.14);
border-radius: 9px;
background: rgba(145, 200, 216, 0.06);
color: #c9dce2;
font: inherit;
font-size: 10px;
font-weight: 650;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
button:hover {
border-color: rgba(120, 223, 241, 0.35);
background: rgba(120, 223, 241, 0.1);
color: white;
}
button:active {
transform: translateY(1px);
}
.explanation {
margin: 15px 0 0;
padding-top: 14px;
border-top: 1px solid rgba(170, 218, 230, 0.1);
color: #91a8b1;
font-size: 10px;
line-height: 1.55;
}
.explanation strong {
color: #bed2d9;
font-weight: 650;
}
.legend {
position: fixed;
z-index: 2;
bottom: 27px;
left: 28px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100vw - 410px);
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(176, 226, 240, 0.12);
border-radius: 999px;
background: rgba(8, 22, 30, 0.66);
color: #aec2ca;
font-size: 10px;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.swatch {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--coral);
}
.swatch.humidity {
border-radius: 50%;
background: #65bfe9;
box-shadow: 0 0 7px rgba(101, 191, 233, 0.7);
}
.swatch.vapor {
border-radius: 50%;
background: #d2fff2;
box-shadow: 0 0 7px rgba(210, 255, 242, 0.8);
}
.swatch.flow {
width: 15px;
height: 2px;
border-radius: 0;
background: var(--cyan);
box-shadow: 0 0 6px rgba(120, 223, 241, 0.7);
}
.hint {
position: fixed;
z-index: 2;
right: 28px;
bottom: 28px;
color: rgba(194, 216, 223, 0.55);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.subtitle {
max-width: 80%;
font-size: 11px;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 45vh;
padding: 15px;
border-radius: 16px;
}
.panel-heading {
margin-bottom: 10px;
}
.control {
margin-top: 13px;
}
.metric {
margin-top: 14px;
}
.legend,
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel skin evaporation simulation"></canvas>
<header class="header">
<div class="eyebrow">Atmospheric surface study / 01</div>
<h1>Voxel evaporation lab</h1>
<p class="subtitle">
Sweep air across a porous skin and watch vapor lift away. Lower humidity
leaves more room for evaporation; stronger airflow removes saturated air.
</p>
</header>
<aside class="panel" aria-label="Simulation controls">
<div class="panel-heading">
<h2>Surface conditions</h2>
<div id="status" class="status" data-state="active" aria-live="polite">
ACTIVE DRYING
</div>
</div>
<div class="control">
<div class="control-row">
<label for="airflow">Airflow</label>
<output id="airflowValue" for="airflow">45%</output>
</div>
<input id="airflow" type="range" min="0" max="100" value="45" />
<div id="airflowDescription" class="control-description">Brisk air moving left to right</div>
</div>
<div class="control">
<div class="control-row">
<label for="humidity">Relative humidity</label>
<output id="humidityValue" for="humidity">55%</output>
</div>
<input id="humidity" type="range" min="0" max="100" value="55" />
<div id="humidityDescription" class="control-description">Moderate moisture in the surrounding air</div>
</div>
<div class="metric">
<div class="metric-top">
<span>Evaporation tendency</span>
<strong id="rateValue">0%</strong>
</div>
<div class="meter" aria-hidden="true"><div id="rateBar"></div></div>
<div class="metric-bottom">
<span>Residual surface moisture</span>
<strong id="wetnessValue">0%</strong>
</div>
</div>
<div class="buttons">
<button id="pauseButton" type="button">Pause</button>
<button id="rewetButton" type="button">Rewet</button>
<button id="viewButton" type="button">Reset view</button>
</div>
<p class="explanation">
<strong>Qualitative model:</strong> evaporation rises with airflow and
saturation deficit. Pale rising beads are vapor; blue dots represent
ambient humidity. Cooler voxel tints indicate residual surface moisture.
This is an illustrative toy model, not a fluid-dynamics solver.
</p>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="swatch"></span>Voxel skin</div>
<div class="legend-item"><span class="swatch humidity"></span>Ambient humidity</div>
<div class="legend-item"><span class="swatch vapor"></span>Water vapor</div>
<div class="legend-item"><span class="swatch flow"></span>Airflow</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</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 ui = {
airflow: document.querySelector("#airflow"),
humidity: document.querySelector("#humidity"),
airflowValue: document.querySelector("#airflowValue"),
humidityValue: document.querySelector("#humidityValue"),
airflowDescription: document.querySelector("#airflowDescription"),
humidityDescription: document.querySelector("#humidityDescription"),
rateValue: document.querySelector("#rateValue"),
rateBar: document.querySelector("#rateBar"),
wetnessValue: document.querySelector("#wetnessValue"),
status: document.querySelector("#status"),
pauseButton: document.querySelector("#pauseButton"),
rewetButton: document.querySelector("#rewetButton"),
viewButton: document.querySelector("#viewButton")
};
const state = {
airflow: 0.45,
humidity: 0.55,
paused: false,
evaporation: 0
};
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x07131b, 1);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07131b, 0.0175);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
150
);
const orbit = {
radius: 35,
yaw: 0.57,
pitch: 1.01,
target: new THREE.Vector3(0, 1.6, 0)
};
function updateCamera() {
const sinPitch = Math.sin(orbit.pitch);
camera.position.set(
orbit.target.x + orbit.radius * sinPitch * Math.sin(orbit.yaw),
orbit.target.y + orbit.radius * Math.cos(orbit.pitch),
orbit.target.z + orbit.radius * sinPitch * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.radius = 35;
orbit.yaw = 0.57;
orbit.pitch = 1.01;
orbit.target.set(0, 1.6, 0);
updateCamera();
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xbcecff, 0x17242a, 1.7));
const keyLight = new THREE.DirectionalLight(0xffd2b5, 3.1);
keyLight.position.set(-13, 22, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -23;
keyLight.shadow.camera.right = 23;
keyLight.shadow.camera.top = 22;
keyLight.shadow.camera.bottom = -22;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 65;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x61d9ff, 34, 42, 2);
cyanLight.position.set(14, 10, -12);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff986f, 18, 34, 2);
warmLight.position.set(-13, 5, 10);
scene.add(warmLight);
// Floor and stage
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
new THREE.MeshStandardMaterial({
color: 0x091820,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.57;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(90, 90, 0x244553, 0x152b35);
grid.position.y = -0.555;
grid.material.transparent = true;
grid.material.opacity = 0.22;
grid.material.depthWrite = false;
scene.add(grid);
const base = new THREE.Mesh(
new THREE.BoxGeometry(26.2, 0.46, 17.1),
new THREE.MeshStandardMaterial({
color: 0x17313b,
roughness: 0.72,
metalness: 0.12
})
);
base.position.y = -0.29;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
const baseEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(base.geometry),
new THREE.LineBasicMaterial({
color: 0x4b8795,
transparent: true,
opacity: 0.34
})
);
baseEdges.position.copy(base.position);
scene.add(baseEdges);
// Deterministic random numbers keep the voxel pattern stable.
let seed = 84721;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function surfaceHeight(x, z) {
return (
1.28 +
Math.sin(x * 0.43) * 0.085 +
Math.cos(z * 0.57) * 0.07 +
Math.sin((x + z) * 0.79) * 0.035
);
}
// Voxel skin: a lower coral layer and a moisture-tinted top layer.
const nx = 27;
const nz = 17;
const spacing = 0.9;
const voxelCount = nx * nz;
const lowerGeometry = new THREE.BoxGeometry(0.84, 0.9, 0.84);
lowerGeometry.setAttribute("color", new THREE.BufferAttribute(
new Float32Array(lowerGeometry.getAttribute("position").count * 3).fill(1), 3
));
const topGeometry = new THREE.BoxGeometry(0.84, 0.34, 0.84);
topGeometry.setAttribute("color", new THREE.BufferAttribute(
new Float32Array(topGeometry.getAttribute("position").count * 3).fill(1), 3
));
const lowerMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.86,
metalness: 0.01
});
const topMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.69,
metalness: 0.015
});
const lowerVoxels = new THREE.InstancedMesh(
lowerGeometry,
lowerMaterial,
voxelCount
);
lowerVoxels.castShadow = true;
lowerVoxels.receiveShadow = true;
const topVoxels = new THREE.InstancedMesh(
topGeometry,
topMaterial,
voxelCount
);
topVoxels.castShadow = true;
topVoxels.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
const dryColor = new THREE.Color(0xe49378);
const wetColor = new THREE.Color(0x58adba);
const wetness = new Float32Array(voxelCount);
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const i = iz * nx + ix;
const x = (ix - (nx - 1) / 2) * spacing;
const z = (iz - (nz - 1) / 2) * spacing;
const variation = random();
dummy.position.set(x, 0.48, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
lowerVoxels.setMatrixAt(i, dummy.matrix);
color.set(0xb96559);
color.offsetHSL(0, 0, (variation - 0.5) * 0.085);
lowerVoxels.setColorAt(i, color);
dummy.position.set(x, surfaceHeight(x, z) - 0.17, z);
dummy.updateMatrix();
topVoxels.setMatrixAt(i, dummy.matrix);
wetness[i] = 0.57 + variation * 0.18;
updateTopColor(i, variation);
}
}
lowerVoxels.instanceMatrix.needsUpdate = true;
lowerVoxels.instanceColor.needsUpdate = true;
topVoxels.instanceMatrix.needsUpdate = true;
topVoxels.instanceColor.needsUpdate = true;
topVoxels.instanceColor.setUsage(THREE.DynamicDrawUsage);
scene.add(lowerVoxels, topVoxels);
function updateTopColor(i, variation = 0.5) {
color.copy(dryColor).lerp(wetColor, THREE.MathUtils.clamp(wetness[i], 0, 1) * 0.72);
color.offsetHSL(0, 0, (variation - 0.5) * 0.055);
topVoxels.setColorAt(i, color);
}
// Small pores make the voxel surface read as a skin-like material.
const poreCount = 125;
const poreGeometry = new THREE.CylinderGeometry(0.028, 0.035, 0.018, 7);
const poreMaterial = new THREE.MeshStandardMaterial({
color: 0x673e47,
roughness: 1
});
const pores = new THREE.InstancedMesh(poreGeometry, poreMaterial, poreCount);
for (let i = 0; i < poreCount; i++) {
const x = (random() - 0.5) * 22.5;
const z = (random() - 0.5) * 14.4;
dummy.position.set(x, surfaceHeight(x, z) + 0.009, z);
dummy.rotation.set(0, random() * Math.PI, 0);
const s = 0.75 + random() * 0.65;
dummy.scale.set(s, 1, s);
dummy.updateMatrix();
pores.setMatrixAt(i, dummy.matrix);
}
pores.instanceMatrix.needsUpdate = true;
scene.add(pores);
// Soft circular particle texture generated locally.
function makeParticleTexture() {
const c = document.createElement("canvas");
c.width = 64;
c.height = 64;
const ctx = c.getContext("2d");
const gradient = ctx.createRadialGradient(32, 32, 0, 32, 32, 32);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.22, "rgba(255,255,255,0.95)");
gradient.addColorStop(0.58, "rgba(255,255,255,0.28)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 64, 64);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const particleTexture = makeParticleTexture();
// Ambient humidity: blue particles distributed above the skin.
const humidityCount = 900;
const humidityPositions = new Float32Array(humidityCount * 3);
const humidityData = [];
for (let i = 0; i < humidityCount; i++) {
const x = (random() - 0.5) * 37;
const y = 1.55 + random() * 9.3;
const z = (random() - 0.5) * 22;
humidityPositions[i * 3] = x;
humidityPositions[i * 3 + 1] = y;
humidityPositions[i * 3 + 2] = z;
humidityData.push({
speed: 0.65 + random() * 0.8,
phase: random() * Math.PI * 2,
drift: 0.015 + random() * 0.035
});
}
const humidityGeometry = new THREE.BufferGeometry();
humidityGeometry.setAttribute(
"position",
new THREE.BufferAttribute(humidityPositions, 3)
);
const humidityMaterial = new THREE.PointsMaterial({
color: 0x65bfe9,
size: 0.26,
map: particleTexture,
transparent: true,
opacity: 0.35,
depthWrite: false,
blending: THREE.AdditiveBlending,
sizeAttenuation: true
});
const humidityPoints = new THREE.Points(humidityGeometry, humidityMaterial);
humidityPoints.frustumCulled = false;
scene.add(humidityPoints);
// Water vapor: pale beads rise from the skin and drift downwind.
const vaporCount = 520;
const vaporPositions = new Float32Array(vaporCount * 3);
const vaporData = [];
for (let i = 0; i < vaporCount; i++) {
const sourceX = (random() - 0.5) * 22.2;
const sourceZ = (random() - 0.5) * 14.2;
vaporData.push({
sourceX,
sourceZ,
phase: random(),
speed: 0.72 + random() * 0.7,
offset: random() * Math.PI * 2
});
vaporPositions[i * 3 + 1] = -100;
}
const vaporGeometry = new THREE.BufferGeometry();
vaporGeometry.setAttribute(
"position",
new THREE.BufferAttribute(vaporPositions, 3)
);
const vaporMaterial = new THREE.PointsMaterial({
color: 0xd4fff3,
size: 0.18,
map: particleTexture,
transparent: true,
opacity: 0.88,
depthWrite: false,
blending: THREE.AdditiveBlending,
sizeAttenuation: true
});
const vaporPoints = new THREE.Points(vaporGeometry, vaporMaterial);
vaporPoints.frustumCulled = false;
scene.add(vaporPoints);
// Moving airflow arrows and short trails.
const flowCount = 64;
const flowGeometry = new THREE.ConeGeometry(0.075, 0.3, 7);
flowGeometry.rotateZ(-Math.PI / 2);
const flowMaterial = new THREE.MeshBasicMaterial({
color: 0x82dff0,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const flowArrows = new THREE.InstancedMesh(
flowGeometry,
flowMaterial,
flowCount
);
flowArrows.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
flowArrows.frustumCulled = false;
scene.add(flowArrows);
const trailPositions = new Float32Array(flowCount * 6);
const trailGeometry = new THREE.BufferGeometry();
trailGeometry.setAttribute(
"position",
new THREE.BufferAttribute(trailPositions, 3)
);
const trailMaterial = new THREE.LineBasicMaterial({
color: 0x78d9ec,
transparent: true,
opacity: 0.27,
depthWrite: false
});
const flowTrails = new THREE.LineSegments(trailGeometry, trailMaterial);
flowTrails.frustumCulled = false;
scene.add(flowTrails);
const flowData = [];
for (let i = 0; i < flowCount; i++) {
flowData.push({
x: (random() - 0.5) * 33,
y: 1.9 + random() * 5.7,
z: (random() - 0.5) * 17,
phase: random() * Math.PI * 2,
speed: 0.65 + random() * 0.8
});
}
const directionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-13, 8.2, -10),
26,
0x75d9ed,
0.9,
0.45
);
directionArrow.line.material.transparent = true;
directionArrow.line.material.opacity = 0.38;
directionArrow.cone.material.transparent = true;
directionArrow.cone.material.opacity = 0.55;
scene.add(directionArrow);
// Controls
function sliderFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateControlDescriptions() {
const air = Math.round(state.airflow * 100);
const humidity = Math.round(state.humidity * 100);
ui.airflowValue.textContent = `${air}%`;
ui.humidityValue.textContent = `${humidity}%`;
const airName =
air === 0 ? "Still air" :
air < 30 ? "Gentle air moving left to right" :
air < 70 ? "Brisk air moving left to right" :
"Strong air moving left to right";
const humidityName =
humidity < 20 ? "Dry air with high evaporation capacity" :
humidity < 50 ? "Moderate moisture in the surrounding air" :
humidity < 80 ? "Humid air slows evaporation" :
"Nearly saturated air";
ui.airflowDescription.textContent = airName;
ui.humidityDescription.textContent = humidityName;
}
ui.airflow.addEventListener("input", () => {
state.airflow = Number(ui.airflow.value) / 100;
sliderFill(ui.airflow);
updateControlDescriptions();
});
ui.humidity.addEventListener("input", () => {
state.humidity = Number(ui.humidity.value) / 100;
sliderFill(ui.humidity);
updateControlDescriptions();
});
ui.pauseButton.addEventListener("click", () => {
state.paused = !state.paused;
ui.pauseButton.textContent = state.paused ? "Resume" : "Pause";
});
ui.rewetButton.addEventListener("click", () => {
for (let i = 0; i < wetness.length; i++) {
wetness[i] = 0.9 + random() * 0.08;
updateTopColor(i, random());
}
topVoxels.instanceColor.needsUpdate = true;
});
ui.viewButton.addEventListener("click", resetCamera);
sliderFill(ui.airflow);
sliderFill(ui.humidity);
updateControlDescriptions();
// Direct camera controls: no external control addon.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch - dy * 0.005,
0.34,
1.43
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
22,
58
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.style.cursor = "grab";
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let elapsed = 0;
let colorTimer = 0;
function updateHumidityParticles(dt) {
const positions = humidityGeometry.attributes.position.array;
for (let i = 0; i < humidityCount; i++) {
const p = i * 3;
const data = humidityData[i];
positions[p] += dt * (0.08 + state.airflow * 3.6) * data.speed;
positions[p + 1] += dt * data.drift;
positions[p + 2] +=
Math.sin(elapsed * 0.25 + data.phase) * dt * 0.055;
if (positions[p] > 19) positions[p] = -19;
if (positions[p + 1] > 10.7) positions[p + 1] = 1.45;
if (positions[p + 2] > 11.5) positions[p + 2] = -11.5;
if (positions[p + 2] < -11.5) positions[p + 2] = 11.5;
}
humidityGeometry.attributes.position.needsUpdate = true;
humidityPoints.visible = state.humidity > 0.005;
humidityGeometry.setDrawRange(
0,
Math.max(1, Math.floor(humidityCount * state.humidity))
);
humidityMaterial.opacity = 0.12 + state.humidity * 0.28;
}
function updateVaporParticles(dt) {
const positions = vaporGeometry.attributes.position.array;
const activeCount = Math.floor(vaporCount * state.evaporation);
for (let i = 0; i < vaporCount; i++) {
const p = i * 3;
const data = vaporData[i];
if (i >= activeCount) {
positions[p + 1] = -100;
continue;
}
data.phase =
(data.phase + dt * (0.065 + state.evaporation * 0.21) * data.speed) % 1;
const phase = data.phase;
const driftDistance = phase * (1.1 + state.airflow * 5.4);
positions[p] =
data.sourceX + driftDistance + Math.sin(phase * 7 + data.offset) * 0.08;
positions[p + 1] =
surfaceHeight(data.sourceX, data.sourceZ) +
0.08 +
phase * (1.9 + state.evaporation * 3.2);
positions[p + 2] =
data.sourceZ + Math.sin(phase * 6.3 + data.offset) * 0.2;
}
vaporGeometry.attributes.position.needsUpdate = true;
vaporGeometry.setDrawRange(0, activeCount);
vaporPoints.visible = activeCount > 0;
vaporMaterial.opacity = 0.68 + state.evaporation * 0.28;
}
function updateFlowParticles(dt) {
const positions = trailGeometry.attributes.position.array;
const visible = state.airflow > 0.01;
flowArrows.visible = visible;
flowTrails.visible = visible;
flowMaterial.opacity = 0.08 + state.airflow * 0.67;
trailMaterial.opacity = 0.04 + state.airflow * 0.29;
for (let i = 0; i < flowCount; i++) {
const data = flowData[i];
data.x += dt * (0.05 + state.airflow * 8.2) * data.speed;
if (data.x > 17) data.x = -17;
const y =
data.y +
Math.sin(elapsed * 0.7 + data.phase) * 0.075;
dummy.position.set(data.x, y, data.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
flowArrows.setMatrixAt(i, dummy.matrix);
const p = i * 6;
positions[p] = data.x - 0.86;
positions[p + 1] = y;
positions[p + 2] = data.z;
positions[p + 3] = data.x - 0.13;
positions[p + 4] = y;
positions[p + 5] = data.z;
}
flowArrows.instanceMatrix.needsUpdate = true;
trailGeometry.attributes.position.needsUpdate = true;
directionArrow.setLength(
7 + state.airflow * 19,
0.8 + state.airflow * 0.25,
0.38 + state.airflow * 0.16
);
}
function updateSurface(dt) {
let averageWetness = 0;
for (let i = 0; i < wetness.length; i++) {
averageWetness += wetness[i];
}
averageWetness /= wetness.length;
const saturationDeficit = 1 - state.humidity;
const windFactor = 0.08 + state.airflow * 0.92;
const wetnessFactor = 0.5 + averageWetness * 0.5;
state.evaporation = THREE.MathUtils.clamp(
windFactor * saturationDeficit * wetnessFactor,
0,
1
);
// Ambient humidity slowly re-wets the surface; evaporation dries it.
const equilibriumWetness =
state.humidity * (0.82 + (1 - state.airflow) * 0.18);
const response = 0.012 + state.evaporation * 0.09;
for (let i = 0; i < wetness.length; i++) {
wetness[i] +=
(equilibriumWetness - wetness[i]) * response * dt;
wetness[i] = THREE.MathUtils.clamp(wetness[i], 0, 1);
}
colorTimer += dt;
if (colorTimer >= 0.075) {
colorTimer = 0;
for (let i = 0; i < wetness.length; i++) {
updateTopColor(i, 0.5 + Math.sin(i * 1.71) * 0.2);
}
topVoxels.instanceColor.needsUpdate = true;
}
}
function updateReadouts() {
const rate = Math.round(state.evaporation * 100);
const moisture = Math.round(
(wetness.reduce((sum, value) => sum + value, 0) / wetness.length) * 100
);
ui.rateValue.textContent = `${rate}%`;
ui.rateBar.style.transform = `scaleX(${state.evaporation})`;
ui.wetnessValue.textContent = `${moisture}%`;
let label = "ACTIVE DRYING";
let statusState = "active";
if (state.humidity >= 0.88 && state.evaporation < 0.12) {
label = "SATURATED";
statusState = "still";
} else if (state.evaporation >= 0.58) {
label = "FAST EVAPORATION";
statusState = "fast";
} else if (state.evaporation < 0.09) {
label = "NEARLY STILL";
statusState = "still";
}
ui.status.textContent = label;
ui.status.dataset.state = statusState;
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (!state.paused) {
elapsed += dt;
updateSurface(dt);
updateHumidityParticles(dt);
updateVaporParticles(dt);
updateFlowParticles(dt);
}
updateReadouts();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```