Prompt specification
Build or customize the Three.js 3D scene "Interleaved tissue cutaway" 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: Interleaved tissue cutaway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/interleaved-tissue-cutaway-x0070
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a voxel cutaway of an interleaved tissue dispenser. Give the box a narrow opening along its top and remove or make transparent one side so several folded sheets can be followed inside; use slightly different pale shades for neighboring tissues and show their alternating folds overlapping near the opening. Animate the exposed tissue being pulled upward; its interleaved fold should lift the next sheet just far enough to leave a new tab protruding. Release that connection as the first tissue exits. Repeat the sequence slowly with the next sheet, keeping every visible tissue path continuous.
Working Three.js Starter (interleaved-tissue-cutaway-x0070):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Interleaved Voxel Tissue Dispenser</title>
<style>
:root {
color-scheme: light;
--ink: #34434a;
--muted: #718087;
--panel: rgba(250, 249, 244, 0.82);
--line: rgba(71, 88, 95, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eceb;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.card {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 12px 34px rgba(48, 64, 70, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#titleCard {
top: 22px;
left: 22px;
width: min(330px, calc(100vw - 44px));
padding: 17px 18px 15px;
border-radius: 15px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 20px;
font-weight: 720;
letter-spacing: -0.025em;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#statusRow {
display: flex;
align-items: center;
gap: 9px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
#statusDot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: #b7c7bd;
box-shadow: 0 0 0 4px rgba(183, 199, 189, 0.18);
transition: background 180ms ease, box-shadow 180ms ease;
}
#status {
font-size: 11px;
font-weight: 650;
letter-spacing: 0.015em;
}
#progressTrack {
height: 3px;
margin-top: 12px;
overflow: hidden;
border-radius: 3px;
background: rgba(75, 91, 98, 0.11);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #9cb7aa, #d9bfae);
}
#dots {
display: flex;
gap: 6px;
margin-top: 11px;
}
.dot {
width: 20px;
height: 4px;
border-radius: 4px;
background: rgba(65, 82, 89, 0.13);
transition: background 180ms ease, transform 180ms ease;
}
.dot.active {
background: #91aa9f;
transform: translateY(-1px);
}
#controls {
right: 22px;
bottom: 22px;
padding: 10px 12px;
border-radius: 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
#controls strong {
color: var(--ink);
font-weight: 680;
}
.buttons {
display: flex;
gap: 7px;
margin-top: 9px;
}
button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.76);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
}
button:hover {
background: white;
border-color: rgba(71, 88, 95, 0.32);
}
button:active { transform: translateY(1px); }
@media (max-width: 620px) {
#titleCard {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
#controls {
right: 12px;
bottom: 12px;
}
h1 { font-size: 17px; }
.subtitle { display: none; }
}
</style>
</head>
<body>
<section id="titleCard" class="card" aria-live="polite">
<p class="eyebrow">Mechanism study · No. 05</p>
<h1>Interleaved Tissue Dispenser</h1>
<p class="subtitle">
A cutaway voxel dispenser showing the folded locking lap transfer from one
tissue to the next.
</p>
<div id="statusRow">
<span id="statusDot"></span>
<span id="status">Preparing the first tissue</span>
</div>
<div id="progressTrack"><div id="progress"></div></div>
<div id="dots" aria-hidden="true"></div>
</section>
<section id="controls" class="card">
<div><strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom</div>
<div class="buttons">
<button id="pauseButton" type="button">Pause</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eceb);
scene.fog = new THREE.Fog(0xe8eceb, 21, 37);
const camera = new THREE.OrthographicCamera(-8, 8, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 3.85, 0);
let yaw = 0.68;
let pitch = 0.47;
let zoom = 1;
let dragging = false;
let dragX = 0;
let dragY = 0;
function updateCamera() {
const radius = 16;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
yaw = 0.68;
pitch = 0.47;
zoom = 1;
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = 6.55;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.0045, 0.18, 1.02);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(zoom * Math.exp(-event.deltaY * 0.001), 0.72, 1.75);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetButton").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffffff, 0x8c9b91, 2.05));
const keyLight = new THREE.DirectionalLight(0xfff7e8, 3.25);
keyLight.position.set(7, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xcadce4, 1.55);
rimLight.position.set(-8, 7, -7);
scene.add(rimLight);
const slotLight = new THREE.PointLight(0xfff1d9, 6.5, 9, 2);
slotLight.position.set(0, 6.0, 1.2);
scene.add(slotLight);
// -------------------------------------------------------------------------
// Voxel dispenser shell
// -------------------------------------------------------------------------
const blockGeometry = new THREE.BoxGeometry(1, 1, 1);
const blocks = [];
const dummy = new THREE.Object3D();
function addBlock(x, y, z, sx, sy, sz, color) {
blocks.push({
position: new THREE.Vector3(x, y, z),
scale: new THREE.Vector3(sx, sy, sz),
color: new THREE.Color(color)
});
}
const coolBlocks = [0xaebbc0, 0xb7c3c7, 0xa7b5ba, 0xc0cacd];
const warmBlocks = [0xc5b6a7, 0xd0c1b2, 0xbbaea3, 0xc9beb2];
// Back wall.
const cols = 10;
const rows = 11;
const cellX = 0.48;
const cellY = 0.47;
for (let ix = 0; ix < cols; ix++) {
for (let iy = 0; iy < rows; iy++) {
const x = -2.4 + (ix + 0.5) * cellX;
const y = 0.16 + (iy + 0.5) * cellY;
const color = coolBlocks[(ix * 3 + iy * 5) % coolBlocks.length];
addBlock(x, y, -2.06, 0.455, 0.448, 0.32, color);
}
}
// Left and right walls.
for (let side = -1; side <= 1; side += 2) {
for (let iz = 0; iz < 8; iz++) {
for (let iy = 0; iy < rows; iy++) {
const z = -1.76 + (iz + 0.5) * 0.44;
const y = 0.16 + (iy + 0.5) * cellY;
const color = coolBlocks[(iz + iy * 2 + (side + 1)) % coolBlocks.length];
addBlock(side * 2.39, y, z, 0.32, 0.448, 0.415, color);
}
}
}
// Top shell, divided into two banks to leave a narrow slit.
for (let ix = 0; ix < cols; ix++) {
const x = -2.4 + (ix + 0.5) * cellX;
for (let iz = 0; iz < 4; iz++) {
const z = -1.98 + (iz + 0.5) * 0.44;
addBlock(x, 5.25, z, 0.455, 0.29, 0.415, warmBlocks[ix % warmBlocks.length]);
}
for (let iz = 0; iz < 4; iz++) {
const z = 0.18 + (iz + 0.5) * 0.44;
addBlock(x, 5.25, z, 0.455, 0.29, 0.415, warmBlocks[(ix + 2) % warmBlocks.length]);
}
}
// Base blocks.
for (let ix = 0; ix < cols; ix++) {
for (let iz = 0; iz < 8; iz++) {
addBlock(
-2.4 + (ix + 0.5) * cellX,
0.04,
-1.76 + (iz + 0.5) * 0.44,
0.455,
0.22,
0.415,
coolBlocks[(ix + iz) % coolBlocks.length]
);
}
}
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0.02
});
const shell = new THREE.InstancedMesh(blockGeometry, shellMaterial, blocks.length);
shell.castShadow = true;
shell.receiveShadow = true;
blocks.forEach((block, index) => {
dummy.position.copy(block.position);
dummy.scale.copy(block.scale);
dummy.updateMatrix();
shell.setMatrixAt(index, dummy.matrix);
shell.setColorAt(index, block.color);
});
shell.instanceMatrix.needsUpdate = true;
if (shell.instanceColor) shell.instanceColor.needsUpdate = true;
scene.add(shell);
// Darker lip around the slit.
const lipMaterial = new THREE.MeshStandardMaterial({
color: 0x6f7d81,
roughness: 0.72,
metalness: 0.12
});
const lipGeometry = new THREE.BoxGeometry(4.82, 0.12, 0.11);
const lipA = new THREE.Mesh(lipGeometry, lipMaterial);
lipA.position.set(0, 5.42, -0.405);
lipA.castShadow = true;
scene.add(lipA);
const lipB = lipA.clone();
lipB.position.z = 0.405;
scene.add(lipB);
// Transparent front wall for the cutaway.
const frontMaterial = new THREE.MeshBasicMaterial({
color: 0xbdd9df,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
});
const frontWall = new THREE.Mesh(new THREE.PlaneGeometry(4.73, 5.04), frontMaterial);
frontWall.position.set(0, 2.55, 2.075);
frontWall.renderOrder = 10;
scene.add(frontWall);
const frontFrame = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(4.78, 5.12, 0.08)),
new THREE.LineBasicMaterial({
color: 0x75888e,
transparent: true,
opacity: 0.34
})
);
frontFrame.position.set(0, 2.55, 2.075);
scene.add(frontFrame);
// Interior floor.
const interiorFloor = new THREE.Mesh(
new THREE.PlaneGeometry(4.55, 3.9),
new THREE.MeshStandardMaterial({
color: 0x7f8d8d,
roughness: 0.96
})
);
interiorFloor.rotation.x = -Math.PI / 2;
interiorFloor.position.y = 0.17;
interiorFloor.receiveShadow = true;
scene.add(interiorFloor);
// Ground.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xdde3e0,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.09;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Continuous folded tissue ribbons
// -------------------------------------------------------------------------
const TISSUE_COUNT = 5;
const BODY_POINT_COUNT = 10;
const HOOK_POINT_COUNT = 3;
const POINTS_PER_TISSUE = BODY_POINT_COUNT + HOOK_POINT_COUNT;
const SEGMENTS_PER_TISSUE = POINTS_PER_TISSUE - 1;
const VERTS_PER_SEGMENT = 24;
const THICKNESS = 0.034;
const palette = [
0xfff2d9,
0xf5e5dc,
0xf2efe0,
0xe8f0e6,
0xe6eef3
];
const tissues = [];
function createRibbonGeometry() {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(SEGMENTS_PER_TISSUE * VERTS_PER_SEGMENT * 3);
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3).setUsage(THREE.DynamicDrawUsage)
);
geometry.setAttribute(
"normal",
new THREE.BufferAttribute(new Float32Array(positions.length), 3)
.setUsage(THREE.DynamicDrawUsage)
);
return geometry;
}
function writeRectPrism(target, offset, a, b, widthA, widthB) {
const dy = b.y - a.y;
const dz = b.z - a.z;
const length = Math.hypot(dy, dz) || 1;
const normalY = -dz / length;
const normalZ = dy / length;
const halfThickness = THICKNESS * 0.5;
const halfA = widthA * 0.5;
const halfB = widthB * 0.5;
const a0 = [
[a.x - halfA, a.y + normalY * halfThickness, a.z + normalZ * halfThickness],
[a.x + halfA, a.y + normalY * halfThickness, a.z + normalZ * halfThickness],
[a.x + halfA, a.y - normalY * halfThickness, a.z - normalZ * halfThickness],
[a.x - halfA, a.y - normalY * halfThickness, a.z - normalZ * halfThickness]
];
const b0 = [
[b.x - halfB, b.y + normalY * halfThickness, b.z + normalZ * halfThickness],
[b.x + halfB, b.y + normalY * halfThickness, b.z + normalZ * halfThickness],
[b.x + halfB, b.y - normalY * halfThickness, b.z - normalZ * halfThickness],
[b.x - halfB, b.y - normalY * halfThickness, b.z - normalZ * halfThickness]
];
const faces = [
[a0[0], a0[1], b0[1], b0[0]],
[a0[3], b0[3], b0[2], a0[2]],
[a0[1], a0[2], b0[2], b0[1]],
[a0[0], b0[0], b0[3], a0[3]],
[a0[0], a0[3], a0[2], a0[1]],
[b0[0], b0[1], b0[2], b0[3]]
];
let cursor = offset;
for (const face of faces) {
const triangleOrder = [0, 1, 2, 0, 2, 3];
for (const index of triangleOrder) {
const vertex = face[index];
target[cursor++] = vertex[0];
target[cursor++] = vertex[1];
target[cursor++] = vertex[2];
}
}
}
function updateRibbonGeometry(geometry, points) {
const positions = geometry.attributes.position.array;
let offset = 0;
for (let i = 0; i < points.length - 1; i++) {
writeRectPrism(
positions,
offset,
points[i],
points[i + 1],
points[i].width,
points[i + 1].width
);
offset += VERTS_PER_SEGMENT * 3;
}
geometry.attributes.position.needsUpdate = true;
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
}
function createTissue(index) {
const color = new THREE.Color(palette[index]);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
side: THREE.DoubleSide
});
const geometry = createRibbonGeometry();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const lineColor = color.clone().multiplyScalar(0.73);
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(POINTS_PER_TISSUE * 3), 3)
.setUsage(THREE.DynamicDrawUsage)
);
const edgeLine = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: lineColor,
transparent: true,
opacity: 0.42
})
);
scene.add(edgeLine);
tissues.push({ mesh, geometry, edgeLine, lineGeometry });
}
for (let i = 0; i < TISSUE_COUNT; i++) createTissue(i);
function makePoint(x, y, z, width) {
return { x, y, z, width };
}
function buildTissuePath(index, ownOffset, nextOffset, hookFactor) {
const direction = index % 2 === 0 ? 1 : -1;
const bias = [-0.10, 0.10, -0.055, 0.055, 0][index];
const xCenter = [-0.10, 0.10, -0.055, 0.055, 0][index];
const width = 2.72 - index * 0.025;
const topZ = (index % 2 === 0 ? -1 : 1) * 0.105;
const foldDepths = [
0.62 * direction,
-0.62 * direction,
0.62 * direction,
-0.62 * direction,
0.40 * direction,
-0.30 * direction,
0.16 * direction,
0.03 * direction
].map((value) => value + bias);
const ys = [0.52, 1.10, 1.78, 2.48, 3.14, 3.72, 4.18, 4.64, 5.17, 5.62];
const points = [];
for (let i = 0; i < BODY_POINT_COUNT; i++) {
const taper = i < 7 ? 1 : 1 - (i - 6) * 0.018;
points.push(
makePoint(
xCenter,
ys[i] + ownOffset,
i >= 7 ? topZ : foldDepths[i],
width * taper
)
);
}
const nextTopZ =
index + 1 < TISSUE_COUNT
? (index + 1) % 2 === 0
? -0.105
: 0.105
: topZ;
// The engaged locking lap reaches over the next tissue.
const engaged = [
makePoint(xCenter, 5.80 + ownOffset, topZ + direction * 0.08, width * 0.97),
makePoint(
xCenter,
5.43 + nextOffset,
(topZ + nextTopZ) * 0.5 + direction * 0.055,
width * 0.95
),
makePoint(xCenter, 5.05 + nextOffset, nextTopZ + direction * 0.045, width * 0.93)
];
// Released state: the same material curls upward and away from the next lap.
const curled = [
makePoint(xCenter, 5.80 + ownOffset, topZ + direction * 0.10, width * 0.97),
makePoint(xCenter, 5.68 + ownOffset, topZ + direction * 0.22, width * 0.95),
makePoint(xCenter, 5.88 + ownOffset, topZ + direction * 0.31, width * 0.93)
];
for (let i = 0; i < HOOK_POINT_COUNT; i++) {
const e = engaged[i];
const c = curled[i];
points.push(
makePoint(
e.x,
THREE.MathUtils.lerp(c.y, e.y, hookFactor),
THREE.MathUtils.lerp(c.z, e.z, hookFactor),
THREE.MathUtils.lerp(c.width, e.width, hookFactor)
)
);
}
return points;
}
function updateTissue(tissue, points) {
updateRibbonGeometry(tissue.geometry, points);
const linePositions = tissue.lineGeometry.attributes.position.array;
for (let i = 0; i < points.length; i++) {
const point = points[i];
const edgeX = point.x + point.width * 0.47;
linePositions[i * 3] = edgeX;
linePositions[i * 3 + 1] = point.y;
linePositions[i * 3 + 2] = point.z;
}
tissue.lineGeometry.attributes.position.needsUpdate = true;
tissue.lineGeometry.computeBoundingSphere();
}
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const STAGE_DURATION = 7.8;
const TAB_LIFT = 0.30;
const SLOT_HEIGHT = 5.20;
const statusElement = document.getElementById("status");
const statusDot = document.getElementById("statusDot");
const progressElement = document.getElementById("progress");
const dotsElement = document.getElementById("dots");
for (let i = 0; i < TISSUE_COUNT; i++) {
const dot = document.createElement("span");
dot.className = "dot";
dotsElement.appendChild(dot);
}
const dots = [...dotsElement.children];
function smooth01(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function interval(value, start, end) {
return smooth01((value - start) / (end - start));
}
let paused = false;
const pauseButton = document.getElementById("pauseButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") resetCamera();
});
function updateStatus(stage, t, action, color) {
const number = stage + 1;
statusElement.textContent = action;
statusDot.style.background = color;
statusDot.style.boxShadow = `0 0 0 4px ${color}28`;
progressElement.style.width = `${((stage + t / STAGE_DURATION) / TISSUE_COUNT) * 100}%`;
dots.forEach((dot, index) => {
dot.classList.toggle("active", index === stage);
});
statusElement.dataset.sheet = number;
}
function updateScene(elapsed) {
const cycleDuration = STAGE_DURATION * TISSUE_COUNT;
const cycleTime = elapsed % cycleDuration;
const stage = Math.min(TISSUE_COUNT - 1, Math.floor(cycleTime / STAGE_DURATION));
const t = cycleTime - stage * STAGE_DURATION;
const currentBaseOffset = stage === 0 ? 0 : TAB_LIFT;
const nextLift = TAB_LIFT * interval(t, 0.8, 3.8);
let currentRise = 0;
if (t < 0.8) {
currentRise = 0;
} else if (t < 3.8) {
currentRise = 0.85 * interval(t, 0.8, 3.8);
} else if (t < 4.6) {
currentRise = 0.85 + 0.20 * interval(t, 3.8, 4.6);
} else if (t < 6.8) {
const exitRise = SLOT_HEIGHT - 0.52 - currentBaseOffset;
currentRise = THREE.MathUtils.lerp(
1.05,
exitRise,
interval(t, 4.6, 6.8)
);
} else {
const exitRise = SLOT_HEIGHT - 0.52 - currentBaseOffset;
currentRise = exitRise;
}
const offsets = new Array(TISSUE_COUNT).fill(0);
offsets[stage] = currentBaseOffset + currentRise;
if (stage + 1 < TISSUE_COUNT) offsets[stage + 1] = nextLift;
for (let i = 0; i < TISSUE_COUNT; i++) {
const tissue = tissues[i];
const isDispensed = i < stage;
tissue.mesh.visible = !isDispensed;
tissue.edgeLine.visible = !isDispensed;
if (isDispensed) continue;
let hookFactor = 0;
if (i === stage) {
if (stage === 0) {
hookFactor = 1 - interval(t, 3.8, 4.6);
} else {
const engagement = interval(t, 0, 0.8);
const release = interval(t, 3.8, 4.6);
hookFactor = engagement * (1 - release);
}
}
const nextOffset = i + 1 < TISSUE_COUNT ? offsets[i + 1] : offsets[i];
const path = buildTissuePath(i, offsets[i], nextOffset, hookFactor);
updateTissue(tissue, path);
}
let action;
let color;
if (t < 0.8) {
action = stage === 0
? "Tissue 1 is ready at the slot"
: `Tissue ${stage + 1} unfolds its locking lap`;
color = "#b7c7bd";
} else if (t < 3.8) {
action = `Tissue ${stage + 1} lifts tissue ${stage + 2}`;
color = "#91aa9f";
} else if (t < 4.6) {
action = `The locking connection on tissue ${stage + 1} releases`;
color = "#d4ad92";
} else if (t < 6.8) {
action = `Tissue ${stage + 1} exits through the slot`;
color = "#c6a796";
} else {
action = `Tissue ${stage + 2} is left as the next tab`;
color = "#9fb7ad";
}
updateStatus(stage, t, action, color);
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
resize();
updateCamera();
const clock = new THREE.Clock();
let animationTime = 0;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) animationTime += delta;
updateScene(animationTime);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```