Prompt specification
Build or customize the Three.js 3D scene "Capillary parameter explorer" 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: Capillary parameter explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/capillary-parameter-explorer-x1448
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: capillary parameter explorer. Allow changing tube radius and contact angle in a simplified equilibrium model; display rise or depression and explain the assumptions behind the calculated height.
Working Three.js Starter (capillary-parameter-explorer-x1448):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Capillary Lab — Voxel Parameter Explorer</title>
<style>
:root {
--paper: #f4efe5;
--paper-2: #ebe4d7;
--ink: #172625;
--muted: #6f7975;
--line: #d8d1c4;
--teal: #20b5a6;
--teal-dark: #087d76;
--teal-soft: #d8f3ed;
--coral: #f27658;
--coral-soft: #fde4dc;
--gold: #d5a534;
--white: #fffdf8;
--shadow: 0 18px 50px rgba(32, 45, 42, 0.10);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
height: 100vh;
overflow: hidden;
}
button, input { font: inherit; }
.topbar {
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 26px;
border-bottom: 1px solid var(--line);
background: rgba(255, 253, 248, 0.82);
backdrop-filter: blur(14px);
position: relative;
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
width: 15px;
height: 15px;
border-radius: 3px;
transform: rotate(30deg) skewY(-10deg);
box-shadow: inset -3px -3px 0 rgba(0,0,0,.10);
}
.brand-mark i:nth-child(1) {
left: 2px; top: 13px;
background: var(--coral);
}
.brand-mark i:nth-child(2) {
left: 13px; top: 4px;
background: var(--gold);
}
.brand-mark i:nth-child(3) {
left: 13px; top: 20px;
background: var(--teal);
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: -0.025em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: .13em;
text-transform: uppercase;
}
.top-tag {
border: 1px solid var(--line);
border-radius: 999px;
padding: 8px 12px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
white-space: nowrap;
}
.workspace {
height: calc(100vh - 72px);
display: grid;
grid-template-columns: 300px minmax(420px, 1fr) 330px;
min-height: 0;
}
.panel {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #c8c1b4 transparent;
}
.controls-panel {
padding: 24px 22px 30px;
border-right: 1px solid var(--line);
background: var(--white);
}
.insights-panel {
padding: 24px 22px 32px;
border-left: 1px solid var(--line);
background: var(--white);
}
.eyebrow {
margin: 0 0 7px;
color: var(--teal-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
h2 {
margin: 0;
font-size: 24px;
line-height: 1.12;
letter-spacing: -.035em;
}
.intro {
margin: 10px 0 24px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.control-card,
.result-card,
.info-card {
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
}
.control-card {
padding: 18px;
margin-bottom: 14px;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.control-heading label {
font-size: 13px;
font-weight: 780;
}
.value-pill {
min-width: 76px;
padding: 6px 9px;
border: 1px solid #cddfdb;
border-radius: 9px;
color: var(--teal-dark);
background: var(--teal-soft);
font-size: 12px;
font-weight: 820;
text-align: center;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 7px;
margin: 4px 0 10px;
border-radius: 999px;
outline: none;
appearance: none;
-webkit-appearance: none;
background:
linear-gradient(to right,
var(--teal) 0%,
var(--teal) var(--fill),
#d9d3c8 var(--fill),
#d9d3c8 100%);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
border: 3px solid var(--white);
border-radius: 5px;
appearance: none;
-webkit-appearance: none;
background: var(--teal-dark);
box-shadow: 0 2px 7px rgba(0,0,0,.22);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid var(--white);
border-radius: 5px;
background: var(--teal-dark);
box-shadow: 0 2px 7px rgba(0,0,0,.22);
}
.range-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.hint {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 23px 0 10px;
font-size: 11px;
font-weight: 850;
letter-spacing: .11em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.preset {
min-height: 38px;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: var(--white);
font-size: 11px;
font-weight: 700;
text-align: left;
cursor: pointer;
transition: .18s ease;
}
.preset:hover {
border-color: #9bcac3;
background: #f0faf7;
transform: translateY(-1px);
}
.preset.active {
border-color: var(--teal);
background: var(--teal-soft);
color: var(--teal-dark);
}
.constants {
display: grid;
gap: 7px;
}
.constant {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 9px 11px;
border-radius: 10px;
background: var(--paper);
font-size: 11px;
}
.constant span { color: var(--muted); }
.constant strong { font-variant-numeric: tabular-nums; }
.formula-card {
margin-top: 14px;
padding: 16px;
border-radius: 15px;
color: #eafff9;
background: var(--ink);
}
.formula-card .eyebrow { color: #62d7ca; }
.formula {
margin: 8px 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
line-height: 1.35;
}
.formula-sub {
padding-top: 10px;
border-top: 1px solid rgba(255,255,255,.14);
color: #b9cbc7;
font-size: 10px;
line-height: 1.55;
font-variant-numeric: tabular-nums;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9e2d5;
}
#viewport canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#viewport canvas:active { cursor: grabbing; }
.viewport-top {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
z-index: 2;
}
.scene-badge {
padding: 9px 11px;
border: 1px solid rgba(23,38,37,.12);
border-radius: 10px;
color: rgba(23,38,37,.72);
background: rgba(255,253,248,.76);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
}
.reset-button {
pointer-events: auto;
padding: 9px 12px;
border: 1px solid rgba(23,38,37,.15);
border-radius: 10px;
color: var(--ink);
background: rgba(255,253,248,.82);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 760;
cursor: pointer;
}
.reset-button:hover { background: var(--white); }
.legend {
position: absolute;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100% - 36px);
z-index: 2;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid rgba(23,38,37,.11);
border-radius: 9px;
background: rgba(255,253,248,.78);
backdrop-filter: blur(10px);
color: rgba(23,38,37,.72);
font-size: 10px;
font-weight: 700;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--teal);
box-shadow: inset -2px -2px rgba(0,0,0,.12);
}
.swatch.glass { background: #a8d7d2; }
.swatch.measure { background: var(--coral); }
.result-card {
position: relative;
overflow: hidden;
padding: 19px;
margin-bottom: 14px;
background: linear-gradient(145deg, #e6f7f2, #f8f3e8);
}
.result-card::after {
content: "";
position: absolute;
width: 90px;
height: 90px;
right: -25px;
top: -28px;
border-radius: 22px;
background: rgba(32,181,166,.10);
transform: rotate(16deg);
}
.result-card.is-depression {
background: linear-gradient(145deg, #fff0e9, #f8f3e8);
}
.result-card.is-depression::after {
background: rgba(242,118,88,.12);
}
.result-label {
margin: 0;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: .14em;
text-transform: uppercase;
}
.result-value {
margin: 8px 0 4px;
font-size: 37px;
font-weight: 820;
letter-spacing: -.055em;
font-variant-numeric: tabular-nums;
}
.result-direction {
display: inline-block;
padding: 5px 8px;
border-radius: 7px;
color: var(--teal-dark);
background: rgba(32,181,166,.13);
font-size: 10px;
font-weight: 850;
letter-spacing: .1em;
}
.is-depression .result-direction {
color: #b54931;
background: rgba(242,118,88,.15);
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 14px;
}
.metric {
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.metric strong {
font-size: 16px;
font-variant-numeric: tabular-nums;
}
.gauge-card {
padding: 16px;
margin-bottom: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
}
.gauge-title {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.gauge {
--marker: 50%;
position: relative;
height: 15px;
margin: 14px 3px 7px;
border-radius: 999px;
background: linear-gradient(90deg,
#f3b29e 0%,
#e9e2d7 47%,
#e9e2d7 53%,
#8bd9ce 100%);
}
.gauge::after {
content: "";
position: absolute;
top: -5px;
bottom: -5px;
left: 50%;
width: 1px;
background: #8d958f;
}
.gauge-marker {
position: absolute;
top: 50%;
left: var(--marker);
width: 13px;
height: 13px;
border: 2px solid var(--white);
border-radius: 4px;
background: var(--ink);
box-shadow: 0 2px 6px rgba(0,0,0,.25);
transform: translate(-50%, -50%) rotate(45deg);
transition: left .22s ease;
}
.gauge-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
}
.info-card {
padding: 16px;
margin-bottom: 14px;
}
.info-card h3 {
margin: 0 0 9px;
font-size: 13px;
letter-spacing: -.01em;
}
.info-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.58;
}
.angle-figure {
display: grid;
grid-template-columns: 120px 1fr;
align-items: center;
gap: 12px;
margin-bottom: 12px;
}
.angle-figure svg {
width: 120px;
height: 74px;
overflow: visible;
}
.angle-number {
font-size: 27px;
font-weight: 830;
letter-spacing: -.04em;
}
.angle-caption {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.assumptions {
margin: 0;
padding: 0;
list-style: none;
counter-reset: assumptions;
}
.assumptions li {
position: relative;
padding: 0 0 13px 30px;
color: var(--muted);
font-size: 11px;
line-height: 1.48;
counter-increment: assumptions;
}
.assumptions li:last-child { padding-bottom: 0; }
.assumptions li::before {
content: counter(assumptions);
position: absolute;
left: 0;
top: 0;
width: 20px;
height: 20px;
display: grid;
place-items: center;
border-radius: 6px;
color: var(--teal-dark);
background: var(--teal-soft);
font-size: 9px;
font-weight: 850;
}
.assumptions strong { color: var(--ink); }
.limit-note {
margin-top: 14px;
padding: 12px;
border-left: 3px solid var(--coral);
border-radius: 0 9px 9px 0;
color: #855244;
background: var(--coral-soft);
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 1180px) {
body { height: auto; overflow: auto; }
.workspace {
height: auto;
min-height: calc(100vh - 72px);
grid-template-columns: 280px minmax(0, 1fr);
}
.controls-panel { grid-row: 1; }
.viewport { min-height: 680px; }
.insights-panel {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
border-top: 1px solid var(--line);
border-left: 0;
}
.insights-panel > * { margin-bottom: 0; }
}
@media (max-width: 720px) {
.topbar {
height: 66px;
padding: 0 16px;
}
.top-tag { display: none; }
.workspace {
display: flex;
flex-direction: column;
}
.controls-panel,
.insights-panel {
border: 0;
padding: 21px 17px;
}
.viewport {
order: -1;
height: 66vh;
min-height: 480px;
}
.insights-panel { display: block; }
.insights-panel > * { margin-bottom: 14px; }
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></div>
<div>
<h1>Capillary Lab</h1>
<p>Voxel parameter explorer</p>
</div>
</div>
<div class="top-tag">Static equilibrium · simplified model</div>
</header>
<main class="workspace">
<aside class="panel controls-panel">
<p class="eyebrow">Parameters</p>
<h2>Shape the interface</h2>
<p class="intro">
Change the tube size and wetting angle to balance surface tension
against the weight of the liquid column.
</p>
<section class="control-card">
<div class="control-heading">
<label for="radius">Tube radius</label>
<output id="radiusValue" class="value-pill">0.65 mm</output>
</div>
<input
id="radius"
type="range"
min="0.25"
max="1.50"
step="0.05"
value="0.65"
/>
<div class="range-labels">
<span>0.25 mm</span>
<span>1.50 mm</span>
</div>
<p class="hint">Narrower tubes produce larger capillary forces per unit mass.</p>
</section>
<section class="control-card">
<div class="control-heading">
<label for="angle">Contact angle θ</label>
<output id="angleValue" class="value-pill">45°</output>
</div>
<input
id="angle"
type="range"
min="0"
max="180"
step="1"
value="45"
/>
<div class="range-labels">
<span>0° · wetting</span>
<span>180° · non-wetting</span>
</div>
<p class="hint">
Below 90° the meniscus supports a rise; above 90° it produces depression.
</p>
</section>
<div class="section-title">Quick presets</div>
<div class="presets">
<button class="preset" data-radius="0.45" data-angle="0">Clean glass</button>
<button class="preset active" data-radius="0.65" data-angle="45">Wetting tube</button>
<button class="preset" data-radius="0.65" data-angle="90">Neutral · 90°</button>
<button class="preset" data-radius="0.65" data-angle="120">Non-wetting</button>
<button class="preset" data-radius="0.65" data-angle="160">Superhydrophobic</button>
</div>
<div class="section-title">Fixed liquid properties</div>
<div class="constants">
<div class="constant"><span>Surface tension, γ</span><strong>72.8 mN/m</strong></div>
<div class="constant"><span>Density, ρ</span><strong>998 kg/m³</strong></div>
<div class="constant"><span>Gravity, g</span><strong>9.81 m/s²</strong></div>
</div>
<div class="formula-card">
<p class="eyebrow">Capillary equilibrium</p>
<div class="formula">h = 2γ cos θ / ρgr</div>
<div id="formulaSub" class="formula-sub"></div>
</div>
</aside>
<section id="viewport" class="viewport" aria-label="Interactive 3D capillary scene">
<div class="viewport-top">
<div class="scene-badge">Schematic · not to scale</div>
<button id="resetView" class="reset-button" type="button">Reset view</button>
</div>
<div class="legend">
<div class="legend-item"><i class="swatch"></i>Liquid voxels</div>
<div class="legend-item"><i class="swatch glass"></i>Capillary wall</div>
<div class="legend-item"><i class="swatch measure"></i>Height difference</div>
</div>
</section>
<aside class="panel insights-panel">
<section id="resultCard" class="result-card">
<p class="result-label">Calculated level difference</p>
<div id="resultValue" class="result-value">+16.2 mm</div>
<span id="resultDirection" class="result-direction">CAPILLARY RISE</span>
</section>
<div class="metric-grid">
<div class="metric">
<span>Direction</span>
<strong id="directionValue">Rise</strong>
</div>
<div class="metric">
<span>Laplace Δp</span>
<strong id="pressureValue">158.3 Pa</strong>
</div>
</div>
<section class="gauge-card">
<div class="gauge-title"><span>Relative level</span><span>±60 mm</span></div>
<div id="gauge" class="gauge"><i id="gaugeMarker" class="gauge-marker"></i></div>
<div class="gauge-labels"><span>Depression</span><span>Bulk level</span><span>Rise</span></div>
</section>
<section class="info-card">
<h3>Why this height?</h3>
<p id="explanation"></p>
</section>
<section class="info-card">
<h3>Contact-angle sketch</h3>
<div class="angle-figure">
<svg viewBox="0 0 120 74" aria-label="Contact angle diagram">
<defs>
<linearGradient id="liquidGradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0" stop-color="#76e5d4"/>
<stop offset="1" stop-color="#169e95"/>
</linearGradient>
</defs>
<path d="M22 8 V66 M98 8 V66"
fill="none" stroke="#82918d" stroke-width="4"/>
<path id="liquidPath" d="M22 40 Q60 54 98 40 L98 67 L22 67 Z"
fill="url(#liquidGradient)" opacity=".88"/>
<path id="meniscusPath" d="M22 40 Q60 54 98 40"
fill="none" stroke="#087d76" stroke-width="3"/>
<text id="angleText" x="108" y="22" fill="#172625"
font-size="13" font-weight="800">45°</text>
</svg>
<div>
<div id="angleNumber" class="angle-number">45°</div>
<div id="angleCaption" class="angle-caption">
Concave, wetting meniscus
</div>
</div>
</div>
<p>
The model measures θ through the liquid. The voxel rendering is a
stylized cross-section, while the displayed value uses the
cylindrical-capillary equation.
</p>
</section>
<section class="info-card">
<h3>Model assumptions</h3>
<ol class="assumptions">
<li><strong>Cylindrical tube:</strong> radius r is uniform and the wall is smooth.</li>
<li><strong>Static equilibrium:</strong> capillary pressure exactly balances ρgh.</li>
<li><strong>Ideal interface:</strong> surface tension and contact angle are constant.</li>
<li><strong>Neglected effects:</strong> meniscus volume, tube expansion, and finite-bath correction are ignored.</li>
<li><strong>Large reservoir:</strong> the external bath level remains effectively fixed.</li>
</ol>
<div class="limit-note">
Real tubes can pin the contact line, have rough or chemically varying
walls, or contain non-Newtonian liquids. Very small tubes may also
require corrections beyond this idealized balance.
</div>
</section>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const gamma = 0.0728; // N/m
const rho = 998; // kg/m^3
const gravity = 9.81; // m/s^2
const state = {
radiusMM: 0.65,
angle: 45,
heightMeters: 0,
heightMM: 0,
deltaPressure: 0,
visualHeight: 0
};
const radiusInput = document.getElementById("radius");
const angleInput = document.getElementById("angle");
const radiusValue = document.getElementById("radiusValue");
const angleValue = document.getElementById("angleValue");
const resultCard = document.getElementById("resultCard");
const resultValue = document.getElementById("resultValue");
const resultDirection = document.getElementById("resultDirection");
const directionValue = document.getElementById("directionValue");
const pressureValue = document.getElementById("pressureValue");
const explanation = document.getElementById("explanation");
const formulaSub = document.getElementById("formulaSub");
const gauge = document.getElementById("gauge");
const angleNumber = document.getElementById("angleNumber");
const angleCaption = document.getElementById("angleCaption");
const angleText = document.getElementById("angleText");
const meniscusPath = document.getElementById("meniscusPath");
const liquidPath = document.getElementById("liquidPath");
const presetButtons = [...document.querySelectorAll(".preset")];
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e2d5);
scene.fog = new THREE.Fog(0xe9e2d5, 19, 36);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
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",
"Voxel capillary tube. Drag to orbit and scroll to zoom."
);
viewport.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8e9, 0x6f817b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.0);
sun.position.set(5.5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.001;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x7be5d7, 1.25);
rim.position.set(-6, 3, -5);
scene.add(rim);
const warm = new THREE.PointLight(0xff936f, 20, 16, 2);
warm.position.set(4, 1, 4);
scene.add(warm);
const environment = new THREE.Group();
const model = new THREE.Group();
scene.add(environment, model);
const dummy = new THREE.Object3D();
function buildVoxelStage() {
const cols = 9;
const rows = 8;
const geometry = new THREE.BoxGeometry(0.96, 0.24, 0.96);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0,
vertexColors: true
});
const tiles = new THREE.InstancedMesh(
geometry,
material,
cols * rows
);
const color = new THREE.Color();
let index = 0;
for (let x = 0; x < cols; x++) {
for (let z = 0; z < rows; z++) {
dummy.position.set(x - 4, -5.48, z - 3.5);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
const variation = ((x * 19 + z * 7) % 5) * 0.012;
color.setHSL(0.105, 0.22, 0.78 + variation);
tiles.setColorAt(index, color);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
environment.add(tiles);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xe9e2d5,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -5.61;
floor.receiveShadow = true;
environment.add(floor);
}
buildVoxelStage();
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabelSprite(text, background = "#172625", foreground = "#fffdf8") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 6, 8, 500, 112, 25);
ctx.fillStyle = background;
ctx.fill();
ctx.fillStyle = foreground;
ctx.font = "800 47px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 20;
return sprite;
}
function disposeGroup(group) {
group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
if (material.map) material.map.dispose();
material.dispose();
}
}
});
}
function clearModel() {
disposeGroup(model);
model.clear();
}
function visualRadius() {
const t = (state.radiusMM - 0.25) / 1.25;
return 0.62 + t * 1.0;
}
function addWall(radius) {
const bottom = -5.18;
const top = 6.05;
const step = 0.145;
const levels = Math.floor((top - bottom) / step) + 1;
const segments = 64;
const geometry = new THREE.BoxGeometry(0.145, 0.145, 0.145);
const material = new THREE.MeshPhysicalMaterial({
color: 0xb8e3df,
transparent: true,
opacity: 0.28,
roughness: 0.18,
metalness: 0,
depthWrite: false
});
const wall = new THREE.InstancedMesh(
geometry,
material,
levels * segments
);
let index = 0;
for (let level = 0; level < levels; level++) {
const y = bottom + level * step;
for (let segment = 0; segment < segments; segment++) {
const angle = segment / segments * Math.PI * 2;
dummy.position.set(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
wall.setMatrixAt(index++, dummy.matrix);
}
}
wall.instanceMatrix.needsUpdate = true;
wall.renderOrder = 4;
model.add(wall);
}
function addBath(radius) {
const step = 0.19;
const extent = 3.15;
const positions = [];
for (let x = -extent; x <= extent; x += step) {
for (let z = -extent; z <= extent; z += step) {
if (Math.hypot(x, z) > radius + 0.17) {
positions.push([x, z]);
}
}
}
const geometry = new THREE.BoxGeometry(0.18, 0.065, 0.18);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.46,
metalness: 0,
vertexColors: true
});
const bath = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
const color = new THREE.Color();
positions.forEach(([x, z], index) => {
dummy.position.set(x, 0, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
bath.setMatrixAt(index, dummy.matrix);
const variation = ((index * 17) % 7) * 0.009;
color.setHSL(0.47, 0.57, 0.48 + variation);
bath.setColorAt(index, color);
});
bath.instanceMatrix.needsUpdate = true;
bath.instanceColor.needsUpdate = true;
bath.receiveShadow = true;
model.add(bath);
const bulkLabel = makeLabelSprite("BULK LEVEL", "#fffdf8", "#40534f");
bulkLabel.position.set(-2.7, 0.27, 2.55);
bulkLabel.scale.set(1.35, 0.34, 1);
model.add(bulkLabel);
}
function addLiquid(radius) {
const innerRadius = Math.max(0.3, radius - 0.14);
const bottom = -5.16;
const step = 0.155;
const cubeSize = 0.143;
const columns = [];
let total = 0;
const cosTheta = Math.cos(THREE.MathUtils.degToRad(state.angle));
for (let x = -innerRadius; x <= innerRadius + 0.0001; x += step) {
for (let z = -innerRadius; z <= innerRadius + 0.0001; z += step) {
const radial = Math.hypot(x, z);
if (radial > innerRadius) continue;
const normalizedRadius = radial / innerRadius;
// Convex for a non-wetting liquid and concave for a wetting liquid.
const meniscusProfile =
cosTheta * (1 - normalizedRadius) * 0.20;
const top = state.visualHeight + meniscusProfile;
const count = Math.max(
0,
Math.ceil((top - bottom) / step)
);
if (count > 0) {
columns.push({ x, z, top, count });
total += count;
}
}
}
if (!total) return;
const geometry = new THREE.BoxGeometry(
cubeSize,
cubeSize,
cubeSize
);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.36,
metalness: 0.03,
vertexColors: true
});
const liquid = new THREE.InstancedMesh(
geometry,
material,
total
);
const color = new THREE.Color();
let instance = 0;
for (const column of columns) {
for (let level = 0; level < column.count; level++) {
dummy.position.set(
column.x,
bottom + (level + 0.5) * step,
column.z
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
liquid.setMatrixAt(instance, dummy.matrix);
const isSurface =
level === column.count - 1;
if (isSurface) {
color.setHSL(
0.45 + 0.02 * Math.sin(column.x * 4 + column.z * 3),
0.68,
0.70
);
} else {
const variation =
((Math.floor(column.x * 13) +
Math.floor(column.z * 11) +
level * 3) % 6) * 0.009;
color.setHSL(0.475, 0.62, 0.48 + variation);
}
liquid.setColorAt(instance, color);
instance++;
}
}
liquid.instanceMatrix.needsUpdate = true;
liquid.instanceColor.needsUpdate = true;
model.add(liquid);
}
function addMeasurement(radius) {
if (Math.abs(state.heightMM) < 0.05) return;
const x = radius + 0.58;
const z = 0.22;
const top = state.visualHeight;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0, z),
new THREE.Vector3(x, top, z),
new THREE.Vector3(x - 0.13, 0, z),
new THREE.Vector3(x + 0.13, 0, z),
new THREE.Vector3(x - 0.13, top, z),
new THREE.Vector3(x + 0.13, top, z)
]);
const material = new THREE.LineBasicMaterial({
color: 0xf27658,
depthTest: false
});
const line = new THREE.LineSegments(geometry, material);
line.renderOrder = 30;
model.add(line);
const sign = state.heightMM > 0 ? "+" : "−";
const label = makeLabelSprite(
`h = ${sign}${Math.abs(state.heightMM).toFixed(1)} mm`,
"#f27658",
"#fffdf8"
);
label.position.set(x + 0.72, top * 0.5, z);
label.scale.set(1.9, 0.475, 1);
model.add(label);
const angleLabel = makeLabelSprite(
`θ = ${state.angle}°`,
"#d5a534",
"#172625"
);
angleLabel.position.set(
-(radius + 0.48),
top + 0.24,
0
);
angleLabel.scale.set(1.15, 0.29, 1);
model.add(angleLabel);
}
let pendingModelUpdate = true;
function rebuildModel() {
clearModel();
const radius = visualRadius();
addBath(radius);
addWall(radius);
addLiquid(radius);
addMeasurement(radius);
pendingModelUpdate = false;
}
// ------------------------------------------------------------
// Direct camera controls — no external controls addon
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.15, 0);
let yaw = 0.68;
let pitch = 0.17;
let distance = 14.8;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * distance,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
yaw = 0.68;
pitch = 0.17;
distance = 14.8;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
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;
previousX = event.clientX;
previousY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(
pitch + dy * 0.005,
-0.25,
1.15
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
distance = THREE.MathUtils.clamp(
distance * Math.exp(event.deltaY * 0.001),
8.5,
24
);
updateCamera();
}, { passive: false });
document.getElementById("resetView").addEventListener("click", resetCamera);
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
resize();
updateCamera();
// ------------------------------------------------------------
// Physical model and UI
// ------------------------------------------------------------
function formatSigned(value) {
if (Math.abs(value) < 0.05) return "0.0";
return `${value > 0 ? "+" : "−"}${Math.abs(value).toFixed(1)}`;
}
function setRangeFill(input) {
const fraction =
(Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min));
input.style.setProperty("--fill", `${fraction * 100}%`);
}
function updatePresetState() {
for (const button of presetButtons) {
const matches =
Math.abs(Number(button.dataset.radius) - state.radiusMM) < 0.001 &&
Math.abs(Number(button.dataset.angle) - state.angle) < 0.001;
button.classList.toggle("active", matches);
}
}
function updateAngleSketch() {
const radians = THREE.MathUtils.degToRad(state.angle);
const cosine = Math.cos(radians);
const controlY = 40 + cosine * 14;
const path = `M22 40 Q60 ${controlY.toFixed(1)} 98 40`;
meniscusPath.setAttribute("d", path);
liquidPath.setAttribute("d", `${path} L98 67 L22 67 Z`);
angleNumber.textContent = `${state.angle}°`;
angleText.textContent = `${state.angle}°`;
if (state.angle === 90) {
angleCaption.textContent = "Flat, neutral interface";
} else if (state.angle < 90) {
angleCaption.textContent = "Concave, wetting meniscus";
} else {
angleCaption.textContent = "Convex, non-wetting meniscus";
}
}
function calculateModel() {
state.radiusMM = Number(radiusInput.value);
state.angle = Number(angleInput.value);
const radiusMeters = state.radiusMM / 1000;
const radians = THREE.MathUtils.degToRad(state.angle);
const cosine = Math.cos(radians);
state.deltaPressure =
2 * gamma * cosine / radiusMeters;
state.heightMeters =
state.deltaPressure / (rho * gravity);
state.heightMM = state.heightMeters * 1000;
if (Math.abs(state.heightMM) < 0.0005) {
state.heightMM = 0;
state.heightMeters = 0;
state.deltaPressure = 0;
}
// Schematic vertical mapping; the displayed readout remains physical.
state.visualHeight =
Math.sign(state.heightMM) *
Math.min(Math.abs(state.heightMM) * 0.09, 4.9);
radiusValue.textContent = `${state.radiusMM.toFixed(2)} mm`;
angleValue.textContent = `${state.angle}°`;
setRangeFill(radiusInput);
setRangeFill(angleInput);
updatePresetState();
updateAngleSketch();
const signedHeight = formatSigned(state.heightMM);
resultValue.textContent = `${signedHeight} mm`;
const isRise = state.heightMM > 0.05;
const isDepression = state.heightMM < -0.05;
resultCard.classList.toggle("is-depression", isDepression);
if (isRise) {
resultDirection.textContent = "CAPILLARY RISE";
directionValue.textContent = "Rise";
explanation.textContent =
"cos θ is positive, so the curved meniscus creates an inward " +
"Laplace pressure jump. Surface tension supports the column until " +
"the hydrostatic pressure ρgh balances 2γ cos θ / r.";
} else if (isDepression) {
resultDirection.textContent = "CAPILLARY DEPRESSION";
directionValue.textContent = "Depression";
explanation.textContent =
"cos θ is negative, reversing the Laplace pressure jump. The " +
"non-wetting meniscus sits below the external bath until the signed " +
"hydrostatic balance ρgh equals 2γ cos θ / r.";
} else {
resultDirection.textContent = "NO CAPILLARY OFFSET";
directionValue.textContent = "Level";
explanation.textContent =
"At θ = 90°, cos θ is zero. The ideal model predicts no pressure " +
"jump and therefore no difference between the meniscus and bulk " +
"liquid levels.";
}
pressureValue.textContent = `${state.deltaPressure.toFixed(1)} Pa`;
const marker = THREE.MathUtils.clamp(
50 - state.heightMM / 60 * 46,
3,
97
);
gauge.style.setProperty("--marker", `${marker}%`);
formulaSub.innerHTML =
`2 × 0.0728 × cos(${state.angle}°) ÷<br>` +
`(998 × 9.81 × ${(state.radiusMM / 1000).toFixed(5)})<br>` +
`= ${state.heightMeters.toFixed(6)} m`;
pendingModelUpdate = true;
}
radiusInput.addEventListener("input", calculateModel);
angleInput.addEventListener("input", calculateModel);
for (const button of presetButtons) {
button.addEventListener("click", () => {
radiusInput.value = button.dataset.radius;
angleInput.value = button.dataset.angle;
calculateModel();
});
}
calculateModel();
function animate() {
requestAnimationFrame(animate);
if (pendingModelUpdate) {
rebuildModel();
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```