Prompt specification
Build or customize the Three.js 3D scene "Workshop Rope Bridge Puzzle" 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: Workshop Rope Bridge Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/workshop-rope-bridge-puzzle-x3495
Scene Description Prompt:
Workshop rope bridge puzzle. Create an original workshop where players route a bounded rope through predefined pulley sockets. Show which arrangement raises a bridge under the declared idealized rules. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (workshop-rope-bridge-puzzle-x3495):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Lantern Lift — Voxel Rope Bridge Puzzle</title>
<style>
:root {
--ink: #f3e8d0;
--muted: #ad9f88;
--panel: rgba(25, 22, 19, 0.91);
--line: rgba(255, 220, 164, 0.16);
--gold: #efb65d;
--green: #74d7ae;
--red: #ef8373;
--blue: #8fb8ce;
--copper: #d99a55;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #17191e;
color: var(--ink);
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;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #17191e;
color: var(--gold);
font: 700 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 16px;
background:
linear-gradient(145deg, rgba(255, 220, 164, 0.055), transparent 40%),
var(--panel);
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.34),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(15px);
scrollbar-width: thin;
scrollbar-color: #725a3d transparent;
}
.eyebrow {
margin-bottom: 6px;
color: var(--gold);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 34px);
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.section {
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.section-title {
margin: 0 0 9px;
color: #d9c9aa;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
details {
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
summary {
padding: 10px 12px;
cursor: pointer;
color: #d9c9aa;
font: 700 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
user-select: none;
}
.rules {
margin: 0;
padding: 0 14px 12px 28px;
color: #c8baa3;
font-size: 12px;
line-height: 1.48;
}
.rules li {
margin: 6px 0;
}
.rules strong {
color: var(--ink);
}
.route {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
min-height: 58px;
padding: 9px;
border: 1px dashed rgba(239, 182, 93, 0.27);
border-radius: 10px;
background: rgba(0, 0, 0, 0.16);
}
.chip {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 32px;
height: 29px;
padding: 0 8px;
border: 1px solid #69727a;
border-radius: 7px;
background: #30363d;
color: #d9e3e8;
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chip.endpoint {
border-color: #65736d;
background: #293630;
color: #a9d8bf;
}
.chip.fixed {
border-color: #557687;
background: #263943;
color: var(--blue);
}
.chip.moving {
border-color: #9d6939;
background: #493421;
color: #efbd7b;
}
.chip.pending {
opacity: 0.48;
}
.arrow {
color: #786b57;
font: 700 12px/1 monospace;
}
.metric {
margin-top: 11px;
}
.metric-row {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 6px;
font-size: 11px;
}
.metric-row span:first-child {
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.08em;
font-weight: 700;
}
.metric-value {
color: var(--ink);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bar {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.bar > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--gold);
transition: width 180ms ease, background 180ms ease;
}
#liftFill {
background: var(--green);
}
.over #ropeFill {
background: var(--red);
}
.status {
margin-top: 14px;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.status strong {
display: block;
color: var(--gold);
font: 800 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.status.success strong {
color: var(--green);
}
.status.failure strong {
color: var(--red);
}
.status small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
button {
min-height: 38px;
padding: 9px 11px;
border: 1px solid rgba(239, 182, 93, 0.28);
border-radius: 9px;
background: #30271e;
color: #e8d9bf;
cursor: pointer;
font: 800 10px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(239, 182, 93, 0.7);
background: #403123;
}
button:active {
transform: translateY(0);
}
button.primary {
grid-column: 1 / -1;
border-color: #c78c43;
background: linear-gradient(135deg, #d99b4d, #ad6d32);
color: #21170e;
box-shadow: 0 8px 24px rgba(198, 127, 54, 0.2);
}
.hint {
margin-top: 12px;
color: #8f826d;
font-size: 10px;
line-height: 1.5;
}
kbd {
padding: 1px 4px;
border: 1px solid #544837;
border-radius: 4px;
background: #29231b;
color: #d6c5a8;
font: 700 9px/1.4 monospace;
}
#cornerNote {
position: fixed;
z-index: 9;
right: 18px;
bottom: 18px;
max-width: 300px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(22, 20, 18, 0.76);
color: #a99b84;
font-size: 10px;
line-height: 1.5;
backdrop-filter: blur(10px);
pointer-events: none;
}
#cornerNote strong {
color: var(--gold);
}
@media (max-width: 720px) {
.panel {
top: 10px;
left: 10px;
width: min(350px, calc(100vw - 20px));
max-height: calc(100vh - 80px);
padding: 14px;
}
#cornerNote {
right: 10px;
bottom: 10px;
max-width: calc(100vw - 20px);
}
}
</style>
</head>
<body>
<div id="loading">Opening the lantern lift workshop…</div>
<aside class="panel">
<div class="eyebrow">Lantern Lift Works · Puzzle 01</div>
<h1>The Rope Bridge</h1>
<p class="subtitle">
Route one bounded rope through the workshop’s fixed pulley sockets.
Find the arrangement that gives the bridge enough idealized lifting force.
</p>
<section class="section">
<details open>
<summary>Declared idealized rules</summary>
<ol class="rules">
<li>
The rope starts at the winch <strong>W</strong> and must finish at the
wall anchor <strong>A</strong>.
</li>
<li>
The rope is massless, inextensible, and frictionless. Tension
<strong>T</strong> is therefore equal throughout it.
</li>
<li>
Blue <strong>C</strong> sockets are fixed redirectors and add no lift.
Copper <strong>B1</strong> and <strong>B2</strong> ride on the bridge.
</li>
<li>
Under this puzzle’s topological idealization, a bridge sheave with
both neighboring sockets above it contributes <strong>2T</strong>.
Slant is visual only.
</li>
<li>
The bridge needs <strong>4T</strong>. The available line is
<strong>27.0 m</strong>; each segment costs its distance plus
<strong>0.55 m</strong> per pulley wrap.
</li>
</ol>
</details>
</section>
<section class="section">
<div class="section-title">Your rope route</div>
<div id="route" class="route" aria-live="polite"></div>
<div class="metric" id="ropeMetric">
<div class="metric-row">
<span>Rope required</span>
<span id="ropeValue" class="metric-value">0.0 / 27.0 m</span>
</div>
<div class="bar"><span id="ropeFill"></span></div>
</div>
<div class="metric">
<div class="metric-row">
<span>Bridge support</span>
<span id="liftValue" class="metric-value">0.0 / 4.0 T</span>
</div>
<div class="bar"><span id="liftFill"></span></div>
</div>
<div id="status" class="status" aria-live="polite">
<strong id="statusTitle">Build the route</strong>
<small id="statusDetail">
Select pulley sockets in travel order, then click anchor A.
</small>
</div>
<div class="buttons">
<button id="undoButton" type="button">Undo</button>
<button id="clearButton" type="button">Clear</button>
<button id="solutionButton" class="primary" type="button">
Show working arrangement
</button>
<button id="viewButton" type="button">Reset view</button>
</div>
<div class="hint">
Click sockets in the 3D workshop. Drag to orbit, right-drag to pan,
and use the wheel to zoom.
<br />
<kbd>U</kbd> undo · <kbd>R</kbd> clear · <kbd>H</kbd> solution
</div>
</section>
</aside>
<div id="cornerNote">
<strong>Workshop note:</strong> the displayed force is a declared puzzle
abstraction, not a structural or material simulation.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const MAX_ROPE = 27.0;
const WRAP_COST = 0.55;
const REQUIRED_LIFT = 4.0;
const SOLUTION = ["W", "C3", "B2", "C2", "B1", "A"];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17191e);
scene.fog = new THREE.Fog(0x17191e, 25, 48);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xb9c9d5, 0x3b2a1e, 1.8);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0ae, 3.4);
sun.position.set(7, 14, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00025;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x83a9c7, 1.25);
coolFill.position.set(-9, 7, -5);
scene.add(coolFill);
const lanternLight = new THREE.PointLight(0xffa94c, 14, 11, 2);
lanternLight.position.set(-7.1, 3.7, 2.2);
scene.add(lanternLight);
// ---------------------------------------------------------------------
// Small material and voxel construction helpers.
// ---------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02,
flatShading: true,
...options
});
}
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 71423;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function makeLabel(text, color = "#e9d6b7", scale = 1) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(20,18,16,0.92)";
ctx.fillRect(8, 12, 240, 72);
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.strokeRect(9, 13, 238, 70);
ctx.fillStyle = color;
ctx.font = "800 42px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.2 * scale, 0.45 * scale, 1);
sprite.renderOrder = 20;
return sprite;
}
const mats = {
ground: material(0x25282b),
trench: material(0x1e292e),
stone: material(0x56595a),
stoneDark: material(0x3e4244),
wall: material(0x4b4945),
wallDark: material(0x383a3a),
wood: material(0x805334),
woodLight: material(0xa16b40),
woodDark: material(0x4e3424),
steel: material(0x52616a, { metalness: 0.42, roughness: 0.55 }),
steelDark: material(0x283238, { metalness: 0.35, roughness: 0.62 }),
rope: material(0xb7803f, { roughness: 1 }),
gold: material(0xe5a84d, { metalness: 0.28, roughness: 0.45 }),
copper: material(0xc98343, { metalness: 0.35, roughness: 0.48 }),
blue: material(0x719bad, { metalness: 0.24, roughness: 0.55 }),
green: material(0x4f9d78),
cream: material(0xe6d4aa),
red: material(0xa9503e),
glass: material(0xffc568, {
emissive: 0xff9d36,
emissiveIntensity: 2.2,
roughness: 0.3
})
};
// ---------------------------------------------------------------------
// Build the voxel workshop.
// ---------------------------------------------------------------------
const workshop = new THREE.Group();
scene.add(workshop);
addBox(
workshop,
[21, 0.5, 10],
[0, -0.42, 0],
mats.ground
);
// Trench bottom and bank tiles.
for (let x = -4.4; x < 8.2; x += 0.8) {
addBox(
workshop,
[0.76, 0.12, 8.6],
[x, -0.10, 0],
mats.trench,
false
);
}
for (let x = -10; x <= 9.7; x += 0.86) {
for (let z = -4.2; z <= 4.1; z += 0.86) {
const inGap = x > -5.0 && x < 8.2;
if (inGap) continue;
const shade = random();
const tileMat =
shade > 0.72
? mats.stone
: shade > 0.38
? mats.stoneDark
: material(0x484d4f);
addBox(
workshop,
[0.79, 0.18, 0.79],
[x, -0.03, z],
tileMat,
false
);
}
}
// Brick rear wall.
for (let row = 0; row < 10; row++) {
const offset = row % 2 ? 0.9 : 0;
for (let col = -6; col < 6; col++) {
const x = col * 1.78 + offset;
const y = 0.38 + row * 0.68;
if (row > 3 && row < 7 && x > -1.8 && x < 1.8) {
continue;
}
const brickMat = random() > 0.5 ? mats.wall : mats.wallDark;
addBox(
workshop,
[1.68, 0.58, 0.34],
[x, y, -4.65],
brickMat
);
}
}
// Window frame made from blocks.
for (let x = -2.7; x <= 2.7; x += 0.9) {
addBox(
workshop,
[0.78, 0.62, 0.15],
[x, 3.55, -4.42],
material(0x304d5b, {
emissive: 0x172a35,
emissiveIntensity: 0.6
}),
false
);
}
addBox(workshop, [5.5, 0.14, 0.2], [0, 3.55, -4.25], mats.woodDark);
addBox(workshop, [0.14, 2.2, 0.2], [0, 3.55, -4.25], mats.woodDark);
// Structural beams.
addBox(workshop, [18.5, 0.4, 0.48], [0.2, 7.5, 0], mats.woodDark);
addBox(workshop, [18.5, 0.32, 0.4], [0.2, 6.95, -4.2], mats.wood);
addBox(workshop, [0.48, 7.4, 0.48], [-9.0, 3.7, -0.2], mats.woodDark);
addBox(workshop, [0.48, 7.4, 0.48], [9.0, 3.7, -0.2], mats.woodDark);
addBox(workshop, [18.4, 0.32, 0.34], [0, 5.9, -3.95], mats.wood);
// Left workbench.
addBox(workshop, [3.4, 0.28, 1.25], [-7.2, 1.55, 2.35], mats.woodLight);
for (const x of [-8.55, -5.85]) {
addBox(workshop, [0.3, 1.55, 0.3], [x, 0.75, 2.0], mats.woodDark);
addBox(workshop, [0.3, 1.55, 0.3], [x, 0.75, 2.7], mats.woodDark);
}
addBox(workshop, [2.7, 0.16, 0.75], [-7.2, 0.65, 2.35], mats.woodDark);
// Tools on the rear wall.
addBox(workshop, [2.5, 1.35, 0.12], [-7.2, 3.3, -4.38], mats.woodDark);
for (let i = 0; i < 4; i++) {
const x = -8.1 + i * 0.6;
addBox(workshop, [0.12, 0.7, 0.12], [x, 3.3, -4.25], mats.steel);
addBox(workshop, [0.42, 0.16, 0.18], [x, 3.55, -4.25], mats.steel);
}
// Shelves.
for (const y of [2.0, 3.35, 4.7]) {
addBox(workshop, [3.4, 0.18, 0.8], [-7.0, y, -3.75], mats.wood);
}
for (let i = 0; i < 5; i++) {
const crate = addBox(
workshop,
[0.5, 0.55, 0.5],
[-8.25 + i * 0.62, 4.98, -3.68],
i % 2 ? mats.woodLight : mats.woodDark
);
crate.rotation.y = (random() - 0.5) * 0.15;
}
// Crates near the right bank.
addBox(workshop, [1.2, 1.1, 1.15], [8.8, 0.55, 2.7], mats.wood);
addBox(workshop, [1.0, 0.85, 0.95], [8.7, 1.48, 2.65], mats.woodLight);
addBox(workshop, [0.15, 1.12, 1.18], [8.8, 0.55, 2.7], mats.woodDark);
// Voxel lantern.
addBox(workshop, [0.16, 1.0, 0.16], [-7.1, 4.2, 2.2], mats.steelDark);
addBox(workshop, [0.55, 0.55, 0.55], [-7.1, 3.65, 2.2], mats.glass, false);
addBox(workshop, [0.68, 0.13, 0.68], [-7.1, 3.95, 2.2], mats.steelDark);
addBox(workshop, [0.68, 0.13, 0.68], [-7.1, 3.35, 2.2], mats.steelDark);
const shopSign = makeLabel("LIFT SHOP", "#efb65d", 1.25);
shopSign.position.set(-0.2, 6.75, -4.25);
workshop.add(shopSign);
// ---------------------------------------------------------------------
// The movable bridge and its two moving sheaves.
// ---------------------------------------------------------------------
const bridge = new THREE.Group();
scene.add(bridge);
const deckMaterials = [mats.wood, mats.woodLight, mats.woodDark];
for (let x = -4.25, i = 0; x < 8; x += 0.5, i++) {
addBox(
bridge,
[0.46, 0.24, 2.5],
[x, 2.02, 0],
deckMaterials[i % 3]
);
// Short curb blocks keep the working face visually open.
addBox(
bridge,
[0.46, 0.18, 0.16],
[x, 2.2, -1.27],
mats.woodDark
);
}
addBox(bridge, [12.3, 0.26, 0.3], [1.9, 1.72, -0.82], mats.woodDark);
addBox(bridge, [12.3, 0.26, 0.3], [1.9, 1.72, 0.82], mats.woodDark);
for (const x of [-4.1, -1.9, 0.3, 2.5, 4.7, 6.9]) {
addBox(bridge, [0.2, 0.8, 0.2], [x, 2.52, -1.18], mats.woodDark);
}
addBox(bridge, [11.3, 0.15, 0.15], [1.35, 2.9, -1.18], mats.wood);
// ---------------------------------------------------------------------
// Sockets and endpoints.
// ---------------------------------------------------------------------
const socketDefs = {
W: {
id: "W",
kind: "endpoint",
label: "W",
pos: new THREE.Vector3(7.6, 1.25, 0)
},
C1: {
id: "C1",
kind: "fixed",
label: "C1",
pos: new THREE.Vector3(-3.6, 6.45, -0.15)
},
C2: {
id: "C2",
kind: "fixed",
label: "C2",
pos: new THREE.Vector3(2.0, 6.45, 0.15)
},
C3: {
id: "C3",
kind: "fixed",
label: "C3",
pos: new THREE.Vector3(5.2, 6.45, -0.15)
},
C4: {
id: "C4",
kind: "fixed",
label: "C4",
pos: new THREE.Vector3(8.0, 6.45, 2.6)
},
B1: {
id: "B1",
kind: "moving",
label: "B1",
pos: new THREE.Vector3(2.0, 3.2, 0)
},
B2: {
id: "B2",
kind: "moving",
label: "B2",
pos: new THREE.Vector3(5.2, 3.2, 0)
},
A: {
id: "A",
kind: "endpoint",
label: "A",
pos: new THREE.Vector3(-4.8, 6.45, 0)
}
};
const socketVisuals = new Map();
const hitMeshes = [];
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
function createPulley(id, position, parent = scene) {
const def = socketDefs[id];
const group = new THREE.Group();
group.position.copy(position);
parent.add(group);
const isMoving = def.kind === "moving";
const wheelMaterial = material(
isMoving ? 0xd99a55 : 0x7f9dab,
{
metalness: isMoving ? 0.4 : 0.26,
roughness: 0.46,
emissive: 0x000000
}
);
const frameMaterial = material(
isMoving ? 0x6f4529 : 0x34444d,
{ metalness: 0.25, roughness: 0.58 }
);
const wheel = new THREE.Group();
group.add(wheel);
// A square, visibly voxel-built pulley wheel.
addBox(wheel, [0.68, 0.14, 0.2], [0, 0.27, 0], wheelMaterial);
addBox(wheel, [0.68, 0.14, 0.2], [0, -0.27, 0], wheelMaterial);
addBox(wheel, [0.14, 0.4, 0.2], [-0.27, 0, 0], wheelMaterial);
addBox(wheel, [0.14, 0.4, 0.2], [0.27, 0, 0], wheelMaterial);
addBox(wheel, [0.18, 0.18, 0.52], [0, 0, 0], mats.steelDark);
// Socket housing.
addBox(group, [0.12, 0.95, 0.12], [0, 0.85, 0], frameMaterial);
addBox(group, [0.82, 0.12, 0.36], [0, 0.52, -0.03], frameMaterial);
addBox(group, [0.82, 0.12, 0.36], [0, -0.52, -0.03], frameMaterial);
addBox(group, [0.12, 0.92, 0.36], [-0.36, 0, -0.03], frameMaterial);
addBox(group, [0.12, 0.92, 0.36], [0.36, 0, -0.03], frameMaterial);
if (isMoving) {
addBox(group, [0.16, 0.9, 0.16], [0, -0.72, 0], frameMaterial);
addBox(group, [0.55, 0.14, 0.55], [0, -1.05, 0], frameMaterial);
}
const label = makeLabel(
id,
isMoving ? "#efbd7b" : "#9bc5d7",
0.9
);
label.position.set(0, 1.25, 0);
group.add(label);
const hit = new THREE.Mesh(
new THREE.BoxGeometry(1.1, 1.15, 0.95),
hitMaterial
);
hit.position.y = 0.1;
hit.userData.socketId = id;
group.add(hit);
hitMeshes.push(hit);
let supportGlyph = null;
if (isMoving) {
supportGlyph = new THREE.Group();
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x74efbd,
transparent: true,
opacity: 0.9,
depthTest: false
});
for (const x of [-0.42, 0.42]) {
addBox(
supportGlyph,
[0.055, 0.7, 0.055],
[x, -0.58, 0.03],
arrowMaterial,
false
);
addBox(
supportGlyph,
[0.2, 0.12, 0.2],
[x, -0.2, 0.03],
arrowMaterial,
false
);
}
supportGlyph.visible = false;
group.add(supportGlyph);
}
socketVisuals.set(id, {
id,
group,
wheel,
wheelMaterial,
frameMaterial,
hit,
supportGlyph,
rest: position.clone()
});
}
// Fixed overhead sockets.
createPulley("C1", socketDefs.C1.pos);
createPulley("C2", socketDefs.C2.pos);
createPulley("C3", socketDefs.C3.pos);
createPulley("C4", socketDefs.C4.pos);
// The two moving bridge sockets are children of the bridge.
createPulley("B1", socketDefs.B1.pos, bridge);
createPulley("B2", socketDefs.B2.pos, bridge);
// Wall anchor A.
const anchorGroup = new THREE.Group();
anchorGroup.position.copy(socketDefs.A.pos);
scene.add(anchorGroup);
addBox(anchorGroup, [0.9, 0.9, 0.25], [0, 0, -0.14], mats.steelDark);
addBox(anchorGroup, [0.18, 0.92, 0.28], [-0.38, 0, 0.02], mats.gold);
addBox(anchorGroup, [0.18, 0.92, 0.28], [0.38, 0, 0.02], mats.gold);
addBox(anchorGroup, [0.78, 0.18, 0.28], [0, -0.4, 0.02], mats.gold);
addBox(anchorGroup, [0.17, 1.0, 0.17], [0, 0.9, 0], mats.steelDark);
const anchorLabel = makeLabel("A", "#a9d8bf", 0.9);
anchorLabel.position.set(0, 1.25, 0);
anchorGroup.add(anchorLabel);
const anchorHit = new THREE.Mesh(
new THREE.BoxGeometry(1.1, 1.15, 0.8),
hitMaterial
);
anchorHit.userData.socketId = "A";
anchorGroup.add(anchorHit);
hitMeshes.push(anchorHit);
socketVisuals.set("A", {
id: "A",
group: anchorGroup,
wheel: null,
wheelMaterial: null,
frameMaterial: null,
hit: anchorHit,
supportGlyph: null,
rest: socketDefs.A.pos.clone()
});
// Winch W and its visibly rotating voxel drum.
const winchGroup = new THREE.Group();
winchGroup.position.copy(socketDefs.W.pos);
scene.add(winchGroup);
addBox(winchGroup, [1.25, 0.22, 1.0], [0, -0.8, 0], mats.woodDark);
addBox(winchGroup, [0.25, 1.5, 0.28], [-0.57, -0.1, 0], mats.steelDark);
addBox(winchGroup, [0.25, 1.5, 0.28], [0.57, -0.1, 0], mats.steelDark);
const winchDrum = new THREE.Group();
winchGroup.add(winchDrum);
addBox(winchDrum, [0.75, 0.65, 0.8], [0, 0, 0], mats.rope);
addBox(winchDrum, [0.95, 0.12, 0.92], [0, 0.34, 0], mats.woodLight);
addBox(winchDrum, [0.95, 0.12, 0.92], [0, -0.34, 0], mats.woodLight);
const crank = new THREE.Group();
crank.position.set(0.65, 0, 0);
winchGroup.add(crank);
addBox(crank, [0.65, 0.12, 0.12], [0.25, 0, 0], mats.steel);
addBox(crank, [0.12, 0.45, 0.12], [0.55, 0.15, 0], mats.steel);
addBox(crank, [0.25, 0.1, 0.1], [0.55, 0.36, 0], mats.woodLight);
const winchLabel = makeLabel("W", "#a9d8bf", 0.9);
winchLabel.position.set(0, 1.25, 0);
winchGroup.add(winchLabel);
const winchHit = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 1.35, 1.1),
hitMaterial
);
winchHit.userData.socketId = "W";
winchGroup.add(winchHit);
hitMeshes.push(winchHit);
socketVisuals.set("W", {
id: "W",
group: winchGroup,
wheel: winchDrum,
wheelMaterial: null,
frameMaterial: null,
hit: winchHit,
supportGlyph: null,
rest: socketDefs.W.pos.clone()
});
// A secondary ceiling beam supports the offset C4 socket.
addBox(workshop, [2.3, 0.3, 0.32], [7.9, 7.48, 2.6], mats.woodDark);
// ---------------------------------------------------------------------
// Voxel rope rendering.
// ---------------------------------------------------------------------
const ropeGeometry = new THREE.BoxGeometry(0.13, 0.21, 0.13);
const ropeMesh = new THREE.InstancedMesh(
ropeGeometry,
mats.rope,
900
);
ropeMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
ropeMesh.frustumCulled = false;
ropeMesh.castShadow = true;
scene.add(ropeMesh);
const dummy = new THREE.Object3D();
const upAxis = new THREE.Vector3(0, 1, 0);
const direction = new THREE.Vector3();
function visualPosition(id, target = new THREE.Vector3()) {
const visual = socketVisuals.get(id);
if (!visual) return target.copy(socketDefs[id].pos);
return visual.group.getWorldPosition(target);
}
function rebuildRope() {
scene.updateMatrixWorld(true);
const points = [];
for (const id of route) {
points.push(visualPosition(id, new THREE.Vector3()));
}
// A short loose tail is visible before the player starts routing.
if (route.length === 1) {
points.push(
points[0].clone().add(new THREE.Vector3(0.18, -0.78, 0.12))
);
}
let instance = 0;
for (let i = 0; i < points.length - 1; i++) {
const from = points[i];
const to = points[i + 1];
direction.subVectors(to, from);
const length = direction.length();
if (length < 0.001) continue;
direction.normalize();
const steps = Math.max(1, Math.ceil(length / 0.15));
for (let step = 0; step < steps; step++) {
if (instance >= ropeMesh.count + 900) break;
dummy.position.lerpVectors(
from,
to,
(step + 0.5) / steps
);
dummy.quaternion.setFromUnitVectors(upAxis, direction);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
ropeMesh.setMatrixAt(instance, dummy.matrix);
instance++;
}
}
// Blocky bends make each socket readable as a wrap point.
for (const point of points) {
if (instance >= 900) break;
dummy.position.copy(point);
dummy.quaternion.identity();
dummy.scale.set(1.16, 1.16, 1.16);
dummy.updateMatrix();
ropeMesh.setMatrixAt(instance, dummy.matrix);
instance++;
}
ropeMesh.count = instance;
ropeMesh.instanceMatrix.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Puzzle state and evaluation.
// ---------------------------------------------------------------------
let route = ["W"];
let bridgeLift = 0;
let targetLift = 0;
let workingArrangement = false;
function segmentLength(a, b) {
return socketDefs[a].pos.distanceTo(socketDefs[b].pos);
}
function evaluateRoute() {
let ropeCost = 0;
for (let i = 0; i < route.length - 1; i++) {
ropeCost += segmentLength(route[i], route[i + 1]);
}
// Only true pulleys consume wrap length.
for (const id of route) {
const kind = socketDefs[id].kind;
if (kind === "fixed" || kind === "moving") {
ropeCost += WRAP_COST;
}
}
let lift = 0;
const supported = new Set();
for (let i = 1; i < route.length - 1; i++) {
const id = route[i];
if (socketDefs[id].kind !== "moving") continue;
const previous = socketDefs[route[i - 1]];
const next = socketDefs[route[i + 1]];
const sheave = socketDefs[id];
const previousAbove = previous.pos.y > sheave.pos.y + 0.45;
const nextAbove = next.pos.y > sheave.pos.y + 0.45;
if (previousAbove && nextAbove) {
lift += 2;
supported.add(id);
}
}
const finalized = route[route.length - 1] === "A";
const valid =
finalized &&
ropeCost <= MAX_ROPE + 0.0001 &&
lift >= REQUIRED_LIFT;
return { ropeCost, lift, supported, finalized, valid };
}
function routeChip(id, pending = false) {
const def = socketDefs[id];
return `
<span class="chip ${def.kind} ${pending ? "pending" : ""}">
${id}
</span>
`;
}
function renderUI() {
const result = evaluateRoute();
workingArrangement = result.valid;
targetLift = result.valid ? 1.12 : 0;
let routeHTML = route
.map((id) => routeChip(id))
.join('<span class="arrow">→</span>');
if (!result.finalized) {
routeHTML +=
'<span class="arrow">→</span>' + routeChip("A", true);
}
$("route").innerHTML = routeHTML;
$("ropeValue").textContent =
`${result.ropeCost.toFixed(1)} / ${MAX_ROPE.toFixed(1)} m`;
$("liftValue").textContent =
`${result.lift.toFixed(1)} / ${REQUIRED_LIFT.toFixed(1)} T`;
$("ropeFill").style.width =
`${Math.min(100, (result.ropeCost / MAX_ROPE) * 100)}%`;
$("liftFill").style.width =
`${Math.min(100, (result.lift / REQUIRED_LIFT) * 100)}%`;
$("ropeMetric").classList.toggle(
"over",
result.ropeCost > MAX_ROPE
);
const status = $("status");
status.classList.remove("success", "failure");
if (result.valid) {
status.classList.add("success");
$("statusTitle").textContent = "BRIDGE RAISES · WORKING ARRANGEMENT";
$("statusDetail").textContent =
"Both bridge sheaves are fed from above: 4.0T support, with the 27.0 m rope limit respected.";
} else if (result.finalized && result.ropeCost > MAX_ROPE) {
status.classList.add("failure");
$("statusTitle").textContent = "ROPE EXCEEDS THE BOUND";
$("statusDetail").textContent =
`This route needs ${(result.ropeCost - MAX_ROPE).toFixed(1)} m more line. Undo A or select a shorter arrangement.`;
} else if (result.finalized && result.lift < REQUIRED_LIFT) {
status.classList.add("failure");
$("statusTitle").textContent = "NOT ENOUGH LIFT";
$("statusDetail").textContent =
"Use B1 and B2, each with an overhead socket on both sides, to obtain 4.0T.";
} else if (result.finalized) {
status.classList.add("failure");
$("statusTitle").textContent = "ROUTE DOES NOT RAISE THE BRIDGE";
$("statusDetail").textContent =
"The line fits, but the declared support topology is insufficient.";
} else {
$("statusTitle").textContent = "BUILD THE ROUTE";
$("statusDetail").textContent =
"Select C and B sockets in travel order, then click anchor A.";
}
for (const id of ["B1", "B2"]) {
const visual = socketVisuals.get(id);
visual.supportGlyph.visible = result.supported.has(id);
}
mats.rope.emissive.setHex(result.valid ? 0x3c2108 : 0x000000);
rebuildRope();
}
function selectSocket(id) {
if (id === "W") return;
// Clicking the last selected node removes it.
if (route[route.length - 1] === id && id !== "A") {
route.pop();
renderUI();
return;
}
if (route.includes(id)) return;
// A is always the terminal node.
if (id !== "A" && route[route.length - 1] === "A") {
route.pop();
}
route.push(id);
renderUI();
}
function undoRoute() {
if (route.length > 1) route.pop();
renderUI();
}
function clearRoute() {
route = ["W"];
renderUI();
}
function showSolution() {
route = [...SOLUTION];
renderUI();
}
$("undoButton").addEventListener("click", undoRoute);
$("clearButton").addEventListener("click", clearRoute);
$("solutionButton").addEventListener("click", showSolution);
// ---------------------------------------------------------------------
// Direct camera controls. No examples/addons are used.
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0.6, 3.0, 0),
yaw: 0.72,
polar: 1.04,
radius: 22
};
function updateCamera() {
const { target, yaw, polar, radius } = cameraState;
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.cos(yaw),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.sin(yaw)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.target.set(0.6, 3.0, 0);
cameraState.yaw = 0.72;
cameraState.polar = 1.04;
cameraState.radius = 22;
updateCamera();
}
$("viewButton").addEventListener("click", resetCamera);
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerDown = new THREE.Vector2();
let pointerIsDown = false;
let dragButton = 0;
let dragDistance = 0;
let hoveredSocket = null;
function pickSocket(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(hitMeshes, false);
if (hits.length) {
return hits[0].object.userData.socketId;
}
return null;
}
function setHovered(id) {
if (hoveredSocket === id) return;
hoveredSocket = id;
for (const visual of socketVisuals.values()) {
if (!visual.wheelMaterial) continue;
visual.wheelMaterial.emissive.setHex(
visual.id === id ? 0x6a4b20 : 0x000000
);
visual.wheelMaterial.emissiveIntensity =
visual.id === id ? 0.75 : 0;
}
renderer.domElement.style.cursor =
id && id !== "W" ? "pointer" : "grab";
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerIsDown = true;
dragButton = event.button;
dragDistance = 0;
pointerDown.set(event.clientX, event.clientY);
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerIsDown) {
setHovered(pickSocket(event));
return;
}
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
dragDistance += Math.abs(dx) + Math.abs(dy);
pointerDown.set(event.clientX, event.clientY);
if (dragButton === 0) {
cameraState.yaw -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.45,
1.38
);
} else if (dragButton === 2) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const panScale = cameraState.radius * 0.0015;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick = dragDistance < 7 && dragButton === 0;
pointerIsDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (wasClick) {
const id = pickSocket(event);
if (id) selectSocket(id);
}
setHovered(pickSocket(event));
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerIsDown = false;
setHovered(null);
});
renderer.domElement.addEventListener(
"pointerleave",
() => {
if (!pointerIsDown) setHovered(null);
}
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
13,
30
);
updateCamera();
},
{ passive: false }
);
addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "u") undoRoute();
if (event.key.toLowerCase() === "r") clearRoute();
if (event.key.toLowerCase() === "h") showSolution();
});
// ---------------------------------------------------------------------
// Animation.
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
bridgeLift = THREE.MathUtils.damp(
bridgeLift,
targetLift,
3.1,
delta
);
bridge.position.y = bridgeLift;
if (workingArrangement) {
winchDrum.rotation.z -= delta * 1.7;
crank.rotation.z -= delta * 1.7;
for (const id of ["B1", "B2"]) {
socketVisuals.get(id).wheel.rotation.z -= delta * 1.25;
}
}
for (const id of ["C1", "C2", "C3", "C4"]) {
if (route.includes(id)) {
socketVisuals.get(id).wheel.rotation.z += delta * 0.7;
}
}
lanternLight.intensity =
13.5 + Math.sin(elapsed * 7.1) * 0.8 +
Math.sin(elapsed * 11.7) * 0.35;
rebuildRope();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
renderUI();
rebuildRope();
renderer.setAnimationLoop(animate);
$("loading").style.display = "none";
</script>
</body>
</html>
```