Prompt specification
Build or customize the Three.js 3D scene "Ice water and vapor concept gallery" 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: Ice water and vapor concept gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ice-water-and-vapor-concept-gallery-x1967
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a voxel gallery of water in different states. Set an ice block, a liquid-water vessel, and a vapor example on three neighboring stands. Beside each, place a separate enlarged particle inset using the same H2O symbol but different arrangements and motion. Keep the macroscopic objects distinct from these symbolic molecular views. If visible white mist appears above the liquid, identify it as suspended droplets rather than visible individual vapor molecules. A shared legend should show that the chemical species stays the same across the examples, while the organization, spacing, and movement in the particle models change.
Working Three.js Starter (ice-water-and-vapor-concept-gallery-x1967):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#07131b">
<title>Phase / Field — A Voxel Gallery of Water</title>
<style>
:root {
color-scheme: dark;
--ink: #edfaff;
--muted: #91a8b4;
--panel: rgba(7, 19, 28, 0.86);
--line: rgba(159, 225, 244, 0.18);
--solid: #91e9ff;
--liquid: #35d4ff;
--gas: #b39cff;
}
* {
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(--ink);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
ellipse at 50% 44%,
transparent 38%,
rgba(1, 8, 13, 0.24) 76%,
rgba(1, 7, 11, 0.64) 100%
);
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 26px 30px 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
z-index: 5;
}
.brand {
max-width: 580px;
}
.kicker {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
color: #89c9d8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.23em;
text-transform: uppercase;
}
.kicker::before {
width: 28px;
height: 2px;
content: "";
background: linear-gradient(90deg, var(--solid), var(--gas));
box-shadow: 0 0 12px rgba(73, 207, 255, 0.5);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
font-weight: 670;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 530px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls-hint {
margin-top: 7px;
color: #64808e;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.science-note {
position: fixed;
z-index: 6;
top: 28px;
right: 28px;
width: min(350px, calc(100vw - 40px));
padding: 14px 16px 14px 44px;
border: 1px solid rgba(151, 224, 241, 0.18);
border-radius: 14px;
background: rgba(6, 18, 27, 0.82);
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(14px);
pointer-events: none;
}
.science-note::before {
position: absolute;
top: 17px;
left: 17px;
width: 12px;
height: 12px;
content: "";
border-radius: 50%;
background: #efffff;
box-shadow:
0 0 0 5px rgba(222, 250, 255, 0.08),
0 0 16px rgba(224, 249, 255, 0.62);
}
.science-note strong {
display: block;
margin-bottom: 4px;
color: #e9fbff;
font-size: 11px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.science-note p {
margin: 0;
color: #9db2bd;
font-size: 11px;
line-height: 1.55;
}
.science-note b {
color: #efffff;
font-weight: 680;
}
.legend {
position: fixed;
z-index: 8;
left: 50%;
bottom: 20px;
width: min(1100px, calc(100vw - 34px));
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(6, 17, 25, 0.88);
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.34),
inset 0 1px 0 rgba(255, 255, 255, 0.025);
backdrop-filter: blur(16px);
}
.legend-inner {
min-height: 78px;
padding: 11px 12px 11px 16px;
display: flex;
align-items: center;
gap: 16px;
}
.species {
min-width: 250px;
display: flex;
align-items: center;
gap: 13px;
}
.formula {
position: relative;
width: 64px;
height: 38px;
display: grid;
place-items: center;
flex: 0 0 auto;
}
.formula .atom {
position: absolute;
display: grid;
place-items: center;
border-radius: 50%;
font-size: 10px;
font-weight: 800;
}
.formula .o {
left: 19px;
width: 28px;
height: 28px;
color: #fff;
background: #df4e51;
box-shadow: 0 0 18px rgba(223, 78, 81, 0.26);
}
.formula .h {
top: 8px;
width: 22px;
height: 22px;
color: #17303b;
background: #eafaff;
}
.formula .h1 {
left: 0;
}
.formula .h2 {
right: 0;
}
.formula .bond {
position: absolute;
top: 17px;
width: 54px;
height: 3px;
border-radius: 2px;
background: linear-gradient(
90deg,
#eafaff 0 35%,
#df4e51 35% 65%,
#eafaff 65% 100%
);
transform: rotate(-8deg);
}
.species strong {
display: block;
font-size: 18px;
letter-spacing: -0.025em;
}
.species small {
display: block;
margin-top: 2px;
color: #78929e;
font-size: 10px;
line-height: 1.35;
}
.divider {
align-self: stretch;
width: 1px;
background: var(--line);
}
.phase-controls {
min-width: 0;
flex: 1;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.phase {
position: relative;
min-height: 50px;
padding: 9px 12px 8px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 11px;
color: inherit;
background: rgba(255, 255, 255, 0.025);
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.phase::before {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 2px;
content: "";
background: var(--phase-color);
box-shadow: 0 0 13px color-mix(in srgb, var(--phase-color), transparent 35%);
}
.phase:hover,
.phase.active {
border-color: color-mix(in srgb, var(--phase-color), transparent 58%);
background: color-mix(in srgb, var(--phase-color), transparent 91%);
}
.phase:active {
transform: translateY(1px);
}
.phase b {
display: block;
color: var(--phase-color);
font-size: 10px;
letter-spacing: 0.13em;
}
.phase span {
display: block;
margin-top: 4px;
color: #91a7b2;
font-size: 10px;
line-height: 1.35;
}
.overview {
width: 42px;
height: 42px;
flex: 0 0 auto;
border: 1px solid var(--line);
border-radius: 12px;
color: #bcd0d8;
background: rgba(255, 255, 255, 0.035);
font-size: 20px;
cursor: pointer;
transition:
color 160ms ease,
border-color 160ms ease,
transform 300ms ease;
}
.overview:hover {
color: #fff;
border-color: rgba(159, 225, 244, 0.45);
}
.overview.spinning {
transform: rotate(180deg);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #8eb8c6;
background: #07131b;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 880px) {
.header {
padding: 20px 20px 0;
}
.science-note {
top: 116px;
right: 18px;
}
.species {
min-width: 205px;
}
.phase {
padding-inline: 9px;
}
}
@media (max-width: 680px) {
h1 {
font-size: 31px;
}
.subtitle {
max-width: 360px;
font-size: 11px;
}
.science-note {
top: 112px;
left: 18px;
right: 18px;
width: auto;
}
.legend {
bottom: 10px;
width: calc(100vw - 20px);
}
.legend-inner {
flex-wrap: wrap;
padding: 10px;
gap: 9px;
}
.species {
min-width: 0;
flex: 1;
}
.species small {
max-width: 145px;
}
.divider {
display: none;
}
.phase-controls {
order: 3;
width: 100%;
flex-basis: 100%;
}
.phase {
min-height: 46px;
padding: 8px;
}
.phase b {
font-size: 9px;
}
.phase span {
font-size: 9px;
}
.overview {
width: 39px;
height: 39px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel gallery showing solid, liquid, and gaseous water"></canvas>
<div class="vignette"></div>
<header class="header">
<div class="brand">
<div class="kicker">Interactive matter gallery · Exhibit 01</div>
<h1>Phase / Field</h1>
<p class="subtitle">
Three neighboring water exhibits. The gallery-scale objects change state;
the adjacent enlarged insets reveal how the same H₂O molecules are
organized, spaced, and moving.
</p>
<div class="controls-hint">Drag to orbit · Scroll to zoom · Select a phase</div>
</div>
</header>
<aside class="science-note">
<strong>Scale & mist note</strong>
<p>
The white mist above the liquid is
<b>suspended droplets</b>, not visible individual H₂O molecules.
The vapor exhibit uses a schematic blue phase field; its symbolic
molecular view is in the separate inset.
</p>
</aside>
<section class="legend" aria-label="Shared molecular legend">
<div class="legend-inner">
<div class="species">
<div class="formula" aria-hidden="true">
<div class="bond"></div>
<div class="atom h h1">H</div>
<div class="atom o">O</div>
<div class="atom h h2">H</div>
</div>
<div>
<strong>H₂O</strong>
<small>Same chemical species in every phase</small>
</div>
</div>
<div class="divider"></div>
<div class="phase-controls">
<button
class="phase"
type="button"
data-phase="0"
style="--phase-color: var(--solid)"
>
<b>SOLID</b>
<span>Ordered · tightly packed · tiny vibration</span>
</button>
<button
class="phase"
type="button"
data-phase="1"
style="--phase-color: var(--liquid)"
>
<b>LIQUID</b>
<span>Disordered · close together · drifting</span>
</button>
<button
class="phase"
type="button"
data-phase="2"
style="--phase-color: var(--gas)"
>
<b>GAS</b>
<span>Separated · far apart · rapid travel</span>
</button>
</div>
<button class="overview" id="overview" type="button" title="Show the full gallery" aria-label="Show the full gallery">
↺
</button>
</div>
</section>
<div id="loading">Loading phase field…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.Fog(0x07131b, 29, 72);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 130);
const hemi = new THREE.HemisphereLight(0xc5eeff, 0x071016, 1.65);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xe7f8ff, 2.7);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x719bff, 1.25);
rimLight.position.set(9, 7, -8);
scene.add(rimLight);
const clock = new THREE.Clock();
// -------------------------------------------------------------------------
// Shared materials and geometry helpers
// -------------------------------------------------------------------------
const materials = {
plinth: new THREE.MeshStandardMaterial({
color: 0x12242e,
roughness: 0.72,
metalness: 0.18
}),
plinthTop: new THREE.MeshStandardMaterial({
color: 0x213945,
roughness: 0.48,
metalness: 0.22
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x1b303b,
roughness: 0.34,
metalness: 0.68
}),
copper: new THREE.MeshStandardMaterial({
color: 0xb9673e,
roughness: 0.38,
metalness: 0.72
}),
ceramic: new THREE.MeshStandardMaterial({
color: 0xd5d6ca,
roughness: 0.68,
metalness: 0.05
}),
ice: new THREE.MeshPhysicalMaterial({
color: 0xc6f2ff,
roughness: 0.1,
metalness: 0,
transmission: 0.32,
thickness: 0.6,
transparent: true,
opacity: 0.8
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xbcecff,
roughness: 0.06,
metalness: 0,
transmission: 0.82,
thickness: 0.12,
transparent: true,
opacity: 0.25,
depthWrite: false,
side: THREE.DoubleSide
}),
water: new THREE.MeshPhysicalMaterial({
color: 0x18b8e8,
roughness: 0.16,
metalness: 0,
transmission: 0.22,
thickness: 0.9,
transparent: true,
opacity: 0.68,
depthWrite: false
}),
waterTop: new THREE.MeshPhysicalMaterial({
color: 0x58d9f3,
roughness: 0.1,
metalness: 0,
transmission: 0.18,
transparent: true,
opacity: 0.78,
depthWrite: false
}),
oxygen: new THREE.MeshStandardMaterial({
color: 0xe44f52,
roughness: 0.34,
metalness: 0.05,
emissive: 0x5c0b12,
emissiveIntensity: 0.22
}),
hydrogen: new THREE.MeshStandardMaterial({
color: 0xf1fbff,
roughness: 0.28,
metalness: 0.02,
emissive: 0x8cb6c3,
emissiveIntensity: 0.12
}),
bond: new THREE.MeshStandardMaterial({
color: 0xdbe9ed,
roughness: 0.46,
metalness: 0.08
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0xbcefff, opacity = 0.48) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
function makeRoundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(title, subtitle, accent = "#8be9ff", width = 2.6) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 256;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 1024, 256);
makeRoundedRect(ctx, 6, 6, 1012, 244, 28);
ctx.fillStyle = "rgba(5, 17, 25, 0.88)";
ctx.fill();
ctx.strokeStyle = "rgba(180, 230, 245, 0.28)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(30, 28, 8, 200);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#effcff";
ctx.font = "700 58px system-ui, sans-serif";
ctx.fillText(title, 522, 92);
ctx.fillStyle = "#91aab5";
ctx.font = "600 27px system-ui, sans-serif";
ctx.fillText(subtitle, 522, 169);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
return sprite;
}
function makeFormulaBadge(accent = "#8be9ff") {
const badgeCanvas = document.createElement("canvas");
badgeCanvas.width = 512;
badgeCanvas.height = 256;
const ctx = badgeCanvas.getContext("2d");
makeRoundedRect(ctx, 8, 8, 496, 240, 38);
ctx.fillStyle = "rgba(7, 22, 31, 0.92)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.globalAlpha = 0.6;
ctx.lineWidth = 5;
ctx.stroke();
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f4fdff";
ctx.font = "750 94px system-ui, sans-serif";
ctx.fillText("H₂O", 256, 108);
ctx.fillStyle = "#8faab6";
ctx.font = "650 28px system-ui, sans-serif";
ctx.fillText("SAME SPECIES", 256, 188);
const texture = new THREE.CanvasTexture(badgeCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(0.94, 0.47, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Gallery architecture
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 55),
new THREE.MeshStandardMaterial({
color: 0x091820,
roughness: 0.91,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(46, 46, 0x315460, 0x19313b);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.25;
scene.add(grid);
const backWall = new THREE.Mesh(
new THREE.PlaneGeometry(55, 18),
new THREE.MeshStandardMaterial({
color: 0x081720,
roughness: 0.92,
metalness: 0.05
})
);
backWall.position.set(0, 7.8, -9.4);
backWall.receiveShadow = true;
scene.add(backWall);
const wallTrim = new THREE.Mesh(
new THREE.BoxGeometry(30, 0.05, 0.05),
new THREE.MeshBasicMaterial({
color: 0x4ba8bc,
transparent: true,
opacity: 0.42
})
);
wallTrim.position.set(0, 8.6, -9.15);
scene.add(wallTrim);
for (let i = -6; i <= 6; i++) {
const strip = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 3.2 + (i % 3) * 0.35, 0.035),
new THREE.MeshBasicMaterial({
color: i % 3 === 0 ? 0x3ca8bd : 0x254753,
transparent: true,
opacity: 0.32
})
);
strip.position.set(i * 2.15, 4.3 + (i % 3) * 0.12, -9.12);
scene.add(strip);
}
const stationXs = [-5.3, 0, 5.3];
const stateColors = [0x91e9ff, 0x35d4ff, 0xb39cff];
const stateCss = ["#91e9ff", "#35d4ff", "#b39cff"];
function makeStand(x, accent) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
addBox(group, [3.08, 0.42, 2.32], [0, 0.21, 0], materials.plinth);
addBox(group, [2.84, 0.16, 2.08], [0, 0.5, 0], materials.plinthTop);
const trimMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 1.35,
roughness: 0.35
});
addBox(group, [2.76, 0.045, 0.05], [0, 0.59, 1.06], trimMaterial, false);
addBox(group, [0.055, 0.18, 2.04], [-1.43, 0.43, 0], trimMaterial, false);
addBox(group, [0.055, 0.18, 2.04], [1.43, 0.43, 0], trimMaterial, false);
return group;
}
stationXs.forEach((x, i) => {
makeStand(x, stateColors[i]);
const pointLight = new THREE.PointLight(stateColors[i], 5.5, 8.5, 2);
pointLight.position.set(x, 3.6, 3.4);
scene.add(pointLight);
});
// -------------------------------------------------------------------------
// Macroscopic exhibits
// -------------------------------------------------------------------------
function makeIceExhibit(x) {
const group = new THREE.Group();
group.position.set(x, 0.59, 0.35);
scene.add(group);
const cubeSize = 0.72;
const gap = 0.055;
const xs = [-cubeSize - gap / 2, 0, cubeSize + gap / 2];
const ys = [cubeSize / 2 + 0.02, cubeSize * 1.5 + gap / 2 + 0.02];
const zs = [-cubeSize / 2 - gap / 2, cubeSize / 2 + gap / 2];
for (const px of xs) {
for (const py of ys) {
for (const pz of zs) {
const cube = addBox(
group,
[cubeSize, cubeSize, cubeSize],
[px, py, pz],
materials.ice
);
addEdges(cube, 0xd8f8ff, 0.42);
}
}
}
const chipMaterial = new THREE.MeshStandardMaterial({
color: 0xe9fbff,
roughness: 0.45,
transparent: true,
opacity: 0.86
});
const chips = [
[-0.42, 1.94, -0.16, 0.19],
[0.12, 1.91, 0.12, 0.13],
[0.55, 1.87, -0.27, 0.15],
[-0.71, 1.83, 0.24, 0.12]
];
for (const [px, py, pz, s] of chips) {
const chip = addBox(group, [s, s, s], [px, py, pz], chipMaterial);
chip.rotation.y = px * 0.8;
}
const label = makeLabel(
"ICE",
"MACROSCOPIC · SOLID",
stateCss[0],
2.5
);
label.position.set(x, 3.28, 0.55);
scene.add(label);
return group;
}
const mistDroplets = [];
function makeLiquidExhibit(x) {
const group = new THREE.Group();
group.position.set(x, 0.59, 0.35);
scene.add(group);
// Open-topped square glass vessel.
addBox(group, [2.04, 0.07, 1.52], [0, 0.04, 0], materials.glass, false);
addBox(group, [0.07, 1.58, 1.52], [-1.0, 0.8, 0], materials.glass, false);
addBox(group, [0.07, 1.58, 1.52], [1.0, 0.8, 0], materials.glass, false);
addBox(group, [1.94, 1.58, 0.06], [0, 0.8, -0.75], materials.glass, false);
addBox(group, [1.94, 1.58, 0.06], [0, 0.8, 0.75], materials.glass, false);
// A block-built water body.
const waterBody = addBox(
group,
[1.83, 1.06, 1.31],
[0, 0.61, 0],
materials.water,
false
);
addEdges(waterBody, 0x52dfff, 0.18);
for (const px of [-0.68, -0.23, 0.23, 0.68]) {
for (const pz of [-0.42, 0, 0.42]) {
const tileMaterial = materials.waterTop.clone();
tileMaterial.opacity = 0.54 + Math.random() * 0.17;
const tile = addBox(
group,
[0.43, 0.045, 0.39],
[px, 1.16 + Math.random() * 0.025, pz],
tileMaterial,
false
);
tile.rotation.y = (Math.random() - 0.5) * 0.06;
}
}
// White suspended droplets above the liquid. They are intentionally not
// presented as individual vapor molecules.
const dropletMaterial = new THREE.MeshBasicMaterial({
color: 0xf3ffff,
transparent: true,
opacity: 0.82,
depthWrite: false
});
for (let i = 0; i < 18; i++) {
const size = 0.038 + Math.random() * 0.035;
const droplet = addBox(
group,
[size, size * (0.8 + Math.random() * 0.8), size],
[0, 1.45 + Math.random() * 1.05, 0],
dropletMaterial,
false
);
mistDroplets.push({
mesh: droplet,
baseX: (Math.random() - 0.5) * 1.38,
baseZ: (Math.random() - 0.5) * 0.82,
phase: Math.random() * 1.1,
speed: 0.12 + Math.random() * 0.11
});
}
const label = makeLabel(
"LIQUID WATER",
"MACROSCOPIC · LIQUID",
stateCss[1],
2.8
);
label.position.set(x, 3.53, 0.55);
scene.add(label);
return group;
}
const vaporBlocks = [];
function makeVaporExhibit(x) {
const group = new THREE.Group();
group.position.set(x, 0.59, 0.35);
scene.add(group);
// A voxel vapor generator: ceramic reservoir, copper heater, and spout.
const heaterMaterial = new THREE.MeshStandardMaterial({
color: 0xb85e36,
roughness: 0.35,
metalness: 0.72,
emissive: 0x4b1608,
emissiveIntensity: 0.35
});
addBox(group, [1.78, 0.23, 1.42], [0, 0.14, 0], heaterMaterial);
addBox(group, [1.48, 0.16, 1.18], [0, 0.33, 0], materials.darkMetal);
const body = addBox(group, [1.42, 0.92, 1.12], [0, 0.86, 0], materials.ceramic);
addEdges(body, 0xffffff, 0.15);
addBox(group, [1.56, 0.16, 1.23], [0, 1.39, 0], materials.copper);
addBox(group, [0.38, 0.18, 0.38], [0, 1.56, 0], materials.darkMetal);
addBox(group, [0.42, 0.22, 0.34], [0.86, 1.02, 0], materials.copper);
addBox(group, [0.35, 0.17, 0.27], [1.18, 1.17, 0], materials.copper);
addBox(group, [0.12, 0.36, 0.12], [-0.84, 1.02, 0], materials.darkMetal);
addBox(group, [0.12, 0.12, 0.64], [-0.84, 1.27, 0], materials.darkMetal);
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0xff7135,
transparent: true,
opacity: 0.46
});
addBox(group, [1.46, 0.055, 0.07], [0, 0.05, 0.72], glowMaterial, false);
// A faint blue phase field, deliberately schematic rather than a field
// of separately drawn visible molecules.
const fieldMaterial = new THREE.MeshBasicMaterial({
color: 0x6bcaff,
transparent: true,
opacity: 0.07,
depthWrite: false
});
const fieldSpecs = [
[-0.15, 1.85, 0.0, 0.58],
[0.22, 2.12, -0.05, 0.72],
[-0.28, 2.38, 0.02, 0.56],
[0.14, 2.62, 0.0, 0.43],
[0.0, 2.83, 0.0, 0.31]
];
for (const [px, py, pz, s] of fieldSpecs) {
const block = addBox(
group,
[s, s * 0.72, s],
[px, py, pz],
fieldMaterial,
false
);
addEdges(block, 0x78caff, 0.16);
vaporBlocks.push({
mesh: block,
baseY: py,
phase: Math.random() * Math.PI * 2
});
}
const label = makeLabel(
"WATER VAPOR",
"MACROSCOPIC · GAS / SCHEMATIC FIELD",
stateCss[2],
3.12
);
label.position.set(x, 3.7, 0.55);
scene.add(label);
return group;
}
makeIceExhibit(stationXs[0]);
makeLiquidExhibit(stationXs[1]);
makeVaporExhibit(stationXs[2]);
// -------------------------------------------------------------------------
// Enlarged symbolic molecular insets
// -------------------------------------------------------------------------
const oxygenGeometry = new THREE.SphereGeometry(0.13, 18, 12);
const hydrogenGeometry = new THREE.SphereGeometry(0.092, 16, 10);
const bondGeometry = new THREE.CylinderGeometry(0.025, 0.025, 0.255, 8);
const particles = [];
function makeMolecule() {
const group = new THREE.Group();
const oxygen = new THREE.Mesh(oxygenGeometry, materials.oxygen);
oxygen.position.set(0, 0.07, 0);
group.add(oxygen);
const leftHydrogen = new THREE.Mesh(hydrogenGeometry, materials.hydrogen);
leftHydrogen.position.set(-0.145, -0.105, 0);
group.add(leftHydrogen);
const rightHydrogen = new THREE.Mesh(hydrogenGeometry, materials.hydrogen);
rightHydrogen.position.set(0.145, -0.105, 0);
group.add(rightHydrogen);
function addBond(start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const bond = new THREE.Mesh(bondGeometry, materials.bond);
bond.position.copy(start).add(end).multiplyScalar(0.5);
bond.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
group.add(bond);
}
addBond(
new THREE.Vector3(0, 0.07, 0),
new THREE.Vector3(-0.145, -0.105, 0)
);
addBond(
new THREE.Vector3(0, 0.07, 0),
new THREE.Vector3(0.145, -0.105, 0)
);
return group;
}
function makeParticlePanel(x, index) {
const accent = stateColors[index];
const cssAccent = stateCss[index];
const panel = new THREE.Mesh(
new THREE.BoxGeometry(2.62, 3.2, 0.13),
new THREE.MeshBasicMaterial({
color: 0x09202b,
transparent: true,
opacity: 0.88
})
);
panel.position.set(x, 3.18, -0.72);
scene.add(panel);
addEdges(panel, accent, 0.68);
// A small physical support keeps each inset visually separate from the
// gallery-scale exhibit.
addBox(
scene,
[0.08, 1.22, 0.08],
[x, 0.61, -0.8],
materials.darkMetal
);
addBox(
scene,
[0.86, 0.08, 0.54],
[x, 0.04, -0.78],
materials.plinthTop
);
const title = makeLabel(
`H₂O · ${["ICE", "WATER", "VAPOR"][index]}`,
[
"ENLARGED INSET · ORDERED / TIGHT / VIBRATING",
"ENLARGED INSET · DISORDERED / CLOSE / DRIFTING",
"ENLARGED INSET · SPACED / FAR / RAPID"
][index],
cssAccent,
2.72
);
title.position.set(x, 5.2, -0.25);
scene.add(title);
const badge = makeFormulaBadge(cssAccent);
badge.position.set(x - 0.76, 4.42, -0.34);
scene.add(badge);
return { x, index };
}
const panelXs = stationXs.map((x) => x + 2.65);
panelXs.forEach((x, i) => makeParticlePanel(x, i));
function registerParticle(group, kind, base, extra = {}) {
group.scale.setScalar(extra.scale ?? 0.72);
group.position.copy(base);
scene.add(group);
particles.push({
group,
kind,
base: base.clone(),
phase: Math.random() * Math.PI * 2,
velocity: extra.velocity ?? new THREE.Vector3(),
rotation: new THREE.Euler(
Math.random() * 0.4,
Math.random() * Math.PI,
Math.random() * Math.PI
)
});
}
// Solid: a rigid, close-packed lattice with only small collective vibration.
{
const panelX = panelXs[0];
const xs = [-0.78, -0.26, 0.26, 0.78];
const ys = [-1.0, -0.42, 0.16, 0.74];
for (let row = 0; row < ys.length; row++) {
for (let col = 0; col < xs.length; col++) {
const molecule = makeMolecule();
const base = new THREE.Vector3(
panelX + xs[col],
3.18 + ys[row],
-0.35 + ((row + col) % 2) * 0.28
);
registerParticle(molecule, "solid", base, { scale: 0.7 });
}
}
}
// Liquid: disordered but still close together, with local drifting.
{
const panelX = panelXs[1];
const positions = [];
let attempts = 0;
while (positions.length < 15 && attempts < 2000) {
attempts++;
const candidate = new THREE.Vector2(
-0.86 + Math.random() * 1.72,
-1.04 + Math.random() * 2.03
);
const separated = positions.every((p) => p.distanceTo(candidate) > 0.34);
if (separated) positions.push(candidate);
}
for (const p of positions) {
const molecule = makeMolecule();
const base = new THREE.Vector3(
panelX + p.x,
3.18 + p.y,
-0.38 + Math.random() * 0.48
);
registerParticle(molecule, "liquid", base, { scale: 0.68 });
}
}
// Gas: sparse molecules moving rapidly across the inset.
{
const panelX = panelXs[2];
const positions = [];
let attempts = 0;
while (positions.length < 9 && attempts < 2000) {
attempts++;
const candidate = new THREE.Vector2(
-0.9 + Math.random() * 1.8,
-1.02 + Math.random() * 2.0
);
const separated = positions.every((p) => p.distanceTo(candidate) > 0.55);
if (separated) positions.push(candidate);
}
for (const p of positions) {
const molecule = makeMolecule();
const base = new THREE.Vector3(
panelX + p.x,
3.18 + p.y,
-0.34 + Math.random() * 0.42
);
const velocity = new THREE.Vector3(
(Math.random() > 0.5 ? 1 : -1) * (0.11 + Math.random() * 0.12),
(Math.random() > 0.5 ? 1 : -1) * (0.07 + Math.random() * 0.09),
0
);
registerParticle(molecule, "gas", base, {
scale: 0.7,
velocity
});
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function updateParticles(time, dt) {
for (const particle of particles) {
const group = particle.group;
if (particle.kind === "solid") {
group.position.copy(particle.base);
group.position.z += Math.sin(time * 1.5 + particle.phase) * 0.009;
group.rotation.set(
particle.rotation.x + Math.sin(time * 1.1 + particle.phase) * 0.012,
particle.rotation.y,
particle.rotation.z + Math.cos(time * 1.2 + particle.phase) * 0.014
);
} else if (particle.kind === "liquid") {
group.position.copy(particle.base);
group.position.x += Math.sin(time * 1.35 + particle.phase) * 0.055;
group.position.y += Math.cos(time * 1.15 + particle.phase * 1.3) * 0.05;
group.position.z += Math.sin(time * 0.9 + particle.phase) * 0.035;
group.rotation.x = particle.rotation.x + Math.sin(time * 0.75 + particle.phase) * 0.2;
group.rotation.y = particle.rotation.y + time * 0.22;
group.rotation.z = particle.rotation.z + Math.cos(time * 0.9 + particle.phase) * 0.18;
} else {
group.position.x += particle.velocity.x * dt;
group.position.y += particle.velocity.y * dt;
const minX = particle.base.x - 0.98;
const maxX = particle.base.x + 0.98;
const minY = particle.base.y - 1.08;
const maxY = particle.base.y + 1.03;
if (group.position.x < minX || group.position.x > maxX) {
particle.velocity.x *= -1;
group.position.x = THREE.MathUtils.clamp(group.position.x, minX, maxX);
}
if (group.position.y < minY || group.position.y > maxY) {
particle.velocity.y *= -1;
group.position.y = THREE.MathUtils.clamp(group.position.y, minY, maxY);
}
group.position.z += Math.sin(time * 1.3 + particle.phase) * dt * 0.04;
group.rotation.x = particle.rotation.x + time * 0.45;
group.rotation.y = particle.rotation.y + time * 0.62;
group.rotation.z = particle.rotation.z + time * 0.35;
}
}
}
function updateMist(time) {
for (const droplet of mistDroplets) {
const rise = (time * droplet.speed + droplet.phase) % 1.12;
droplet.mesh.position.y = 1.46 + rise;
droplet.mesh.position.x =
droplet.baseX + Math.sin(time * 0.8 + droplet.phase) * 0.11;
droplet.mesh.position.z =
droplet.baseZ + Math.cos(time * 0.65 + droplet.phase) * 0.08;
droplet.mesh.rotation.y = time * 0.4 + droplet.phase;
}
}
function updateVaporField(time) {
for (const block of vaporBlocks) {
block.mesh.position.y =
block.baseY + Math.sin(time * 0.65 + block.phase) * 0.055;
block.mesh.rotation.y = Math.sin(time * 0.32 + block.phase) * 0.08;
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no external control add-ons
// -------------------------------------------------------------------------
const tanHalfFov = Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5));
const desiredTarget = new THREE.Vector3(0.9, 2.55, 0);
const currentTarget = desiredTarget.clone();
let desiredYaw = 0;
let desiredPolar = 1.37;
let desiredRadius = 18.8;
let currentYaw = desiredYaw;
let currentPolar = desiredPolar;
let currentRadius = desiredRadius;
function overviewRadius() {
return Math.max(18.8, 9.2 / (tanHalfFov * camera.aspect));
}
function focusRadius() {
return Math.max(11.8, 4.7 / (tanHalfFov * camera.aspect));
}
function updateCamera(dt, immediate = false) {
const blend = immediate ? 1 : 1 - Math.exp(-dt * 6.5);
currentYaw = THREE.MathUtils.lerp(currentYaw, desiredYaw, blend);
currentPolar = THREE.MathUtils.lerp(currentPolar, desiredPolar, blend);
currentRadius = THREE.MathUtils.lerp(currentRadius, desiredRadius, blend);
currentTarget.lerp(desiredTarget, blend);
const sinPolar = Math.sin(currentPolar);
camera.position.set(
currentTarget.x +
currentRadius * sinPolar * Math.sin(currentYaw),
currentTarget.y + currentRadius * Math.cos(currentPolar),
currentTarget.z +
currentRadius * sinPolar * Math.cos(currentYaw)
);
camera.lookAt(currentTarget);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredYaw -= dx * 0.005;
desiredPolar = THREE.MathUtils.clamp(
desiredPolar + dy * 0.004,
0.92,
1.53
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
9.5,
48
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", showOverview);
const phaseButtons = [...document.querySelectorAll(".phase")];
function showOverview() {
desiredTarget.set(0.9, 2.55, 0);
desiredYaw = 0;
desiredPolar = 1.37;
desiredRadius = overviewRadius();
phaseButtons.forEach((button) => button.classList.remove("active"));
const overview = document.getElementById("overview");
overview.classList.add("spinning");
setTimeout(() => overview.classList.remove("spinning"), 320);
}
phaseButtons.forEach((button, index) => {
button.addEventListener("click", () => {
desiredTarget.set(stationXs[index] + 0.65, 2.7, -0.05);
desiredYaw = 0;
desiredPolar = 1.39;
desiredRadius = focusRadius();
phaseButtons.forEach((b) => b.classList.remove("active"));
button.classList.add("active");
});
});
document.getElementById("overview").addEventListener("click", showOverview);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (!dragging) {
desiredRadius = overviewRadius();
}
}
window.addEventListener("resize", onResize);
onResize();
updateCamera(0, true);
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.04);
const time = clock.elapsedTime;
updateCamera(dt);
updateParticles(time, dt);
updateMist(time);
updateVaporField(time);
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```