Prompt specification
Build or customize the Three.js 3D scene "Cooling bottle comparison" 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: Cooling bottle comparison
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cooling-bottle-comparison-x0038
Scene Description Prompt:
Animate a qualitative low-poly cooling comparison of covered and uncovered sealed bottles under equal conditions. Three.js from cdnjs, one HTML file.
Working Three.js Starter (cooling-bottle-comparison-x0038):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Covered vs. Uncovered — Cooling Comparison</title>
<style>
:root {
--ink: #17313d;
--muted: #607985;
--panel: rgba(250, 253, 252, 0.88);
--line: rgba(23, 49, 61, 0.12);
--covered: #279fc9;
--uncovered: #f47d45;
--cold: #42b8e8;
--hot: #ff583f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e8;
color: var(--ink);
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%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 26%),
radial-gradient(circle at 50% 40%, transparent 45%, rgba(36, 66, 73, 0.09));
}
.header {
position: fixed;
z-index: 5;
top: 25px;
left: 28px;
max-width: 470px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #3f6875;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 3px;
border-radius: 99px;
background: linear-gradient(90deg, var(--covered), var(--uncovered));
content: "";
}
h1 {
margin: 0;
font-size: clamp(27px, 3.1vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 420px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.model-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(23, 49, 61, 0.1);
border-radius: 999px;
background: rgba(255, 255, 255, 0.58);
color: #4a6a75;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.model-badge span {
width: 6px;
height: 6px;
border-radius: 50%;
background: #50b6c8;
box-shadow: 0 0 0 4px rgba(80, 182, 200, 0.13);
}
.controls {
position: fixed;
z-index: 10;
top: 24px;
right: 26px;
display: flex;
align-items: center;
gap: 8px;
}
.button-row {
display: flex;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 9px 30px rgba(46, 73, 80, 0.08);
backdrop-filter: blur(12px);
}
.button-row button {
min-width: 39px;
height: 39px;
padding: 0 13px;
border: 0;
border-right: 1px solid var(--line);
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: background 150ms ease, color 150ms ease;
}
.button-row button:last-child {
border-right: 0;
}
.button-row button:hover {
background: rgba(39, 159, 201, 0.1);
color: #147ca3;
}
.button-row button:focus-visible {
outline: 2px solid var(--covered);
outline-offset: -3px;
}
#play {
min-width: 78px;
}
.camera-hint {
position: fixed;
z-index: 5;
right: 29px;
bottom: 23px;
color: rgba(38, 69, 80, 0.68);
font-size: 11px;
pointer-events: none;
}
.chart-card,
.readout {
position: fixed;
z-index: 7;
bottom: 23px;
border: 1px solid rgba(23, 49, 61, 0.1);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 16px 48px rgba(44, 70, 78, 0.11);
backdrop-filter: blur(15px);
}
.chart-card {
left: 25px;
width: min(650px, calc(100vw - 440px));
min-width: 510px;
padding: 15px 18px 12px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-bottom: 7px;
}
.panel-title strong {
font-size: 12px;
letter-spacing: 0.02em;
}
.legend {
display: flex;
align-items: center;
gap: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.legend i {
display: inline-block;
width: 14px;
height: 3px;
border-radius: 99px;
}
.legend .covered-line {
background: var(--covered);
}
.legend .uncovered-line {
background: var(--uncovered);
}
.chart {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.chart text {
fill: #6f858e;
font-family: inherit;
font-size: 9px;
}
.readout {
right: 25px;
width: 350px;
padding: 17px 18px 15px;
}
.readout-head {
display: flex;
align-items: center;
gap: 8px;
padding-bottom: 12px;
border-bottom: 1px solid var(--line);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #49b98a;
box-shadow: 0 0 0 4px rgba(73, 185, 138, 0.13);
}
.status-dot.paused {
background: #e5a244;
box-shadow: 0 0 0 4px rgba(229, 162, 68, 0.14);
}
.status-dot.complete {
background: var(--covered);
box-shadow: 0 0 0 4px rgba(39, 159, 201, 0.14);
}
#clock {
margin-left: auto;
color: var(--muted);
font-variant-numeric: tabular-nums;
letter-spacing: 0;
}
.temperature-row {
display: grid;
grid-template-columns: 92px 67px 1fr;
align-items: center;
gap: 10px;
min-height: 46px;
}
.sample-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 800;
}
.sample-name i {
width: 9px;
height: 9px;
border-radius: 3px;
}
.sample-name .covered-dot {
background: var(--covered);
}
.sample-name .uncovered-dot {
background: var(--uncovered);
}
.temperature {
font-size: 16px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.02em;
}
.bar {
height: 5px;
overflow: hidden;
border-radius: 99px;
background: #e5edef;
}
.bar span {
display: block;
width: 100%;
height: 100%;
border-radius: inherit;
transition: width 80ms linear;
}
#coveredBar {
background: linear-gradient(90deg, #42b8e8, #279fc9);
}
#uncoveredBar {
background: linear-gradient(90deg, #ffb154, #f47d45);
}
.gap-copy {
margin: 6px 0 12px;
padding: 9px 10px;
border-radius: 10px;
background: rgba(39, 159, 201, 0.08);
color: #476773;
font-size: 11px;
text-align: center;
}
.gap-copy strong {
color: #197d9f;
font-variant-numeric: tabular-nums;
}
.conditions {
display: flex;
flex-wrap: wrap;
gap: 5px 10px;
color: #78909a;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.conditions span::before {
margin-right: 5px;
color: #5eb4c7;
content: "•";
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.bottle-tag {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 132px;
padding: 8px 10px;
border: 1px solid rgba(23, 49, 61, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 8px 24px rgba(40, 68, 76, 0.09);
transform: translate(-50%, -115%);
backdrop-filter: blur(9px);
transition: opacity 120ms linear;
}
.bottle-tag i {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
}
#tag-covered i {
background: var(--covered);
box-shadow: 0 0 0 4px rgba(39, 159, 201, 0.12);
}
#tag-uncovered i {
background: var(--uncovered);
box-shadow: 0 0 0 4px rgba(244, 125, 69, 0.12);
}
.bottle-tag strong {
display: block;
font-size: 10px;
letter-spacing: 0.08em;
}
.bottle-tag small {
display: block;
margin-top: 2px;
color: #78909a;
font-size: 9px;
}
@media (max-width: 1000px) {
.chart-card {
display: none;
}
.camera-hint {
display: none;
}
}
@media (max-width: 680px) {
.header {
top: 17px;
left: 17px;
max-width: calc(100vw - 34px);
}
h1 {
max-width: 270px;
font-size: 29px;
}
.subtitle {
max-width: 285px;
font-size: 11px;
}
.model-badge {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
}
.readout {
right: 14px;
bottom: 64px;
left: 14px;
width: auto;
padding: 13px 14px;
}
.temperature-row {
min-height: 36px;
}
.gap-copy {
margin: 4px 0 9px;
}
.conditions {
display: none;
}
.bottle-tag {
min-width: 108px;
padding: 6px 8px;
}
.bottle-tag small {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Cooling comparison</div>
<h1>Covered vs.<br />uncovered.</h1>
<p class="subtitle">
An insulating cover slows the transfer of heat. Both sealed bottles begin
under identical conditions.
</p>
<div class="model-badge"><span></span>Qualitative model · not a measurement</div>
</header>
<div class="controls" aria-label="Animation and camera controls">
<div class="button-row">
<button id="play" type="button" aria-pressed="false">Pause</button>
<button id="restart" type="button">Restart</button>
</div>
<div class="button-row">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="cameraReset" type="button" aria-label="Reset camera">Reset</button>
</div>
</div>
<div id="labels">
<div class="bottle-tag" id="tag-covered">
<i></i>
<div>
<strong>COVERED</strong>
<small>Insulated sleeve</small>
</div>
</div>
<div class="bottle-tag" id="tag-uncovered">
<i></i>
<div>
<strong>UNCOVERED</strong>
<small>Exposed surface</small>
</div>
</div>
</div>
<section class="chart-card" aria-label="Illustrative cooling graph">
<div class="panel-title">
<strong>Illustrative temperature curve</strong>
<div class="legend">
<span><i class="covered-line"></i>Covered</span>
<span><i class="uncovered-line"></i>Uncovered</span>
</div>
</div>
<svg class="chart" viewBox="0 0 640 165" role="img"
aria-label="Covered bottle cools more slowly than uncovered bottle">
<defs>
<linearGradient id="coveredArea" x1="0" x2="0" y1="0" y2="1">
<stop offset="0" stop-color="#279fc9" stop-opacity="0.19" />
<stop offset="1" stop-color="#279fc9" stop-opacity="0" />
</linearGradient>
</defs>
<g stroke="#dfe8e9" stroke-width="1">
<line x1="42" y1="12" x2="618" y2="12" />
<line x1="42" y1="72" x2="618" y2="72" />
<line x1="42" y1="132" x2="618" y2="132" />
</g>
<line x1="42" y1="124" x2="618" y2="124"
stroke="#83a0aa" stroke-width="1" stroke-dasharray="4 5" />
<text x="7" y="15">50°</text>
<text x="13" y="75">35°</text>
<text x="13" y="135">20°</text>
<text x="619" y="126" text-anchor="end">Room temperature</text>
<path id="coveredAreaPath" fill="url(#coveredArea)" />
<path id="coveredPath" fill="none" stroke="#279fc9"
stroke-width="3" stroke-linecap="round" />
<path id="uncoveredPath" fill="none" stroke="#f47d45"
stroke-width="3" stroke-linecap="round" />
<line id="currentLine" y1="8" y2="136"
stroke="#829ba4" stroke-width="1" stroke-dasharray="3 4" />
<circle id="coveredMarker" r="5" fill="#fff" stroke="#279fc9" stroke-width="3" />
<circle id="uncoveredMarker" r="5" fill="#fff" stroke="#f47d45" stroke-width="3" />
<text x="42" y="154" text-anchor="middle">0 s</text>
<text x="330" y="154" text-anchor="middle">20 s</text>
<text x="618" y="154" text-anchor="middle">40 s</text>
</svg>
</section>
<section class="readout" aria-label="Live comparison">
<div class="readout-head">
<span class="status-dot" id="statusDot"></span>
<span id="status">Live cool-down</span>
<span id="clock">0.0 / 40 s</span>
</div>
<div class="temperature-row">
<div class="sample-name">
<i class="covered-dot"></i>Covered
</div>
<div class="temperature" id="coveredTemp">46.0°C</div>
<div class="bar"><span id="coveredBar"></span></div>
</div>
<div class="temperature-row">
<div class="sample-name">
<i class="uncovered-dot"></i>Uncovered
</div>
<div class="temperature" id="uncoveredTemp">46.0°C</div>
<div class="bar"><span id="uncoveredBar"></span></div>
</div>
<div class="gap-copy">
The covered bottle is <strong id="gap">0.0°C warmer</strong>
</div>
<div class="conditions">
<span>Same volume</span>
<span>Same seal</span>
<span>Same start</span>
<span>Same airflow</span>
</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll or pinch to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.getElementById("scene");
// ------------------------------------------------------------
// Renderer, scene, lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e8);
scene.fog = new THREE.Fog(0xdce9e8, 12, 25);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 1.3, 0);
let cameraTheta = 0;
let cameraPhi = 1.22;
let cameraRadius = window.innerWidth < 700 ? 12.4 : 9.2;
function defaultRadius() {
return window.innerWidth < 700 ? 12.4 : 9.2;
}
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xe8f8ff, 0xa2aaa0, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff2df, 2.7);
keyLight.position.set(4.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbcecff, 1.15);
fillLight.position.set(-5, 4, 1);
scene.add(fillLight);
const coveredSpot = new THREE.PointLight(0xdff8ff, 13, 7, 2);
coveredSpot.position.set(-2.1, 4.1, 2.1);
scene.add(coveredSpot);
const uncoveredSpot = new THREE.PointLight(0xdff8ff, 13, 7, 2);
uncoveredSpot.position.set(2.1, 4.1, 2.1);
scene.add(uncoveredSpot);
// ------------------------------------------------------------
// Low-poly environment
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 20),
new THREE.MeshStandardMaterial({
color: 0xd5e2e1,
roughness: 0.94
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(8, 0.24, 3.6),
new THREE.MeshStandardMaterial({
color: 0xf2eee1,
roughness: 0.82
})
);
plinth.position.y = 0.12;
plinth.castShadow = true;
plinth.receiveShadow = true;
scene.add(plinth);
const divider = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.018, 3.05),
new THREE.MeshBasicMaterial({ color: 0xb8c9c8 })
);
divider.position.set(0, 0.251, 0);
scene.add(divider);
const pedestalTrimMaterial = new THREE.MeshStandardMaterial({
color: 0x244d5a,
roughness: 0.7
});
for (const x of [-2.1, 2.1]) {
const trim = new THREE.Mesh(
new THREE.TorusGeometry(0.76, 0.025, 4, 32),
pedestalTrimMaterial
);
trim.rotation.x = Math.PI / 2;
trim.position.set(x, 0.252, 0);
scene.add(trim);
}
// Small decorative blocks give the stage a low-poly silhouette.
const blockMaterial = new THREE.MeshStandardMaterial({
color: 0xb7ccca,
roughness: 0.9
});
const blockGeometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
for (const [x, z, s] of [
[-4.2, -1.1, 1.2],
[4.2, -1.1, 1.2],
[-3.7, 1.25, 0.65],
[3.7, 1.25, 0.65]
]) {
const block = new THREE.Mesh(blockGeometry, blockMaterial);
block.scale.setScalar(s);
block.position.set(x, 0.25 * s, z);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
// ------------------------------------------------------------
// Bottles
// ------------------------------------------------------------
const HOT = new THREE.Color(0xff583f);
const WARM = new THREE.Color(0xffbd52);
const COLD = new THREE.Color(0x42b8e8);
const WHITE = new THREE.Color(0xf5fbfa);
const bottleObjects = [];
function thermalColor(temperature, target = new THREE.Color()) {
const n = THREE.MathUtils.clamp(
(temperature - ambientTemperature) /
(startingTemperature - ambientTemperature),
0,
1
);
if (n < 0.5) {
target.lerpColors(COLD, WARM, n * 2);
} else {
target.lerpColors(WARM, HOT, (n - 0.5) * 2);
}
return target;
}
function createBottle(x, covered) {
const root = new THREE.Group();
root.position.set(x, 0.245, 0);
scene.add(root);
const liquidMaterial = new THREE.MeshStandardMaterial({
color: HOT,
roughness: 0.34,
metalness: 0.02,
emissive: HOT,
emissiveIntensity: 0.16
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffb09b,
roughness: 0.16,
metalness: 0,
transparent: true,
opacity: 0.39,
depthWrite: false,
side: THREE.DoubleSide
});
const liquid = new THREE.Mesh(
new THREE.CylinderGeometry(0.435, 0.455, 1.45, 8),
liquidMaterial
);
liquid.position.y = 0.75;
liquid.castShadow = true;
root.add(liquid);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.49, 0.52, 1.7, 8),
glassMaterial
);
body.position.y = 0.85;
body.castShadow = true;
root.add(body);
const shoulder = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.49, 0.4, 8),
glassMaterial
);
shoulder.position.y = 1.9;
shoulder.castShadow = true;
root.add(shoulder);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.23, 0.22, 8),
glassMaterial
);
neck.position.y = 2.21;
root.add(neck);
const capMaterial = new THREE.MeshStandardMaterial({
color: covered ? 0x285568 : 0xe1683e,
roughness: 0.58,
metalness: 0.04
});
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.285, 0.285, 0.21, 10),
capMaterial
);
cap.position.y = 2.43;
cap.castShadow = true;
root.add(cap);
const sealMaterial = new THREE.MeshStandardMaterial({
color: 0xf5e7bd,
roughness: 0.5
});
const seal = new THREE.Mesh(
new THREE.TorusGeometry(0.238, 0.026, 4, 12),
sealMaterial
);
seal.rotation.x = Math.PI / 2;
seal.position.y = 2.31;
root.add(seal);
const thermalMaterials = [];
if (!covered) {
const labelMaterial = new THREE.MeshStandardMaterial({
color: 0xf7f2df,
roughness: 0.88,
side: THREE.DoubleSide
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.6, 0.44),
labelMaterial
);
label.position.set(0, 0.98, 0.518);
root.add(label);
const stripMaterial = new THREE.MeshStandardMaterial({
color: HOT,
roughness: 0.5,
emissive: HOT,
emissiveIntensity: 0.1
});
const strip = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.25, 0.018),
stripMaterial
);
strip.position.set(-0.17, 0.98, 0.532);
root.add(strip);
thermalMaterials.push(stripMaterial);
} else {
const sleeveMaterial = new THREE.MeshStandardMaterial({
color: 0x28566c,
roughness: 0.82,
metalness: 0.03,
side: THREE.DoubleSide
});
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.575, 0.595, 1.36, 10, 1, true),
sleeveMaterial
);
sleeve.position.y = 0.69;
sleeve.castShadow = true;
root.add(sleeve);
const bandMaterial = new THREE.MeshStandardMaterial({
color: 0x3b7387,
roughness: 0.72
});
for (const y of [0.07, 1.32]) {
const band = new THREE.Mesh(
new THREE.CylinderGeometry(0.59, 0.59, 0.13, 10, 1, true),
bandMaterial
);
band.position.y = y;
band.castShadow = true;
root.add(band);
}
const ribMaterial = new THREE.MeshStandardMaterial({
color: 0x5e8998,
roughness: 0.75
});
for (let i = 0; i < 7; i++) {
const rib = new THREE.Mesh(
new THREE.TorusGeometry(0.59, 0.018, 4, 12),
ribMaterial
);
rib.rotation.x = Math.PI / 2;
rib.position.y = 0.18 + i * 0.18;
root.add(rib);
}
const windowMaterial = new THREE.MeshStandardMaterial({
color: HOT,
roughness: 0.35,
emissive: HOT,
emissiveIntensity: 0.13
});
const windowMesh = new THREE.Mesh(
new THREE.PlaneGeometry(0.38, 0.59),
windowMaterial
);
windowMesh.position.set(0, 0.73, 0.607);
root.add(windowMesh);
thermalMaterials.push(windowMaterial);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0xd5e2df,
roughness: 0.5
});
const frameParts = [
[0, 1.055, 0.44, 0.045],
[0, 0.405, 0.44, 0.045],
[-0.205, 0.73, 0.045, 0.69],
[0.205, 0.73, 0.045, 0.69]
];
for (const [fx, fy, fw, fh] of frameParts) {
const frame = new THREE.Mesh(
new THREE.BoxGeometry(fw, fh, 0.025),
frameMaterial
);
frame.position.set(fx, fy, 0.625);
root.add(frame);
}
}
bottleObjects.push({
root,
covered,
liquidMaterial,
glassMaterial,
thermalMaterials
});
}
createBottle(-2.1, true);
createBottle(2.1, false);
// ------------------------------------------------------------
// Equal airflow indicators: two identical animated fan units
// ------------------------------------------------------------
const fanRotors = [];
function createFan(x) {
const group = new THREE.Group();
group.position.set(x, 3.72, -0.72);
scene.add(group);
const housing = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 0.48, 0.32),
new THREE.MeshStandardMaterial({
color: 0x3c6470,
roughness: 0.76
})
);
housing.castShadow = true;
group.add(housing);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.275, 0.028, 4, 16),
new THREE.MeshStandardMaterial({
color: 0xb8d5d8,
roughness: 0.48
})
);
ring.position.z = 0.18;
group.add(ring);
const rotor = new THREE.Group();
rotor.position.z = 0.195;
group.add(rotor);
const bladeMaterial = new THREE.MeshStandardMaterial({
color: 0x83cad4,
roughness: 0.55
});
for (let i = 0; i < 3; i++) {
const pivot = new THREE.Group();
pivot.rotation.z = (i / 3) * Math.PI * 2;
const blade = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.28, 0.025),
bladeMaterial
);
blade.position.y = 0.115;
pivot.add(blade);
rotor.add(pivot);
}
const support = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 1.05, 0.07),
new THREE.MeshStandardMaterial({
color: 0x91aaad,
roughness: 0.85
})
);
support.position.set(x, 2.98, -0.76);
scene.add(support);
fanRotors.push(rotor);
}
createFan(-2.1);
createFan(2.1);
// Moving blue dashes make the equal airflow visible around both bottles.
const airflowDashes = [];
for (const bottleX of [-2.1, 2.1]) {
for (let i = 0; i < 12; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x75c8d6,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.2, 0.022, 0.025),
material
);
scene.add(dash);
airflowDashes.push({
mesh: dash,
material,
x: bottleX,
phase: i / 12,
offset: i * 0.137
});
}
}
// Warm particles show heat leaving the exposed bottle more readily.
const warmParticles = [];
for (const bottle of bottleObjects) {
const count = bottle.covered ? 5 : 8;
for (let i = 0; i < count; i++) {
const material = new THREE.MeshBasicMaterial({
color: HOT,
transparent: true,
opacity: 0,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.052, 0),
material
);
scene.add(mesh);
warmParticles.push({
mesh,
material,
covered: bottle.covered,
x: bottle.root.position.x,
phase: i / count,
offset: i * 0.137
});
}
}
// ------------------------------------------------------------
// Illustrative cooling model
// ------------------------------------------------------------
const startingTemperature = 46;
const ambientTemperature = 21;
const duration = 40;
const coveredTimeConstant = 24;
const uncoveredTimeConstant = 8.5;
let elapsed = 0;
let motionTime = 0;
let running = true;
function temperatureAt(time, timeConstant) {
return (
ambientTemperature +
(startingTemperature - ambientTemperature) *
Math.exp(-time / timeConstant)
);
}
const coveredTemperature = temperatureAt(elapsed, coveredTimeConstant);
const uncoveredTemperature = temperatureAt(elapsed, uncoveredTimeConstant);
const plot = {
left: 42,
right: 618,
top: 12,
bottom: 132
};
function chartX(time) {
return plot.left + (time / duration) * (plot.right - plot.left);
}
function chartY(temperature) {
const n = (temperature - 20) / 30;
return plot.bottom - n * (plot.bottom - plot.top);
}
function makeCurve(timeConstant) {
let d = "";
for (let i = 0; i <= 100; i++) {
const time = (i / 100) * duration;
const x = chartX(time);
const y = chartY(temperatureAt(time, timeConstant));
d += `${i === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)} `;
}
return d.trim();
}
const coveredCurve = makeCurve(coveredTimeConstant);
const uncoveredCurve = makeCurve(uncoveredTimeConstant);
document.getElementById("coveredPath").setAttribute("d", coveredCurve);
document.getElementById("uncoveredPath").setAttribute("d", uncoveredCurve);
document.getElementById("coveredAreaPath").setAttribute(
"d",
`${coveredCurve} L${plot.right},${plot.bottom} L${plot.left},${plot.bottom} Z`
);
const coveredTempElement = document.getElementById("coveredTemp");
const uncoveredTempElement = document.getElementById("uncoveredTemp");
const coveredBar = document.getElementById("coveredBar");
const uncoveredBar = document.getElementById("uncoveredBar");
const gapElement = document.getElementById("gap");
const statusElement = document.getElementById("status");
const statusDot = document.getElementById("statusDot");
const clockElement = document.getElementById("clock");
const currentLine = document.getElementById("currentLine");
const coveredMarker = document.getElementById("coveredMarker");
const uncoveredMarker = document.getElementById("uncoveredMarker");
const colorScratch = new THREE.Color();
const glassScratch = new THREE.Color();
function updateThermalVisuals(tCovered, tUncovered) {
for (const bottle of bottleObjects) {
const temperature = bottle.covered ? tCovered : tUncovered;
thermalColor(temperature, colorScratch);
bottle.liquidMaterial.color.copy(colorScratch);
bottle.liquidMaterial.emissive.copy(colorScratch).multiplyScalar(0.13);
glassScratch.copy(colorScratch).lerp(WHITE, 0.68);
bottle.glassMaterial.color.copy(glassScratch);
for (const material of bottle.thermalMaterials) {
material.color.copy(colorScratch);
material.emissive.copy(colorScratch).multiplyScalar(0.12);
}
}
}
function updateInterface(tCovered, tUncovered) {
coveredTempElement.textContent = `${tCovered.toFixed(1)}°C`;
uncoveredTempElement.textContent = `${tUncovered.toFixed(1)}°C`;
const coveredLevel =
(tCovered - ambientTemperature) /
(startingTemperature - ambientTemperature);
const uncoveredLevel =
(tUncovered - ambientTemperature) /
(startingTemperature - ambientTemperature);
coveredBar.style.width = `${THREE.MathUtils.clamp(coveredLevel, 0, 1) * 100}%`;
uncoveredBar.style.width =
`${THREE.MathUtils.clamp(uncoveredLevel, 0, 1) * 100}%`;
const gap = tCovered - tUncovered;
gapElement.textContent = `${gap.toFixed(1)}°C warmer`;
clockElement.textContent = `${elapsed.toFixed(1)} / ${duration} s`;
if (elapsed >= duration) {
statusElement.textContent = "Experiment complete";
statusDot.className = "status-dot complete";
} else if (!running) {
statusElement.textContent = "Paused";
statusDot.className = "status-dot paused";
} else {
statusElement.textContent = "Live cool-down";
statusDot.className = "status-dot";
}
const x = chartX(elapsed);
const coveredY = chartY(tCovered);
const uncoveredY = chartY(tUncovered);
currentLine.setAttribute("x1", x);
currentLine.setAttribute("x2", x);
coveredMarker.setAttribute("cx", x);
coveredMarker.setAttribute("cy", coveredY);
uncoveredMarker.setAttribute("cx", x);
uncoveredMarker.setAttribute("cy", uncoveredY);
}
// ------------------------------------------------------------
// HTML labels projected from 3D anchor points
// ------------------------------------------------------------
const coveredTag = document.getElementById("tag-covered");
const uncoveredTag = document.getElementById("tag-uncovered");
const coveredAnchor = new THREE.Vector3(-2.1, 3.02, 0);
const uncoveredAnchor = new THREE.Vector3(2.1, 3.02, 0);
const projected = new THREE.Vector3();
function positionTag(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ------------------------------------------------------------
// Direct camera controls — no addons or examples
// ------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + dy * 0.005, 0.68, 1.48);
});
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();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
6.4,
14
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraTheta = 0;
cameraPhi = 1.22;
cameraRadius = defaultRadius();
});
document.getElementById("zoomIn").addEventListener("click", () => {
cameraRadius = Math.max(6.4, cameraRadius - 0.7);
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraRadius = Math.min(14, cameraRadius + 0.7);
});
document.getElementById("cameraReset").addEventListener("click", () => {
cameraTheta = 0;
cameraPhi = 1.22;
cameraRadius = defaultRadius();
});
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
const playButton = document.getElementById("play");
function updatePlayButton() {
if (elapsed >= duration) {
playButton.textContent = "Replay";
playButton.setAttribute("aria-pressed", "false");
} else if (running) {
playButton.textContent = "Pause";
playButton.setAttribute("aria-pressed", "true");
} else {
playButton.textContent = "Play";
playButton.setAttribute("aria-pressed", "false");
}
}
playButton.addEventListener("click", () => {
if (elapsed >= duration) {
elapsed = 0;
running = true;
} else {
running = !running;
}
updatePlayButton();
});
document.getElementById("restart").addEventListener("click", () => {
elapsed = 0;
running = true;
updatePlayButton();
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
motionTime += delta;
if (running && elapsed < duration) {
elapsed = Math.min(duration, elapsed + delta);
if (elapsed >= duration) {
running = false;
updatePlayButton();
}
}
const tCovered = temperatureAt(elapsed, coveredTimeConstant);
const tUncovered = temperatureAt(elapsed, uncoveredTimeConstant);
updateThermalVisuals(tCovered, tUncovered);
updateInterface(tCovered, tUncovered);
for (const rotor of fanRotors) {
rotor.rotation.z -= delta * 3.2;
}
for (const dash of airflowDashes) {
const a = motionTime * 0.72 + dash.phase * Math.PI * 2;
const vertical =
0.35 + ((motionTime * 0.16 + dash.offset) % 1) * 2.75;
dash.mesh.position.set(
dash.x + Math.sin(a) * 0.88,
vertical,
Math.cos(a) * 0.68
);
dash.mesh.rotation.y = -a;
dash.material.opacity =
0.18 + 0.13 * (0.5 + 0.5 * Math.sin(a * 2));
}
const warmth = THREE.MathUtils.clamp(
(tCovered - ambientTemperature) /
(startingTemperature - ambientTemperature),
0,
1
);
for (const particle of warmParticles) {
const speed = particle.covered ? 0.075 : 0.15;
const life =
(motionTime * speed + particle.offset) % 1;
particle.mesh.position.set(
particle.x + Math.sin(life * 9 + particle.phase * 8) * 0.38,
1.35 + life * 1.72,
Math.cos(life * 7 + particle.phase * 6) * 0.27
);
const maximumOpacity = particle.covered ? 0.09 : 0.48;
particle.material.opacity =
maximumOpacity * warmth * Math.sin(life * Math.PI);
particle.material.color.copy(
thermalColor(
particle.covered ? tCovered : tUncovered,
colorScratch
)
);
}
updateCamera();
positionTag(coveredTag, coveredAnchor);
positionTag(uncoveredTag, uncoveredAnchor);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateThermalVisuals(coveredTemperature, uncoveredTemperature);
updateInterface(coveredTemperature, uncoveredTemperature);
updatePlayButton();
requestAnimationFrame(animate);
</script>
</body>
</html>
```