Prompt specification
Build or customize the Three.js 3D scene "Milk-to-curd phase diagram model" 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: Milk-to-curd phase diagram model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/milk-to-curd-phase-diagram-model-x1053
Scene Description Prompt:
Use Three.js from cdnjs to show a transparent vessel containing symbolic curds and whey beside a uniform milk sample; distinguish solid aggregation from separated liquid without providing a production recipe. Deliver one self-contained HTML file with stylized solid shapes.
Working Three.js Starter (milk-to-curd-phase-diagram-model-x1053):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Curds, Whey, and Uniform Milk — Symbolic Phase Comparison</title>
<style>
:root {
--ink: #15343d;
--muted: #5f777c;
--cream: #fbf7ec;
--gold: #e7bd56;
--whey: #9fd3d4;
--milk: #f3ead7;
--glass: rgba(255, 255, 255, 0.72);
--border: rgba(38, 80, 88, 0.14);
--shadow: 0 18px 50px rgba(42, 79, 86, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(circle at 70% 15%, rgba(255, 255, 255, 0.96), transparent 36%),
radial-gradient(circle at 17% 78%, rgba(188, 226, 220, 0.42), transparent 35%),
linear-gradient(145deg, #edf6f3 0%, #f8f4e8 58%, #e7f1ef 100%);
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#stage canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.intro {
position: absolute;
top: clamp(24px, 4vw, 54px);
left: clamp(24px, 4vw, 62px);
width: min(380px, calc(100vw - 48px));
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 14px;
color: #4e7478;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
border-radius: 99px;
background: var(--gold);
content: "";
}
h1 {
margin: 0;
font-size: clamp(34px, 4.2vw, 64px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.055em;
}
h1 em {
color: #6b9897;
font-family: Georgia, "Times New Roman", serif;
font-weight: 400;
}
.intro p {
max-width: 345px;
margin: 19px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.concept-badge {
position: absolute;
top: clamp(24px, 4vw, 54px);
right: clamp(24px, 4vw, 62px);
display: flex;
align-items: center;
gap: 9px;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 999px;
color: #5e777a;
background: rgba(255, 255, 255, 0.56);
box-shadow: 0 8px 30px rgba(42, 79, 86, 0.06);
backdrop-filter: blur(14px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.concept-badge span {
width: 7px;
height: 7px;
border-radius: 50%;
background: #76aaa2;
box-shadow: 0 0 0 4px rgba(118, 170, 162, 0.15);
}
.info-card {
position: absolute;
top: 112px;
right: clamp(24px, 4vw, 62px);
width: 286px;
padding: 20px 21px;
border: 1px solid var(--border);
border-radius: 20px;
background: rgba(255, 255, 255, 0.57);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.info-card h2 {
margin: 0 0 14px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.info-row {
display: grid;
grid-template-columns: 13px 1fr;
gap: 10px;
margin: 12px 0;
color: #536e72;
font-size: 12px;
line-height: 1.5;
}
.info-row i {
width: 10px;
height: 10px;
margin-top: 3px;
border-radius: 3px;
}
.info-row i.solid {
background: var(--gold);
box-shadow: inset 0 0 0 1px rgba(112, 77, 14, 0.12);
}
.info-row i.liquid {
background: linear-gradient(135deg, #c9e8e6, #78bfc2);
}
.info-row i.uniform {
border: 1px solid rgba(121, 106, 79, 0.13);
background: var(--milk);
}
.info-card p {
margin: 17px 0 0;
padding-top: 14px;
border-top: 1px solid var(--border);
color: #75898c;
font-size: 11px;
line-height: 1.55;
}
.legend {
position: absolute;
bottom: clamp(28px, 5vw, 58px);
left: clamp(24px, 4vw, 62px);
display: flex;
gap: 22px;
padding: 14px 17px;
border: 1px solid var(--border);
border-radius: 17px;
background: rgba(255, 255, 255, 0.62);
box-shadow: 0 12px 35px rgba(42, 79, 86, 0.08);
backdrop-filter: blur(16px);
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #536d71;
font-size: 11px;
font-weight: 700;
}
.swatch {
width: 14px;
height: 14px;
border-radius: 4px;
}
.swatch.gold {
background: var(--gold);
box-shadow: inset 0 0 0 1px rgba(112, 77, 14, 0.12);
}
.swatch.whey {
background: linear-gradient(135deg, #c9e8e6, #78bfc2);
}
.swatch.milk {
border: 1px solid rgba(121, 106, 79, 0.13);
background: var(--milk);
}
.controls {
position: absolute;
right: clamp(24px, 4vw, 62px);
bottom: clamp(28px, 5vw, 58px);
display: flex;
align-items: center;
gap: 7px;
padding: 7px;
border: 1px solid var(--border);
border-radius: 16px;
background: rgba(255, 255, 255, 0.68);
box-shadow: 0 12px 35px rgba(42, 79, 86, 0.08);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.controls button {
min-height: 36px;
padding: 0 12px;
border: 0;
border-radius: 10px;
color: #557176;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.controls button:hover {
color: var(--ink);
background: rgba(101, 151, 148, 0.1);
}
.controls button:active {
transform: translateY(1px);
}
.controls button.active {
color: #315d60;
background: rgba(103, 160, 155, 0.16);
}
.controls .divider {
width: 1px;
height: 23px;
background: var(--border);
}
.hint {
position: absolute;
left: 50%;
bottom: 16px;
transform: translateX(-50%);
color: rgba(52, 83, 88, 0.56);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
#labels.hidden {
display: none;
}
.scene-label {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
transition: opacity 180ms ease;
}
.scene-label.visible {
opacity: 1;
}
.scene-label > i {
position: absolute;
top: -4px;
left: -4px;
width: 8px;
height: 8px;
border: 2px solid rgba(255, 255, 255, 0.9);
border-radius: 50%;
background: #4c7778;
box-shadow: 0 2px 8px rgba(31, 68, 73, 0.25);
}
.label-copy {
position: absolute;
min-width: 126px;
padding: 9px 11px;
border: 1px solid rgba(45, 84, 90, 0.13);
border-radius: 11px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 8px 24px rgba(37, 75, 81, 0.1);
backdrop-filter: blur(12px);
white-space: nowrap;
}
.label-copy b,
.label-copy span {
display: block;
}
.label-copy b {
color: #294f55;
font-size: 11px;
font-weight: 800;
}
.label-copy span {
margin-top: 2px;
color: #779093;
font-size: 9px;
font-weight: 650;
}
#label-curds .label-copy {
left: 50%;
bottom: 15px;
transform: translateX(-50%);
}
#label-curds .label-copy::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
background: rgba(65, 104, 107, 0.4);
content: "";
}
#label-whey .label-copy {
right: 15px;
top: 50%;
transform: translateY(-50%);
}
#label-whey .label-copy::after {
position: absolute;
top: 50%;
left: 100%;
width: 15px;
height: 1px;
background: rgba(65, 104, 107, 0.4);
content: "";
}
#label-uniform .label-copy {
left: 15px;
top: 50%;
transform: translateY(-50%);
}
#label-uniform .label-copy::after {
position: absolute;
top: 50%;
right: 100%;
width: 15px;
height: 1px;
background: rgba(65, 104, 107, 0.4);
content: "";
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #5e7a7d;
background: #edf5f1;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.04em;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 980px) {
.info-card {
top: auto;
right: 24px;
bottom: 100px;
width: 250px;
}
.concept-badge {
display: none;
}
}
@media (max-width: 720px) {
.intro {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
h1 {
max-width: 280px;
font-size: 37px;
}
.intro p {
max-width: 280px;
margin-top: 12px;
font-size: 12px;
}
.eyebrow {
margin-bottom: 10px;
}
.info-card {
display: none;
}
.legend {
bottom: 82px;
left: 20px;
gap: 13px;
padding: 11px 13px;
}
.legend-item {
font-size: 9px;
}
.controls {
right: 20px;
bottom: 22px;
left: 20px;
justify-content: center;
overflow-x: auto;
}
.controls button {
padding: 0 9px;
font-size: 10px;
}
.hint {
display: none;
}
.label-copy {
min-width: auto;
padding: 7px 9px;
}
.label-copy span {
display: none;
}
}
@media (max-width: 480px) {
#label-whey .label-copy,
#label-uniform .label-copy {
display: none;
}
.legend {
right: 20px;
justify-content: space-between;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels">
<div class="scene-label" id="label-curds">
<i></i>
<div class="label-copy">
<b>Curds</b>
<span>symbolic solid aggregates</span>
</div>
</div>
<div class="scene-label" id="label-whey">
<i></i>
<div class="label-copy">
<b>Whey</b>
<span>continuous liquid phase</span>
</div>
</div>
<div class="scene-label" id="label-uniform">
<i></i>
<div class="label-copy">
<b>Uniform milk</b>
<span>single visible phase</span>
</div>
</div>
</div>
<div class="hud">
<header class="intro">
<div class="eyebrow">Symbolic phase comparison</div>
<h1>Separated structure<br /><em>vs. uniform sample</em></h1>
<p>
An abstract comparison of clustered solids, a continuous liquid phase,
and milk with no visible internal phase boundary.
</p>
</header>
<div class="concept-badge">
<span></span>
Conceptual visualization
</div>
<aside class="info-card">
<h2>Reading the forms</h2>
<div class="info-row">
<i class="solid"></i>
<span><b>Golden clusters</b> represent symbolic solid aggregation.</span>
</div>
<div class="info-row">
<i class="liquid"></i>
<span><b>Blue-white body</b> represents the separated liquid phase.</span>
</div>
<div class="info-row">
<i class="uniform"></i>
<span><b>Cream sample</b> remains visually uniform, without distinct forms.</span>
</div>
<p>
Phase-state illustration only. Shapes, colors, and relative sizes are
symbolic and do not represent a production recipe or process.
</p>
</aside>
<div class="legend">
<div class="legend-item">
<span class="swatch gold"></span>
Solid aggregate
</div>
<div class="legend-item">
<span class="swatch whey"></span>
Continuous liquid
</div>
<div class="legend-item">
<span class="swatch milk"></span>
Uniform sample
</div>
</div>
<nav class="controls" aria-label="Visualization controls">
<button type="button" data-view="all" class="active">Both</button>
<button type="button" data-view="separated">Separated</button>
<button type="button" data-view="uniform">Uniform</button>
<span class="divider"></span>
<button type="button" id="rotateButton" aria-pressed="false">Auto rotate</button>
<button type="button" id="labelsButton" aria-pressed="true">Labels</button>
<button type="button" id="resetButton">Reset</button>
</nav>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
</div>
<div id="loading">Preparing the phase comparison…</div>
<script>
setTimeout(() => {
if (!window.__phaseVizReady) {
document.getElementById("loading").textContent =
"The 3D library could not be loaded. Check your connection and reload.";
}
}, 12000);
</script>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of symbolic curds and whey beside a uniform milk sample"
);
stage.appendChild(renderer.domElement);
const world = new THREE.Group();
world.position.y = -0.12;
scene.add(world);
const hemisphere = new THREE.HemisphereLight(0xf9fffc, 0xa7b9b4, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff8e9, 3.2);
keyLight.position.set(4.5, 7.5, 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 = 20;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e8e4, 1.35);
fillLight.position.set(-5, 3.5, -3);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xffefcc, 12, 12, 2);
rimLight.position.set(0, 4, -4);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.ShadowMaterial({
color: 0x33575a,
opacity: 0.15
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = 0;
floor.receiveShadow = true;
scene.add(floor);
const vesselRadius = 1.02;
const vesselHeight = 2.62;
const vesselBottom = 0.16;
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd9f4f2,
transparent: true,
opacity: 0.24,
roughness: 0.08,
metalness: 0,
transmission: 0.12,
thickness: 0.08,
side: THREE.DoubleSide,
depthWrite: false
});
const rimMaterial = new THREE.MeshPhysicalMaterial({
color: 0xe8ffff,
transparent: true,
opacity: 0.48,
roughness: 0.1,
metalness: 0,
transmission: 0.08,
depthWrite: false
});
function createVessel() {
const group = new THREE.Group();
const wall = new THREE.Mesh(
new THREE.CylinderGeometry(
vesselRadius,
vesselRadius * 0.94,
vesselHeight,
64,
1,
true
),
glassMaterial
);
wall.position.y = vesselBottom + vesselHeight / 2;
wall.renderOrder = 5;
group.add(wall);
const bottom = new THREE.Mesh(
new THREE.CylinderGeometry(
vesselRadius * 0.945,
vesselRadius * 0.945,
0.055,
64
),
glassMaterial
);
bottom.position.y = vesselBottom;
bottom.renderOrder = 5;
group.add(bottom);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(vesselRadius, 0.035, 12, 72),
rimMaterial
);
rim.rotation.x = Math.PI / 2;
rim.position.y = vesselBottom + vesselHeight;
rim.renderOrder = 6;
group.add(rim);
const lowerRing = new THREE.Mesh(
new THREE.TorusGeometry(vesselRadius * 0.945, 0.018, 10, 72),
rimMaterial
);
lowerRing.rotation.x = Math.PI / 2;
lowerRing.position.y = vesselBottom + 0.035;
lowerRing.renderOrder = 6;
group.add(lowerRing);
return group;
}
function createSurface(radius, y, material) {
const surface = new THREE.Mesh(
new THREE.CircleGeometry(radius, 72),
material
);
surface.rotation.x = -Math.PI / 2;
surface.position.y = y;
surface.receiveShadow = true;
return surface;
}
const leftVessel = createVessel();
leftVessel.position.x = -1.62;
world.add(leftVessel);
const rightVessel = createVessel();
rightVessel.position.x = 1.62;
world.add(rightVessel);
const wheyHeight = 1.54;
const wheyBase = 0.205;
const wheyTop = wheyBase + wheyHeight;
const wheyMaterial = new THREE.MeshPhysicalMaterial({
color: 0xa9d9d8,
transparent: true,
opacity: 0.43,
roughness: 0.24,
metalness: 0,
transmission: 0.08,
thickness: 0.5,
depthWrite: false,
side: THREE.DoubleSide
});
const wheyVolume = new THREE.Mesh(
new THREE.CylinderGeometry(
0.895,
0.87,
wheyHeight,
72
),
wheyMaterial
);
wheyVolume.position.set(-1.62, wheyBase + wheyHeight / 2, 0);
wheyVolume.renderOrder = 1;
world.add(wheyVolume);
const wheySurfaceMaterial = new THREE.MeshPhysicalMaterial({
color: 0xbce2df,
transparent: true,
opacity: 0.66,
roughness: 0.25,
metalness: 0,
transmission: 0.06,
thickness: 0.08,
depthWrite: false,
side: THREE.DoubleSide
});
const wheySurface = createSurface(
0.89,
wheyTop + 0.004,
wheySurfaceMaterial
);
wheySurface.position.x = -1.62;
wheySurface.renderOrder = 2;
world.add(wheySurface);
const wheyMeniscus = new THREE.Mesh(
new THREE.TorusGeometry(0.865, 0.011, 8, 72),
new THREE.MeshBasicMaterial({
color: 0xe3ffff,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
wheyMeniscus.rotation.x = Math.PI / 2;
wheyMeniscus.position.set(-1.62, wheyTop + 0.008, 0);
wheyMeniscus.renderOrder = 3;
world.add(wheyMeniscus);
function randomGenerator(seed) {
let state = seed >>> 0;
return () => {
state = (1664525 * state + 1013904223) >>> 0;
return state / 4294967296;
};
}
function createBlobGeometry(radius, seed) {
const geometry = new THREE.IcosahedronGeometry(radius, 2);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const displacement =
1 +
0.11 * Math.sin(x * 10.7 + seed * 1.3) +
0.075 * Math.cos(y * 9.1 - seed * 1.9) +
0.055 * Math.sin(z * 12.4 + seed * 0.7);
positions.setXYZ(
i,
x * displacement,
y * displacement,
z * displacement
);
}
geometry.computeVertexNormals();
return geometry;
}
const curdPalette = [
0xeac45f,
0xf0cd6c,
0xf6d982,
0xe4b94f
];
function createCurdAggregate(x, y, z, seed) {
const random = randomGenerator(seed);
const aggregate = new THREE.Group();
aggregate.position.set(x, y, z);
aggregate.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
const material = new THREE.MeshStandardMaterial({
color: curdPalette[Math.floor(random() * curdPalette.length)],
roughness: 0.72,
metalness: 0
});
const pieceCount = 4;
for (let i = 0; i < pieceCount; i++) {
const radius = 0.18 + random() * 0.105;
const piece = new THREE.Mesh(
createBlobGeometry(radius, seed * 7 + i * 2.31),
material
);
piece.position.set(
(random() - 0.5) * 0.25,
(random() - 0.5) * 0.23,
(random() - 0.5) * 0.22
);
piece.scale.set(
0.88 + random() * 0.34,
0.78 + random() * 0.4,
0.86 + random() * 0.3
);
piece.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
piece.castShadow = true;
piece.receiveShadow = true;
piece.renderOrder = 2;
aggregate.add(piece);
}
return aggregate;
}
const curdLayout = [
[-1.92, 0.43, 0.04, 11],
[-1.36, 0.46, -0.17, 23],
[-1.26, 0.73, 0.16, 37],
[-1.84, 0.78, -0.08, 51],
[-1.61, 1.03, 0.06, 67],
[-1.93, 1.16, -0.12, 83],
[-1.42, 1.29, -0.02, 97]
];
for (const [x, y, z, seed] of curdLayout) {
world.add(createCurdAggregate(x, y, z, seed));
}
const milkHeight = 1.61;
const milkBase = 0.205;
const milkTop = milkBase + milkHeight;
const milkMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf3ead8,
roughness: 0.34,
metalness: 0,
clearcoat: 0.2,
clearcoatRoughness: 0.48,
emissive: 0x2b2519,
emissiveIntensity: 0.025
});
const milkVolume = new THREE.Mesh(
new THREE.CylinderGeometry(
0.895,
0.87,
milkHeight,
72
),
milkMaterial
);
milkVolume.position.set(1.62, milkBase + milkHeight / 2, 0);
milkVolume.castShadow = true;
milkVolume.receiveShadow = true;
world.add(milkVolume);
const milkSurface = createSurface(
0.892,
milkTop + 0.005,
new THREE.MeshPhysicalMaterial({
color: 0xf8f0df,
roughness: 0.3,
metalness: 0,
clearcoat: 0.24,
clearcoatRoughness: 0.42,
side: THREE.DoubleSide
})
);
milkSurface.position.x = 1.62;
world.add(milkSurface);
const milkMeniscus = new THREE.Mesh(
new THREE.TorusGeometry(0.87, 0.012, 8, 72),
new THREE.MeshBasicMaterial({
color: 0xfffaf0,
transparent: true,
opacity: 0.58
})
);
milkMeniscus.rotation.x = Math.PI / 2;
milkMeniscus.position.set(1.62, milkTop + 0.009, 0);
world.add(milkMeniscus);
const labelAnchors = {
curds: new THREE.Object3D(),
whey: new THREE.Object3D(),
uniform: new THREE.Object3D()
};
labelAnchors.curds.position.set(-1.62, 1.75, 0.15);
labelAnchors.whey.position.set(-2.34, 0.78, 0.62);
labelAnchors.uniform.position.set(1.68, 1.78, 0.28);
Object.values(labelAnchors).forEach((anchor) => world.add(anchor));
const current = {
azimuth: 0.39,
polar: 1.12,
radius: 7.55,
target: new THREE.Vector3(0, 1.12, 0)
};
const goal = {
azimuth: current.azimuth,
polar: current.polar,
radius: current.radius,
target: current.target.clone()
};
let autoRotate = false;
let labelsVisible = true;
function setView(name) {
if (name === "separated") {
goal.target.set(-1.52, 1.05, 0);
goal.radius = 4.75;
goal.azimuth = 0.3;
goal.polar = 1.1;
} else if (name === "uniform") {
goal.target.set(1.52, 1.05, 0);
goal.radius = 4.75;
goal.azimuth = -0.18;
goal.polar = 1.1;
} else {
goal.target.set(0, 1.12, 0);
goal.radius = 7.55;
goal.azimuth = 0.39;
goal.polar = 1.12;
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const rotateButton = document.getElementById("rotateButton");
rotateButton.addEventListener("click", () => {
autoRotate = !autoRotate;
rotateButton.classList.toggle("active", autoRotate);
rotateButton.setAttribute("aria-pressed", String(autoRotate));
rotateButton.textContent = autoRotate ? "Pause rotate" : "Auto rotate";
});
const labelsButton = document.getElementById("labelsButton");
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
document.getElementById("labels").classList.toggle("hidden", !labelsVisible);
labelsButton.classList.toggle("active", labelsVisible);
labelsButton.setAttribute("aria-pressed", String(labelsVisible));
});
document.getElementById("resetButton").addEventListener("click", () => {
setView("all");
});
const pointers = new Map();
let pinchDistance = 0;
function clampPolar(value) {
return Math.max(0.55, Math.min(1.48, value));
}
function updatePointer(event) {
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && previous) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
current.azimuth -= dx * 0.006;
current.polar = clampPolar(current.polar - dy * 0.005);
goal.azimuth = current.azimuth;
goal.polar = current.polar;
}
if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
const delta = pinchDistance - distance;
current.radius = THREE.MathUtils.clamp(
current.radius + delta * 0.012,
3.7,
11
);
goal.radius = current.radius;
}
pinchDistance = distance;
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
updatePointer(event);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointers.has(event.pointerId)) {
updatePointer(event);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
current.radius = THREE.MathUtils.clamp(
current.radius + event.deltaY * 0.006,
3.7,
11
);
goal.radius = current.radius;
},
{ passive: false }
);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const compact = width < 720;
const veryCompact = width < 480;
world.scale.setScalar(
compact ? (veryCompact ? 0.61 : 0.72) : 1
);
}
window.addEventListener("resize", resize);
resize();
const projected = new THREE.Vector3();
function updateLabel(anchor, element) {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.classList.toggle("visible", visible);
if (!visible) {
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (autoRotate) {
goal.azimuth += dt * 0.13;
}
const smoothing = 1 - Math.exp(-dt * 7.5);
current.azimuth += (goal.azimuth - current.azimuth) * smoothing;
current.polar += (goal.polar - current.polar) * smoothing;
current.radius += (goal.radius - current.radius) * smoothing;
current.target.lerp(goal.target, smoothing);
const sinPolar = Math.sin(current.polar);
camera.position.set(
current.target.x +
current.radius * sinPolar * Math.sin(current.azimuth),
current.target.y + current.radius * Math.cos(current.polar),
current.target.z +
current.radius * sinPolar * Math.cos(current.azimuth)
);
camera.lookAt(current.target);
updateLabel(
labelAnchors.curds,
document.getElementById("label-curds")
);
updateLabel(
labelAnchors.whey,
document.getElementById("label-whey")
);
updateLabel(
labelAnchors.uniform,
document.getElementById("label-uniform")
);
renderer.render(scene, camera);
}
animate();
window.__phaseVizReady = true;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
</script>
</body>
</html>
```