Prompt specification
Build or customize the Three.js 3D scene "Heat-retention materials 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: Heat-retention materials exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/heat-retention-materials-exhibit-x0040
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a hot-water bottle. Build a classroom table with identical warm containers and different removable wraps; a restart control compares labeled illustrative cooling curves without presenting measured real-world temperatures. Low-poly.
Working Three.js Starter (heat-retention-materials-exhibit-x0040):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Warmth Lab — Low-Poly Hot-Water Bottle Comparison</title>
<style>
:root {
--ink: #203638;
--muted: #647779;
--paper: rgba(250, 248, 238, 0.94);
--line: rgba(32, 54, 56, 0.14);
--gold: #d59b48;
--teal: #4f9d8c;
--coral: #d9735b;
--violet: #8b6bb1;
--shadow: 0 18px 55px rgba(30, 51, 53, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe7e4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#viewport canvas {
display: block;
cursor: grab;
touch-action: none;
outline: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid rgba(255, 255, 255, 0.68);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 18px;
left: 18px;
width: min(430px, calc(100vw - 36px));
padding: 19px 21px 18px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #53706e;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--coral);
content: "";
transform: rotate(12deg);
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 3vw, 2.2rem);
line-height: 1.04;
letter-spacing: -0.04em;
}
#intro p {
margin: 10px 0 0;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.5;
}
.same-start {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 7px 10px;
border: 1px solid rgba(213, 155, 72, 0.3);
border-radius: 999px;
background: rgba(213, 155, 72, 0.11);
color: #7d5925;
font-size: 0.76rem;
font-weight: 750;
}
.same-start::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: #e4834d;
box-shadow: 0 0 0 4px rgba(228, 131, 77, 0.15);
content: "";
}
#labPanel {
top: 18px;
right: 18px;
width: min(390px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 17px;
border-radius: 20px;
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.panel-heading h2 {
margin: 0;
font-size: 1rem;
letter-spacing: -0.02em;
}
.small-tag {
flex: none;
padding: 5px 8px;
border-radius: 999px;
background: #e5ece8;
color: #526967;
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.buttons {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-bottom: 12px;
}
button {
border: 0;
border-radius: 11px;
cursor: pointer;
transition:
transform 140ms ease,
box-shadow 140ms ease,
background 140ms ease;
}
button:hover {
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(79, 157, 140, 0.35);
outline-offset: 2px;
}
#restart {
padding: 11px 13px;
background: var(--ink);
box-shadow: 0 8px 18px rgba(32, 54, 56, 0.18);
color: white;
font-size: 0.83rem;
font-weight: 780;
}
#resetView {
padding: 10px 12px;
background: #e3ebe7;
color: #385351;
font-size: 0.75rem;
font-weight: 750;
}
#status {
min-height: 37px;
margin-bottom: 11px;
color: #607271;
font-size: 0.76rem;
line-height: 1.45;
}
.progress-track {
height: 5px;
overflow: hidden;
margin-bottom: 14px;
border-radius: 999px;
background: #dce4df;
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--coral), var(--gold));
}
.section-label {
margin: 15px 0 8px;
color: #6c7d7b;
font-size: 0.67rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.chart-wrap {
position: relative;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.55);
}
#chart {
display: block;
width: 100%;
height: auto;
}
.chart-note {
margin: 8px 2px 0;
color: #73817f;
font-size: 0.68rem;
line-height: 1.4;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px 9px;
margin-top: 10px;
}
.legend-item {
display: flex;
align-items: center;
min-width: 0;
gap: 7px;
color: #526563;
font-size: 0.68rem;
font-weight: 700;
}
.legend-swatch {
width: 17px;
height: 4px;
flex: none;
border-radius: 99px;
}
.cards {
display: grid;
gap: 7px;
}
.wrap-card {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.46);
}
.wrap-card .swatch {
width: 10px;
height: 27px;
border-radius: 4px;
background: var(--accent);
}
.wrap-card strong {
display: block;
font-size: 0.76rem;
}
.wrap-card small {
display: block;
margin-top: 1px;
color: #7b8987;
font-size: 0.63rem;
}
.wrap-card button {
padding: 7px 9px;
background: #e4ebe7;
color: #3c5755;
font-size: 0.66rem;
font-weight: 800;
}
.wrap-card.is-off button {
background: #f2dfd7;
color: #8e4f3b;
}
#hint {
position: fixed;
z-index: 4;
bottom: 17px;
left: 50%;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
background: rgba(250, 248, 238, 0.86);
box-shadow: 0 8px 28px rgba(30, 51, 53, 0.12);
color: #58706d;
font-size: 0.7rem;
font-weight: 700;
pointer-events: none;
transform: translateX(-50%);
white-space: nowrap;
}
@media (max-width: 820px) {
#intro {
width: min(350px, calc(100vw - 28px));
top: 12px;
left: 12px;
padding: 14px 16px;
}
#intro p {
display: none;
}
.same-start {
margin-top: 9px;
}
#labPanel {
top: auto;
right: 10px;
bottom: 10px;
width: min(370px, calc(100vw - 20px));
max-height: 53vh;
padding: 13px;
}
#hint {
display: none;
}
}
@media (max-width: 430px) {
#intro h1 {
font-size: 1.4rem;
}
.legend {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header id="intro" class="panel">
<div class="eyebrow">Low-poly classroom model</div>
<h1>Warmth Lab</h1>
<p>
Four identical warm hot-water bottles share one starting condition.
Remove or replace the fabric wraps to compare their illustrative cooling curves.
</p>
<div class="same-start">Same container shape · Same initial relative warmth</div>
</header>
<aside id="labPanel" class="panel" aria-label="Comparison controls and chart">
<div class="panel-heading">
<h2>Cooling comparison</h2>
<span class="small-tag">Illustrative only</span>
</div>
<div class="buttons">
<button id="restart" title="Restore all wraps and replay the comparison">
↻ Restart comparison
</button>
<button id="resetView" title="Return the camera to its starting view">
Reset view
</button>
</div>
<div id="status" aria-live="polite">
Ready. Restart the comparison to begin.
</div>
<div class="progress-track" aria-hidden="true">
<div id="progressFill"></div>
</div>
<div class="section-label">Relative warmth index</div>
<div class="chart-wrap">
<svg
id="chart"
viewBox="0 0 380 250"
role="img"
aria-label="Illustrative cooling curves for four warm containers"
>
<g id="grid"></g>
<path id="curveA" fill="none"></path>
<path id="curveB" fill="none"></path>
<path id="curveC" fill="none"></path>
<path id="curveD" fill="none"></path>
<line id="playhead"></line>
<text class="axis-label" x="190" y="242" text-anchor="middle">
arbitrary comparison time
</text>
<text
class="axis-label"
x="13"
y="108"
text-anchor="middle"
transform="rotate(-90 13 108)"
>
relative warmth index
</text>
</svg>
</div>
<p class="chart-note">
Curves are a stylized classroom model, not measured data and not calibrated
to real-world temperature. All containers begin at index 100.
</p>
<div class="legend" aria-label="Curve legend">
<div class="legend-item">
<span class="legend-swatch" style="background:#d59b48"></span>
<span id="legendA">A · No wrap</span>
</div>
<div class="legend-item">
<span class="legend-swatch" style="background:#4f9d8c"></span>
<span id="legendB">B · Cotton</span>
</div>
<div class="legend-item">
<span class="legend-swatch" style="background:#d9735b"></span>
<span id="legendC">C · Knit</span>
</div>
<div class="legend-item">
<span class="legend-swatch" style="background:#8b6bb1"></span>
<span id="legendD">D · Wool</span>
</div>
</div>
<div class="section-label">Removable wraps</div>
<div class="cards">
<article class="wrap-card" style="--accent:#d59b48">
<span class="swatch"></span>
<div>
<strong>A · Reference bottle</strong>
<small>Exposed container</small>
</div>
<button disabled style="opacity:.55;cursor:default">Reference</button>
</article>
<article id="cardB" class="wrap-card" style="--accent:#4f9d8c">
<span class="swatch"></span>
<div>
<strong>B · Cotton wrap</strong>
<small id="stateB">Wrap fitted</small>
</div>
<button data-bottle="1">Remove</button>
</article>
<article id="cardC" class="wrap-card" style="--accent:#d9735b">
<span class="swatch"></span>
<div>
<strong>C · Knit wrap</strong>
<small id="stateC">Wrap fitted</small>
</div>
<button data-bottle="2">Remove</button>
</article>
<article id="cardD" class="wrap-card" style="--accent:#8b6bb1">
<span class="swatch"></span>
<div>
<strong>D · Wool wrap</strong>
<small id="stateD">Wrap fitted</small>
</div>
<button data-bottle="3">Remove</button>
</article>
</div>
</aside>
<div id="hint">Drag to orbit · Scroll to zoom · Click a wrapped bottle to remove its wrap</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene and renderer
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly classroom containing four warm hot-water bottles"
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dbe7e4");
scene.fog = new THREE.Fog("#dbe7e4", 15, 30);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.55, 0);
let cameraAzimuth = 0.43;
let cameraElevation = 0.49;
let cameraRadius = 12.2;
function updateCamera() {
const horizontal = Math.cos(cameraElevation) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraAzimuth) * horizontal,
cameraTarget.y + Math.sin(cameraElevation) * cameraRadius,
cameraTarget.z + Math.cos(cameraAzimuth) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Low-poly lighting
// ------------------------------------------------------------
const hemi = new THREE.HemisphereLight("#f5fff7", "#71817b", 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff1d5", 3.1);
sun.position.set(-5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 28;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#a9d7dc", 1.2);
fill.position.set(7, 4, -4);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0,
flatShading: true,
...options
});
}
function box(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Classroom environment
// ------------------------------------------------------------
const floorMaterial = standard("#b8c6bf");
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 28),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.42;
floor.receiveShadow = true;
scene.add(floor);
const wallMaterial = standard("#e6ede5");
box(24, 11, 0.28, wallMaterial, 0, 3.05, -6.6);
const wainscot = standard("#91aaa4");
box(24, 1.5, 0.34, wainscot, 0, -1.65, -6.42);
// Classroom table.
const tableTopMaterial = standard("#b98250");
const tableEdgeMaterial = standard("#8e5e3b");
const tableMetal = standard("#52696b", { roughness: 0.65 });
box(11.6, 0.32, 5.35, tableTopMaterial, 0, -0.16, 0);
box(11.7, 0.11, 5.45, tableEdgeMaterial, 0, -0.34, 0);
for (const x of [-4.85, 4.85]) {
for (const z of [-1.9, 1.9]) {
box(0.19, 2.05, 0.19, tableMetal, x, -1.37, z);
cylinder(
0.13,
0.13,
0.08,
8,
standard("#33494a"),
x,
-2.34,
z
);
}
}
box(9.8, 0.12, 0.12, tableMetal, 0, -1.55, -1.9);
box(9.8, 0.12, 0.12, tableMetal, 0, -1.55, 1.9);
// Chairs behind the table.
const chairSeat = standard("#65827f");
const chairFrame = standard("#52696b");
function addChair(x, z, rotation = 0) {
const chair = new THREE.Group();
chair.position.set(x, 0, z);
chair.rotation.y = rotation;
scene.add(chair);
box(1.05, 0.13, 0.95, chairSeat, 0, -1.12, 0, chair);
box(1.05, 0.88, 0.12, chairSeat, 0, -0.58, -0.42, chair);
for (const lx of [-0.42, 0.42]) {
for (const lz of [-0.35, 0.35]) {
box(
0.08,
1.18,
0.08,
chairFrame,
lx,
-1.78,
lz,
chair
);
}
}
}
addChair(-3.9, -3.25, 0);
addChair(-1.3, -3.25, 0);
addChair(1.3, -3.25, 0);
addChair(3.9, -3.25, 0);
// Whiteboard with an in-world heading.
box(7.6, 2.55, 0.16, standard("#52696b"), -1.3, 3.05, -6.38);
box(7.35, 2.3, 0.08, standard("#f7f8ed"), -1.3, 3.05, -6.27);
function makeTextTexture(
lines,
width = 1024,
height = 320,
background = null,
foreground = "#294746"
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
if (background) {
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
} else {
ctx.clearRect(0, 0, width, height);
}
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const lineHeight = height / (lines.length + 0.6);
lines.forEach((line, index) => {
const fontSize = index === 0 ? height * 0.24 : height * 0.1;
ctx.font = `${index === 0 ? 800 : 600} ${fontSize}px system-ui`;
ctx.fillText(
line,
width / 2,
height / 2 + (index - (lines.length - 1) / 2) * lineHeight
);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return texture;
}
const boardText = makeTextTexture([
"WARMTH LAB",
"same start • different wraps"
]);
const boardMesh = new THREE.Mesh(
new THREE.PlaneGeometry(6.8, 1.65),
new THREE.MeshBasicMaterial({
map: boardText,
transparent: true
})
);
boardMesh.position.set(-1.3, 3.05, -6.205);
scene.add(boardMesh);
// Small chalk-like marks on the board.
const chalkMaterial = new THREE.MeshBasicMaterial({
color: "#86aaa4",
transparent: true,
opacity: 0.55
});
box(1.4, 0.025, 0.015, chalkMaterial, -3.4, 2.15, -6.19);
box(1.8, 0.025, 0.015, chalkMaterial, 0.8, 2.15, -6.19);
// Low-poly wall clock.
const clockGroup = new THREE.Group();
clockGroup.position.set(4.3, 3.35, -6.18);
scene.add(clockGroup);
const clock = cylinder(
0.57,
0.57,
0.14,
12,
standard("#355052"),
0,
0,
0,
clockGroup
);
clock.rotation.x = Math.PI / 2;
const clockFace = cylinder(
0.48,
0.48,
0.02,
12,
standard("#f5f1dc"),
0,
0,
0.08,
clockGroup
);
clockFace.rotation.x = Math.PI / 2;
const minuteHand = box(
0.04,
0.34,
0.035,
standard("#315052"),
0,
0.13,
0.11,
clockGroup
);
minuteHand.rotation.z = -0.75;
const hourHand = box(
0.05,
0.23,
0.035,
standard("#d9735b"),
-0.05,
0.07,
0.12,
clockGroup
);
hourHand.rotation.z = 0.7;
// Books and a pencil cup.
const bookColors = ["#c96858", "#e3b454", "#6f9e91"];
bookColors.forEach((color, index) => {
const book = box(
1.1,
0.12,
0.75,
standard(color),
4.45,
0.07 + index * 0.13,
-1.5
);
book.rotation.y = index * 0.035;
});
const pencilCup = cylinder(
0.28,
0.23,
0.48,
8,
standard("#708b87"),
-4.55,
0.24,
-1.55
);
[
["#d59b48", -0.1, 0.1],
["#d9735b", 0.06, -0.03],
["#8b6bb1", -0.02, -0.11]
].forEach(([color, dx, dz]) => {
const pencil = cylinder(
0.025,
0.025,
0.78,
6,
standard(color),
-4.55 + dx,
0.77,
-1.55 + dz
);
pencil.rotation.z = dx * 2.2;
});
// ------------------------------------------------------------
// Fabric textures
// ------------------------------------------------------------
function makeFabricTexture(base, pattern) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = base;
ctx.fillRect(0, 0, 128, 128);
ctx.strokeStyle = "rgba(255,255,255,0.22)";
ctx.fillStyle = "rgba(255,255,255,0.17)";
ctx.lineWidth = 2;
if (pattern === "cotton") {
for (let x = 0; x <= 128; x += 16) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, 128);
ctx.stroke();
}
for (let y = 0; y <= 128; y += 16) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(128, y);
ctx.stroke();
}
} else if (pattern === "knit") {
for (let y = -16; y < 160; y += 16) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(64, y + 12);
ctx.lineTo(128, y);
ctx.stroke();
}
ctx.strokeStyle = "rgba(40,40,40,0.13)";
for (let y = 0; y < 128; y += 8) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(128, y);
ctx.stroke();
}
} else {
for (let i = 0; i < 90; i++) {
const x = (i * 37) % 128;
const y = (i * 61) % 128;
ctx.fillRect(x, y, 3, 3);
ctx.fillRect((x + 8) % 128, (y + 5) % 128, 2, 2);
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2, 1.5);
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return texture;
}
// ------------------------------------------------------------
// Hot-water bottles
// ------------------------------------------------------------
const bottleProfile = [
new THREE.Vector2(0.14, -0.9),
new THREE.Vector2(0.35, -0.86),
new THREE.Vector2(0.55, -0.64),
new THREE.Vector2(0.63, -0.3),
new THREE.Vector2(0.61, 0.12),
new THREE.Vector2(0.51, 0.46),
new THREE.Vector2(0.33, 0.7),
new THREE.Vector2(0.2, 0.78),
new THREE.Vector2(0.2, 1.04)
];
const wrapProfile = [
new THREE.Vector2(0, -0.75),
new THREE.Vector2(0.55, -0.75),
new THREE.Vector2(0.64, -0.58),
new THREE.Vector2(0.68, -0.2),
new THREE.Vector2(0.64, 0.22),
new THREE.Vector2(0.55, 0.48),
new THREE.Vector2(0, 0.48)
];
const bottleSpecs = [
{ letter: "A", type: null, label: "NO WRAP", color: "#d59b48" },
{ letter: "B", type: "cotton", label: "COTTON", color: "#4f9d8c" },
{ letter: "C", type: "knit", label: "KNIT", color: "#d9735b" },
{ letter: "D", type: "wool", label: "WOOL", color: "#8b6bb1" }
];
const bottleGroups = [];
const bottleStates = [];
const warmColor = new THREE.Color("#d86d4e");
const coolColor = new THREE.Color("#708896");
function createBottleLabelTexture(index, wrapped) {
const spec = bottleSpecs[index];
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fffaf0";
ctx.fillRect(0, 0, 512, 128);
ctx.strokeStyle = spec.color;
ctx.lineWidth = 10;
ctx.strokeRect(5, 5, 502, 118);
ctx.fillStyle = spec.color;
ctx.fillRect(0, 0, 24, 128);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#294746";
ctx.font = "800 46px system-ui";
ctx.fillText(
`${spec.letter} · ${wrapped ? spec.label : "UNWRAPPED"}`,
270,
62
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return texture;
}
function setBottleLabel(index, wrapped) {
const state = bottleStates[index];
const oldTexture = state.labelMesh.material.map;
const texture = createBottleLabelTexture(index, wrapped);
state.labelMesh.material.map = texture;
state.labelMesh.material.needsUpdate = true;
if (oldTexture) oldTexture.dispose();
}
function createWrap(spec, index) {
const group = new THREE.Group();
group.userData.bottleIndex = index;
const texture = makeFabricTexture(spec.color, spec.type);
const material = standard("#ffffff", {
map: texture,
roughness: 1,
transparent: true,
opacity: 1
});
const sleeve = new THREE.Mesh(
new THREE.LatheGeometry(wrapProfile, 12),
material
);
sleeve.scale.z = 0.58;
sleeve.castShadow = true;
sleeve.receiveShadow = true;
group.add(sleeve);
const seamMaterial = standard(spec.color, {
roughness: 1,
transparent: true,
opacity: 0.9
});
[ -0.73, 0.46 ].forEach((y) => {
const seam = new THREE.Mesh(
new THREE.TorusGeometry(y < 0 ? 0.58 : 0.57, 0.026, 4, 12),
seamMaterial
);
seam.rotation.x = Math.PI / 2;
seam.scale.z = 0.58;
seam.position.y = y;
seam.castShadow = true;
group.add(seam);
});
// Small fabric label.
const tagTexture = makeTextTexture(
[spec.label],
256,
96,
"#fff9e9",
"#314b4a"
);
const tag = new THREE.Mesh(
new THREE.PlaneGeometry(0.48, 0.18),
new THREE.MeshBasicMaterial({
map: tagTexture,
transparent: true
})
);
tag.position.set(0, -0.05, 0.405);
group.add(tag);
// Wool gets a few chunky low-poly knots.
if (spec.type === "wool") {
const knotMaterial = standard("#a98ac7", {
roughness: 1,
transparent: true,
opacity: 1
});
for (let i = 0; i < 14; i++) {
const angle = (i / 14) * Math.PI * 2;
const knot = new THREE.Mesh(
new THREE.OctahedronGeometry(0.075, 0),
knotMaterial
);
knot.position.set(
Math.cos(angle) * 0.65,
-0.55 + ((i * 17) % 9) * 0.115,
Math.sin(angle) * 0.65 * 0.58
);
knot.scale.set(1, 0.7, 0.7);
knot.castShadow = true;
group.add(knot);
}
}
const materials = [];
group.traverse((object) => {
if (object.material) materials.push(object.material);
});
group.userData.materials = materials;
group.userData.targetPosition = new THREE.Vector3();
group.userData.targetScale = new THREE.Vector3(1, 1, 1);
group.userData.targetRotation = new THREE.Euler();
group.userData.targetOpacity = 1;
return group;
}
function createBottle(spec, index, x) {
const group = new THREE.Group();
group.position.set(x, 0.9, 0.12);
group.userData.bottleIndex = index;
scene.add(group);
const rubberMaterial = standard("#d86d4e", {
roughness: 0.76,
emissive: "#b74226",
emissiveIntensity: 0.08
});
const body = new THREE.Mesh(
new THREE.LatheGeometry(bottleProfile, 12),
rubberMaterial
);
body.scale.z = 0.58;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const ribMaterial = standard("#b9523d", {
roughness: 0.78
});
const ribData = [
[-0.52, 0.59],
[-0.28, 0.63],
[-0.03, 0.62],
[0.22, 0.58],
[0.43, 0.51]
];
ribData.forEach(([y, radius]) => {
const rib = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.025, 4, 12),
ribMaterial
);
rib.rotation.x = Math.PI / 2;
rib.scale.z = 0.58;
rib.position.y = y;
rib.castShadow = true;
group.add(rib);
});
cylinder(
0.2,
0.2,
0.24,
10,
rubberMaterial,
0,
1.08,
0,
group
);
const capMaterial = standard("#374d50", {
roughness: 0.68
});
cylinder(
0.245,
0.225,
0.23,
10,
capMaterial,
0,
1.25,
0,
group
);
const capBand = new THREE.Mesh(
new THREE.TorusGeometry(0.225, 0.025, 4, 12),
capMaterial
);
capBand.rotation.x = Math.PI / 2;
capBand.position.y = 1.18;
group.add(capBand);
// Small warm-air diamonds above each cap.
const steam = [];
const steamMaterial = new THREE.MeshBasicMaterial({
color: "#ee8b4f",
transparent: true,
opacity: 0.65,
depthWrite: false
});
for (let i = 0; i < 3; i++) {
const puff = new THREE.Mesh(
new THREE.OctahedronGeometry(0.055 - i * 0.008, 0),
steamMaterial.clone()
);
puff.position.set(
Math.sin(i * 2.1) * 0.08,
1.48 + i * 0.16,
Math.cos(i * 2.1) * 0.05
);
group.add(puff);
steam.push(puff);
}
let wrap = null;
if (spec.type) {
wrap = createWrap(spec, index);
group.add(wrap);
}
const labelMesh = new THREE.Mesh(
new THREE.PlaneGeometry(1.35, 0.34),
new THREE.MeshBasicMaterial({
map: createBottleLabelTexture(index, Boolean(spec.type)),
transparent: true
})
);
labelMesh.position.set(0, -0.82, 0.78);
labelMesh.rotation.x = -0.12;
group.add(labelMesh);
bottleGroups.push(group);
bottleStates.push({
group,
rubberMaterial,
steam,
wrap,
labelMesh,
wrapOn: Boolean(spec.type),
phase: index * 0.7
});
}
[-3.55, -1.18, 1.18, 3.55].forEach((x, index) => {
createBottle(bottleSpecs[index], index, x);
});
// ------------------------------------------------------------
// Illustrative cooling model
// ------------------------------------------------------------
const coolingRates = {
none: 0.145,
cotton: 0.075,
knit: 0.052,
wool: 0.033
};
function currentMode(index) {
const spec = bottleSpecs[index];
if (!spec.type) return "none";
return bottleStates[index].wrapOn ? spec.type : "none";
}
function currentLabel(index) {
const spec = bottleSpecs[index];
if (!spec.type) return "No wrap";
return bottleStates[index].wrapOn ? spec.label : "No wrap";
}
function relativeWarmth(mode, time) {
const rate = coolingRates[mode];
return 100 * Math.exp(-rate * time);
}
// ------------------------------------------------------------
// SVG chart
// ------------------------------------------------------------
const svgNS = "http://www.w3.org/2000/svg";
const grid = document.getElementById("grid");
const chartPaths = [
document.getElementById("curveA"),
document.getElementById("curveB"),
document.getElementById("curveC"),
document.getElementById("curveD")
];
const legendLabels = [
document.getElementById("legendA"),
document.getElementById("legendB"),
document.getElementById("legendC"),
document.getElementById("legendD")
];
const playhead = document.getElementById("playhead");
const chart = {
left: 42,
right: 366,
top: 18,
bottom: 213,
duration: 6
};
for (let value = 0; value <= 100; value += 25) {
const y =
chart.bottom -
(value / 100) * (chart.bottom - chart.top);
const line = document.createElementNS(svgNS, "line");
line.setAttribute("x1", chart.left);
line.setAttribute("x2", chart.right);
line.setAttribute("y1", y);
line.setAttribute("y2", y);
line.setAttribute("stroke", "#cfd9d4");
line.setAttribute("stroke-width", "1");
grid.appendChild(line);
const text = document.createElementNS(svgNS, "text");
text.setAttribute("x", chart.left - 8);
text.setAttribute("y", y + 4);
text.setAttribute("text-anchor", "end");
text.setAttribute("fill", "#758481");
text.setAttribute("font-size", "10");
text.setAttribute("font-family", "system-ui");
text.textContent = value;
grid.appendChild(text);
}
for (let step = 0; step <= 6; step++) {
const x =
chart.left +
(step / chart.duration) * (chart.right - chart.left);
const line = document.createElementNS(svgNS, "line");
line.setAttribute("x1", x);
line.setAttribute("x2", x);
line.setAttribute("y1", chart.top);
line.setAttribute("y2", chart.bottom);
line.setAttribute("stroke", "#e2e8e4");
line.setAttribute("stroke-width", "1");
grid.appendChild(line);
const text = document.createElementNS(svgNS, "text");
text.setAttribute("x", x);
text.setAttribute("y", chart.bottom + 17);
text.setAttribute("text-anchor", "middle");
text.setAttribute("fill", "#758481");
text.setAttribute("font-size", "10");
text.setAttribute("font-family", "system-ui");
text.textContent = step;
grid.appendChild(text);
}
const axisTitleStyle = document.createElementNS(svgNS, "style");
axisTitleStyle.textContent = `
.axis-label {
fill: #748481;
font-family: system-ui, sans-serif;
font-size: 10px;
font-weight: 650;
}
`;
document.getElementById("chart").appendChild(axisTitleStyle);
chartPaths.forEach((path, index) => {
path.setAttribute("stroke", bottleSpecs[index].color);
path.setAttribute("stroke-width", "3");
path.setAttribute("stroke-linecap", "round");
path.setAttribute("stroke-linejoin", "round");
path.setAttribute("pathLength", "1");
path.style.strokeDasharray = "1";
path.style.strokeDashoffset = "1";
});
playhead.setAttribute("y1", chart.top);
playhead.setAttribute("y2", chart.bottom);
playhead.setAttribute("stroke", "#304b4b");
playhead.setAttribute("stroke-width", "1");
playhead.setAttribute("stroke-dasharray", "3 3");
playhead.setAttribute("opacity", "0.55");
function makeCurvePath(mode) {
const points = [];
for (let step = 0; step <= 100; step++) {
const time = (step / 100) * chart.duration;
const x =
chart.left +
(time / chart.duration) * (chart.right - chart.left);
const value = relativeWarmth(mode, time);
const y =
chart.bottom -
(value / 100) * (chart.bottom - chart.top);
points.push(`${x.toFixed(2)},${y.toFixed(2)}`);
}
return `M ${points.join(" L ")}`;
}
function updateChartPaths() {
chartPaths.forEach((path, index) => {
path.setAttribute("d", makeCurvePath(currentMode(index)));
legendLabels[index].textContent =
`${bottleSpecs[index].letter} · ${currentLabel(index)}`;
});
}
updateChartPaths();
// ------------------------------------------------------------
// Wrap controls
// ------------------------------------------------------------
const status = document.getElementById("status");
const progressFill = document.getElementById("progressFill");
const cards = [
document.getElementById("cardB"),
document.getElementById("cardC"),
document.getElementById("cardD")
];
const stateLabels = [
document.getElementById("stateB"),
document.getElementById("stateC"),
document.getElementById("stateD")
];
function setWrapVisual(index, fitted, instant = false) {
const state = bottleStates[index];
if (!state.wrap) return;
const target = state.wrap.userData;
target.targetPosition.set(
fitted ? 0 : 0.74,
fitted ? 0 : -0.85,
fitted ? 0 : 0.46
);
target.targetScale.set(
fitted ? 1 : 1.08,
fitted ? 1 : 0.28,
fitted ? 1 : 1.04
);
target.targetRotation.set(
fitted ? 0 : 0.08,
fitted ? 0 : -0.06,
fitted ? 0 : -0.14
);
target.targetOpacity = fitted ? 1 : 0.76;
if (instant) {
state.wrap.position.copy(target.targetPosition);
state.wrap.scale.copy(target.targetScale);
state.wrap.rotation.copy(target.targetRotation);
target.materials.forEach((material) => {
material.opacity = target.targetOpacity;
});
}
}
function updateWrapUI(index) {
const cardIndex = index - 1;
const state = bottleStates[index];
const button = cards[cardIndex].querySelector("button");
button.textContent = state.wrapOn ? "Remove" : "Add";
stateLabels[cardIndex].textContent = state.wrapOn
? "Wrap fitted"
: "Exposed container";
cards[cardIndex].classList.toggle("is-off", !state.wrapOn);
setBottleLabel(index, state.wrapOn);
}
function toggleWrap(index) {
if (!bottleSpecs[index].type) return;
const state = bottleStates[index];
state.wrapOn = !state.wrapOn;
setWrapVisual(index, state.wrapOn);
updateWrapUI(index);
updateChartPaths();
status.textContent =
`${bottleSpecs[index].label} wrap ${
state.wrapOn ? "added" : "removed"
}. ` +
`Container ${bottleSpecs[index].letter} now follows the ${
currentLabel(index).toLowerCase()
} illustrative curve.`;
}
document.querySelectorAll("[data-bottle]").forEach((button) => {
button.addEventListener("click", () => {
toggleWrap(Number(button.dataset.bottle));
});
});
// ------------------------------------------------------------
// Comparison animation
// ------------------------------------------------------------
const durationMilliseconds = 6000;
let comparisonStart = performance.now();
let elapsed = 0;
let running = false;
let completed = false;
let previousFrame = performance.now();
function restartComparison() {
comparisonStart = performance.now();
elapsed = 0;
running = true;
completed = false;
bottleStates.forEach((state, index) => {
state.wrapOn = Boolean(bottleSpecs[index].type);
if (state.wrap) {
setWrapVisual(index, true, true);
updateWrapUI(index);
}
});
updateChartPaths();
chartPaths.forEach((path) => {
path.style.strokeDashoffset = "1";
});
progressFill.style.width = "0%";
status.textContent =
"Comparison restarted: all four containers begin at the same relative warmth.";
}
document.getElementById("restart").addEventListener(
"click",
restartComparison
);
document.getElementById("resetView").addEventListener("click", () => {
cameraAzimuth = 0.43;
cameraElevation = 0.49;
cameraRadius = 12.2;
updateCamera();
});
// ------------------------------------------------------------
// Custom camera controls — no external controls addon
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
let pointerTravel = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerTravel = 0;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
cameraAzimuth -= dx * 0.006;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + dy * 0.005,
0.2,
1.2
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
const clickDistance =
Math.abs(event.clientX - pointerStartX) +
Math.abs(event.clientY - pointerStartY);
if (clickDistance < 6 && pointerTravel < 10) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(bottleGroups, true);
if (hits.length) {
let object = hits[0].object;
while (object && object.userData.bottleIndex === undefined) {
object = object.parent;
}
if (object) toggleWrap(object.userData.bottleIndex);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.009,
7.5,
18
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraAzimuth = 0.43;
cameraElevation = 0.49;
cameraRadius = 12.2;
updateCamera();
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousFrame) / 1000, 0.05);
previousFrame = now;
if (running) {
elapsed = Math.min(
durationMilliseconds / 1000,
(now - comparisonStart) / 1000
);
const progress = elapsed / (durationMilliseconds / 1000);
progressFill.style.width = `${progress * 100}%`;
chartPaths.forEach((path) => {
path.style.strokeDashoffset = String(1 - progress);
});
const playheadX =
chart.left +
progress * (chart.right - chart.left);
playhead.setAttribute("x1", playheadX);
playhead.setAttribute("x2", playheadX);
if (elapsed >= durationMilliseconds / 1000) {
running = false;
completed = true;
status.textContent =
"Comparison complete. Remove a wrap to inspect a new curve, or restart to replay.";
}
}
bottleStates.forEach((state, index) => {
const warmth = relativeWarmth(currentMode(index), elapsed);
const warmthAmount = THREE.MathUtils.clamp(warmth / 100, 0, 1);
state.rubberMaterial.color.lerpColors(
coolColor,
warmColor,
warmthAmount
);
state.rubberMaterial.emissiveIntensity = 0.015 + warmthAmount * 0.085;
state.steam.forEach((puff, puffIndex) => {
const cycle = (now * 0.001 + state.phase + puffIndex * 0.8) % 1.6;
puff.position.y = 1.47 + puffIndex * 0.16 + cycle * 0.08;
puff.position.x += Math.sin(now * 0.002 + puffIndex) * 0.0006;
puff.material.opacity =
Math.max(0, warmthAmount * 0.72 - cycle * 0.22);
const pulse = 0.85 + Math.sin(now * 0.004 + puffIndex) * 0.12;
puff.scale.setScalar(pulse);
});
if (state.wrap) {
const target = state.wrap.userData;
const smoothing = 1 - Math.exp(-delta * 8);
state.wrap.position.lerp(target.targetPosition, smoothing);
state.wrap.scale.lerp(target.targetScale, smoothing);
state.wrap.rotation.x = THREE.MathUtils.lerp(
state.wrap.rotation.x,
target.targetRotation.x,
smoothing
);
state.wrap.rotation.y = THREE.MathUtils.lerp(
state.wrap.rotation.y,
target.targetRotation.y,
smoothing
);
state.wrap.rotation.z = THREE.MathUtils.lerp(
state.wrap.rotation.z,
target.targetRotation.z,
smoothing
);
target.materials.forEach((material) => {
material.opacity = THREE.MathUtils.lerp(
material.opacity,
target.targetOpacity,
smoothing
);
});
}
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
});
</script>
</body>
</html>
```