Prompt specification
Build or customize the Three.js 3D scene "Food-processing material-flow puzzle" 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: Food-processing material-flow puzzle
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/food-processing-material-flow-puzzle-x1056
Scene Description Prompt:
In one HTML file using Three.js from cdnjs, route products and byproducts through a low-poly fictional dairy with stated ratios and conserved material tokens.
Working Three.js Starter (food-processing-material-flow-puzzle-x1056):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mooflow Dairy — Material Balance</title>
<style>
:root {
--ink: #17342f;
--muted: #62746f;
--paper: #f7f2e7;
--panel: rgba(255, 252, 244, 0.92);
--line: rgba(23, 52, 47, 0.14);
--cream: #e9b84f;
--yogurt: #d96b83;
--cheese: #e7834f;
--whey: #8775c5;
--compost: #8d6648;
--green: #287966;
--shadow: 0 18px 50px rgba(33, 60, 52, 0.15);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe6dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.topbar {
position: fixed;
top: 22px;
left: 26px;
right: 26px;
z-index: 10;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 47px;
height: 47px;
border-radius: 15px;
background: var(--ink);
color: var(--paper);
display: grid;
place-items: center;
font-size: 23px;
box-shadow: var(--shadow);
transform: rotate(-4deg);
}
.eyebrow {
margin: 0 0 3px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.4vw, 35px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin-top: 7px;
color: var(--muted);
font-size: 12px;
}
.actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.action {
border: 1px solid rgba(23, 52, 47, 0.14);
background: rgba(255, 252, 244, 0.88);
color: var(--ink);
border-radius: 999px;
padding: 10px 14px;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 24px rgba(33, 60, 52, 0.09);
backdrop-filter: blur(12px);
transition: transform 150ms ease, background 150ms ease;
}
.action:hover {
transform: translateY(-1px);
background: #fffdf7;
}
.action.primary {
background: var(--ink);
color: white;
}
.ledger {
position: fixed;
z-index: 10;
top: 100px;
right: 26px;
width: min(340px, calc(100vw - 40px));
max-height: calc(100vh - 126px);
overflow: auto;
padding: 19px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 24px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
}
.ledger-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-bottom: 14px;
}
.ledger h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.025em;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--green);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #48a46d;
box-shadow: 0 0 0 4px rgba(72, 164, 109, 0.13);
}
.balance-hero {
padding: 15px;
border-radius: 17px;
background: var(--ink);
color: white;
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: end;
}
.balance-hero .big {
font-size: 31px;
line-height: 1;
font-weight: 850;
letter-spacing: -0.055em;
}
.balance-hero .unit {
margin-top: 4px;
color: #bfd0ca;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.conserved {
color: #cbe9d9;
font-size: 10px;
font-weight: 850;
text-align: right;
line-height: 1.4;
}
.section-title {
margin: 18px 0 8px;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--muted);
}
.subtotal {
width: 100%;
border: 0;
border-radius: 12px;
padding: 10px 11px;
background: transparent;
color: var(--ink);
cursor: pointer;
text-align: left;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
font-weight: 800;
}
.subtotal:hover, .subtotal.active {
background: rgba(40, 121, 102, 0.09);
}
.subtotal span:last-child { color: var(--muted); }
.output-list {
display: grid;
gap: 7px;
}
.output-row {
position: relative;
width: 100%;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
padding: 10px 11px;
cursor: pointer;
text-align: left;
transition: opacity 180ms ease, transform 150ms ease, border-color 150ms ease;
}
.output-row::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: var(--ratio);
background: var(--tint);
opacity: 0.48;
transition: opacity 150ms ease;
}
.output-row:hover {
transform: translateX(2px);
border-color: rgba(23, 52, 47, 0.3);
}
.output-row.active {
border-color: var(--accent);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}
.output-row.muted { opacity: 0.36; }
.output-row > span {
position: relative;
z-index: 1;
}
.row-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
font-size: 12px;
font-weight: 850;
}
.row-bottom {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.dot {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 50%;
background: var(--accent);
}
.ratio-pill {
border-radius: 999px;
padding: 3px 7px;
background: rgba(255, 255, 255, 0.74);
font-size: 10px;
}
.math {
margin-top: 15px;
padding: 12px;
border-radius: 14px;
border: 1px dashed rgba(23, 52, 47, 0.22);
background: rgba(255, 255, 255, 0.45);
color: var(--muted);
font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.math strong { color: var(--ink); }
.token-note {
margin-top: 12px;
display: flex;
gap: 9px;
align-items: center;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.token-cube {
flex: 0 0 auto;
width: 18px;
height: 18px;
border-radius: 4px;
background: #45a386;
box-shadow: inset -4px -4px rgba(0, 0, 0, 0.1);
transform: rotate(8deg);
}
#label-layer {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
min-width: 106px;
max-width: 170px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-left: 4px solid var(--accent, var(--green));
border-radius: 9px;
background: rgba(255, 252, 244, 0.9);
box-shadow: 0 7px 18px rgba(30, 54, 48, 0.12);
color: var(--ink);
pointer-events: auto;
cursor: pointer;
will-change: transform;
transition: opacity 180ms ease;
}
.scene-label strong {
display: block;
font-size: 10px;
letter-spacing: -0.01em;
}
.scene-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
line-height: 1.25;
}
.scene-label.muted { opacity: 0.22; }
.scene-label.hidden { display: none; }
.bottom-left {
position: fixed;
left: 26px;
bottom: 24px;
z-index: 8;
width: min(430px, calc(100vw - 40px));
pointer-events: none;
}
.filter-wrap {
display: inline-flex;
gap: 5px;
padding: 5px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 999px;
background: rgba(255, 252, 244, 0.87);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.filter-wrap button {
border: 0;
border-radius: 999px;
background: transparent;
color: var(--muted);
padding: 7px 10px;
font-size: 10px;
font-weight: 850;
cursor: pointer;
}
.filter-wrap button.active {
background: var(--ink);
color: white;
}
.filter-status {
margin-top: 8px;
color: var(--ink);
font-size: 10px;
font-weight: 750;
text-shadow: 0 1px 2px rgba(255,255,255,.8);
}
.camera-hint {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.bottom-center {
position: fixed;
z-index: 8;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 11px 15px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 15px;
background: rgba(255, 252, 244, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
text-align: center;
pointer-events: none;
}
.bottom-center .formula {
font-size: 11px;
font-weight: 850;
letter-spacing: -0.01em;
}
.bottom-center .formula em {
color: var(--green);
font-style: normal;
}
.bottom-center small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.grain {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
opacity: 0.11;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.3'/%3E%3C/svg%3E");
}
@media (max-width: 900px) {
.ledger {
top: auto;
bottom: 18px;
right: 18px;
width: 295px;
max-height: 43vh;
}
.bottom-left { bottom: 18px; left: 18px; }
.bottom-center { display: none; }
.subtitle { display: none; }
}
@media (max-width: 620px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand-mark { width: 40px; height: 40px; }
h1 { font-size: 20px; }
.eyebrow { font-size: 8px; }
.actions { gap: 4px; }
.action { padding: 8px 9px; font-size: 10px; }
.ledger {
right: 10px;
bottom: 10px;
width: 250px;
max-height: 38vh;
padding: 14px;
}
.bottom-left { left: 10px; bottom: 10px; max-width: calc(100vw - 280px); }
.filter-wrap button { padding: 6px 7px; font-size: 9px; }
.camera-hint { display: none; }
.scene-label { min-width: 84px; padding: 5px 7px; }
.scene-label strong { font-size: 8px; }
.scene-label small { font-size: 7px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly dairy material-flow scene"></canvas>
<div class="grain"></div>
<div id="label-layer"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">◒</div>
<div>
<p class="eyebrow">Mooflow fictional dairy · Plant 07</p>
<h1>The Great Balance</h1>
<div class="subtitle">Every drop has a destination · milk-equivalent material tokens</div>
</div>
</div>
<div class="actions">
<button class="action primary" id="flow-button" aria-pressed="true">Pause flow</button>
<button class="action" id="label-button" aria-pressed="true">Hide labels</button>
<button class="action" id="reset-button">Reset view</button>
</div>
</header>
<aside class="ledger" aria-label="Material balance ledger">
<div class="ledger-header">
<h2>Material ledger</h2>
<span class="live">Balanced</span>
</div>
<div class="balance-hero">
<div>
<div class="big">1,000 L-eq</div>
<div class="unit">Raw milk input</div>
</div>
<div class="conserved">1000 IN<br />1000 OUT</div>
</div>
<div class="section-title">
<span>Output categories</span>
<span>Share</span>
</div>
<button class="subtotal" data-filter="product">
<span>● Products</span>
<span>780 L-eq · 78%</span>
</button>
<button class="subtotal" data-filter="byproduct">
<span>● Byproducts</span>
<span>220 L-eq · 22%</span>
</button>
<div class="section-title">
<span>Final destinations</span>
<span>1 cube = 10 L-eq</span>
</div>
<div class="output-list">
<button
class="output-row"
data-filter="cream"
style="--accent:#e9b84f;--tint:#e9b84f;--ratio:18%"
>
<span class="row-top">
<span><i class="dot"></i>Golden cream</span>
<span class="ratio-pill">18%</span>
</span>
<span class="row-bottom">
<span>180 L-eq · 18 tokens</span>
<span>Product</span>
</span>
</button>
<button
class="output-row"
data-filter="yogurt"
style="--accent:#d96b83;--tint:#d96b83;--ratio:24%"
>
<span class="row-top">
<span><i class="dot"></i>Cloud yogurt</span>
<span class="ratio-pill">24%</span>
</span>
<span class="row-bottom">
<span>240 L-eq · 24 tokens</span>
<span>Product</span>
</span>
</button>
<button
class="output-row"
data-filter="cheese"
style="--accent:#e7834f;--tint:#e7834f;--ratio:36%"
>
<span class="row-top">
<span><i class="dot"></i>Amber cheese</span>
<span class="ratio-pill">36%</span>
</span>
<span class="row-bottom">
<span>360 L-eq · 36 tokens</span>
<span>Product</span>
</span>
</button>
<button
class="output-row"
data-filter="whey"
style="--accent:#8775c5;--tint:#8775c5;--ratio:14%"
>
<span class="row-top">
<span><i class="dot"></i>Lilac whey</span>
<span class="ratio-pill">14%</span>
</span>
<span class="row-bottom">
<span>140 L-eq · 14 tokens</span>
<span>Byproduct</span>
</span>
</button>
<button
class="output-row"
data-filter="compost"
style="--accent:#8d6648;--tint:#8d6648;--ratio:8%"
>
<span class="row-top">
<span><i class="dot"></i>Moogrow compost</span>
<span class="ratio-pill">8%</span>
</span>
<span class="row-bottom">
<span>80 L-eq · 8 tokens</span>
<span>Byproduct</span>
</span>
</button>
</div>
<div class="math">
<strong>1000</strong> feed<br />
→ <strong>920</strong> processing + <strong>80</strong> compost<br />
→ 180 cream + 240 yogurt + 500 cheese milk<br />
→ 500 = <strong>360</strong> cheese + <strong>140</strong> whey<br />
<strong>= 780 product + 220 byproduct</strong>
</div>
<div class="token-note">
<span class="token-cube"></span>
<span>
All routes use milk-equivalent units, so solids and liquids remain comparable.
No token is created or discarded.
</span>
</div>
</aside>
<div class="bottom-left">
<div class="filter-wrap" aria-label="Route filters">
<button class="active" data-filter="all">All routes</button>
<button data-filter="product">Products</button>
<button data-filter="byproduct">Byproducts</button>
</div>
<div class="filter-status" id="filter-status" aria-live="polite">
All 5 routes · 100 tokens conserved
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom · select a destination to isolate it</div>
</div>
<div class="bottom-center">
<div class="formula">
920 process milk + 80 compost = 1,000 L-eq
→ <em>780 product + 220 byproduct = 1,000</em>
</div>
<small>Fictional milk-equivalent conservation model</small>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, camera and scene
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe6dc);
scene.fog = new THREE.Fog(0xdbe6dc, 25, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(-0.1, 0.8, 0.8),
theta: -0.66,
phi: 1.02,
radius: 19.5,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf8f2df, 0x668377, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d5, 3.4);
sun.position.set(-7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fc6d1, 1.1);
fill.position.set(10, 7, -12);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
flatShading: true,
...options
});
}
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(36, 26),
material(0xcbd9cc)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.02;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x8ea99c, 0xa8bbae);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.19;
scene.add(grid);
// Low-poly landscape silhouettes.
const hillMaterial = material(0xb7cdb7);
[
[-14, 1.5, -12, 5.8],
[-7, 1.1, -14, 4.1],
[9, 1.3, -14, 5.2],
[15, 0.9, -8, 4.3]
].forEach(([x, y, z, radius]) => {
const hill = new THREE.Mesh(
new THREE.ConeGeometry(radius, 4.5, 7),
hillMaterial
);
hill.position.set(x, y, z);
hill.rotation.y = x * 0.3;
hill.receiveShadow = true;
scene.add(hill);
});
// ---------------------------------------------------------------------
// Equipment helpers
// ---------------------------------------------------------------------
const pickables = [];
function shadowMesh(mesh, cast = true, receive = true) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function makeTank(x, z, radius, height, color, filter, accent = 0xf1ead7) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const body = shadowMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.04, height, 8),
material(color)
)
);
body.position.y = 0.32 + height / 2;
group.add(body);
const roof = shadowMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0.035, radius * 1.05, 0.66, 8),
material(accent)
)
);
roof.position.y = 0.32 + height + 0.32;
group.add(roof);
for (const y of [0.72, height + 0.05]) {
const band = shadowMesh(
new THREE.Mesh(
new THREE.TorusGeometry(radius * 1.018, 0.045, 4, 8),
material(0x49675e)
)
);
band.rotation.x = Math.PI / 2;
band.position.y = y;
group.add(band);
}
const legMaterial = material(0x52675e);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const leg = shadowMesh(
new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.5, 0.15),
legMaterial
)
);
leg.position.set(
sx * radius * 0.62,
0.22,
sz * radius * 0.62
);
group.add(leg);
}
}
scene.add(group);
group.traverse((object) => {
if (object.isMesh) {
object.userData.filter = filter;
pickables.push(object);
}
});
return group;
}
function makeHall(x, z, color, filter) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const base = shadowMesh(
new THREE.Mesh(
new THREE.BoxGeometry(2.05, 1.45, 1.65),
material(color)
)
);
base.position.y = 0.78;
group.add(base);
const roof = shadowMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0, 1.62, 0.95, 4),
material(0xf1ead7)
)
);
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.82;
roof.position.y = 1.92;
group.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.93, 0.06),
material(0x38574e)
);
door.position.set(0, 0.49, 0.86);
group.add(door);
for (const xOffset of [-0.63, 0.63]) {
const window = new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.28, 0.055),
material(0xbfe2dd, { emissive: 0x294e48, emissiveIntensity: 0.15 })
);
window.position.set(xOffset, 1.05, 0.86);
group.add(window);
}
const stack = shadowMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.2, 0.9, 7),
material(0x8b6d5a)
)
);
stack.position.set(-0.65, 2.15, -0.3);
group.add(stack);
scene.add(group);
group.traverse((object) => {
if (object.isMesh) {
object.userData.filter = filter;
pickables.push(object);
}
});
return group;
}
function makeCompostBay(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const base = shadowMesh(
new THREE.Mesh(
new THREE.BoxGeometry(2.15, 0.38, 1.65),
material(0x8d6648)
)
);
base.position.y = 0.19;
group.add(base);
const pileMaterial = material(0x765137);
[
[-0.55, 0.65, -0.2, 0.55],
[0.4, 0.58, 0.25, 0.46],
[0.15, 0.78, -0.35, 0.39]
].forEach(([px, py, pz, scale]) => {
const pile = shadowMesh(
new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
pileMaterial
)
);
pile.position.set(px, py, pz);
pile.scale.y = 0.72;
group.add(pile);
});
const postMaterial = material(0x52675e);
for (const px of [-0.95, 0.95]) {
const post = shadowMesh(
new THREE.Mesh(
new THREE.BoxGeometry(0.12, 1.5, 0.12),
postMaterial
)
);
post.position.set(px, 0.75, -0.65);
group.add(post);
}
scene.add(group);
group.traverse((object) => {
if (object.isMesh) {
object.userData.filter = "compost";
pickables.push(object);
}
});
}
makeTank(-7, 0, 1.05, 2.7, 0xece5d2, "all", 0x2d7665);
makeHall(-4.6, 0, 0xf0dfbb, "all");
makeHall(-1.1, 0, 0xdce5d5, "product");
makeTank(1.1, 2.5, 0.82, 1.25, 0xe6c777, "cheese", 0xe7834f);
makeTank(4.2, -3.4, 0.92, 1.85, 0xe9b84f, "cream", 0xf7ebc6);
makeTank(4.6, -1.3, 0.78, 1.25, 0xd96b83, "yogurt", 0xf5d2da);
makeTank(4.8, 2.6, 1.0, 2.35, 0xe7834f, "cheese", 0xf4c295);
makeTank(2.5, 5.0, 0.72, 1.05, 0x8775c5, "whey", 0xc5b9e8);
makeCompostBay(4.2, 5.0);
// A small low-poly dairy cow.
function makeCow() {
const cow = new THREE.Group();
cow.position.set(-7.3, 0, 2.55);
cow.rotation.y = -0.4;
const white = material(0xf4efe0);
const black = material(0x263a35);
const pink = material(0xe9aaa0);
const body = shadowMesh(
new THREE.Mesh(new THREE.BoxGeometry(1.45, 0.72, 0.66), white)
);
body.position.y = 0.92;
cow.add(body);
const head = shadowMesh(
new THREE.Mesh(new THREE.BoxGeometry(0.56, 0.56, 0.48), white)
);
head.position.set(0.91, 1.05, 0);
cow.add(head);
const snout = shadowMesh(
new THREE.Mesh(new THREE.BoxGeometry(0.25, 0.22, 0.5), pink)
);
snout.position.set(1.24, 0.92, 0);
cow.add(snout);
for (const sx of [-0.48, 0.48]) {
for (const sz of [-0.23, 0.23]) {
const leg = shadowMesh(
new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.62, 0.16), black)
);
leg.position.set(sx, 0.31, sz);
cow.add(leg);
}
}
for (const sz of [-0.34, 0.34]) {
const spot = shadowMesh(
new THREE.Mesh(new THREE.BoxGeometry(0.54, 0.34, 0.035), black)
);
spot.position.set(-0.2, 1.01, sz);
cow.add(spot);
}
const hornMaterial = material(0xd9c99f);
for (const sz of [-0.17, 0.17]) {
const horn = shadowMesh(
new THREE.Mesh(new THREE.ConeGeometry(0.07, 0.28, 5), hornMaterial)
);
horn.position.set(0.94, 1.46, sz);
horn.rotation.z = -0.15;
cow.add(horn);
}
scene.add(cow);
}
makeCow();
// Tiny low-poly trees.
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
const trunk = shadowMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.18, 1.2, 6),
material(0x866448)
)
);
trunk.position.y = 0.6;
tree.add(trunk);
const crown = shadowMesh(
new THREE.Mesh(
new THREE.ConeGeometry(0.78, 2, 7),
material(0x4f8064)
)
);
crown.position.y = 1.75;
tree.add(crown);
scene.add(tree);
}
[
[-11, 4.8, 1.1],
[-4, 6.0, 0.9],
[7.2, 6.2, 1.0],
[10, -6.7, 0.85],
[-10, -5.6, 0.75]
].forEach((args) => makeTree(...args));
// ---------------------------------------------------------------------
// Pipe routes
// ---------------------------------------------------------------------
const sourceIntakePoints = [
[-7, 1.35, 0],
[-6.25, 1.35, 0],
[-4.6, 1.35, 0]
];
const intakeProcessPoints = [
[-4.6, 1.35, 0],
[-3.25, 1.35, 0],
[-1.1, 1.35, 0]
];
const processCreamPoints = [
[-1.1, 1.35, 0],
[-0.9, 1.35, -3.4],
[1.1, 1.35, -3.4],
[4.2, 1.35, -3.4]
];
const processYogurtPoints = [
[-1.1, 1.35, 0],
[0.6, 1.35, -1.3],
[2.6, 1.35, -1.3],
[4.6, 1.35, -1.3]
];
const processCheesePoints = [
[-1.1, 1.35, 0],
[-0.7, 1.35, 2.5],
[1.1, 1.35, 2.5]
];
const cheeseOutputPoints = [
[1.1, 1.35, 2.5],
[2.4, 1.35, 2.5],
[4.8, 1.35, 2.6]
];
const wheyOutputPoints = [
[1.1, 1.35, 2.5],
[1.45, 0.95, 4.25],
[2.5, 0.95, 5]
];
const compostOutputPoints = [
[-4.6, 1.35, 0],
[-4.35, 0.95, 2.65],
[-2.2, 0.7, 5],
[1.8, 0.7, 5],
[4.2, 0.7, 5]
];
const routeDefinitions = [
{
id: "source-intake",
points: sourceIntakePoints,
color: 0x356d61,
cats: ["cream", "yogurt", "cheese", "whey", "compost"]
},
{
id: "intake-process",
points: intakeProcessPoints,
color: 0x3d7d6e,
cats: ["cream", "yogurt", "cheese", "whey"]
},
{
id: "process-cream",
points: processCreamPoints,
color: 0xe9b84f,
cats: ["cream"]
},
{
id: "process-yogurt",
points: processYogurtPoints,
color: 0xd96b83,
cats: ["yogurt"]
},
{
id: "process-cheese",
points: processCheesePoints,
color: 0xd98a4d,
cats: ["cheese", "whey"]
},
{
id: "cheese-output",
points: cheeseOutputPoints,
color: 0xe7834f,
cats: ["cheese"]
},
{
id: "whey-output",
points: wheyOutputPoints,
color: 0x8775c5,
cats: ["whey"]
},
{
id: "compost-output",
points: compostOutputPoints,
color: 0x8d6648,
cats: ["compost"]
}
];
function curveFromPoints(points) {
return new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.12
);
}
const routes = routeDefinitions.map((definition) => {
const curve = curveFromPoints(definition.points);
const pipe = shadowMesh(
new THREE.Mesh(
new THREE.TubeGeometry(curve, 42, 0.085, 6, false),
material(definition.color, {
transparent: true,
opacity: 0.9,
roughness: 0.55
})
),
false,
true
);
scene.add(pipe);
return {
...definition,
curve,
pipe,
material: pipe.material
};
});
// Small faceted junction housings.
[
[-4.6, 1.35, 0, 0xf0dfbb],
[-1.1, 1.35, 0, 0xdce5d5],
[1.1, 1.35, 2.5, 0xe6c777]
].forEach(([x, y, z, color]) => {
const junction = shadowMesh(
new THREE.Mesh(
new THREE.IcosahedronGeometry(0.27, 0),
material(color)
)
);
junction.position.set(x, y, z);
scene.add(junction);
});
// ---------------------------------------------------------------------
// Exactly 100 conserved material tokens
// ---------------------------------------------------------------------
function combinePoints(...sections) {
const result = [];
sections.forEach((section, sectionIndex) => {
section.forEach((point, pointIndex) => {
if (sectionIndex === 0 || pointIndex > 0) {
result.push(point);
}
});
});
return result;
}
const tokenDefinitions = [
{
name: "cream",
count: 18,
color: 0xf5ca57,
points: combinePoints(
sourceIntakePoints,
intakeProcessPoints,
processCreamPoints
)
},
{
name: "yogurt",
count: 24,
color: 0xe8899c,
points: combinePoints(
sourceIntakePoints,
intakeProcessPoints,
processYogurtPoints
)
},
{
name: "cheese",
count: 36,
color: 0xf29a63,
points: combinePoints(
sourceIntakePoints,
intakeProcessPoints,
processCheesePoints,
cheeseOutputPoints
)
},
{
name: "whey",
count: 14,
color: 0xa592dc,
points: combinePoints(
sourceIntakePoints,
intakeProcessPoints,
processCheesePoints,
wheyOutputPoints
)
},
{
name: "compost",
count: 8,
color: 0xa87a55,
points: combinePoints(
sourceIntakePoints,
compostOutputPoints
)
}
];
const tokenGeometry = new THREE.BoxGeometry(0.19, 0.19, 0.19);
const dummy = new THREE.Object3D();
const tokenGroups = tokenDefinitions.map((definition) => {
const tokenMaterial = material(definition.color, {
emissive: definition.color,
emissiveIntensity: 0.12,
transparent: true,
opacity: 1
});
const mesh = new THREE.InstancedMesh(
tokenGeometry,
tokenMaterial,
definition.count
);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
scene.add(mesh);
return {
...definition,
mesh,
material: tokenMaterial,
curve: curveFromPoints(definition.points)
};
});
// ---------------------------------------------------------------------
// HTML labels projected directly from Three.js coordinates
// ---------------------------------------------------------------------
const labelLayer = document.querySelector("#label-layer");
const labels = [
{
title: "Raw milk silo",
detail: "1,000 L-eq · 100 tokens",
position: new THREE.Vector3(-7, 3.9, 0),
cats: ["cream", "yogurt", "cheese", "whey", "compost"],
color: "#287966"
},
{
title: "Intake gate",
detail: "920 process · 80 compost",
position: new THREE.Vector3(-4.6, 2.3, 0),
cats: ["cream", "yogurt", "cheese", "whey", "compost"],
color: "#287966"
},
{
title: "Creamery router",
detail: "180 cream · 240 yogurt · 500 cheese milk",
position: new THREE.Vector3(-1.1, 2.85, 0),
cats: ["cream", "yogurt", "cheese"],
color: "#e7834f"
},
{
title: "Cheese splitter",
detail: "360 cheese · 140 whey",
position: new THREE.Vector3(1.1, 2.72, 2.5),
cats: ["cheese", "whey"],
color: "#8775c5"
},
{
title: "Golden cream",
detail: "180 L-eq · 18% · product",
position: new THREE.Vector3(4.2, 2.95, -3.4),
cats: ["cream"],
color: "#e9b84f"
},
{
title: "Cloud yogurt",
detail: "240 L-eq · 24% · product",
position: new THREE.Vector3(4.6, 2.28, -1.3),
cats: ["yogurt"],
color: "#d96b83"
},
{
title: "Amber cheese",
detail: "360 L-eq · 36% · product",
position: new THREE.Vector3(4.8, 3.72, 2.6),
cats: ["cheese"],
color: "#e7834f"
},
{
title: "Lilac whey",
detail: "140 L-eq · 14% · byproduct",
position: new THREE.Vector3(2.5, 2.03, 5),
cats: ["whey"],
color: "#8775c5"
},
{
title: "Moogrow compost",
detail: "80 L-eq · 8% · byproduct",
position: new THREE.Vector3(4.2, 1.62, 5),
cats: ["compost"],
color: "#8d6648"
}
].map((label) => {
const element = document.createElement("div");
element.className = "scene-label";
element.style.setProperty("--accent", label.color);
element.innerHTML =
`<strong>${label.title}</strong><small>${label.detail}</small>`;
element.addEventListener("click", () => setFilter(label.cats[0]));
labelLayer.appendChild(element);
return { ...label, element };
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -100 &&
x < width + 100 &&
y > -80 &&
y < height + 80;
label.element.style.display = visible ? "block" : "none";
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
});
}
// ---------------------------------------------------------------------
// Filtering and UI
// ---------------------------------------------------------------------
let activeFilter = "all";
let flowRunning = true;
let labelsVisible = true;
let flowTime = 0;
function categoryVisible(categories) {
if (activeFilter === "all") return true;
if (activeFilter === "product") {
return categories.some((category) =>
["cream", "yogurt", "cheese"].includes(category)
);
}
if (activeFilter === "byproduct") {
return categories.some((category) =>
["whey", "compost"].includes(category)
);
}
return categories.includes(activeFilter);
}
function setFilter(filter) {
activeFilter = filter;
document.querySelectorAll("[data-filter]").forEach((button) => {
button.classList.toggle("active", button.dataset.filter === filter);
});
routes.forEach((route) => {
const visible = categoryVisible(route.cats);
route.material.opacity = visible ? 0.93 : 0.11;
});
tokenGroups.forEach((group) => {
const visible = categoryVisible([group.name]);
group.material.opacity = visible ? 1 : 0.08;
group.material.depthWrite = visible;
});
labels.forEach((label) => {
label.element.classList.toggle(
"muted",
!categoryVisible(label.cats)
);
});
const descriptions = {
all: "All 5 routes · 100 tokens conserved",
product: "Products highlighted · 780 L-eq · 78% of feed",
byproduct: "Byproducts highlighted · 220 L-eq · 22% of feed",
cream: "Golden cream isolated · 180 L-eq · 18%",
yogurt: "Cloud yogurt isolated · 240 L-eq · 24%",
cheese: "Amber cheese isolated · 360 L-eq · 36%",
whey: "Lilac whey isolated · 140 L-eq · 14%",
compost: "Moogrow compost isolated · 80 L-eq · 8%"
};
document.querySelector("#filter-status").textContent =
descriptions[filter];
}
document.querySelectorAll("[data-filter]").forEach((button) => {
button.addEventListener("click", () => {
setFilter(button.dataset.filter);
});
});
document.querySelector("#flow-button").addEventListener("click", () => {
flowRunning = !flowRunning;
const button = document.querySelector("#flow-button");
button.textContent = flowRunning ? "Pause flow" : "Resume flow";
button.setAttribute("aria-pressed", String(flowRunning));
});
document.querySelector("#label-button").addEventListener("click", () => {
labelsVisible = !labelsVisible;
const button = document.querySelector("#label-button");
button.textContent = labelsVisible ? "Hide labels" : "Show labels";
button.setAttribute("aria-pressed", String(labelsVisible));
labels.forEach((label) => {
label.element.classList.toggle("hidden", !labelsVisible);
});
});
document.querySelector("#reset-button").addEventListener("click", () => {
controls.target.set(-0.1, 0.8, 0.8);
controls.theta = -0.66;
controls.phi = 1.02;
controls.radius = 19.5;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
document.querySelector("#flow-button").click();
}
if (event.key.toLowerCase() === "r") {
document.querySelector("#reset-button").click();
}
if (event.key === "Escape") {
setFilter("all");
}
});
// ---------------------------------------------------------------------
// Direct camera controls; no addons
// ---------------------------------------------------------------------
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.46,
1.38
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
controls.dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
10,
29
);
updateCamera();
},
{ passive: false }
);
// Select equipment directly.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDownPosition = null;
canvas.addEventListener("pointerdown", (event) => {
pointerDownPosition = {
x: event.clientX,
y: event.clientY
};
});
canvas.addEventListener("pointerup", (event) => {
if (!pointerDownPosition) return;
const travel = Math.hypot(
event.clientX - pointerDownPosition.x,
event.clientY - pointerDownPosition.y
);
pointerDownPosition = null;
if (travel > 5) return;
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickables, false)[0];
if (hit && hit.object.userData.filter) {
setFilter(hit.object.userData.filter);
}
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (flowRunning) flowTime += delta * 0.048;
tokenGroups.forEach((group) => {
const visible = categoryVisible([group.name]);
for (let index = 0; index < group.count; index++) {
const t = (index / group.count + flowTime) % 1;
const position = group.curve.getPointAt(t);
dummy.position.copy(position);
dummy.position.y += 0.17;
dummy.rotation.set(
t * Math.PI * 3,
t * Math.PI * 5,
t * Math.PI * 2
);
dummy.scale.setScalar(visible ? 1 : 0.001);
dummy.updateMatrix();
group.mesh.setMatrixAt(index, dummy.matrix);
}
group.mesh.instanceMatrix.needsUpdate = true;
});
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
setFilter("all");
animate();
</script>
</body>
</html>
```