Prompt specification
Build or customize the Three.js 3D scene "Coastal land-water heating exhibit" 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: Coastal land-water heating exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coastal-land-water-heating-exhibit-x1471
Scene Description Prompt:
Warm adjacent voxel land and water slabs using an explicitly simplified thermal-storage model. Create one HTML file with Three.js from cdnjs.
Working Three.js Starter (coastal-land-water-heating-exhibit-x1471):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Thermal Shoreline</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(9, 19, 31, 0.78);
--border: rgba(164, 203, 225, 0.18);
--text: #eaf5fb;
--muted: #91a9b9;
--accent: #66d9c2;
--warm: #ff9b61;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111c;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 42%, transparent 38%, rgba(2, 8, 15, 0.3) 100%),
linear-gradient(180deg, rgba(3, 10, 18, 0.18), transparent 28%);
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.25),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px) saturate(120%);
-webkit-backdrop-filter: blur(18px) saturate(120%);
}
header {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
pointer-events: none;
max-width: 560px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 1px;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
h1 {
margin: 0;
font-size: clamp(26px, 3.5vw, 48px);
line-height: 1.03;
letter-spacing: -0.045em;
text-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}
header p {
max-width: 470px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.controls {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 8;
width: min(430px, calc(100vw - 48px));
padding: 15px;
}
.status-row,
.stats,
.button-row,
.speed-row {
display: flex;
align-items: center;
}
.status-row {
justify-content: space-between;
margin-bottom: 12px;
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
color: #b9d1dc;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.status .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #62e2aa;
box-shadow: 0 0 12px #62e2aa;
}
.status.paused .dot {
background: #ffc56c;
box-shadow: 0 0 12px #ffc56c;
}
.clock {
color: #d9e9f1;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
}
.button-row {
flex-wrap: wrap;
gap: 7px;
}
button {
appearance: none;
border: 1px solid rgba(180, 216, 235, 0.16);
border-radius: 9px;
padding: 9px 12px;
color: #dcecf4;
background: rgba(255, 255, 255, 0.045);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(180, 216, 235, 0.3);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
button.primary {
color: #06131b;
background: var(--accent);
border-color: transparent;
}
button.active {
color: #ffd4b9;
border-color: rgba(255, 139, 80, 0.42);
background: rgba(255, 122, 63, 0.13);
}
.speed-row {
gap: 12px;
margin-top: 13px;
color: var(--muted);
font-size: 11px;
}
.speed-row label {
white-space: nowrap;
}
input[type="range"] {
width: 100%;
accent-color: var(--accent);
cursor: pointer;
}
#speedValue {
min-width: 40px;
color: #d8e9f0;
font-family: "SFMono-Regular", Consolas, monospace;
text-align: right;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(174, 210, 230, 0.1);
}
.stat span {
display: block;
margin-bottom: 3px;
color: #78909e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
display: block;
color: #e9f5fa;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 13px;
font-weight: 600;
}
.model {
position: fixed;
top: 112px;
right: 24px;
z-index: 7;
width: 310px;
max-height: calc(100vh - 235px);
overflow: auto;
padding: 0 16px 15px;
scrollbar-width: thin;
scrollbar-color: #31495a transparent;
}
.model summary {
padding: 15px 0 13px;
color: #e9f5fa;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.03em;
cursor: pointer;
user-select: none;
}
.model summary::marker {
color: var(--accent);
}
.equation {
margin: 2px 0 13px;
padding: 12px;
border: 1px solid rgba(102, 217, 194, 0.14);
border-radius: 10px;
color: #b9f0e5;
background: rgba(102, 217, 194, 0.055);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 11px;
line-height: 1.55;
overflow-wrap: anywhere;
}
.model h3 {
margin: 13px 0 8px;
color: #8099a8;
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.parameter {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 5px 0;
color: #a9bdc8;
font-size: 10px;
border-bottom: 1px solid rgba(174, 210, 230, 0.055);
}
.parameter b {
color: #dcecf4;
font-family: "SFMono-Regular", Consolas, monospace;
font-weight: 500;
text-align: right;
}
.assumptions {
margin: 12px 0 0;
padding-left: 17px;
color: #8198a6;
font-size: 10px;
line-height: 1.65;
}
.legend {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 7;
width: 310px;
padding: 13px 15px;
}
.legend-title {
margin-bottom: 9px;
color: #8ea6b4;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 42px 1fr;
align-items: center;
gap: 9px;
margin-top: 7px;
color: #b7c9d3;
font-size: 9px;
}
.gradient {
height: 7px;
border-radius: 20px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.gradient.land {
background: linear-gradient(
90deg,
#5f4638,
#a9653f 30%,
#d99145 55%,
#f4b454 75%,
#ff6a48
);
}
.gradient.water {
background: linear-gradient(
90deg,
#123b80,
#1476b9 30%,
#16abc0 55%,
#66d9bd 75%,
#d8e879
);
}
.legend-scale {
display: flex;
justify-content: space-between;
margin: 5px 0 0 51px;
color: #6f8795;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 8px;
}
.hint {
position: fixed;
left: 50%;
bottom: 25px;
z-index: 4;
transform: translateX(-50%);
color: rgba(174, 200, 214, 0.62);
font-size: 10px;
pointer-events: none;
white-space: nowrap;
}
.tooltip {
position: fixed;
z-index: 20;
display: none;
min-width: 185px;
padding: 11px 12px;
border: 1px solid rgba(173, 221, 242, 0.22);
border-radius: 10px;
background: rgba(6, 15, 24, 0.93);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.35);
pointer-events: none;
backdrop-filter: blur(12px);
}
.tooltip strong {
display: block;
margin-bottom: 6px;
color: #eff9fc;
font-size: 11px;
}
.tooltip span {
display: block;
margin-top: 3px;
color: #90a8b7;
font-size: 10px;
}
.tooltip b {
color: #d9edf5;
font-family: "SFMono-Regular", Consolas, monospace;
font-weight: 600;
}
@media (max-width: 900px) {
header {
top: 17px;
left: 17px;
}
header p {
display: none;
}
.model {
top: 96px;
right: 14px;
width: 270px;
max-height: 45vh;
}
.controls {
left: 14px;
bottom: 14px;
width: min(390px, calc(100vw - 28px));
}
.legend {
right: 14px;
bottom: 14px;
width: 270px;
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
h1 {
max-width: 340px;
font-size: 27px;
}
.model {
top: 91px;
width: 230px;
max-height: 34vh;
padding-inline: 12px;
}
.legend {
display: none;
}
.controls {
padding: 12px;
}
.stats {
gap: 4px;
}
.stat strong {
font-size: 11px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel land and water thermal simulation"></canvas>
<div class="vignette"></div>
<header>
<div class="eyebrow">Thermal storage study</div>
<h1>Voxel<br />Thermal Shoreline</h1>
<p>
A visibly simplified heat-storage model warms neighboring land and water
voxels. Hover to inspect a cell; drag to orbit and scroll to zoom.
</p>
</header>
<section class="controls glass" aria-label="Simulation controls">
<div class="status-row">
<div id="status" class="status">
<span class="dot"></span>
<span id="statusText">Running</span>
</div>
<div id="clock" class="clock">00:00.0</div>
</div>
<div class="button-row">
<button id="pauseButton" class="primary">Pause</button>
<button id="warmButton" class="active" aria-pressed="true">
Warm interface: On
</button>
<button id="resetButton">Reset</button>
<button id="cameraButton">Reset view</button>
</div>
<div class="speed-row">
<label for="speed">Model speed</label>
<input id="speed" type="range" min="0.5" max="12" step="0.5" value="5" />
<span id="speedValue">5×</span>
</div>
<div class="stats">
<div class="stat">
<span>Land average</span>
<strong id="landAverage">—</strong>
</div>
<div class="stat">
<span>Water average</span>
<strong id="waterAverage">—</strong>
</div>
<div class="stat">
<span>Shore flux</span>
<strong id="shoreFlux">—</strong>
</div>
</div>
</section>
<details class="model glass" open>
<summary>Explicitly simplified model</summary>
<div class="equation">
C<sub>i</sub> dT<sub>i</sub>/dt =
Σ G<sub>ij</sub>(T<sub>j</sub> − T<sub>i</sub>)
+ P<sub>i</sub> + h(T<sub>air</sub> − T<sub>i</sub>)
</div>
<h3>Storage and contacts</h3>
<div class="parameter">
<span>Land heat capacity C</span><b>1.00 u/K</b>
</div>
<div class="parameter">
<span>Water heat capacity C</span><b>2.50 u/K</b>
</div>
<div class="parameter">
<span>Land–land contact G</span><b>0.28 u/K</b>
</div>
<div class="parameter">
<span>Water–water contact G</span><b>0.24 u/K</b>
</div>
<div class="parameter">
<span>Land–water contact G</span><b>0.16 u/K</b>
</div>
<h3>Boundary conditions</h3>
<div class="parameter">
<span>Air temperature</span><b>8 °C</b>
</div>
<div class="parameter">
<span>Air coupling h</span><b>0.014 u/K</b>
</div>
<div class="parameter">
<span>Interface heater</span><b>8 voxels</b>
</div>
<div class="parameter">
<span>Maximum heater P</span><b>0.22 u/s</b>
</div>
<div class="parameter">
<span>Integration step</span><b>0.10 model s</b>
</div>
<ul class="assumptions">
<li>Relative units are scaled for visual legibility, not engineering prediction.</li>
<li>The heater is applied symmetrically to land and water interface cells and fades above 30 °C.</li>
<li>No fluid advection, phase change, radiation, moisture transport, or groundwater flow.</li>
</ul>
</details>
<section class="legend glass" aria-label="Temperature legends">
<div class="legend-title">Voxel temperature · 8–36 °C</div>
<div class="legend-row">
<span>Land</span>
<div class="gradient land"></div>
</div>
<div class="legend-row">
<span>Water</span>
<div class="gradient water"></div>
</div>
<div class="legend-scale">
<span>8</span>
<span>14</span>
<span>20</span>
<span>27</span>
<span>36</span>
</div>
</section>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</div>
<div id="tooltip" class="tooltip"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and simplified model
// -------------------------------------------------------------------------
const NX = 18;
const NZ = 8;
const NY = 2;
const LAND_COLUMNS = 9;
const VOXEL_EDGE = 0.82;
const VOXEL_PITCH = 0.94;
const MODEL = Object.freeze({
timestep: 0.1,
ambientTemperature: 8,
airCoupling: 0.014,
maximumSource: 0.22,
heaterLimit: 30,
heaterFadeRange: 6,
capacities: {
land: 1.0,
water: 2.5
},
conductances: {
land: 0.28,
water: 0.24,
shore: 0.16
}
});
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111c);
scene.fog = new THREE.FogExp2(0x07111c, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls: no examples or addons are imported.
const cameraState = {
yaw: 0.67,
pitch: 0.57,
radius: 22,
target: new THREE.Vector3(0, 0.7, 0)
};
function updateCamera() {
const s = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x +
cameraState.radius * s * Math.sin(cameraState.yaw),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.pitch),
cameraState.target.z +
cameraState.radius * s * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0x9ad9ff, 0x182017, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6c5, 3.2);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x58bfe9, 1.2);
rimLight.position.set(10, 7, -12);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x08131e,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.34;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(42, 42, 0x234154, 0x142a39);
grid.position.y = -0.325;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
const slabWidth = LAND_COLUMNS * VOXEL_PITCH - 0.08;
const slabDepth = NZ * VOXEL_PITCH - 0.08;
const landCenterX = -LAND_COLUMNS * VOXEL_PITCH * 0.5 + VOXEL_PITCH * 0.5;
const waterCenterX = -landCenterX;
const landBase = new THREE.Mesh(
new THREE.BoxGeometry(slabWidth, 0.28, slabDepth),
new THREE.MeshStandardMaterial({
color: 0x30241d,
roughness: 0.94
})
);
landBase.position.set(landCenterX, -0.17, 0);
landBase.receiveShadow = true;
scene.add(landBase);
const waterBase = new THREE.Mesh(
new THREE.BoxGeometry(slabWidth, 0.28, slabDepth),
new THREE.MeshStandardMaterial({
color: 0x0b2739,
roughness: 0.68,
metalness: 0.08
})
);
waterBase.position.set(waterCenterX, -0.17, 0);
waterBase.receiveShadow = true;
scene.add(waterBase);
// -------------------------------------------------------------------------
// Voxel data
// -------------------------------------------------------------------------
const cellAt = new Array(NX * NZ * NY).fill(null);
const cells = [];
const edges = [];
function cellId(x, y, z) {
return (y * NZ + z) * NX + x;
}
for (let y = 0; y < NY; y++) {
for (let z = 0; z < NZ; z++) {
for (let x = 0; x < NX; x++) {
// The water slab is one voxel deep; land is two voxels deep.
if (x >= LAND_COLUMNS && y > 0) continue;
const material = x < LAND_COLUMNS ? "land" : "water";
const centerDistance = Math.abs(z - (NZ - 1) * 0.5);
const normalizedDistance = centerDistance / ((NZ - 1) * 0.5);
let initialTemperature;
if (material === "land") {
initialTemperature =
15.0 + 0.6 * (1 - normalizedDistance);
} else {
initialTemperature =
8.3 + 0.2 * (1 - normalizedDistance);
}
const cell = {
id: cellId(x, y, z),
x,
y,
z,
material,
temperature: initialTemperature,
initialTemperature,
capacity: MODEL.capacities[material],
position: new THREE.Vector3(
(x - (NX - 1) * 0.5) * VOXEL_PITCH,
VOXEL_EDGE * 0.5 + y * VOXEL_EDGE + 0.02,
(z - (NZ - 1) * 0.5) * VOXEL_PITCH
),
isSource: false,
mesh: null,
meshIndex: -1
};
cells.push(cell);
cellAt[cell.id] = cell;
}
}
}
// Symmetric heater around the central shoreline.
for (const cell of cells) {
cell.isSource =
cell.y === 0 &&
(cell.x === LAND_COLUMNS - 1 || cell.x === LAND_COLUMNS) &&
(cell.z === 3 || cell.z === 4);
}
function conductanceBetween(a, b) {
if (a.material !== b.material) {
return MODEL.conductances.shore;
}
return a.material === "land"
? MODEL.conductances.land
: MODEL.conductances.water;
}
function connect(a, b) {
if (!a || !b) return;
edges.push({
a,
b,
conductance: conductanceBetween(a, b)
});
}
for (const cell of cells) {
connect(cell, cellAt[cellId(cell.x + 1, cell.y, cell.z)]);
connect(cell, cellAt[cellId(cell.x, cell.y, cell.z + 1)]);
connect(cell, cellAt[cellId(cell.x, cell.y + 1, cell.z)]);
}
// -------------------------------------------------------------------------
// Temperature palettes and instanced voxel meshes
// -------------------------------------------------------------------------
const palettes = {
land: [
{ value: 8, color: new THREE.Color(0x5f4638) },
{ value: 14, color: new THREE.Color(0xa9653f) },
{ value: 20, color: new THREE.Color(0xd99145) },
{ value: 27, color: new THREE.Color(0xf4b454) },
{ value: 36, color: new THREE.Color(0xff6a48) }
],
water: [
{ value: 8, color: new THREE.Color(0x123b80) },
{ value: 14, color: new THREE.Color(0x1476b9) },
{ value: 20, color: new THREE.Color(0x16abc0) },
{ value: 27, color: new THREE.Color(0x66d9bd) },
{ value: 36, color: new THREE.Color(0xd8e879) }
]
};
const temporaryColor = new THREE.Color();
function temperatureColor(material, temperature, output) {
const stops = palettes[material];
if (temperature <= stops[0].value) {
return output.copy(stops[0].color);
}
for (let i = 1; i < stops.length; i++) {
if (temperature <= stops[i].value) {
const previous = stops[i - 1];
const next = stops[i];
const amount =
(temperature - previous.value) /
(next.value - previous.value);
return output
.copy(previous.color)
.lerp(next.color, THREE.MathUtils.clamp(amount, 0, 1));
}
}
return output.copy(stops[stops.length - 1].color);
}
const boxGeometry = new THREE.BoxGeometry(
VOXEL_EDGE,
VOXEL_EDGE,
VOXEL_EDGE
);
const landMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.87,
metalness: 0.015
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.22,
metalness: 0.08,
transparent: true,
opacity: 0.81,
depthWrite: true
});
function createVoxelMesh(material, materialCells) {
const mesh = new THREE.InstancedMesh(
boxGeometry,
material === "land" ? landMaterial : waterMaterial,
materialCells.length
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
mesh.userData.material = material;
mesh.userData.cells = materialCells;
const transform = new THREE.Object3D();
materialCells.forEach((cell, index) => {
cell.mesh = mesh;
cell.meshIndex = index;
transform.position.copy(cell.position);
transform.updateMatrix();
mesh.setMatrixAt(index, transform.matrix);
temperatureColor(cell.material, cell.temperature, temporaryColor);
mesh.setColorAt(index, temporaryColor);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
scene.add(mesh);
return mesh;
}
const landCells = cells.filter((cell) => cell.material === "land");
const waterCells = cells.filter((cell) => cell.material === "water");
const landMesh = createVoxelMesh("land", landCells);
const waterMesh = createVoxelMesh("water", waterCells);
// A faint animated surface gives the voxel water a readable shoreline.
const waterSurfaceGeometry = new THREE.PlaneGeometry(
slabWidth,
slabDepth,
24,
16
);
waterSurfaceGeometry.rotateX(-Math.PI / 2);
const waterSurfaceBase = Float32Array.from(
waterSurfaceGeometry.attributes.position.array
);
const waterSurface = new THREE.Mesh(
waterSurfaceGeometry,
new THREE.MeshStandardMaterial({
color: 0x68d8ef,
roughness: 0.16,
metalness: 0.12,
transparent: true,
opacity: 0.12,
depthWrite: false,
side: THREE.DoubleSide
})
);
waterSurface.position.set(waterCenterX, VOXEL_EDGE + 0.055, 0);
scene.add(waterSurface);
// Warm boundary marker.
const heaterMaterial = new THREE.MeshBasicMaterial({
color: 0xff8b49,
transparent: true,
opacity: 0.55,
depthWrite: false
});
const heaterGlow = new THREE.Mesh(
new THREE.BoxGeometry(0.055, VOXEL_EDGE * 0.78, 1.3),
heaterMaterial
);
heaterGlow.position.set(0, VOXEL_EDGE * 0.42, 0);
scene.add(heaterGlow);
const heaterRingMaterial = new THREE.MeshBasicMaterial({
color: 0xffb06b,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const heaterRing = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.035, 10, 48),
heaterRingMaterial
);
heaterRing.rotation.x = Math.PI / 2;
heaterRing.position.set(0, VOXEL_EDGE + 0.095, 0);
scene.add(heaterRing);
const heaterLight = new THREE.PointLight(0xff7d38, 22, 5, 2);
heaterLight.position.set(0, 1.15, 0);
scene.add(heaterLight);
// -------------------------------------------------------------------------
// Canvas-texture labels
// -------------------------------------------------------------------------
function makeLabel(text, color) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 96;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(5, 14, 23, 0.78)";
context.fillRect(0, 0, 512, 96);
context.strokeStyle = color;
context.lineWidth = 2;
context.strokeRect(2, 2, 508, 92);
context.fillStyle = color;
context.font = "700 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.4, 0.64, 1);
sprite.renderOrder = 10;
return sprite;
}
const landLabel = makeLabel("LAND · 144 VOXELS", "#f4b454");
landLabel.position.set(landCenterX, 2.32, -4.45);
scene.add(landLabel);
const waterLabel = makeLabel("WATER · 72 VOXELS", "#58d7e7");
waterLabel.position.set(waterCenterX, 1.48, -4.45);
scene.add(waterLabel);
const heaterLabel = makeLabel("WARM BOUNDARY", "#ff9b61");
heaterLabel.scale.set(2.35, 0.44, 1);
heaterLabel.position.set(0, 2.55, 0.25);
scene.add(heaterLabel);
// -------------------------------------------------------------------------
// Thermal simulation
// -------------------------------------------------------------------------
let heating = true;
let paused = false;
let simulationSpeed = 5;
let simulationTime = 0;
let simulationAccumulator = 0;
const netFlux = new Float32Array(NX * NZ * NY);
function simulateStep(dt) {
netFlux.fill(0);
// Conservative exchange across every connected voxel pair.
for (const edge of edges) {
const flux =
edge.conductance *
(edge.b.temperature - edge.a.temperature);
netFlux[edge.a.id] += flux;
netFlux[edge.b.id] -= flux;
}
for (const cell of cells) {
const airFlux =
MODEL.airCoupling *
(MODEL.ambientTemperature - cell.temperature);
let heaterFlux = 0;
if (heating && cell.isSource) {
const fade = THREE.MathUtils.clamp(
(MODEL.heaterLimit - cell.temperature) /
MODEL.heaterFadeRange,
0,
1
);
heaterFlux = MODEL.maximumSource * fade;
}
const totalFlux =
netFlux[cell.id] + airFlux + heaterFlux;
cell.temperature +=
(totalFlux / cell.capacity) * dt;
}
simulationTime += dt;
}
function updateVoxelColors() {
for (const cell of cells) {
temperatureColor(
cell.material,
cell.temperature,
temporaryColor
);
cell.mesh.setColorAt(cell.meshIndex, temporaryColor);
}
if (landMesh.instanceColor) landMesh.instanceColor.needsUpdate = true;
if (waterMesh.instanceColor) waterMesh.instanceColor.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Interface controls and statistics
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pauseButton");
const warmButton = document.getElementById("warmButton");
const resetButton = document.getElementById("resetButton");
const cameraButton = document.getElementById("cameraButton");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speedValue");
const status = document.getElementById("status");
const statusText = document.getElementById("statusText");
const clock = document.getElementById("clock");
const landAverage = document.getElementById("landAverage");
const waterAverage = document.getElementById("waterAverage");
const shoreFluxOutput = document.getElementById("shoreFlux");
function updateControlLabels() {
pauseButton.textContent = paused ? "Resume" : "Pause";
warmButton.textContent = `Warm interface: ${heating ? "On" : "Off"}`;
warmButton.classList.toggle("active", heating);
warmButton.setAttribute("aria-pressed", String(heating));
status.classList.toggle("paused", paused);
statusText.textContent = paused
? "Paused"
: heating
? "Running · warming"
: "Running · passive";
}
pauseButton.addEventListener("click", () => {
paused = !paused;
updateControlLabels();
});
warmButton.addEventListener("click", () => {
heating = !heating;
updateControlLabels();
});
resetButton.addEventListener("click", () => {
for (const cell of cells) {
cell.temperature = cell.initialTemperature;
}
simulationTime = 0;
simulationAccumulator = 0;
heating = true;
paused = false;
updateControlLabels();
updateVoxelColors();
updateStatistics();
});
cameraButton.addEventListener("click", () => {
cameraState.yaw = 0.67;
cameraState.pitch = 0.57;
cameraState.radius = 22;
cameraState.target.set(0, 0.7, 0);
updateCamera();
});
speedInput.addEventListener("input", () => {
simulationSpeed = Number(speedInput.value);
speedValue.textContent = `${simulationSpeed}×`;
});
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remaining = (seconds % 60).toFixed(1).padStart(4, "0");
return `${String(minutes).padStart(2, "0")}:${remaining}`;
}
function updateStatistics() {
let landSum = 0;
let waterSum = 0;
let landCount = 0;
let waterCount = 0;
let shoreFlux = 0;
for (const cell of cells) {
if (cell.material === "land") {
landSum += cell.temperature;
landCount++;
} else {
waterSum += cell.temperature;
waterCount++;
}
}
for (const edge of edges) {
if (edge.a.material !== edge.b.material) {
const land = edge.a.material === "land" ? edge.a : edge.b;
const water = edge.a.material === "water" ? edge.a : edge.b;
// Positive values mean heat is moving from land into water.
shoreFlux +=
edge.conductance *
(water.temperature - land.temperature);
}
}
landAverage.textContent = `${(landSum / landCount).toFixed(1)} °C`;
waterAverage.textContent = `${(waterSum / waterCount).toFixed(1)} °C`;
shoreFluxOutput.textContent = `${shoreFlux.toFixed(2)} u/s`;
clock.textContent = formatTime(simulationTime);
}
updateControlLabels();
updateStatistics();
// -------------------------------------------------------------------------
// Hover inspection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const tooltip = document.getElementById("tooltip");
const highlightGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(
VOXEL_EDGE + 0.035,
VOXEL_EDGE + 0.035,
VOXEL_EDGE + 0.035
)
);
const highlight = new THREE.LineSegments(
highlightGeometry,
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.88
})
);
highlight.visible = false;
scene.add(highlight);
function inspectPointer(event) {
const bounds = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
[landMesh, waterMesh],
false
);
if (intersections.length === 0) {
highlight.visible = false;
tooltip.style.display = "none";
return;
}
const hit = intersections[0];
const cell = hit.object.userData.cells[hit.instanceId];
if (!cell) return;
highlight.visible = true;
highlight.position.copy(cell.position);
const sourceText = cell.isSource
? "Yes · heater target"
: "No";
tooltip.innerHTML = `
<strong>${cell.material === "land" ? "Land" : "Water"} voxel</strong>
<span>X ${cell.x} · Y ${cell.y} · Z ${cell.z}</span>
<span>Temperature <b>${cell.temperature.toFixed(2)} °C</b></span>
<span>Storage <b>${cell.capacity.toFixed(2)} u/K</b></span>
<span>Heater input <b>${sourceText}</b></span>
`;
const left = Math.min(
event.clientX + 16,
window.innerWidth - 220
);
const top = Math.min(
event.clientY + 16,
window.innerHeight - 135
);
tooltip.style.left = `${left}px`;
tooltip.style.top = `${top}px`;
tooltip.style.display = "block";
}
// -------------------------------------------------------------------------
// Direct pointer camera controls
// -------------------------------------------------------------------------
const pointerControl = {
active: false,
pointerId: -1,
mode: "orbit",
lastX: 0,
lastY: 0,
moved: false
};
canvas.addEventListener("pointerdown", (event) => {
pointerControl.active = true;
pointerControl.pointerId = event.pointerId;
pointerControl.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
pointerControl.lastX = event.clientX;
pointerControl.lastY = event.clientY;
pointerControl.moved = false;
canvas.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (pointerControl.active) {
const dx = event.clientX - pointerControl.lastX;
const dy = event.clientY - pointerControl.lastY;
pointerControl.lastX = event.clientX;
pointerControl.lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) {
pointerControl.moved = true;
}
if (pointerControl.mode === "orbit") {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.18,
1.35
);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = cameraState.radius * 0.0015;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-8,
8
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
-0.5,
4
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-7,
7
);
}
highlight.visible = false;
tooltip.style.display = "none";
return;
}
inspectPointer(event);
});
function endPointer(event) {
if (!pointerControl.active) return;
if (
canvas.hasPointerCapture &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
pointerControl.active = false;
pointerControl.pointerId = -1;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", () => {
if (!pointerControl.active) {
highlight.visible = false;
tooltip.style.display = "none";
}
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8,
40
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
let previousTime = performance.now();
let statisticsTimer = 0;
function animate(now) {
requestAnimationFrame(animate);
const realDelta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
simulationAccumulator += realDelta * simulationSpeed;
let steps = 0;
while (
simulationAccumulator >= MODEL.timestep &&
steps < 80
) {
simulateStep(MODEL.timestep);
simulationAccumulator -= MODEL.timestep;
steps++;
}
}
updateVoxelColors();
updateCamera();
const elapsed = now * 0.001;
const surfacePositions = waterSurfaceGeometry.attributes.position.array;
for (let i = 0; i < surfacePositions.length; i += 3) {
const x = waterSurfaceBase[i];
const z = waterSurfaceBase[i + 2];
surfacePositions[i + 1] =
waterSurfaceBase[i + 1] +
Math.sin(x * 1.6 + elapsed * 1.15) * 0.012 +
Math.cos(z * 1.9 - elapsed * 0.8) * 0.008;
}
waterSurfaceGeometry.attributes.position.needsUpdate = true;
waterSurfaceGeometry.computeVertexNormals();
waterMaterial.opacity =
0.79 + Math.sin(elapsed * 0.7) * 0.025;
const heaterPulse = 1 + Math.sin(elapsed * 3.2) * 0.11;
heaterRing.scale.setScalar(heaterPulse);
heaterRing.rotation.z = elapsed * 0.18;
heaterMaterial.opacity = heating
? 0.43 + Math.sin(elapsed * 3.2) * 0.12
: 0.12;
heaterRingMaterial.opacity = heating
? 0.56 + Math.sin(elapsed * 3.2) * 0.15
: 0.14;
heaterLight.intensity = heating
? 20 + Math.sin(elapsed * 3.2) * 5
: 2;
statisticsTimer += realDelta;
if (statisticsTimer >= 0.12) {
statisticsTimer = 0;
updateStatistics();
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```