Prompt specification
Build or customize the Three.js 3D scene "Ice water coexistence vessel" 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 coexistence vessel
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ice-water-coexistence-vessel-x1489
Scene Description Prompt:
A low-poly transparent cup contains floating ice melting at a stated fixed-pressure transition temperature. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (ice-water-coexistence-vessel-x1489):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Phase Change — Ice at 0 °C and 1 atm</title>
<style>
:root {
color-scheme: dark;
--text: #edfaff;
--muted: #91adbb;
--cyan: #76e6ff;
--blue: #65a9ff;
--warm: #ffc36a;
--panel: rgba(8, 24, 37, 0.68);
--line: rgba(164, 231, 255, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #173a50 0%, #0b1d2c 38%, #050d15 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(to bottom, rgba(2, 8, 13, 0.26), transparent 30%),
radial-gradient(circle, transparent 45%, rgba(0, 5, 10, 0.42) 100%);
z-index: 1;
}
.panel {
position: fixed;
z-index: 3;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.25),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(16px) saturate(125%);
-webkit-backdrop-filter: blur(16px) saturate(125%);
}
.intro {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 22px 24px 21px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--cyan);
font-size: 0.7rem;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 2.6vw, 2.3rem);
font-weight: 670;
line-height: 1.04;
letter-spacing: -0.035em;
}
.intro p {
margin: 14px 0 0;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.58;
}
.pressure-pill {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding: 7px 10px;
border: 1px solid rgba(118, 230, 255, 0.23);
border-radius: 999px;
background: rgba(118, 230, 255, 0.075);
color: #bcefff;
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.pressure-pill::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
.readout {
top: 24px;
right: 24px;
width: 286px;
padding: 18px;
pointer-events: none;
}
.readout-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
padding-bottom: 14px;
border-bottom: 1px solid var(--line);
}
.readout-label {
color: var(--muted);
font-size: 0.67rem;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.temperature {
margin-top: 5px;
font-size: 2.05rem;
font-weight: 650;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.phase {
margin-top: 7px;
color: var(--cyan);
font-size: 0.74rem;
font-weight: 700;
white-space: nowrap;
}
.phase::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
content: "";
vertical-align: 1px;
}
.metrics {
display: grid;
gap: 10px;
margin-top: 14px;
}
.metric {
display: flex;
justify-content: space-between;
gap: 16px;
color: var(--muted);
font-size: 0.75rem;
}
.metric strong {
color: var(--text);
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.progress-label {
display: flex;
justify-content: space-between;
margin-top: 16px;
color: var(--muted);
font-size: 0.7rem;
font-weight: 650;
}
.progress-label strong {
color: var(--text);
font-variant-numeric: tabular-nums;
}
.progress-track {
height: 5px;
margin-top: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
.progress-fill {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--cyan));
box-shadow: 0 0 14px rgba(118, 230, 255, 0.45);
transform-origin: left;
transition: transform 100ms linear;
}
.energy-note {
margin-top: 11px;
color: var(--muted);
font-size: 0.69rem;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 4;
left: 50%;
bottom: 25px;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(6, 18, 29, 0.82);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
transform: translateX(-50%);
}
.controls button {
min-height: 40px;
padding: 0 14px;
border: 1px solid transparent;
border-radius: 10px;
background: rgba(255, 255, 255, 0.065);
color: var(--text);
cursor: pointer;
font-size: 0.78rem;
font-weight: 680;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.controls button:hover {
border-color: rgba(164, 231, 255, 0.24);
background: rgba(255, 255, 255, 0.12);
transform: translateY(-1px);
}
.controls button:active {
transform: translateY(0);
}
.controls button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.controls .warm {
background: rgba(255, 195, 106, 0.13);
color: #ffe0a8;
}
.controls .warm:hover {
border-color: rgba(255, 195, 106, 0.36);
background: rgba(255, 195, 106, 0.21);
}
.hint {
position: fixed;
z-index: 3;
right: 26px;
bottom: 26px;
color: rgba(190, 222, 234, 0.62);
font-size: 0.68rem;
pointer-events: none;
}
#temp-tag {
position: fixed;
z-index: 2;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(118, 230, 255, 0.28);
border-radius: 999px;
background: rgba(8, 27, 40, 0.78);
color: #d8f8ff;
font-size: 0.68rem;
font-weight: 720;
letter-spacing: 0.05em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
}
#temp-tag::after {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
content: "";
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px 18px;
}
.intro p {
display: none;
}
.pressure-pill {
margin-top: 12px;
}
.readout {
top: auto;
right: 12px;
bottom: 82px;
width: 220px;
padding: 13px;
}
.readout .metrics,
.readout .energy-note {
display: none;
}
.temperature {
font-size: 1.5rem;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
}
.controls button {
flex: 1;
padding: 0 8px;
}
.hint,
#temp-tag {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<section class="panel intro">
<div class="eyebrow">Phase change study / 01</div>
<h1>Ice, held at its point of change.</h1>
<p>
At a fixed pressure of 1 atm, pure water transitions between ice and
liquid at <strong>0 °C</strong>. While both phases coexist, incoming
thermal energy melts the ice without raising the transition temperature.
</p>
<div class="pressure-pill">1 atm · fixed pressure</div>
</section>
<section class="panel readout" aria-live="polite">
<div class="readout-head">
<div>
<div class="readout-label">Temperature</div>
<div class="temperature" id="temperature">0.0 °C</div>
</div>
<div class="phase" id="phase">Ice + water</div>
</div>
<div class="metrics">
<div class="metric">
<span>Transition point</span>
<strong>0.0 °C</strong>
</div>
<div class="metric">
<span>Latent heat of fusion</span>
<strong>334 kJ/kg</strong>
</div>
<div class="metric">
<span>Pressure</span>
<strong>101.325 kPa</strong>
</div>
</div>
<div class="progress-label">
<span>Ice remaining</span>
<strong id="ice-percent">100%</strong>
</div>
<div class="progress-track">
<div class="progress-fill" id="progress-fill"></div>
</div>
<div class="energy-note" id="energy-note">
Thermal input is absorbed as latent heat during the phase transition.
</div>
</section>
<div id="temp-tag">0.0 °C · MELTING</div>
<nav class="controls" aria-label="Simulation controls">
<button id="pause" type="button">Pause</button>
<button id="warm" class="warm" type="button">Warm pulse</button>
<button id="reset" type="button">Reset</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const mount = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131e);
scene.fog = new THREE.Fog(0x07131e, 10, 22);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
50
);
// Direct camera controls: no addons or examples modules are used.
const controls = {
azimuth: 0.42,
polar: 1.12,
distance: 7.7,
target: new THREE.Vector3(0, 1.48, 0)
};
function updateCamera() {
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x +
controls.distance * sinPolar * Math.sin(controls.azimuth),
controls.target.y + controls.distance * Math.cos(controls.polar),
controls.target.z +
controls.distance * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
updateCamera();
// Procedural studio environment for reflections in the glass and ice.
function createEnvironmentTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 0, 256);
gradient.addColorStop(0, "#c8f3ff");
gradient.addColorStop(0.38, "#477b9e");
gradient.addColorStop(0.72, "#10283d");
gradient.addColorStop(1, "#02070c");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 512, 256);
ctx.fillStyle = "rgba(255,255,255,0.72)";
ctx.fillRect(52, 22, 34, 176);
ctx.fillStyle = "rgba(118,230,255,0.5)";
ctx.fillRect(355, 12, 60, 190);
ctx.fillStyle = "rgba(255,210,155,0.28)";
ctx.fillRect(245, 0, 70, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.mapping = THREE.EquirectangularReflectionMapping;
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const environmentSource = createEnvironmentTexture();
const pmrem = new THREE.PMREMGenerator(renderer);
const environmentTarget = pmrem.fromEquirectangular(environmentSource);
scene.environment = environmentTarget.texture;
environmentSource.dispose();
pmrem.dispose();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9eaff, 0x07101b, 2.15));
const keyLight = new THREE.DirectionalLight(0xf4fbff, 3.4);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65dfff, 2.1);
rimLight.position.set(-5, 3.8, -4);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0x9ac7ff, 1.2, 12, 2);
fillLight.position.set(0, 2.6, 4.5);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Display plinth
// -------------------------------------------------------------------------
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(3.15, 3.5, 0.18, 24),
new THREE.MeshStandardMaterial({
color: 0x10283a,
roughness: 0.46,
metalness: 0.26
})
);
plinth.position.y = 0.02;
plinth.receiveShadow = true;
scene.add(plinth);
const plinthRing = new THREE.Mesh(
new THREE.TorusGeometry(2.55, 0.018, 3, 48),
new THREE.MeshBasicMaterial({
color: 0x4bc7e8,
transparent: true,
opacity: 0.35
})
);
plinthRing.rotation.x = Math.PI / 2;
plinthRing.position.y = 0.115;
scene.add(plinthRing);
const shadowDisc = new THREE.Mesh(
new THREE.CircleGeometry(1.65, 32),
new THREE.MeshBasicMaterial({
color: 0x000711,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
shadowDisc.rotation.x = -Math.PI / 2;
shadowDisc.position.y = 0.12;
scene.add(shadowDisc);
// -------------------------------------------------------------------------
// Transparent low-poly cup
// -------------------------------------------------------------------------
const cup = new THREE.Group();
scene.add(cup);
const cupBottom = 0.14;
const cupTop = 2.82;
const cupHeight = cupTop - cupBottom;
const cupMid = (cupTop + cupBottom) / 2;
const radiusBottom = 1.04;
const radiusTop = 1.26;
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xccefff,
roughness: 0.1,
metalness: 0,
transmission: 0.88,
thickness: 0.16,
ior: 1.45,
transparent: true,
opacity: 0.34,
clearcoat: 1,
clearcoatRoughness: 0.08,
side: THREE.DoubleSide,
depthWrite: false
});
const cupShell = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
cupHeight,
12,
1,
true
),
glassMaterial
);
cupShell.position.y = cupMid;
cupShell.renderOrder = 5;
cup.add(cupShell);
const cupBase = new THREE.Mesh(
new THREE.CircleGeometry(radiusBottom, 12),
glassMaterial.clone()
);
cupBase.rotation.x = -Math.PI / 2;
cupBase.position.y = cupBottom + 0.015;
cupBase.renderOrder = 5;
cup.add(cupBase);
const cupEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(cupShell.geometry, 18),
new THREE.LineBasicMaterial({
color: 0xc5f2ff,
transparent: true,
opacity: 0.26
})
);
cupEdges.position.copy(cupShell.position);
cupEdges.renderOrder = 6;
cup.add(cupEdges);
const topRim = new THREE.Mesh(
new THREE.TorusGeometry(radiusTop, 0.047, 4, 12),
glassMaterial.clone()
);
topRim.rotation.x = Math.PI / 2;
topRim.position.y = cupTop;
topRim.renderOrder = 6;
cup.add(topRim);
const baseRim = new THREE.Mesh(
new THREE.TorusGeometry(radiusBottom, 0.038, 4, 12),
glassMaterial.clone()
);
baseRim.rotation.x = Math.PI / 2;
baseRim.position.y = cupBottom;
baseRim.renderOrder = 6;
cup.add(baseRim);
// Faceted handle.
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.067, 4, 10),
glassMaterial.clone()
);
handle.position.set(1.34, 1.62, 0);
handle.scale.set(0.85, 1.25, 1);
handle.renderOrder = 5;
cup.add(handle);
// Small exterior condensation droplets.
const condensationGeometry = new THREE.OctahedronGeometry(0.025, 0);
const condensationMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd9f8ff,
roughness: 0.12,
transparent: true,
opacity: 0.5,
transmission: 0.25,
depthWrite: false
});
for (let i = 0; i < 24; i++) {
const angle = Math.random() * Math.PI * 2;
const y = 0.38 + Math.random() * 2.25;
const t = (y - cupBottom) / cupHeight;
const radius = THREE.MathUtils.lerp(radiusBottom, radiusTop, t) + 0.025;
const drop = new THREE.Mesh(
condensationGeometry,
condensationMaterial
);
drop.position.set(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
drop.scale.set(
0.65 + Math.random() * 0.6,
0.8 + Math.random() * 1.2,
0.65 + Math.random() * 0.6
);
drop.rotation.set(Math.random(), Math.random(), Math.random());
drop.renderOrder = 6;
cup.add(drop);
}
// -------------------------------------------------------------------------
// Water
// -------------------------------------------------------------------------
const waterBottom = 0.2;
const waterLevel = 2.27;
const waterHeight = waterLevel - waterBottom;
const waterMid = (waterLevel + waterBottom) / 2;
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x43bfe2,
roughness: 0.16,
metalness: 0,
transmission: 0.52,
thickness: 0.8,
ior: 1.333,
transparent: true,
opacity: 0.32,
side: THREE.DoubleSide,
depthWrite: false
});
const waterSide = new THREE.Mesh(
new THREE.CylinderGeometry(
1.22,
1.04,
waterHeight,
16,
1,
true
),
waterMaterial
);
waterSide.position.y = waterMid;
waterSide.renderOrder = 1;
cup.add(waterSide);
const surfaceGeometry = new THREE.CircleGeometry(1.22, 24);
const waterSurface = new THREE.Mesh(
surfaceGeometry,
new THREE.MeshPhysicalMaterial({
color: 0x8ce8ff,
roughness: 0.09,
metalness: 0,
transmission: 0.35,
transparent: true,
opacity: 0.47,
side: THREE.DoubleSide,
depthWrite: false
})
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.position.y = waterLevel;
waterSurface.renderOrder = 2;
cup.add(waterSurface);
const surfaceFacets = new THREE.LineSegments(
new THREE.EdgesGeometry(surfaceGeometry, 1),
new THREE.LineBasicMaterial({
color: 0xbef5ff,
transparent: true,
opacity: 0.12
})
);
surfaceFacets.rotation.x = -Math.PI / 2;
surfaceFacets.position.y = waterLevel + 0.002;
surfaceFacets.renderOrder = 3;
cup.add(surfaceFacets);
const meniscus = new THREE.Mesh(
new THREE.TorusGeometry(1.22, 0.015, 3, 24),
new THREE.MeshBasicMaterial({
color: 0xc6f7ff,
transparent: true,
opacity: 0.42
})
);
meniscus.rotation.x = Math.PI / 2;
meniscus.position.y = waterLevel + 0.008;
meniscus.renderOrder = 3;
cup.add(meniscus);
// Sparse cup graduation marks.
const markMaterial = new THREE.LineBasicMaterial({
color: 0xd8f7ff,
transparent: true,
opacity: 0.42
});
for (const y of [0.72, 1.15, 1.58, 2.01]) {
const t = (y - cupBottom) / cupHeight;
const radius = THREE.MathUtils.lerp(radiusBottom, radiusTop, t);
const x = -0.34;
const length = y === 2.01 ? 0.28 : 0.16;
const z = Math.sqrt(radius * radius - x * x) + 0.018;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, y, z),
new THREE.Vector3(x + length, y, z)
]);
const mark = new THREE.Line(geometry, markMaterial);
mark.renderOrder = 6;
cup.add(mark);
}
// -------------------------------------------------------------------------
// Floating faceted ice
// -------------------------------------------------------------------------
const iceGroup = new THREE.Group();
scene.add(iceGroup);
const iceDefinitions = [
{ x: -0.4, z: 0.18, size: 0.43, seed: 2.1, rate: 1.0 },
{ x: 0.38, z: 0.24, size: 0.37, seed: 8.7, rate: 0.93 },
{ x: 0.02, z: -0.43, size: 0.33, seed: 15.4, rate: 0.83 }
];
const iceChunks = [];
function hash3(x, y, z, seed) {
const value = Math.sin(
x * 127.1 + y * 311.7 + z * 74.7 + seed * 91.3
) * 43758.5453;
return value - Math.floor(value);
}
function createIceChunk(definition, index) {
const size = definition.size;
const geometry = new THREE.IcosahedronGeometry(size, 0);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const vertex = new THREE.Vector3().fromBufferAttribute(positions, i);
const direction = vertex.clone().normalize();
const hash = hash3(
direction.x,
direction.y,
direction.z,
definition.seed
);
const radius = size * (0.83 + hash * 0.32);
direction.multiplyScalar(radius);
positions.setXYZ(i, direction.x, direction.y, direction.z);
}
geometry.computeVertexNormals();
const material = new THREE.MeshPhysicalMaterial({
color: 0xcaf7ff,
roughness: 0.12,
metalness: 0,
transmission: 0.3,
thickness: 0.55,
ior: 1.31,
transparent: true,
opacity: 0.92,
clearcoat: 0.55,
clearcoatRoughness: 0.12,
flatShading: true,
depthWrite: false
});
const coreMaterial = new THREE.MeshBasicMaterial({
color: 0xe9fdff,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const group = new THREE.Group();
const shell = new THREE.Mesh(geometry, material);
shell.castShadow = true;
shell.renderOrder = 4;
group.add(shell);
const core = new THREE.Mesh(geometry, coreMaterial);
core.scale.set(0.55, 0.48, 0.54);
core.rotation.set(0.4 + index, 0.7, 0.2);
core.renderOrder = 3;
group.add(core);
const baseScale = new THREE.Vector3(
0.9 + index * 0.08,
0.78 + index * 0.045,
1.02 - index * 0.05
);
group.scale.copy(baseScale);
group.position.set(definition.x, waterLevel, definition.z);
group.rotation.y = index * 1.37;
iceGroup.add(group);
const chunk = {
group,
shell,
core,
material,
coreMaterial,
size,
seed: definition.seed,
rate: definition.rate,
baseScale,
melt: 0,
bobPhase: index * 2.1,
driftPhase: index * 1.8,
meltMarkers: new Set()
};
iceChunks.push(chunk);
return chunk;
}
iceDefinitions.forEach(createIceChunk);
function smoothstep(min, max, value) {
const t = THREE.MathUtils.clamp(
(value - min) / (max - min),
0,
1
);
return t * t * (3 - 2 * t);
}
function updateIceVisual(chunk) {
const progress = chunk.melt;
const scaleX = chunk.baseScale.x * (1 - 0.86 * progress);
const scaleY = chunk.baseScale.y * (1 - 0.9 * progress);
const scaleZ = chunk.baseScale.z * (1 - 0.86 * progress);
chunk.group.scale.set(scaleX, scaleY, scaleZ);
// Stylized buoyancy: the chunk rides high enough to remain visibly faceted.
const halfHeight = chunk.size * scaleY * 0.5;
const submergedFraction = 0.72;
const floatingOffset = halfHeight * (1 - 2 * submergedFraction);
chunk.group.position.y = waterLevel + floatingOffset;
const fade = 1 - smoothstep(0.78, 1, progress);
chunk.material.opacity = 0.08 + 0.84 * fade;
chunk.coreMaterial.opacity = 0.16 * fade;
chunk.group.visible = progress < 0.999;
chunk.group.rotation.y += 0.0014;
chunk.group.rotation.z = Math.sin(
performance.now() * 0.00045 + chunk.bobPhase
) * 0.045;
}
// -------------------------------------------------------------------------
// Melt droplets, ripples, and thermal pulses
// -------------------------------------------------------------------------
const droplets = [];
const ripples = [];
const pulses = [];
const dropletGeometry = new THREE.OctahedronGeometry(0.032, 0);
const dropletMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd8fbff,
roughness: 0.08,
transparent: true,
opacity: 0.76,
transmission: 0.2,
depthWrite: false
});
function spawnDroplet(chunk) {
const mesh = new THREE.Mesh(dropletGeometry, dropletMaterial);
const spread = chunk.size * 0.65;
mesh.position.set(
chunk.group.position.x + (Math.random() - 0.5) * spread,
waterLevel + 0.08 + Math.random() * chunk.size * 0.25,
chunk.group.position.z + (Math.random() - 0.5) * spread
);
mesh.scale.setScalar(0.65 + Math.random() * 0.65);
mesh.renderOrder = 4;
scene.add(mesh);
droplets.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 0.18,
-0.18 - Math.random() * 0.25,
(Math.random() - 0.5) * 0.18
),
life: 0
});
}
function spawnRipple(position) {
const material = new THREE.MeshBasicMaterial({
color: 0xbaf5ff,
transparent: true,
opacity: 0.5,
side: THREE.DoubleSide,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.RingGeometry(0.035, 0.055, 20),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(position.x, waterLevel + 0.012, position.z);
mesh.renderOrder = 4;
scene.add(mesh);
ripples.push({ mesh, age: 0 });
}
function spawnHeatPulse() {
const material = new THREE.MeshBasicMaterial({
color: 0xffbc62,
transparent: true,
opacity: 0.65,
side: THREE.DoubleSide,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.RingGeometry(1.08, 1.14, 32),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = 0.135;
mesh.renderOrder = 2;
scene.add(mesh);
pulses.push({ mesh, age: 0 });
}
function updateParticles(dt) {
for (let i = droplets.length - 1; i >= 0; i--) {
const droplet = droplets[i];
droplet.life += dt;
droplet.velocity.y -= 2.1 * dt;
droplet.mesh.position.addScaledVector(droplet.velocity, dt);
droplet.mesh.rotation.x += dt * 5;
droplet.mesh.rotation.z += dt * 3;
const fade = Math.max(0, 1 - droplet.life * 0.45);
droplet.mesh.scale.multiplyScalar(Math.pow(0.985, dt * 60));
if (
droplet.mesh.position.y <= waterLevel + 0.01 ||
droplet.life > 3
) {
if (droplet.mesh.position.y <= waterLevel + 0.01) {
spawnRipple(droplet.mesh.position);
}
scene.remove(droplet.mesh);
droplets.splice(i, 1);
} else {
droplet.mesh.scale.setScalar(fade);
}
}
for (let i = ripples.length - 1; i >= 0; i--) {
const ripple = ripples[i];
ripple.age += dt;
const t = ripple.age / 0.7;
ripple.mesh.scale.setScalar(1 + t * 4);
ripple.mesh.material.opacity = 0.48 * (1 - t);
if (t >= 1) {
scene.remove(ripple.mesh);
ripple.mesh.geometry.dispose();
ripple.mesh.material.dispose();
ripples.splice(i, 1);
}
}
for (let i = pulses.length - 1; i >= 0; i--) {
const pulse = pulses[i];
pulse.age += dt;
const t = pulse.age / 1.15;
pulse.mesh.scale.setScalar(1 + t * 1.8);
pulse.mesh.material.opacity = 0.62 * (1 - t);
if (t >= 1) {
scene.remove(pulse.mesh);
pulse.mesh.geometry.dispose();
pulse.mesh.material.dispose();
pulses.splice(i, 1);
}
}
}
// -------------------------------------------------------------------------
// Simulation state
// -------------------------------------------------------------------------
let paused = false;
let heatBoost = 0;
let postMeltHeat = 0;
let elapsed = 0;
const initialMass = iceChunks.reduce(
(sum, chunk) => sum + chunk.size ** 3,
0
);
function remainingIceMass() {
return iceChunks.reduce((sum, chunk) => {
const massFraction = Math.max(0, 1 - chunk.melt) ** 3;
return sum + chunk.size ** 3 * massFraction;
}, 0);
}
function updateSimulation(dt) {
heatBoost *= Math.exp(-dt * 0.85);
const hasIce = remainingIceMass() > 0.0001;
for (const chunk of iceChunks) {
if (chunk.melt >= 1) continue;
const oldMelt = chunk.melt;
const rate =
0.018 *
chunk.rate *
(1 + heatBoost * 2.4);
chunk.melt = Math.min(1, chunk.melt + rate * dt);
for (const marker of [0.2, 0.42, 0.64, 0.82]) {
if (
oldMelt < marker &&
chunk.melt >= marker &&
!chunk.meltMarkers.has(marker)
) {
chunk.meltMarkers.add(marker);
spawnDroplet(chunk);
}
}
updateIceVisual(chunk);
}
if (!hasIce) {
// After coexistence, a warm pulse can produce sensible heating.
postMeltHeat += dt * 0.0018;
}
const bobTime = elapsed;
iceChunks.forEach((chunk, index) => {
if (chunk.melt >= 1) return;
chunk.group.position.x +=
Math.sin(bobTime * 0.45 + chunk.driftPhase) * dt * 0.006;
chunk.group.position.z +=
Math.cos(bobTime * 0.38 + chunk.driftPhase) * dt * 0.005;
chunk.group.rotation.x =
Math.sin(bobTime * 0.37 + chunk.bobPhase) * 0.035;
});
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const temperatureElement = document.getElementById("temperature");
const phaseElement = document.getElementById("phase");
const icePercentElement = document.getElementById("ice-percent");
const progressFill = document.getElementById("progress-fill");
const energyNote = document.getElementById("energy-note");
const pauseButton = document.getElementById("pause");
const warmButton = document.getElementById("warm");
const resetButton = document.getElementById("reset");
const tempTag = document.getElementById("temp-tag");
function updateUI() {
const mass = remainingIceMass();
const percent = initialMass > 0 ? (mass / initialMass) * 100 : 0;
const hasIce = mass > 0.0001;
const temperature = hasIce ? 0 : Math.min(8, postMeltHeat * 8);
temperatureElement.textContent = `${temperature.toFixed(1)} °C`;
icePercentElement.textContent = `${Math.max(0, percent).toFixed(0)}%`;
progressFill.style.transform = `scaleX(${THREE.MathUtils.clamp(percent / 100, 0, 1)})`;
if (hasIce) {
phaseElement.textContent = "Ice + water";
phaseElement.style.color = "var(--cyan)";
energyNote.textContent =
"Thermal input is absorbed as latent heat during the phase transition.";
tempTag.textContent = `${temperature.toFixed(1)} °C · MELTING`;
} else {
phaseElement.textContent = "Liquid water";
phaseElement.style.color = "var(--warm)";
energyNote.textContent =
"The transition is complete; additional heat produces sensible warming.";
tempTag.textContent = `${temperature.toFixed(1)} °C · LIQUID`;
}
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
warmButton.addEventListener("click", () => {
if (remainingIceMass() > 0.0001) {
heatBoost = Math.min(3.2, heatBoost + 1.15);
spawnHeatPulse();
} else {
postMeltHeat += 0.08;
spawnHeatPulse();
}
});
function clearTransientObjects() {
for (const droplet of droplets) scene.remove(droplet.mesh);
droplets.length = 0;
for (const ripple of ripples) {
scene.remove(ripple.mesh);
ripple.mesh.geometry.dispose();
ripple.mesh.material.dispose();
}
ripples.length = 0;
for (const pulse of pulses) {
scene.remove(pulse.mesh);
pulse.mesh.geometry.dispose();
pulse.mesh.material.dispose();
}
pulses.length = 0;
}
resetButton.addEventListener("click", () => {
for (const chunk of iceChunks) {
chunk.melt = 0;
chunk.meltMarkers.clear();
chunk.group.visible = true;
chunk.group.scale.copy(chunk.baseScale);
chunk.group.position.x = iceDefinitions[iceChunks.indexOf(chunk)].x;
chunk.group.position.z = iceDefinitions[iceChunks.indexOf(chunk)].z;
updateIceVisual(chunk);
}
heatBoost = 0;
postMeltHeat = 0;
elapsed = 0;
clearTransientObjects();
updateUI();
});
// -------------------------------------------------------------------------
// Direct orbit, zoom, touch, and keyboard camera controls
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.azimuth -= dx * 0.007;
controls.polar = THREE.MathUtils.clamp(
controls.polar + dy * 0.006,
0.58,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
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();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
5.2,
11
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
controls.azimuth = 0.42;
controls.polar = 1.12;
controls.distance = 7.7;
updateCamera();
}
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.azimuth -= 0.08;
else if (event.key === "ArrowRight") controls.azimuth += 0.08;
else if (event.key === "ArrowUp") controls.polar -= 0.06;
else if (event.key === "ArrowDown") controls.polar += 0.06;
else if (event.key === "+" || event.key === "=") {
controls.distance = Math.max(5.2, controls.distance - 0.35);
} else if (event.key === "-") {
controls.distance = Math.min(11, controls.distance + 0.35);
} else {
return;
}
controls.polar = THREE.MathUtils.clamp(controls.polar, 0.58, 1.43);
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const labelPosition = new THREE.Vector3(0.38, 3.08, 0.2);
const projectedLabel = new THREE.Vector3();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const rawDt = Math.min(clock.getDelta(), 0.05);
const dt = paused ? 0 : rawDt;
elapsed += dt;
updateSimulation(dt);
updateParticles(dt);
// Subtle motion on the water surface and its faceted wire overlay.
const surfaceOffset = Math.sin(elapsed * 0.72) * 0.006;
waterSurface.position.y = waterLevel + surfaceOffset;
surfaceFacets.position.y = waterLevel + 0.002 + surfaceOffset;
meniscus.position.y = waterLevel + 0.008 + surfaceOffset;
uiAccumulator += rawDt;
if (uiAccumulator > 0.08) {
updateUI();
uiAccumulator = 0;
}
// Project the temperature tag into screen space.
projectedLabel.copy(labelPosition).project(camera);
const labelX = (projectedLabel.x * 0.5 + 0.5) * window.innerWidth;
const labelY = (-projectedLabel.y * 0.5 + 0.5) * window.innerHeight;
tempTag.style.left = `${labelX}px`;
tempTag.style.top = `${labelY}px`;
renderer.render(scene, camera);
}
updateUI();
animate();
</script>
</body>
</html>
```