Prompt specification
Build or customize the Three.js 3D scene "Vessel Capacity and Stability Studio" 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: Vessel Capacity and Stability Studio
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/vessel-capacity-and-stability-studio-x3332
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts pottery vessel shapes, walls, and capacity. Let users change a vessel's profile within bounded parameters. Compare approximate capacity and support footprint, showing geometric estimates rather than a complete ceramic engineering simulation. Voxel style.
Working Three.js Starter (vessel-capacity-and-stability-studio-x3332):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Vessel Lab</title>
<style>
:root {
--paper: #f3ecde;
--paper-dark: #e8decc;
--ink: #302823;
--muted: #786d61;
--line: #d8ccb8;
--live: #c96f4f;
--live-dark: #8e4534;
--reference: #4f8d88;
--reference-dark: #2f6662;
--water: #4e94b8;
--panel: rgba(250, 246, 238, 0.94);
--shadow: 0 12px 35px rgba(64, 48, 31, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
display: grid;
grid-template-columns: 320px minmax(0, 1fr);
width: 100vw;
height: 100vh;
}
.controls {
position: relative;
z-index: 5;
overflow-y: auto;
padding: 26px 24px 24px;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 34%),
var(--paper);
border-right: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 8px;
color: var(--live-dark);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 2rem;
font-weight: 500;
line-height: 1;
letter-spacing: -0.035em;
}
.intro {
margin: 13px 0 22px;
color: var(--muted);
font-size: 0.84rem;
line-height: 1.55;
}
.section {
padding: 18px 0;
border-top: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-heading span {
color: var(--muted);
font-size: 0.68rem;
}
.preset-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 7px;
}
.preset {
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.38);
cursor: pointer;
font-size: 0.74rem;
font-weight: 700;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.preset:hover {
transform: translateY(-1px);
border-color: #bcae98;
background: rgba(255, 255, 255, 0.72);
}
.preset.active {
color: #fff;
border-color: var(--live);
background: var(--live);
}
.slider-row {
margin-bottom: 17px;
}
.slider-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.slider-label label {
font-size: 0.78rem;
font-weight: 650;
}
output {
min-width: 64px;
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 0.73rem;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
border-radius: 99px;
outline: none;
appearance: none;
background: linear-gradient(90deg, var(--live) var(--fill, 50%), #d8ccb8 var(--fill, 50%));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--live);
box-shadow: 0 0 0 1px var(--live-dark);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--live);
box-shadow: 0 0 0 1px var(--live-dark);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #9a8d7e;
font-size: 0.61rem;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.button {
min-height: 39px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.5);
cursor: pointer;
font-size: 0.74rem;
font-weight: 750;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
.button:hover {
transform: translateY(-1px);
border-color: #bcae98;
background: #fffaf0;
}
.button.primary {
color: #fff;
border-color: var(--live);
background: var(--live);
}
.button.active {
color: #fff;
border-color: var(--reference-dark);
background: var(--reference-dark);
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
color: var(--muted);
font-size: 0.73rem;
}
.check-row input {
width: 16px;
height: 16px;
accent-color: var(--live);
}
.estimate-note {
padding-top: 16px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 0.67rem;
line-height: 1.55;
}
.estimate-note strong {
color: var(--ink);
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
background: #eee6d7;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.stage-header {
position: absolute;
z-index: 3;
top: 18px;
left: 20px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: none;
}
.estimate-badge {
padding: 7px 10px;
border: 1px solid rgba(94, 76, 54, 0.16);
border-radius: 99px;
color: #66594b;
background: rgba(250, 246, 238, 0.76);
backdrop-filter: blur(8px);
font-size: 0.62rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.camera-tools {
position: absolute;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
gap: 5px;
}
.camera-tools button {
width: 33px;
height: 33px;
padding: 0;
border: 1px solid rgba(94, 76, 54, 0.18);
border-radius: 8px;
background: rgba(250, 246, 238, 0.84);
cursor: pointer;
font-size: 0.86rem;
font-weight: 800;
}
.camera-tools button:hover {
background: #fffaf0;
}
.vessel-label {
position: absolute;
z-index: 2;
top: 0;
left: 0;
padding: 6px 9px;
border-radius: 6px;
color: #fff;
pointer-events: none;
white-space: nowrap;
font-size: 0.61rem;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
box-shadow: 0 5px 16px rgba(54, 39, 26, 0.15);
transform: translate(-50%, -50%);
}
.vessel-label.live {
background: var(--live-dark);
}
.vessel-label.reference {
background: var(--reference-dark);
}
.camera-hint {
position: absolute;
z-index: 3;
bottom: 18px;
left: 20px;
max-width: 220px;
color: #74695d;
pointer-events: none;
font-size: 0.65rem;
line-height: 1.5;
}
.metrics {
position: absolute;
z-index: 4;
right: 18px;
bottom: 18px;
width: min(322px, calc(100% - 36px));
padding: 16px;
border: 1px solid rgba(94, 76, 54, 0.16);
border-radius: 14px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.metrics-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.metrics-header h2 {
margin: 0;
font-size: 0.74rem;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.legend {
display: flex;
gap: 10px;
color: var(--muted);
font-size: 0.62rem;
}
.legend span {
display: flex;
align-items: center;
gap: 4px;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.dot.live {
background: var(--live);
}
.dot.reference {
background: var(--reference);
}
.metric-block {
padding: 12px 0;
border-top: 1px solid var(--line);
}
.metric-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
}
.metric-heading h3 {
margin: 0;
font-size: 0.72rem;
}
.ratio {
color: var(--muted);
font-size: 0.65rem;
font-variant-numeric: tabular-nums;
}
.metric-row {
display: grid;
grid-template-columns: 68px 1fr 66px;
align-items: center;
gap: 8px;
margin-top: 7px;
font-size: 0.65rem;
}
.metric-row > span {
color: var(--muted);
}
.metric-row strong {
font-size: 0.68rem;
font-variant-numeric: tabular-nums;
text-align: right;
}
.track {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: #ded4c4;
}
.track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 280ms ease;
}
#capBarCurrent {
background: var(--live);
}
#capBarReference {
background: var(--reference);
}
#footBarCurrent {
background: var(--live);
}
#footBarReference {
background: var(--reference);
}
.metric-facts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.fact {
padding: 9px;
border-radius: 8px;
background: rgba(225, 214, 196, 0.38);
}
.fact span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 0.58rem;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.fact strong {
font-size: 0.72rem;
font-variant-numeric: tabular-nums;
}
.method-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 0.59rem;
line-height: 1.45;
}
.toast {
position: absolute;
z-index: 10;
top: 64px;
left: 50%;
padding: 9px 13px;
border-radius: 8px;
color: #fff;
background: rgba(48, 40, 35, 0.88);
pointer-events: none;
opacity: 0;
transform: translate(-50%, -8px);
transition:
opacity 180ms ease,
transform 180ms ease;
font-size: 0.68rem;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 850px) {
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(420px, 58vh) auto;
height: auto;
min-height: 100vh;
}
.stage {
grid-row: 1;
}
.controls {
grid-row: 2;
overflow: visible;
border-top: 1px solid var(--line);
border-right: 0;
}
.metrics {
width: 292px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 540px) {
.stage-header {
top: 12px;
left: 12px;
}
.estimate-badge {
max-width: 185px;
font-size: 0.54rem;
}
.camera-tools {
top: 12px;
right: 12px;
}
.metrics {
right: 10px;
bottom: 10px;
width: calc(100% - 20px);
padding: 12px;
}
.metric-facts,
.method-note {
display: none;
}
.controls {
padding: 24px 20px;
}
}
</style>
</head>
<body>
<div class="app">
<aside class="controls" aria-label="Vessel profile controls">
<p class="eyebrow">Voxel Vessel Lab</p>
<h1>Shape, wall & capacity</h1>
<p class="intro">
Edit a revolved vessel profile, inspect its voxel shell, and compare
geometric capacity with a pinned reference.
</p>
<section class="section">
<div class="section-heading">
<h2>Starting forms</h2>
<span>bounded profiles</span>
</div>
<div class="preset-grid">
<button class="preset" data-preset="bowl">Bowl</button>
<button class="preset" data-preset="jar">Jar</button>
<button class="preset active" data-preset="amphora">Amphora</button>
<button class="preset" data-preset="vase">Vase</button>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Profile parameters</h2>
<span id="profileName">Amphora</span>
</div>
<div class="slider-row">
<div class="slider-label">
<label for="height">Height</label>
<output id="heightOut">55 cm</output>
</div>
<input id="height" type="range" min="22" max="62" step="1" value="55" />
<div class="range-ends"><span>22 cm</span><span>62 cm</span></div>
</div>
<div class="slider-row">
<div class="slider-label">
<label for="belly">Maximum diameter</label>
<output id="bellyOut">34 cm</output>
</div>
<input id="belly" type="range" min="18" max="38" step="1" value="34" />
<div class="range-ends"><span>18 cm</span><span>38 cm</span></div>
</div>
<div class="slider-row">
<div class="slider-label">
<label for="base">Base diameter</label>
<output id="baseOut">12 cm</output>
</div>
<input id="base" type="range" min="9" max="24" step="1" value="12" />
<div class="range-ends"><span>9 cm</span><span>24 cm</span></div>
</div>
<div class="slider-row">
<div class="slider-label">
<label for="mouth">Mouth diameter</label>
<output id="mouthOut">10 cm</output>
</div>
<input id="mouth" type="range" min="8" max="34" step="1" value="10" />
<div class="range-ends"><span>8 cm</span><span>34 cm</span></div>
</div>
<div class="slider-row">
<div class="slider-label">
<label for="bellyPos">Belly height</label>
<output id="bellyPosOut">56%</output>
</div>
<input id="bellyPos" type="range" min="25" max="85" step="1" value="56" />
<div class="range-ends"><span>25%</span><span>85%</span></div>
</div>
<div class="slider-row">
<div class="slider-label">
<label for="wall">Radial wall thickness</label>
<output id="wallOut">15 mm</output>
</div>
<input id="wall" type="range" min="0.8" max="2.4" step="0.1" value="1.5" />
<div class="range-ends"><span>8 mm</span><span>24 mm</span></div>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Inspection</h2>
<span>voxel scene</span>
</div>
<div class="button-row">
<button id="pinButton" class="button primary">Pin as reference</button>
<button id="resetButton" class="button">Reset profile</button>
</div>
<div class="button-row" style="margin-top: 8px">
<button id="sectionButton" class="button" aria-pressed="false">
Section view
</button>
<button id="resetCamera" class="button">Reset camera</button>
</div>
<label class="check-row">
<span>Show estimated capacity fill</span>
<input id="fillToggle" type="checkbox" checked />
</label>
</section>
<p class="estimate-note">
<strong>Geometric estimate only.</strong>
Capacity is calculated from a numerically revolved inner profile.
Support footprint is the base contact area, πr². Handles, throwing
rings, deformation, glaze, clay shrinkage, and structural failure
are not simulated.
</p>
</aside>
<main class="stage" id="stage">
<canvas id="scene" aria-label="Interactive 3D voxel pottery comparison"></canvas>
<div class="stage-header">
<div class="estimate-badge">Geometric estimates · not a ceramic simulation</div>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="homeCamera" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<div id="liveLabel" class="vessel-label live">Editing · Amphora</div>
<div id="referenceLabel" class="vessel-label reference">Reference · Jar</div>
<div class="camera-hint">
Drag to orbit · scroll to zoom · double-click to reset the camera
</div>
<section class="metrics" aria-label="Capacity and footprint comparison">
<div class="metrics-header">
<h2>Comparison</h2>
<div class="legend">
<span><i class="dot live"></i>Editing</span>
<span><i class="dot reference"></i>Reference</span>
</div>
</div>
<div class="metric-block">
<div class="metric-heading">
<h3>Approximate capacity</h3>
<span id="capRatio" class="ratio">1.00× ref.</span>
</div>
<div class="metric-row">
<span>Editing</span>
<div class="track"><i id="capBarCurrent"></i></div>
<strong id="capCurrent">—</strong>
</div>
<div class="metric-row">
<span>Reference</span>
<div class="track"><i id="capBarReference"></i></div>
<strong id="capReference">—</strong>
</div>
</div>
<div class="metric-block">
<div class="metric-heading">
<h3>Support footprint</h3>
<span id="footRatio" class="ratio">1.00× ref.</span>
</div>
<div class="metric-row">
<span>Editing</span>
<div class="track"><i id="footBarCurrent"></i></div>
<strong id="footCurrent">—</strong>
</div>
<div class="metric-row">
<span>Reference</span>
<div class="track"><i id="footBarReference"></i></div>
<strong id="footReference">—</strong>
</div>
</div>
<div class="metric-facts">
<div class="fact">
<span>Estimated wall material</span>
<strong id="wallEstimate">—</strong>
</div>
<div class="fact">
<span>Opening area</span>
<strong id="openingArea">—</strong>
</div>
</div>
<p class="method-note">
The blue voxels indicate the estimated interior volume. The dotted
ring marks the base contact boundary.
</p>
</section>
<div id="toast" class="toast" aria-live="polite"></div>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const stage = $("#stage");
const canvas = $("#scene");
const presets = {
bowl: {
name: "Bowl",
height: 26,
belly: 34,
base: 13,
mouth: 30,
bellyPos: 82,
wall: 1.1
},
jar: {
name: "Jar",
height: 46,
belly: 31,
base: 16,
mouth: 18,
bellyPos: 45,
wall: 1.4
},
amphora: {
name: "Amphora",
height: 55,
belly: 34,
base: 12,
mouth: 10,
bellyPos: 56,
wall: 1.5
},
vase: {
name: "Vase",
height: 39,
belly: 27,
base: 14,
mouth: 20,
bellyPos: 48,
wall: 1.2
}
};
let current = { ...presets.amphora };
let reference = { ...presets.jar };
let currentPreset = "amphora";
let sectionView = false;
let showFill = true;
let rebuildQueued = false;
const liveX = -25;
const referenceX = 25;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee6d7);
const camera = new THREE.OrthographicCamera(-80, 80, 45, -45, 0.1, 500);
const cameraTarget = new THREE.Vector3(0, 22, 0);
let cameraAzimuth = 0.18;
let cameraElevation = 0.56;
function updateCamera() {
const distance = 160;
const horizontal = distance * Math.cos(cameraElevation);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraAzimuth),
cameraTarget.y + distance * Math.sin(cameraElevation),
cameraTarget.z + horizontal * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraAzimuth = 0.18;
cameraElevation = 0.56;
camera.zoom = 0.96;
camera.updateProjectionMatrix();
updateCamera();
}
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
const aspect = width / height;
const viewHeight = Math.max(86, 100 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
resetCamera();
const hemi = new THREE.HemisphereLight(0xfff7e8, 0x85786a, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.2);
sun.position.set(-48, 105, 62);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -90;
sun.shadow.camera.right = 90;
sun.shadow.camera.top = 90;
sun.shadow.camera.bottom = -90;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 250;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb9d7df, 0.75);
fillLight.position.set(65, 48, -70);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function makeGround() {
const tileSize = 5;
const columns = 34;
const rows = 28;
const count = columns * rows;
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0
});
const tiles = new THREE.InstancedMesh(unitBox, material, count);
tiles.receiveShadow = true;
tiles.frustumCulled = false;
const colors = [
new THREE.Color(0xe6ddcc),
new THREE.Color(0xdfd5c2),
new THREE.Color(0xe9e0d0)
];
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
dummy.position.set(
(column - (columns - 1) / 2) * tileSize,
-1.52,
(row - (rows - 1) / 2) * tileSize
);
dummy.scale.set(tileSize * 0.985, 0.5, tileSize * 0.985);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
tiles.setColorAt(
index,
colors[(column + row * 2) % colors.length]
);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
const pedestalGeometry = new THREE.BoxGeometry(46, 1.5, 46);
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0xf0e8da,
roughness: 0.94
});
for (const x of [liveX, referenceX]) {
const pedestal = new THREE.Mesh(pedestalGeometry, pedestalMaterial);
pedestal.position.set(x, -0.55, 0);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(pedestalGeometry),
new THREE.LineBasicMaterial({
color: 0xb6a891,
transparent: true,
opacity: 0.45
})
);
edge.position.copy(pedestal.position);
scene.add(edge);
}
}
makeGround();
function smoothstep(value) {
const t = clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function outerRadius(profile, y) {
const t = clamp(y / profile.height, 0, 1);
const bellyPosition = profile.bellyPos / 100;
const base = profile.base / 2;
const belly = profile.belly / 2;
const mouth = profile.mouth / 2;
if (t <= bellyPosition) {
const u = bellyPosition === 0 ? 1 : t / bellyPosition;
return lerp(base, belly, smoothstep(u));
}
const u = (t - bellyPosition) / Math.max(0.001, 1 - bellyPosition);
return lerp(belly, mouth, smoothstep(u));
}
function estimateProfile(profile) {
const steps = 600;
const start = profile.wall;
const step = (profile.height - start) / steps;
let capacity = 0;
let outerVolume = 0;
const outerStep = profile.height / steps;
for (let i = 0; i < steps; i++) {
const y = start + (i + 0.5) * step;
const innerRadius = Math.max(0, outerRadius(profile, y) - profile.wall);
capacity += Math.PI * innerRadius * innerRadius * step;
}
for (let i = 0; i < steps; i++) {
const y = (i + 0.5) * outerStep;
const radius = outerRadius(profile, y);
outerVolume += Math.PI * radius * radius * outerStep;
}
const baseRadius = profile.base / 2;
const mouthRadius = profile.mouth / 2;
return {
capacity,
outerVolume,
wallVolume: Math.max(0, outerVolume - capacity),
footprint: Math.PI * baseRadius * baseRadius,
opening: Math.PI * mouthRadius * mouthRadius
};
}
function formatVolume(volumeCm3) {
if (volumeCm3 >= 1000) {
return `${(volumeCm3 / 1000).toFixed(2)} L`;
}
return `${Math.round(volumeCm3)} mL`;
}
function formatArea(area) {
return `${Math.round(area)} cm²`;
}
function hashNoise(x, y, z) {
const value =
Math.imul(x + 31, 73856093) ^
Math.imul(y + 17, 19349663) ^
Math.imul(z + 11, 83492791);
return (value >>> 0) / 4294967295;
}
const palettes = {
live: {
outer: new THREE.Color(0xc96f4f),
inner: new THREE.Color(0x914b39),
rim: new THREE.Color(0x63372e),
ring: new THREE.Color(0xc96f4f)
},
reference: {
outer: new THREE.Color(0x4f8d88),
inner: new THREE.Color(0x326964),
rim: new THREE.Color(0x254f4c),
ring: new THREE.Color(0x4f8d88)
}
};
let liveObjects = [];
let referenceObjects = [];
function disposeObject(object) {
if (!object) return;
scene.remove(object);
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
if (typeof object.dispose === "function") {
object.dispose();
}
}
function clearObjects(objects) {
objects.forEach(disposeObject);
}
function createInstancedMesh(positions, tones, palette, size, xOffset) {
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0,
flatShading: true
});
const mesh = new THREE.InstancedMesh(unitBox, material, positions.length);
mesh.position.set(xOffset, 0.23, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
const hsl = {};
for (const key of ["outer", "inner", "rim"]) {
hsl[key] = {};
palette[key].getHSL(hsl[key]);
}
for (let i = 0; i < positions.length; i++) {
const [x, y, z] = positions[i];
const [type, jitter] = tones[i];
dummy.position.set(x, y, z);
dummy.scale.setScalar(size * 0.91);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
const base = hsl[type];
const color = new THREE.Color().setHSL(
base.h + (jitter - 0.5) * 0.012,
clamp(base.s + (jitter - 0.5) * 0.035, 0, 1),
clamp(base.l + (jitter - 0.5) * 0.065, 0, 1)
);
mesh.setColorAt(i, color);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
return mesh;
}
function createFillMesh(positions, xOffset) {
const material = new THREE.MeshBasicMaterial({
color: 0x4e94b8,
transparent: true,
opacity: 0.17,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(unitBox, material, positions.length);
mesh.position.set(xOffset, 0.23, 0);
mesh.frustumCulled = false;
mesh.renderOrder = 2;
for (let i = 0; i < positions.length; i++) {
const [x, y, z] = positions[i];
dummy.position.set(x, y, z);
dummy.scale.setScalar(1.02);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
return mesh;
}
function createFootprintRing(profile, xOffset, color) {
const positions = [];
const step = 0.7;
const radius = profile.base / 2;
const extent = Math.ceil(radius / step) + 1;
for (let iz = -extent; iz <= extent; iz++) {
for (let ix = -extent; ix <= extent; ix++) {
const x = (ix + 0.5) * step;
const z = (iz + 0.5) * step;
const distance = Math.hypot(x, z);
if (
distance <= radius + step * 0.5 &&
distance >= radius - step * 0.6
) {
positions.push([x, 0, z]);
}
}
}
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(unitBox, material, positions.length);
mesh.position.set(xOffset, 0.235, 0);
mesh.frustumCulled = false;
mesh.renderOrder = 3;
for (let i = 0; i < positions.length; i++) {
const [x, y, z] = positions[i];
dummy.position.set(x, y, z);
dummy.scale.set(step * 0.72, 0.035, step * 0.72);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
return mesh;
}
function buildVessel(profile, xOffset, palette, includeFill) {
const voxelSize = 1.05;
const maximumRadius = Math.max(
profile.base / 2,
profile.belly / 2,
profile.mouth / 2
);
const horizontalExtent = Math.ceil(maximumRadius / voxelSize) + 1;
const verticalExtent = Math.ceil(profile.height / voxelSize);
const shellPositions = [];
const shellTones = [];
const fillPositions = [];
let directionX = 0;
let directionZ = 1;
if (sectionView) {
directionX = camera.position.x - cameraTarget.x;
directionZ = camera.position.z - cameraTarget.z;
const length = Math.hypot(directionX, directionZ) || 1;
directionX /= length;
directionZ /= length;
}
function isSectionOpening(x, z, radius) {
if (!sectionView) return false;
const towardCamera = x * directionX + z * directionZ;
const acrossCamera = -x * directionZ + z * directionX;
return (
towardCamera > radius * 0.08 &&
Math.abs(acrossCamera) < radius * 0.68
);
}
for (let iy = 0; iy < verticalExtent; iy++) {
const y = (iy + 0.5) * voxelSize;
const radius = outerRadius(profile, y);
const innerRadius = Math.max(0, radius - profile.wall);
const isFloor = y < profile.wall;
const isRim = y > profile.height - voxelSize * 1.25;
for (let iz = -horizontalExtent; iz <= horizontalExtent; iz++) {
for (let ix = -horizontalExtent; ix <= horizontalExtent; ix++) {
const x = (ix + 0.5) * voxelSize;
const z = (iz + 0.5) * voxelSize;
const distance = Math.hypot(x, z);
if (distance > radius) continue;
const sectionOpening = isSectionOpening(x, z, radius);
const noise = hashNoise(ix, iy, iz);
if (isFloor) {
if (!sectionOpening) {
shellPositions.push([x, y, z]);
shellTones.push([isRim ? "rim" : "inner", noise]);
}
continue;
}
if (distance >= innerRadius) {
if (!sectionOpening) {
let type = "outer";
if (isRim) {
type = "rim";
} else if (distance < radius - voxelSize * 0.72) {
type = "inner";
}
shellPositions.push([x, y, z]);
shellTones.push([type, noise]);
}
} else if (includeFill && !sectionOpening) {
fillPositions.push([x, y, z]);
}
}
}
}
const objects = [];
if (shellPositions.length) {
const shell = createInstancedMesh(
shellPositions,
shellTones,
palette,
voxelSize,
xOffset
);
scene.add(shell);
objects.push(shell);
}
if (includeFill && showFill && fillPositions.length) {
const fill = createFillMesh(fillPositions, xOffset);
scene.add(fill);
objects.push(fill);
}
const footprint = createFootprintRing(profile, xOffset, palette.ring);
scene.add(footprint);
objects.push(footprint);
return objects;
}
function rebuildVessels() {
clearObjects(liveObjects);
clearObjects(referenceObjects);
liveObjects = buildVessel(current, liveX, palettes.live, true);
referenceObjects = buildVessel(reference, referenceX, palettes.reference, false);
}
function queueRebuild() {
if (rebuildQueued) return;
rebuildQueued = true;
requestAnimationFrame(() => {
rebuildQueued = false;
rebuildVessels();
});
}
function updateRangeFill(input) {
const minimum = Number(input.min);
const maximum = Number(input.max);
const value = Number(input.value);
const percentage = ((value - minimum) / (maximum - minimum)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function syncControls() {
const values = {
height: `${current.height} cm`,
belly: `${current.belly} cm`,
base: `${current.base} cm`,
mouth: `${current.mouth} cm`,
bellyPos: `${current.bellyPos}%`,
wall: `${Math.round(current.wall * 10)} mm`
};
for (const [key, value] of Object.entries(values)) {
$(`#${key}`).value = current[key];
$(`#${key}Out`).textContent = value;
updateRangeFill($(`#${key}`));
}
$("#profileName").textContent = current.name;
$("#liveLabel").textContent = `Editing · ${current.name}`;
}
function markPreset(name) {
currentPreset = name;
document.querySelectorAll(".preset").forEach((button) => {
button.classList.toggle("active", button.dataset.preset === name);
});
}
function updateComparison() {
const currentEstimate = estimateProfile(current);
const referenceEstimate = estimateProfile(reference);
$("#capCurrent").textContent = formatVolume(currentEstimate.capacity);
$("#capReference").textContent = formatVolume(referenceEstimate.capacity);
$("#footCurrent").textContent = formatArea(currentEstimate.footprint);
$("#footReference").textContent = formatArea(referenceEstimate.footprint);
const capacityRatio =
referenceEstimate.capacity > 0
? currentEstimate.capacity / referenceEstimate.capacity
: 0;
const footprintRatio =
referenceEstimate.footprint > 0
? currentEstimate.footprint / referenceEstimate.footprint
: 0;
$("#capRatio").textContent = `${capacityRatio.toFixed(2)}× ref.`;
$("#footRatio").textContent = `${footprintRatio.toFixed(2)}× ref.`;
const capacityMaximum =
Math.max(currentEstimate.capacity, referenceEstimate.capacity) * 1.08 || 1;
const footprintMaximum =
Math.max(currentEstimate.footprint, referenceEstimate.footprint) * 1.08 || 1;
$("#capBarCurrent").style.width =
`${(currentEstimate.capacity / capacityMaximum) * 100}%`;
$("#capBarReference").style.width =
`${(referenceEstimate.capacity / capacityMaximum) * 100}%`;
$("#footBarCurrent").style.width =
`${(currentEstimate.footprint / footprintMaximum) * 100}%`;
$("#footBarReference").style.width =
`${(referenceEstimate.footprint / footprintMaximum) * 100}%`;
$("#wallEstimate").textContent = formatVolume(currentEstimate.wallVolume);
$("#openingArea").textContent = formatArea(currentEstimate.opening);
$("#referenceLabel").textContent = `Reference · ${reference.name}`;
}
const sliderKeys = [
"height",
"belly",
"base",
"mouth",
"bellyPos",
"wall"
];
sliderKeys.forEach((key) => {
$(`#${key}`).addEventListener("input", (event) => {
current[key] = Number(event.target.value);
// Keep the profile geometrically bounded and internally consistent.
if (current.mouth > current.belly) {
current.belly = current.mouth;
}
if (current.base > current.belly) {
current.base = current.belly;
}
current.name = "Custom";
markPreset(null);
syncControls();
updateComparison();
queueRebuild();
});
});
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
const key = button.dataset.preset;
current = { ...presets[key] };
markPreset(key);
syncControls();
updateComparison();
queueRebuild();
showToast(`${presets[key].name} profile loaded`);
});
});
let toastTimer;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 1800);
}
$("#pinButton").addEventListener("click", () => {
reference = { ...current, name: "Pinned" };
updateComparison();
queueRebuild();
showToast("Current profile pinned as the reference");
});
$("#resetButton").addEventListener("click", () => {
current = { ...presets.amphora };
markPreset("amphora");
syncControls();
updateComparison();
queueRebuild();
showToast("Profile reset to amphora");
});
$("#sectionButton").addEventListener("click", () => {
sectionView = !sectionView;
$("#sectionButton").classList.toggle("active", sectionView);
$("#sectionButton").setAttribute("aria-pressed", String(sectionView));
$("#sectionButton").textContent = sectionView ? "Section on" : "Section view";
queueRebuild();
});
$("#fillToggle").addEventListener("change", (event) => {
showFill = event.target.checked;
queueRebuild();
});
function zoomBy(factor) {
camera.zoom = clamp(camera.zoom * factor, 0.62, 2.35);
camera.updateProjectionMatrix();
}
$("#zoomIn").addEventListener("click", () => zoomBy(1.15));
$("#zoomOut").addEventListener("click", () => zoomBy(1 / 1.15));
$("#resetCamera").addEventListener("click", resetCamera);
$("#homeCamera").addEventListener("click", resetCamera);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomBy(Math.exp(-event.deltaY * 0.001));
},
{ passive: false }
);
let dragging = false;
let dragMoved = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragMoved = false;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 1) {
dragMoved = true;
}
cameraAzimuth -= deltaX * 0.006;
cameraElevation = clamp(cameraElevation + deltaY * 0.0045, 0.23, 1.13);
updateCamera();
});
function endDrag(event) {
if (!dragging) return;
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (sectionView && dragMoved) {
queueRebuild();
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("dblclick", resetCamera);
const projected = new THREE.Vector3();
function placeLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const xPixel = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const yPixel = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${xPixel}px`;
element.style.top = `${yPixel}px`;
}
function updateLabels() {
placeLabel($("#liveLabel"), liveX, current.height + 4.5, 0);
placeLabel($("#referenceLabel"), referenceX, reference.height + 4.5, 0);
}
syncControls();
updateComparison();
rebuildVessels();
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```