Prompt specification
Build or customize the Three.js 3D scene "Warehouse hoist teaching diorama" 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: Warehouse hoist teaching diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/warehouse-hoist-teaching-diorama-x1423
Scene Description Prompt:
Warehouse hoist teaching diorama. Compose a small goods platform with two alternative pulley rigs and distance markers; animate synchronized lifts while keeping rope length and load displacement geometrically consistent. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (warehouse-hoist-teaching-diorama-x1423):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Warehouse Hoist Teaching Diorama</title>
<style>
:root {
color-scheme: dark;
--ink: #f6f1e7;
--muted: #aeb9ba;
--panel: rgba(19, 29, 34, 0.88);
--line: rgba(255, 255, 255, 0.12);
--orange: #ff7849;
--teal: #45d4c0;
--yellow: #f4bd52;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #ece7dc 0%, #cbc6bd 70%, #a9a59f 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--ink);
}
.title {
position: absolute;
top: 22px;
left: 24px;
max-width: min(430px, calc(100vw - 48px));
padding: 15px 18px 14px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 12px 34px rgba(20, 25, 27, 0.18);
backdrop-filter: blur(12px);
}
.eyebrow {
color: var(--yellow);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.title h1 {
margin: 5px 0 4px;
font-size: clamp(20px, 2.3vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.title p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.controls {
position: absolute;
top: 22px;
right: 24px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 9px;
background: var(--panel);
color: var(--ink);
padding: 9px 12px;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
}
button:hover { background: rgba(39, 55, 62, 0.96); }
.hint {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(19, 29, 34, 0.72);
color: #d1d8d7;
font-size: 11px;
backdrop-filter: blur(10px);
}
.metrics {
position: absolute;
left: 24px;
bottom: 22px;
width: min(470px, calc(100vw - 48px));
padding: 15px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 12px 34px rgba(20, 25, 27, 0.18);
backdrop-filter: blur(12px);
}
.status-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 11px;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
}
.status::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 12px rgba(69, 212, 192, 0.9);
}
.cycle {
color: var(--muted);
font-size: 10px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.metric-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px 9px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.06);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
white-space: nowrap;
font: 750 15px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.metric.a strong { color: var(--orange); }
.metric.b strong { color: var(--teal); }
.metric.lock strong { color: var(--yellow); }
.geometry {
position: absolute;
right: 24px;
bottom: 22px;
width: min(340px, calc(100vw - 48px));
padding: 15px 16px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 12px 34px rgba(20, 25, 27, 0.18);
backdrop-filter: blur(12px);
}
.geometry h2 {
margin: 0 0 9px;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.geometry p {
margin: 5px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.geometry code {
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
}
.legend {
display: flex;
gap: 14px;
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.legend i {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 5px;
border-radius: 2px;
vertical-align: -1px;
}
@media (max-width: 850px) {
.geometry { display: none; }
.hint { display: none; }
.title { top: 12px; left: 12px; }
.controls { top: 12px; right: 12px; }
.metrics { left: 12px; bottom: 12px; width: calc(100vw - 24px); }
}
@media (max-width: 560px) {
.title p { display: none; }
.title { padding: 11px 13px; }
.title h1 { font-size: 18px; }
.metric-grid { grid-template-columns: repeat(2, 1fr); }
.metrics { padding: 11px; }
.cycle { display: none; }
}
</style>
</head>
<body>
<div class="hud">
<section class="title">
<div class="eyebrow">Warehouse training bay 04</div>
<h1>Hoist & Pulley Geometry</h1>
<p>Two ideal rope systems lift identical loads. Watch the hand line travel while total rope length remains locked.</p>
</section>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom</div>
<button id="pause">Pause</button>
<button id="reset">Reset</button>
</div>
<section class="metrics">
<div class="status-row">
<div class="status">LOADS SYNCHRONIZED</div>
<div class="cycle" id="cycle">CYCLE 0.00 s</div>
</div>
<div class="metric-grid">
<div class="metric">
<span>Load lift</span>
<strong id="lift">0.00 m</strong>
</div>
<div class="metric a">
<span>A hand travel</span>
<strong id="haulA">0.00 m</strong>
</div>
<div class="metric b">
<span>B hand travel</span>
<strong id="haulB">0.00 m</strong>
</div>
<div class="metric lock">
<span>Rope length Δ</span>
<strong id="ropeDelta">0.000 m</strong>
</div>
</div>
</section>
<section class="geometry">
<h2>Geometric model</h2>
<p><code>RIG A / 1:1</code><br />Load rise Δy → hand end moves down Δy.</p>
<p><code>RIG B / 2:1</code><br />Load rise Δy → hand end moves down 2Δy.</p>
<p>Short supporting rope segments are balanced by lengthening the live hand segment. Pulley arcs stay constant.</p>
<div class="legend">
<span><i style="background:#ff7849"></i>load travel</span>
<span><i style="background:#45d4c0"></i>hand travel</span>
<span><i style="background:#f4bd52"></i>fixed structure</span>
</div>
</section>
</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 renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xc7c4bc, 19, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.9, 0);
let cameraAzimuth = 0.13;
let cameraPolar = 1.08;
let cameraRadius = 15.4;
function updateCamera() {
const horizontal = Math.sin(cameraPolar) * cameraRadius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraAzimuth),
cameraTarget.y + Math.cos(cameraPolar) * cameraRadius,
cameraTarget.z + horizontal * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff7e8, 0x46545c, 2.0);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff1d6, 3.0);
keyLight.position.set(-6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8fd9e5, 1.15);
fillLight.position.set(8, 5, -4);
scene.add(fillLight);
/* --------------------------------------------------------------------------
Shared materials and voxel helpers
-------------------------------------------------------------------------- */
const material = (color, roughness = 0.78, metalness = 0.0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const MAT = {
base: material(0x202b31),
floorA: material(0xffffff),
floorB: material(0xffffff),
wallA: material(0x67737a),
wallB: material(0x59666d),
frame: material(0x3a4b53, 0.68, 0.18),
frameLight: material(0x607079, 0.65, 0.16),
yellow: material(0xf4bd52),
orange: material(0xff7849),
teal: material(0x45d4c0),
blue: material(0x4d91c8),
wood: material(0xb87842),
woodLight: material(0xd39a58),
dark: material(0x182126),
rope: material(0x252d2f, 0.9),
pulley: material(0x73848a, 0.48, 0.42),
pulleyDark: material(0x34434a, 0.58, 0.32),
white: material(0xf1eee4),
rubber: material(0x12191c)
};
const UNIT_BOX = new THREE.BoxGeometry(1, 1, 1);
function box(w, h, d, mat, x, y, z, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(UNIT_BOX, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makePanelSprite(title, subtitle, accent = "#f4bd52") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 190;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(0,0,0,.24)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 7;
roundedRect(ctx, 8, 8, 624, 174, 22);
ctx.fillStyle = "rgba(18,28,33,.92)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.fillStyle = accent;
roundedRect(ctx, 8, 8, 15, 174, 7);
ctx.fill();
ctx.textAlign = "center";
ctx.fillStyle = "#f8f4ea";
ctx.font = "800 47px system-ui, sans-serif";
ctx.fillText(title, 326, 78);
ctx.fillStyle = "#afbec0";
ctx.font = "600 26px system-ui, sans-serif";
ctx.fillText(subtitle, 326, 126);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.55, 1.055, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeSmallLabel(text) {
const canvas = document.createElement("canvas");
canvas.width = 160;
canvas.height = 80;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 6, 6, 148, 68, 14);
ctx.fillStyle = "rgba(18,28,33,.84)";
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#d9e1df";
ctx.font = "700 31px ui-monospace, monospace";
ctx.fillText(text, 80, 41);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.64, 0.32, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeDynamicLabel(width = 1.0) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 96;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.3, 1);
sprite.renderOrder = 21;
function update(text, color = "#f4bd52") {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 310, 86, 16);
ctx.fillStyle = "rgba(16,25,29,.90)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = "800 35px ui-monospace, monospace";
ctx.fillText(text, 160, 50);
texture.needsUpdate = true;
}
return { sprite, update };
}
function voxelCrate(parent, cx, cy, cz, size, colorMat) {
const gap = 0.016;
const block = size / 2 - gap;
const stride = size / 2;
for (let ix = 0; ix < 2; ix++) {
for (let iy = 0; iy < 2; iy++) {
for (let iz = 0; iz < 2; iz++) {
box(
block, block, block,
colorMat,
cx + (ix - 0.5) * stride,
cy + (iy - 0.5) * stride,
cz + (iz - 0.5) * stride,
parent
);
}
}
}
box(size * 1.015, 0.035, 0.035, MAT.dark, cx, cy, cz + size / 2 + 0.01, parent);
box(0.045, size * 1.015, 0.035, MAT.dark, cx, cy, cz + size / 2 + 0.015, parent);
box(0.05, 0.03, size * 1.01, MAT.dark, cx, cy + size / 2 + 0.01, cz, parent);
}
/* --------------------------------------------------------------------------
Voxel pulley wheels
-------------------------------------------------------------------------- */
function makeVoxelPulley(radius, parent = scene) {
const group = new THREE.Group();
parent.add(group);
const blocks = 14;
for (let i = 0; i < blocks; i++) {
const a = (i / blocks) * Math.PI * 2;
const r = radius - 0.065;
const block = box(
0.145, 0.145, 0.18,
i % 2 === 0 ? MAT.pulley : MAT.pulleyDark,
Math.cos(a) * r,
Math.sin(a) * r,
0,
group
);
block.rotation.z = a + Math.PI / 2;
}
box(0.20, 0.20, 0.25, MAT.dark, 0, 0, 0, group);
box(radius * 0.70, 0.075, 0.15, MAT.pulleyDark, radius * 0.32, 0, 0, group);
box(0.11, radius * 0.68, 0.15, MAT.pulleyDark, 0, 0, 0, group);
// A bright index block makes wheel rotation readable.
box(0.13, 0.13, 0.20, MAT.yellow, radius * 0.55, 0, 0.015, group);
return group;
}
/* --------------------------------------------------------------------------
Polyline and block-segment ropes
-------------------------------------------------------------------------- */
class Polyline3 {
constructor(points) {
this.set(points);
}
set(points) {
this.points = points;
this.cumulative = [0];
this.total = 0;
for (let i = 1; i < points.length; i++) {
const a = points[i - 1];
const b = points[i];
const dx = b.x - a.x;
const dy = b.y - a.y;
const dz = b.z - a.z;
this.total += Math.hypot(dx, dy, dz);
this.cumulative.push(this.total);
}
}
pointAt(distance) {
const d = THREE.MathUtils.clamp(distance, 0, this.total);
let index = 1;
while (
index < this.cumulative.length - 1 &&
this.cumulative[index] < d
) {
index++;
}
const a = this.points[index - 1];
const b = this.points[index];
const segmentLength = this.cumulative[index] - this.cumulative[index - 1];
const t = segmentLength > 0
? (d - this.cumulative[index - 1]) / segmentLength
: 0;
return {
x: THREE.MathUtils.lerp(a.x, b.x, t),
y: THREE.MathUtils.lerp(a.y, b.y, t),
z: THREE.MathUtils.lerp(a.z, b.z, t)
};
}
}
class VoxelRope {
constructor(maxSegments = 190) {
const geometry = new THREE.BoxGeometry(0.052, 1, 0.052);
this.mesh = new THREE.InstancedMesh(geometry, MAT.rope, maxSegments);
this.mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
this.mesh.frustumCulled = false;
this.mesh.castShadow = true;
scene.add(this.mesh);
this.maxSegments = maxSegments;
this.path = new Polyline3([]);
this.dummy = new THREE.Object3D();
this.up = new THREE.Vector3(0, 1, 0);
this.direction = new THREE.Vector3();
}
set(points) {
this.path.set(points);
const count = Math.min(
this.maxSegments,
Math.max(2, Math.ceil(this.path.total / 0.066))
);
this.mesh.count = count;
const step = this.path.total / count;
for (let i = 0; i < count; i++) {
const p1 = this.path.pointAt(i * step);
const p2 = this.path.pointAt((i + 1) * step);
this.dummy.position.set(
(p1.x + p2.x) * 0.5,
(p1.y + p2.y) * 0.5,
(p1.z + p2.z) * 0.5
);
this.direction.set(
p2.x - p1.x,
p2.y - p1.y,
p2.z - p1.z
);
const length = this.direction.length();
if (length > 0.00001) {
this.direction.multiplyScalar(1 / length);
this.dummy.quaternion.setFromUnitVectors(this.up, this.direction);
}
this.dummy.scale.set(1, length * 1.12, 1);
this.dummy.updateMatrix();
this.mesh.setMatrixAt(i, this.dummy.matrix);
}
this.mesh.instanceMatrix.needsUpdate = true;
}
}
/* --------------------------------------------------------------------------
Diorama base, warehouse shell, props
-------------------------------------------------------------------------- */
box(12.6, 0.36, 6.6, MAT.base, 0, -0.27, 0);
const floorTileCount = 13 * 7;
const floorTiles = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.79, 0.08, 0.79),
MAT.floorA,
floorTileCount
);
floorTiles.receiveShadow = true;
scene.add(floorTiles);
const floorDummy = new THREE.Object3D();
let tileIndex = 0;
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 13; col++) {
floorDummy.position.set(
-5.4 + col * 0.9,
-0.04,
-2.7 + row * 0.9
);
floorDummy.updateMatrix();
floorTiles.setMatrixAt(tileIndex, floorDummy.matrix);
const shade = (row + col) % 3;
const color = new THREE.Color(
shade === 0 ? 0x536169 :
shade === 1 ? 0x4b5961 : 0x5a676d
);
floorTiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
floorTiles.instanceMatrix.needsUpdate = true;
floorTiles.instanceColor.needsUpdate = true;
// Rear warehouse wall, constructed from individual blocks.
for (let i = 0; i < 12; i++) {
box(
1.02, 1.75, 0.16,
i % 2 ? MAT.wallA : MAT.wallB,
-5.55 + i * 1.01,
0.87,
-2.83
);
}
// Global warehouse columns and beam.
box(0.22, 5.2, 0.25, MAT.frame, -5.9, 2.6, -2.72);
box(0.22, 5.2, 0.25, MAT.frame, 5.9, 2.6, -2.72);
box(12.1, 0.24, 0.28, MAT.frame, 0, 5.18, -2.72);
box(0.55, 0.16, 0.48, MAT.yellow, -5.9, 0.08, -2.72);
box(0.55, 0.16, 0.48, MAT.yellow, 5.9, 0.08, -2.72);
// Back-wall sign.
const warehouseSign = makePanelSprite(
"WAREHOUSE 04",
"HOIST COMPARISON BAY",
"#45d4c0"
);
warehouseSign.scale.set(2.35, 0.70, 1);
warehouseSign.position.set(0, 2.55, -2.68);
scene.add(warehouseSign);
// Small cargo stacks at the outer corners.
const cornerCargo = new THREE.Group();
scene.add(cornerCargo);
voxelCrate(cornerCargo, -5.15, 0.48, -2.05, 0.80, MAT.woodLight);
voxelCrate(cornerCargo, -5.15, 1.24, -2.05, 0.72, MAT.yellow);
voxelCrate(cornerCargo, 5.15, 0.48, -2.05, 0.80, MAT.teal);
voxelCrate(cornerCargo, 5.15, 1.25, -2.05, 0.70, MAT.blue);
/* --------------------------------------------------------------------------
Rig constants and frames
-------------------------------------------------------------------------- */
const BAY_A = -2.55;
const BAY_B = 2.55;
const HEIGHT = 4.35;
const RADIUS_A = 0.34;
const RADIUS_MOVING = 0.36;
const RADIUS_FIXED_B = 0.30;
const LEFT_ATTACH_BASE = 1.24;
const LEFT_FREE_BASE = 1.24;
const RIGHT_MOVING_BASE = 1.52;
const RIGHT_FREE_BASE = 3.15;
const MAX_LIFT = 0.95;
const ROPE_Z = 0.56;
const PULLEY_Z = 0.44;
const rightFixedCenterX =
BAY_B + RADIUS_MOVING + RADIUS_FIXED_B;
function buildRigFrame(bayX, accent) {
const leftPost = bayX - 1.27;
const rightPost = bayX + 1.27;
box(0.20, 5.0, 0.22, MAT.frame, leftPost, 2.5, -0.36);
box(0.20, 5.0, 0.22, MAT.frame, rightPost, 2.5, -0.36);
box(0.45, 0.14, 0.48, accent, leftPost, 0.07, -0.36);
box(0.45, 0.14, 0.48, accent, rightPost, 0.07, -0.36);
box(2.78, 0.22, 0.26, MAT.frameLight, bayX, 5.04, -0.36);
box(0.16, 0.16, 1.0, MAT.frameLight, bayX, 4.92, 0.05);
// Yellow block collars.
box(0.24, 0.30, 0.30, accent, bayX - 1.36, 5.04, -0.36);
box(0.24, 0.30, 0.30, accent, bayX + 1.36, 5.04, -0.36);
}
buildRigFrame(BAY_A, MAT.orange);
buildRigFrame(BAY_B, MAT.teal);
function buildPulleyHanger(x) {
box(0.12, 0.73, 0.12, MAT.frameLight, x, 4.78, PULLEY_Z);
box(0.38, 0.12, 0.22, MAT.frameLight, x, 5.06, PULLEY_Z);
box(0.16, 0.16, 0.22, MAT.yellow, x, 4.58, PULLEY_Z);
}
buildPulleyHanger(BAY_A);
buildPulleyHanger(rightFixedCenterX);
/* --------------------------------------------------------------------------
Platforms and voxel goods
-------------------------------------------------------------------------- */
function buildPlatform(bayX, accent, movingPulley = false) {
const group = new THREE.Group();
group.position.x = bayX;
scene.add(group);
// Blocky pallet runners.
box(1.52, 0.13, 0.18, MAT.wood, 0, 0.11, -0.44, group);
box(1.52, 0.13, 0.18, MAT.wood, 0, 0.11, 0.00, group);
box(1.52, 0.13, 0.18, MAT.wood, 0, 0.11, 0.44, group);
// Individual deck slats.
for (let i = 0; i < 6; i++) {
box(
0.22, 0.13, 1.18,
i % 2 ? MAT.woodLight : MAT.wood,
-0.68 + i * 0.272,
0.24,
0,
group
);
}
// Dollies / blocks below the pallet.
for (const x of [-0.53, 0.53]) {
box(0.31, 0.18, 1.06, MAT.rubber, x, 0.07, 0, group);
box(0.23, 0.12, 0.20, accent, x, 0.14, -0.39, group);
box(0.23, 0.12, 0.20, accent, x, 0.14, 0.39, group);
}
// Voxel goods.
voxelCrate(group, -0.30, 0.68, -0.08, 0.64, accent);
voxelCrate(group, 0.31, 0.61, 0.12, 0.50, MAT.yellow);
voxelCrate(group, 0.30, 1.02, 0.12, 0.40, MAT.blue);
// Small safety corner blocks.
box(0.17, 0.12, 0.17, MAT.yellow, -0.68, 0.35, 0.52, group);
box(0.17, 0.12, 0.17, MAT.yellow, 0.68, 0.35, 0.52, group);
if (movingPulley) {
const pulley = makeVoxelPulley(RADIUS_MOVING, group);
pulley.position.set(0, RIGHT_MOVING_BASE, PULLEY_Z);
box(
0.16, 0.30, 0.18,
MAT.pulleyDark,
0,
1.28,
PULLEY_Z,
group
);
return { group, pulley };
}
// Left load-side rope termination.
box(
0.17, 0.17, 0.20,
MAT.yellow,
-RADIUS_A,
LEFT_ATTACH_BASE,
PULLEY_Z,
group
);
return { group, pulley: null };
}
const platformA = buildPlatform(BAY_A, MAT.orange, false);
const platformB = buildPlatform(BAY_B, MAT.teal, true);
const pulleyA = makeVoxelPulley(RADIUS_A);
pulleyA.position.set(BAY_A, HEIGHT, PULLEY_Z);
const pulleyB = makeVoxelPulley(RADIUS_FIXED_B);
pulleyB.position.set(rightFixedCenterX, HEIGHT, PULLEY_Z);
// Visible fixed-end anchor for Rig B.
box(
0.17, 0.17, 0.20,
MAT.yellow,
BAY_B - RADIUS_MOVING,
HEIGHT,
PULLEY_Z
);
// Hand grips.
const gripA = box(
0.14, 0.23, 0.14,
MAT.orange,
BAY_A + RADIUS_A,
LEFT_FREE_BASE,
ROPE_Z
);
const gripB = box(
0.14, 0.23, 0.14,
MAT.teal,
rightFixedCenterX + RADIUS_FIXED_B,
RIGHT_FREE_BASE,
ROPE_Z
);
/* --------------------------------------------------------------------------
Rig labels, rulers, and haul markers
-------------------------------------------------------------------------- */
const labelA = makePanelSprite(
"RIG A / FIXED PULLEY",
"1:1 - HAND TRAVEL = LOAD TRAVEL",
"#ff7849"
);
labelA.position.set(BAY_A, 5.72, 0.02);
scene.add(labelA);
const labelB = makePanelSprite(
"RIG B / MOVING PULLEY",
"2:1 - HAND TRAVEL = 2 x LOAD TRAVEL",
"#45d4c0"
);
labelB.position.set(BAY_B, 5.72, 0.02);
scene.add(labelB);
function buildLiftRuler(x, accent) {
const z = 1.02;
box(0.035, 1.30, 0.035, MAT.white, x, 0.65, z);
for (let i = 0; i <= 6; i++) {
const y = 0.04 + i * 0.20;
box(
i % 2 === 0 ? 0.22 : 0.14,
0.025,
0.035,
MAT.white,
x,
y,
z
);
if (i % 2 === 0) {
const label = makeSmallLabel((i * 0.2).toFixed(1));
label.position.set(x - 0.30, y, z);
scene.add(label);
}
}
const liveBar = box(
0.065,
0.02,
0.065,
accent,
x + 0.15,
0.04,
z
);
liveBar.castShadow = false;
const liveTick = box(
0.25,
0.035,
0.065,
accent,
x + 0.15,
0.04,
z
);
liveTick.castShadow = false;
const liveLabel = makeDynamicLabel(0.92);
liveLabel.sprite.position.set(x + 0.40, 0.16, z);
scene.add(liveLabel.sprite);
return {
update(lift) {
liveBar.scale.y = Math.max(0.015, lift);
liveBar.position.y = 0.04 + Math.max(0, lift) * 0.5;
liveTick.position.y = 0.04 + lift;
liveLabel.sprite.position.y = 0.15 + lift * 0.52;
liveLabel.update(`+${lift.toFixed(2)} m`, "#f4bd52");
}
};
}
const rulerA = buildLiftRuler(BAY_A - 1.0, MAT.orange);
const rulerB = buildLiftRuler(BAY_B - 0.98, MAT.teal);
function buildHaulMarker(x, baseY, accent, multiplier) {
const z = 0.74;
const bar = box(
0.045,
0.02,
0.045,
accent,
x,
baseY,
z
);
const topTick = box(0.18, 0.03, 0.05, accent, x, baseY, z);
const bottomTick = box(0.18, 0.03, 0.05, accent, x, baseY, z);
const label = makeDynamicLabel(1.08);
label.sprite.position.set(x + 0.39, baseY, z);
scene.add(label.sprite);
return {
update(haul) {
bar.scale.y = Math.max(0.012, haul);
bar.position.y = baseY - Math.max(0, haul) * 0.5;
topTick.position.y = baseY;
bottomTick.position.y = baseY - haul;
label.sprite.position.y = baseY - haul * 0.52;
label.update(`${multiplier}x ${haul.toFixed(2)} m`, accent === MAT.orange ? "#ff7849" : "#45d4c0");
}
};
}
const haulMarkerA = buildHaulMarker(
BAY_A + RADIUS_A + 0.18,
LEFT_FREE_BASE,
MAT.orange,
1
);
const haulMarkerB = buildHaulMarker(
rightFixedCenterX + RADIUS_FIXED_B + 0.18,
RIGHT_FREE_BASE,
MAT.teal,
2
);
// Painted floor bays.
for (const bayX of [BAY_A, BAY_B]) {
for (let i = 0; i < 6; i++) {
box(
0.26,
0.025,
0.075,
MAT.yellow,
bayX - 0.75 + i * 0.30,
0.015,
1.47
);
}
box(0.075, 0.025, 1.10, MAT.yellow, bayX - 1.12, 0.015, 0.92);
box(0.075, 0.025, 1.10, MAT.yellow, bayX + 1.12, 0.015, 0.92);
}
/* --------------------------------------------------------------------------
Rope geometry
-------------------------------------------------------------------------- */
const ropeA = new VoxelRope();
const ropeB = new VoxelRope();
function point(x, y, z = ROPE_Z) {
return { x, y, z };
}
function leftRopePoints(attachY, freeY) {
const points = [
point(BAY_A - RADIUS_A, attachY),
point(BAY_A - RADIUS_A, HEIGHT)
];
// Wrap over the fixed pulley.
const arcSteps = 22;
for (let i = 1; i <= arcSteps; i++) {
const angle = Math.PI * (1 - i / arcSteps);
points.push(point(
BAY_A + Math.cos(angle) * RADIUS_A,
HEIGHT + Math.sin(angle) * RADIUS_A
));
}
points.push(point(BAY_A + RADIUS_A, freeY));
return points;
}
function rightRopePoints(movingY, freeY) {
const points = [
// Fixed overhead end.
point(BAY_B - RADIUS_MOVING, HEIGHT),
// Down to the moving pulley's left tangent.
point(BAY_B - RADIUS_MOVING, movingY)
];
// Wrap under the moving pulley.
const movingArcSteps = 24;
for (let i = 1; i <= movingArcSteps; i++) {
const angle = Math.PI + Math.PI * (i / movingArcSteps);
points.push(point(
BAY_B + Math.cos(angle) * RADIUS_MOVING,
movingY + Math.sin(angle) * RADIUS_MOVING
));
}
// Up to the fixed redirect pulley's left tangent.
points.push(point(
rightFixedCenterX - RADIUS_FIXED_B,
HEIGHT
));
// Wrap over the fixed redirect pulley.
const fixedArcSteps = 20;
for (let i = 1; i <= fixedArcSteps; i++) {
const angle = Math.PI * (1 - i / fixedArcSteps);
points.push(point(
rightFixedCenterX + Math.cos(angle) * RADIUS_FIXED_B,
HEIGHT + Math.sin(angle) * RADIUS_FIXED_B
));
}
// Down to the hand end.
points.push(point(
rightFixedCenterX + RADIUS_FIXED_B,
freeY
));
return points;
}
/* --------------------------------------------------------------------------
UI references and animation
-------------------------------------------------------------------------- */
const liftText = document.getElementById("lift");
const haulAText = document.getElementById("haulA");
const haulBText = document.getElementById("haulB");
const ropeDeltaText = document.getElementById("ropeDelta");
const cycleText = document.getElementById("cycle");
const pauseButton = document.getElementById("pause");
const resetButton = document.getElementById("reset");
let elapsed = 0;
let paused = false;
let baselineRopeA = 0;
let baselineRopeB = 0;
let initializedLengths = false;
const CYCLE_DURATION = 9;
function easeInOut(t) {
t = THREE.MathUtils.clamp(t, 0, 1);
return t * t * (3 - 2 * t);
}
function cycleLift(time) {
const t = time % CYCLE_DURATION;
if (t < 1.0) return 0;
if (t < 4.0) return MAX_LIFT * easeInOut((t - 1.0) / 3.0);
if (t < 5.0) return MAX_LIFT;
if (t < 8.0) return MAX_LIFT * (1 - easeInOut((t - 5.0) / 3.0));
return 0;
}
function updateScene(lift) {
// Both loads receive exactly the same vertical displacement.
platformA.group.position.y = lift;
platformB.group.position.y = lift;
/*
Rig A:
L = (H - attachY) + constantArc + (H - freeY)
Therefore freeY = freeY0 - lift.
Rig B:
L = 2(H - movingY) + constantArcs + (H - freeY)
Therefore freeY = freeY0 - 2 * lift.
*/
const leftAttachY = LEFT_ATTACH_BASE + lift;
const leftFreeY = LEFT_FREE_BASE - lift;
const rightMovingY = RIGHT_MOVING_BASE + lift;
const rightFreeY = RIGHT_FREE_BASE - 2 * lift;
ropeA.set(leftRopePoints(leftAttachY, leftFreeY));
ropeB.set(rightRopePoints(rightMovingY, rightFreeY));
gripA.position.y = leftFreeY;
gripB.position.y = rightFreeY;
pulleyA.rotation.z = -lift / RADIUS_A;
pulleyB.rotation.z = -2 * lift / RADIUS_FIXED_B;
platformB.pulley.rotation.z = lift / RADIUS_MOVING;
rulerA.update(lift);
rulerB.update(lift);
haulMarkerA.update(lift);
haulMarkerB.update(2 * lift);
if (!initializedLengths) {
baselineRopeA = ropeA.path.total;
baselineRopeB = ropeB.path.total;
initializedLengths = true;
}
const deltaA = Math.abs(ropeA.path.total - baselineRopeA);
const deltaB = Math.abs(ropeB.path.total - baselineRopeB);
const totalDelta = Math.max(deltaA, deltaB);
liftText.textContent = `${lift.toFixed(2)} m`;
haulAText.textContent = `${lift.toFixed(2)} m ↓`;
haulBText.textContent = `${(2 * lift).toFixed(2)} m ↓`;
ropeDeltaText.textContent = `${totalDelta.toFixed(3)} m`;
cycleText.textContent = `CYCLE ${(elapsed % CYCLE_DURATION).toFixed(2)} s`;
}
/* --------------------------------------------------------------------------
Custom camera controls: orbit, zoom, keyboard reset
-------------------------------------------------------------------------- */
const pointer = {
active: false,
x: 0,
y: 0,
pointerId: null
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.pointerId = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.pointerId) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar - dy * 0.005,
0.72,
1.36
);
});
function endPointer(event) {
if (event.pointerId !== pointer.pointerId) return;
pointer.active = false;
pointer.pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
9,
23
);
},
{ passive: false }
);
function resetCamera() {
cameraAzimuth = 0.13;
cameraPolar = 1.08;
cameraRadius = window.innerWidth < 650 ? 17.5 : 15.4;
}
renderer.domElement.addEventListener("dblclick", resetCamera);
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
resetButton.addEventListener("click", () => {
elapsed = 0;
resetCamera();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
}
if (event.key.toLowerCase() === "r") {
elapsed = 0;
resetCamera();
}
});
/* --------------------------------------------------------------------------
Resize and render loop
-------------------------------------------------------------------------- */
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
let lastTime = performance.now();
renderer.setAnimationLoop((now) => {
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) elapsed += dt;
const lift = cycleLift(elapsed);
updateScene(lift);
updateCamera();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```