Prompt specification
Build or customize the Three.js 3D scene "Compost particle-size progression" 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: Compost particle-size progression
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compost-particle-size-progression-x1046
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows compost structure. Animate recognizable scraps becoming smaller dark fragments over an accelerated timeline; symbolic decomposer activity remains separate from the changing material geometry and all rates are illustrative. Voxel style.
Working Three.js Starter (compost-particle-size-progression-x1046):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Compost Structure — Voxel Process</title>
<style>
:root {
--paper: #f3f0e7;
--ink: #29352d;
--muted: #6f786f;
--line: #d8d4c8;
--green: #496b52;
--green-dark: #314b39;
--yellow: #d4a93c;
--purple: #8065c4;
--teal: #3fae9d;
--card: rgba(250, 248, 241, 0.88);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.wash {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 50% 42%,
rgba(255, 255, 255, 0) 40%,
rgba(77, 66, 43, 0.065) 100%
);
}
.intro {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
max-width: 510px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--green);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 4px;
background: var(--yellow);
box-shadow: 8px 0 0 var(--green);
}
h1 {
max-width: 480px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4.1vw, 61px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
max-width: 440px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.rate-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(73, 107, 82, 0.23);
border-radius: 999px;
background: rgba(255, 255, 255, 0.45);
color: var(--green-dark);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
}
.rate-badge i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--yellow);
box-shadow: 0 0 0 3px rgba(212, 169, 60, 0.16);
}
.readout {
position: fixed;
top: 24px;
right: 26px;
z-index: 6;
width: 286px;
padding: 18px;
border: 1px solid rgba(89, 96, 84, 0.15);
border-radius: 15px;
background: var(--card);
box-shadow: 0 16px 45px rgba(62, 54, 39, 0.09);
backdrop-filter: blur(14px);
}
.card-label {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.readout h2 {
margin: 7px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 500;
letter-spacing: -0.025em;
}
.readout > p {
min-height: 51px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.inventory {
display: grid;
gap: 8px;
margin-top: 15px;
padding: 12px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.inventory-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 8px;
font-size: 11px;
}
.inventory-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--dot);
}
.inventory-state {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
text-transform: uppercase;
}
.overlay-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 15px;
}
.overlay-name {
display: flex;
align-items: center;
gap: 8px;
color: var(--ink);
font-size: 11px;
font-weight: 750;
}
.overlay-icon {
width: 11px;
height: 11px;
border-radius: 3px;
background: var(--purple);
box-shadow:
7px 3px 0 -1px var(--teal),
3px 8px 0 -2px var(--purple);
transform: rotate(-8deg);
}
.switch {
position: relative;
display: inline-flex;
cursor: pointer;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch span {
position: relative;
width: 36px;
height: 20px;
border-radius: 999px;
background: #cbc8bf;
transition: background 160ms ease;
}
.switch span::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 14px;
height: 14px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
transition: transform 160ms ease;
}
.switch input:checked + span {
background: var(--purple);
}
.switch input:checked + span::after {
transform: translateX(16px);
}
.overlay-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.layer-legend {
display: flex;
flex-wrap: wrap;
gap: 7px 12px;
margin-top: 14px;
color: var(--muted);
font-size: 9px;
}
.layer-legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.layer-legend i {
width: 7px;
height: 7px;
border-radius: 1px;
}
.annotation {
position: fixed;
z-index: 4;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(65, 72, 61, 0.16);
border-radius: 8px;
background: rgba(250, 248, 241, 0.84);
box-shadow: 0 8px 22px rgba(58, 50, 37, 0.07);
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
opacity: var(--label-opacity, 1);
transition: opacity 180ms ease;
}
.annotation::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: rgba(65, 72, 61, 0.28);
}
.annotation-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--dot);
}
.transport {
position: fixed;
z-index: 8;
left: 26px;
right: 26px;
bottom: 24px;
padding: 16px 18px 13px;
border: 1px solid rgba(89, 96, 84, 0.16);
border-radius: 15px;
background: var(--card);
box-shadow: 0 18px 50px rgba(62, 54, 39, 0.11);
backdrop-filter: blur(15px);
}
.transport-top {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 16px;
}
.buttons {
display: flex;
gap: 8px;
}
.button {
height: 36px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
transform 140ms ease,
background 140ms ease;
}
.button:hover {
transform: translateY(-1px);
background: white;
}
.button.primary {
min-width: 75px;
border-color: var(--green);
background: var(--green);
color: white;
}
.timeline-wrap {
position: relative;
min-width: 0;
}
#timeline {
--p: 0%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 99px;
outline: none;
appearance: none;
cursor: pointer;
background: linear-gradient(
to right,
var(--green) 0%,
var(--green) var(--p),
#d8d4c9 var(--p),
#d8d4c9 100%
);
}
#timeline::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--green);
box-shadow: 0 2px 8px rgba(44, 65, 49, 0.3);
}
#timeline::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 8px rgba(44, 65, 49, 0.3);
}
.time-readout {
min-width: 104px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-align: right;
}
.stages {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 12px;
}
.stage {
position: relative;
padding-top: 8px;
color: #92978f;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stage::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 17px;
height: 2px;
background: #c7c4ba;
transition: background 180ms ease;
}
.stage.active {
color: var(--green-dark);
}
.stage.active::before {
background: var(--green);
}
.stage.done {
color: #697d6d;
}
.stage.done::before {
background: #8daa91;
}
.hint {
position: fixed;
right: 30px;
bottom: 151px;
z-index: 3;
color: rgba(61, 70, 61, 0.56);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 900px) {
.intro {
top: 20px;
left: 20px;
}
.readout {
top: 18px;
right: 18px;
width: 245px;
}
.transport {
left: 16px;
right: 16px;
bottom: 16px;
}
}
@media (max-width: 700px) {
.intro {
max-width: calc(100vw - 40px);
}
h1 {
max-width: 360px;
font-size: 38px;
}
.intro p {
max-width: 330px;
font-size: 12px;
}
.readout,
.annotation,
.hint {
display: none;
}
.transport {
padding: 13px;
}
.transport-top {
grid-template-columns: auto 1fr;
gap: 11px;
}
.time-readout {
display: none;
}
.stages {
gap: 4px;
}
.stage {
font-size: 7px;
letter-spacing: 0.02em;
}
.button {
padding: 0 11px;
}
}
@media (max-height: 650px) {
.intro p,
.rate-badge,
.inventory,
.layer-legend {
display: none;
}
.readout {
padding: 14px;
}
.readout > p {
min-height: 0;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel compost cross-section"></canvas>
<div class="wash"></div>
<header class="intro">
<div class="eyebrow">Compost / voxel process</div>
<h1>From fresh scraps<br />to stable soil.</h1>
<p>
A cutaway view of organic inputs shrinking, darkening, and settling
through a layered compost bed.
</p>
<div class="rate-badge"><i></i>36-second accelerated model · illustrative rates</div>
</header>
<aside class="readout">
<div class="card-label">Material state</div>
<h2 id="phaseTitle">Recognizable scraps</h2>
<p id="phaseText">
Bright food voxels remain distinct above the layered compost bed.
</p>
<div class="inventory" aria-label="Scrap states">
<div class="inventory-row">
<i class="inventory-dot" style="--dot:#d9503f"></i>
<span>Apple</span>
<span class="inventory-state">intact</span>
</div>
<div class="inventory-row">
<i class="inventory-dot" style="--dot:#e2b83e"></i>
<span>Banana peel</span>
<span class="inventory-state">intact</span>
</div>
<div class="inventory-row">
<i class="inventory-dot" style="--dot:#57964d"></i>
<span>Leafy greens</span>
<span class="inventory-state">intact</span>
</div>
<div class="inventory-row">
<i class="inventory-dot" style="--dot:#b87843"></i>
<span>Bread crust</span>
<span class="inventory-state">intact</span>
</div>
</div>
<div class="overlay-row">
<div class="overlay-name">
<span class="overlay-icon"></span>
Decomposer signals
</div>
<label class="switch" title="Toggle symbolic decomposer overlay">
<input id="decompToggle" type="checkbox" checked />
<span></span>
</label>
</div>
<p class="overlay-note">
Independent symbolic overlay. These markers animate separately and
never become part of the material geometry.
</p>
<div class="layer-legend">
<span><i style="background:#38271e"></i>humus base</span>
<span><i style="background:#6b482d"></i>active bed</span>
<span><i style="background:#87603d"></i>fresh inputs</span>
</div>
</aside>
<div id="labelFresh" class="annotation" style="--dot:#d9503f">
<span class="annotation-dot"></span>Fresh food voxels
</div>
<div id="labelFragments" class="annotation" style="--dot:#49352a; --label-opacity:0">
<span class="annotation-dot"></span>Darkened fragments
</div>
<div id="labelDecomp" class="annotation" style="--dot:#8065c4">
<span class="annotation-dot"></span>Independent activity signals
</div>
<section class="transport" aria-label="Animation controls">
<div class="transport-top">
<div class="buttons">
<button id="play" class="button primary" type="button">Pause</button>
<button id="reset" class="button" type="button">Reset</button>
</div>
<div class="timeline-wrap">
<input
id="timeline"
type="range"
min="0"
max="1000"
step="1"
value="0"
aria-label="Compost transformation timeline"
/>
</div>
<div id="timeReadout" class="time-readout">00.0 / 36.0 s</div>
</div>
<div class="stages">
<span class="stage active">01 · Fresh inputs</span>
<span class="stage">02 · Fragmentation</span>
<span class="stage">03 · Active change</span>
<span class="stage">04 · Soil-like endpoint</span>
</div>
</section>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET VIEW</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Constants and deterministic helpers
// ------------------------------------------------------------
const DURATION = 36;
const canvas = document.querySelector("#scene");
const playButton = document.querySelector("#play");
const resetButton = document.querySelector("#reset");
const timeline = document.querySelector("#timeline");
const timeReadout = document.querySelector("#timeReadout");
const phaseTitle = document.querySelector("#phaseTitle");
const phaseText = document.querySelector("#phaseText");
const decompToggle = document.querySelector("#decompToggle");
const stageElements = [...document.querySelectorAll(".stage")];
const inventoryStates = [
...document.querySelectorAll(".inventory-state")
];
const labelFresh = document.querySelector("#labelFresh");
const labelFragments = document.querySelector("#labelFragments");
const labelDecomp = document.querySelector("#labelDecomp");
const clamp = (v, min = 0, max = 1) =>
Math.min(max, Math.max(min, v));
const smooth = (v) => {
v = clamp(v);
return v * v * (3 - 2 * v);
};
let randomState = 912847;
function random() {
randomState =
(1664525 * randomState + 1013904223) >>> 0;
return randomState / 4294967296;
}
function randomBetween(min, max) {
return min + (max - min) * random();
}
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xf3f0e7, 16, 30);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 50);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const cameraState = {
azimuth: 0.74,
elevation: 0.55,
zoom: 1,
radius: 13
};
function updateCamera() {
const { azimuth, elevation, zoom, radius } = cameraState;
const horizontal = Math.cos(elevation) * radius;
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * horizontal,
cameraTarget.y + Math.sin(elevation) * radius,
cameraTarget.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.azimuth = 0.74;
cameraState.elevation = 0.55;
cameraState.zoom = 1;
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 0.8 ? 10.8 : 7.5;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemisphere = new THREE.HemisphereLight(
0xfff9e8,
0x7d8d73,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.1);
sun.position.set(-5.5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8ddff, 1.1);
fill.position.set(6, 4, -5);
scene.add(fill);
// ------------------------------------------------------------
// Ground and open-front voxel compost bin
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xe6e0d2,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.055;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x8e9486, 0xa6aa9e);
grid.position.y = -0.045;
grid.material.transparent = true;
grid.material.opacity = 0.16;
grid.material.depthWrite = false;
scene.add(grid);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addBox(size, position, color, castShadow = true) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.92
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size.x, size.y, size.z);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const woodLight = 0xa77b4c;
const woodMid = 0x8c643e;
const woodDark = 0x6f4b31;
// Back wall.
for (let i = 0; i < 3; i++) {
addBox(
new THREE.Vector3(6.95, 0.28, 0.18),
new THREE.Vector3(0, 0.35 + i * 0.43, -2.16),
i % 2 === 0 ? woodMid : woodLight
);
}
// Side walls.
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
addBox(
new THREE.Vector3(0.18, 0.28, 4.42),
new THREE.Vector3(side * 3.46, 0.35 + i * 0.43, 0),
i % 2 === 0 ? woodLight : woodMid
);
}
// Front and rear corner posts.
for (const z of [-2.16, 2.16]) {
addBox(
new THREE.Vector3(0.26, 1.72, 0.26),
new THREE.Vector3(side * 3.46, 0.79, z),
woodDark
);
}
}
// Rear corner posts.
for (const side of [-1, 1]) {
addBox(
new THREE.Vector3(0.26, 1.72, 0.26),
new THREE.Vector3(side * 3.46, 0.79, -2.16),
woodDark
);
}
// A low front rail leaves the compost cross-section exposed.
addBox(
new THREE.Vector3(6.95, 0.18, 0.16),
new THREE.Vector3(0, 0.18, 2.16),
woodDark
);
// Small dark fasteners retain the voxel-model appearance.
const fastenerMaterial = new THREE.MeshStandardMaterial({
color: 0x40352e,
roughness: 0.8
});
for (const side of [-1, 1]) {
for (const y of [0.35, 0.78, 1.21]) {
const fastener = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 0.065, 0.065),
fastenerMaterial
);
fastener.position.set(side * 3.46, y, 2.285);
scene.add(fastener);
}
}
// ------------------------------------------------------------
// Layered compost mound
// ------------------------------------------------------------
const moundColors = [
new THREE.Color(0x39271e),
new THREE.Color(0x4b3324),
new THREE.Color(0x60402a),
new THREE.Color(0x765137)
];
function moundHeightAt(x, z) {
const radius = Math.sqrt(
Math.pow(x / 3.35, 2) + Math.pow(z / 2.2, 2)
);
const noise =
Math.sin(x * 11.7 + z * 4.1) * 0.22 +
Math.cos(z * 15.3 - x * 6.2) * 0.17;
const height = Math.round(
4.45 * (1 - radius * 0.78) + 0.42 + noise
);
return clamp(height, 1, 4);
}
function surfaceYAt(x, z) {
return 0.34 + (moundHeightAt(x, z) - 1) * 0.38 + 0.23;
}
const moundInstances = [];
const nx = 13;
const nz = 9;
const step = 0.5;
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const x = (ix - (nx - 1) / 2) * step;
const z = (iz - (nz - 1) / 2) * step;
const height = moundHeightAt(x, z);
for (let layer = 0; layer < height; layer++) {
moundInstances.push({
x,
y: 0.34 + layer * 0.38,
z,
layer
});
}
}
}
const mound = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
}),
moundInstances.length
);
mound.castShadow = true;
mound.receiveShadow = true;
const dummy = new THREE.Object3D();
const instanceColor = new THREE.Color();
moundInstances.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.scale.set(0.465, 0.365, 0.465);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mound.setMatrixAt(index, dummy.matrix);
instanceColor.copy(moundColors[item.layer]);
instanceColor.offsetHSL(
randomBetween(-0.015, 0.015),
randomBetween(-0.025, 0.025),
randomBetween(-0.045, 0.045)
);
mound.setColorAt(index, instanceColor);
});
mound.instanceMatrix.needsUpdate = true;
mound.instanceColor.needsUpdate = true;
scene.add(mound);
// Loose dark voxels make the top layer read as fragmented matter.
const crumbCount = 72;
const crumbs = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
}),
crumbCount
);
for (let i = 0; i < crumbCount; i++) {
const angle = randomBetween(0, Math.PI * 2);
const radius = Math.sqrt(random()) * 0.9;
const x = Math.cos(angle) * radius * 3.0;
const z = Math.sin(angle) * radius * 1.8;
const size = randomBetween(0.075, 0.145);
dummy.position.set(
x,
surfaceYAt(x, z) + randomBetween(-0.02, 0.08),
z
);
dummy.scale.set(
size * randomBetween(0.8, 1.25),
size * randomBetween(0.65, 1.1),
size * randomBetween(0.8, 1.25)
);
dummy.rotation.set(
randomBetween(-0.12, 0.12),
randomBetween(-0.35, 0.35),
randomBetween(-0.12, 0.12)
);
dummy.updateMatrix();
crumbs.setMatrixAt(i, dummy.matrix);
instanceColor.set(
random() > 0.5 ? 0x4c3425 : 0x68462e
);
crumbs.setColorAt(i, instanceColor);
}
crumbs.instanceMatrix.needsUpdate = true;
crumbs.instanceColor.needsUpdate = true;
crumbs.castShadow = true;
crumbs.receiveShadow = true;
scene.add(crumbs);
// ------------------------------------------------------------
// Recognizable fresh scraps, built from small voxel blocks
// ------------------------------------------------------------
const scraps = [];
function createScrap({
center,
start,
voxels,
baseSize = 0.205
}) {
const group = new THREE.Group();
group.position.copy(center);
scene.add(group);
const records = [];
for (const voxel of voxels) {
const position = new THREE.Vector3(
voxel.x,
voxel.y,
voxel.z
);
const fresh = new THREE.Color(voxel.color);
const dark = new THREE.Color(
voxel.dark || 0x30231b
);
const material = new THREE.MeshStandardMaterial({
color: fresh,
roughness: 0.87
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.copy(position);
const size = voxel.size || baseSize;
mesh.scale.setScalar(size);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const angle = randomBetween(0, Math.PI * 2);
const spread = randomBetween(0.28, 0.78);
const dx = Math.cos(angle) * spread;
const dz = Math.sin(angle) * spread;
const targetWorldX = center.x + dx;
const targetWorldZ = center.z + dz;
const targetWorldY =
surfaceYAt(targetWorldX, targetWorldZ) +
randomBetween(0.025, 0.19);
const target = new THREE.Vector3(
dx,
targetWorldY - center.y,
dz
);
records.push({
mesh,
size,
fresh,
dark,
startPosition: position.clone(),
target,
delay: randomBetween(0, 0.12),
duration: randomBetween(0.49, 0.62),
spin: new THREE.Vector3(
randomBetween(-1.2, 1.2),
randomBetween(-1.7, 1.7),
randomBetween(-1.2, 1.2)
),
baseRotation: new THREE.Vector3(
randomBetween(-0.06, 0.06),
randomBetween(-0.08, 0.08),
randomBetween(-0.05, 0.05)
)
});
}
scraps.push({ group, start, voxels: records });
return group;
}
const apple = createScrap({
center: new THREE.Vector3(
-1.42,
surfaceYAt(-1.42, 0.42) + 0.025,
0.42
),
start: 0.08,
voxels: [
{ x: -0.22, y: 0, z: 0, color: 0xdb4e3d },
{ x: 0, y: 0, z: 0, color: 0xe15945 },
{ x: 0.22, y: 0, z: 0, color: 0xcf493a },
{ x: -0.22, y: 0.21, z: 0, color: 0xe45b48 },
{ x: 0, y: 0.21, z: 0, color: 0xdb4e3d },
{ x: 0.22, y: 0.21, z: 0, color: 0xe65d49 },
{ x: 0, y: 0.21, z: -0.21, color: 0xc94436 },
{ x: -0.11, y: 0.42, z: 0, color: 0xe55a47 },
{ x: 0.11, y: 0.42, z: 0, color: 0xd84d3d },
{ x: 0, y: 0.42, z: 0, color: 0xe75f4a },
{
x: 0,
y: 0.64,
z: 0,
color: 0x725039,
size: 0.12,
dark: 0x2d2118
},
{
x: 0.19,
y: 0.65,
z: 0,
color: 0x5c954d,
size: 0.17,
dark: 0x2e2819
}
]
});
const banana = createScrap({
center: new THREE.Vector3(
0.68,
surfaceYAt(0.68, 0.72) + 0.48,
0.72
),
start: 0.13,
baseSize: 0.185,
voxels: [
{ x: -0.52, y: 0.06, z: 0, color: 0xdeb83a },
{ x: -0.62, y: -0.08, z: 0, color: 0xe6c348 },
{ x: -0.60, y: -0.25, z: 0, color: 0xe0b93b },
{ x: -0.48, y: -0.39, z: 0, color: 0xd7aa30 },
{ x: -0.28, y: -0.48, z: 0, color: 0xe1bd3f },
{ x: 0, y: -0.50, z: 0, color: 0xe7c64c },
{ x: 0.28, y: -0.48, z: 0, color: 0xdfb638 },
{ x: 0.48, y: -0.39, z: 0, color: 0xe4bf42 },
{ x: 0.60, y: -0.25, z: 0, color: 0xd9ae31 },
{ x: 0.62, y: -0.08, z: 0, color: 0xe8c64a },
{ x: 0.52, y: 0.06, z: 0, color: 0xdeb83a },
{ x: -0.38, y: -0.28, z: 0.17, color: 0xf0d36a },
{ x: 0, y: -0.37, z: 0.17, color: 0xf2d876 },
{ x: 0.38, y: -0.28, z: 0.17, color: 0xedcf62 }
]
});
const greens = createScrap({
center: new THREE.Vector3(
1.72,
surfaceYAt(1.72, -0.62) + 0.025,
-0.62
),
start: 0.18,
baseSize: 0.175,
voxels: [
{ x: 0, y: 0, z: 0, color: 0x8cb55e },
{ x: 0, y: 0.18, z: 0, color: 0x78a953 },
{ x: 0, y: 0.36, z: 0, color: 0x679947 },
{ x: -0.18, y: 0.08, z: 0, color: 0x4f8d46 },
{ x: -0.35, y: 0.17, z: 0, color: 0x5d994d },
{ x: -0.51, y: 0.28, z: 0, color: 0x43823e },
{ x: -0.30, y: 0.30, z: 0, color: 0x5b964a },
{ x: -0.14, y: 0.22, z: 0, color: 0x4b8a43 },
{ x: 0.18, y: 0.10, z: 0, color: 0x579849 },
{ x: 0.35, y: 0.19, z: 0, color: 0x69a151 },
{ x: 0.51, y: 0.30, z: 0, color: 0x4a893f },
{ x: 0.30, y: 0.32, z: 0, color: 0x72a95a },
{ x: 0.14, y: 0.23, z: 0, color: 0x5a9949 },
{ x: -0.10, y: 0.08, z: -0.18, color: 0x3e773a },
{ x: 0.12, y: 0.13, z: -0.18, color: 0x4b8941 }
]
});
const bread = createScrap({
center: new THREE.Vector3(
-0.46,
surfaceYAt(-0.46, -0.72) + 0.02,
-0.72
),
start: 0.23,
baseSize: 0.215,
voxels: [
{ x: -0.30, y: 0, z: -0.20, color: 0x9f6238 },
{ x: 0, y: 0, z: -0.20, color: 0xb87843 },
{ x: 0.30, y: 0, z: -0.20, color: 0x995a33 },
{ x: -0.30, y: 0, z: 0, color: 0xb47440 },
{ x: 0, y: 0, z: 0, color: 0xc88a4f },
{ x: 0.30, y: 0, z: 0, color: 0xb97844 },
{ x: -0.30, y: 0.21, z: -0.20, color: 0xb06d3b },
{ x: 0, y: 0.21, z: -0.20, color: 0xc27b43 },
{ x: 0.30, y: 0.21, z: -0.20, color: 0xa96337 },
{ x: -0.30, y: 0.21, z: 0, color: 0xc58249 },
{ x: 0, y: 0.21, z: 0, color: 0xce9054 },
{ x: 0.30, y: 0.21, z: 0, color: 0xba7742 },
{ x: -0.15, y: 0.42, z: -0.10, color: 0xcb884b },
{ x: 0.15, y: 0.42, z: -0.10, color: 0xc27a42 },
{ x: 0, y: 0.42, z: 0.10, color: 0xd09355 }
]
});
const workingColor = new THREE.Color();
function updateScraps(progress) {
for (const scrap of scraps) {
for (const voxel of scrap.voxels) {
const localProgress = clamp(
(progress - scrap.start - voxel.delay) / voxel.duration
);
const eased = smooth(localProgress);
const scale = voxel.size * (1 - eased * 0.70);
voxel.mesh.scale.setScalar(scale);
voxel.mesh.position.lerpVectors(
voxel.startPosition,
voxel.target,
eased
);
// A small arc makes the settling motion readable.
voxel.mesh.position.y +=
Math.sin(eased * Math.PI) * (0.14 + voxel.delay * 0.45);
voxel.mesh.rotation.set(
voxel.baseRotation.x + voxel.spin.x * eased * 0.55,
voxel.baseRotation.y + voxel.spin.y * eased * 0.55,
voxel.baseRotation.z + voxel.spin.z * eased * 0.55
);
workingColor
.copy(voxel.fresh)
.lerp(voxel.dark, smooth((eased - 0.08) / 0.84));
voxel.mesh.material.color.copy(workingColor);
}
}
}
// ------------------------------------------------------------
// Independent symbolic decomposer layer
//
// Deliberately separate from the changing material:
// this layer uses elapsed wall time and never reads timeline progress.
// ------------------------------------------------------------
const decompLayer = new THREE.Group();
scene.add(decompLayer);
const purpleMaterial = new THREE.MeshStandardMaterial({
color: 0x8065c4,
emissive: 0x3c286f,
emissiveIntensity: 0.38,
roughness: 0.55
});
const tealMaterial = new THREE.MeshStandardMaterial({
color: 0x3fae9d,
emissive: 0x174e49,
emissiveIntensity: 0.34,
roughness: 0.55
});
const paleSignalMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e2f2,
roughness: 0.5
});
function addSignalCube(group, position, size, material) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.copy(position);
mesh.scale.set(size, size, size);
mesh.castShadow = true;
group.add(mesh);
return mesh;
}
const decomposerSymbols = [];
for (let i = 0; i < 10; i++) {
const symbol = new THREE.Group();
const isWorm = i % 3 === 0;
const material = isWorm ? tealMaterial : purpleMaterial;
if (isWorm) {
// A segmented, abstract worm signal.
for (let segment = 0; segment < 4; segment++) {
addSignalCube(
symbol,
new THREE.Vector3(
(segment - 1.5) * 0.14,
Math.sin(segment * 1.3) * 0.025,
0
),
segment === 1 || segment === 2 ? 0.13 : 0.105,
material
);
}
} else {
// A clustered microbial signal.
addSignalCube(symbol, new THREE.Vector3(0, 0, 0), 0.15, material);
addSignalCube(symbol, new THREE.Vector3(0.13, 0.03, 0), 0.095, material);
addSignalCube(symbol, new THREE.Vector3(-0.11, -0.03, 0.02), 0.085, material);
addSignalCube(symbol, new THREE.Vector3(0.01, 0.13, 0.03), 0.065, paleSignalMaterial);
}
decompLayer.add(symbol);
decomposerSymbols.push({
group: symbol,
angle: (i / 10) * Math.PI * 2,
speed: randomBetween(0.075, 0.13) * (i % 2 ? 1 : -1),
phase: randomBetween(0, Math.PI * 2),
radiusX: randomBetween(3.72, 4.03),
radiusZ: randomBetween(2.88, 3.18),
worm: isWorm
});
}
const ringPoints = [];
for (let i = 0; i <= 128; i++) {
const angle = (i / 128) * Math.PI * 2;
ringPoints.push(
new THREE.Vector3(
Math.cos(angle) * 3.86,
0.22,
Math.sin(angle) * 3.02
)
);
}
const ringGeometry = new THREE.BufferGeometry().setFromPoints(
ringPoints
);
const ring = new THREE.Line(
ringGeometry,
new THREE.LineDashedMaterial({
color: 0x8065c4,
dashSize: 0.13,
gapSize: 0.11,
transparent: true,
opacity: 0.36
})
);
ring.computeLineDistances();
decompLayer.add(ring);
function updateDecomposers(elapsed) {
for (const symbol of decomposerSymbols) {
const angle =
symbol.angle + elapsed * symbol.speed;
const pulse =
1 + Math.sin(elapsed * 2.1 + symbol.phase) * 0.11;
symbol.group.position.set(
Math.cos(angle) * symbol.radiusX,
0.92 +
Math.sin(elapsed * 1.45 + symbol.phase) * 0.16,
Math.sin(angle) * symbol.radiusZ
);
symbol.group.rotation.y =
symbol.worm
? -angle + Math.PI / 2
: elapsed * 0.32 + symbol.phase;
symbol.group.rotation.z =
Math.sin(elapsed * 1.7 + symbol.phase) * 0.12;
symbol.group.scale.setScalar(pulse);
}
}
decompToggle.addEventListener("change", () => {
decompLayer.visible = decompToggle.checked;
});
// ------------------------------------------------------------
// Direct camera controls — no addons
// ------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = clamp(
cameraState.elevation + dy * 0.0045,
0.22,
1.12
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Timeline, playback, and interface state
// ------------------------------------------------------------
let progress = 0;
let playing = true;
let previousTime = performance.now();
playButton.addEventListener("click", () => {
if (progress >= 0.999) {
progress = 0;
playing = true;
} else {
playing = !playing;
}
});
resetButton.addEventListener("click", () => {
progress = 0;
playing = true;
});
timeline.addEventListener("input", () => {
progress = Number(timeline.value) / 1000;
playing = false;
});
const phaseData = [
{
title: "Recognizable scraps",
text: "Bright food voxels remain distinct above the layered compost bed.",
state: "intact"
},
{
title: "Fragmentation begins",
text: "Fresh scraps separate, contract, and spread into smaller voxel pieces.",
state: "splitting"
},
{
title: "Active decomposition",
text: "Material darkens while fragments move downward into the active bed.",
state: "darkening"
},
{
title: "Soil-like endpoint",
text: "Small dark fragments settle into a more uniform organic layer.",
state: "settled"
}
];
function getPhaseIndex(p) {
if (p < 0.16) return 0;
if (p < 0.44) return 1;
if (p < 0.81) return 2;
return 3;
}
function updateInterface(p) {
const phaseIndex = getPhaseIndex(p);
const phase = phaseData[phaseIndex];
timeline.value = Math.round(p * 1000);
timeline.style.setProperty("--p", `${p * 100}%`);
timeReadout.textContent = `${(p * DURATION)
.toFixed(1)
.padStart(4, "0")} / ${DURATION.toFixed(1)} s`;
if (phaseTitle.textContent !== phase.title) {
phaseTitle.textContent = phase.title;
phaseText.textContent = phase.text;
}
const playLabel = playing
? "Pause"
: p >= 0.999
? "Replay"
: "Play";
if (playButton.textContent !== playLabel) {
playButton.textContent = playLabel;
}
stageElements.forEach((element, index) => {
element.classList.toggle("active", index === phaseIndex);
element.classList.toggle("done", index < phaseIndex);
});
inventoryStates.forEach((element) => {
element.textContent = phase.state;
});
}
// ------------------------------------------------------------
// Screen-space annotation projection
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, opacity) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
opacity > 0.01;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.setProperty("--label-opacity", visible ? opacity : 0);
}
const freshAnchor = new THREE.Vector3(
apple.position.x - 0.1,
apple.position.y + 0.82,
apple.position.z
);
const fragmentAnchor = new THREE.Vector3(0.85, 1.48, 0.62);
const decompAnchor = new THREE.Vector3(3.82, 1.76, 0.05);
function updateAnnotations(p) {
const freshOpacity = 1 - smooth((p - 0.12) / 0.28);
const fragmentOpacity = smooth((p - 0.24) / 0.34);
placeLabel(labelFresh, freshAnchor, freshOpacity);
placeLabel(labelFragments, fragmentAnchor, fragmentOpacity);
placeLabel(
labelDecomp,
decompAnchor,
decompToggle.checked ? 0.95 : 0
);
}
// ------------------------------------------------------------
// Main loop
// ------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
progress += dt / DURATION;
if (progress >= 1) {
progress = 1;
playing = false;
}
}
updateScraps(progress);
// Wall-clock driven, independent of the material timeline.
updateDecomposers(now / 1000);
updateInterface(progress);
updateAnnotations(progress);
renderer.render(scene, camera);
}
updateScraps(0);
updateDecomposers(0);
updateInterface(0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```