Prompt specification
Build or customize the Three.js 3D scene "Disconnect one belt and trace remaining power paths" 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: Disconnect one belt and trace remaining power paths
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/disconnect-one-belt-and-trace-remaining-power-paths-x2540
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows steam engines and mechanical power transmission. Let users disengage a machine belt in the workshop. Stop that machine while the engine and other connected equipment continue, showing the topology of mechanical power distribution. Voxel style.
Working Three.js Starter (disconnect-one-belt-and-trace-remaining-power-paths-x2540):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Steamworks — Mechanical Power Distribution</title>
<style>
:root {
--ink: #101820;
--panel: rgba(17, 24, 32, 0.92);
--panel-light: rgba(31, 43, 54, 0.92);
--line: rgba(220, 232, 236, 0.18);
--cream: #efe8d6;
--muted: #9aabb2;
--amber: #f4b942;
--green: #69db9b;
--red: #ff665b;
--cyan: #6cd6df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101820;
color: var(--cream);
font-family: "Courier New", Courier, monospace;
}
body {
user-select: none;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow:
0 12px 35px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(10px);
}
.masthead {
position: absolute;
top: 22px;
left: 22px;
min-width: 310px;
padding: 17px 19px 16px;
border-left: 4px solid var(--amber);
}
.eyebrow {
margin-bottom: 8px;
color: var(--amber);
font-size: 10px;
font-weight: bold;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.2vw, 31px);
line-height: 1;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.subtitle {
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.drive-panel {
position: absolute;
top: 22px;
right: 22px;
width: 286px;
padding: 16px;
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: bold;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-lamp {
width: 9px;
height: 9px;
flex: 0 0 auto;
background: var(--green);
box-shadow: 0 0 12px rgba(105, 219, 155, 0.85);
}
.status-lamp.off {
background: var(--red);
box-shadow: 0 0 12px rgba(255, 102, 91, 0.9);
}
.drive-title {
margin-bottom: 5px;
font-size: 16px;
font-weight: bold;
letter-spacing: 0.025em;
text-transform: uppercase;
}
.drive-copy {
min-height: 34px;
margin-bottom: 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
button {
width: 100%;
min-height: 43px;
border: 0;
border-radius: 0;
padding: 11px 12px;
background: var(--amber);
color: #1b1710;
cursor: pointer;
font: bold 11px "Courier New", Courier, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
transition:
background 160ms ease,
transform 100ms ease,
box-shadow 160ms ease;
}
button:hover {
background: #ffd16c;
box-shadow: 0 0 0 3px rgba(244, 185, 66, 0.13);
}
button:active {
transform: translateY(1px);
}
button.disconnected {
background: var(--red);
color: #fff3f0;
}
button.disconnected:hover {
background: #ff7d73;
box-shadow: 0 0 0 3px rgba(255, 102, 91, 0.15);
}
.button-note {
margin-top: 9px;
color: #778a92;
font-size: 9px;
line-height: 1.4;
text-align: center;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.topology {
position: absolute;
right: 22px;
bottom: 22px;
left: 22px;
padding: 13px 17px 14px;
}
.topology-heading {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: bold;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.topology-map {
display: flex;
align-items: center;
gap: 14px;
min-height: 57px;
}
.topo-source {
display: flex;
align-items: center;
gap: 10px;
}
.topo-node {
position: relative;
min-width: 126px;
padding: 9px 12px;
border: 1px solid rgba(105, 219, 155, 0.42);
background: rgba(105, 219, 155, 0.06);
color: var(--cream);
font-size: 10px;
font-weight: bold;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.topo-node::before {
content: "";
position: absolute;
top: 6px;
right: 6px;
width: 5px;
height: 5px;
background: var(--green);
box-shadow: 0 0 8px rgba(105, 219, 155, 0.7);
}
.topo-node small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
font-weight: normal;
letter-spacing: 0.08em;
}
.topo-node.disconnected {
border-color: rgba(255, 102, 91, 0.65);
background: rgba(255, 102, 91, 0.08);
}
.topo-node.disconnected::before {
background: var(--red);
box-shadow: 0 0 8px rgba(255, 102, 91, 0.85);
}
.topo-node.disconnected small {
color: #ff9189;
}
.topo-link {
position: relative;
width: 50px;
height: 2px;
overflow: hidden;
background: rgba(105, 219, 155, 0.32);
}
.topo-link i {
position: absolute;
inset: 0 auto 0 -18px;
width: 18px;
background: var(--green);
animation: flow 1.2s linear infinite;
}
@keyframes flow {
to {
transform: translateX(68px);
}
}
.topo-fork {
position: relative;
width: 38px;
height: 52px;
border-left: 2px solid rgba(105, 219, 155, 0.42);
}
.topo-fork::before,
.topo-fork::after {
content: "";
position: absolute;
left: 0;
width: 22px;
height: 2px;
background: rgba(105, 219, 155, 0.42);
}
.topo-fork::before {
top: 10px;
}
.topo-fork::after {
bottom: 10px;
}
.topo-branches {
display: grid;
gap: 6px;
}
.topo-branches .topo-node {
min-width: 145px;
padding-top: 6px;
padding-bottom: 6px;
}
.hint {
position: absolute;
bottom: 121px;
left: 22px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
background: rgba(10, 15, 20, 0.7);
color: #91a3aa;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label {
position: fixed;
z-index: 8;
min-width: 104px;
padding: 7px 9px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.18);
background: rgba(12, 18, 24, 0.87);
box-shadow: 0 5px 14px rgba(0, 0, 0, 0.28);
color: var(--cream);
pointer-events: none;
text-align: center;
transition: opacity 120ms ease;
}
.world-label::after {
content: "";
position: absolute;
bottom: -7px;
left: 50%;
width: 1px;
height: 6px;
background: rgba(255, 255, 255, 0.4);
}
.world-label b {
display: block;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.world-label span {
display: block;
margin-top: 3px;
color: var(--green);
font-size: 8px;
letter-spacing: 0.07em;
}
.world-label.stopped span {
color: var(--red);
}
#loader {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #101820;
color: var(--amber);
font-size: 12px;
font-weight: bold;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loader.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.masthead {
top: 12px;
left: 12px;
min-width: 0;
max-width: calc(100vw - 24px);
padding: 12px 14px;
}
.subtitle {
display: none;
}
.drive-panel {
top: auto;
right: 12px;
bottom: 108px;
width: 225px;
padding: 12px;
}
.drive-copy,
.button-note {
display: none;
}
.drive-title {
font-size: 12px;
}
.topology {
right: 12px;
bottom: 12px;
left: 12px;
padding: 10px;
}
.topology-map {
gap: 6px;
}
.topo-source {
gap: 5px;
}
.topo-node {
min-width: 92px;
padding: 7px;
font-size: 8px;
}
.topo-branches .topo-node {
min-width: 98px;
}
.topo-link {
width: 20px;
}
.topo-fork {
width: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="hud">
<header class="panel masthead">
<div class="eyebrow">Steamworks / Bay 07</div>
<h1>Power Transmission</h1>
<div class="subtitle">
Live mechanical topology. Disconnect the press belt without stopping
the engine, main shaft, or pump.
</div>
</header>
<section class="panel drive-panel" aria-label="Belt controls">
<div class="panel-heading">
<span>Selected Machine</span>
<span id="beltLamp" class="status-lamp"></span>
</div>
<div class="drive-title">Stamping Press / Drive A</div>
<div id="beltDescription" class="drive-copy">
Belt engaged. The press receives power from the main shaft.
</div>
<button id="disconnectBtn" type="button">Disengage Machine Belt</button>
<div class="button-note">Or click the red workshop lever</div>
</section>
<section class="panel topology" aria-label="Mechanical power topology">
<div class="topology-heading">
<span>Live Power Topology</span>
<span>Engine remains the source</span>
</div>
<div class="topology-map">
<div class="topo-source">
<div class="topo-node">
Steam Engine
<small id="engineStatus">RUNNING · 142 RPM</small>
</div>
<div class="topo-link"><i></i></div>
<div class="topo-node">
Main Shaft
<small>RUNNING · 142 RPM</small>
</div>
</div>
<div class="topo-fork"></div>
<div class="topo-branches">
<div id="nodePress" class="topo-node">
Stamping Press
<small id="pressStatus">RUNNING · 142 RPM</small>
</div>
<div id="nodePump" class="topo-node">
Transfer Pump
<small>RUNNING · 142 RPM</small>
</div>
</div>
</div>
</section>
<div class="hint">
Drag to orbit · Scroll to zoom · Right-drag to pan · Click red lever
</div>
</div>
<div id="labelEngine" class="world-label">
<b>Steam Engine</b><span>142 RPM</span>
</div>
<div id="labelShaft" class="world-label">
<b>Main Shaft</b><span>Running</span>
</div>
<div id="labelPress" class="world-label">
<b>Stamping Press</b><span>142 RPM</span>
</div>
<div id="labelPump" class="world-label">
<b>Transfer Pump</b><span>142 RPM</span>
</div>
<div id="loader">Starting Steamworks…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const loader = document.getElementById("loader");
const renderer = new THREE.WebGLRenderer({
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;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101820);
scene.fog = new THREE.Fog(0x101820, 22, 43);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xc8e0eb, 0x403226, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfb4, 3.2);
sun.position.set(-7, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x78cbd7, 1.35);
rim.position.set(11, 8, -10);
scene.add(rim);
const workshopLight = new THREE.PointLight(0xffb95f, 28, 17, 2);
workshopLight.position.set(0, 7.5, 2);
scene.add(workshopLight);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.76,
metalness: options.metalness ?? 0.08,
flatShading: options.flatShading ?? true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
const M = {
floor: material(0x59636a, { roughness: 0.96, metalness: 0.02 }),
floorDark: material(0x303b43, { roughness: 0.95 }),
wall: material(0x3a4850, { roughness: 0.95 }),
wallDark: material(0x263239, { roughness: 0.95 }),
steel: material(0x77868b, { roughness: 0.42, metalness: 0.72 }),
darkSteel: material(0x28353d, { roughness: 0.54, metalness: 0.68 }),
iron: material(0x526168, { roughness: 0.6, metalness: 0.55 }),
cream: material(0xd6c9a9, { roughness: 0.86 }),
amber: material(0xe8a83b, { roughness: 0.6, metalness: 0.25 }),
red: material(0xb64135, { roughness: 0.62, metalness: 0.25 }),
teal: material(0x3f8f8d, { roughness: 0.68, metalness: 0.22 }),
belt: material(0x171d20, { roughness: 0.95, metalness: 0.02 }),
beltMark: material(0xf3b83e, { roughness: 0.62 }),
window: material(0x83bac5, {
roughness: 0.25,
metalness: 0.12,
emissive: 0x28525a,
emissiveIntensity: 0.45
}),
wood: material(0x826143, { roughness: 0.95 }),
green: material(0x4ebf78, {
emissive: 0x1e6b3b,
emissiveIntensity: 1.1
}),
warning: material(0xff5e4e, {
emissive: 0x7a1008,
emissiveIntensity: 1.1
})
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addBox(parent, size, position, mat, options = {}) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(...size);
mesh.position.set(...position);
mesh.castShadow = options.cast ?? true;
mesh.receiveShadow = options.receive ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
length,
position,
mat,
axis = "x",
segments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
mat
);
mesh.position.set(...position);
if (axis === "x") mesh.rotation.z = Math.PI / 2;
if (axis === "z") mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makePulley(radius, width, mat = M.darkSteel) {
const group = new THREE.Group();
addCylinder(group, radius, width, [0, 0, 0], M.belt, "x", 12);
addCylinder(group, radius * 0.68, width + 0.09, [0, 0, 0], mat, "x", 12);
addCylinder(group, radius * 0.2, width + 0.18, [0, 0, 0], M.steel, "x", 10);
const xAxis = new THREE.Vector3(1, 0, 0);
for (let i = 0; i < 4; i++) {
const angle = (i * Math.PI) / 2;
const radial = new THREE.Vector3(0, Math.cos(angle), Math.sin(angle));
const spoke = addBox(
group,
[radius * 1.58, 0.12, 0.16],
[0, 0, 0],
M.steel
);
spoke.quaternion.setFromUnitVectors(xAxis, radial);
}
for (let i = 0; i < 8; i++) {
const angle = (i * Math.PI * 2) / 8;
addBox(
group,
[width + 0.12, 0.12, 0.12],
[0, Math.cos(angle) * radius * 0.79, Math.sin(angle) * radius * 0.79],
M.amber
);
}
addBox(
group,
[width + 0.15, radius * 0.26, 0.15],
[0, radius * 0.74, 0],
M.beltMark
);
return group;
}
// -------------------------------------------------------------------------
// Workshop environment
// -------------------------------------------------------------------------
const workshop = new THREE.Group();
scene.add(workshop);
addBox(workshop, [29, 0.45, 16], [0, -0.27, 0], M.floor, {
cast: false
});
for (let x = -14; x <= 14; x += 2) {
addBox(
workshop,
[0.035, 0.015, 16],
[x, -0.035, 0],
M.floorDark,
{ cast: false }
);
}
for (let z = -8; z <= 8; z += 2) {
addBox(
workshop,
[29, 0.015, 0.035],
[0, -0.035, z],
M.floorDark,
{ cast: false }
);
}
addBox(workshop, [29, 8.5, 0.35], [0, 4.05, -5.65], M.wall, {
cast: false
});
addBox(workshop, [0.35, 8.5, 16], [-14.3, 4.05, 2], M.wallDark, {
cast: false
});
for (let x = -12; x <= 12; x += 4) {
addBox(workshop, [0.28, 8.2, 0.42], [x, 4.1, -5.4], M.wallDark, {
cast: false
});
}
for (let y = 1; y < 8; y += 1.2) {
addBox(
workshop,
[28.5, 0.035, 0.03],
[0, y, -5.44],
M.wallDark,
{ cast: false }
);
}
for (const x of [-9, -3, 3, 9]) {
addBox(workshop, [3.4, 2.7, 0.16], [x, 4.55, -5.35], M.darkSteel, {
cast: false
});
addBox(workshop, [3.05, 2.35, 0.12], [x, 4.55, -5.2], M.window, {
cast: false
});
addBox(workshop, [0.12, 2.45, 0.16], [x, 4.55, -5.08], M.darkSteel, {
cast: false
});
addBox(workshop, [3.15, 0.12, 0.16], [x, 4.55, -5.08], M.darkSteel, {
cast: false
});
}
// Safety paint around machine bays.
const paint = material(0xd7a84a, { roughness: 0.9 });
for (const [x, width] of [[-8.1, 5.7], [0.2, 4.4], [4.8, 4.4]]) {
addBox(
workshop,
[width, 0.025, 0.11],
[x, 0.005, 2.75],
paint,
{ cast: false }
);
addBox(
workshop,
[width, 0.025, 0.11],
[x, 0.005, -3.25],
paint,
{ cast: false }
);
}
// Background shelving and crates.
for (const x of [-11, 10.5]) {
addBox(workshop, [3.2, 0.16, 1.2], [x, 1.2, -4.75], M.wood);
addBox(workshop, [3.2, 0.16, 1.2], [x, 2.55, -4.75], M.wood);
addBox(workshop, [0.16, 3.4, 0.16], [x - 1.4, 1.8, -4.75], M.darkSteel);
addBox(workshop, [0.16, 3.4, 0.16], [x + 1.4, 1.8, -4.75], M.darkSteel);
for (let i = 0; i < 4; i++) {
addBox(
workshop,
[0.55, 0.55, 0.62],
[x - 1 + i * 0.65, 2.94, -4.7],
i % 2 ? M.wood : M.amber
);
}
}
// Block-style ceiling lamps.
for (const x of [-8, 0, 8]) {
addBox(workshop, [1.5, 0.16, 0.75], [x, 7.35, -0.6], M.darkSteel);
addBox(
workshop,
[1.25, 0.08, 0.52],
[x, 7.22, -0.6],
material(0xffd889, {
emissive: 0xff9d35,
emissiveIntensity: 1.25
})
);
}
// -------------------------------------------------------------------------
// Main overhead shaft and supports
// -------------------------------------------------------------------------
const shaftY = 5.15;
const shaftZ = 0;
addCylinder(
scene,
0.12,
14.7,
[0.35, shaftY, shaftZ],
M.steel,
"x",
12
);
for (const x of [-5.1, 4.55, 8.25]) {
addBox(scene, [0.28, 5.1, 0.3], [x, 2.55, -0.68], M.darkSteel);
addBox(scene, [0.75, 0.25, 1.05], [x, 5.03, -0.38], M.steel);
addBox(scene, [0.6, 0.18, 0.85], [x, 0.12, -0.65], M.darkSteel);
}
const shaftCoupler = new THREE.Group();
shaftCoupler.position.set(-4.65, shaftY, shaftZ);
scene.add(shaftCoupler);
addCylinder(shaftCoupler, 0.28, 1.05, [0, 0, 0], M.amber, "x", 12);
for (let i = 0; i < 4; i++) {
const angle = (i * Math.PI) / 2;
addBox(
shaftCoupler,
[0.9, 0.13, 0.48],
[0, Math.cos(angle) * 0.21, Math.sin(angle) * 0.21],
M.darkSteel
);
}
// -------------------------------------------------------------------------
// Steam engine
// -------------------------------------------------------------------------
const engine = new THREE.Group();
engine.position.set(-8, 0, -0.6);
scene.add(engine);
addBox(engine, [4.8, 0.48, 3.8], [0, 0.3, 0], M.darkSteel);
addBox(engine, [4.25, 0.18, 3.3], [0, 0.63, 0], M.iron);
addCylinder(engine, 0.78, 3.35, [-0.45, 2, -0.72], M.iron, "x", 10);
addBox(engine, [2.35, 1.2, 1.55], [-0.75, 1.65, -0.85], M.teal);
addBox(engine, [2.6, 0.28, 1.75], [-0.75, 2.32, -0.85], M.steel);
addBox(engine, [0.7, 2.55, 0.7], [-1.25, 3.15, -1.25], M.darkSteel);
addBox(engine, [0.92, 0.3, 0.92], [-1.25, 4.53, -1.25], M.iron);
addBox(engine, [0.58, 0.24, 0.58], [-1.25, 4.78, -1.25], M.belt);
addCylinder(engine, 0.22, 1.2, [0.85, 3.55, -0.8], M.brass || M.amber, "y", 10);
addBox(engine, [1.2, 0.18, 0.18], [0.65, 4.12, -0.8], M.amber);
const engineFlywheel = makePulley(0.95, 0.4, M.red);
engineFlywheel.position.set(1.55, 1.65, 0);
engine.add(engineFlywheel);
const primaryShaftPulley = makePulley(0.95, 0.35, M.amber);
primaryShaftPulley.position.set(-6.45, shaftY, shaftZ);
scene.add(primaryShaftPulley);
const engineLamp = addBox(
engine,
[0.18, 0.18, 0.18],
[0.85, 2.65, 0.04],
M.green
);
// -------------------------------------------------------------------------
// Stamping press
// -------------------------------------------------------------------------
const press = new THREE.Group();
press.position.set(0.2, 0, -0.6);
scene.add(press);
addBox(press, [3.55, 0.5, 3.45], [0, 0.3, 0], M.darkSteel);
addBox(press, [3.15, 0.18, 3.05], [0, 0.64, 0], M.iron);
for (const x of [-1.25, 1.25]) {
for (const z of [-1.1, 1.1]) {
addBox(press, [0.36, 3.5, 0.36], [x, 2.25, z], M.teal);
}
}
addBox(press, [3.25, 0.65, 2.85], [0, 4.16, 0], M.teal);
addBox(press, [2.8, 0.2, 2.4], [0, 3.77, 0], M.steel);
addBox(press, [1.85, 0.46, 1.65], [0, 1.05, 0], M.darkSteel);
const pressRam = new THREE.Group();
pressRam.position.set(0, 2.75, 0);
press.add(pressRam);
addBox(pressRam, [1.65, 1.05, 1.45], [0, 0, 0], M.steel);
addBox(pressRam, [1.85, 0.25, 1.65], [0, -0.62, 0], M.darkSteel);
const pressWheel = makePulley(0.62, 0.34, M.red);
pressWheel.position.set(2, 1.35, 0);
press.add(pressWheel);
const pressUpperPulley = makePulley(0.62, 0.34, M.amber);
pressUpperPulley.position.set(2.2, shaftY, shaftZ);
scene.add(pressUpperPulley);
const pressLampMaterial = M.green.clone();
const pressLamp = addBox(
press,
[0.2, 0.2, 0.2],
[1.25, 3.73, 1.48],
pressLampMaterial
);
// -------------------------------------------------------------------------
// Transfer pump
// -------------------------------------------------------------------------
const pump = new THREE.Group();
pump.position.set(4.8, 0, -0.6);
scene.add(pump);
addBox(pump, [3.6, 0.5, 3.2], [0, 0.3, 0], M.darkSteel);
addBox(pump, [3.1, 0.18, 2.75], [0, 0.64, 0], M.iron);
addBox(pump, [2.65, 1.4, 2.2], [-0.25, 1.55, -0.25], M.teal);
addBox(pump, [1.3, 0.65, 1.3], [-0.8, 2.55, -0.25], M.steel);
addCylinder(pump, 0.38, 1.25, [0.75, 2.2, 0.2], M.amber, "y", 10);
addCylinder(pump, 0.16, 1.2, [0.75, 3.15, 0.2], M.steel, "y", 10);
addBox(pump, [0.65, 0.16, 0.65], [0.75, 3.76, 0.2], M.darkSteel);
const pumpPiston = new THREE.Group();
pumpPiston.position.set(0.75, 3.25, 0.2);
pump.add(pumpPiston);
addBox(pumpPiston, [0.75, 0.3, 0.75], [0, 0, 0], M.amber);
const pumpWheel = makePulley(0.62, 0.34, M.red);
pumpWheel.position.set(2, 1.35, 0);
pump.add(pumpWheel);
const pumpUpperPulley = makePulley(0.62, 0.34, M.amber);
pumpUpperPulley.position.set(6.8, shaftY, shaftZ);
scene.add(pumpUpperPulley);
const pumpLamp = addBox(
pump,
[0.2, 0.2, 0.2],
[0.8, 2.97, 0.94],
M.green
);
// -------------------------------------------------------------------------
// Belt geometry
// Each belt lies in a Y/Z plane and turns around X-axis pulleys.
// -------------------------------------------------------------------------
function createBeltPath(a, b, radius) {
const ah = a.z;
const av = a.y;
const bh = b.z;
const bv = b.y;
const dx = bh - ah;
const dy = bv - av;
const distance = Math.hypot(dx, dy);
const ux = dx / distance;
const uy = dy / distance;
const px = -uy;
const py = ux;
const theta = Math.atan2(py, px);
const points = [];
const lineSteps = 5;
const arcSteps = 14;
for (let i = 0; i <= lineSteps; i++) {
const t = i / lineSteps;
points.push({
h: ah + px * radius + (bh + px * radius - ah - px * radius) * t,
v: av + py * radius + (bv + py * radius - av - py * radius) * t
});
}
for (let i = 1; i <= arcSteps; i++) {
const angle = theta - (Math.PI * i) / arcSteps;
points.push({
h: bh + Math.cos(angle) * radius,
v: bv + Math.sin(angle) * radius
});
}
for (let i = 1; i <= lineSteps; i++) {
const t = i / lineSteps;
points.push({
h: bh - px * radius + (ah - px * radius - bh + px * radius) * t,
v: bv - py * radius + (av - py * radius - bv + py * radius) * t
});
}
for (let i = 1; i <= arcSteps; i++) {
const angle = theta - Math.PI - (Math.PI * i) / arcSteps;
points.push({
h: ah + Math.cos(angle) * radius,
v: av + Math.sin(angle) * radius
});
}
const cumulative = [0];
let total = 0;
for (let i = 1; i < points.length; i++) {
total += Math.hypot(
points[i].h - points[i - 1].h,
points[i].v - points[i - 1].v
);
cumulative.push(total);
}
function sample(distanceAlongPath) {
const d = ((distanceAlongPath % total) + total) % total;
let index = 1;
while (index < cumulative.length - 1 && cumulative[index] < d) {
index++;
}
const start = points[index - 1];
const end = points[index];
const segmentLength = cumulative[index] - cumulative[index - 1];
const t = segmentLength > 0 ? (d - cumulative[index - 1]) / segmentLength : 0;
const h = THREE.MathUtils.lerp(start.h, end.h, t);
const v = THREE.MathUtils.lerp(start.v, end.v, t);
const th = end.h - start.h;
const tv = end.v - start.v;
const tangentLength = Math.hypot(th, tv) || 1;
return {
point: new THREE.Vector3(a.x, v, h),
tangent: new THREE.Vector3(0, tv / tangentLength, th / tangentLength)
};
}
return { points, cumulative, total, sample };
}
function orientBeltPart(mesh, tangent) {
const normal = new THREE.Vector3(1, 0, 0);
const inPlane = new THREE.Vector3().crossVectors(normal, tangent).normalize();
const basis = new THREE.Matrix4().makeBasis(tangent, inPlane, normal);
mesh.quaternion.setFromRotationMatrix(basis);
}
function createBelt(a, b, radius, markerColor = M.beltMark) {
const group = new THREE.Group();
scene.add(group);
const path = createBeltPath(a, b, radius);
for (let i = 0; i < path.points.length - 1; i++) {
const p1 = path.points[i];
const p2 = path.points[i + 1];
const y1 = p1.v;
const z1 = p1.h;
const y2 = p2.v;
const z2 = p2.h;
const length = Math.hypot(y2 - y1, z2 - z1);
const tangent = new THREE.Vector3(0, y2 - y1, z2 - z1).normalize();
const segment = addBox(
group,
[length + 0.025, 0.18, 0.1],
[a.x, (y1 + y2) / 2, (z1 + z2) / 2],
M.belt
);
orientBeltPart(segment, tangent);
}
const markers = [];
for (let i = 0; i < 12; i++) {
const marker = addBox(
group,
[0.2, 0.25, 0.14],
[a.x, 0, 0],
markerColor
);
markers.push(marker);
}
return {
group,
path,
markers,
phase: 0,
update(motion = 1) {
this.phase = (this.phase + motion * this.path.total * 0.055) % this.path.total;
for (let i = 0; i < this.markers.length; i++) {
const distance = this.phase + (i / this.markers.length) * this.path.total;
const sample = this.path.sample(distance);
this.markers[i].position.copy(sample.point);
orientBeltPart(this.markers[i], sample.tangent);
}
}
};
}
const primaryBelt = createBelt(
{ x: -6.45, y: 1.65, z: 0 },
{ x: -6.45, y: shaftY, z: 0 },
0.93
);
const pressBelt = createBelt(
{ x: 2.2, y: 1.35, z: 0 },
{ x: 2.2, y: shaftY, z: 0 },
0.6
);
const pumpBelt = createBelt(
{ x: 6.8, y: 1.35, z: 0 },
{ x: 6.8, y: shaftY, z: 0 },
0.6
);
// -------------------------------------------------------------------------
// Belt disengagement lever
// -------------------------------------------------------------------------
const leverPivot = new THREE.Group();
leverPivot.position.set(2.2, shaftY, 0.82);
scene.add(leverPivot);
addCylinder(leverPivot, 0.22, 0.34, [0, 0, 0], M.darkSteel, "x", 10);
const leverHandleMaterial = M.red.clone();
const leverHandle = addBox(
leverPivot,
[0.18, 0.18, 0.9],
[0, 0, 0.42],
leverHandleMaterial
);
const leverHitbox = addBox(
scene,
[0.85, 0.9, 1.2],
[2.2, shaftY, 0.85],
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
}),
{ cast: false, receive: false }
);
// -------------------------------------------------------------------------
// Voxel steam
// -------------------------------------------------------------------------
const steam = [];
for (let i = 0; i < 11; i++) {
const size = 0.22 + (i % 3) * 0.055;
const puff = addBox(
scene,
[size, size, size],
[-9.25, 5, -1.85],
new THREE.MeshStandardMaterial({
color: 0xc7d1d2,
roughness: 1,
transparent: true,
opacity: 0.4,
depthWrite: false
}),
{ cast: false, receive: false }
);
steam.push(puff);
}
// -------------------------------------------------------------------------
// Interaction state and UI
// -------------------------------------------------------------------------
let pressDisconnected = false;
let pressSpeed = 1;
let engineAngle = 0;
let shaftAngle = 0;
let pressAngle = 0;
let pumpAngle = 0;
let hoveredLever = false;
const disconnectButton = document.getElementById("disconnectBtn");
const beltLamp = document.getElementById("beltLamp");
const beltDescription = document.getElementById("beltDescription");
const pressStatus = document.getElementById("pressStatus");
const pressNode = document.getElementById("nodePress");
const pressLabel = document.getElementById("labelPress");
function setPressDisconnected(disconnected) {
pressDisconnected = disconnected;
disconnectButton.textContent = disconnected
? "Re-engage Machine Belt"
: "Disengage Machine Belt";
disconnectButton.classList.toggle("disconnected", disconnected);
beltLamp.classList.toggle("off", disconnected);
pressNode.classList.toggle("disconnected", disconnected);
pressLabel.classList.toggle("stopped", disconnected);
if (disconnected) {
beltDescription.textContent =
"Belt disengaged. The press coasts to a stop while the engine, main shaft, and pump continue.";
} else {
beltDescription.textContent =
"Belt engaged. The press receives power from the main shaft.";
}
updateStatusText();
}
function updateStatusText() {
const rpm = Math.round(142 * pressSpeed);
pressStatus.textContent = pressDisconnected
? `BELT OFF · ${rpm} RPM`
: `RUNNING · ${rpm} RPM`;
pressLabel.querySelector("span").textContent = pressDisconnected
? `Stopped · ${rpm} RPM`
: `${rpm} RPM`;
}
disconnectButton.addEventListener("click", () => {
setPressDisconnected(!pressDisconnected);
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan and zoom
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 2.45, -0.1);
let cameraYaw = 0.58;
let cameraPitch = 1.13;
let cameraDistance = 23.5;
function applyCamera() {
const horizontal = Math.sin(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + Math.cos(cameraPitch) * cameraDistance,
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
applyCamera();
let pointerDown = false;
let pointerButton = 0;
let pointerX = 0;
let pointerY = 0;
let totalPointerTravel = 0;
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
const interactiveObjects = [leverHandle, leverHitbox];
function setPointerNdc(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function leverIsHovered(event) {
setPointerNdc(event);
raycaster.setFromCamera(pointerNdc, camera);
return raycaster.intersectObjects(interactiveObjects, false).length > 0;
}
function updateLeverHover(isHovered) {
if (hoveredLever === isHovered) return;
hoveredLever = isHovered;
renderer.domElement.style.cursor = isHovered ? "pointer" : "grab";
leverHandleMaterial.emissive.setHex(isHovered ? 0x5d0c05 : 0x000000);
leverHandleMaterial.emissiveIntensity = isHovered ? 0.8 : 0;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerButton = event.button;
pointerX = event.clientX;
pointerY = event.clientY;
totalPointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) {
updateLeverHover(leverIsHovered(event));
return;
}
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
totalPointerTravel += Math.abs(dx) + Math.abs(dy);
if (pointerButton === 2) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
cameraTarget.addScaledVector(right, -dx * cameraDistance * 0.0015);
cameraTarget.addScaledVector(up, dy * cameraDistance * 0.0015);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -10, 10);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 0.5, 6);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -5, 5);
} else {
cameraYaw -= dx * 0.005;
cameraPitch = THREE.MathUtils.clamp(cameraPitch - dy * 0.005, 0.48, 1.43);
}
applyCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (
pointerDown &&
pointerButton === 0 &&
totalPointerTravel < 7 &&
leverIsHovered(event)
) {
setPressDisconnected(!pressDisconnected);
}
pointerDown = false;
updateLeverHover(leverIsHovered(event));
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) updateLeverHover(false);
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.012,
12,
34
);
applyCamera();
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// Projected world labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("labelEngine"),
anchor: new THREE.Vector3(-8.2, 4.65, -0.65)
},
{
element: document.getElementById("labelShaft"),
anchor: new THREE.Vector3(-1.2, 5.9, 0)
},
{
element: document.getElementById("labelPress"),
anchor: new THREE.Vector3(0.25, 4.72, -0.55)
},
{
element: document.getElementById("labelPump"),
anchor: new THREE.Vector3(5.1, 4.25, -0.5)
}
];
function updateWorldLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const projected = label.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let uiTimer = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
uiTimer += delta;
// The engine and main shaft never stop.
engineAngle += delta * 2.4;
shaftAngle += delta * 2.4;
pumpAngle += delta * 2.4;
const targetPressSpeed = pressDisconnected ? 0 : 1;
pressSpeed = THREE.MathUtils.damp(
pressSpeed,
targetPressSpeed,
4.2,
delta
);
pressAngle += delta * 2.4 * pressSpeed;
engineFlywheel.rotation.x = engineAngle;
primaryShaftPulley.rotation.x = shaftAngle;
shaftCoupler.rotation.x = shaftAngle;
pressUpperPulley.rotation.x = shaftAngle;
pumpUpperPulley.rotation.x = shaftAngle;
pressWheel.rotation.x = pressAngle;
pumpWheel.rotation.x = pumpAngle;
// Press hammer and pump piston are visibly powered.
pressRam.position.y = 2.75 + Math.sin(pressAngle) * 0.32 * pressSpeed;
pumpPiston.position.y = 3.25 + Math.sin(pumpAngle) * 0.34;
// Belt motion stops when its branch is disconnected.
primaryBelt.update(1);
pressBelt.update(pressDisconnected ? 0 : 1);
pumpBelt.update(1);
// Move the disconnected belt laterally off both pulleys.
const beltShiftTarget = pressDisconnected ? 0.72 : 0;
pressBelt.group.position.x = THREE.MathUtils.damp(
pressBelt.group.position.x,
beltShiftTarget,
8,
delta
);
leverPivot.rotation.x = THREE.MathUtils.damp(
leverPivot.rotation.x,
pressDisconnected ? 1.15 : 0,
9,
delta
);
pressLampMaterial.color.setHex(pressDisconnected ? 0xff5e4e : 0x4ebf78);
pressLampMaterial.emissive.setHex(pressDisconnected ? 0x7a1008 : 0x1e6b3b);
pressLampMaterial.emissiveIntensity = pressDisconnected ? 1.3 : 0.8;
// Small steam puffs make the source engine's continued operation obvious.
for (let i = 0; i < steam.length; i++) {
const puff = steam[i];
const life = (elapsed * 0.42 + i * 0.34) % 3.7;
const size = 0.22 + (i % 3) * 0.055 + life * 0.075;
puff.position.set(
-9.25 + Math.sin(i * 2.1 + elapsed * 0.35) * life * 0.09,
5.02 + life,
-1.85 + Math.cos(i * 1.7 + elapsed * 0.28) * life * 0.07
);
puff.scale.set(size, size, size);
puff.material.opacity = Math.max(0, 0.42 - life * 0.095);
}
// Subtle pulse on the main power shaft indicators.
const pulse = 1 + Math.sin(elapsed * 4) * 0.08;
engineLamp.scale.set(0.18 * pulse, 0.18 * pulse, 0.18 * pulse);
pumpLamp.scale.set(0.2 * pulse, 0.2 * pulse, 0.2 * pulse);
if (uiTimer > 0.1) {
updateStatusText();
uiTimer = 0;
}
updateWorldLabels();
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));
applyCamera();
});
updateStatusText();
animate();
requestAnimationFrame(() => {
loader.classList.add("hidden");
setTimeout(() => loader.remove(), 350);
});
</script>
</body>
</html>
```