Prompt specification
Build or customize the Three.js 3D scene "Compost Bin Air-Channel Connectivity Cutaway" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Compost Bin Air-Channel Connectivity Cutaway
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compost-bin-air-channel-connectivity-cutaway-x3925
Scene Description Prompt:
Compost bin air-channel connectivity cutaway. Model a schematic compost bin with perforated walls and connected internal air channels. Compare an open vent and a blocked vent geometrically without claiming measured oxygen or decomposition rates. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (compost-bin-air-channel-connectivity-cutaway-x3925):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compost Bin Air-Channel Connectivity</title>
<style>
:root {
--ink: #18342f;
--muted: #5f726c;
--paper: rgba(249, 251, 246, 0.93);
--line: rgba(24, 52, 47, 0.15);
--open: #16866f;
--open-soft: #d9eee6;
--blocked: #c45a3f;
--blocked-soft: #f5e1d9;
--accent: #d48355;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eee5;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 24px;
left: 28px;
max-width: 440px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--open);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 38px);
line-height: 1.04;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 390px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 22px;
right: 24px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 10px;
padding: 10px 13px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 5px 16px rgba(22, 47, 40, 0.07);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(24, 52, 47, 0.3);
}
button[aria-pressed="true"] {
border-color: rgba(22, 134, 111, 0.45);
background: var(--open-soft);
}
.legend {
position: absolute;
top: 80px;
right: 25px;
display: grid;
gap: 8px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(249, 251, 246, 0.82);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(8px);
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 17px;
height: 7px;
border-radius: 999px;
background: #28b9a5;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.blocked {
background: var(--blocked);
}
.swatch.cut {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--accent);
}
.model-label {
position: absolute;
min-width: 150px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(250, 252, 248, 0.94);
box-shadow: 0 7px 20px rgba(25, 50, 43, 0.1);
text-align: center;
transform: translate(-50%, -100%);
will-change: transform;
}
.model-label strong {
display: block;
font-size: 12px;
letter-spacing: 0.02em;
}
.model-label span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.model-label.open {
border-top: 3px solid var(--open);
}
.model-label.blocked {
border-top: 3px solid var(--blocked);
}
.vent-label {
position: absolute;
padding: 5px 8px;
border-radius: 7px;
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translate(-50%, -100%);
white-space: nowrap;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.vent-label.open {
background: var(--open);
}
.vent-label.blocked {
background: var(--blocked);
}
.comparison {
position: absolute;
left: 50%;
bottom: 62px;
display: grid;
grid-template-columns: repeat(2, minmax(230px, 285px));
gap: 12px;
transform: translateX(-50%);
pointer-events: auto;
}
.card {
position: relative;
overflow: hidden;
padding: 15px 16px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(25, 50, 43, 0.1);
backdrop-filter: blur(10px);
}
.card::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 4px;
content: "";
}
.card.open::before {
background: var(--open);
}
.card.blocked::before {
background: var(--blocked);
}
.card-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
font-size: 13px;
font-weight: 800;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
}
.open .dot {
background: var(--open);
}
.blocked .dot {
background: var(--blocked);
}
.card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.note {
position: absolute;
right: 25px;
bottom: 18px;
left: 25px;
color: #64746f;
font-size: 10px;
line-height: 1.45;
text-align: center;
}
.help {
position: absolute;
bottom: 20px;
left: 27px;
color: rgba(24, 52, 47, 0.58);
font-size: 10px;
letter-spacing: 0.02em;
}
@media (max-width: 800px) {
header {
top: 16px;
left: 17px;
max-width: calc(100vw - 34px);
}
h1 {
font-size: 25px;
}
.subtitle {
max-width: 310px;
font-size: 11px;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
}
.legend {
display: none;
}
.comparison {
bottom: 66px;
grid-template-columns: 1fr;
width: min(360px, calc(100vw - 28px));
}
.card {
padding: 10px 13px;
}
.card p {
font-size: 10px;
}
.help,
.note {
display: none;
}
.model-label {
min-width: 118px;
padding: 6px 8px;
}
.model-label strong {
font-size: 10px;
}
.model-label span {
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="viewport"></div>
<div class="overlay">
<header>
<div class="eyebrow">Schematic cutaway · connectivity study</div>
<h1>Compost bin air-channel pathways</h1>
<p class="subtitle">
Compare the visible connection between a perforated enclosure,
internal ducts, and an external vent. Geometry only.
</p>
</header>
<nav class="controls" aria-label="Model controls">
<button id="cutaway" type="button" aria-pressed="true">Cutaway on</button>
<button id="route" type="button" aria-pressed="true">Route markers on</button>
<button id="reset" type="button">Reset view</button>
</nav>
<aside class="legend" aria-label="Legend">
<div class="legend-row">
<span class="swatch"></span>
<span>Connected internal channel</span>
</div>
<div class="legend-row">
<span class="swatch blocked"></span>
<span>Sealed termination</span>
</div>
<div class="legend-row">
<span class="swatch cut"></span>
<span>Cutaway boundary</span>
</div>
</aside>
<div id="openModelLabel" class="model-label open">
<strong>OPEN VENT</strong>
<span>Visible passage to exterior</span>
</div>
<div id="blockedModelLabel" class="model-label blocked">
<strong>BLOCKED VENT</strong>
<span>Outlet terminates at a solid plug</span>
</div>
<div id="openVentLabel" class="vent-label open">Open outlet</div>
<div id="blockedVentLabel" class="vent-label blocked">Blocked outlet</div>
<section class="comparison" aria-label="Geometric comparison">
<article class="card open">
<div class="card-title"><span class="dot"></span>Open vent geometry</div>
<p>
The grille leaves visible openings, and the schematic duct remains
continuous from the lower manifold to the exterior.
</p>
</article>
<article class="card blocked">
<div class="card-title"><span class="dot"></span>Blocked vent geometry</div>
<p>
A solid plate and internal plug interrupt the same duct before it
reaches the exterior grille.
</p>
</article>
</section>
<div class="help">Drag to orbit · Scroll to zoom · Shift/right-drag to pan</div>
<div class="note">
Schematic geometry only. Markers indicate possible route continuity,
not speed or flow rate. This model does not measure or predict oxygen,
airflow, temperature, or decomposition rate.
</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8eee5");
scene.fog = new THREE.Fog("#e8eee5", 13, 24);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
"#f7fff5",
"#6a7566",
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff5dc", 3.25);
sun.position.set(5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -5;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b8d8e8", 1.15);
fill.position.set(-5, 4, -4);
scene.add(fill);
const materials = {
wall: new THREE.MeshStandardMaterial({
color: "#668b7d",
roughness: 0.82,
metalness: 0.02,
flatShading: true
}),
wallDark: new THREE.MeshStandardMaterial({
color: "#42685f",
roughness: 0.8,
flatShading: true
}),
frame: new THREE.MeshStandardMaterial({
color: "#263d38",
roughness: 0.68,
metalness: 0.12,
flatShading: true
}),
frameLight: new THREE.MeshStandardMaterial({
color: "#516b65",
roughness: 0.62,
metalness: 0.1,
flatShading: true
}),
tray: new THREE.MeshStandardMaterial({
color: "#3d5149",
roughness: 0.86,
flatShading: true
}),
compost: new THREE.MeshStandardMaterial({
color: "#80633f",
roughness: 1,
flatShading: true
}),
compostLight: new THREE.MeshStandardMaterial({
color: "#9a774a",
roughness: 1,
flatShading: true
}),
compostDark: new THREE.MeshStandardMaterial({
color: "#5f4932",
roughness: 1,
flatShading: true
}),
duct: new THREE.MeshStandardMaterial({
color: "#31b9aa",
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.42,
depthWrite: false,
side: THREE.DoubleSide
}),
ductCore: new THREE.MeshStandardMaterial({
color: "#167b70",
roughness: 0.45,
metalness: 0.08
}),
open: new THREE.MeshStandardMaterial({
color: "#16866f",
roughness: 0.55,
flatShading: true
}),
blocked: new THREE.MeshStandardMaterial({
color: "#c45a3f",
roughness: 0.6,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: "#aebbb5",
roughness: 0.46,
metalness: 0.3,
flatShading: true
}),
cut: new THREE.LineBasicMaterial({
color: "#d48355",
transparent: true,
opacity: 0.95
}),
pedestal: new THREE.MeshStandardMaterial({
color: "#d8e0d3",
roughness: 0.95,
flatShading: true
}),
ground: new THREE.MeshStandardMaterial({
color: "#e3e9df",
roughness: 1
})
};
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 22),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.09;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(22, 44, "#cbd5c9", "#d6ddd3");
grid.position.y = -0.075;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const bins = [];
const routeMarkers = [];
const cameraState = {
target: new THREE.Vector3(0, 1.15, 0),
radius: 10.7,
theta: 0.53,
phi: 0.42
};
const reducedMotion = matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function addBox(parent, size, position, material, rotation = null) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
if (rotation) mesh.rotation.set(rotation.x, rotation.y, rotation.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
length,
position,
material,
rotation = null,
radialSegments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.copy(position);
if (rotation) mesh.rotation.set(rotation.x, rotation.y, rotation.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
/**
* Builds a panel from solid strips, leaving actual rectangular apertures.
* The panel lies in the local XY plane.
*/
function makeLatticePanel(
parent,
width,
height,
columns,
rows,
position,
rotationY = 0,
material = materials.wall
) {
const group = new THREE.Group();
group.position.copy(position);
group.rotation.y = rotationY;
parent.add(group);
const border = 0.095;
const bar = 0.047;
const cellWidth =
(width - border * 2 - bar * (columns - 1)) / columns;
const cellHeight =
(height - border * 2 - bar * (rows - 1)) / rows;
for (let i = 0; i <= columns; i++) {
let x;
if (i === 0) {
x = -width / 2 + border / 2;
} else if (i === columns) {
x = width / 2 - border / 2;
} else {
x =
-width / 2 +
border +
(i - 1) * (cellWidth + bar) +
cellWidth +
bar / 2;
}
addBox(
group,
new THREE.Vector3(border, height, 0.055),
new THREE.Vector3(x, 0, 0),
material
);
}
for (let i = 0; i <= rows; i++) {
let y;
if (i === 0) {
y = -height / 2 + border / 2;
} else if (i === rows) {
y = height / 2 - border / 2;
} else {
y =
-height / 2 +
border +
(i - 1) * (cellHeight + bar) +
cellHeight +
bar / 2;
}
addBox(
group,
new THREE.Vector3(width, border, 0.055),
new THREE.Vector3(0, y, 0),
material
);
}
return group;
}
function addPipeSegment(parent, a, b, radius = 0.105) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
6,
1,
true
),
materials.duct
);
shell.position.copy(midpoint);
shell.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
parent.add(shell);
const core = new THREE.Mesh(
new THREE.CylinderGeometry(
radius * 0.25,
radius * 0.25,
length,
6
),
materials.ductCore
);
core.position.copy(midpoint);
core.quaternion.copy(shell.quaternion);
parent.add(core);
}
function addPipeJoint(parent, position) {
const joint = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 1),
materials.duct
);
joint.position.set(...position);
parent.add(joint);
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.042, 1),
materials.ductCore
);
core.position.set(...position);
parent.add(core);
}
function createCompost(parent) {
const moundGeometry = new THREE.IcosahedronGeometry(1, 1);
const positionAttribute = moundGeometry.attributes.position;
for (let i = 0; i < positionAttribute.count; i++) {
const x = positionAttribute.getX(i);
const y = positionAttribute.getY(i);
const z = positionAttribute.getZ(i);
const variation =
1 +
0.075 * Math.sin(x * 11.7 + z * 7.3 + y * 5.1);
positionAttribute.setXYZ(
i,
x * variation,
y * variation,
z * variation
);
}
moundGeometry.computeVertexNormals();
const mound = new THREE.Mesh(
moundGeometry,
materials.compost
);
mound.position.set(-0.22, 0.72, 0.08);
mound.scale.set(0.76, 0.42, 0.59);
mound.rotation.y = 0.2;
mound.castShadow = true;
mound.receiveShadow = true;
parent.add(mound);
const chunks = [
[-0.65, 0.92, 0.32, 0.12, materials.compostLight],
[-0.38, 1.00, 0.47, 0.10, materials.compostDark],
[0.02, 0.89, 0.45, 0.09, materials.compostLight],
[-0.52, 0.80, -0.25, 0.11, materials.compostDark],
[-0.08, 0.96, -0.22, 0.09, materials.compostLight],
[0.16, 0.83, 0.14, 0.08, materials.compostDark],
[-0.72, 0.70, 0.02, 0.10, materials.compostLight],
[-0.27, 0.73, 0.52, 0.08, materials.compostDark]
];
for (const [x, y, z, size, material] of chunks) {
const chunk = new THREE.Mesh(
new THREE.DodecahedronGeometry(size, 0),
material
);
chunk.position.set(x, y, z);
chunk.rotation.set(x * 2, z * 3, y);
chunk.castShadow = true;
parent.add(chunk);
}
}
function createVent(parent, blocked) {
const vent = new THREE.Group();
parent.add(vent);
const stateMaterial = blocked
? materials.blocked
: materials.open;
// Hood frame around the exterior outlet.
addBox(
vent,
new THREE.Vector3(0.16, 0.07, 0.62),
new THREE.Vector3(1.49, 2.34, 0.35),
materials.metal
);
addBox(
vent,
new THREE.Vector3(0.16, 0.07, 0.62),
new THREE.Vector3(1.49, 1.90, 0.35),
materials.metal
);
addBox(
vent,
new THREE.Vector3(0.16, 0.44, 0.07),
new THREE.Vector3(1.49, 2.12, 0.075),
materials.metal
);
addBox(
vent,
new THREE.Vector3(0.16, 0.44, 0.07),
new THREE.Vector3(1.49, 2.12, 0.625),
materials.metal
);
// Small mounting bracket.
addBox(
vent,
new THREE.Vector3(0.10, 0.16, 0.44),
new THREE.Vector3(1.34, 1.77, 0.35),
materials.frameLight
);
if (blocked) {
// Solid plate closes the outlet.
addBox(
vent,
new THREE.Vector3(0.085, 0.39, 0.50),
new THREE.Vector3(1.435, 2.12, 0.35),
materials.blocked
);
// A plug interrupts the conduit before the grille.
addCylinder(
vent,
0.135,
0.13,
new THREE.Vector3(1.25, 2.12, 0.35),
materials.blocked,
new THREE.Euler(0, 0, Math.PI / 2),
8
);
// Low-poly X mark on the solid closure.
const xBarA = addBox(
vent,
new THREE.Vector3(0.035, 0.40, 0.05),
new THREE.Vector3(1.49, 2.12, 0.35),
materials.paper || materials.metal,
new THREE.Euler(0.75, 0, 0)
);
const xBarB = addBox(
vent,
new THREE.Vector3(0.035, 0.40, 0.05),
new THREE.Vector3(1.49, 2.12, 0.35),
materials.metal,
new THREE.Euler(-0.75, 0, 0)
);
xBarA.material = materials.metal;
} else {
// Three separated louvers leave visible open gaps.
for (const y of [1.99, 2.12, 2.25]) {
addBox(
vent,
new THREE.Vector3(0.12, 0.045, 0.50),
new THREE.Vector3(1.50, y, 0.35),
materials.metal
);
}
}
// Colored status tab makes the comparison immediately legible.
addBox(
vent,
new THREE.Vector3(0.08, 0.11, 0.24),
new THREE.Vector3(1.54, 1.77, 0.35),
stateMaterial
);
return vent;
}
function createCutEdges(parent) {
const group = new THREE.Group();
parent.add(group);
const vertices = [];
const segments = [
[-0.45, 0.44, 0.89, -0.45, 2.40, 0.89],
[-1.20, 2.40, 0.89, -0.45, 2.40, 0.89],
[1.20, 0.44, -0.15, 1.20, 2.40, -0.15],
[1.20, 2.40, -0.15, 1.20, 2.40, 0.89]
];
for (const segment of segments) {
vertices.push(...segment);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
const lines = new THREE.LineSegments(geometry, materials.cut);
group.add(lines);
return group;
}
function createBin(xPosition, blocked) {
const group = new THREE.Group();
group.position.x = xPosition;
scene.add(group);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.72, 1.80, 0.14, 8),
materials.pedestal
);
pedestal.position.y = 0.0;
pedestal.receiveShadow = true;
group.add(pedestal);
// Base tray.
addBox(
group,
new THREE.Vector3(2.58, 0.22, 2.02),
new THREE.Vector3(0, 0.22, 0),
materials.tray
);
addBox(
group,
new THREE.Vector3(2.35, 0.06, 1.80),
new THREE.Vector3(0, 0.36, 0),
materials.frameLight
);
// Four corner posts.
for (const x of [-1.20, 1.20]) {
for (const z of [-0.89, 0.89]) {
addBox(
group,
new THREE.Vector3(0.105, 2.17, 0.105),
new THREE.Vector3(x, 1.42, z),
materials.frame
);
addBox(
group,
new THREE.Vector3(0.18, 0.11, 0.18),
new THREE.Vector3(x, 0.40, z),
materials.frameLight
);
}
}
// Top and lower perimeter rails.
addBox(
group,
new THREE.Vector3(2.50, 0.11, 0.11),
new THREE.Vector3(0, 2.48, -0.89),
materials.frame
);
addBox(
group,
new THREE.Vector3(2.50, 0.11, 0.11),
new THREE.Vector3(0, 2.48, 0.89),
materials.frame
);
addBox(
group,
new THREE.Vector3(0.11, 0.11, 1.88),
new THREE.Vector3(-1.20, 2.48, 0),
materials.frame
);
addBox(
group,
new THREE.Vector3(0.11, 0.11, 1.88),
new THREE.Vector3(1.20, 2.48, 0),
materials.frame
);
// Perforated walls.
makeLatticePanel(
group,
2.35,
1.95,
6,
5,
new THREE.Vector3(0, 1.42, -0.89)
);
makeLatticePanel(
group,
1.72,
1.95,
4,
5,
new THREE.Vector3(-1.20, 1.42, 0),
Math.PI / 2,
materials.wallDark
);
makeLatticePanel(
group,
0.72,
1.95,
2,
5,
new THREE.Vector3(1.20, 1.42, -0.525),
Math.PI / 2,
materials.wallDark
);
// These pieces are removed in cutaway mode.
const cutawayHidden = new THREE.Group();
group.add(cutawayHidden);
makeLatticePanel(
cutawayHidden,
1.62,
1.95,
4,
5,
new THREE.Vector3(0.38, 1.42, 0.89)
);
makeLatticePanel(
cutawayHidden,
1.02,
1.95,
3,
5,
new THREE.Vector3(1.20, 1.42, 0.375),
Math.PI / 2,
materials.wallDark
);
createCompost(group);
// Connected internal duct network.
const ductGroup = new THREE.Group();
group.add(ductGroup);
const pipeSegments = [
[[-0.72, 0.49, -0.40], [0.58, 0.49, -0.40]],
[[0.58, 0.49, -0.40], [0.58, 0.49, 0.50]],
[[-0.72, 0.49, -0.40], [-0.72, 0.49, 0.50]],
[[0.58, 0.49, -0.40], [0.58, 2.12, -0.40]],
[[0.58, 2.12, -0.40], [0.58, 2.12, 0.35]],
[[0.58, 2.12, 0.35], [1.43, 2.12, 0.35]]
];
for (const [a, b] of pipeSegments) {
addPipeSegment(ductGroup, a, b);
}
for (const joint of [
[-0.72, 0.49, -0.40],
[0.58, 0.49, -0.40],
[0.58, 0.49, 0.50],
[0.58, 2.12, -0.40],
[0.58, 2.12, 0.35]
]) {
addPipeJoint(ductGroup, joint);
}
createVent(group, blocked);
const cutEdges = createCutEdges(group);
cutEdges.visible = true;
const routeGroup = new THREE.Group();
group.add(routeGroup);
const openRoute = [
new THREE.Vector3(-0.72, 0.49, -0.40),
new THREE.Vector3(0.58, 0.49, -0.40),
new THREE.Vector3(0.58, 2.12, -0.40),
new THREE.Vector3(0.58, 2.12, 0.35),
new THREE.Vector3(1.92, 2.12, 0.35)
];
const blockedRoute = [
new THREE.Vector3(-0.72, 0.49, -0.40),
new THREE.Vector3(0.58, 0.49, -0.40),
new THREE.Vector3(0.58, 2.12, -0.40),
new THREE.Vector3(0.58, 2.12, 0.35),
new THREE.Vector3(1.23, 2.12, 0.35)
];
const routeColor = blocked ? "#b8563d" : "#2bb9a8";
createRouteMarkers(
routeGroup,
blocked ? blockedRoute : openRoute,
routeColor,
blocked ? 23 : 30,
!blocked
);
return {
group,
cutawayHidden,
cutEdges,
routeGroup,
blocked
};
}
function createRouteMarkers(
parent,
points,
color,
count,
moving
) {
const lengths = [];
let totalLength = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
totalLength += length;
}
const markerGeometry = new THREE.SphereGeometry(0.035, 6, 4);
const markerMaterial = new THREE.MeshBasicMaterial({ color });
function samplePath(distance) {
let remaining = distance;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i] || i === lengths.length - 1) {
const t = Math.min(1, remaining / lengths[i]);
return new THREE.Vector3().lerpVectors(
points[i],
points[i + 1],
t
);
}
remaining -= lengths[i];
}
return points[points.length - 1].clone();
}
for (let i = 0; i < count; i++) {
const baseT = count === 1 ? 0 : i / (count - 1);
const marker = new THREE.Mesh(
markerGeometry,
markerMaterial
);
marker.position.copy(samplePath(baseT * totalLength));
marker.userData.baseT = baseT;
marker.userData.moving = moving;
marker.userData.totalLength = totalLength;
parent.add(marker);
routeMarkers.push(marker);
}
}
const openBin = createBin(-2.25, false);
const blockedBin = createBin(2.25, true);
bins.push(openBin, blockedBin);
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
// Custom orbit, pan, wheel zoom, and touch controls.
const canvas = renderer.domElement;
const pointers = new Map();
let dragMode = "orbit";
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
if (pointers.size === 1) {
dragMode =
event.shiftKey || event.button === 2 || event.button === 1
? "pan"
: "orbit";
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
dragMode = "pinch";
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (dragMode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.15,
1.30
);
} else if (dragMode === "pan") {
panCamera(dx, dy);
}
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2 && dragMode === "pinch") {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
const scale = previousPinchDistance / distance;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * scale,
5.5,
17
);
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
previousX = remaining.x;
previousY = remaining.y;
dragMode = "orbit";
}
if (pointers.size === 0) {
canvas.classList.remove("dragging");
dragMode = "orbit";
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
5.5,
17
);
},
{ passive: false }
);
function panCamera(dx, dy) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const scale = cameraState.radius * 0.00145;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-5,
5
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
0,
4
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-4,
4
);
}
let cutawayEnabled = true;
let routesEnabled = true;
const cutawayButton = document.getElementById("cutaway");
const routeButton = document.getElementById("route");
const resetButton = document.getElementById("reset");
cutawayButton.addEventListener("click", () => {
cutawayEnabled = !cutawayEnabled;
for (const bin of bins) {
bin.cutawayHidden.visible = !cutawayEnabled;
bin.cutEdges.visible = cutawayEnabled;
}
cutawayButton.setAttribute(
"aria-pressed",
String(cutawayEnabled)
);
cutawayButton.textContent = cutawayEnabled
? "Cutaway on"
: "Cutaway off";
});
routeButton.addEventListener("click", () => {
routesEnabled = !routesEnabled;
for (const bin of bins) {
bin.routeGroup.visible = routesEnabled;
}
routeButton.setAttribute("aria-pressed", String(routesEnabled));
routeButton.textContent = routesEnabled
? "Route markers on"
: "Route markers off";
});
resetButton.addEventListener("click", () => {
cameraState.target.set(0, 1.15, 0);
cameraState.radius = 10.7;
cameraState.theta = 0.53;
cameraState.phi = 0.42;
updateCamera();
});
const openModelLabel = document.getElementById("openModelLabel");
const blockedModelLabel = document.getElementById("blockedModelLabel");
const openVentLabel = document.getElementById("openVentLabel");
const blockedVentLabel = document.getElementById("blockedVentLabel");
function positionDOMLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
positionDOMLabel(
openModelLabel,
new THREE.Vector3(-2.25, 2.82, 0)
);
positionDOMLabel(
blockedModelLabel,
new THREE.Vector3(2.25, 2.82, 0)
);
positionDOMLabel(
openVentLabel,
new THREE.Vector3(-0.72, 2.54, 0.35)
);
positionDOMLabel(
blockedVentLabel,
new THREE.Vector3(3.78, 2.54, 0.35)
);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
if (routesEnabled && !reducedMotion) {
for (const marker of routeMarkers) {
if (!marker.userData.moving) continue;
const t =
(marker.userData.baseT + elapsed * 0.085) % 1;
// The path is sampled from the same polyline used when creating it.
// Using a temporary route lookup keeps the animation lightweight.
const route = marker.parent.parent.blocked
? [
[-0.72, 0.49, -0.40],
[0.58, 0.49, -0.40],
[0.58, 2.12, -0.40],
[0.58, 2.12, 0.35],
[1.23, 2.12, 0.35]
]
: [
[-0.72, 0.49, -0.40],
[0.58, 0.49, -0.40],
[0.58, 2.12, -0.40],
[0.58, 2.12, 0.35],
[1.92, 2.12, 0.35]
];
const vectors = route.map((p) => new THREE.Vector3(...p));
const lengths = [];
let total = 0;
for (let i = 0; i < vectors.length - 1; i++) {
const length = vectors[i].distanceTo(vectors[i + 1]);
lengths.push(length);
total += length;
}
let remaining = t * total;
let found = false;
for (let i = 0; i < lengths.length; i++) {
if (
remaining <= lengths[i] ||
i === lengths.length - 1
) {
const segmentT = Math.min(
1,
remaining / lengths[i]
);
marker.position.lerpVectors(
vectors[i],
vectors[i + 1],
segmentT
);
found = true;
break;
}
remaining -= lengths[i];
}
if (!found) marker.position.copy(vectors.at(-1));
}
}
scene.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```