Prompt specification
Build or customize the Three.js 3D scene "Grass regrowth after clipping" 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: Grass regrowth after clipping
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/grass-regrowth-after-clipping-x0738
Scene Description Prompt:
Use Three.js from cdnjs to show a grass blade shortened above its base and then extending through new geometry from the growth region; retain the cut edge in the visible sequence. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (grass-regrowth-after-clipping-x0738):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Grass — Cut and Regrow</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(7, 18, 14, 0.78);
--line: rgba(175, 255, 204, 0.16);
--mint: #a7ffd0;
--gold: #ffd36a;
--muted: #91aa9a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07110d;
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; }
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}
#header {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #effff4;
font-size: clamp(22px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
#description {
min-height: 38px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
#stageRow {
display: flex;
align-items: center;
gap: 10px;
margin-top: 15px;
}
#stageNumber {
display: grid;
width: 30px;
height: 30px;
place-items: center;
flex: 0 0 auto;
border: 1px solid rgba(167, 255, 208, 0.28);
border-radius: 8px;
color: var(--mint);
background: rgba(167, 255, 208, 0.07);
font-size: 11px;
font-weight: 800;
}
#stageTitle {
color: #effff4;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.04em;
}
#data {
top: 22px;
right: 22px;
width: 218px;
padding: 15px;
border-radius: 14px;
font-size: 11px;
}
.data-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid rgba(175, 255, 204, 0.09);
color: var(--muted);
}
.data-row:last-child { border-bottom: 0; }
.data-row strong {
color: #effff4;
font-variant-numeric: tabular-nums;
}
.swatch {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 2px;
vertical-align: 1px;
}
.swatch.gold { background: var(--gold); box-shadow: 0 0 12px rgba(255, 211, 106, 0.55); }
.swatch.mint { background: var(--mint); box-shadow: 0 0 12px rgba(167, 255, 208, 0.55); }
#timeline {
position: fixed;
z-index: 5;
right: 22px;
bottom: 22px;
left: 22px;
display: flex;
align-items: center;
gap: 14px;
padding: 12px 14px;
border-radius: 14px;
}
#timelineTrack {
position: relative;
height: 5px;
flex: 1;
overflow: hidden;
border-radius: 99px;
background: rgba(220, 255, 232, 0.11);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #5fd895, #a7ffd0);
box-shadow: 0 0 15px rgba(167, 255, 208, 0.42);
}
button {
min-width: 76px;
height: 34px;
border: 1px solid rgba(167, 255, 208, 0.22);
border-radius: 9px;
color: #effff4;
background: rgba(167, 255, 208, 0.08);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(167, 255, 208, 0.15);
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
#time {
min-width: 72px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
#hint {
position: fixed;
z-index: 4;
bottom: 88px;
left: 24px;
color: rgba(205, 235, 215, 0.52);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
#cutLabel {
position: fixed;
z-index: 6;
left: 0;
top: 0;
padding: 7px 10px;
border: 1px solid rgba(255, 211, 106, 0.42);
border-radius: 8px;
color: var(--gold);
background: rgba(22, 19, 9, 0.86);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
white-space: nowrap;
pointer-events: none;
opacity: 0;
transform: translate(-50%, calc(-100% - 25px));
transition: opacity 160ms ease;
}
#cutLabel::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 18px;
background: linear-gradient(var(--gold), rgba(255, 211, 106, 0.15));
}
@media (max-width: 700px) {
#header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
#data {
top: 150px;
right: 12px;
width: 178px;
padding: 10px;
}
#timeline {
right: 12px;
bottom: 12px;
left: 12px;
}
#hint { display: none; }
#description { min-height: 0; }
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="header" class="panel">
<div class="eyebrow">Procedural voxel study</div>
<h1>Cut. Preserve. Regrow.</h1>
<p id="description">A full voxel grass blade is cut above its base.</p>
<div id="stageRow">
<div id="stageNumber">01</div>
<div id="stageTitle">FULL BLADE</div>
</div>
</section>
<aside id="data" class="panel">
<div class="data-row">
<span><i class="swatch gold"></i>Retained edge</span>
<strong>VISIBLE</strong>
</div>
<div class="data-row">
<span>New meshes</span>
<strong id="meshCount">00</strong>
</div>
<div class="data-row">
<span>Blade height</span>
<strong id="heightValue">0.00</strong>
</div>
</aside>
<div id="hint">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE · R TO REPLAY</div>
<div id="cutLabel">RETAINED CUT EDGE</div>
<section id="timeline" class="panel">
<button id="playButton" type="button">PAUSE</button>
<div id="timelineTrack"><div id="progress"></div></div>
<button id="replayButton" type="button">REPLAY</button>
<div id="time">00.0 / 09.0</div>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const description = document.getElementById("description");
const stageNumber = document.getElementById("stageNumber");
const stageTitle = document.getElementById("stageTitle");
const meshCount = document.getElementById("meshCount");
const heightValue = document.getElementById("heightValue");
const progress = document.getElementById("progress");
const timeLabel = document.getElementById("time");
const playButton = document.getElementById("playButton");
const replayButton = document.getElementById("replayButton");
const cutLabel = document.getElementById("cutLabel");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07130e);
scene.fog = new THREE.Fog(0x07130e, 10, 23);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 60);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xb9ffe0, 0x172216, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd0, 3.1);
sun.position.set(5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -5;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x79ffc2, 1.5);
rim.position.set(-5, 4, -5);
scene.add(rim);
const cameraTarget = new THREE.Vector3(0.05, 2.35, 0);
const orbit = {
theta: 0.67,
phi: 1.08,
radius: 9.2,
targetTheta: 0.67,
targetPhi: 1.08,
targetRadius: 9.2
};
function updateCamera(dt) {
const ease = 1 - Math.exp(-dt * 9);
orbit.theta += (orbit.targetTheta - orbit.theta) * ease;
orbit.phi += (orbit.targetPhi - orbit.phi) * ease;
orbit.radius += (orbit.targetRadius - orbit.radius) * ease;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(orbit.targetPhi - dy * 0.005, 0.42, 1.43);
});
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("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.007,
5.6,
15
);
}, { passive: false });
// Voxel-tiled ground.
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0,
vertexColors: true
});
const tileGeometry = new THREE.BoxGeometry(0.47, 0.13, 0.47);
const tileCount = 25;
const tiles = new THREE.InstancedMesh(tileGeometry, groundMaterial, tileCount * tileCount);
tiles.receiveShadow = true;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let tileIndex = 0;
for (let z = 0; z < tileCount; z++) {
for (let x = 0; x < tileCount; x++) {
const px = (x - (tileCount - 1) / 2) * 0.5;
const pz = (z - (tileCount - 1) / 2) * 0.5;
matrix.makeTranslation(px, -0.075, pz);
tiles.setMatrixAt(tileIndex, matrix);
const variation = 0.025 * Math.sin(x * 1.7 + z * 0.9);
color.setHSL(0.285 + variation, 0.22, 0.09 + variation * 0.4);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
const VOXEL = 0.17;
const SPACING = 0.175;
const ORIGINAL_ROWS = 26;
const CUT_ROW = 10;
const GROWTH_ROWS = 32;
const GROWTH_X = 0.52;
const GROWTH_Z = 0.10;
const cubeGeometry = new THREE.BoxGeometry(VOXEL, VOXEL, VOXEL);
function rowCenter(row) {
return 0.12 + row * SPACING;
}
function bladeCurve(row) {
return Math.sin(row * 0.15) * 0.17 + row * 0.012;
}
function originalWidth(row) {
if (row < 4) return 3;
if (row < 18) return 2;
return 1;
}
function growthWidth(row) {
if (row < 3) return 1;
if (row < 21) return 2;
return 1;
}
const lowerPalette = [
new THREE.MeshStandardMaterial({ color: 0x287744, roughness: 0.82 }),
new THREE.MeshStandardMaterial({ color: 0x329452, roughness: 0.8 }),
new THREE.MeshStandardMaterial({ color: 0x3ba65a, roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: 0x56bd68, roughness: 0.76 })
];
const upperPalette = lowerPalette.map(material => {
const clone = material.clone();
clone.transparent = true;
return clone;
});
const growthPalette = [
new THREE.MeshStandardMaterial({ color: 0x55e887, roughness: 0.7 }),
new THREE.MeshStandardMaterial({ color: 0x72f39a, roughness: 0.68 }),
new THREE.MeshStandardMaterial({ color: 0x91ffb0, roughness: 0.66 }),
new THREE.MeshStandardMaterial({ color: 0xb5ffd0, roughness: 0.64 })
];
const lowerBlade = new THREE.Group();
const upperBlade = new THREE.Group();
scene.add(lowerBlade, upperBlade);
for (let row = 0; row <= CUT_ROW; row++) {
const width = originalWidth(row);
for (let column = 0; column < width; column++) {
const material = lowerPalette[(row + column * 2) % lowerPalette.length];
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.position.set(
bladeCurve(row) + (column - (width - 1) / 2) * SPACING,
rowCenter(row),
0
);
mesh.castShadow = true;
mesh.receiveShadow = true;
lowerBlade.add(mesh);
}
}
const pivotY = rowCenter(CUT_ROW) + VOXEL / 2;
upperBlade.position.y = pivotY;
for (let row = CUT_ROW + 1; row < ORIGINAL_ROWS; row++) {
const width = originalWidth(row);
for (let column = 0; column < width; column++) {
const material = upperPalette[(row + column) % upperPalette.length];
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.position.set(
bladeCurve(row) + (column - (width - 1) / 2) * SPACING,
rowCenter(row) - pivotY,
0
);
mesh.castShadow = true;
mesh.receiveShadow = true;
upperBlade.add(mesh);
}
}
// Bright, retained cut face. It stays in the scene after the new blade grows.
const cutGroup = new THREE.Group();
cutGroup.position.set(bladeCurve(CUT_ROW), pivotY + 0.018, 0);
cutGroup.visible = false;
scene.add(cutGroup);
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xffd36a,
emissive: 0xffa62b,
emissiveIntensity: 0.9,
roughness: 0.48
});
const cutFace = new THREE.Mesh(
new THREE.BoxGeometry(0.39, 0.045, 0.185),
cutMaterial
);
cutFace.castShadow = true;
cutGroup.add(cutFace);
const cutPixelMaterial = new THREE.MeshBasicMaterial({ color: 0xfff2b4 });
const cutPixel = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.05, 0.025),
cutPixelMaterial
);
cutPixel.position.set(0, 0, 0.103);
cutGroup.add(cutPixel);
// The growth region remains visible at the base.
const growthGroup = new THREE.Group();
growthGroup.position.set(GROWTH_X, 0, GROWTH_Z);
scene.add(growthGroup);
const growthMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0xa7ffd0,
emissive: 0x42ff9a,
emissiveIntensity: 1.3,
roughness: 0.35
});
const markerGeometry = new THREE.BoxGeometry(0.07, 0.07, 0.07);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const marker = new THREE.Mesh(markerGeometry, growthMarkerMaterial);
marker.position.set(Math.cos(angle) * 0.22, 0.045, Math.sin(angle) * 0.22);
growthGroup.add(marker);
}
const growthLight = new THREE.PointLight(0x75ffb0, 0, 2.1, 2);
growthLight.position.set(GROWTH_X, 0.18, GROWTH_Z);
scene.add(growthLight);
// Small voxel particles emphasize the cut while leaving the cut face behind.
const particles = [];
for (let i = 0; i < 18; i++) {
const material = new THREE.MeshBasicMaterial({
color: i % 3 === 0 ? 0xfff0a0 : 0x8fe89d,
transparent: true,
opacity: 0
});
const particle = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.035, 0.035),
material
);
particle.visible = false;
scene.add(particle);
particles.push({
mesh: particle,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 1.6,
0.7 + Math.random() * 1.25,
(Math.random() - 0.5) * 0.8
),
birth: 2.5 + Math.random() * 0.25,
spin: new THREE.Vector3(
Math.random() * 4,
Math.random() * 4,
Math.random() * 4
)
});
}
const CUT_START = 2.4;
const CUT_DURATION = 1.2;
const GROWTH_START = 4.0;
const ROW_DELAY = 0.13;
const FINAL_TIME = 9.0;
let elapsed = 0;
let playing = true;
let nextGrowthRow = 0;
let createdMeshCount = 0;
let lastStage = -1;
const clamp01 = value => THREE.MathUtils.clamp(value, 0, 1);
const smoothstep = value => {
const x = clamp01(value);
return x * x * (3 - 2 * x);
};
const easeOutBack = value => {
const x = clamp01(value);
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
};
function createGrowthRow(row) {
const width = growthWidth(row);
const curve = Math.sin(row * 0.13) * 0.18;
for (let column = 0; column < width; column++) {
const material = growthPalette[(row + column * 2) % growthPalette.length];
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.position.set(
curve + (column - (width - 1) / 2) * SPACING,
rowCenter(row),
0
);
mesh.scale.setScalar(0.001);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.birth = GROWTH_START + row * ROW_DELAY;
growthGroup.add(mesh);
createdMeshCount++;
}
}
function resetGrowth() {
growthGroup.children
.filter(child => child.userData.birth !== undefined)
.forEach(child => growthGroup.remove(child));
nextGrowthRow = 0;
createdMeshCount = 0;
meshCount.textContent = "00";
}
function resetAnimation() {
elapsed = 0;
playing = true;
lastStage = -1;
playButton.textContent = "PAUSE";
resetGrowth();
upperBlade.visible = true;
upperBlade.position.set(0, pivotY, 0);
upperBlade.rotation.set(0, 0, 0);
upperPalette.forEach(material => material.opacity = 1);
cutGroup.visible = false;
cutGroup.scale.setScalar(0.001);
particles.forEach(particle => {
particle.mesh.visible = false;
particle.mesh.material.opacity = 0;
});
heightValue.textContent = "0.00";
}
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "PAUSE" : "PLAY";
});
replayButton.addEventListener("click", resetAnimation);
addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "r") resetAnimation();
});
function setStage(index, title, text) {
if (lastStage === index) return;
lastStage = index;
stageNumber.textContent = String(index).padStart(2, "0");
stageTitle.textContent = title;
description.textContent = text;
}
function updateCut() {
const p = clamp01((elapsed - CUT_START) / CUT_DURATION);
if (elapsed >= CUT_START) {
const fall = smoothstep(p);
upperBlade.visible = p < 0.995;
upperBlade.position.x = fall * 1.35;
upperBlade.position.y = pivotY - fall * fall * 0.55;
upperBlade.rotation.z = -fall * 1.22;
upperBlade.rotation.x = fall * 0.18;
upperPalette.forEach(material => material.opacity = 1 - smoothstep((p - 0.08) / 0.92));
const capReveal = easeOutBack((p - 0.08) / 0.34);
cutGroup.visible = p >= 0.08;
cutGroup.scale.setScalar(Math.max(0.001, capReveal));
}
particles.forEach(particle => {
const age = elapsed - particle.birth;
if (age < 0 || age > 1.25) {
particle.mesh.visible = false;
return;
}
particle.mesh.visible = true;
particle.mesh.position.set(
bladeCurve(CUT_ROW) + particle.velocity.x * age,
pivotY + particle.velocity.y * age - 1.65 * age * age,
particle.velocity.z * age
);
particle.mesh.rotation.set(
particle.spin.x * age,
particle.spin.y * age,
particle.spin.z * age
);
particle.mesh.scale.setScalar(Math.max(0.01, 1 - age / 1.35));
particle.mesh.material.opacity = Math.max(0, 1 - age / 1.25);
});
}
function updateGrowth() {
while (
nextGrowthRow < GROWTH_ROWS &&
elapsed >= GROWTH_START + nextGrowthRow * ROW_DELAY
) {
createGrowthRow(nextGrowthRow);
nextGrowthRow++;
}
let visibleHeight = 0;
growthGroup.children.forEach(mesh => {
if (mesh.userData.birth === undefined) return;
const age = elapsed - mesh.userData.birth;
const scale = age <= 0 ? 0.001 : easeOutBack(age / 0.28);
mesh.scale.setScalar(Math.max(0.001, scale));
if (age >= 0) {
visibleHeight = Math.max(visibleHeight, mesh.position.y + VOXEL / 2);
}
});
const pulse = 0.5 + 0.5 * Math.sin(elapsed * 5.2);
growthMarkerMaterial.emissiveIntensity = 0.65 + pulse * 1.25;
growthLight.intensity = elapsed > 3.25 ? 0.45 + pulse * 0.75 : 0.18;
heightValue.textContent = visibleHeight.toFixed(2);
meshCount.textContent = String(createdMeshCount).padStart(2, "0");
}
const cutLabelPoint = new THREE.Vector3(
bladeCurve(CUT_ROW),
pivotY + 0.08,
0
);
const projected = new THREE.Vector3();
function updateCutLabel() {
if (!cutGroup.visible || cutGroup.scale.x < 0.7) {
cutLabel.style.opacity = "0";
return;
}
projected.copy(cutLabelPoint).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
cutLabel.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
cutLabel.style.left = `${x}px`;
cutLabel.style.top = `${y}px`;
cutLabel.style.opacity = "1";
}
function updateStage() {
if (elapsed < CUT_START) {
setStage(
1,
"FULL BLADE",
"A complete grass blade is assembled from visible cubic voxels."
);
} else if (elapsed < 3.6) {
setStage(
2,
"CUT ABOVE THE BASE",
"The upper section detaches. The lower blade and its bright cut face remain."
);
} else if (elapsed < GROWTH_START) {
setStage(
3,
"GROWTH REGION",
"The protected base stays intact while the new growth origin is revealed."
);
} else if (elapsed < 8.5) {
setStage(
4,
"NEW GEOMETRY GROWS",
"Fresh voxel meshes are created row by row from the luminous growth region."
);
} else {
setStage(
5,
"CUT EDGE RETAINED",
"The new blade extends beyond its former height while the original cut edge remains visible."
);
}
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
elapsed = Math.min(elapsed + dt, FINAL_TIME);
}
updateCut();
updateGrowth();
updateStage();
updateCamera(dt);
updateCutLabel();
progress.style.width = `${(elapsed / FINAL_TIME) * 100}%`;
timeLabel.textContent = `${elapsed.toFixed(1).padStart(4, "0")} / 09.0`;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resetAnimation();
requestAnimationFrame(animate);
</script>
</body>
</html>
```