Prompt specification
Build or customize the Three.js 3D scene "Potter's Wheel Profile Change" 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: Potter's Wheel Profile Change
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/potter-s-wheel-profile-change-x3330
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing pottery vessel shapes, walls, and capacity. Animate a stylized clay form changing between several hand-authored profiles while rotating. Keep the model explicitly schematic and prevent the wall from crossing itself. A 3D cutaway view.
Working Three.js Starter (potter-s-wheel-profile-change-x3330):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vessel / Sectioned — Ceramic Form Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #181a1c;
--panel: rgba(28, 30, 31, 0.78);
--panel-line: rgba(255, 255, 255, 0.11);
--text: #f1eee7;
--muted: #a6a59f;
--clay: #cf7d55;
--clay-light: #e5aa73;
--water: #75d8d4;
--section: #efb56d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
position: relative;
width: 100vw;
height: 100vh;
isolation: isolate;
}
#stage {
position: absolute;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.texture {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
opacity: 0.22;
background:
radial-gradient(circle at 50% 42%, transparent 0 35%, rgba(0, 0, 0, 0.32) 90%),
repeating-linear-gradient(
0deg,
rgba(255, 255, 255, 0.012) 0,
rgba(255, 255, 255, 0.012) 1px,
transparent 1px,
transparent 3px
);
mix-blend-mode: soft-light;
}
header {
position: absolute;
z-index: 4;
top: 27px;
left: 30px;
right: 30px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.brand {
max-width: 620px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--clay-light);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(29px, 3.4vw, 51px);
font-weight: 520;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 560px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.toolbar {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
.tool-button {
min-height: 34px;
padding: 8px 12px;
border: 1px solid var(--panel-line);
border-radius: 999px;
background: rgba(30, 32, 33, 0.72);
color: #cfcdc6;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(14px);
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease;
}
.tool-button:hover,
.tool-button.active {
border-color: rgba(229, 170, 115, 0.55);
background: rgba(87, 56, 40, 0.72);
color: #ffe0bb;
}
.tool-button .dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: currentColor;
vertical-align: 1px;
}
.panel {
position: absolute;
z-index: 4;
border: 1px solid var(--panel-line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(18px) saturate(115%);
}
#profiles {
top: 154px;
left: 30px;
width: 252px;
padding: 17px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: #dad6cd;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel-title span:last-child {
color: #777873;
font-weight: 500;
letter-spacing: 0.05em;
}
.profile-list {
display: grid;
gap: 7px;
}
.profile-button {
display: grid;
grid-template-columns: 38px 1fr 8px;
align-items: center;
gap: 10px;
width: 100%;
padding: 10px;
border: 1px solid transparent;
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
text-align: left;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.profile-button:hover {
background: rgba(255, 255, 255, 0.055);
transform: translateX(2px);
}
.profile-button.active {
border-color: rgba(229, 170, 115, 0.42);
background: rgba(167, 93, 55, 0.14);
}
.profile-button svg {
width: 34px;
height: 40px;
overflow: visible;
fill: none;
stroke: #a8a69e;
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
transition: stroke 160ms ease;
}
.profile-button.active svg {
stroke: var(--clay-light);
}
.profile-name {
display: block;
color: #ece8df;
font-size: 12px;
font-weight: 620;
letter-spacing: -0.01em;
}
.profile-note {
display: block;
margin-top: 3px;
color: #85857f;
font-size: 9px;
line-height: 1.25;
}
.profile-index {
color: #70716d;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.constraint-note {
display: flex;
gap: 9px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #898a84;
font-size: 9px;
line-height: 1.45;
}
.constraint-note::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 3px;
border-radius: 50%;
background: #86b9a4;
box-shadow: 0 0 0 4px rgba(134, 185, 164, 0.08);
}
#readout {
top: 154px;
right: 30px;
width: 294px;
padding: 18px;
}
.profile-heading {
margin-bottom: 16px;
}
#profileName {
margin: 4px 0 0;
font-size: 22px;
font-weight: 520;
letter-spacing: -0.035em;
}
#profileDescription {
margin-top: 5px;
color: #92928c;
font-size: 10px;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-height: 74px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.metric.wide {
grid-column: 1 / -1;
}
.metric-label {
display: block;
margin-bottom: 7px;
color: #858680;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
font-size: 24px;
font-weight: 510;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.metric-value small {
margin-left: 4px;
color: #95958f;
font-size: 11px;
font-weight: 500;
letter-spacing: 0;
}
.metric-value.water {
color: var(--water);
}
.fill-block {
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.fill-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #b8b7b0;
font-size: 10px;
}
#fillPercent {
color: var(--water);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0 8px;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--water) 0 var(--fill, 65%),
rgba(255, 255, 255, 0.12) var(--fill, 65%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #d6f5f1;
border-radius: 50%;
appearance: none;
background: #477f7d;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #d6f5f1;
border-radius: 50%;
background: #477f7d;
}
.range-ends {
display: flex;
justify-content: space-between;
color: #686965;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #8d8e88;
font-size: 9px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--clay);
}
.swatch.inner {
background: #d58a60;
}
.swatch.section {
background: var(--section);
}
.swatch.water {
background: var(--water);
}
.schematic {
margin-top: 14px;
padding: 10px 11px;
border-left: 2px solid rgba(229, 170, 115, 0.55);
background: rgba(229, 170, 115, 0.05);
color: #8f8f89;
font-size: 9px;
line-height: 1.5;
}
#heightTag {
position: absolute;
z-index: 3;
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 5px;
background: rgba(24, 26, 28, 0.76);
color: #aaa9a2;
font-size: 9px;
letter-spacing: 0.05em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
}
#hint {
position: absolute;
z-index: 3;
bottom: 24px;
left: 50%;
padding: 9px 14px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
background: rgba(22, 24, 25, 0.62);
color: #858680;
font-size: 9px;
letter-spacing: 0.05em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(12px);
white-space: nowrap;
}
#loading {
position: absolute;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #181a1c;
color: #aaa69d;
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
header {
top: 20px;
left: 20px;
right: 20px;
}
#profiles {
top: auto;
bottom: 20px;
left: 20px;
width: 220px;
}
#readout {
top: 128px;
right: 20px;
width: 250px;
}
#hint {
display: none;
}
}
@media (max-width: 650px) {
header {
display: block;
}
.toolbar {
justify-content: flex-start;
margin-top: 15px;
}
.subtitle {
display: none;
}
#profiles {
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
padding: 10px;
overflow-x: auto;
}
#profiles > .panel-title,
.constraint-note {
display: none;
}
.profile-list {
display: flex;
min-width: max-content;
}
.profile-button {
width: 145px;
grid-template-columns: 28px 1fr;
}
.profile-button svg {
width: 27px;
}
.profile-index,
.profile-note {
display: none;
}
#readout {
top: 120px;
right: 14px;
width: 205px;
padding: 13px;
}
.metric {
min-height: 61px;
padding: 9px;
}
.metric-value {
font-size: 19px;
}
.legend,
.schematic {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<div id="stage" aria-label="Interactive three-dimensional pottery cutaway"></div>
<div class="texture"></div>
<header>
<div class="brand">
<div class="eyebrow">Ceramic / Form Lab · Study 04</div>
<h1>Vessel, sectioned.</h1>
<p class="subtitle">
A schematic construction model of pottery profiles. The clay body morphs
between authored silhouettes while the radial wall remains separated
from the interior cavity.
</p>
</div>
<div class="toolbar">
<button class="tool-button active" id="autoButton" type="button">
<span class="dot"></span>Auto morph
</button>
<button class="tool-button active" id="cutButton" type="button">
<span class="dot"></span>Cutaway
</button>
<button class="tool-button" id="homeButton" type="button">
Reset view
</button>
</div>
</header>
<section class="panel" id="profiles" aria-label="Authored vessel profiles">
<div class="panel-title">
<span>Authored profiles</span>
<span>04 forms</span>
</div>
<div class="profile-list">
<button class="profile-button active" data-profile="0" type="button">
<svg viewBox="0 0 40 48" aria-hidden="true">
<path d="M14 5h12M16 5v5C9 14 7 19 8 28c1 8 5 14 12 14s11-6 12-14c1-9-1-14-8-18V5" />
<path d="M17 30c2-2 4-2 6 0" />
</svg>
<span>
<span class="profile-name">Bellied jar</span>
<span class="profile-note">wide shoulder · short neck</span>
</span>
<span class="profile-index">01</span>
</button>
<button class="profile-button" data-profile="1" type="button">
<svg viewBox="0 0 40 48" aria-hidden="true">
<path d="M15 3h10M16 3v6c0 3-2 5-5 8-4 4-5 10-3 19 1 6 5 9 12 9s11-3 12-9c2-9 1-15-3-19-3-3-5-5-5-8V3" />
<path d="M15 26c3-2 7-2 10 0" />
</svg>
<span>
<span class="profile-name">Tall bottle</span>
<span class="profile-note">narrow throat · lifted shoulder</span>
</span>
<span class="profile-index">02</span>
</button>
<button class="profile-button" data-profile="2" type="button">
<svg viewBox="0 0 40 48" aria-hidden="true">
<path d="M11 5h18l-1 34c-4 3-12 3-16 0L11 5Z" />
<path d="M12 35c5 2 11 2 16 0" />
</svg>
<span>
<span class="profile-name">Straight beaker</span>
<span class="profile-note">cylindrical body · even gauge</span>
</span>
<span class="profile-index">03</span>
</button>
<button class="profile-button" data-profile="3" type="button">
<svg viewBox="0 0 40 48" aria-hidden="true">
<path d="M7 9h26M9 9c1 10 3 23 11 30 8-7 10-20 11-30" />
<path d="M13 29c4 3 10 3 14 0" />
</svg>
<span>
<span class="profile-name">Open bowl</span>
<span class="profile-note">low body · continuous flare</span>
</span>
<span class="profile-index">04</span>
</button>
</div>
<div class="constraint-note">
Shape-preserving radial interpolation keeps the inner wall outside the
axis and below the outer surface.
</div>
</section>
<section class="panel" id="readout" aria-label="Live vessel measurements">
<div class="profile-heading">
<div class="eyebrow">Live profile</div>
<h2 id="profileName">Bellied jar</h2>
<div id="profileDescription">wide shoulder · short neck</div>
</div>
<div class="metric-grid">
<div class="metric wide">
<span class="metric-label">Calculated capacity</span>
<div class="metric-value water">
<span id="capacityValue">0.00</span><small>L</small>
</div>
</div>
<div class="metric">
<span class="metric-label">Wall</span>
<div class="metric-value"><span id="wallValue">0</span><small>mm</small></div>
</div>
<div class="metric">
<span class="metric-label">Height</span>
<div class="metric-value"><span id="heightValue">0</span><small>cm</small></div>
</div>
</div>
<div class="fill-block">
<label class="fill-label" for="fillSlider">
<span>Capacity fill</span>
<span id="fillPercent">65%</span>
</label>
<input
id="fillSlider"
type="range"
min="0"
max="100"
value="65"
aria-label="Liquid fill percentage"
/>
<div class="range-ends">
<span>Empty</span>
<span>Full</span>
</div>
</div>
<div class="legend" aria-label="Section legend">
<div class="legend-item"><span class="swatch"></span>Outer clay</div>
<div class="legend-item"><span class="swatch inner"></span>Inner cavity</div>
<div class="legend-item"><span class="swatch section"></span>Cut material</div>
<div class="legend-item"><span class="swatch water"></span>Liquid</div>
</div>
<div class="schematic">
Schematic model. Capacity is a design-space estimate derived from the
displayed cavity, not a manufacturing specification.
</div>
</section>
<div id="heightTag">H 0.0 cm</div>
<div id="hint">Drag to orbit · Scroll to zoom · Select a profile to morph</div>
<div id="loading">Preparing clay form…</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Profile mathematics
// -------------------------------------------------------------------------
const RADIUS_SAMPLES = 129;
const MORPH_DURATION = 2400;
const CYCLE_PAUSE = 5200;
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
/*
* Shape-preserving monotone cubic interpolation.
* It prevents authored control points from producing an oscillating or
* self-crossing radial profile.
*/
function monotoneSpline(points) {
const xs = points.map((p) => p[0]);
const ys = points.map((p) => p[1]);
const n = xs.length;
const h = [];
const delta = [];
const m = new Array(n).fill(0);
for (let i = 0; i < n - 1; i++) {
h[i] = xs[i + 1] - xs[i];
delta[i] = (ys[i + 1] - ys[i]) / h[i];
}
m[0] = delta[0];
m[n - 1] = delta[n - 2];
for (let i = 1; i < n - 1; i++) {
if (delta[i - 1] * delta[i] <= 0) {
m[i] = 0;
} else {
const w1 = 2 * h[i] + h[i - 1];
const w2 = h[i] + 2 * h[i - 1];
m[i] = (w1 + w2) / (w1 / delta[i - 1] + w2 / delta[i]);
}
}
return function evaluate(x) {
if (x <= xs[0]) return ys[0];
if (x >= xs[n - 1]) return ys[n - 1];
let i = 0;
while (i < n - 2 && x > xs[i + 1]) i++;
const t = (x - xs[i]) / h[i];
const t2 = t * t;
const t3 = t2 * t;
return (
(2 * t3 - 3 * t2 + 1) * ys[i] +
(t3 - 2 * t2 + t) * h[i] * m[i] +
(-2 * t3 + 3 * t2) * ys[i + 1] +
(t3 - t2) * h[i] * m[i + 1]
);
};
}
function makeProfile(index, name, description, height, wall, controls) {
const spline = monotoneSpline(controls);
const radii = Array.from({ length: RADIUS_SAMPLES }, (_, i) => {
const u = i / (RADIUS_SAMPLES - 1);
return Math.max(wall + 0.45, spline(u));
});
return {
index,
name,
description,
height,
wall,
floor: Math.max(0.58, wall * 1.15),
radii
};
}
const profiles = [
makeProfile(
0,
"Bellied jar",
"wide shoulder · short neck",
18,
0.85,
[
[0.00, 4.4],
[0.10, 6.1],
[0.30, 7.5],
[0.52, 7.6],
[0.72, 6.3],
[0.88, 4.6],
[1.00, 4.9]
]
),
makeProfile(
1,
"Tall bottle",
"narrow throat · lifted shoulder",
31,
0.72,
[
[0.00, 4.6],
[0.10, 5.5],
[0.30, 7.0],
[0.50, 7.7],
[0.67, 6.2],
[0.84, 3.2],
[1.00, 3.0]
]
),
makeProfile(
2,
"Straight beaker",
"cylindrical body · even gauge",
20,
0.72,
[
[0.00, 5.0],
[0.12, 5.05],
[0.32, 5.12],
[0.52, 5.18],
[0.72, 5.18],
[0.88, 5.22],
[1.00, 5.25]
]
),
makeProfile(
3,
"Open bowl",
"low body · continuous flare",
10.5,
0.70,
[
[0.00, 3.4],
[0.12, 5.4],
[0.36, 7.3],
[0.60, 8.25],
[0.82, 8.75],
[1.00, 8.95]
]
)
];
function smoothstep(t) {
t = clamp(t, 0, 1);
return t * t * (3 - 2 * t);
}
function interpolateShape(a, b, t) {
const e = smoothstep(t);
const height = lerp(a.height, b.height, e);
const wall = lerp(a.wall, b.wall, e);
const radii = a.radii.map((radius, i) => {
const value = lerp(radius, b.radii[i], e);
// Hard construction constraint: a positive cavity must always remain
// inside the outer radial surface.
return Math.max(value, wall + 0.45);
});
return {
index: b.index,
name: b.name,
description: b.description,
height,
wall,
floor: Math.max(0.58, wall * 1.15),
radii
};
}
function cloneShape(shape) {
return {
...shape,
radii: shape.radii.slice()
};
}
function radiusAt(shape, y) {
const u = clamp(y / shape.height, 0, 1);
const p = u * (RADIUS_SAMPLES - 1);
const i = Math.min(RADIUS_SAMPLES - 2, Math.floor(p));
const f = p - i;
return lerp(shape.radii[i], shape.radii[i + 1], f);
}
function innerRadiusAt(shape, y) {
if (y < shape.floor) return 0;
return Math.max(0.05, radiusAt(shape, y) - shape.wall);
}
// -------------------------------------------------------------------------
// DOM and renderer
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.localClippingEnabled = true;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x181a1c);
scene.fog = new THREE.Fog(0x181a1c, 58, 112);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
180
);
// Removes the positive-X half in world space, leaving a stationary
// section plane while the axisymmetric clay body rotates.
const clipPlane = new THREE.Plane(new THREE.Vector3(-1, 0, 0), 0);
const hemisphere = new THREE.HemisphereLight(0xffe7cf, 0x25292b, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffd0a0, 3.1);
keyLight.position.set(18, 36, 24);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -34;
keyLight.shadow.camera.right = 34;
keyLight.shadow.camera.top = 40;
keyLight.shadow.camera.bottom = -18;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 100;
keyLight.shadow.bias = -0.00045;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8fc8d0, 1.15);
rimLight.position.set(-22, 15, -18);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xe79057, 22, 75, 2);
warmFill.position.set(20, 10, -18);
scene.add(warmFill);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(40, 96),
new THREE.MeshStandardMaterial({
color: 0x202224,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.23;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(72, 72, 0x655a50, 0x343536);
grid.position.y = -0.205;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(11.6, 12.3, 0.32, 96),
new THREE.MeshStandardMaterial({
color: 0x2a2c2d,
roughness: 0.9
})
);
pedestal.position.y = -0.38;
pedestal.receiveShadow = true;
pedestal.castShadow = true;
scene.add(pedestal);
// -------------------------------------------------------------------------
// Reusable parametric geometry
// -------------------------------------------------------------------------
function createGrid(rows, columns, flip = false) {
const stride = columns + 1;
const positions = new Float32Array((rows + 1) * stride * 3);
const uvs = new Float32Array((rows + 1) * stride * 2);
const indices = [];
for (let row = 0; row <= rows; row++) {
for (let col = 0; col <= columns; col++) {
const index = row * stride + col;
uvs[index * 2] = col / columns;
uvs[index * 2 + 1] = row / rows;
}
}
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const a = row * stride + col;
const b = a + 1;
const c = a + stride;
const d = c + 1;
if (flip) {
indices.push(a, c, b, b, c, d);
} else {
indices.push(a, b, c, b, d, c);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
geometry.setAttribute("uv", new THREE.BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function updateGrid(geometry, rows, columns, pointFunction) {
const position = geometry.getAttribute("position");
const array = position.array;
const stride = columns + 1;
const p = new THREE.Vector3();
for (let row = 0; row <= rows; row++) {
for (let col = 0; col <= columns; col++) {
pointFunction(col / columns, row / rows, p);
const index = row * stride + col;
array[index * 3] = p.x;
array[index * 3 + 1] = p.y;
array[index * 3 + 2] = p.z;
}
}
position.needsUpdate = true;
geometry.computeVertexNormals();
}
function createDynamicGeometry(maxVertices) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(maxVertices * 3), 3).setUsage(
THREE.DynamicDrawUsage
)
);
geometry.setDrawRange(0, 0);
return geometry;
}
function uploadTriangles(geometry, vertices) {
const attribute = geometry.getAttribute("position");
if (vertices.length > attribute.array.length) {
throw new Error("Dynamic geometry capacity exceeded.");
}
attribute.array.set(vertices);
attribute.needsUpdate = true;
geometry.setDrawRange(0, vertices.length / 3);
geometry.computeVertexNormals();
}
function pushQuad(target, a, b, c, d) {
target.push(
...a, ...b, ...c,
...a, ...c, ...d
);
}
// -------------------------------------------------------------------------
// Clay shell
// -------------------------------------------------------------------------
const vessel = new THREE.Group();
scene.add(vessel);
const shellMaterials = [];
function clayMaterial(color, extra = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
clippingPlanes: [clipPlane],
clipShadows: true,
side: THREE.FrontSide,
...extra
});
shellMaterials.push(material);
return material;
}
const outerMaterial = clayMaterial(0xb96846);
const innerMaterial = clayMaterial(0xd58b61);
const rimMaterial = clayMaterial(0xe3a16e);
const undersideMaterial = clayMaterial(0x8e4938);
const markMaterial = clayMaterial(0x743b2e);
const WALL_ROWS = 42;
const SEGMENTS = 96;
const outerMesh = new THREE.Mesh(
createGrid(WALL_ROWS, SEGMENTS, true),
outerMaterial
);
const innerMesh = new THREE.Mesh(
createGrid(WALL_ROWS, SEGMENTS, false),
innerMaterial
);
const rimMesh = new THREE.Mesh(
createGrid(1, SEGMENTS, false),
rimMaterial
);
const undersideMesh = new THREE.Mesh(
createGrid(1, SEGMENTS, true),
undersideMaterial
);
const floorMesh = new THREE.Mesh(
createGrid(1, SEGMENTS, false),
innerMaterial
);
for (const mesh of [
outerMesh,
innerMesh,
rimMesh,
undersideMesh,
floorMesh
]) {
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
vessel.add(mesh);
}
// Small registration marks make the rotation visible on the otherwise
// rotationally symmetric clay body.
const marks = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.11, 0.42, 0.075),
markMaterial,
24
);
marks.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
marks.castShadow = true;
marks.frustumCulled = false;
vessel.add(marks);
const dummy = new THREE.Object3D();
// -------------------------------------------------------------------------
// Cut section and liquid
// -------------------------------------------------------------------------
const capGeometry = createDynamicGeometry(2400);
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xefb56d,
emissive: 0x4a2410,
emissiveIntensity: 0.18,
roughness: 0.7,
side: THREE.DoubleSide
});
const capMesh = new THREE.Mesh(capGeometry, capMaterial);
capMesh.frustumCulled = false;
scene.add(capMesh);
const capLineGeometry = createDynamicGeometry(1000);
const capLines = new THREE.LineSegments(
capLineGeometry,
new THREE.LineBasicMaterial({
color: 0xffe0b4,
transparent: true,
opacity: 0.78
})
);
capLines.frustumCulled = false;
scene.add(capLines);
const fillWallMaterial = new THREE.MeshStandardMaterial({
color: 0x62c9c8,
roughness: 0.32,
metalness: 0,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide,
clippingPlanes: [clipPlane],
clipShadows: false
});
const fillTopMaterial = new THREE.MeshStandardMaterial({
color: 0x79ded9,
roughness: 0.22,
metalness: 0,
transparent: true,
opacity: 0.48,
depthWrite: false,
side: THREE.DoubleSide,
clippingPlanes: [clipPlane],
clipShadows: false
});
const fillSectionMaterial = new THREE.MeshBasicMaterial({
color: 0x64d1cf,
transparent: true,
opacity: 0.32,
depthWrite: false,
side: THREE.DoubleSide
});
const fillWall = new THREE.Mesh(
createGrid(26, SEGMENTS, false),
fillWallMaterial
);
const fillTop = new THREE.Mesh(
createGrid(1, SEGMENTS, false),
fillTopMaterial
);
const fillSection = new THREE.Mesh(
createDynamicGeometry(1400),
fillSectionMaterial
);
for (const mesh of [fillWall, fillTop, fillSection]) {
mesh.frustumCulled = false;
mesh.renderOrder = 3;
scene.add(mesh);
}
// -------------------------------------------------------------------------
// Dimension guide
// -------------------------------------------------------------------------
const guideGeometry = createDynamicGeometry(100);
const guide = new THREE.LineSegments(
guideGeometry,
new THREE.LineBasicMaterial({
color: 0x777b78,
transparent: true,
opacity: 0.6
})
);
guide.frustumCulled = false;
scene.add(guide);
const heightTag = document.getElementById("heightTag");
// -------------------------------------------------------------------------
// Capacity calculations
// -------------------------------------------------------------------------
function integrateInner(shape, y0, y1, samples = 180) {
const dy = (y1 - y0) / samples;
let volume = 0;
for (let i = 0; i < samples; i++) {
const yA = y0 + i * dy;
const yB = y0 + (i + 1) * dy;
const rA = innerRadiusAt(shape, yA);
const rB = innerRadiusAt(shape, yB);
volume += Math.PI * 0.5 * (rA * rA + rB * rB) * dy;
}
return volume;
}
function capacityOf(shape) {
return integrateInner(shape, shape.floor, shape.height, 240);
}
function fillHeightFor(shape, fraction) {
if (fraction <= 0) return shape.floor;
const total = capacityOf(shape);
const target = total * fraction;
let low = shape.floor;
let high = shape.height;
for (let i = 0; i < 22; i++) {
const middle = (low + high) * 0.5;
const amount = integrateInner(shape, shape.floor, middle, 90);
if (amount < target) low = middle;
else high = middle;
}
return (low + high) * 0.5;
}
// -------------------------------------------------------------------------
// Geometry updates
// -------------------------------------------------------------------------
function updateVessel(shape) {
updateGrid(
outerMesh.geometry,
WALL_ROWS,
SEGMENTS,
(u, v, p) => {
const y = v * shape.height;
const r = radiusAt(shape, y);
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, y, Math.sin(theta) * r);
}
);
updateGrid(
innerMesh.geometry,
WALL_ROWS,
SEGMENTS,
(u, v, p) => {
const y = lerp(shape.floor, shape.height, v);
const r = innerRadiusAt(shape, y);
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, y, Math.sin(theta) * r);
}
);
updateGrid(
rimMesh.geometry,
1,
SEGMENTS,
(u, v, p) => {
const outer = radiusAt(shape, shape.height);
const inner = innerRadiusAt(shape, shape.height);
const r = lerp(inner, outer, v);
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, shape.height, Math.sin(theta) * r);
}
);
updateGrid(
undersideMesh.geometry,
1,
SEGMENTS,
(u, v, p) => {
const r = radiusAt(shape, 0) * v;
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, 0, Math.sin(theta) * r);
}
);
updateGrid(
floorMesh.geometry,
1,
SEGMENTS,
(u, v, p) => {
const r = innerRadiusAt(shape, shape.floor) * v;
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, shape.floor, Math.sin(theta) * r);
}
);
for (let i = 0; i < 24; i++) {
const row = Math.floor(i / 8);
const column = i % 8;
const u = 0.23 + row * 0.235;
const y = u * shape.height;
const theta = (column / 8) * Math.PI * 2 + row * 0.31;
const r = radiusAt(shape, y) + 0.045;
dummy.position.set(
Math.cos(theta) * r,
y,
Math.sin(theta) * r
);
dummy.rotation.set(0, Math.PI / 2 - theta, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
marks.setMatrixAt(i, dummy.matrix);
}
marks.instanceMatrix.needsUpdate = true;
updateSection(shape);
updateLiquid(shape);
updateGuide(shape);
updateReadout(shape);
}
function updateSection(shape) {
const triangles = [];
const lines = [];
const baseRows = 7;
for (let i = 0; i < baseRows; i++) {
const y0 = lerp(0, shape.floor, i / baseRows);
const y1 = lerp(0, shape.floor, (i + 1) / baseRows);
const r0 = radiusAt(shape, y0);
const r1 = radiusAt(shape, y1);
pushQuad(
triangles,
[0, y0, -r0],
[0, y0, r0],
[0, y1, r1],
[0, y1, -r1]
);
}
for (const side of [1, -1]) {
for (let i = 0; i < WALL_ROWS; i++) {
const y0 = lerp(shape.floor, shape.height, i / WALL_ROWS);
const y1 = lerp(shape.floor, shape.height, (i + 1) / WALL_ROWS);
const outer0 = radiusAt(shape, y0);
const outer1 = radiusAt(shape, y1);
const inner0 = innerRadiusAt(shape, y0);
const inner1 = innerRadiusAt(shape, y1);
if (side > 0) {
pushQuad(
triangles,
[0, y0, inner0],
[0, y0, outer0],
[0, y1, outer1],
[0, y1, inner1]
);
} else {
pushQuad(
triangles,
[0, y0, -outer0],
[0, y0, -inner0],
[0, y1, -inner1],
[0, y1, -outer1]
);
}
}
}
uploadTriangles(capGeometry, triangles);
function line(a, b) {
lines.push(...a, ...b);
}
for (let i = 0; i < WALL_ROWS; i++) {
const y0 = lerp(0, shape.height, i / WALL_ROWS);
const y1 = lerp(0, shape.height, (i + 1) / WALL_ROWS);
const ro0 = radiusAt(shape, y0);
const ro1 = radiusAt(shape, y1);
line([0, y0, ro0], [0, y1, ro1]);
line([0, y0, -ro0], [0, y1, -ro1]);
}
for (let i = 0; i < WALL_ROWS; i++) {
const y0 = lerp(shape.floor, shape.height, i / WALL_ROWS);
const y1 = lerp(shape.floor, shape.height, (i + 1) / WALL_ROWS);
const ri0 = innerRadiusAt(shape, y0);
const ri1 = innerRadiusAt(shape, y1);
line([0, y0, ri0], [0, y1, ri1]);
line([0, y0, -ri0], [0, y1, -ri1]);
}
const bottomRadius = radiusAt(shape, 0);
const floorRadius = innerRadiusAt(shape, shape.floor);
const rimOuter = radiusAt(shape, shape.height);
const rimInner = innerRadiusAt(shape, shape.height);
line([0, 0, -bottomRadius], [0, 0, bottomRadius]);
line([0, shape.floor, -floorRadius], [0, shape.floor, floorRadius]);
line([0, shape.height, rimInner], [0, shape.height, rimOuter]);
line([0, shape.height, -rimOuter], [0, shape.height, -rimInner]);
uploadTriangles(capLineGeometry, lines);
}
function updateLiquid(shape) {
const fillY = fillHeightFor(shape, fillFraction);
if (fillFraction <= 0.001 || fillY <= shape.floor + 0.01) {
fillWall.visible = false;
fillTop.visible = false;
fillSection.visible = false;
return;
}
fillWall.visible = true;
fillTop.visible = true;
updateGrid(
fillWall.geometry,
26,
SEGMENTS,
(u, v, p) => {
const y = lerp(shape.floor, fillY, v);
const r = Math.max(0.04, innerRadiusAt(shape, y) - 0.035);
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, y, Math.sin(theta) * r);
}
);
updateGrid(
fillTop.geometry,
1,
SEGMENTS,
(u, v, p) => {
const r = Math.max(0.04, innerRadiusAt(shape, fillY) - 0.035);
const theta = u * Math.PI * 2;
p.set(Math.cos(theta) * r, fillY, Math.sin(theta) * r);
}
);
const sectionVertices = [];
const rows = 28;
for (let i = 0; i < rows; i++) {
const y0 = lerp(shape.floor, fillY, i / rows);
const y1 = lerp(shape.floor, fillY, (i + 1) / rows);
const r0 = innerRadiusAt(shape, y0);
const r1 = innerRadiusAt(shape, y1);
pushQuad(
sectionVertices,
[0.012, y0, -r0],
[0.012, y0, r0],
[0.012, y1, r1],
[0.012, y1, -r1]
);
}
uploadTriangles(fillSection.geometry, sectionVertices);
fillSection.visible = cutawayEnabled;
}
function updateGuide(shape) {
const x = -12.5;
const z = 4;
const vertices = [];
vertices.push(x, 0, z, x, shape.height, z);
vertices.push(x - 0.7, 0, z, x + 0.7, 0, z);
vertices.push(x - 0.7, shape.height, z, x + 0.7, shape.height, z);
const middle = shape.height * 0.5;
vertices.push(x - 0.35, middle, z, x + 0.35, middle, z);
uploadTriangles(guideGeometry, vertices);
heightTag.textContent = `H ${shape.height.toFixed(1)} cm`;
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const capacityValue = document.getElementById("capacityValue");
const wallValue = document.getElementById("wallValue");
const heightValue = document.getElementById("heightValue");
const profileName = document.getElementById("profileName");
const profileDescription = document.getElementById("profileDescription");
const fillSlider = document.getElementById("fillSlider");
const fillPercent = document.getElementById("fillPercent");
const autoButton = document.getElementById("autoButton");
const cutButton = document.getElementById("cutButton");
const homeButton = document.getElementById("homeButton");
const profileButtons = [...document.querySelectorAll(".profile-button")];
let fillFraction = Number(fillSlider.value) / 100;
let cutawayEnabled = true;
let autoMorph = !reducedMotion;
const morph = {
from: profiles[0],
to: profiles[0],
t: 1,
startedAt: 0
};
let currentShape = interpolateShape(morph.from, morph.to, morph.t);
let nextMorphAt = performance.now() + CYCLE_PAUSE;
function updateReadout(shape) {
capacityValue.textContent = (capacityOf(shape) / 1000).toFixed(2);
wallValue.textContent = (shape.wall * 10).toFixed(1);
heightValue.textContent = shape.height.toFixed(1);
profileName.textContent = shape.name;
profileDescription.textContent = shape.description;
}
function updateActiveProfile(index) {
profileButtons.forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.profile) === index
);
});
}
function beginMorph(target, manual = false) {
morph.from = cloneShape(currentShape);
morph.to = target;
morph.t = 0;
morph.startedAt = performance.now();
nextMorphAt = performance.now() + MORPH_DURATION + CYCLE_PAUSE;
if (manual) {
autoMorph = false;
autoButton.classList.remove("active");
}
updateActiveProfile(target.index);
}
function refreshShape() {
currentShape = interpolateShape(morph.from, morph.to, morph.t);
updateVessel(currentShape);
}
fillSlider.addEventListener("input", () => {
fillFraction = Number(fillSlider.value) / 100;
fillPercent.textContent = `${fillSlider.value}%`;
fillSlider.style.setProperty("--fill", `${fillSlider.value}%`);
updateLiquid(currentShape);
});
fillSlider.style.setProperty("--fill", `${fillSlider.value}%`);
profileButtons.forEach((button) => {
button.addEventListener("click", () => {
const index = Number(button.dataset.profile);
beginMorph(profiles[index], true);
});
});
autoButton.addEventListener("click", () => {
autoMorph = !autoMorph;
autoButton.classList.toggle("active", autoMorph);
if (autoMorph) {
nextMorphAt = performance.now() + 900;
}
});
autoButton.classList.toggle("active", autoMorph);
function setCutaway(enabled) {
cutawayEnabled = enabled;
for (const material of shellMaterials) {
material.clippingPlanes = enabled ? [clipPlane] : [];
material.needsUpdate = true;
}
for (const material of [fillWallMaterial, fillTopMaterial]) {
material.clippingPlanes = enabled ? [clipPlane] : [];
material.needsUpdate = true;
}
capMesh.visible = enabled;
capLines.visible = enabled;
fillSection.visible =
enabled &&
fillFraction > 0.001 &&
fillHeightFor(currentShape, fillFraction) > currentShape.floor + 0.01;
cutButton.classList.toggle("active", enabled);
}
cutButton.addEventListener("click", () => {
setCutaway(!cutawayEnabled);
});
// -------------------------------------------------------------------------
// Direct camera controls
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.68,
phi: 1.17,
radius: 46,
target: new THREE.Vector3(0, 8.5, 0),
autoFrame: true
};
homeButton.addEventListener("click", () => {
cameraState.theta = 0.68;
cameraState.phi = 1.17;
cameraState.autoFrame = true;
});
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.34, 1.47);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.radius = clamp(
cameraState.radius * (pinchDistance / distance),
24,
88
);
cameraState.autoFrame = false;
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
24,
88
);
cameraState.autoFrame = false;
},
{ passive: false }
);
function updateCamera() {
const desiredRadius = clamp(currentShape.height * 1.55, 31, 52);
if (cameraState.autoFrame) {
cameraState.radius = lerp(
cameraState.radius,
desiredRadius,
0.035
);
}
cameraState.target.set(0, currentShape.height * 0.48, 0);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const projectedTag = new THREE.Vector3();
function updateHeightTag() {
projectedTag.set(
-12.5,
currentShape.height * 0.57,
4
).project(camera);
const x = (projectedTag.x * 0.5 + 0.5) * innerWidth;
const y = (-projectedTag.y * 0.5 + 0.5) * innerHeight;
heightTag.style.left = `${x}px`;
heightTag.style.top = `${y}px`;
heightTag.style.opacity =
projectedTag.z > -1 && projectedTag.z < 1 ? "1" : "0";
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
refreshShape();
updateActiveProfile(0);
const clock = new THREE.Clock();
let firstFrame = true;
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (morph.t < 1) {
morph.t = clamp((now - morph.startedAt) / MORPH_DURATION, 0, 1);
refreshShape();
if (morph.t >= 1) {
currentShape = cloneShape(morph.to);
updateVessel(currentShape);
}
} else if (autoMorph && now >= nextMorphAt) {
const nextIndex = (morph.to.index + 1) % profiles.length;
beginMorph(profiles[nextIndex]);
}
if (!reducedMotion) {
vessel.rotation.y += delta * 0.18;
}
updateCamera();
updateHeightTag();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
}
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```