Prompt specification
Build or customize the Three.js 3D scene "Bathroom ventilation teaching room" 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: Bathroom ventilation teaching room
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bathroom-ventilation-teaching-room-x1243
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts relative humidity. Compose a shower area, cool mirror, window, and exhaust vent; illustrate moisture transport and condensation qualitatively, distinguishing vapor from visible mist and surface droplets. Voxel style.
Working Three.js Starter (bathroom-ventilation-teaching-room-x1243):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Relative Humidity — Voxel Bathroom</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf7fb;
--muted: #9eb6c3;
--cyan: #42d9e6;
--mint: #76e4b3;
--blue: #147bb4;
--panel: rgba(11, 26, 38, 0.91);
--line: rgba(168, 215, 230, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b5c6ce;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#app canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(340px, calc(100vw - 36px));
padding: 18px;
color: var(--ink);
background:
linear-gradient(145deg, rgba(25, 49, 63, 0.95), var(--panel)),
var(--panel);
border: 1px solid var(--line);
border-radius: 18px;
box-shadow:
0 22px 60px rgba(15, 30, 40, 0.24),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(66, 217, 230, 0.7);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 29px);
line-height: 1.02;
letter-spacing: -0.04em;
}
.intro {
margin: 10px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.metrics {
display: grid;
grid-template-columns: 1.2fr 1fr 1fr;
gap: 8px;
margin-bottom: 11px;
}
.metric {
min-width: 0;
padding: 10px;
background: rgba(255, 255, 255, 0.045);
border: 1px solid rgba(255, 255, 255, 0.065);
border-radius: 11px;
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: #fff;
font-size: 19px;
font-variant-numeric: tabular-nums;
font-weight: 760;
letter-spacing: -0.04em;
text-overflow: ellipsis;
white-space: nowrap;
}
#rh-value {
color: var(--cyan);
}
.condition {
display: flex;
align-items: center;
gap: 8px;
min-height: 39px;
margin-bottom: 15px;
padding: 9px 11px;
color: #d8edf3;
background: rgba(66, 217, 230, 0.075);
border: 1px solid rgba(66, 217, 230, 0.2);
border-radius: 10px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
}
.condition-dot {
flex: 0 0 auto;
width: 7px;
height: 7px;
background: var(--cyan);
border-radius: 50%;
box-shadow: 0 0 10px currentColor;
}
.control {
margin-top: 13px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 7px;
color: #d7e7ed;
font-size: 11px;
font-weight: 650;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--fill, 50%),
rgba(255, 255, 255, 0.13) var(--fill, 50%),
rgba(255, 255, 255, 0.13) 100%
);
border-radius: 999px;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
background: #eafcff;
border: 3px solid #26c4d3;
border-radius: 3px;
box-shadow: 0 0 0 4px rgba(66, 217, 230, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
background: #eafcff;
border: 3px solid #26c4d3;
border-radius: 3px;
box-shadow: 0 0 0 4px rgba(66, 217, 230, 0.12);
}
.divider {
height: 1px;
margin: 16px 0 12px;
background: var(--line);
}
.toggles {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.toggle {
position: relative;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle span {
display: block;
padding: 7px 5px;
color: var(--muted);
background: rgba(255, 255, 255, 0.035);
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 8px;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.035em;
text-align: center;
cursor: pointer;
transition: 160ms ease;
}
.toggle input:checked + span {
color: #06151e;
background: var(--cyan);
border-color: var(--cyan);
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 13px;
}
button {
padding: 9px 8px;
color: #d8ecf2;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
color: #fff;
background: rgba(66, 217, 230, 0.13);
border-color: rgba(66, 217, 230, 0.4);
}
.note {
margin: 13px 0 0;
padding-left: 10px;
color: #8faab7;
border-left: 2px solid rgba(66, 217, 230, 0.45);
font-size: 10px;
line-height: 1.48;
}
.legend {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
display: grid;
gap: 8px;
width: min(285px, calc(100vw - 36px));
padding: 14px;
color: var(--ink);
background: rgba(11, 26, 38, 0.87);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 16px 45px rgba(16, 31, 41, 0.2);
backdrop-filter: blur(15px);
pointer-events: none;
}
.legend-title {
margin-bottom: 1px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-item {
display: grid;
grid-template-columns: 27px 1fr;
align-items: center;
gap: 9px;
font-size: 10px;
line-height: 1.25;
}
.legend-item strong {
display: block;
margin-bottom: 1px;
color: #eefbff;
font-size: 10px;
}
.legend-item small {
color: #8faab7;
font-size: 9px;
}
.swatch {
position: relative;
width: 27px;
height: 20px;
}
.swatch.vapor::before {
position: absolute;
top: 9px;
right: 0;
left: 0;
content: "";
border-top: 2px dashed var(--cyan);
}
.swatch.vapor::after {
position: absolute;
top: 6px;
left: 4px;
width: 5px;
height: 5px;
content: "";
background: var(--cyan);
border-radius: 1px;
box-shadow: 9px 0 var(--cyan), 18px 0 var(--cyan);
}
.swatch.mist {
background:
linear-gradient(90deg, transparent 0 8%, #e7fbff 8% 24%, transparent 24% 34%,
#e7fbff 34% 53%, transparent 53% 64%, #e7fbff 64% 82%, transparent 82%);
opacity: 0.9;
}
.swatch.droplet::before,
.swatch.droplet::after {
position: absolute;
width: 6px;
height: 8px;
content: "";
background: #1584bd;
border-radius: 1px;
box-shadow: 0 0 6px rgba(21, 132, 189, 0.45);
}
.swatch.droplet::before {
top: 3px;
left: 5px;
}
.swatch.droplet::after {
top: 9px;
left: 15px;
height: 6px;
}
.swatch.airflow::before {
position: absolute;
top: 9px;
right: 1px;
left: 1px;
content: "";
border-top: 2px dashed var(--mint);
}
.hint {
position: fixed;
z-index: 8;
right: 18px;
top: 18px;
padding: 8px 11px;
color: rgba(18, 48, 61, 0.72);
background: rgba(238, 248, 251, 0.63);
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 9px;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(8px);
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 7px;
color: #163746;
background: rgba(239, 250, 253, 0.82);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 6px;
box-shadow: 0 5px 18px rgba(21, 44, 55, 0.13);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
transform: translate(-50%, -50%);
backdrop-filter: blur(7px);
}
.scene-label::before {
width: 5px;
height: 5px;
content: "";
background: #19b8ca;
border-radius: 1px;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: #153949;
background: #b5c6ce;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#loading.hidden {
display: none;
}
@media (max-width: 760px) {
.panel {
top: 10px;
left: 10px;
width: min(310px, calc(100vw - 20px));
padding: 14px;
}
.intro,
.note,
.legend,
.hint,
.scene-label {
display: none;
}
.metrics {
margin-bottom: 8px;
}
.condition {
margin-bottom: 10px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels"></div>
<aside class="panel">
<div class="eyebrow">Relative humidity / voxel study</div>
<h1>Vapor, mist &<br>condensation</h1>
<p class="intro">
Adjust humidity and cool-surface temperature. The shower supplies moisture;
cool glass collects liquid while the vent removes humid air.
</p>
<div class="metrics">
<div class="metric">
<span class="metric-label">Relative humidity</span>
<span class="metric-value" id="rh-value">78%</span>
</div>
<div class="metric">
<span class="metric-label">Dew point</span>
<span class="metric-value" id="dew-value">19.9°</span>
</div>
<div class="metric">
<span class="metric-label">Surface</span>
<span class="metric-value" id="surface-value">17°</span>
</div>
</div>
<div class="condition">
<span class="condition-dot"></span>
<span id="condition-text">ACTIVE CONDENSATION</span>
</div>
<div class="control">
<div class="control-row">
<label for="humidity">Room relative humidity</label>
<output id="humidity-output" for="humidity">78%</output>
</div>
<input id="humidity" type="range" min="35" max="100" value="78">
</div>
<div class="control">
<div class="control-row">
<label for="surface">Cool mirror / window</label>
<output id="surface-output" for="surface">17°C</output>
</div>
<input id="surface" type="range" min="10" max="26" value="17">
</div>
<div class="divider"></div>
<div class="toggles">
<label class="toggle">
<input id="toggle-vapor" type="checkbox" checked>
<span>Vapor paths</span>
</label>
<label class="toggle">
<input id="toggle-mist" type="checkbox" checked>
<span>Visible mist</span>
</label>
<label class="toggle">
<input id="toggle-droplets" type="checkbox" checked>
<span>Droplets</span>
</label>
</div>
<div class="buttons">
<button id="pause" type="button">Pause motion</button>
<button id="reset" type="button">Reset camera</button>
</div>
<p class="note">
Water vapor itself is invisible. Cyan dotted routes are schematic transport
annotations; white clouds represent suspended liquid droplets, and dark
blue blocks represent condensed surface water.
</p>
</aside>
<section class="legend" aria-label="Visualization legend">
<div class="legend-title">Reading the scene</div>
<div class="legend-item">
<span class="swatch vapor"></span>
<span>
<strong>Water-vapor transport</strong>
<small>Invisible gas; dotted route is an annotation.</small>
</span>
</div>
<div class="legend-item">
<span class="swatch mist"></span>
<span>
<strong>Visible mist</strong>
<small>Airborne liquid droplets near the shower.</small>
</span>
</div>
<div class="legend-item">
<span class="swatch droplet"></span>
<span>
<strong>Surface condensation</strong>
<small>Liquid droplets on cool mirror and window.</small>
</span>
</div>
<div class="legend-item">
<span class="swatch airflow"></span>
<span>
<strong>Exhaust airflow</strong>
<small>Humid air is drawn toward the vent.</small>
</span>
</div>
</section>
<div class="hint">Drag to orbit · wheel to zoom · space to pause</div>
<div id="loading">Building voxel room…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const app = document.querySelector("#app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb5c6ce);
scene.fog = new THREE.Fog(0xb5c6ce, 22, 40);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const orbit = {
theta: 0.62,
phi: 1.02,
zoom: 1
};
const cameraTarget = new THREE.Vector3(-0.3, 2.8, -1.2);
const cameraRadius = 17;
scene.add(new THREE.HemisphereLight(0xe9f8ff, 0x71808a, 2.0));
const sun = new THREE.DirectionalLight(0xfff3d8, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0005;
scene.add(sun);
const windowLight = new THREE.PointLight(0x7ddff3, 12, 10, 2);
windowLight.position.set(3.4, 3.4, -2.8);
scene.add(windowLight);
// -------------------------------------------------------------------------
// Shared voxel geometry and materials
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = {
grout: new THREE.MeshStandardMaterial({
color: 0x71838c,
roughness: 0.95
}),
wall: new THREE.MeshStandardMaterial({
color: 0x8499a3,
roughness: 0.9
}),
floorA: new THREE.MeshStandardMaterial({
color: 0xbecbd0,
roughness: 0.84
}),
floorB: new THREE.MeshStandardMaterial({
color: 0xaebfc6,
roughness: 0.87
}),
tileA: new THREE.MeshStandardMaterial({
color: 0xd4dfe1,
roughness: 0.78
}),
tileB: new THREE.MeshStandardMaterial({
color: 0xc4d3d7,
roughness: 0.82
}),
tileC: new THREE.MeshStandardMaterial({
color: 0xbdcdd2,
roughness: 0.82
}),
dark: new THREE.MeshStandardMaterial({
color: 0x243b47,
roughness: 0.65,
metalness: 0.15
}),
steel: new THREE.MeshStandardMaterial({
color: 0x91aab3,
roughness: 0.25,
metalness: 0.72
}),
shower: new THREE.MeshStandardMaterial({
color: 0xe7f1f2,
roughness: 0.25,
metalness: 0.1
}),
glass: new THREE.MeshStandardMaterial({
color: 0xb9e6ef,
transparent: true,
opacity: 0.12,
depthWrite: false,
roughness: 0.08
}),
mist: new THREE.MeshStandardMaterial({
color: 0xe6fbff,
emissive: 0x8bd9e5,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.25,
depthWrite: false,
roughness: 1
}),
drop: new THREE.MeshStandardMaterial({
color: 0x0878b4,
emissive: 0x063d65,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.88,
roughness: 0.16,
metalness: 0.08
})
};
function makeBox(parent, size, position, mat, options = {}) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
let seed = 72491;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function randomBetween(min, max) {
return min + (max - min) * random();
}
// -------------------------------------------------------------------------
// Voxel bathroom shell
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
// Floor foundation.
makeBox(room, [11.4, 0.28, 8.4], [0, -0.16, 0], material.grout);
// Floor tiles.
for (let x = 0; x < 15; x++) {
for (let z = 0; z < 11; z++) {
const variant = (x + z * 2) % 5;
const tileMaterial =
variant === 0
? material.floorB
: variant === 1
? material.tileC
: material.floorA;
makeBox(
room,
[0.70, 0.065, 0.70],
[-5.13 + x * 0.735, 0.015, -3.66 + z * 0.735],
tileMaterial,
{ castShadow: false }
);
}
}
// Back wall and tiled face.
makeBox(room, [11.4, 7.25, 0.38], [0, 3.48, -4.23], material.wall);
for (let x = 0; x < 15; x++) {
for (let y = 0; y < 10; y++) {
const variant = (x * 3 + y) % 7;
const tileMaterial =
variant === 0
? material.tileC
: variant === 1
? material.tileB
: material.tileA;
makeBox(
room,
[0.705, 0.66, 0.09],
[-5.13 + x * 0.735, 0.37 + y * 0.69, -4.00],
tileMaterial,
{ castShadow: false }
);
}
}
// Left return wall.
makeBox(room, [0.28, 7.25, 8.4], [-5.58, 3.48, -0.12], material.wall);
makeBox(room, [0.08, 0.18, 8.2], [-5.39, 0.10, -0.12], material.grout);
// -------------------------------------------------------------------------
// Shower area
// -------------------------------------------------------------------------
const showerGroup = new THREE.Group();
scene.add(showerGroup);
makeBox(
showerGroup,
[3.65, 0.34, 4.25],
[-3.55, 0.18, -1.90],
material.shower
);
makeBox(
showerGroup,
[3.32, 0.10, 3.92],
[-3.55, 0.39, -1.90],
material.floorB
);
makeBox(
showerGroup,
[0.065, 3.85, 3.92],
[-1.76, 2.23, -1.90],
material.glass,
{ castShadow: false }
);
makeBox(
showerGroup,
[0.12, 4.05, 0.12],
[-1.76, 2.28, -3.84],
material.steel
);
// Riser pipe and square shower head.
makeBox(
showerGroup,
[0.16, 3.50, 0.16],
[-4.62, 2.36, -3.40],
material.steel
);
makeBox(
showerGroup,
[1.35, 0.16, 0.16],
[-4.05, 4.03, -3.40],
material.steel
);
makeBox(
showerGroup,
[0.88, 0.16, 0.78],
[-3.44, 4.18, -3.23],
material.steel
);
for (let x = 0; x < 4; x++) {
for (let z = 0; z < 3; z++) {
makeBox(
showerGroup,
[0.09, 0.07, 0.09],
[-3.72 + x * 0.19, 4.075, -3.43 + z * 0.20],
material.dark
);
}
}
// Mixer controls.
makeBox(
showerGroup,
[0.52, 0.24, 0.20],
[-4.62, 1.55, -3.30],
material.dark
);
// Shower drain.
makeBox(
showerGroup,
[0.52, 0.025, 0.52],
[-3.55, 0.46, -1.35],
material.steel
);
for (let i = 0; i < 4; i++) {
makeBox(
showerGroup,
[0.42, 0.035, 0.045],
[-3.55, 0.48, -1.50 + i * 0.10],
material.dark
);
}
// -------------------------------------------------------------------------
// Cool mirror
// -------------------------------------------------------------------------
const mirrorGlassMaterial = new THREE.MeshStandardMaterial({
color: 0x86b2c0,
emissive: 0x123e50,
emissiveIntensity: 0.18,
roughness: 0.18,
metalness: 0.72
});
const mirrorFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x536d78,
emissive: 0x0a5366,
emissiveIntensity: 0.05,
roughness: 0.28,
metalness: 0.65
});
const mirrorGroup = new THREE.Group();
scene.add(mirrorGroup);
makeBox(
mirrorGroup,
[2.75, 3.02, 0.17],
[0.05, 3.13, -3.80],
mirrorFrameMaterial
);
makeBox(
mirrorGroup,
[2.43, 2.70, 0.075],
[0.05, 3.13, -3.60],
mirrorGlassMaterial
);
makeBox(
mirrorGroup,
[2.58, 0.10, 0.10],
[0.05, 4.54, -3.50],
mirrorFrameMaterial
);
makeBox(
mirrorGroup,
[2.58, 0.10, 0.10],
[0.05, 1.72, -3.50],
mirrorFrameMaterial
);
makeBox(
mirrorGroup,
[0.10, 2.82, 0.10],
[-1.18, 3.13, -3.50],
mirrorFrameMaterial
);
makeBox(
mirrorGroup,
[0.10, 2.82, 0.10],
[1.28, 3.13, -3.50],
mirrorFrameMaterial
);
// Stylized reflected light streaks.
const reflectionMaterial = new THREE.MeshBasicMaterial({
color: 0xe6fbff,
transparent: true,
opacity: 0.22,
depthWrite: false
});
makeBox(
mirrorGroup,
[0.12, 1.48, 0.025],
[-0.57, 3.32, -3.545],
reflectionMaterial,
{ rotation: [0, 0, -0.66], castShadow: false }
);
makeBox(
mirrorGroup,
[0.08, 0.82, 0.025],
[-0.30, 3.14, -3.54],
reflectionMaterial,
{ rotation: [0, 0, -0.66], castShadow: false }
);
// -------------------------------------------------------------------------
// Window
// -------------------------------------------------------------------------
const windowPaneMaterial = new THREE.MeshStandardMaterial({
color: 0x5da9c3,
emissive: 0x2b7997,
emissiveIntensity: 0.38,
roughness: 0.24,
metalness: 0.05
});
const windowFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x405965,
emissive: 0x0a4255,
emissiveIntensity: 0.04,
roughness: 0.4,
metalness: 0.38
});
const windowGroup = new THREE.Group();
scene.add(windowGroup);
makeBox(
windowGroup,
[2.68, 2.90, 0.18],
[3.45, 3.18, -3.80],
windowFrameMaterial
);
makeBox(
windowGroup,
[2.40, 2.63, 0.08],
[3.45, 3.18, -3.61],
windowPaneMaterial
);
makeBox(
windowGroup,
[0.09, 2.68, 0.10],
[3.45, 3.18, -3.49],
windowFrameMaterial
);
makeBox(
windowGroup,
[2.44, 0.09, 0.10],
[3.45, 3.18, -3.49],
windowFrameMaterial
);
// Voxel sky/cloud blocks visible through the window.
const cloudMaterial = new THREE.MeshBasicMaterial({
color: 0xdaf5fa,
transparent: true,
opacity: 0.68
});
makeBox(
windowGroup,
[0.58, 0.20, 0.04],
[3.91, 4.03, -3.54],
cloudMaterial,
{ castShadow: false }
);
makeBox(
windowGroup,
[0.30, 0.30, 0.04],
[3.58, 4.00, -3.53],
cloudMaterial,
{ castShadow: false }
);
// Window sill and puddle.
makeBox(
windowGroup,
[2.88, 0.16, 0.48],
[3.45, 1.67, -3.58],
material.shower
);
const puddleMaterial = new THREE.MeshStandardMaterial({
color: 0x117eb5,
transparent: true,
opacity: 0.7,
roughness: 0.12,
depthWrite: false
});
const puddle = makeBox(
windowGroup,
[1.0, 0.025, 0.22],
[3.45, 1.77, -3.43],
puddleMaterial,
{ castShadow: false }
);
puddle.visible = false;
// -------------------------------------------------------------------------
// Exhaust vent
// -------------------------------------------------------------------------
const ventGroup = new THREE.Group();
scene.add(ventGroup);
makeBox(
ventGroup,
[1.72, 0.88, 0.20],
[2.85, 5.82, -3.76],
material.steel
);
makeBox(
ventGroup,
[1.44, 0.64, 0.08],
[2.85, 5.82, -3.61],
material.dark
);
const fan = new THREE.Group();
fan.position.set(2.85, 5.82, -3.53);
ventGroup.add(fan);
makeBox(
fan,
[0.14, 0.52, 0.055],
[0, 0, 0],
material.steel
);
makeBox(
fan,
[0.52, 0.14, 0.055],
[0, 0, 0],
material.steel
);
makeBox(
fan,
[0.12, 0.12, 0.10],
[0, 0, 0.02],
material.dark
);
for (let i = 0; i < 5; i++) {
makeBox(
ventGroup,
[1.34, 0.065, 0.10],
[2.85, 5.58 + i * 0.12, -3.43],
material.steel
);
}
// -------------------------------------------------------------------------
// Schematic vapor transport paths
// -------------------------------------------------------------------------
const vaporGroup = new THREE.Group();
scene.add(vaporGroup);
const airflowGroup = new THREE.Group();
scene.add(airflowGroup);
const routes = [];
function createRoute(parent, points, color, count, speed, tag) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.35
);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(90)
);
const lineMaterial = new THREE.LineDashedMaterial({
color,
dashSize: 0.16,
gapSize: 0.13,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const line = new THREE.Line(geometry, lineMaterial);
line.computeLineDistances();
parent.add(line);
const markerMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.94,
depthWrite: false
});
const markers = [];
for (let i = 0; i < count; i++) {
const marker = new THREE.Mesh(unitBox, markerMaterial);
const size = tag === "airflow" ? 0.075 : 0.065;
marker.scale.setScalar(size);
marker.userData.offset = i / count;
parent.add(marker);
markers.push(marker);
}
routes.push({ curve, markers, speed, tag });
}
createRoute(
vaporGroup,
[
[-3.40, 4.02, -2.95],
[-2.45, 3.85, -2.72],
[-1.50, 3.45, -2.85],
[-0.70, 3.18, -3.10]
],
0x31d7e5,
8,
0.095,
"vapor"
);
createRoute(
vaporGroup,
[
[-3.35, 4.18, -2.90],
[-1.75, 4.70, -2.50],
[0.70, 4.75, -2.60],
[2.85, 4.20, -3.12]
],
0x31d7e5,
9,
0.082,
"vapor"
);
createRoute(
vaporGroup,
[
[-3.30, 4.32, -2.85],
[-1.85, 5.02, -2.36],
[0.25, 5.55, -2.55],
[2.70, 5.80, -3.25]
],
0x31d7e5,
9,
0.075,
"vapor"
);
createRoute(
airflowGroup,
[
[-0.35, 4.55, -1.35],
[0.55, 5.05, -1.75],
[1.65, 5.55, -2.48],
[2.85, 5.80, -3.30]
],
0x76e4b3,
6,
0.14,
"airflow"
);
// -------------------------------------------------------------------------
// Visible airborne mist: liquid droplets, not invisible vapor
// -------------------------------------------------------------------------
const mistGroup = new THREE.Group();
scene.add(mistGroup);
const mistParticles = [];
for (let i = 0; i < 44; i++) {
const mesh = new THREE.Mesh(unitBox, material.mist);
mesh.castShadow = false;
mesh.receiveShadow = false;
const data = {
mesh,
phase: random(),
speed: randomBetween(0.7, 1.25),
size: randomBetween(0.12, 0.34),
x: randomBetween(-4.05, -3.05),
z: randomBetween(-3.45, -2.35),
wobble: randomBetween(0.4, 1.2)
};
mistParticles.push(data);
mistGroup.add(mesh);
}
// -------------------------------------------------------------------------
// Surface condensation droplets
// -------------------------------------------------------------------------
const surfaceDrops = [];
const rivulets = [];
function createSurfaceDrops(count, bounds, parent = scene) {
for (let i = 0; i < count; i++) {
const size = randomBetween(0.045, 0.115);
const mesh = makeBox(
parent,
[size, size * randomBetween(1.05, 1.65), 0.055],
[
randomBetween(bounds.xMin, bounds.xMax),
randomBetween(bounds.yMin, bounds.yMax),
bounds.z
],
material.drop,
{ castShadow: false }
);
mesh.visible = false;
surfaceDrops.push({
mesh,
threshold: random()
});
}
}
createSurfaceDrops(62, {
xMin: -1.05,
xMax: 1.13,
yMin: 1.86,
yMax: 4.38,
z: -3.47
});
createSurfaceDrops(52, {
xMin: 2.36,
xMax: 4.54,
yMin: 1.97,
yMax: 4.36,
z: -3.45
});
function createRivulets(count, bounds, parent = scene) {
for (let i = 0; i < count; i++) {
const x = randomBetween(bounds.xMin, bounds.xMax);
const y = randomBetween(bounds.yMin, bounds.yMax);
const length = randomBetween(0.22, 0.55);
const mesh = makeBox(
parent,
[0.045, length, 0.045],
[x, y, bounds.z],
material.drop,
{ castShadow: false }
);
mesh.visible = false;
rivulets.push({
mesh,
baseY: y,
phase: random(),
threshold: randomBetween(0.42, 0.88)
});
}
}
createRivulets(12, {
xMin: -0.95,
xMax: 1.05,
yMin: 1.90,
yMax: 2.55,
z: -3.455
});
createRivulets(10, {
xMin: 2.40,
xMax: 4.48,
yMin: 1.98,
yMax: 2.45,
z: -3.435
});
// -------------------------------------------------------------------------
// Labels projected from 3D anchor points
// -------------------------------------------------------------------------
const labelDefinitions = [
{
text: "01 · Shower source",
position: new THREE.Vector3(-3.50, 4.82, -3.20)
},
{
text: "02 · Cool mirror",
position: new THREE.Vector3(0.05, 4.86, -3.38)
},
{
text: "03 · Cold window",
position: new THREE.Vector3(3.45, 4.88, -3.38)
},
{
text: "04 · Exhaust vent",
position: new THREE.Vector3(2.85, 6.43, -3.38)
}
];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = "scene-label";
element.textContent = definition.text;
document.querySelector("#labels").appendChild(element);
definition.element = element;
}
// -------------------------------------------------------------------------
// Humidity model
// -------------------------------------------------------------------------
const AMBIENT_TEMPERATURE = 24;
const state = {
humidity: 78,
surfaceTemperature: 17,
condensation: 0,
playing: true,
showVapor: true,
showMist: true,
showDroplets: true
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function calculateDewPoint(temperature, relativeHumidity) {
// Magnus-Tetens approximation.
const a = 17.62;
const b = 243.12;
const gamma =
Math.log(relativeHumidity / 100) +
(a * temperature) / (b + temperature);
return (b * gamma) / (a - gamma);
}
const humidityInput = document.querySelector("#humidity");
const surfaceInput = document.querySelector("#surface");
const humidityOutput = document.querySelector("#humidity-output");
const surfaceOutput = document.querySelector("#surface-output");
const rhValue = document.querySelector("#rh-value");
const dewValue = document.querySelector("#dew-value");
const surfaceValue = document.querySelector("#surface-value");
const conditionText = document.querySelector("#condition-text");
function updateSliderFill(input) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateModel() {
state.humidity = Number(humidityInput.value);
state.surfaceTemperature = Number(surfaceInput.value);
const dewPoint = calculateDewPoint(
AMBIENT_TEMPERATURE,
state.humidity
);
const dewPointMargin = dewPoint - state.surfaceTemperature;
// Qualitative coverage: no condensation above dew point, then progressively
// stronger coverage as the cool surface falls farther below dew point.
state.condensation = clamp(
(dewPointMargin + 0.12) / 5.0,
0,
1
);
humidityOutput.value = `${state.humidity}%`;
surfaceOutput.value = `${state.surfaceTemperature}°C`;
rhValue.textContent = `${state.humidity}%`;
dewValue.textContent = `${dewPoint.toFixed(1)}°`;
surfaceValue.textContent = `${state.surfaceTemperature}°`;
updateSliderFill(humidityInput);
updateSliderFill(surfaceInput);
if (dewPointMargin <= 0.12) {
conditionText.textContent = "NO SURFACE CONDENSATION";
} else if (state.condensation < 0.30) {
conditionText.textContent = "LIGHT CONDENSATION";
} else if (state.condensation < 0.68) {
conditionText.textContent = "ACTIVE CONDENSATION";
} else {
conditionText.textContent = "HEAVY CONDENSATION";
}
for (const drop of surfaceDrops) {
drop.mesh.visible =
state.showDroplets && drop.threshold <= state.condensation;
}
for (const rivulet of rivulets) {
rivulet.mesh.visible =
state.showDroplets &&
state.condensation >= rivulet.threshold;
}
puddle.visible = state.showDroplets && state.condensation > 0.68;
puddle.scale.x = 0.45 + state.condensation * 1.35;
puddle.scale.z = 0.45 + state.condensation * 0.75;
vaporGroup.visible = state.showVapor;
mistGroup.visible = state.showMist;
const wetMirrorColor = new THREE.Color(0x86b2c0).lerp(
new THREE.Color(0x4aa9c2),
state.condensation * 0.72
);
mirrorGlassMaterial.color.copy(wetMirrorColor);
mirrorGlassMaterial.emissiveIntensity = 0.16 + state.condensation * 0.30;
mirrorFrameMaterial.emissiveIntensity = 0.03 + state.condensation * 0.28;
const wetWindowColor = new THREE.Color(0x5da9c3).lerp(
new THREE.Color(0x398eb1),
state.condensation * 0.72
);
windowPaneMaterial.color.copy(wetWindowColor);
windowPaneMaterial.emissiveIntensity = 0.30 + state.condensation * 0.32;
windowFrameMaterial.emissiveIntensity = 0.03 + state.condensation * 0.25;
material.mist.opacity = 0.14 + (state.humidity / 100) * 0.16;
}
humidityInput.addEventListener("input", updateModel);
surfaceInput.addEventListener("input", updateModel);
document.querySelector("#toggle-vapor").addEventListener("change", (event) => {
state.showVapor = event.target.checked;
vaporGroup.visible = state.showVapor;
});
document.querySelector("#toggle-mist").addEventListener("change", (event) => {
state.showMist = event.target.checked;
mistGroup.visible = state.showMist;
});
document.querySelector("#toggle-droplets").addEventListener("change", (event) => {
state.showDroplets = event.target.checked;
updateModel();
});
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
state.playing = !state.playing;
pauseButton.textContent = state.playing ? "Pause motion" : "Resume motion";
});
function resetCamera() {
orbit.theta = 0.62;
orbit.phi = 1.02;
orbit.zoom = 1;
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Direct camera controls — no addons or examples modules
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= deltaX * 0.005;
orbit.phi = clamp(orbit.phi + deltaY * 0.004, 0.55, 1.42);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.65
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x +
cameraRadius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + cameraRadius * Math.cos(orbit.phi),
cameraTarget.z +
cameraRadius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Keep the full room visible on narrow screens.
const viewHeight = Math.max(12.2, 13.2 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let firstFrame = true;
function updateMist() {
const visibleCount = Math.floor(20 + state.humidity * 0.235);
mistParticles.forEach((particle, index) => {
const visible = index < visibleCount;
particle.mesh.visible = visible;
if (!visible) return;
const travel =
(elapsed * (0.13 + particle.speed * 0.055) + particle.phase) % 1;
const spread = travel * travel;
particle.mesh.position.set(
particle.x +
spread * 0.85 +
Math.sin(elapsed * 2.2 + particle.phase * 9) * 0.08 *
particle.wobble,
4.04 - travel * 3.55,
particle.z +
(travel - 0.5) * 0.58 +
Math.cos(elapsed * 1.8 + particle.phase * 7) * 0.06
);
const size =
particle.size *
(0.62 + travel * 0.88) *
(0.88 + state.humidity / 360);
particle.mesh.scale.set(size, size, size);
particle.mesh.rotation.set(
elapsed * 0.12 + particle.phase,
elapsed * 0.16,
particle.phase * 3
);
});
}
function updateRoutes() {
const humiditySpeed = 0.75 + state.humidity / 100 * 0.45;
for (const route of routes) {
route.markers.forEach((marker) => {
const travel =
(elapsed * route.speed * humiditySpeed + marker.userData.offset) %
1;
route.curve.getPointAt(travel, marker.position);
marker.rotation.set(0, elapsed * 1.2, elapsed * 0.8);
});
}
}
function updateRivulets() {
for (const rivulet of rivulets) {
if (!rivulet.mesh.visible) continue;
const pulse =
Math.sin(elapsed * 2.0 + rivulet.phase * Math.PI * 2) * 0.035;
rivulet.mesh.position.y = rivulet.baseY + pulse;
}
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelDefinitions) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1;
label.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
elapsed += delta;
fan.rotation.z -= delta * (1.25 + state.humidity * 0.011);
}
updateCamera();
updateMist();
updateRoutes();
updateRivulets();
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hidden");
}
}
updateModel();
resize();
updateCamera();
animate();
</script>
</body>
</html>
```