Prompt specification
Build or customize the Three.js 3D scene "Dilution without solute removal" 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: Dilution without solute removal
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/dilution-without-solute-removal-x1994
Scene Description Prompt:
Dilution without solute removal. Add solvent to a closed solute inventory and expand the solution volume; show constant solute amount but decreasing concentration under an additive-volume toy assumption. Please build this with Three.js from cdnjs in one self-contained HTML file, using a 3D cutaway.
Working Three.js Starter (dilution-without-solute-removal-x1994):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dilution Without Solute Removal</title>
<style>
:root {
--bg: #07111d;
--panel: #0c1928;
--panel-2: #101f31;
--line: rgba(156, 199, 230, 0.16);
--text: #eaf5ff;
--muted: #91a8bc;
--cyan: #56c8ff;
--gold: #ffc55a;
--green: #67e3b1;
--orange: #ff9e64;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
height: 100vh;
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
gap: 14px;
padding: 14px;
background:
radial-gradient(circle at 35% 35%, rgba(29, 91, 133, 0.16), transparent 38%),
linear-gradient(145deg, #07111d, #050b13);
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 20px;
background:
radial-gradient(circle at 45% 35%, rgba(43, 112, 159, 0.14), transparent 42%),
linear-gradient(180deg, #0a1826, #07111c);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.webgl {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
.webgl:active {
cursor: grabbing;
}
.scene-head {
position: absolute;
z-index: 5;
top: 20px;
left: 22px;
pointer-events: none;
max-width: min(510px, calc(100% - 44px));
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 40px);
line-height: 1.03;
letter-spacing: -0.035em;
font-weight: 750;
}
.scene-subtitle {
margin: 10px 0 0;
max-width: 520px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid rgba(103, 227, 177, 0.22);
border-radius: 999px;
background: rgba(8, 28, 33, 0.72);
color: #baf5dd;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px rgba(103, 227, 177, 0.8);
}
.callout {
position: absolute;
z-index: 4;
pointer-events: none;
white-space: nowrap;
transform: translate(-50%, -50%);
padding: 7px 10px;
border: 1px solid rgba(173, 214, 240, 0.22);
border-radius: 9px;
background: rgba(5, 15, 25, 0.82);
color: #dbeeff;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
font-size: 11px;
line-height: 1.3;
backdrop-filter: blur(12px);
}
.callout::after {
content: "";
position: absolute;
left: 50%;
bottom: -8px;
width: 1px;
height: 8px;
background: rgba(173, 214, 240, 0.35);
}
.callout b {
color: #fff;
}
.callout .dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
vertical-align: 1px;
}
.dot.gold {
background: var(--gold);
box-shadow: 0 0 9px rgba(255, 197, 90, 0.65);
}
.dot.blue {
background: var(--cyan);
box-shadow: 0 0 9px rgba(86, 200, 255, 0.65);
}
.legend {
position: absolute;
z-index: 5;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
max-width: calc(100% - 36px);
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(6, 15, 25, 0.72);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.orbit-hint {
position: absolute;
z-index: 5;
right: 16px;
bottom: 18px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(6, 15, 25, 0.7);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.panel {
min-height: 0;
overflow-y: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 20px;
background: linear-gradient(180deg, rgba(16, 31, 49, 0.96), rgba(10, 23, 37, 0.96));
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.24);
scrollbar-width: thin;
scrollbar-color: #29445d transparent;
}
.panel h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.01em;
}
.panel-intro {
margin: 7px 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.card {
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(5, 15, 26, 0.46);
}
.card + .card {
margin-top: 11px;
}
.card-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 12px;
color: #bdd1e2;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.locked {
display: inline-flex;
align-items: center;
gap: 5px;
color: var(--green);
letter-spacing: 0.03em;
text-transform: none;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-width: 0;
padding: 11px;
border: 1px solid rgba(156, 199, 230, 0.11);
border-radius: 11px;
background: rgba(17, 34, 52, 0.58);
}
.metric.wide {
grid-column: 1 / -1;
}
.metric-label {
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.metric-value {
margin-top: 5px;
color: #fff;
font-size: 22px;
font-weight: 760;
letter-spacing: -0.035em;
font-variant-numeric: tabular-nums;
}
.metric-value.gold {
color: var(--gold);
}
.metric-value.cyan {
color: var(--cyan);
}
.metric-value small {
color: var(--muted);
font-size: 10px;
font-weight: 600;
letter-spacing: 0;
}
.bar-track {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.07);
}
.bar-fill {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #31aaf2, #73e0ff);
box-shadow: 0 0 14px rgba(86, 200, 255, 0.35);
transition: width 80ms linear;
}
.bar-note {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
}
.slider-head {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: #cbdbe8;
font-size: 11px;
}
.slider-head output {
color: var(--cyan);
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 0 0 13px;
accent-color: var(--cyan);
cursor: pointer;
}
.primary {
width: 100%;
padding: 12px 14px;
border: 0;
border-radius: 11px;
background: linear-gradient(135deg, #46bdf4, #67d7ff);
color: #03131e;
font-weight: 850;
font-size: 12px;
cursor: pointer;
box-shadow: 0 10px 24px rgba(39, 162, 224, 0.18);
transition: transform 120ms ease, filter 120ms ease;
}
.primary:hover:not(:disabled) {
transform: translateY(-1px);
filter: brightness(1.06);
}
.primary:disabled {
cursor: not-allowed;
filter: grayscale(0.45);
opacity: 0.5;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 8px;
}
.secondary {
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(18, 37, 56, 0.72);
color: #bdd1e2;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
.secondary:hover {
background: rgba(28, 52, 75, 0.86);
}
.secondary.active {
border-color: rgba(86, 200, 255, 0.38);
color: var(--cyan);
background: rgba(28, 100, 135, 0.22);
}
.equation {
padding: 11px 12px;
border-left: 2px solid var(--cyan);
border-radius: 0 9px 9px 0;
background: rgba(42, 135, 178, 0.09);
color: #d9edfa;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
line-height: 1.8;
}
.equation .accent {
color: var(--cyan);
}
.equation .constant {
color: var(--gold);
}
.chart-wrap {
position: relative;
margin-top: 2px;
}
#trendChart {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.chart-note {
margin-top: 7px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.assumption {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.assumption strong {
color: #d7e9f7;
}
.pulse {
animation: inventoryPulse 500ms ease;
}
@keyframes inventoryPulse {
0% {
box-shadow: 0 0 0 rgba(255, 197, 90, 0);
}
40% {
box-shadow: 0 0 26px rgba(255, 197, 90, 0.26);
}
100% {
box-shadow: 0 0 0 rgba(255, 197, 90, 0);
}
}
@media (max-width: 950px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
grid-template-columns: 1fr;
}
#viewport {
height: 65vh;
min-height: 480px;
}
.panel {
overflow: visible;
}
}
@media (max-width: 560px) {
.app {
padding: 8px;
gap: 8px;
}
#viewport {
min-height: 520px;
border-radius: 15px;
}
.panel {
padding: 14px;
border-radius: 15px;
}
.scene-head {
top: 15px;
left: 15px;
}
.scene-subtitle {
max-width: 92%;
}
.callout {
font-size: 9px;
padding: 6px 8px;
}
.orbit-hint {
display: none;
}
.legend {
right: 12px;
left: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<main class="app">
<section id="viewport" aria-label="Interactive three-dimensional dilution cutaway">
<div class="scene-head">
<div class="eyebrow">Closed inventory · additive-volume model</div>
<h1>Dilution without<br />solute removal</h1>
<p class="scene-subtitle">
Fresh solvent enters the vessel. The solute inventory stays closed while
the solution volume grows, so the same amount is distributed through more liquid.
</p>
<div class="status">
<span class="status-dot"></span>
SOLUTE EXIT = 0 · INVENTORY CONSTANT
</div>
</div>
<div id="soluteCallout" class="callout">
<span class="dot gold"></span>
<b>12 mmol solute</b> · closed inventory
</div>
<div id="solventCallout" class="callout">
<span class="dot blue"></span>
Fresh solvent inlet
</div>
<div id="volumeCallout" class="callout">
Solution volume: <b>2.00 L</b>
</div>
<div class="legend">
<span><i class="dot gold"></i>Solute: constant marker count</span>
<span><i class="dot blue"></i>Solvent markers: illustrative only</span>
<span>Amber dashed line = cutaway boundary</span>
</div>
<div class="orbit-hint">Drag to orbit · scroll to zoom · double-click to reset view</div>
</section>
<aside class="panel">
<h2>Dilution controls</h2>
<p class="panel-intro">
Add solvent and watch the concentration fall without deleting any solute.
</p>
<section class="card">
<div class="card-title">
Live model
<span class="locked">● Inventory locked</span>
</div>
<div class="metrics">
<div class="metric wide" id="soluteMetric">
<div class="metric-label">Solute amount nₛ</div>
<div class="metric-value gold">12.00 <small>mmol</small></div>
</div>
<div class="metric">
<div class="metric-label">Solution volume V</div>
<div class="metric-value cyan" id="volumeValue">2.00 <small>L</small></div>
</div>
<div class="metric">
<div class="metric-label">Concentration c</div>
<div class="metric-value" id="concentrationValue">
6.00 <small>mmol/L</small>
</div>
</div>
<div class="metric wide">
<div class="metric-label">Relative to initial concentration</div>
<div class="bar-track">
<div id="concentrationBar" class="bar-fill"></div>
</div>
<div class="bar-note">
<span id="relativeValue">100% of initial</span>
<span id="addedValue">0.00 L added</span>
</div>
</div>
</div>
</section>
<section class="card">
<div class="card-title">Add solvent</div>
<div class="slider-head">
<label for="solventAmount">Solvent added per pour</label>
<output id="amountOutput" for="solventAmount">0.25 L</output>
</div>
<input
id="solventAmount"
type="range"
min="0.10"
max="0.50"
step="0.05"
value="0.25"
/>
<button id="pourButton" class="primary">Add 0.25 L solvent</button>
<div class="button-row">
<button id="autoButton" class="secondary">Auto pour: off</button>
<button id="resetButton" class="secondary">Reset model</button>
</div>
</section>
<section class="card">
<div class="card-title">Additive-volume calculation</div>
<div class="equation">
nₛ′ = <span class="constant">nₛ = 12 mmol</span><br />
V′ = V + ΔV<sub>solvent</sub><br />
c′ = <span class="accent">nₛ′ / V′</span>
</div>
</section>
<section class="card">
<div class="card-title">Concentration history</div>
<div class="chart-wrap">
<svg id="trendChart" viewBox="0 0 320 120" aria-label="Concentration versus solution volume">
<defs>
<linearGradient id="areaGradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0%" stop-color="#56c8ff" stop-opacity="0.28" />
<stop offset="100%" stop-color="#56c8ff" stop-opacity="0" />
</linearGradient>
</defs>
<line x1="20" y1="20" x2="300" y2="20" stroke="#24394d" stroke-width="1" />
<line x1="20" y1="60" x2="300" y2="60" stroke="#24394d" stroke-width="1" />
<line x1="20" y1="100" x2="300" y2="100" stroke="#24394d" stroke-width="1" />
<line x1="20" y1="30" x2="300" y2="30" stroke="#ffc55a" stroke-opacity="0.35" stroke-dasharray="4 5" />
<polygon id="trendArea" fill="url(#areaGradient)" points="" />
<polyline
id="trendLine"
fill="none"
stroke="#56c8ff"
stroke-width="2.5"
stroke-linejoin="round"
stroke-linecap="round"
points=""
/>
<circle id="trendDot" r="4.5" fill="#07111d" stroke="#56c8ff" stroke-width="2.5" />
<text x="20" y="116" fill="#71899d" font-size="9">2 L</text>
<text x="283" y="116" fill="#71899d" font-size="9">4 L</text>
<text x="5" y="33" fill="#71899d" font-size="9">6</text>
<text x="5" y="73" fill="#71899d" font-size="9">4.5</text>
<text x="5" y="103" fill="#71899d" font-size="9">3</text>
<text x="204" y="13" fill="#a98d55" font-size="9">initial c</text>
</svg>
</div>
<div class="chart-note">
mmol/L versus total solution volume. Each completed pour adds one point.
</div>
</section>
<section class="card">
<div class="card-title">Toy assumptions</div>
<p class="assumption">
<strong>Volumes add exactly:</strong>
V<sub>new</sub> = V<sub>old</sub> + V<sub>solvent added</sub>.
Mixing causes no contraction, and solute/solvent partial volumes are ignored.
Marker counts illustrate the mechanism; the numerical readouts use the stated
additive-volume model.
</p>
</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";
// -------------------------------------------------------------------------
// Model constants
// -------------------------------------------------------------------------
const INITIAL_VOLUME = 2.0; // L
const CAPACITY = 4.0; // L
const SOLUTE_MMOL = 12.0; // mmol
const SOLUTE_MARKERS = 72; // illustrative marker count, never changed
const MAX_SOLVENT_MARKERS = 720;
const viewport = document.getElementById("viewport");
const volumeValue = document.getElementById("volumeValue");
const concentrationValue = document.getElementById("concentrationValue");
const concentrationBar = document.getElementById("concentrationBar");
const relativeValue = document.getElementById("relativeValue");
const addedValue = document.getElementById("addedValue");
const soluteMetric = document.getElementById("soluteMetric");
const solventAmount = document.getElementById("solventAmount");
const amountOutput = document.getElementById("amountOutput");
const pourButton = document.getElementById("pourButton");
const autoButton = document.getElementById("autoButton");
const resetButton = document.getElementById("resetButton");
const volumeCallout = document.getElementById("volumeCallout");
const soluteCallout = document.getElementById("soluteCallout");
const solventCallout = document.getElementById("solventCallout");
const trendLine = document.getElementById("trendLine");
const trendArea = document.getElementById("trendArea");
const trendDot = document.getElementById("trendDot");
let currentVolume = INITIAL_VOLUME;
let targetVolume = INITIAL_VOLUME;
let history = [{ volume: INITIAL_VOLUME, concentration: SOLUTE_MMOL / INITIAL_VOLUME }];
let inventoryPulse = 0;
let autoTimer = null;
const pour = {
active: false,
from: INITIAL_VOLUME,
to: INITIAL_VOLUME,
elapsed: 0,
duration: 1.15
};
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.className = "webgl";
viewport.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111c, 0.035);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const orbit = {
radius: 8.4,
theta: 0.64,
phi: 1.08,
target: new THREE.Vector3(0, 1.65, 0)
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
applyCamera();
const hemisphere = new THREE.HemisphereLight(0xbfe7ff, 0x102235, 1.6);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x39baff, 16, 11, 2);
rimLight.position.set(-4, 3.5, -2);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb452, 8, 7, 2);
warmLight.position.set(2.7, 2.6, 1.8);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Ground and platform
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x07131e,
roughness: 0.86,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.11;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x28506b, 0x173246);
grid.position.y = -0.1;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const tank = {
width: 4.4,
depth: 2.6,
height: 3.45,
liquidHeight: 3.12,
base: 0.18
};
const platform = new THREE.Mesh(
new THREE.BoxGeometry(tank.width + 0.2, 0.18, tank.depth + 0.2),
new THREE.MeshStandardMaterial({
color: 0x142737,
roughness: 0.42,
metalness: 0.62
})
);
platform.position.y = 0.06;
platform.castShadow = true;
platform.receiveShadow = true;
scene.add(platform);
// -------------------------------------------------------------------------
// Cutaway vessel: back and left glass, half of the right glass, open front
// -------------------------------------------------------------------------
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xb8e6ff,
transparent: true,
opacity: 0.14,
roughness: 0.08,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x7894a9,
roughness: 0.28,
metalness: 0.72
});
function addGlassPanel(width, height, depth, x, y, z) {
const panel = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
glassMaterial
);
panel.position.set(x, y, z);
panel.renderOrder = 4;
scene.add(panel);
return panel;
}
addGlassPanel(
tank.width,
tank.height,
0.055,
0,
tank.height / 2,
-tank.depth / 2
);
addGlassPanel(
0.055,
tank.height,
tank.depth,
-tank.width / 2,
tank.height / 2,
0
);
addGlassPanel(
0.055,
tank.height,
tank.depth / 2,
tank.width / 2,
tank.height / 2,
-tank.depth / 4
);
function addFrameBox(width, height, depth, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
frameMaterial
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
const postSize = 0.055;
const corners = [
[-tank.width / 2, -tank.depth / 2],
[-tank.width / 2, tank.depth / 2],
[tank.width / 2, -tank.depth / 2],
[tank.width / 2, tank.depth / 2]
];
corners.forEach(([x, z]) => {
addFrameBox(postSize, tank.height, postSize, x, tank.height / 2, z);
});
addFrameBox(tank.width, postSize, postSize, 0, tank.height, -tank.depth / 2);
addFrameBox(tank.width, postSize, postSize, 0, tank.height, tank.depth / 2);
addFrameBox(postSize, postSize, tank.depth, -tank.width / 2, tank.height, 0);
addFrameBox(postSize, postSize, tank.depth, tank.width / 2, tank.height, 0);
// Dashed amber boundary emphasizes the sectioned surface.
const cutPoints = [
new THREE.Vector3(tank.width / 2, 0.18, 0),
new THREE.Vector3(tank.width / 2, tank.height, 0),
new THREE.Vector3(-tank.width / 2, 0.18, 0),
new THREE.Vector3(tank.width / 2, 0.18, 0)
];
const cutGeometry = new THREE.BufferGeometry().setFromPoints(cutPoints);
const cutLine = new THREE.LineSegments(
cutGeometry,
new THREE.LineDashedMaterial({
color: 0xffb45f,
dashSize: 0.13,
gapSize: 0.08,
transparent: true,
opacity: 0.8
})
);
cutLine.computeLineDistances();
scene.add(cutLine);
// -------------------------------------------------------------------------
// Liquid volume and surface
// -------------------------------------------------------------------------
const innerWidth = tank.width - 0.16;
const innerDepth = tank.depth - 0.16;
const liquidMaterial = new THREE.MeshPhongMaterial({
color: 0x2da9ed,
transparent: true,
opacity: 0.16,
shininess: 75,
specular: 0x9ee8ff,
depthWrite: false,
side: THREE.DoubleSide
});
const liquidMesh = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
liquidMaterial
);
liquidMesh.renderOrder = 1;
scene.add(liquidMesh);
const liquidEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(1, 1, 1)),
new THREE.LineBasicMaterial({
color: 0x67d5ff,
transparent: true,
opacity: 0.42
})
);
scene.add(liquidEdges);
const surface = new THREE.Mesh(
new THREE.PlaneGeometry(innerWidth, innerDepth),
new THREE.MeshPhysicalMaterial({
color: 0x70d8ff,
transparent: true,
opacity: 0.42,
roughness: 0.18,
metalness: 0.05,
side: THREE.DoubleSide,
depthWrite: false
})
);
surface.rotation.x = -Math.PI / 2;
surface.renderOrder = 2;
scene.add(surface);
function heightForVolume(volume) {
return (volume / CAPACITY) * tank.liquidHeight;
}
function updateLiquid(volume) {
const height = heightForVolume(volume);
const centerY = tank.base + height / 2;
liquidMesh.scale.set(innerWidth, height, innerDepth);
liquidMesh.position.y = centerY;
liquidEdges.scale.set(innerWidth, height, innerDepth);
liquidEdges.position.y = centerY;
surface.position.y = tank.base + height;
}
// -------------------------------------------------------------------------
// Volume gauge
// -------------------------------------------------------------------------
function makeTextSprite(text, color = "#d8efff") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(5, 15, 25, 0.72)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(160, 205, 235, 0.22)";
context.strokeRect(1, 1, canvas.width - 2, canvas.height - 2);
context.font = "600 32px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.renderOrder = 10;
return sprite;
}
for (let i = 0; i <= 4; i++) {
const y = tank.base + heightForVolume(i);
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.27, 0.014, 0.018),
new THREE.MeshBasicMaterial({ color: 0x83b8d2 })
);
tick.position.set(-tank.width / 2 - 0.18, y, -tank.depth / 2 + 0.02);
scene.add(tick);
const label = makeTextSprite(`${i} L`);
label.scale.set(0.57, 0.143, 1);
label.position.set(-tank.width / 2 - 0.67, y, -tank.depth / 2 + 0.02);
scene.add(label);
}
const volumeIndicator = new THREE.Mesh(
new THREE.BoxGeometry(0.06, 1, 0.025),
new THREE.MeshBasicMaterial({ color: 0x5bceff })
);
scene.add(volumeIndicator);
// -------------------------------------------------------------------------
// Solvent inlet pipe
// -------------------------------------------------------------------------
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x7893a8,
roughness: 0.28,
metalness: 0.78
});
function cylinderBetween(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(radius, radius, length, 18);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
const pipeX = 2.65;
const pipeZ = 0.1;
const nozzleX = 1.35;
const nozzleY = 3.82;
cylinderBetween(
new THREE.Vector3(pipeX, 3.45, pipeZ),
new THREE.Vector3(pipeX, 4.6, pipeZ),
0.105,
pipeMaterial
);
cylinderBetween(
new THREE.Vector3(pipeX, 4.08, pipeZ),
new THREE.Vector3(nozzleX, 4.08, pipeZ),
0.105,
pipeMaterial
);
cylinderBetween(
new THREE.Vector3(nozzleX, 4.08, pipeZ),
new THREE.Vector3(nozzleX, nozzleY, pipeZ),
0.105,
pipeMaterial
);
const nozzleRing = new THREE.Mesh(
new THREE.TorusGeometry(0.107, 0.018, 10, 24),
new THREE.MeshBasicMaterial({ color: 0x5ed0ff })
);
nozzleRing.rotation.x = Math.PI / 2;
nozzleRing.position.set(nozzleX, nozzleY, pipeZ);
scene.add(nozzleRing);
// -------------------------------------------------------------------------
// Deterministic particle seeds
// -------------------------------------------------------------------------
let seed = 923741;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const soluteSeeds = Array.from({ length: SOLUTE_MARKERS }, () => ({
x: (random() - 0.5) * (innerWidth - 0.27),
z: (random() - 0.5) * (innerDepth - 0.27),
layer: random(),
phase: random() * Math.PI * 2
}));
const solventSeeds = Array.from({ length: MAX_SOLVENT_MARKERS }, () => ({
x: (random() - 0.5) * (innerWidth - 0.16),
z: (random() - 0.5) * (innerDepth - 0.16),
layer: random(),
phase: random() * Math.PI * 2
}));
// -------------------------------------------------------------------------
// Solute markers: fixed count and fixed x/z positions
// -------------------------------------------------------------------------
const soluteMaterial = new THREE.MeshStandardMaterial({
color: 0xffbd43,
emissive: 0xa24f08,
emissiveIntensity: 0.42,
roughness: 0.27,
metalness: 0.22
});
const soluteMesh = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.045, 10, 8),
soluteMaterial,
SOLUTE_MARKERS
);
soluteMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
soluteMesh.frustumCulled = false;
scene.add(soluteMesh);
const instanceDummy = new THREE.Object3D();
function updateSolute(volume, time) {
const height = heightForVolume(volume);
soluteSeeds.forEach((particle, index) => {
const y =
tank.base +
0.065 +
particle.layer * Math.max(0.05, height - 0.13) +
Math.sin(time * 0.85 + particle.phase) * 0.009;
instanceDummy.position.set(particle.x, y, particle.z);
instanceDummy.rotation.set(0, 0, 0);
instanceDummy.scale.setScalar(1);
instanceDummy.updateMatrix();
soluteMesh.setMatrixAt(index, instanceDummy.matrix);
});
soluteMesh.instanceMatrix.needsUpdate = true;
soluteMaterial.emissiveIntensity = 0.42 + inventoryPulse * 1.7;
}
// -------------------------------------------------------------------------
// Solvent markers: count grows as solvent is added
// -------------------------------------------------------------------------
const solventPositions = new Float32Array(MAX_SOLVENT_MARKERS * 3);
const solventGeometry = new THREE.BufferGeometry();
solventGeometry.setAttribute(
"position",
new THREE.BufferAttribute(solventPositions, 3)
);
const solventMaterial = new THREE.PointsMaterial({
color: 0x70d7ff,
size: 0.035,
transparent: true,
opacity: 0.64,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const solventPoints = new THREE.Points(solventGeometry, solventMaterial);
solventPoints.frustumCulled = false;
solventPoints.renderOrder = 2;
scene.add(solventPoints);
function updateSolvent(volume, time) {
const height = heightForVolume(volume);
const count = Math.min(
MAX_SOLVENT_MARKERS,
Math.floor(260 + (volume - INITIAL_VOLUME) * 210)
);
solventGeometry.setDrawRange(0, count);
for (let i = 0; i < count; i++) {
const particle = solventSeeds[i];
const y =
tank.base +
0.04 +
particle.layer * Math.max(0.04, height - 0.08) +
Math.sin(time * 0.65 + particle.phase) * 0.006;
solventPositions[i * 3] = particle.x;
solventPositions[i * 3 + 1] = y;
solventPositions[i * 3 + 2] = particle.z;
}
solventGeometry.attributes.position.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Pouring stream
// -------------------------------------------------------------------------
const STREAM_COUNT = 72;
const streamPositions = new Float32Array(STREAM_COUNT * 3);
const streamGeometry = new THREE.BufferGeometry();
streamGeometry.setAttribute(
"position",
new THREE.BufferAttribute(streamPositions, 3)
);
const streamMaterial = new THREE.PointsMaterial({
color: 0x8ae4ff,
size: 0.052,
transparent: true,
opacity: 0.9,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const streamPoints = new THREE.Points(streamGeometry, streamMaterial);
streamPoints.visible = false;
streamPoints.frustumCulled = false;
scene.add(streamPoints);
function updateStream(time) {
const surfaceY = tank.base + heightForVolume(currentVolume);
for (let i = 0; i < STREAM_COUNT; i++) {
const phase = (time * 1.45 + i / STREAM_COUNT) % 1;
const spread = 0.035 + phase * 0.045;
streamPositions[i * 3] =
nozzleX + (random() - 0.5) * spread;
streamPositions[i * 3 + 1] =
nozzleY - phase * (nozzleY - surfaceY);
streamPositions[i * 3 + 2] =
pipeZ + (random() - 0.5) * spread;
}
streamGeometry.attributes.position.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Metrics and chart
// -------------------------------------------------------------------------
function updateMetrics() {
const concentration = SOLUTE_MMOL / currentVolume;
const relative = (concentration / (SOLUTE_MMOL / INITIAL_VOLUME)) * 100;
const added = currentVolume - INITIAL_VOLUME;
volumeValue.innerHTML = `${currentVolume.toFixed(2)} <small>L</small>`;
concentrationValue.innerHTML = `${concentration.toFixed(2)} <small>mmol/L</small>`;
concentrationBar.style.width = `${relative}%`;
relativeValue.textContent = `${relative.toFixed(1)}% of initial`;
addedValue.textContent = `${added.toFixed(2)} L added`;
volumeCallout.innerHTML = `Solution volume: <b>${currentVolume.toFixed(2)} L</b>`;
const volumeHeight = heightForVolume(currentVolume);
volumeIndicator.scale.y = Math.max(0.001, volumeHeight);
volumeIndicator.position.set(
-tank.width / 2 - 0.34,
tank.base + volumeHeight / 2,
-tank.depth / 2 + 0.02
);
}
function chartPoint(volume) {
const concentration = SOLUTE_MMOL / volume;
const x = 20 + ((volume - INITIAL_VOLUME) / (CAPACITY - INITIAL_VOLUME)) * 280;
const y = 100 - ((concentration - 2.5) / 4) * 80;
return { x, y };
}
function updateChart() {
const points = [...history];
const finalPoint = points[points.length - 1];
if (Math.abs(finalPoint.volume - currentVolume) > 0.0001) {
points.push({
volume: currentVolume,
concentration: SOLUTE_MMOL / currentVolume
});
}
const coordinates = points.map(point => {
const projected = chartPoint(point.volume);
return `${projected.x.toFixed(2)},${projected.y.toFixed(2)}`;
});
trendLine.setAttribute("points", coordinates.join(" "));
if (coordinates.length > 1) {
const first = coordinates[0].split(",");
const last = coordinates[coordinates.length - 1].split(",");
trendArea.setAttribute(
"points",
`${first[0]},100 ${coordinates.join(" ")} ${last[0]},100`
);
} else {
trendArea.setAttribute("points", "");
}
const current = chartPoint(currentVolume);
trendDot.setAttribute("cx", current.x);
trendDot.setAttribute("cy", current.y);
}
// -------------------------------------------------------------------------
// Model actions
// -------------------------------------------------------------------------
function addSolvent() {
if (targetVolume >= CAPACITY - 0.0001) {
stopAutoPour();
return;
}
const amount = Number(solventAmount.value);
const from = currentVolume;
const to = Math.min(CAPACITY, targetVolume + amount);
targetVolume = to;
pour.active = true;
pour.from = from;
pour.to = to;
pour.elapsed = 0;
inventoryPulse = 1;
streamPoints.visible = true;
soluteMetric.classList.remove("pulse");
void soluteMetric.offsetWidth;
soluteMetric.classList.add("pulse");
}
function resetModel() {
stopAutoPour();
currentVolume = INITIAL_VOLUME;
targetVolume = INITIAL_VOLUME;
pour.active = false;
pour.from = INITIAL_VOLUME;
pour.to = INITIAL_VOLUME;
pour.elapsed = 0;
history = [
{ volume: INITIAL_VOLUME, concentration: SOLUTE_MMOL / INITIAL_VOLUME }
];
inventoryPulse = 0;
streamPoints.visible = false;
updateLiquid(currentVolume);
updateMetrics();
updateChart();
updateButtons();
}
function updateButtons() {
const amount = Number(solventAmount.value);
amountOutput.textContent = `${amount.toFixed(2)} L`;
pourButton.textContent = pour.active
? "Pouring solvent…"
: `Add ${amount.toFixed(2)} L solvent`;
pourButton.disabled = targetVolume >= CAPACITY - 0.0001;
if (targetVolume >= CAPACITY - 0.0001) {
pourButton.textContent = "Vessel full";
}
}
function startAutoPour() {
if (autoTimer !== null) return;
autoTimer = window.setInterval(() => {
if (targetVolume >= CAPACITY - 0.0001) {
stopAutoPour();
return;
}
addSolvent();
}, 1500);
autoButton.textContent = "Auto pour: on";
autoButton.classList.add("active");
}
function stopAutoPour() {
if (autoTimer !== null) {
window.clearInterval(autoTimer);
autoTimer = null;
}
autoButton.textContent = "Auto pour: off";
autoButton.classList.remove("active");
}
solventAmount.addEventListener("input", updateButtons);
pourButton.addEventListener("click", addSolvent);
autoButton.addEventListener("click", () => {
if (autoTimer === null) {
startAutoPour();
} else {
stopAutoPour();
}
});
resetButton.addEventListener("click", resetModel);
// -------------------------------------------------------------------------
// Custom camera controls — no addon imports
// -------------------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
orbit.theta -= deltaX * 0.007;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.006,
0.38,
1.43
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
applyCamera();
});
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(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
5.6,
13
);
applyCamera();
},
{ passive: false }
);
function resetCamera() {
orbit.radius = 8.4;
orbit.theta = 0.64;
orbit.phi = 1.08;
orbit.target.set(0, 1.65, 0);
applyCamera();
}
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Project HTML labels from 3D anchors
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionCallout(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const rect = viewport.getBoundingClientRect();
const x = (projected.x * 0.5 + 0.5) * rect.width;
const y = (-projected.y * 0.5 + 0.5) * rect.height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.visibility =
projected.z < -1 || projected.z > 1 ? "hidden" : "visible";
}
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (pour.active) {
pour.elapsed += delta;
const progress = Math.min(1, pour.elapsed / pour.duration);
const eased = progress * progress * (3 - 2 * progress);
currentVolume =
pour.from + (pour.to - pour.from) * eased;
if (progress >= 1) {
currentVolume = pour.to;
targetVolume = pour.to;
pour.active = false;
streamPoints.visible = false;
const previous = history[history.length - 1];
if (Math.abs(previous.volume - currentVolume) > 0.0001) {
history.push({
volume: currentVolume,
concentration: SOLUTE_MMOL / currentVolume
});
}
updateButtons();
}
}
inventoryPulse = Math.max(0, inventoryPulse - delta * 2.2);
updateLiquid(currentVolume);
updateSolute(currentVolume, time);
updateSolvent(currentVolume, time);
if (streamPoints.visible) {
updateStream(time);
}
updateMetrics();
updateChart();
const height = heightForVolume(currentVolume);
const surfaceY = tank.base + height;
positionCallout(
soluteCallout,
new THREE.Vector3(-0.55, tank.base + height * 0.66, 0.75)
);
positionCallout(
solventCallout,
new THREE.Vector3(nozzleX + 0.25, nozzleY + 0.36, pipeZ)
);
positionCallout(
volumeCallout,
new THREE.Vector3(1.65, surfaceY + 0.23, 1.0)
);
renderer.render(scene, camera);
}
updateLiquid(currentVolume);
updateMetrics();
updateChart();
updateButtons();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```