Prompt specification
Build or customize the Three.js 3D scene "Educational dairy processing exhibit" 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: Educational dairy processing exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/educational-dairy-processing-exhibit-x1055
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing dairy processing. Build a museum-style line with collection, thermal-treatment diagram, separation, and packaging stations; labels describe purposes without giving operational temperatures, timings, or safety guarantees. Voxel style.
Working Three.js Starter (educational-dairy-processing-exhibit-x1055):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dairy Processing — Voxel Museum</title>
<style>
:root {
--ink: #25343a;
--muted: #65767a;
--paper: #f8f4ea;
--line: rgba(37, 52, 58, 0.16);
--teal: #168b91;
--orange: #e36f3d;
--gold: #d9ad54;
--shadow: 0 14px 38px rgba(42, 52, 54, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e4dc;
color: var(--ink);
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.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 48%, rgba(33, 43, 44, 0.08) 100%);
z-index: 2;
}
.masthead {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
max-width: min(560px, calc(100vw - 250px));
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.controls {
position: fixed;
top: 22px;
right: 24px;
z-index: 7;
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(248, 244, 234, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.controls button {
border: 0;
border-radius: 9px;
padding: 9px 12px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.controls button:hover {
background: var(--ink);
color: white;
transform: translateY(-1px);
}
.controls button:focus-visible,
.station-card:focus-visible {
outline: 3px solid rgba(22, 139, 145, 0.35);
outline-offset: 2px;
}
#hotspots {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 9px 5px 5px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
background: rgba(248, 244, 234, 0.9);
box-shadow: 0 7px 20px rgba(36, 48, 50, 0.18);
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
pointer-events: auto;
cursor: pointer;
user-select: none;
}
.hotspot .number {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border-radius: 50%;
background: var(--ink);
color: white;
font-size: 10px;
font-weight: 900;
}
.hotspot .name {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
white-space: nowrap;
}
.hotspot[data-accent="orange"] .number {
background: var(--orange);
}
.hotspot[data-accent="gold"] .number {
background: #b88b2e;
}
.hotspot[data-accent="teal"] .number {
background: var(--teal);
}
.guide-wrap {
position: fixed;
right: 18px;
bottom: 18px;
left: 18px;
z-index: 6;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: rgba(248, 244, 234, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.guide-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 0 4px 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.guide-heading strong {
color: var(--ink);
}
#station-guide {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px;
}
.station-card {
position: relative;
min-width: 0;
padding: 12px 13px 13px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.54);
cursor: pointer;
transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}
.station-card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
background: var(--accent, var(--teal));
content: "";
}
.station-card:hover,
.station-card.active {
border-color: rgba(37, 52, 58, 0.35);
background: white;
transform: translateY(-2px);
}
.card-top {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 5px;
}
.card-index {
color: var(--accent, var(--teal));
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
}
.station-card h2 {
margin: 0;
overflow: hidden;
font-size: 12px;
letter-spacing: 0.04em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.station-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.42;
}
.interaction-note {
position: fixed;
right: 24px;
bottom: 145px;
z-index: 5;
color: rgba(37, 52, 58, 0.66);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
pointer-events: none;
}
#error {
position: fixed;
inset: 0;
z-index: 20;
display: none;
place-items: center;
padding: 30px;
background: #eee9df;
text-align: center;
}
#error div {
max-width: 520px;
padding: 26px;
border: 1px solid var(--line);
border-radius: 18px;
background: white;
box-shadow: var(--shadow);
}
@media (max-width: 800px) {
.masthead {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.subtitle {
max-width: 62vw;
font-size: 11px;
}
.controls {
top: auto;
right: 14px;
bottom: 148px;
}
.controls button {
padding: 8px 9px;
font-size: 10px;
}
.guide-wrap {
right: 10px;
bottom: 10px;
left: 10px;
padding: 8px;
}
#station-guide {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
scrollbar-width: thin;
}
.station-card {
flex: 0 0 230px;
scroll-snap-align: start;
}
.guide-heading span {
display: none;
}
.interaction-note {
display: none;
}
.hotspot .name {
display: none;
}
.hotspot {
padding: 4px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional dairy processing museum exhibit"></div>
<div class="vignette"></div>
<header class="masthead">
<div class="eyebrow">Museum of everyday systems · Exhibit 04</div>
<h1>Dairy, deconstructed</h1>
<div class="subtitle">
An interactive voxel walk through collection, thermal treatment,
separation, and packaging. Drag to orbit and select a station to explore.
</div>
</header>
<nav class="controls" aria-label="Camera controls">
<button id="reset-view" type="button">Reset view</button>
<button id="top-view" type="button">Top view</button>
</nav>
<div id="hotspots"></div>
<section class="guide-wrap" aria-label="Station purposes">
<div class="guide-heading">
<strong>Station purpose guide</strong>
<span>Illustrative museum sequence · schematic equipment</span>
</div>
<div id="station-guide"></div>
</section>
<div class="interaction-note">Drag to orbit · Wheel to zoom · Select a station</div>
<div id="error" role="alert">
<div>
<h2>Unable to start the exhibit</h2>
<p>This scene needs a browser with WebGL enabled and access to the Three.js CDN.</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stationData = [
{
number: "01",
short: "Collection",
title: "Collection",
purpose: "Receives incoming milk and presents a continuous feed to the line.",
accent: "#168b91",
x: -8,
anchor: new THREE.Vector3(-8, 5.05, -0.25)
},
{
number: "02",
short: "Thermal treatment",
title: "Thermal-treatment diagram",
purpose: "Illustrates where heat treatment belongs in the line and what the stage is for.",
accent: "#e36f3d",
x: -2.7,
anchor: new THREE.Vector3(-2.7, 5.2, -0.35)
},
{
number: "03",
short: "Separation",
title: "Separation",
purpose: "Separates milk into its main fractions before the finishing stage.",
accent: "#d9ad54",
x: 2.7,
anchor: new THREE.Vector3(2.7, 5.05, -0.35)
},
{
number: "04",
short: "Packaging",
title: "Packaging",
purpose: "Packages the prepared product into finished units for handling and presentation.",
accent: "#477f9d",
x: 8,
anchor: new THREE.Vector3(8, 5.05, 0.35)
}
];
const sceneElement = document.getElementById("scene");
const hotspotsElement = document.getElementById("hotspots");
const guideElement = document.getElementById("station-guide");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
document.getElementById("error").style.display = "grid";
throw error;
}
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;
sceneElement.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e4dc);
scene.fog = new THREE.Fog(0xe8e4dc, 31, 57);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const initialRadius = window.innerWidth / window.innerHeight < 0.8 ? 39 : 26;
const cameraState = {
target: new THREE.Vector3(0, 2.1, 0.1),
goalTarget: new THREE.Vector3(0, 2.1, 0.1),
radius: initialRadius,
goalRadius: initialRadius,
theta: 0.7,
goalTheta: 0.7,
phi: 0.93,
goalPhi: 0.93
};
const palette = {
floor: 0xd9d4ca,
floorEdge: 0xc9c2b5,
wall: 0xeee9df,
wallInset: 0xe3ddd1,
cream: 0xf4f0e6,
white: 0xfffdf7,
ink: 0x304047,
steel: 0x9aa8a9,
steelDark: 0x607174,
belt: 0x36464a,
teal: 0x168b91,
tealLight: 0x67b7b4,
blue: 0x477f9d,
blueLight: 0x8db8c9,
orange: 0xe36f3d,
orangeLight: 0xf3a26e,
gold: 0xd9ad54,
yellowLight: 0xf1d68a,
green: 0x6d9d72
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.05,
flatShading: true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
const M = {
floor: material(palette.floor),
floorEdge: material(palette.floorEdge),
wall: material(palette.wall),
wallInset: material(palette.wallInset),
cream: material(palette.cream),
white: material(palette.white),
ink: material(palette.ink),
steel: material(palette.steel, { roughness: 0.55, metalness: 0.42 }),
steelDark: material(palette.steelDark, { roughness: 0.62, metalness: 0.35 }),
belt: material(palette.belt, { roughness: 0.9 }),
teal: material(palette.teal),
tealLight: material(palette.tealLight),
blue: material(palette.blue),
blueLight: material(palette.blueLight),
orange: material(palette.orange, {
emissive: palette.orange,
emissiveIntensity: 0.12
}),
orangeLight: material(palette.orangeLight),
gold: material(palette.gold),
yellowLight: material(palette.yellowLight),
green: material(palette.green),
glass: material(0xa9d9d7, {
transparent: true,
opacity: 0.22,
depthWrite: false,
roughness: 0.25
})
};
function box(parent, width, height, depth, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeSignTexture(title, accent) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f8f4ea";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 25, canvas.height);
ctx.fillStyle = "#304047";
ctx.font = "800 52px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.textAlign = "center";
let label = title.toUpperCase();
const maxWidth = 690;
while (ctx.measureText(label).width > maxWidth && label.length > 3) {
label = label.slice(0, -2);
}
if (label !== title.toUpperCase()) label += "…";
ctx.fillText(label, canvas.width / 2 + 10, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addStationSign(title, accent, x, y, z, width = 3.9) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
box(group, width, 0.8, 0.16, 0, 0, 0, M.cream);
box(group, 0.16, 0.54, 0.2, -width / 2 + 0.28, 0, 0.04, M.ink);
const signMaterial = new THREE.MeshBasicMaterial({
map: makeSignTexture(title, accent),
toneMapped: false
});
const plane = new THREE.Mesh(new THREE.PlaneGeometry(width - 0.16, 0.68), signMaterial);
plane.position.set(0.07, 0, 0.086);
group.add(plane);
return group;
}
// Lighting and museum environment.
const hemisphere = new THREE.HemisphereLight(0xfff9ec, 0x758184, 2.05);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dd, 3.25);
keyLight.position.set(-9, 17, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -23;
keyLight.shadow.camera.right = 23;
keyLight.shadow.camera.top = 17;
keyLight.shadow.camera.bottom = -17;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 55;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8dce0, 1.2);
fillLight.position.set(12, 8, -10);
scene.add(fillLight);
const tealLight = new THREE.PointLight(palette.tealLight, 10, 10, 2);
tealLight.position.set(-7, 3.8, 2.5);
scene.add(tealLight);
const orangeLight = new THREE.PointLight(palette.orangeLight, 13, 9, 2);
orangeLight.position.set(-2.7, 2.7, 0.4);
scene.add(orangeLight);
// Floor, wall, plinth, and exhibit panels.
box(scene, 38, 0.3, 22, 0, -0.18, 0, M.floor);
box(scene, 38.5, 0.16, 22.5, 0, -0.38, 0, M.floorEdge);
box(scene, 34, 6.4, 0.3, 0, 3.1, -6.2, M.wall);
stationData.forEach((station) => {
box(scene, 5.3, 0.24, 5.1, station.x, 0.09, 0.2, M.floorEdge);
box(scene, 4.8, 0.08, 4.65, station.x, 0.23, 0.2, M.cream);
box(scene, 4.6, 4.6, 0.08, station.x, 2.75, -6.01, M.wallInset);
});
for (let x = -16; x <= 16; x += 2) {
box(scene, 0.025, 0.012, 20, x, -0.015, 0, M.floorEdge, false);
}
for (let z = -9; z <= 9; z += 2) {
box(scene, 36, 0.012, 0.025, 0, -0.014, z, M.floorEdge, false);
}
// Conveyor.
const conveyorGroup = new THREE.Group();
scene.add(conveyorGroup);
box(conveyorGroup, 26.5, 0.34, 2.18, 0, 0.96, 0.45, M.belt);
box(conveyorGroup, 26.8, 0.16, 0.18, 0, 0.93, -0.72, M.steelDark);
box(conveyorGroup, 26.8, 0.16, 0.18, 0, 0.93, 1.62, M.steelDark);
for (let x = -12; x <= 12; x += 3) {
box(conveyorGroup, 0.24, 0.9, 0.24, x, 0.43, -0.45, M.steel);
box(conveyorGroup, 0.24, 0.9, 0.24, x, 0.43, 1.35, M.steel);
box(conveyorGroup, 0.24, 0.2, 2.05, x, 0.28, 0.45, M.steelDark);
}
const beltSlats = [];
for (let x = -12.8; x <= 12.8; x += 0.48) {
const slat = box(conveyorGroup, 0.2, 0.075, 1.92, x, 1.17, 0.45, M.steelDark, false);
beltSlats.push(slat);
}
// Blocky direction arrows.
[-5.3, 0, 5.3].forEach((x) => {
box(scene, 1.1, 0.04, 0.15, x - 0.2, 0.02, 3.35, M.teal, false);
const arrowA = box(scene, 0.58, 0.04, 0.15, x + 0.35, 0.02, 3.55, M.teal, false);
const arrowB = box(scene, 0.58, 0.04, 0.15, x + 0.35, 0.02, 3.15, M.teal, false);
arrowA.rotation.y = -0.65;
arrowB.rotation.y = 0.65;
});
// 01 — Collection.
const collection = new THREE.Group();
collection.position.set(-8, 0.25, -1.35);
scene.add(collection);
box(collection, 2.8, 0.45, 2.8, 0, 0.23, 0, M.ink);
box(collection, 2.35, 2.5, 2.35, 0, 1.68, 0, M.cream);
box(collection, 2.55, 0.28, 2.55, 0, 3.03, 0, M.teal);
box(collection, 1.65, 0.42, 1.65, 0, 3.38, 0, M.tealLight);
box(collection, 1.15, 0.22, 1.15, 0, 3.68, 0, M.cream);
box(collection, 0.28, 0.65, 0.28, -1.65, 2.4, 0, M.steel);
box(collection, 1.55, 0.28, 0.28, -0.95, 2.68, 0, M.steel);
box(collection, 0.28, 1.5, 0.28, 0, 1.2, 1.32, M.steel);
box(collection, 0.28, 0.28, 1.15, 0, 0.98, 1.75, M.steel);
box(collection, 0.78, 1.45, 0.08, -0.38, 1.65, 1.19, M.blueLight);
box(collection, 0.08, 1.55, 0.12, -0.38, 1.65, 1.25, M.steel, false);
box(collection, 1.05, 0.22, 0.25, 0.35, 1.1, 1.25, M.teal);
const collectionBlocks = [];
for (let i = 0; i < 4; i++) {
const cube = box(collection, 0.28, 0.28, 0.28, -0.5 + (i % 2) * 0.42,
3.67 + Math.floor(i / 2) * 0.2, -0.25 + Math.floor(i / 2) * 0.35,
M.white, false);
collectionBlocks.push(cube);
}
addStationSign("Collection", "#168b91", -8, 4.45, 0.02, 3.65);
// 02 — Thermal-treatment chamber and diagram.
const thermal = new THREE.Group();
thermal.position.set(-2.7, 0.25, 0.45);
scene.add(thermal);
box(thermal, 4.35, 0.3, 3.3, 0, 0.12, 0, M.ink);
box(thermal, 0.22, 2.65, 0.22, -1.92, 1.52, -1.35, M.steel);
box(thermal, 0.22, 2.65, 0.22, 1.92, 1.52, -1.35, M.steel);
box(thermal, 0.22, 2.65, 0.22, -1.92, 1.52, 1.35, M.steel);
box(thermal, 0.22, 2.65, 0.22, 1.92, 1.52, 1.35, M.steel);
box(thermal, 4.05, 0.2, 3.05, 0, 2.86, 0, M.steel);
box(thermal, 0.12, 2.25, 2.6, -1.98, 1.55, 0, M.glass, false);
box(thermal, 0.12, 2.25, 2.6, 1.98, 1.55, 0, M.glass, false);
box(thermal, 3.78, 2.25, 0.1, 0, 1.55, -1.38, M.glass, false);
box(thermal, 3.78, 2.25, 0.1, 0, 1.55, 1.38, M.glass, false);
const thermalBlocks = [];
for (let i = 0; i < 5; i++) {
const block = box(thermal, 0.48, 0.48, 0.48,
-1.28 + i * 0.64, 1.55 + (i % 2) * 0.18, -0.72,
i % 2 === 0 ? M.orange : M.orangeLight, false);
thermalBlocks.push(block);
}
box(thermal, 3.8, 0.18, 0.2, 0, 0.63, -0.72, M.blue);
box(thermal, 0.18, 0.18, 1.7, -1.7, 0.63, 0.1, M.blue);
box(thermal, 0.18, 0.18, 1.7, 1.7, 0.63, 0.1, M.blue);
// A purpose diagram: feed block, treatment blocks, prepared block.
box(thermal, 4.3, 1.5, 0.14, 0, 3.48, -2.1, M.cream);
box(thermal, 0.72, 0.62, 0.12, -1.25, 3.1, -1.99, M.blue);
box(thermal, 0.26, 0.22, 0.12, -0.73, 3.1, -1.99, M.ink);
box(thermal, 0.26, 0.22, 0.12, -0.42, 3.1, -1.99, M.ink);
box(thermal, 0.62, 0.62, 0.12, 0.18, 3.1, -1.99, M.orange);
box(thermal, 0.26, 0.22, 0.12, 0.58, 3.1, -1.99, M.ink);
box(thermal, 0.26, 0.22, 0.12, 0.91, 3.1, -1.99, M.ink);
box(thermal, 0.72, 0.62, 0.12, 1.58, 3.1, -1.99, M.green);
addStationSign("Thermal treatment", "#e36f3d", -2.7, 4.65, -0.25, 4.5);
// 03 — Separation.
const separation = new THREE.Group();
separation.position.set(2.7, 0.25, -1.0);
scene.add(separation);
box(separation, 3.8, 0.45, 3.5, 0, 0.2, 0, M.ink);
box(separation, 3.25, 0.25, 3.0, 0, 0.52, 0, M.cream);
box(separation, 0.22, 2.05, 2.7, -1.48, 1.55, 0, M.steel);
box(separation, 0.22, 2.05, 2.7, 1.48, 1.55, 0, M.steel);
box(separation, 2.75, 2.05, 0.2, 0, 1.55, -1.23, M.steel);
box(separation, 2.75, 2.05, 0.08, 0, 1.55, 1.23, M.glass, false);
box(separation, 2.75, 0.2, 2.55, 0, 2.58, 0, M.gold);
box(separation, 0.55, 1.7, 0.55, 0, 1.47, 0, M.steelDark);
box(separation, 0.85, 0.25, 0.85, 0, 0.82, 0, M.blue);
const rotor = new THREE.Group();
rotor.position.set(0, 1.75, 0);
separation.add(rotor);
box(rotor, 3.0, 0.16, 0.28, 0, 0, 0, M.blue);
box(rotor, 0.28, 0.16, 3.0, 0, 0, 0, M.blue);
box(rotor, 0.52, 0.35, 0.52, 1.25, 0, 0, M.blueLight);
box(rotor, 0.52, 0.35, 0.52, -1.25, 0, 0, M.yellowLight);
box(separation, 0.55, 0.55, 0.55, -1.08, 0.87, 0.75, M.white);
box(separation, 0.55, 0.55, 0.55, 1.08, 0.87, 0.75, M.yellowLight);
box(separation, 0.32, 0.7, 0.32, -0.95, 0.7, -0.8, M.blue);
box(separation, 0.32, 0.7, 0.32, 0.95, 0.7, -0.8, M.gold);
addStationSign("Separation", "#d9ad54", 2.7, 4.55, -0.18, 3.8);
// 04 — Packaging.
const packaging = new THREE.Group();
packaging.position.set(8, 0.25, 0.45);
scene.add(packaging);
box(packaging, 4.6, 0.28, 3.8, 0, 0.1, 0, M.ink);
box(packaging, 0.3, 3.0, 0.3, -1.75, 1.75, -1.25, M.steel);
box(packaging, 0.3, 3.0, 0.3, 1.75, 1.75, -1.25, M.steel);
box(packaging, 0.3, 3.0, 0.3, -1.75, 1.75, 1.25, M.steel);
box(packaging, 0.3, 3.0, 0.3, 1.75, 1.75, 1.25, M.steel);
box(packaging, 3.8, 0.34, 2.8, 0, 3.24, 0, M.blue);
box(packaging, 0.65, 0.7, 0.65, 0, 2.7, 0, M.cream);
box(packaging, 0.32, 0.65, 0.32, 0, 2.14, 0, M.steel);
box(packaging, 1.3, 0.18, 0.32, 0, 1.8, 0, M.steel);
function carton(parent, x, y, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, y, z);
g.scale.setScalar(scale);
parent.add(g);
box(g, 0.58, 0.9, 0.58, 0, 0.45, 0, M.white);
box(g, 0.62, 0.13, 0.62, 0, 0.91, 0, M.blue);
box(g, 0.32, 0.26, 0.025, 0, 0.48, 0.3, M.teal);
return g;
}
carton(packaging, 0, 1.22, 0, 0.9);
carton(packaging, 0.9, 1.22, 0.45, 0.75);
carton(packaging, 3.0, 0.02, -0.55, 0.9);
carton(packaging, 3.0, 1.0, -0.55, 0.9);
carton(packaging, 3.0, 0.02, 0.45, 0.8);
carton(packaging, 3.0, 0.86, 0.45, 0.8);
addStationSign("Packaging", "#477f9d", 8, 4.55, 0.18, 3.8);
// Abstract material units moving along the conveyor.
const flowCubes = [];
for (let i = 0; i < 7; i++) {
const cube = box(
scene,
0.34,
0.34,
0.34,
-11 + i * 3.5,
1.47,
0.45,
i % 3 === 0 ? M.blueLight : M.white,
false
);
flowCubes.push(cube);
}
// Build DOM station guide and projected markers.
const hotspotNodes = [];
const cardNodes = [];
stationData.forEach((station) => {
const hotspot = document.createElement("button");
hotspot.className = "hotspot";
hotspot.type = "button";
hotspot.dataset.accent = station.accent;
hotspot.style.setProperty("--accent", station.accent);
hotspot.setAttribute("aria-label", `Focus on ${station.title}`);
const number = document.createElement("span");
number.className = "number";
number.textContent = station.number;
const name = document.createElement("span");
name.className = "name";
name.textContent = station.short;
hotspot.append(number, name);
hotspotsElement.appendChild(hotspot);
hotspotNodes.push(hotspot);
const card = document.createElement("article");
card.className = "station-card";
card.tabIndex = 0;
card.style.setProperty("--accent", station.accent);
const top = document.createElement("div");
top.className = "card-top";
const index = document.createElement("span");
index.className = "card-index";
index.textContent = station.number;
const title = document.createElement("h2");
title.textContent = station.title;
const description = document.createElement("p");
description.textContent = station.purpose;
top.append(index, title);
card.append(top, description);
guideElement.appendChild(card);
cardNodes.push(card);
const focusStation = () => focusStationView(station);
hotspot.addEventListener("click", focusStation);
card.addEventListener("click", focusStation);
card.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
focusStation();
}
});
});
function focusStationView(station) {
cameraState.goalTarget.set(station.x, 2.0, 0.05);
cameraState.goalRadius = window.innerWidth / window.innerHeight < 0.8 ? 21 : 13.5;
cameraState.goalTheta = 0.72;
cameraState.goalPhi = 0.94;
cardNodes.forEach((card, index) => {
card.classList.toggle("active", stationData[index] === station);
});
}
function resetView() {
cameraState.goalTarget.set(0, 2.1, 0.1);
cameraState.goalRadius = window.innerWidth / window.innerHeight < 0.8 ? 39 : 26;
cameraState.goalTheta = 0.7;
cameraState.goalPhi = 0.93;
cardNodes.forEach((card) => card.classList.remove("active"));
}
function topView() {
cameraState.goalTarget.set(0, 1.2, 0.1);
cameraState.goalRadius = window.innerWidth / window.innerHeight < 0.8 ? 43 : 30;
cameraState.goalTheta = 0.7;
cameraState.goalPhi = 0.18;
cardNodes.forEach((card) => card.classList.remove("active"));
}
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("top-view").addEventListener("click", topView);
// Direct camera controls: pointer orbit, wheel zoom, and keyboard arrows.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
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;
cameraState.goalTheta -= dx * 0.006;
cameraState.goalPhi = THREE.MathUtils.clamp(
cameraState.goalPhi - dy * 0.005,
0.16,
1.35
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.goalRadius = THREE.MathUtils.clamp(
cameraState.goalRadius * Math.exp(event.deltaY * 0.001),
10,
46
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {
return;
}
if (event.key === "ArrowLeft") cameraState.goalTheta += 0.12;
if (event.key === "ArrowRight") cameraState.goalTheta -= 0.12;
if (event.key === "ArrowUp") {
cameraState.goalPhi = Math.max(0.16, cameraState.goalPhi - 0.08);
}
if (event.key === "ArrowDown") {
cameraState.goalPhi = Math.min(1.35, cameraState.goalPhi + 0.08);
}
if (event.key === "+" || event.key === "=") {
cameraState.goalRadius = Math.max(10, cameraState.goalRadius - 1.5);
}
if (event.key === "-" || event.key === "_") {
cameraState.goalRadius = Math.min(46, cameraState.goalRadius + 1.5);
}
});
const projected = new THREE.Vector3();
const cameraOffset = new THREE.Vector3();
const clock = new THREE.Clock();
function updateCamera() {
const smoothing = 1 - Math.pow(0.001, clock.getDelta());
cameraState.target.lerp(cameraState.goalTarget, smoothing * 0.72);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.goalRadius,
smoothing * 0.72
);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.goalTheta,
smoothing * 0.72
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.goalPhi,
smoothing * 0.72
);
const sinPhi = Math.sin(cameraState.phi);
cameraOffset.set(
cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.radius * Math.cos(cameraState.phi),
cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.position.copy(cameraState.target).add(cameraOffset);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function updateHotspots() {
const width = window.innerWidth;
const height = window.innerHeight;
stationData.forEach((station, index) => {
projected.copy(station.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
hotspotNodes[index].style.left = `${x}px`;
hotspotNodes[index].style.top = `${y}px`;
hotspotNodes[index].style.display = visible ? "flex" : "none";
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera();
beltSlats.forEach((slat) => {
slat.position.x += delta * 0.85;
if (slat.position.x > 13) slat.position.x = -13;
});
flowCubes.forEach((cube, index) => {
cube.position.x += delta * (0.8 + index * 0.025);
cube.position.y = 1.47 + Math.sin(elapsed * 2.4 + index) * 0.025;
if (cube.position.x > 12.3) cube.position.x = -12.3;
});
rotor.rotation.y += delta * 0.72;
collectionBlocks.forEach((cube, index) => {
cube.position.y = 3.67 + Math.floor(index / 2) * 0.2 +
Math.sin(elapsed * 2 + index * 0.7) * 0.035;
});
M.orange.emissiveIntensity = 0.16 + Math.sin(elapsed * 2.2) * 0.09;
orangeLight.intensity = 12 + Math.sin(elapsed * 2.2) * 2;
updateHotspots();
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
animate();
</script>
</body>
</html>
```