Prompt specification
Build or customize the Three.js 3D scene "Steam-powered workshop line shaft" 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: Steam-powered workshop line shaft
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/steam-powered-workshop-line-shaft-x2539
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: Steam-powered workshop line shaft. Build a compact historical workshop where one engine drives a line shaft and several machines. Show belt paths and distinct driven motions without depicting disconnected decorative machinery. Return one self-contained HTML file.
Working Three.js Starter (steam-powered-workshop-line-shaft-x2539):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Steam-Powered Workshop Line Shaft</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(24, 20, 15, 0.9);
--brass: #d5aa55;
--cream: #eee1c3;
--muted: #b9aa8c;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #171410;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 5;
color: var(--cream);
background: var(--panel);
border: 1px solid rgba(213, 170, 85, 0.52);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(7px);
}
#title {
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 17px 19px 15px;
border-radius: 4px;
}
.eyebrow {
color: var(--brass);
font: 700 11px/1.2 Arial, sans-serif;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
color: #f1dfb7;
font-size: clamp(22px, 3vw, 31px);
line-height: 1;
font-weight: 600;
letter-spacing: 0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font: 13px/1.45 Arial, sans-serif;
}
.power-path {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin-top: 13px;
color: #e6d2a7;
font: 700 10px/1 Arial, sans-serif;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.power-path span {
padding: 5px 7px;
border: 1px solid rgba(213, 170, 85, 0.28);
background: rgba(213, 170, 85, 0.08);
}
.power-path i {
color: var(--brass);
font-style: normal;
}
#controls {
right: 18px;
top: 18px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 4px;
}
button {
border: 1px solid rgba(213, 170, 85, 0.48);
background: rgba(213, 170, 85, 0.08);
color: #ead7ad;
padding: 8px 11px;
font: 700 11px/1 Arial, sans-serif;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover { background: rgba(213, 170, 85, 0.2); }
button:focus-visible { outline: 2px solid #f2d795; outline-offset: 2px; }
#status {
left: 18px;
bottom: 18px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border-radius: 4px;
color: var(--muted);
font: 12px/1.25 Arial, sans-serif;
}
#statusDot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #76a75b;
box-shadow: 0 0 9px rgba(118, 167, 91, 0.8);
}
#hint {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 4;
padding: 8px 11px;
color: rgba(238, 225, 195, 0.75);
background: rgba(24, 20, 15, 0.68);
border: 1px solid rgba(213, 170, 85, 0.25);
font: 11px/1.3 Arial, sans-serif;
pointer-events: none;
}
@media (max-width: 680px) {
#title { top: 10px; left: 10px; width: calc(100vw - 20px); }
#controls { top: auto; right: 10px; bottom: 60px; }
#status { left: 10px; bottom: 10px; max-width: calc(100vw - 20px); }
#hint { display: none; }
.power-path { display: none; }
}
</style>
</head>
<body>
<div id="title" class="panel">
<div class="eyebrow">Workshop No. 4 · circa 1880</div>
<h1>THE SHAFT WORKS</h1>
<p class="subtitle">
One steam engine turns one overhead line shaft. Every pulley and belt
below belongs to that power train.
</p>
<div class="power-path">
<span>Engine</span><i>→</i><span>Line shaft</span><i>→</i>
<span>Lathe</span><i>·</i><span>Saw</span><i>·</i><span>Press</span>
</div>
</div>
<div id="controls" class="panel">
<button id="pauseButton" type="button">Pause</button>
<button id="labelButton" type="button">Labels</button>
<button id="resetButton" type="button">Reset View</button>
</div>
<div id="status" class="panel">
<span id="statusDot"></span>
<span id="motionState">Power transmission running</span>
</div>
<div id="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x28231d);
scene.fog = new THREE.Fog(0x28231d, 14, 27);
const camera = new THREE.PerspectiveCamera(43, innerWidth / innerHeight, 0.08, 60);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.appendChild(renderer.domElement);
const V = (x = 0, y = 0, z = 0) => new THREE.Vector3(x, y, z);
const Y_AXIS = V(0, 1, 0);
const Z_AXIS = V(0, 0, 1);
scene.add(new THREE.HemisphereLight(0xe8d6b3, 0x30271e, 2.15));
const sun = new THREE.DirectionalLight(0xffdfb2, 3.0);
sun.position.set(5.5, 9.5, 7.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const windowLight = new THREE.PointLight(0xa8c8d4, 2.2, 10, 2);
windowLight.position.set(-1.4, 3.0, -3.35);
scene.add(windowLight);
const furnaceLight = new THREE.PointLight(0xff8a32, 2.8, 4.2, 2);
furnaceLight.position.set(-3.5, 0.65, -1.65);
scene.add(furnaceLight);
const materials = {
floor: new THREE.MeshStandardMaterial({ color: 0x6b4930, roughness: 0.94, flatShading: true }),
floorDark: new THREE.MeshStandardMaterial({ color: 0x3a291d, roughness: 1, flatShading: true }),
plank: new THREE.MeshStandardMaterial({ color: 0x805537, roughness: 0.93, flatShading: true }),
plankAlt: new THREE.MeshStandardMaterial({ color: 0x70472f, roughness: 0.96, flatShading: true }),
wall: new THREE.MeshStandardMaterial({ color: 0xa58e6f, roughness: 1, flatShading: true }),
wallDark: new THREE.MeshStandardMaterial({ color: 0x715c47, roughness: 1, flatShading: true }),
wood: new THREE.MeshStandardMaterial({ color: 0x55331f, roughness: 0.91, flatShading: true }),
woodLight: new THREE.MeshStandardMaterial({ color: 0x8a5a34, roughness: 0.89, flatShading: true }),
iron: new THREE.MeshStandardMaterial({ color: 0x25282a, roughness: 0.68, metalness: 0.72, flatShading: true }),
ironDark: new THREE.MeshStandardMaterial({ color: 0x151719, roughness: 0.73, metalness: 0.66, flatShading: true }),
green: new THREE.MeshStandardMaterial({ color: 0x243d35, roughness: 0.7, metalness: 0.36, flatShading: true }),
greenLight: new THREE.MeshStandardMaterial({ color: 0x365449, roughness: 0.72, metalness: 0.32, flatShading: true }),
brass: new THREE.MeshStandardMaterial({ color: 0xc4933f, roughness: 0.35, metalness: 0.82, flatShading: true }),
steel: new THREE.MeshStandardMaterial({ color: 0xaeb7b8, roughness: 0.32, metalness: 0.9, flatShading: true }),
belt: new THREE.MeshStandardMaterial({
color: 0x342117, roughness: 0.92, metalness: 0.02, side: THREE.DoubleSide
}),
red: new THREE.MeshStandardMaterial({ color: 0x7c2e23, roughness: 0.76, flatShading: true }),
board: new THREE.MeshStandardMaterial({ color: 0xb47b45, roughness: 0.86, flatShading: true }),
glass: new THREE.MeshStandardMaterial({
color: 0x92b8c8, roughness: 0.32, emissive: 0x426776, emissiveIntensity: 0.45
}),
brick: new THREE.MeshStandardMaterial({ color: 0x704034, roughness: 1, flatShading: true })
};
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, material, x = 0, y = 0, z = 0, axis = "y", parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments, 1, false),
material
);
mesh.position.set(x, y, z);
if (axis === "z") mesh.rotation.x = Math.PI / 2;
if (axis === "x") mesh.rotation.z = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function torus(radius, tube, material, x, y, z, axis = "z", parent = scene, radial = 6, tubular = 20) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, radial, tubular),
material
);
mesh.position.set(x, y, z);
if (axis === "x") mesh.rotation.y = Math.PI / 2;
if (axis === "y") mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rodBetween(a, b, radius, material, parent = scene, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, segments),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
setRod(mesh, a, b);
return mesh;
}
function setRod(mesh, a, b) {
const direction = V().subVectors(b, a);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(a).addScaledVector(direction, 0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
}
function timberBetween(a, b, width, material, parent = scene) {
const direction = V().subVectors(b, a);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, width, direction.length()),
material
);
mesh.position.copy(a).addScaledVector(direction, 0.5);
mesh.quaternion.setFromUnitVectors(Z_AXIS, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Workshop shell
// -------------------------------------------------------------------------
box(10.5, 0.22, 8.4, materials.floorDark, 0, -0.12, 0);
for (let i = 0; i < 21; i++) {
const material = i % 3 === 0 ? materials.plankAlt : materials.plank;
box(0.485, 0.12, 8.25, material, -5 + i * 0.5, 0, 0);
}
box(10.4, 4.35, 0.18, materials.wall, 0, 2.08, -4.22);
box(0.18, 3.65, 8.0, materials.wallDark, -5.15, 1.75, -0.25);
for (let x = -4.6; x <= 4.7; x += 1.15) {
box(0.13, 4.15, 0.12, materials.wood, x, 2.04, -4.08);
}
box(10.3, 0.22, 0.22, materials.wood, 0, 4.12, -4.02);
box(0.22, 0.22, 8.0, materials.wood, -5.02, 3.5, -0.2);
// Back-wall window.
box(2.05, 1.75, 0.10, materials.wood, -1.3, 2.92, -4.02);
box(1.78, 1.48, 0.06, materials.glass, -1.3, 2.92, -3.94);
box(0.09, 1.5, 0.11, materials.woodLight, -1.3, 2.92, -3.88);
box(1.8, 0.09, 0.11, materials.woodLight, -1.3, 2.92, -3.88);
box(2.22, 0.14, 0.36, materials.woodLight, -1.3, 1.98, -3.91);
// Brick hearth beneath the engine.
box(1.65, 0.75, 1.20, materials.brick, -3.75, 0.37, -1.92);
box(1.30, 0.20, 0.90, materials.ironDark, -3.75, 0.84, -2.03);
box(0.78, 0.12, 0.45, materials.brass, -3.75, 0.96, -1.96);
// Exposed ceiling ties and shaft hangers.
for (const z of [-2.02, 0.92]) {
box(9.85, 0.22, 0.24, materials.wood, -0.05, 4.58, z);
rodBetween(V(0.35, 4.48, z), V(0.35, 4.02, z), 0.045, materials.iron);
torus(0.145, 0.045, materials.brass, 0.35, 3.85, z);
box(0.44, 0.12, 0.24, materials.iron, 0.35, 3.99, z);
}
// -------------------------------------------------------------------------
// Pulleys and belts
// -------------------------------------------------------------------------
function makePulley(radius, width, parent = scene, spokeCount = 6, material = materials.iron) {
const group = new THREE.Group();
parent.add(group);
const tube = Math.max(0.022, radius * 0.105);
torus(radius - tube, tube, material, 0, 0, 0, "z", group, 5, 20);
cylinder(radius * 0.23, radius * 0.23, width * 1.35, 10,
materials.brass, 0, 0, 0, "z", group);
const spokeLength = radius * 0.72;
for (let i = 0; i < spokeCount; i++) {
const angle = (i / spokeCount) * Math.PI * 2;
const spoke = box(
spokeLength, Math.max(0.028, radius * 0.075), width * 0.56,
material,
Math.cos(angle) * radius * 0.38,
Math.sin(angle) * radius * 0.38,
0,
group
);
spoke.rotation.z = angle;
}
return group;
}
function createBelt(c1, r1, c2, r2, z, width, speed, direction = 1, markerCount = 9) {
const center1 = new THREE.Vector2(c1[0], c1[1]);
const center2 = new THREE.Vector2(c2[0], c2[1]);
const delta = center2.clone().sub(center1);
const distance = delta.length();
const u = delta.clone().normalize();
const perpendicular = V(-u.y, u.x);
const k = (r1 - r2) / distance;
const h = Math.sqrt(Math.max(0, 1 - k * k));
const nA = u.clone().multiplyScalar(k).addScaledVector(perpendicular, h).normalize();
const nB = u.clone().multiplyScalar(k).addScaledVector(perpendicular, -h).normalize();
const a1 = center1.clone().addScaledVector(nA, r1);
const a2 = center2.clone().addScaledVector(nA, r2);
const b2 = center2.clone().addScaledVector(nB, r2);
const b1 = center1.clone().addScaledVector(nB, r1);
const points = [];
const addPoint = p => {
const last = points[points.length - 1];
if (!last || last.distanceToSquared(p) > 0.000001) points.push(p);
};
addPoint(a1);
addPoint(a2);
const arc = (center, radius, start, end, segments) => {
const clockwise = ((start - end) % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2);
for (let i = 1; i <= segments; i++) {
const angle = start - clockwise * (i / segments);
addPoint(V(
center.x + Math.cos(angle) * radius,
center.y + Math.sin(angle) * radius
));
}
};
arc(center2, r2, Math.atan2(nA.y, nA.x), Math.atan2(nB.y, nB.x), 22);
addPoint(b2);
addPoint(b1);
arc(center1, r1, Math.atan2(nB.y, nB.x), Math.atan2(nA.y, nA.x), 22);
const vertices = [];
const indices = [];
for (const p of points) {
vertices.push(p.x, p.y, z - width / 2);
vertices.push(p.x, p.y, z + width / 2);
}
for (let i = 0; i < points.length; i++) {
const next = (i + 1) % points.length;
const a = i * 2;
const b = next * 2;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, materials.belt);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const cumulative = [0];
let beltLength = 0;
for (let i = 1; i < points.length; i++) {
beltLength += points[i].distanceTo(points[i - 1]);
cumulative.push(beltLength);
}
beltLength += points[0].distanceTo(points[points.length - 1]);
cumulative.push(beltLength);
const markers = [];
const markerGeometry = new THREE.BoxGeometry(0.075, 0.038, width * 1.08);
for (let i = 0; i < markerCount; i++) {
const marker = new THREE.Mesh(markerGeometry, materials.brass);
marker.castShadow = true;
scene.add(marker);
markers.push({ mesh: marker, offset: i / markerCount });
}
function sample(distanceAlongBelt) {
let d = ((distanceAlongBelt % beltLength) + beltLength) % beltLength;
for (let i = 1; i < cumulative.length; i++) {
if (d <= cumulative[i]) {
const segmentLength = cumulative[i] - cumulative[i - 1];
const t = (d - cumulative[i - 1]) / Math.max(segmentLength, 0.00001);
const a = points[i - 1];
const b = points[i % points.length];
const p = a.clone().lerp(b, t);
const tangent = b.clone().sub(a).normalize();
return { p, tangent };
}
}
return { p: points[0].clone(), tangent: points[1].clone().sub(points[0]).normalize() };
}
return {
mesh,
markers,
length: beltLength,
speed,
direction,
sample
};
}
// -------------------------------------------------------------------------
// Main overhead line shaft
// -------------------------------------------------------------------------
const lineGroup = new THREE.Group();
lineGroup.position.set(0.35, 3.85, 0);
scene.add(lineGroup);
cylinder(0.078, 0.078, 5.78, 12, materials.steel, 0, 0, -0.18, "z", lineGroup);
box(0.026, 0.035, 5.46, materials.brass, 0.073, 0, -0.2, lineGroup);
const inputPulley = makePulley(0.28, 0.17, lineGroup, 6);
inputPulley.position.z = -2.65;
const latheTopPulley = makePulley(0.32, 0.18, lineGroup, 6);
latheTopPulley.position.z = -1.35;
const sawTopPulley = makePulley(0.22, 0.15, lineGroup, 5);
sawTopPulley.position.z = 0.25;
const pressTopPulley = makePulley(0.34, 0.18, lineGroup, 6);
pressTopPulley.position.z = 2.15;
// -------------------------------------------------------------------------
// Steam engine, flywheel, piston, and boiler
// -------------------------------------------------------------------------
const engine = new THREE.Group();
scene.add(engine);
// Vertical boiler.
cylinder(0.70, 0.76, 2.72, 12, materials.green, -4.04, 1.55, -2.65, "y", engine);
const boilerTop = new THREE.Mesh(new THREE.SphereGeometry(0.72, 12, 6), materials.green);
boilerTop.position.set(-4.04, 2.92, -2.65);
boilerTop.scale.y = 0.53;
boilerTop.castShadow = true;
engine.add(boilerTop);
for (const y of [0.70, 1.55, 2.40]) {
torus(0.715, 0.045, materials.brass, -4.04, y, -2.65, "y", engine, 5, 16);
}
cylinder(0.14, 0.17, 0.88, 10, materials.ironDark, -4.04, 3.54, -2.65, "y", engine);
cylinder(0.22, 0.22, 0.10, 10, materials.iron, -4.04, 3.98, -2.65, "y", engine);
// Boiler steam pipe into the engine cylinder.
rodBetween(V(-3.47, 2.30, -2.65), V(-3.08, 2.30, -2.65), 0.075, materials.brass, engine);
rodBetween(V(-3.08, 2.30, -2.65), V(-2.92, 1.78, -2.65), 0.075, materials.brass, engine);
torus(0.11, 0.025, materials.brass, -3.47, 2.30, -2.65, "x", engine);
// Horizontal engine cylinder and bed.
box(2.05, 0.22, 1.12, materials.ironDark, -3.02, 0.35, -2.65, engine);
cylinder(0.39, 0.44, 1.28, 12, materials.green, -2.87, 1.15, -2.65, "x", engine);
cylinder(0.42, 0.42, 0.16, 12, materials.iron, -2.25, 1.15, -2.65, "x", engine);
box(0.95, 0.28, 0.63, materials.greenLight, -2.84, 1.62, -2.65, engine);
cylinder(0.07, 0.07, 0.40, 8, materials.brass, -2.82, 1.92, -2.65, "y", engine);
// Pressure gauge.
const gauge = new THREE.Group();
gauge.position.set(-2.85, 1.86, -2.27);
engine.add(gauge);
cylinder(0.17, 0.17, 0.055, 16, materials.brass, 0, 0, 0, "z", gauge);
cylinder(0.142, 0.142, 0.025, 16, materials.board, 0, 0, 0.042, "z", gauge);
const gaugeNeedle = new THREE.Group();
gaugeNeedle.position.z = 0.062;
gauge.add(gaugeNeedle);
box(0.014, 0.105, 0.012, materials.ironDark, 0, 0.043, 0, gaugeNeedle);
// Flywheel and crank.
const flywheel = makePulley(0.72, 0.19, scene, 8, materials.ironDark);
flywheel.position.set(-2.05, 1.15, -2.65);
const crankArm = box(0.32, 0.075, 0.075, materials.brass, 0.15, 0, 0.15, flywheel);
const crankPin = cylinder(0.075, 0.075, 0.16, 10, materials.brass, 0.30, 0, 0.18, "z", flywheel);
// Crosshead guide rails.
box(1.15, 0.065, 0.10, materials.steel, -1.78, 1.00, -2.39, engine);
box(1.15, 0.065, 0.10, materials.steel, -1.78, 1.31, -2.39, engine);
const crosshead = box(0.20, 0.28, 0.20, materials.brass, -1.25, 1.15, -2.39, engine);
const pistonRod = rodBetween(V(-2.22, 1.15, -2.45), V(-1.3, 1.15, -2.45), 0.045, materials.steel, engine);
const connectingRod = rodBetween(V(), V(1, 0, 0), 0.055, materials.steel, engine);
// Small exhaust pipe and steam emitter.
rodBetween(V(-2.92, 1.66, -2.38), V(-3.22, 1.66, -2.20), 0.055, materials.iron, engine);
const steamOrigin = V(-3.22, 1.72, -2.20);
// -------------------------------------------------------------------------
// Metal lathe
// -------------------------------------------------------------------------
const lathe = new THREE.Group();
scene.add(lathe);
box(3.35, 0.24, 0.68, materials.green, 2.73, 0.29, -1.35, lathe);
box(3.36, 0.12, 0.14, materials.steel, 2.73, 0.52, -1.51, lathe);
box(3.36, 0.12, 0.14, materials.steel, 2.73, 0.52, -1.19, lathe);
box(0.60, 0.83, 0.62, materials.greenLight, 1.45, 0.83, -1.35, lathe);
box(0.48, 0.69, 0.50, materials.greenLight, 4.00, 0.79, -1.35, lathe);
box(0.50, 0.18, 0.52, materials.iron, 1.43, 1.29, -1.35, lathe);
box(0.45, 0.17, 0.48, materials.iron, 4.00, 1.20, -1.35, lathe);
// Lathe countershaft, belt pulley, and visible bevel gearing.
const latheWheel = makePulley(0.34, 0.18, scene, 6);
latheWheel.position.set(2.80, 0.72, -1.35);
cylinder(0.075, 0.075, 0.66, 10, materials.steel, 2.80, 0.72, -1.18, "z", lathe);
const countershaftGear = new THREE.Group();
countershaftGear.position.set(2.80, 0.84, -1.10);
lathe.add(countershaftGear);
cylinder(0.20, 0.20, 0.10, 12, materials.brass, 0, 0, 0, "z", countershaftGear);
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
const tooth = box(0.075, 0.07, 0.11, materials.brass,
Math.cos(a) * 0.20, Math.sin(a) * 0.20, 0, countershaftGear);
tooth.rotation.z = a;
}
// Rotating spindle, chuck, and workpiece.
const latheSpindle = new THREE.Group();
latheSpindle.position.set(3.05, 1.04, -1.35);
lathe.add(latheSpindle);
cylinder(0.115, 0.115, 1.05, 12, materials.steel, 0, 0, 0, "x", latheSpindle);
cylinder(0.255, 0.255, 0.20, 12, materials.iron, -0.12, 0, 0, "x", latheSpindle);
cylinder(0.145, 0.145, 0.12, 10, materials.brass, -0.26, 0, 0, "x", latheSpindle);
for (let i = 0; i < 3; i++) {
const a = (i / 3) * Math.PI * 2;
const jaw = box(0.18, 0.10, 0.10, materials.brass,
-0.27, Math.cos(a) * 0.16, Math.sin(a) * 0.16, latheSpindle);
jaw.rotation.x = a;
}
cylinder(0.12, 0.12, 0.92, 12, materials.brass, 0.42, 0, 0, "x", latheSpindle);
const spindleGear = new THREE.Group();
spindleGear.position.set(2.80, 0.84, -1.01);
spindleGear.rotation.y = Math.PI / 2;
lathe.add(spindleGear);
cylinder(0.18, 0.11, 0.14, 12, materials.brass, 0, 0, 0, "z", spindleGear);
// Tool carriage reciprocates along the lathe bed.
const carriage = new THREE.Group();
carriage.position.set(3.05, 0.72, -1.08);
lathe.add(carriage);
box(0.52, 0.16, 0.43, materials.greenLight, 0, 0, 0, carriage);
box(0.13, 0.42, 0.16, materials.iron, 0, 0.27, 0.08, carriage);
box(0.28, 0.09, 0.13, materials.brass, 0.05, 0.49, 0.08, carriage);
box(0.025, 0.17, 0.025, materials.steel, 0.05, 0.39, 0.08, carriage);
// -------------------------------------------------------------------------
// Circular saw
// -------------------------------------------------------------------------
const saw = new THREE.Group();
scene.add(saw);
box(1.75, 0.16, 1.03, materials.woodLight, 2.65, 0.98, 0.25, saw);
for (const x of [1.93, 3.37]) {
for (const z of [-0.10, 0.60]) {
box(0.13, 0.94, 0.13, materials.wood, x, 0.47, z, saw);
}
}
box(1.64, 0.10, 0.13, materials.wood, 2.65, 0.38, 0.25, saw);
box(1.32, 0.12, 0.28, materials.board, 2.70, 1.10, 0.54, saw);
const sawRotor = new THREE.Group();
sawRotor.position.set(2.65, 1.25, 0.25);
saw.add(sawRotor);
cylinder(0.52, 0.52, 0.045, 24, materials.steel, 0, 0, 0, "z", sawRotor);
torus(0.52, 0.035, materials.steel, 0, 0, 0, "z", sawRotor, 5, 28);
for (let i = 0; i < 20; i++) {
const a = (i / 20) * Math.PI * 2;
const tooth = box(0.115, 0.085, 0.055, materials.steel,
Math.cos(a) * 0.535, Math.sin(a) * 0.535, 0, sawRotor);
tooth.rotation.z = a;
}
const sawPulley = makePulley(0.18, 0.13, sawRotor, 5);
sawPulley.position.z = 0.025;
cylinder(0.07, 0.07, 0.26, 10, materials.brass, 0, 0, 0.08, "z", sawRotor);
// -------------------------------------------------------------------------
// Crank-driven arbor press
// -------------------------------------------------------------------------
const press = new THREE.Group();
scene.add(press);
box(2.18, 0.20, 0.92, materials.ironDark, 2.90, 0.31, 1.72, press);
box(0.22, 2.55, 0.25, materials.green, 2.04, 1.65, 1.68, press);
box(0.22, 2.55, 0.25, materials.green, 3.76, 1.65, 1.68, press);
box(2.03, 0.24, 0.40, materials.greenLight, 2.90, 2.93, 1.68, press);
box(1.50, 0.10, 0.46, materials.iron, 2.90, 0.74, 1.70, press);
box(0.72, 0.22, 0.42, materials.board, 2.90, 0.91, 1.70, press);
// Guide rods.
for (const x of [2.64, 3.16]) {
cylinder(0.045, 0.045, 1.54, 8, materials.steel, x, 1.78, 1.99, "y", press);
}
const pressWheel = makePulley(0.46, 0.18, scene, 7);
pressWheel.position.set(2.90, 0.65, 2.15);
const pressCrankArm = box(0.36, 0.065, 0.07, materials.brass, 0.18, 0, 0.15, pressWheel);
const pressCrankPin = cylinder(0.065, 0.065, 0.15, 10, materials.brass, 0.36, 0, 0.18, "z", pressWheel);
const pressRam = new THREE.Group();
press.add(pressRam);
box(0.67, 0.32, 0.43, materials.iron, 2.90, 1.55, 1.99, pressRam);
cylinder(0.075, 0.045, 0.43, 8, materials.steel, 2.90, 1.20, 1.99, "y", pressRam);
const pressLink = rodBetween(V(), V(0, 1, 0), 0.048, materials.steel, press);
// -------------------------------------------------------------------------
// Continuous power train belts
// -------------------------------------------------------------------------
const belts = [
createBelt([-2.05, 1.15], 0.72, [0.35, 3.85], 0.28, -2.65, 0.15, 0.84, 1, 11),
createBelt([0.35, 3.85], 0.32, [2.80, 0.72], 0.34, -1.35, 0.15, 0.96, 1, 10),
createBelt([0.35, 3.85], 0.22, [2.65, 1.25], 0.18, 0.25, 0.13, 0.66, 1, 9),
createBelt([0.35, 3.85], 0.34, [2.90, 0.65], 0.46, 2.15, 0.16, 1.02, 1, 10)
];
// -------------------------------------------------------------------------
// Steam puffs
// -------------------------------------------------------------------------
const steamPuffs = [];
const puffGeometry = new THREE.IcosahedronGeometry(0.11, 1);
for (let i = 0; i < 12; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0xe4dfd2,
roughness: 1,
transparent: true,
opacity: 0,
depthWrite: false
});
const puff = new THREE.Mesh(puffGeometry, material);
puff.visible = false;
scene.add(puff);
steamPuffs.push({
mesh: puff,
life: 0,
maxLife: 1,
velocity: V()
});
}
let steamTimer = 0;
function emitSteam() {
const puff = steamPuffs.find(p => p.life <= 0);
if (!puff) return;
puff.life = 1.6;
puff.maxLife = 1.6;
puff.mesh.position.copy(steamOrigin);
puff.mesh.scale.setScalar(0.65);
puff.mesh.visible = true;
puff.velocity.set(
(Math.random() - 0.5) * 0.18,
0.55 + Math.random() * 0.24,
(Math.random() - 0.5) * 0.12
);
}
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const labelGroup = new THREE.Group();
scene.add(labelGroup);
function makeLabel(text, x, y, z, scale = 1.55) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
const r = 16;
ctx.beginPath();
ctx.moveTo(r, 4);
ctx.lineTo(508 - r, 4);
ctx.quadraticCurveTo(508, 4, 508, 4 + r);
ctx.lineTo(508, 108 - r);
ctx.quadraticCurveTo(508, 108, 508 - r, 108);
ctx.lineTo(r, 108);
ctx.quadraticCurveTo(4, 108, 4, 108 - r);
ctx.lineTo(4, 4 + r);
ctx.quadraticCurveTo(4, 4, r, 4);
ctx.closePath();
ctx.fillStyle = "rgba(24,20,15,0.91)";
ctx.fill();
ctx.strokeStyle = "#c9a253";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#f0ddb5";
ctx.font = "700 31px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text.toUpperCase(), 256, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(x, y, z);
sprite.scale.set(scale, scale * 112 / 512, 1);
sprite.renderOrder = 20;
labelGroup.add(sprite);
return sprite;
}
makeLabel("Steam engine", -3.45, 3.83, -2.44, 1.45);
makeLabel("Main line shaft", 0.35, 4.88, -0.28, 1.58);
makeLabel("Belt-driven lathe", 2.73, 2.08, -1.33, 1.58);
makeLabel("Circular saw", 2.65, 2.22, 0.25, 1.43);
makeLabel("Crank press", 2.90, 3.53, 1.79, 1.43);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without Three.js addons
// -------------------------------------------------------------------------
const orbit = {
target: V(-0.05, 1.78, -0.35),
radius: 12.5,
theta: 0.72,
phi: 1.12
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.target.set(-0.05, 1.78, -0.35);
orbit.radius = 12.5;
orbit.theta = 0.72;
orbit.phi = 1.12;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
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;
orbit.theta -= dx * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.004, 0.48, 1.42);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * 0.008, 6.8, 18);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
let running = true;
const pauseButton = document.getElementById("pauseButton");
const labelButton = document.getElementById("labelButton");
const resetButton = document.getElementById("resetButton");
const motionState = document.getElementById("motionState");
const statusDot = document.getElementById("statusDot");
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause" : "Resume";
motionState.textContent = running
? "Power transmission running"
: "Power transmission paused";
statusDot.style.background = running ? "#76a75b" : "#c06a4a";
statusDot.style.boxShadow = running
? "0 0 9px rgba(118,167,91,0.8)"
: "0 0 9px rgba(192,106,74,0.7)";
});
labelButton.addEventListener("click", () => {
labelGroup.visible = !labelGroup.visible;
labelButton.textContent = labelGroup.visible ? "Labels" : "Show Labels";
});
resetButton.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let simTime = 0;
const crankPinWorld = V();
const pressPinWorld = V();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (running) simTime += dt;
const lineAngle = simTime * 3.0;
const engineAngle = lineAngle * (0.28 / 0.72);
const latheAngle = lineAngle * (0.32 / 0.34);
const sawAngle = lineAngle * (0.22 / 0.18);
const pressAngle = lineAngle * (0.34 / 0.46);
lineGroup.rotation.z = lineAngle;
flywheel.rotation.z = engineAngle;
// Engine slider-crank.
const crankRadius = 0.30;
const connectingLength = 0.75;
const crankX = -2.05 + Math.cos(engineAngle) * crankRadius;
const crankY = 1.15 + Math.sin(engineAngle) * crankRadius;
const crossheadX =
-2.05 + Math.cos(engineAngle) * crankRadius +
Math.sqrt(connectingLength * connectingLength -
Math.pow(Math.sin(engineAngle) * crankRadius, 2));
crosshead.position.x = crossheadX;
crankPinWorld.set(crankX, crankY, -2.47);
setRod(connectingRod, crankPinWorld, V(crossheadX, 1.15, -2.47));
setRod(pistonRod, V(-2.22, 1.15, -2.45), V(crossheadX, 1.15, -2.45));
gaugeNeedle.rotation.z = -0.75 + Math.sin(engineAngle * 1.7) * 0.08;
// Lathe drive: countershaft, bevel gears, spindle, and reciprocating feed.
latheWheel.rotation.z = latheAngle;
countershaftGear.rotation.z = -latheAngle;
latheSpindle.rotation.x = latheAngle * 4.1;
spindleGear.rotation.z = -latheAngle * 4.1;
carriage.position.x = 3.05 + Math.sin(lineAngle * 0.83) * 0.24;
// Circular saw.
sawRotor.rotation.z = sawAngle;
// Crank press: wheel, crank pin, connecting rod, and vertical ram.
pressWheel.rotation.z = pressAngle;
pressCrankPin.getWorldPosition(pressPinWorld);
const pressCrankRadius = 0.36;
const pressRodLength = 0.75;
const horizontalOffset = Math.cos(pressAngle) * pressCrankRadius;
const ramPinY =
0.65 + Math.sqrt(pressRodLength * pressRodLength - horizontalOffset * horizontalOffset);
pressRam.position.y = ramPinY - 1.55;
setRod(pressLink, pressPinWorld, V(2.90, ramPinY, 2.34));
// Belt cleats visibly travel around each complete belt loop.
for (const belt of belts) {
for (const marker of belt.markers) {
const d = marker.offset * belt.length +
simTime * belt.speed * belt.direction;
const sample = belt.sample(d);
marker.mesh.position.set(sample.p.x, sample.p.y, belt.mesh.position.z);
marker.mesh.rotation.z = Math.atan2(sample.tangent.y, sample.tangent.x);
}
}
// Steam puffs.
steamTimer += dt;
if (running && steamTimer > 0.30) {
steamTimer = 0;
emitSteam();
}
for (const puff of steamPuffs) {
if (puff.life <= 0) continue;
puff.life -= dt;
const age = 1 - puff.life / puff.maxLife;
puff.mesh.position.addScaledVector(puff.velocity, dt);
puff.mesh.rotation.x += dt * 0.8;
puff.mesh.rotation.y += dt * 0.6;
puff.mesh.scale.setScalar(0.65 + age * 1.8);
puff.mesh.material.opacity = Math.max(0, 0.42 * (1 - age));
if (puff.life <= 0) puff.mesh.visible = false;
}
renderer.render(scene, camera);
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", onResize);
resetCamera();
animate();
</script>
</body>
</html>
```