Prompt specification
Build or customize the Three.js 3D scene "Bicycle Trainer Power Transmission Exhibit" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Bicycle Trainer Power Transmission Exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bicycle-trainer-power-transmission-exhibit-x2011
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts belt-driven pulleys and tension control. Build an original teaching rig with pedals, pulleys, and a generator indicator. Keep the mechanical drive geometry coherent and label electrical output as schematic. Voxel style.
Working Three.js Starter (bicycle-trainer-power-transmission-exhibit-x2011):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Belt Lab — Pedal-to-Generator Teaching Rig</title>
<style>
:root {
--ink: #17282f;
--paper: #f3f0e7;
--panel: rgba(248, 246, 238, 0.94);
--orange: #e96d3d;
--teal: #2c9d91;
--yellow: #efb84e;
--blue: #5e8fc8;
--line: rgba(23, 40, 47, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e7df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 18px 16px;
background: var(--panel);
border: 2px solid var(--ink);
box-shadow: 7px 7px 0 rgba(23, 40, 47, 0.18);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
content: "";
background: var(--teal);
box-shadow: 3px 3px 0 var(--ink);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
max-width: 340px;
color: rgba(23, 40, 47, 0.72);
font-size: 13px;
line-height: 1.45;
}
.readout {
position: absolute;
top: 22px;
right: 22px;
width: 278px;
padding: 15px;
background: var(--panel);
border: 2px solid var(--ink);
box-shadow: 7px 7px 0 rgba(23, 40, 47, 0.18);
}
.readout h2 {
margin: 0 0 12px;
padding-bottom: 9px;
border-bottom: 2px solid var(--ink);
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin: 8px 0;
font-size: 12px;
}
.readout-row span:first-child {
color: rgba(23, 40, 47, 0.65);
font-weight: 700;
}
.readout-row strong {
font-variant-numeric: tabular-nums;
}
.status {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--teal);
}
.status::before {
width: 8px;
height: 8px;
content: "";
background: currentColor;
box-shadow: 2px 2px 0 var(--ink);
}
.output-box {
margin-top: 12px;
padding: 11px;
color: #ecf6e7;
background: var(--ink);
border: 2px solid var(--ink);
}
.output-title {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.schematic-tag {
padding: 3px 5px;
color: var(--ink);
background: var(--yellow);
font-size: 9px;
letter-spacing: 0.08em;
}
.meter {
display: flex;
gap: 5px;
height: 28px;
margin-top: 10px;
align-items: flex-end;
}
.meter i {
display: block;
flex: 1;
height: 100%;
background: #284049;
border: 1px solid #49606a;
transition: background 90ms linear, box-shadow 90ms linear;
}
.meter i.on {
background: var(--teal);
box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18);
}
.meter i.hot {
background: var(--yellow);
}
.output-note {
margin: 8px 0 0;
color: #aebdc0;
font-size: 10px;
line-height: 1.4;
}
.controls {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
align-items: stretch;
gap: 10px;
width: min(790px, calc(100vw - 44px));
padding: 10px;
transform: translateX(-50%);
background: var(--panel);
border: 2px solid var(--ink);
box-shadow: 7px 7px 0 rgba(23, 40, 47, 0.18);
pointer-events: auto;
}
.control-group {
min-width: 0;
padding: 7px 11px;
border-right: 1px solid var(--line);
}
.control-group:last-child {
border-right: 0;
}
.control-label {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-label output {
color: var(--teal);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 0;
appearance: none;
background: #c9cbc3;
border: 1px solid var(--ink);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 20px;
appearance: none;
background: var(--orange);
border: 2px solid var(--ink);
box-shadow: 2px 2px 0 rgba(23, 40, 47, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 18px;
background: var(--orange);
border: 2px solid var(--ink);
border-radius: 0;
}
button {
min-width: 92px;
padding: 0 14px;
color: var(--paper);
background: var(--ink);
border: 2px solid var(--ink);
box-shadow: 3px 3px 0 rgba(23, 40, 47, 0.22);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
color: var(--ink);
background: var(--yellow);
}
button:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 rgba(23, 40, 47, 0.22);
}
.button-stack {
display: flex;
flex-direction: column;
justify-content: center;
gap: 6px;
}
.button-stack button {
min-height: 31px;
padding: 0 10px;
}
.hint {
position: absolute;
right: 22px;
bottom: 22px;
padding: 8px 10px;
color: rgba(23, 40, 47, 0.72);
background: rgba(248, 246, 238, 0.84);
border: 1px solid rgba(23, 40, 47, 0.18);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e9e7df;
color: var(--ink);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 200ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.readout {
top: auto;
right: 12px;
bottom: 112px;
width: 235px;
}
.title-card {
top: 12px;
left: 12px;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
.title-card {
width: calc(100vw - 24px);
padding: 12px;
}
.subtitle {
display: none;
}
.readout {
display: none;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
}
.control-group {
border-right: 0;
}
.button-stack {
grid-column: 1 / -1;
flex-direction: row;
}
.button-stack button {
flex: 1;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D pedal, belt, pulley, and generator teaching rig"></canvas>
<div class="overlay">
<section class="title-card">
<div class="eyebrow">Voxel mechanics / learning rig 01</div>
<h1>Belt Lab</h1>
<p class="subtitle">
A pedal-driven flywheel transfers motion through an open belt to a sliding,
spring-loaded generator pulley. Drag the pulley carriage to explore tension.
</p>
</section>
<aside class="readout">
<h2>Live transmission</h2>
<div class="readout-row">
<span>Rig state</span>
<strong id="state" class="status">Running</strong>
</div>
<div class="readout-row">
<span>Pedal rate</span>
<strong id="rpm">48 RPM</strong>
</div>
<div class="readout-row">
<span>Generator rate</span>
<strong id="generator-rpm">112 RPM</strong>
</div>
<div class="readout-row">
<span>Belt ratio</span>
<strong>2.33 : 1</strong>
</div>
<div class="readout-row">
<span>Belt tension</span>
<strong id="tension-readout">68%</strong>
</div>
<div class="output-box">
<div class="output-title">
<span>Generator output</span>
<span class="schematic-tag">Schematic</span>
</div>
<div class="meter" id="meter" aria-label="Schematic generator output level">
<i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<p class="output-note">
Illustrative indicator only. No electrical connection, load, or measured output is represented.
</p>
</div>
</aside>
<section class="controls">
<div class="control-group" style="flex: 1.2">
<div class="control-label">
<label for="cadence">Pedal cadence</label>
<output id="cadence-output" for="cadence">48 RPM</output>
</div>
<input id="cadence" type="range" min="12" max="90" value="48" step="1">
</div>
<div class="control-group" style="flex: 1.2">
<div class="control-label">
<label for="tension">Spring tension</label>
<output id="tension-output" for="tension">68%</output>
</div>
<input id="tension" type="range" min="0" max="100" value="68" step="1">
</div>
<div class="button-stack">
<button id="play" type="button">Pause</button>
<button id="reset-view" type="button">Reset view</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</div>
<div id="loading">Building teaching rig…</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 canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e7df);
scene.fog = new THREE.Fog(0xe9e7df, 15, 29);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemi = new THREE.HemisphereLight(0xfff9e8, 0x8b9694, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d2, 3.5);
sun.position.set(-4, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -5;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x84c6d0, 1.15);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const palette = {
ink: 0x17282f,
frame: 0x304650,
frameLight: 0x52666d,
orange: 0xe96d3d,
teal: 0x2c9d91,
yellow: 0xefb84e,
blue: 0x5e8fc8,
rubber: 0x20292d,
cream: 0xf3f0e7,
steel: 0x9aa7a8,
darkSteel: 0x59666b,
green: 0x77c86d,
red: 0xdb5b4d
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
flatShading: true,
...options
});
}
const mats = {
ink: material(palette.ink),
frame: material(palette.frame),
frameLight: material(palette.frameLight),
orange: material(palette.orange),
teal: material(palette.teal),
yellow: material(palette.yellow),
blue: material(palette.blue),
rubber: material(palette.rubber),
cream: material(palette.cream),
steel: material(palette.steel, { metalness: 0.42, roughness: 0.48 }),
darkSteel: material(palette.darkSteel, { metalness: 0.35, roughness: 0.52 }),
green: material(palette.green, {
emissive: palette.green,
emissiveIntensity: 0.1
}),
red: material(palette.red),
floor: material(0xd9d8d0)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderZ(radius, depth, mat, x, y, z, parent = scene, segments = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, depth, segments),
mat
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x17282f, opacity = 0.28) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
// -------------------------------------------------------------------------
// Small canvas-based labels. No external fonts or texture assets are used.
// -------------------------------------------------------------------------
function makeLabelTexture(text, accent = "#2c9d91") {
const c = document.createElement("canvas");
c.width = 768;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(23, 40, 47, 0.94)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 16, c.height);
ctx.fillStyle = "#f5f1e7";
ctx.font = "900 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2 + 8, c.height / 2 + 1);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function worldLabel(text, x, y, z, width = 2.05, accent = "#2c9d91") {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeLabelTexture(text, accent),
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(width, width / 6, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
worldLabel("01 PEDAL FLYWHEEL", -2.45, 3.12, 0.25, 2.25, "#e96d3d");
worldLabel("02 OPEN BELT", -0.75, 3.63, 0.35, 1.75, "#efb84e");
worldLabel("03 GENERATOR", 0.62, 3.72, 0.25, 1.75, "#2c9d91");
worldLabel("SPRING TENSION", 1.07, 1.05, 0.25, 1.75, "#e96d3d");
// -------------------------------------------------------------------------
// Platform and structural frame
// -------------------------------------------------------------------------
box(10.9, 0.28, 3.65, mats.cream, 0.35, 0.04, 0);
addEdges(scene.children[scene.children.length - 1], 0x17282f, 0.16);
box(10.35, 0.075, 3.12, mats.floor, 0.35, 0.205, 0);
// Grid inlaid into the base.
for (let x = -4.5; x <= 5.25; x += 0.5) {
box(0.018, 0.012, 3.05, mats.cream, x, 0.249, 0);
}
for (let z = -1.5; z <= 1.51; z += 0.5) {
box(10.25, 0.012, 0.018, mats.cream, 0.35, 0.249, z);
}
// Feet.
for (const x of [-4.25, 5.0]) {
for (const z of [-1.35, 1.35]) {
box(0.72, 0.22, 0.72, mats.ink, x, -0.12, z);
}
}
// Drive frame: two uprights and a lower cross member.
for (const x of [-3.78, -1.12]) {
const post = box(0.28, 2.15, 0.38, mats.frame, x, 1.29, -0.52);
addEdges(post);
box(0.68, 0.17, 0.72, mats.frameLight, x, 0.34, -0.52);
}
box(2.92, 0.25, 0.38, mats.frame, -2.45, 0.69, -0.52);
box(2.92, 0.18, 0.38, mats.frame, -2.45, 2.36, -0.52);
// Axle housing.
box(0.58, 0.58, 0.24, mats.darkSteel, -2.45, 1.65, -0.7);
cylinderZ(0.12, 1.55, mats.steel, -2.45, 1.65, -0.1);
// Sliding generator rail.
box(2.55, 0.16, 0.36, mats.steel, 0.78, 1.36, -0.12);
box(2.88, 0.12, 0.48, mats.frame, 0.78, 1.24, -0.12);
for (const x of [-0.35, 1.92]) {
box(0.24, 0.46, 0.58, mats.frame, x, 1.13, -0.12);
}
// Generator indicator board and stand.
box(0.26, 2.0, 0.32, mats.frame, 3.68, 1.18, -0.45);
box(1.55, 0.18, 0.72, mats.frameLight, 3.68, 0.32, -0.45);
// -------------------------------------------------------------------------
// Pulley construction
// -------------------------------------------------------------------------
function makePulley(radius, rimColor, spokeCount = 12, parent = scene) {
const group = new THREE.Group();
parent.add(group);
const rimBlocks = Math.max(12, Math.round(radius * 14));
const radialThickness = radius < 0.7 ? 0.13 : 0.16;
const tangentLength =
2 * radius * Math.sin(Math.PI / rimBlocks) * 1.08;
for (let i = 0; i < rimBlocks; i++) {
const angle = (i / rimBlocks) * Math.PI * 2;
const rim = box(
tangentLength,
radialThickness,
0.32,
rimColor,
Math.cos(angle) * (radius - radialThickness / 2),
Math.sin(angle) * (radius - radialThickness / 2),
0,
group
);
rim.rotation.z = angle + Math.PI / 2;
}
const spokeLength = radius * 0.73;
for (let i = 0; i < spokeCount; i++) {
const angle = (i / spokeCount) * Math.PI * 2;
const spoke = box(
spokeLength,
radius < 0.7 ? 0.11 : 0.15,
0.19,
i % 2 === 0 ? mats.teal : mats.cream,
Math.cos(angle) * spokeLength * 0.45,
Math.sin(angle) * spokeLength * 0.45,
0,
group
);
spoke.rotation.z = angle;
}
cylinderZ(
radius < 0.7 ? 0.15 : 0.24,
0.43,
mats.ink,
0,
0,
0.04,
group,
12
);
// Voxel bolts.
const boltRadius = radius * 0.43;
for (let i = 0; i < 4; i++) {
const angle = Math.PI / 4 + i * Math.PI / 2;
box(
0.075,
0.075,
0.07,
mats.yellow,
Math.cos(angle) * boltRadius,
Math.sin(angle) * boltRadius,
0.27,
group
);
}
return group;
}
const driveCenter = new THREE.Vector2(-2.45, 1.65);
const driveRadius = 1.12;
const drivePulley = new THREE.Group();
drivePulley.position.set(driveCenter.x, driveCenter.y, 0.12);
scene.add(drivePulley);
const rotatingDrive = makePulley(driveRadius, mats.orange, 8, drivePulley);
rotatingDrive.position.z = 0;
// Pedal crank sits in front of the flywheel.
const crank = new THREE.Group();
crank.position.set(driveCenter.x, driveCenter.y, 0.56);
scene.add(crank);
for (const direction of [1, -1]) {
box(
0.72,
0.13,
0.13,
mats.yellow,
direction * 0.36,
0,
0,
crank
);
}
cylinderZ(0.19, 0.18, mats.ink, 0, 0, 0.02, crank);
const pedalGroups = [];
for (const direction of [1, -1]) {
const pedal = new THREE.Group();
pedal.position.set(direction * 0.79, 0, 0.09);
crank.add(pedal);
pedalGroups.push(pedal);
box(0.48, 0.13, 0.31, mats.rubber, 0, 0, 0, pedal);
box(0.54, 0.055, 0.08, mats.steel, 0, 0.08, -0.09, pedal);
box(0.54, 0.055, 0.08, mats.steel, 0, 0.08, 0, pedal);
box(0.54, 0.055, 0.08, mats.steel, 0, 0.08, 0.09, pedal);
}
// -------------------------------------------------------------------------
// Sliding generator assembly
// -------------------------------------------------------------------------
const outputRadius = 0.48;
const outputY = 2.72;
const outputAssembly = new THREE.Group();
scene.add(outputAssembly);
const outputPulleyMount = new THREE.Group();
outputPulleyMount.position.set(0, outputY, 0.12);
outputAssembly.add(outputPulleyMount);
const rotatingOutput = makePulley(outputRadius, mats.yellow, 6, outputPulleyMount);
// Generator can and rear cap.
cylinderZ(0.50, 0.88, mats.blue, 0, outputY, -0.55, outputAssembly, 12);
cylinderZ(0.43, 0.10, mats.frameLight, 0, outputY, -1.02, outputAssembly, 12);
// Generator casing ribs.
for (const x of [-0.28, 0.28]) {
box(0.11, 0.62, 0.10, mats.cream, x, outputY, -0.10, outputAssembly);
}
// Carriage and upright.
box(0.48, 0.42, 0.54, mats.orange, 0, 1.59, -0.12, outputAssembly);
box(0.20, 0.96, 0.22, mats.frame, 0, 2.08, -0.35, outputAssembly);
box(0.58, 0.16, 0.28, mats.frameLight, 0, 2.49, -0.35, outputAssembly);
// Terminal board and indicator lamps on top of the generator.
box(0.68, 0.12, 0.28, mats.ink, 0, 3.30, -0.43, outputAssembly);
const generatorLeds = [];
for (let i = 0; i < 4; i++) {
const ledMat = mats.green.clone();
const led = box(
0.105,
0.105,
0.105,
ledMat,
-0.225 + i * 0.15,
3.405,
-0.36,
outputAssembly
);
generatorLeds.push(led);
}
// Terminal cubes, explicitly schematic rather than functional wiring.
box(0.10, 0.10, 0.10, mats.red, -0.23, 3.30, -0.20, outputAssembly);
box(0.10, 0.10, 0.10, mats.steel, 0, 3.30, -0.20, outputAssembly);
box(0.10, 0.10, 0.10, mats.teal, 0.23, 3.30, -0.20, outputAssembly);
// Spring and tension screw.
const springBlocks = [];
for (let i = 0; i < 10; i++) {
springBlocks.push(
box(0.095, 0.095, 0.095, mats.orange, 0, 1.59, 0.08, scene)
);
}
const tensionRod = cylinderZ(
0.055,
0.82,
mats.steel,
1.74,
1.59,
0.08,
scene,
8
);
tensionRod.rotation.set(0, Math.PI / 2, 0);
const tensionKnob = box(0.22, 0.36, 0.34, mats.yellow, 2.12, 1.59, 0.08);
addEdges(tensionKnob);
// -------------------------------------------------------------------------
// Schematic generator output board
// -------------------------------------------------------------------------
function makeSchematicTexture() {
const c = document.createElement("canvas");
c.width = 768;
c.height = 640;
const ctx = c.getContext("2d");
ctx.fillStyle = "#17282f";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "#304650";
ctx.lineWidth = 4;
ctx.strokeRect(18, 18, c.width - 36, c.height - 36);
ctx.fillStyle = "#efb84e";
ctx.fillRect(18, 18, 18, c.height - 36);
ctx.fillStyle = "#f3f0e7";
ctx.font = "900 42px system-ui, sans-serif";
ctx.fillText("GENERATOR", 66, 83);
ctx.fillStyle = "#2c9d91";
ctx.font = "800 22px system-ui, sans-serif";
ctx.fillText("SCHEMATIC AC OUTPUT", 67, 122);
// Generator symbol.
ctx.strokeStyle = "#f3f0e7";
ctx.lineWidth = 8;
ctx.beginPath();
ctx.arc(175, 260, 70, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(105, 260);
ctx.lineTo(245, 260);
ctx.stroke();
ctx.fillStyle = "#efb84e";
ctx.font = "900 62px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("G", 175, 282);
ctx.textAlign = "left";
// Sine-wave output.
ctx.strokeStyle = "#2c9d91";
ctx.lineWidth = 9;
ctx.beginPath();
for (let x = 310; x <= 670; x++) {
const y = 260 + Math.sin((x - 310) * 0.035) * 58;
if (x === 310) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
// Terminal nodes.
for (const x of [310, 670]) {
ctx.fillStyle = "#efb84e";
ctx.fillRect(x - 8, 252, 16, 16);
}
ctx.fillStyle = "#9eb0b4";
ctx.font = "700 19px system-ui, sans-serif";
ctx.fillText("ILLUSTRATIVE SIGNAL PATH", 67, 395);
ctx.fillStyle = "#17282f";
ctx.fillRect(64, 430, 640, 110);
ctx.strokeStyle = "#efb84e";
ctx.lineWidth = 3;
ctx.strokeRect(64, 430, 640, 110);
ctx.fillStyle = "#efb84e";
ctx.font = "900 29px system-ui, sans-serif";
ctx.fillText("SCHEMATIC ONLY", 92, 477);
ctx.fillStyle = "#9eb0b4";
ctx.font = "600 20px system-ui, sans-serif";
ctx.fillText("NO DIRECT ELECTRICAL CONNECTION OR LOAD", 92, 514);
ctx.fillStyle = "#5f747b";
ctx.font = "700 17px system-ui, sans-serif";
ctx.fillText("BELT LAB / GENERATOR INDICATOR / REV 01", 66, 588);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
const schematicTexture = makeSchematicTexture();
const panelGroup = new THREE.Group();
panelGroup.position.set(3.68, 2.66, -0.43);
scene.add(panelGroup);
const panelBox = box(2.55, 2.23, 0.18, mats.ink, 0, 0, 0, panelGroup);
addEdges(panelBox, 0x080d0f, 0.7);
const panelFace = new THREE.Mesh(
new THREE.PlaneGeometry(2.30, 1.98),
new THREE.MeshBasicMaterial({ map: schematicTexture })
);
panelFace.position.z = 0.096;
panelGroup.add(panelFace);
// -------------------------------------------------------------------------
// Open-belt geometry
//
// The belt centerline uses exact external tangents between the two pulleys.
// The tension carriage changes the output pulley center, so the belt is
// rebuilt and remains tangent rather than being a decorative diagonal.
// -------------------------------------------------------------------------
const beltMaterial = material(palette.rubber, {
roughness: 0.93,
metalness: 0
});
const beltGeometry = new THREE.BoxGeometry(1, 0.075, 0.14);
const beltMesh = new THREE.InstancedMesh(beltGeometry, beltMaterial, 320);
beltMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
beltMesh.castShadow = true;
beltMesh.receiveShadow = true;
beltMesh.frustumCulled = false;
scene.add(beltMesh);
const beltMarkers = [];
for (let i = 0; i < 7; i++) {
const marker = box(
0.075,
0.145,
0.17,
mats.yellow,
0,
0,
0.415
);
marker.castShadow = false;
beltMarkers.push(marker);
}
function computeOpenBeltPath(c1, r1, c2, r2) {
const dx = c2.x - c1.x;
const dy = c2.y - c1.y;
const distance = Math.hypot(dx, dy);
const phi = Math.atan2(dy, dx);
const ratio = THREE.MathUtils.clamp((r1 - r2) / distance, -1, 1);
const alpha = Math.acos(ratio);
const lowerAngle = phi - alpha;
const upperAngle = phi + alpha;
const points = [];
const arcA = 76;
const arcB = 44;
const lineSamples = 38;
// Large pulley: outer wrap, from upper tangent around the left side.
for (let i = 0; i <= arcA; i++) {
const t = i / arcA;
const angle = THREE.MathUtils.lerp(
upperAngle,
lowerAngle + Math.PI * 2,
t
);
points.push(
new THREE.Vector2(
c1.x + Math.cos(angle) * r1,
c1.y + Math.sin(angle) * r1
)
);
}
const aLower = new THREE.Vector2(
c1.x + Math.cos(lowerAngle) * r1,
c1.y + Math.sin(lowerAngle) * r1
);
const bLower = new THREE.Vector2(
c2.x + Math.cos(lowerAngle) * r2,
c2.y + Math.sin(lowerAngle) * r2
);
for (let i = 1; i <= lineSamples; i++) {
points.push(aLower.clone().lerp(bLower, i / lineSamples));
}
// Small pulley: outer wrap on the opposite, right-hand side.
for (let i = 1; i <= arcB; i++) {
const t = i / arcB;
const angle = THREE.MathUtils.lerp(lowerAngle, upperAngle, t);
points.push(
new THREE.Vector2(
c2.x + Math.cos(angle) * r2,
c2.y + Math.sin(angle) * r2
)
);
}
const aUpper = new THREE.Vector2(
c1.x + Math.cos(upperAngle) * r1,
c1.y + Math.sin(upperAngle) * r1
);
const bUpper = new THREE.Vector2(
c2.x + Math.cos(upperAngle) * r2,
c2.y + Math.sin(upperAngle) * r2
);
for (let i = 1; i <= lineSamples; i++) {
points.push(bUpper.clone().lerp(aUpper, i / lineSamples));
}
return points;
}
let beltPath = [];
let beltLength = 0;
let cumulativeLengths = [];
const dummy = new THREE.Object3D();
function rebuildBelt() {
const outputX = outputAssembly.position.x;
const outputCenter = new THREE.Vector2(outputX, outputY);
beltPath = computeOpenBeltPath(
driveCenter,
driveRadius,
outputCenter,
outputRadius
);
cumulativeLengths = [0];
beltLength = 0;
for (let i = 1; i < beltPath.length; i++) {
beltLength += beltPath[i].distanceTo(beltPath[i - 1]);
cumulativeLengths.push(beltLength);
}
beltMesh.count = beltPath.length - 1;
for (let i = 0; i < beltPath.length - 1; i++) {
const a = beltPath[i];
const b = beltPath[i + 1];
const dx = b.x - a.x;
const dy = b.y - a.y;
const length = Math.hypot(dx, dy);
const angle = Math.atan2(dy, dx);
dummy.position.set((a.x + b.x) / 2, (a.y + b.y) / 2, 0.34);
dummy.rotation.set(0, 0, angle);
dummy.scale.set(length * 1.035, 1, 1);
dummy.updateMatrix();
beltMesh.setMatrixAt(i, dummy.matrix);
}
beltMesh.instanceMatrix.needsUpdate = true;
}
function pointAtBeltDistance(distance) {
const d = ((distance % beltLength) + beltLength) % beltLength;
let low = 0;
let high = cumulativeLengths.length - 1;
while (low < high) {
const mid = Math.floor((low + high) / 2);
if (cumulativeLengths[mid] < d) low = mid + 1;
else high = mid;
}
const index = Math.max(1, low);
const prevLength = cumulativeLengths[index - 1];
const segmentLength = cumulativeLengths[index] - prevLength;
const t = segmentLength > 0 ? (d - prevLength) / segmentLength : 0;
return beltPath[index - 1].clone().lerp(beltPath[index], t);
}
function updateBeltMarkers(travel) {
const spacing = beltLength / beltMarkers.length;
for (let i = 0; i < beltMarkers.length; i++) {
const d = travel + i * spacing;
const point = pointAtBeltDistance(d);
const before = pointAtBeltDistance(d - 0.035);
const after = pointAtBeltDistance(d + 0.035);
const angle = Math.atan2(after.y - before.y, after.x - before.x);
beltMarkers[i].position.set(point.x, point.y, 0.415);
beltMarkers[i].rotation.z = angle;
}
}
// -------------------------------------------------------------------------
// Tension control
// -------------------------------------------------------------------------
let tension = 0.68;
let outputX = 0;
function updateTension() {
// Increasing spring tension pulls the carriage toward the drive pulley.
outputX = 1.12 - tension * 0.72;
outputAssembly.position.x = outputX;
// Stretch the visible voxel spring between carriage and fixed anchor.
const start = outputX + 0.28;
const end = 1.52;
const step = (end - start) / springBlocks.length;
springBlocks.forEach((block, i) => {
const t = (i + 0.5) / springBlocks.length;
block.position.x = start + step * (i + 0.5);
block.position.y = 1.59 + (i % 2 === 0 ? 0.075 : -0.075);
block.rotation.z = i % 2 === 0 ? 0.32 : -0.32;
});
rebuildBelt();
const percent = Math.round(tension * 100);
document.querySelector("#tension-output").value = `${percent}%`;
document.querySelector("#tension-readout").textContent = `${percent}%`;
}
document.querySelector("#tension").addEventListener("input", (event) => {
tension = Number(event.target.value) / 100;
updateTension();
});
// -------------------------------------------------------------------------
// Custom orbit controls, implemented without Three.js addons
// -------------------------------------------------------------------------
const controls = {
yaw: 0.43,
pitch: 0.46,
radius: 11.7,
target: new THREE.Vector3(0.2, 1.75, 0),
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const horizontal = controls.radius * Math.cos(controls.pitch);
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.yaw),
controls.target.y + controls.radius * Math.sin(controls.pitch),
controls.target.z + horizontal * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.yaw -= dx * 0.005;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.004,
0.18,
1.18
);
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.008,
7.3,
17
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", () => {
controls.yaw = 0.43;
controls.pitch = 0.46;
controls.radius = 11.7;
controls.target.set(0.2, 1.75, 0);
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Animation and UI
// -------------------------------------------------------------------------
let running = true;
let cadence = 48;
let driveAngle = 0;
let outputAngle = 0;
let beltTravel = 0;
const playButton = document.querySelector("#play");
const stateLabel = document.querySelector("#state");
const rpmLabel = document.querySelector("#rpm");
const generatorRpmLabel = document.querySelector("#generator-rpm");
const meterBars = [...document.querySelectorAll("#meter i")];
playButton.addEventListener("click", () => {
running = !running;
playButton.textContent = running ? "Pause" : "Run";
stateLabel.textContent = running ? "Running" : "Paused";
stateLabel.style.color = running ? "var(--teal)" : "var(--orange)";
});
const cadenceInput = document.querySelector("#cadence");
cadenceInput.addEventListener("input", (event) => {
cadence = Number(event.target.value);
document.querySelector("#cadence-output").value = `${cadence} RPM`;
rpmLabel.textContent = `${cadence} RPM`;
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (running) {
const inputRadians = (cadence / 60) * Math.PI * 2 * dt;
driveAngle += inputRadians;
outputAngle += inputRadians * (driveRadius / outputRadius);
beltTravel += inputRadians * driveRadius;
}
rotatingDrive.rotation.z = driveAngle;
rotatingOutput.rotation.z = outputAngle;
crank.rotation.z = driveAngle;
// Keep the pedal platforms level as the crank rotates.
pedalGroups.forEach((pedal) => {
pedal.rotation.z = -driveAngle;
});
updateBeltMarkers(beltTravel);
const generatorRpm = Math.round(cadence * (driveRadius / outputRadius));
generatorRpmLabel.textContent = `${generatorRpm} RPM`;
const activeBars = running
? Math.max(1, Math.min(6, Math.round(cadence / 15)))
: 0;
meterBars.forEach((bar, i) => {
bar.classList.toggle("on", i < activeBars);
bar.classList.toggle("hot", i < activeBars && i >= 4);
});
const ledCount = running
? Math.max(1, Math.min(4, Math.ceil(cadence / 23)))
: 0;
generatorLeds.forEach((led, i) => {
const on = i < ledCount;
led.material.emissiveIntensity = on ? 1.35 : 0.04;
led.material.color.setHex(on ? 0x77c86d : 0x32443e);
});
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
updateTension();
updateBeltMarkers(0);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 250);
});
</script>
</body>
</html>
```