Prompt specification
Build or customize the Three.js 3D scene "Tea infuser mesh and leaves" 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: Tea infuser mesh and leaves
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tea-infuser-mesh-and-leaves-x0157
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Display a split spherical infuser with coarse leaf fragments inside and visible perforations; compare fragment size against openings to explain what remains physically contained.
Working Three.js Starter (tea-infuser-mesh-and-leaves-x0157):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Infuser — Fragment Retention Study</title>
<style>
:root {
--bg: #0b100e;
--panel: rgba(15, 23, 19, 0.82);
--line: rgba(220, 231, 221, 0.15);
--text: #edf4ed;
--muted: #96a89d;
--brass: #d4a65b;
--leaf: #a8c968;
--pass: #6ed6a0;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.hero {
position: absolute;
top: 30px;
left: 34px;
width: min(360px, 30vw);
}
.kicker {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--pass);
box-shadow: 0 0 13px rgba(110, 214, 160, 0.75);
}
h1 {
margin: 18px 0 12px;
font-size: clamp(35px, 4.1vw, 61px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 760;
}
h1 em {
color: var(--brass);
font-style: normal;
font-weight: 430;
}
.lede {
width: 290px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.readout {
position: absolute;
top: 28px;
right: 28px;
width: 344px;
padding: 20px;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(255,255,255,0.035), transparent 48%),
var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.readout-head {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--muted);
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.readout-head span:last-child {
color: var(--brass);
}
.equation {
display: flex;
align-items: baseline;
gap: 7px;
margin: 18px 0 3px;
font-variant-numeric: tabular-nums;
}
.equation .fragment-size {
color: var(--leaf);
font-size: 43px;
font-weight: 720;
letter-spacing: -0.06em;
}
.equation .unit {
color: var(--muted);
font-size: 13px;
}
.equation .operator {
margin: 0 4px;
color: #617168;
font-size: 26px;
}
.equation .opening-size {
color: var(--brass);
font-size: 35px;
font-weight: 680;
letter-spacing: -0.05em;
}
.equation-note {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
}
.measurements {
margin-top: 20px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.measurement {
margin: 12px 0;
}
.measurement-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #b8c6bd;
font-size: 10px;
letter-spacing: 0.04em;
}
.measurement-label strong {
color: var(--text);
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.track {
position: relative;
height: 8px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.065);
}
.track::after {
content: "";
position: absolute;
inset: 0;
background: repeating-linear-gradient(
90deg,
transparent 0,
transparent 19%,
rgba(255,255,255,0.12) 20%
);
}
.opening-range {
position: absolute;
inset: 0 auto 0 0;
width: 32%;
border-radius: inherit;
background: var(--brass);
}
.fragment-range {
position: absolute;
top: 0;
bottom: 0;
left: 44%;
width: 50%;
border-radius: inherit;
background: linear-gradient(90deg, #769948, var(--leaf));
}
.scale-ends {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #63756b;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.verdict {
display: flex;
align-items: center;
gap: 11px;
margin-top: 17px;
padding: 12px;
border: 1px solid rgba(110, 214, 160, 0.22);
border-radius: 11px;
background: rgba(110, 214, 160, 0.07);
}
.check {
display: grid;
place-items: center;
width: 25px;
height: 25px;
flex: 0 0 auto;
border-radius: 50%;
color: #0b2418;
background: var(--pass);
font-size: 14px;
font-weight: 900;
}
.verdict strong {
display: block;
color: var(--pass);
font-size: 10px;
letter-spacing: 0.08em;
}
.verdict span:last-child {
display: block;
margin-top: 3px;
color: #a9b9ae;
font-size: 10px;
line-height: 1.35;
}
.explanation {
margin: 13px 0 0;
color: #9caea2;
font-size: 11px;
line-height: 1.52;
}
.explanation b {
color: #dfe8df;
font-weight: 620;
}
.caveat {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #667a6e;
font-size: 9px;
line-height: 1.45;
}
.legend {
position: absolute;
left: 34px;
bottom: 30px;
display: flex;
flex-wrap: wrap;
gap: 17px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
}
.swatch.metal { background: var(--brass); }
.swatch.hole { border: 1px solid var(--brass); background: #0b100e; }
.swatch.leaf { background: var(--leaf); }
.toolbar {
position: absolute;
left: 50%;
bottom: 28px;
display: flex;
align-items: center;
gap: 9px;
transform: translateX(-50%);
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(255,255,255,0.16);
border-radius: 99px;
padding: 11px 17px;
color: var(--text);
background: rgba(16, 24, 20, 0.84);
box-shadow: 0 8px 25px rgba(0,0,0,0.2);
backdrop-filter: blur(12px);
cursor: pointer;
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
transition: background 160ms, border-color 160ms, transform 160ms;
}
button:hover {
background: rgba(40, 57, 47, 0.92);
border-color: rgba(212, 166, 91, 0.55);
transform: translateY(-1px);
}
button.primary {
color: #171308;
border-color: var(--brass);
background: var(--brass);
}
button.primary:hover {
background: #e0b66f;
}
.hint {
position: absolute;
right: 32px;
bottom: 33px;
color: #6d8074;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
}
.pin {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 150ms;
will-change: transform;
}
.pin::before {
content: "";
position: absolute;
left: -4px;
top: -4px;
width: 8px;
height: 8px;
border: 2px solid #e9c27e;
border-radius: 50%;
background: #111812;
box-shadow: 0 0 0 4px rgba(212,166,91,0.12);
}
.pin::after {
content: "";
position: absolute;
left: 5px;
top: 0;
width: 28px;
height: 1px;
background: rgba(233,194,126,0.62);
}
.pin .tag {
position: absolute;
top: 0;
left: 31px;
transform: translateY(-50%);
padding: 7px 9px;
border: 1px solid rgba(233,194,126,0.25);
border-radius: 7px;
white-space: nowrap;
color: #d8e3d9;
background: rgba(12,18,14,0.82);
font: 9px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
box-shadow: 0 8px 20px rgba(0,0,0,0.22);
}
.pin .tag b {
color: #e9c27e;
font-weight: 700;
}
.pin.fragment::before {
border-color: var(--leaf);
box-shadow: 0 0 0 4px rgba(168,201,104,0.11);
}
.pin.fragment::after {
background: rgba(168,201,104,0.62);
}
.pin.fragment .tag b {
color: var(--leaf);
}
@media (max-width: 900px) {
.hero {
width: 300px;
}
.readout {
width: 310px;
}
.hint { display: none; }
}
@media (max-width: 700px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
margin-top: 12px;
font-size: 38px;
}
.lede { display: none; }
.readout {
top: auto;
right: 14px;
bottom: 78px;
width: min(330px, calc(100vw - 28px));
padding: 15px;
}
.equation { margin-top: 12px; }
.equation .fragment-size { font-size: 34px; }
.equation .opening-size { font-size: 29px; }
.measurements { margin-top: 13px; padding-top: 10px; }
.measurement { margin: 8px 0; }
.explanation, .caveat { display: none; }
.verdict { margin-top: 12px; padding: 9px; }
.legend {
left: 18px;
bottom: 18px;
gap: 10px;
}
.toolbar {
left: auto;
right: 14px;
bottom: 14px;
transform: none;
}
.toolbar button:not(.primary) { display: none; }
.pin { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="hero">
<div class="kicker">
<span class="status-dot"></span>
Material study / 03
</div>
<h1>Will it<br><em>stay inside?</em></h1>
<p class="lede">
A voxel cutaway of a perforated spherical infuser. Compare the
maximum opening with the smallest coarse leaf fragment.
</p>
</header>
<section class="readout" aria-label="Fragment and opening size comparison">
<div class="readout-head">
<span>Passage test</span>
<span>Ø 58 mm sphere</span>
</div>
<div class="equation" aria-label="2.6 millimetres greater than 1.9 millimetres">
<span class="fragment-size">2.6</span>
<span class="unit">mm</span>
<span class="operator">></span>
<span class="opening-size">1.9</span>
<span class="unit">mm</span>
</div>
<div class="equation-note">smallest coarse fragment > largest opening</div>
<div class="measurements">
<div class="measurement">
<div class="measurement-label">
<span>Maximum aperture</span>
<strong>Ø 1.9 mm</strong>
</div>
<div class="track">
<div class="opening-range"></div>
</div>
</div>
<div class="measurement">
<div class="measurement-label">
<span>Coarse fragment range</span>
<strong>Ø 2.6–5.4 mm</strong>
</div>
<div class="track">
<div class="fragment-range"></div>
</div>
</div>
<div class="scale-ends">
<span>0 mm</span>
<span>6 mm</span>
</div>
</div>
<div class="verdict">
<span class="check">✓</span>
<div>
<strong>ALL DISPLAYED COARSE FRAGMENTS RETAINED</strong>
<span>None can pass intact through the largest opening.</span>
</div>
</div>
<p class="explanation">
<b>What remains:</b> every displayed leaf fragment, because its minimum
characteristic diameter is larger than every aperture. Only particles
below <b>1.9 mm</b>, such as dust or fine crumbs, could pass.
</p>
<p class="caveat">
Size-only rigid-particle model. Real flexible leaves may bend or thread
through openings; wetness and flow can also affect passage.
</p>
</section>
<div class="legend">
<span class="legend-item"><i class="swatch metal"></i>Voxel shell</span>
<span class="legend-item"><i class="swatch hole"></i>Perforation</span>
<span class="legend-item"><i class="swatch leaf"></i>Coarse leaf</span>
</div>
<div class="toolbar">
<button id="resetView" type="button">Reset view</button>
<button id="toggleShell" class="primary" type="button" aria-pressed="true">
Close infuser
</button>
</div>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
<div id="aperturePin" class="pin">
<div class="tag">MAX OPENING<br><b>Ø 1.9 mm</b></div>
</div>
<div id="fragmentPin" class="pin fragment">
<div class="tag">COARSE FRAGMENT<br><b>≥ Ø 2.6 mm</b></div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b100e);
scene.fog = new THREE.FogExp2(0x0b100e, 0.035);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.55, 0);
const cameraState = {
radius: 9.2,
theta: 0.72,
phi: 1.12
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Lighting and pedestal
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc9e2d4, 0x24190f, 1.65));
const keyLight = new THREE.DirectionalLight(0xffe2b2, 3.2);
keyLight.position.set(5.5, 9, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x9ccfc1, 2.2);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xd9b36b, 12, 11, 2);
fillLight.position.set(3.5, 4.8, 4.5);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(10, 96),
new THREE.MeshStandardMaterial({
color: 0x101713,
roughness: 0.94,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(18, 36, 0x385044, 0x25332c);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(3.85, 4.02, 0.15, 96),
new THREE.MeshStandardMaterial({
color: 0x17211b,
roughness: 0.58,
metalness: 0.38
})
);
pedestal.position.y = 0.075;
pedestal.receiveShadow = true;
pedestal.castShadow = true;
scene.add(pedestal);
const pedestalRing = new THREE.Mesh(
new THREE.TorusGeometry(3.83, 0.025, 8, 144),
new THREE.MeshStandardMaterial({
color: 0xb58a4d,
emissive: 0x3a260c,
emissiveIntensity: 0.35,
roughness: 0.35,
metalness: 0.75
})
);
pedestalRing.rotation.x = Math.PI / 2;
pedestalRing.position.y = 0.17;
scene.add(pedestalRing);
// ------------------------------------------------------------
// Deterministic randomness
// ------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(58391);
// ------------------------------------------------------------
// Voxel shell construction
//
// Each surface panel is a 3×3 array of small voxel blocks.
// The center block is omitted, leaving one square perforation.
// ------------------------------------------------------------
const SHELL_RADIUS = 2.65;
const SHELL_CENTER_Y = 3.0;
const LATITUDE_ROWS = 20;
const BASE_LONGITUDE_SEGMENTS = 36;
const shellLeft = new THREE.Group();
const shellRight = new THREE.Group();
shellLeft.position.y = SHELL_CENTER_Y;
shellRight.position.y = SHELL_CENTER_Y;
scene.add(shellLeft, shellRight);
const leftEntries = [];
const rightEntries = [];
const yAxis = new THREE.Vector3(0, 1, 0);
const targetApertureDirection = new THREE.Vector3(0.67, 0.18, 0.72).normalize();
let bestApertureScore = -Infinity;
let bestApertureLocal = new THREE.Vector3();
for (let row = 0; row < LATITUDE_ROWS; row++) {
const theta = ((row + 0.5) / LATITUDE_ROWS) * Math.PI;
const sinTheta = Math.sin(theta);
const cosTheta = Math.cos(theta);
const longitudeSegments = Math.max(
4,
Math.round(BASE_LONGITUDE_SEGMENTS * sinTheta)
);
const panelHeight =
(2 * SHELL_RADIUS * Math.PI) / LATITUDE_ROWS;
for (let column = 0; column < longitudeSegments; column++) {
const phi =
((column + 0.5) / longitudeSegments) * Math.PI * 2;
const normal = new THREE.Vector3(
sinTheta * Math.cos(phi),
cosTheta,
sinTheta * Math.sin(phi)
);
const tangentX = new THREE.Vector3()
.crossVectors(yAxis, normal);
if (tangentX.lengthSq() < 0.00001) {
tangentX.set(1, 0, 0);
} else {
tangentX.normalize();
}
const tangentY = new THREE.Vector3()
.crossVectors(normal, tangentX)
.normalize();
const basis = new THREE.Matrix4().makeBasis(
tangentX,
tangentY,
normal
);
const quaternion = new THREE.Quaternion()
.setFromRotationMatrix(basis);
const panelWidth =
(2 * Math.PI * SHELL_RADIUS * sinTheta) /
longitudeSegments;
const cellX = panelWidth / 3;
const cellY = panelHeight / 3;
const isRight = normal.x >= 0;
const entries = isRight ? rightEntries : leftEntries;
const panelCenter = normal
.clone()
.multiplyScalar(SHELL_RADIUS);
// Create an eight-voxel frame around a missing central voxel.
for (let ix = -1; ix <= 1; ix++) {
for (let iy = -1; iy <= 1; iy++) {
if (ix === 0 && iy === 0) continue;
const position = panelCenter.clone()
.addScaledVector(tangentX, ix * cellX)
.addScaledVector(tangentY, iy * cellY);
const scale = new THREE.Vector3(
cellX * 0.86,
cellY * 0.86,
0.085
);
const color = new THREE.Color().setHSL(
0.095 + (random() - 0.5) * 0.018,
0.32 + random() * 0.12,
0.43 + (random() - 0.5) * 0.08
);
entries.push({
position,
quaternion: quaternion.clone(),
scale,
color
});
}
}
// Select a visible aperture for the on-canvas annotation.
const score = normal.dot(targetApertureDirection);
if (isRight && score > bestApertureScore) {
bestApertureScore = score;
bestApertureLocal.copy(panelCenter);
}
}
}
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
metalness: 0.68,
roughness: 0.36
});
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function createInstancedMesh(entries, material) {
const mesh = new THREE.InstancedMesh(
unitBox,
material,
entries.length
);
const helper = new THREE.Object3D();
entries.forEach((entry, index) => {
helper.position.copy(entry.position);
helper.quaternion.copy(entry.quaternion);
helper.scale.copy(entry.scale);
helper.updateMatrix();
mesh.setMatrixAt(index, helper.matrix);
mesh.setColorAt(index, entry.color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
return mesh;
}
shellLeft.add(createInstancedMesh(leftEntries, shellMaterial));
shellRight.add(createInstancedMesh(rightEntries, shellMaterial));
// A dotted voxel outline marks the original equatorial split plane.
const seamEntries = [];
for (let i = 0; i < 72; i++) {
const angle = (i / 72) * Math.PI * 2;
seamEntries.push({
position: new THREE.Vector3(
0,
Math.cos(angle) * SHELL_RADIUS,
Math.sin(angle) * SHELL_RADIUS
),
quaternion: new THREE.Quaternion(),
scale: new THREE.Vector3(0.075, 0.075, 0.075),
color: new THREE.Color(0x9f7942)
});
}
const seam = createInstancedMesh(
seamEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
metalness: 0.7,
roughness: 0.4
})
);
seam.position.y = SHELL_CENTER_Y;
scene.add(seam);
// ------------------------------------------------------------
// Coarse voxel leaf fragments
// ------------------------------------------------------------
const leafGroup = new THREE.Group();
leafGroup.position.y = SHELL_CENTER_Y;
scene.add(leafGroup);
const leafEntries = [];
const leafPatterns = [
[
[-1, 0, 0], [0, 0, 0], [1, 0, 0],
[0, 0, 1], [-1, 0, 1]
],
[
[-1, 0, 0], [0, 0, 0], [1, 0, 0],
[0, 0, -1], [0, 0, 1], [1, 0, 1]
],
[
[-1, 0, 0], [0, 0, 0], [0, 0, 1],
[-1, 0, 1], [0, 0, -1]
]
];
function addLeafFragment(origin, quaternion, cellSize, hueOffset = 0) {
const pattern =
leafPatterns[Math.floor(random() * leafPatterns.length)];
pattern.forEach((voxel, index) => {
const local = new THREE.Vector3(
voxel[0] * cellSize,
(random() - 0.5) * cellSize * 0.18,
voxel[2] * cellSize
);
const position = local
.clone()
.applyQuaternion(quaternion)
.add(origin);
const color = new THREE.Color().setHSL(
0.23 + hueOffset + (random() - 0.5) * 0.055,
0.34 + random() * 0.2,
0.25 + random() * 0.18
);
leafEntries.push({
position,
quaternion: quaternion.clone(),
scale: new THREE.Vector3(
cellSize * 0.92,
cellSize * (0.65 + random() * 0.3),
cellSize * 0.92
),
color
});
// Small contrasting vein block on some fragments.
if (index === 1) {
const veinLocal = new THREE.Vector3(
0,
cellSize * 0.52,
0
);
leafEntries.push({
position: veinLocal
.clone()
.applyQuaternion(quaternion)
.add(origin),
quaternion: quaternion.clone(),
scale: new THREE.Vector3(
cellSize * 0.14,
cellSize * 0.16,
cellSize * 1.65
),
color: new THREE.Color().setHSL(
0.19,
0.42,
0.47 + random() * 0.08
)
});
}
});
}
// A larger, clearly visible hero fragment near the split.
const heroOrigin = new THREE.Vector3(0.12, 0.18, 1.06);
const heroQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0.12, -0.22, -0.34)
);
addLeafFragment(
heroOrigin,
heroQuaternion,
0.18,
-0.015
);
// Remaining fragments are distributed inside the shell.
for (let i = 0; i < 26; i++) {
const y = random() * 2 - 1;
const azimuth = random() * Math.PI * 2;
const radius = 0.4 + 1.08 * Math.cbrt(random());
const horizontal = Math.sqrt(1 - y * y);
const origin = new THREE.Vector3(
Math.cos(azimuth) * horizontal * radius,
y * radius * 0.82,
Math.sin(azimuth) * horizontal * radius
);
const quaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(
(random() - 0.5) * 0.8,
random() * Math.PI * 2,
(random() - 0.5) * 0.8
)
);
addLeafFragment(
origin,
quaternion,
0.13 + random() * 0.055,
(random() - 0.5) * 0.06
);
}
const leaves = createInstancedMesh(
leafEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
metalness: 0.02,
roughness: 0.88
})
);
leafGroup.add(leaves);
// ------------------------------------------------------------
// Annotation anchors
// ------------------------------------------------------------
const apertureAnchor = new THREE.Object3D();
apertureAnchor.position.copy(bestApertureLocal);
shellRight.add(apertureAnchor);
const fragmentAnchor = new THREE.Object3D();
fragmentAnchor.position.copy(heroOrigin).add(
new THREE.Vector3(0, 0.13, 0)
);
leafGroup.add(fragmentAnchor);
const aperturePin = document.getElementById("aperturePin");
const fragmentPin = document.getElementById("fragmentPin");
const projectedPosition = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
function placePin(element, anchor) {
anchor.getWorldPosition(worldPosition);
projectedPosition.copy(worldPosition).project(camera);
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1;
const x = (projectedPosition.x * 0.5 + 0.5) *
window.innerWidth;
const y = (-projectedPosition.y * 0.5 + 0.5) *
window.innerHeight;
element.style.transform =
`translate3d(${x}px, ${y}px, 0)`;
element.style.opacity = visible ? "1" : "0";
}
// ------------------------------------------------------------
// Direct camera controls — no external controls addon
// ------------------------------------------------------------
const canvas = renderer.domElement;
const pointer = {
active: false,
x: 0,
y: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi -= dy * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi,
0.28,
Math.PI - 0.28
);
updateCamera();
});
function releasePointer(event) {
pointer.active = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
5.3,
14
);
updateCamera();
}, { passive: false });
document.getElementById("resetView").addEventListener("click", () => {
cameraState.radius = 9.2;
cameraState.theta = 0.72;
cameraState.phi = 1.12;
updateCamera();
});
// ------------------------------------------------------------
// Shell opening/closing interaction
// ------------------------------------------------------------
let shellOpen = true;
let splitAmount = 1;
const toggleButton = document.getElementById("toggleShell");
toggleButton.addEventListener("click", () => {
shellOpen = !shellOpen;
toggleButton.textContent = shellOpen
? "Close infuser"
: "Open cutaway";
toggleButton.setAttribute(
"aria-pressed",
String(shellOpen)
);
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
let previousTime = performance.now();
function animate(time) {
requestAnimationFrame(animate);
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
const target = shellOpen ? 1 : 0;
splitAmount +=
(target - splitAmount) *
(1 - Math.exp(-5.5 * dt));
const separation = splitAmount * 0.62;
shellLeft.position.x = -separation;
shellRight.position.x = separation;
shellLeft.rotation.y = splitAmount * 0.12;
shellRight.rotation.y = -splitAmount * 0.12;
shellLeft.rotation.z = splitAmount * 0.012;
shellRight.rotation.z = -splitAmount * 0.012;
// Very restrained movement suggests suspended fragments without
// making the containment comparison ambiguous.
leafGroup.rotation.y = Math.sin(time * 0.00022) * 0.075;
leafGroup.rotation.z = Math.sin(time * 0.00031) * 0.025;
leafGroup.position.y =
SHELL_CENTER_Y + Math.sin(time * 0.0007) * 0.028;
scene.updateMatrixWorld();
placePin(aperturePin, apertureAnchor);
placePin(fragmentPin, fragmentAnchor);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
// ------------------------------------------------------------
// Resize
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```