Prompt specification
Build or customize the Three.js 3D scene "Temporary repair station" 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: Temporary repair station
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/temporary-repair-station-x0027
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing an extension cable reel. Arrange a garage work area with portable lights, tools, and cable covers; illuminate each lamp when its visible connection reaches the power distribution board. Voxel style.
Working Three.js Starter (temporary-repair-station-x0027):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Garage Cable Reel</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(13, 20, 26, 0.9);
--line: rgba(255, 255, 255, 0.13);
--muted: #91a3af;
--green: #73f5a0;
--yellow: #ffd166;
--red: #ff6b68;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101820;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app, #app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#app canvas {
touch-action: none;
cursor: grab;
}
#app canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 22px;
left: 22px;
max-width: min(440px, calc(100vw - 44px));
padding: 16px 18px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 5px;
color: var(--yellow);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #f5fbff;
font-size: clamp(19px, 2.4vw, 27px);
line-height: 1.1;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.control-card {
position: absolute;
top: 22px;
right: 22px;
width: min(310px, calc(100vw - 44px));
padding: 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.control-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: #eaf4fb;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.board-status {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--green);
font-size: 11px;
}
.board-status.offline { color: var(--red); }
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
button {
width: 100%;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 9px;
padding: 10px 12px;
color: #eef8ff;
background: #26333c;
font: inherit;
font-size: 12px;
font-weight: 750;
text-align: left;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #31424e;
border-color: rgba(255, 255, 255, 0.28);
}
button:active { transform: translateY(0); }
#powerButton {
margin-bottom: 12px;
background: #1e5536;
border-color: rgba(115, 245, 160, 0.4);
}
#powerButton.off {
background: #552b2b;
border-color: rgba(255, 107, 104, 0.4);
}
.route {
display: grid;
grid-template-columns: 11px 1fr auto;
align-items: center;
gap: 9px;
min-height: 31px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: #d6e3eb;
font-size: 11px;
}
.route .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #56646d;
}
.route.active .dot {
background: var(--green);
box-shadow: 0 0 10px rgba(115, 245, 160, 0.85);
}
.route span:last-child {
color: #758994;
font-size: 10px;
text-align: right;
}
.route.active span:last-child { color: var(--green); }
.lamp-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 12px;
}
.lamp-buttons button {
padding: 9px 5px;
text-align: center;
font-size: 10px;
}
.lamp-buttons button.connected {
color: var(--green);
background: #203a2d;
}
.lamp-buttons button.disconnected {
color: var(--red);
background: #40272a;
}
.hint {
position: absolute;
right: 22px;
bottom: 20px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 9px;
color: #aebdc7;
background: rgba(13, 20, 26, 0.78);
font-size: 11px;
}
.footer-note {
position: absolute;
left: 22px;
bottom: 20px;
color: rgba(218, 232, 240, 0.65);
font-size: 11px;
text-shadow: 0 1px 4px #000;
}
@media (max-width: 720px) {
.title-card {
top: 12px;
left: 12px;
padding: 12px 14px;
}
.subtitle { display: none; }
.control-card {
top: auto;
right: 12px;
bottom: 48px;
width: min(290px, calc(100vw - 24px));
padding: 12px;
}
.hint { right: 12px; bottom: 12px; }
.footer-note { display: none; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="ui">
<section class="title-card">
<div class="eyebrow">Garage Electrical Test</div>
<h1>Extension Cable Reel</h1>
<p class="subtitle">
Each portable lamp lights only when its visible cable path is complete
through the extension reel to the distribution board.
</p>
</section>
<section class="control-card">
<div class="control-title">
<span>Power Distribution</span>
<span id="boardStatus" class="board-status">
<span class="status-dot"></span>
<span id="boardStatusText">ONLINE</span>
</span>
</div>
<button id="powerButton">POWER BOARD: ON</button>
<div class="route" id="routeA">
<span class="dot"></span>
<span>Lamp A → Reel → Board</span>
<span>CONNECTED</span>
</div>
<div class="route" id="routeB">
<span class="dot"></span>
<span>Lamp B → Reel → Board</span>
<span>CONNECTED</span>
</div>
<div class="route" id="routeC">
<span class="dot"></span>
<span>Lamp C → Reel → Board</span>
<span>CONNECTED</span>
</div>
<div class="lamp-buttons">
<button id="lampA" class="connected">LAMP A<br>CONNECTED</button>
<button id="lampB" class="connected">LAMP B<br>CONNECTED</button>
<button id="lampC" class="connected">LAMP C<br>CONNECTED</button>
</div>
</section>
<div class="hint">Drag to orbit · Wheel to zoom · Click a lamp to disconnect it</div>
<div class="footer-note">Voxel-style interactive work area</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const app = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.15;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x111920);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.1, -0.45);
const orbit = {
yaw: 0.56,
pitch: 0.57,
radius: 22,
zoom: 1
};
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = Math.max(6.8, 9.4 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
const cp = Math.cos(orbit.pitch);
camera.position.set(
cameraTarget.x + orbit.radius * Math.sin(orbit.yaw) * cp,
cameraTarget.y + orbit.radius * Math.sin(orbit.pitch),
cameraTarget.z + orbit.radius * Math.cos(orbit.yaw) * cp
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb9d8ef, 0x343029, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d4, 2.7);
keyLight.position.set(-7, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
// -------------------------------------------------------------------------
// Voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function standardMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.06
})
);
}
return materialCache.get(color);
}
function addBox(parent, size, position, color, options = {}) {
const material =
options.material ||
(color && color.isMaterial ? color : standardMaterial(color));
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0],
options.rotation[1],
options.rotation[2]
);
}
mesh.castShadow = options.cast ?? true;
mesh.receiveShadow = options.receive ?? true;
parent.add(mesh);
return mesh;
}
function makeLabel(parent, text, width, height, position, foreground = "#eaf5ff") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = foreground;
context.font = "900 78px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const label = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
label.position.set(position[0], position[1], position[2]);
parent.add(label);
return label;
}
function makeGroup(position = [0, 0, 0], parent = scene) {
const group = new THREE.Group();
group.position.set(position[0], position[1], position[2]);
parent.add(group);
return group;
}
// -------------------------------------------------------------------------
// Garage shell
// -------------------------------------------------------------------------
addBox(scene, [17.8, 0.26, 13], [0, -0.15, 0.65], 0x30383d);
addBox(scene, [17.8, 6.2, 0.3], [0, 3.05, -5.55], 0x58636a);
addBox(scene, [0.3, 6.2, 13], [-8.75, 3.05, 0.65], 0x4c575d);
// Floor grid.
for (let x = -8; x <= 8; x += 1) {
addBox(scene, [0.025, 0.012, 12.6], [x, 0.005, 0.65], 0x3a4449, {
cast: false
});
}
for (let z = -5; z <= 7; z += 1) {
addBox(scene, [17.3, 0.012, 0.025], [0, 0.006, z], 0x3a4449, {
cast: false
});
}
// Wall trim and columns.
addBox(scene, [17.5, 0.22, 0.16], [0, 0.15, -5.34], 0x293238);
addBox(scene, [0.16, 0.22, 12.7], [-8.54, 0.15, 0.65], 0x293238);
for (let x = -7; x <= 7; x += 3.5) {
addBox(scene, [0.22, 6, 0.18], [x, 3, -5.34], 0x424c52);
}
// Garage door on the left wall.
addBox(scene, [0.16, 4.9, 6.7], [-8.52, 2.55, 1.45], 0x6c777d);
addBox(scene, [0.1, 0.16, 6.85], [-8.39, 4.98, 1.45], 0x30383d);
addBox(scene, [0.1, 0.16, 6.85], [-8.39, 0.12, 1.45], 0x30383d);
for (let y = 0.7; y <= 4.5; y += 0.62) {
addBox(scene, [0.06, 0.065, 6.45], [-8.41, y, 1.45], 0x4e595f, {
cast: false
});
}
for (let z = -1.3; z <= 4.2; z += 1.1) {
addBox(scene, [0.055, 4.45, 0.055], [-8.4, 2.55, z], 0x536067, {
cast: false
});
}
// -------------------------------------------------------------------------
// Workbench and pegboard
// -------------------------------------------------------------------------
const bench = makeGroup([-5.0, 0, -4.45]);
addBox(bench, [4.6, 0.2, 1.45], [0, 1.76, 0], 0x9a7048);
addBox(bench, [4.25, 0.12, 1.22], [0, 0.48, 0], 0x5e4a37);
for (const x of [-1.9, 1.9]) {
for (const z of [-0.48, 0.48]) {
addBox(bench, [0.18, 1.65, 0.18], [x, 0.83, z], 0x4d565b);
}
}
addBox(bench, [1.65, 1.05, 1.12], [-0.95, 1.12, 0], 0xbb4938);
for (let i = 0; i < 3; i++) {
addBox(bench, [1.45, 0.23, 0.04], [-0.95, 0.83 + i * 0.29, 0.58], 0x30383d);
addBox(bench, [0.72, 0.055, 0.08], [-0.95, 0.83 + i * 0.29, 0.63], 0xb8c2c7);
}
// Bench vice.
addBox(bench, [0.65, 0.32, 0.65], [1.35, 1.98, 0.08], 0x3f6d83);
addBox(bench, [0.72, 0.16, 0.25], [1.35, 2.18, 0.08], 0x273238);
addBox(bench, [0.12, 0.12, 0.9], [1.95, 1.96, 0.08], 0x8b969c);
// Pegboard.
const pegboard = makeGroup([-5.0, 0, -5.3]);
addBox(pegboard, [4.85, 2.2, 0.12], [0, 3.23, 0], 0x9b774d);
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 13; col++) {
addBox(
pegboard,
[0.045, 0.045, 0.025],
[-2.08 + col * 0.35, 2.42 + row * 0.31, 0.075],
0x554330,
{ cast: false }
);
}
}
// Hanging hammer.
const hammer = makeGroup([-6.35, 3.2, -5.16]);
addBox(hammer, [0.14, 0.85, 0.12], [0, 0, 0], 0xa87542);
addBox(hammer, [0.68, 0.2, 0.18], [0, 0.45, 0], 0x77858b);
// Hanging wrench.
const wrench = makeGroup([-5.35, 3.25, -5.14]);
addBox(wrench, [0.16, 1.1, 0.1], [0, 0, 0], 0xaeb9bd);
addBox(wrench, [0.43, 0.16, 0.1], [0, 0.57, 0], 0xaeb9bd);
addBox(wrench, [0.15, 0.32, 0.1], [-0.17, 0.7, 0], 0xaeb9bd);
addBox(wrench, [0.15, 0.32, 0.1], [0.17, 0.7, 0], 0xaeb9bd);
addBox(wrench, [0.29, 0.15, 0.1], [0, -0.58, 0], 0xaeb9bd);
// Hanging pliers.
const pliers = makeGroup([-4.45, 3.27, -5.14]);
addBox(pliers, [0.13, 0.75, 0.1], [-0.13, -0.18, 0], 0xc84b3f, {
rotation: [0, 0, -0.14]
});
addBox(pliers, [0.13, 0.75, 0.1], [0.13, -0.18, 0], 0xc84b3f, {
rotation: [0, 0, 0.14]
});
addBox(pliers, [0.26, 0.38, 0.12], [0, 0.35, 0], 0x9ca9ad);
// Hanging hand saw.
const saw = makeGroup([-3.45, 3.3, -5.14]);
addBox(saw, [1.1, 0.3, 0.06], [0.15, 0.12, 0], 0xb4bec2);
addBox(saw, [0.48, 0.58, 0.13], [-0.58, 0.1, 0], 0xe48737);
// Cordless drill on the bench.
const drill = makeGroup([-0.2, 1.87, 0.12]);
addBox(drill, [0.68, 0.3, 0.32], [0, 0.13, 0], 0x31789d);
addBox(drill, [0.26, 0.58, 0.25], [-0.12, -0.22, 0], 0x24576f, {
rotation: [0, 0, -0.18]
});
addBox(drill, [0.22, 0.18, 0.22], [0.42, 0.13, 0], 0x8f9ca1);
addBox(drill, [0.12, 0.12, 0.12], [0.58, 0.13, 0], 0x29353a);
addBox(drill, [0.48, 0.13, 0.38], [-0.1, 0.32, 0], 0x9aa5aa);
// -------------------------------------------------------------------------
// Tool chest, materials, and small garage details
// -------------------------------------------------------------------------
const chest = makeGroup([6.45, 0, -4.15]);
addBox(chest, [1.8, 2.15, 1.25], [0, 1.22, 0], 0xbd4036);
addBox(chest, [1.95, 0.15, 1.4], [0, 2.35, 0], 0x30393f);
for (let i = 0; i < 5; i++) {
addBox(chest, [1.58, 0.29, 0.045], [0, 0.48 + i * 0.37, 0.65], 0x30383d);
addBox(chest, [0.85, 0.055, 0.08], [0, 0.48 + i * 0.37, 0.71], 0xb8c1c5);
}
for (const x of [-0.65, 0.65]) {
addBox(chest, [0.25, 0.28, 0.42], [x, 0.2, 0.45], 0x20282d);
}
// Stack of timber.
for (let i = 0; i < 5; i++) {
addBox(
scene,
[2.3, 0.16, 0.34],
[6.7, 0.1 + i * 0.18, -1.8 + (i % 2) * 0.08],
i % 2 ? 0xa47c4e : 0xb58b58
);
}
// Storage bins.
addBox(scene, [1.05, 0.7, 0.9], [-7.15, 0.35, -2.65], 0x397789);
addBox(scene, [0.9, 0.55, 0.8], [-7.15, 0.98, -2.65], 0xd69a35);
addBox(scene, [0.8, 0.48, 0.75], [7.15, 0.25, 1.1], 0x8b4c3d);
// Safety cone.
const cone = makeGroup([5.4, 0, 4.2]);
addBox(cone, [0.8, 0.12, 0.8], [0, 0.06, 0], 0x252b2f);
for (let i = 0; i < 4; i++) {
addBox(
cone,
[0.65 - i * 0.13, 0.16, 0.65 - i * 0.13],
[0, 0.2 + i * 0.2, 0],
i === 2 ? 0xf2eee4 : 0xe66c31
);
}
// -------------------------------------------------------------------------
// Power distribution board
// -------------------------------------------------------------------------
const board = makeGroup([3.15, 0, -5.25]);
addBox(board, [2.05, 2.35, 0.32], [0, 2.55, 0], 0x303a40);
addBox(board, [1.78, 2.06, 0.08], [0, 2.55, 0.2], 0x4a565d);
addBox(board, [0.08, 0.48, 0.12], [-0.92, 2.55, 0.23], 0x89969b);
addBox(board, [0.08, 0.48, 0.12], [0.92, 2.55, 0.23], 0x89969b);
makeLabel(board, "PDB / 230V", 1.45, 0.34, [0, 3.38, 0.255], "#f7dc78");
const boardLEDMaterial = new THREE.MeshStandardMaterial({
color: 0x73f5a0,
emissive: 0x44ff77,
emissiveIntensity: 3,
roughness: 0.35
});
addBox(board, [0.19, 0.19, 0.08], [-0.58, 2.95, 0.29], boardLEDMaterial);
addBox(board, [0.62, 0.8, 0.1], [0.48, 2.63, 0.26], 0x232d32);
addBox(board, [0.17, 0.17, 0.12], [0.22, 2.55, 0.35], 0x11181c);
addBox(board, [0.17, 0.17, 0.12], [0.72, 2.55, 0.35], 0x11181c);
const switchBase = addBox(board, [0.55, 0.72, 0.12], [-0.45, 2.03, 0.29], 0x20292e);
const switchLever = addBox(
board,
[0.16, 0.45, 0.16],
[-0.45, 2.08, 0.39],
0xe85b49
);
// Board outlet used by the reel's supply cable.
addBox(board, [0.4, 0.42, 0.15], [-0.15, 1.15, 0.26], 0x1d252a);
addBox(board, [0.18, 0.18, 0.08], [-0.15, 1.15, 0.36], 0x090e11);
// Wall conduit.
addBox(scene, [0.12, 2.1, 0.12], [3.15, 5.15, -5.34], 0x4e5a61);
addBox(scene, [0.12, 0.12, 0.6], [3.15, 6.18, -5.05], 0x4e5a61);
// -------------------------------------------------------------------------
// Extension reel
// -------------------------------------------------------------------------
const reel = makeGroup([0, 0, -0.8]);
// Frame and feet.
addBox(reel, [0.24, 1.45, 0.24], [-0.78, 0.82, 0], 0xd66d2d);
addBox(reel, [0.24, 1.45, 0.24], [0.78, 0.82, 0], 0xd66d2d);
addBox(reel, [1.95, 0.18, 1.85], [0, 0.1, 0], 0x303a40);
addBox(reel, [2.25, 0.16, 0.42], [0, 0.13, -0.58], 0xd66d2d);
addBox(reel, [2.25, 0.16, 0.42], [0, 0.13, 0.58], 0xd66d2d);
// Spool.
addBox(reel, [0.18, 1.75, 1.75], [-0.69, 1.28, 0], 0xe27b32);
addBox(reel, [0.18, 1.75, 1.75], [0.69, 1.28, 0], 0xe27b32);
addBox(reel, [1.08, 1.25, 1.27], [0, 1.28, 0], 0x343e44);
// Visible wound cable bands.
for (let x = -0.4; x <= 0.41; x += 0.16) {
addBox(reel, [0.075, 1.43, 1.39], [x, 1.28, 0], 0x171f25);
}
// Hub and three branch sockets.
addBox(reel, [1.55, 0.75, 0.3], [0, 0.63, 0.63], 0x252e33);
addBox(reel, [1.3, 0.13, 0.5], [0, 0.25, 0.56], 0xd66d2d);
makeLabel(reel, "EXTENSION REEL", 1.35, 0.28, [0, 0.36, 0.795], "#ffd166");
const socketLEDMaterials = [];
function makeSocketLED(x, y, z, color) {
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 2,
roughness: 0.35
});
socketLEDMaterials.push(material);
return addBox(reel, [0.13, 0.13, 0.08], [x, y, z], material);
}
makeSocketLED(-0.55, 0.78, 0.82, 0x73f5a0);
makeSocketLED(0.55, 0.78, 0.82, 0x73f5a0);
makeSocketLED(0, 0.49, 0.82, 0x73f5a0);
addBox(reel, [0.2, 0.2, 0.12], [-0.55, 0.61, 0.82], 0x11181c);
addBox(reel, [0.2, 0.2, 0.12], [0.55, 0.61, 0.82], 0x11181c);
addBox(reel, [0.2, 0.2, 0.12], [0, 0.33, 0.82], 0x11181c);
// Crank on the right side.
addBox(reel, [0.2, 0.2, 0.55], [0.9, 1.48, 0], 0x8e999e);
addBox(reel, [0.18, 0.58, 0.18], [0.9, 1.74, 0.25], 0x8e999e);
addBox(reel, [0.18, 0.18, 0.55], [0.9, 2.0, 0.48], 0x252d32);
// -------------------------------------------------------------------------
// Portable work lights
// -------------------------------------------------------------------------
function makePortableLamp(id, x, z, accent, angle) {
const group = makeGroup([x, 0, z]);
addBox(group, [0.7, 0.14, 0.58], [0, 0.13, 0], 0x303a40);
addBox(group, [0.13, 0.92, 0.13], [-0.22, 0.52, -0.16], 0x515d63, {
rotation: [0.25, 0, 0.2]
});
addBox(group, [0.13, 0.92, 0.13], [0.22, 0.52, -0.16], 0x515d63, {
rotation: [0.25, 0, -0.2]
});
addBox(group, [0.13, 0.9, 0.13], [0, 0.52, 0.22], 0x515d63, {
rotation: [-0.25, 0, 0]
});
addBox(group, [0.14, 1.45, 0.14], [0, 1.03, 0], 0x667278);
addBox(group, [0.4, 0.12, 0.3], [0, 1.56, 0], accent);
const head = makeGroup([0, 1.85, 0], group);
head.rotation.y = angle;
addBox(head, [0.95, 0.67, 0.34], [0, 0, 0], 0x303a40);
addBox(head, [0.84, 0.56, 0.08], [0, 0, 0.19], accent);
addBox(head, [0.12, 0.36, 0.48], [-0.54, 0, 0], 0x515c62);
addBox(head, [0.12, 0.36, 0.48], [0.54, 0, 0], 0x515c62);
addBox(head, [0.5, 0.12, 0.15], [0, 0.43, 0], 0x252d32);
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0xfff0bd,
emissive: 0xffd77d,
emissiveIntensity: 4,
roughness: 0.28
});
addBox(head, [0.72, 0.45, 0.07], [0, 0, 0.25], panelMaterial);
// Plug at the lamp base.
addBox(group, [0.2, 0.18, 0.25], [0.35, 0.37, 0], 0x1a2227);
addBox(group, [0.11, 0.11, 0.28], [0.35, 0.37, 0], accent);
const point = new THREE.PointLight(0xffd88b, 0, 7, 2);
point.position.set(x, 1.85, z);
scene.add(point);
const target = new THREE.Object3D();
target.position.set(
x + Math.sin(angle) * 1.7,
0.025,
z + Math.cos(angle) * 1.7
);
scene.add(target);
const spot = new THREE.SpotLight(0xffd58a, 0, 9, 0.78, 0.18, 1.5);
spot.position.set(
x + Math.sin(angle) * 0.3,
1.85,
z + Math.cos(angle) * 0.3
);
spot.target = target;
scene.add(spot);
const poolMaterial = new THREE.MeshBasicMaterial({
color: 0xffd68a,
transparent: true,
opacity: 0.11,
depthWrite: false
});
const pool = addBox(
scene,
[2.5, 0.012, 1.9],
[target.position.x, 0.018, target.position.z],
poolMaterial,
{ cast: false, receive: false }
);
pool.rotation.y = angle;
pool.visible = false;
makeLabel(group, `LIGHT ${id}`, 0.78, 0.2, [0, 0.79, 0.302], "#e8f3fa");
return {
id,
group,
panelMaterial,
point,
spot,
pool,
connected: true,
setOn(on) {
panelMaterial.color.set(on ? 0xfff0bd : 0x32383a);
panelMaterial.emissiveIntensity = on ? 4.5 : 0.025;
point.intensity = on ? 18 : 0;
spot.intensity = on ? 70 : 0;
pool.visible = on;
}
};
}
const lampA = makePortableLamp("A", -3.55, 1.55, 0xe78732, -0.22);
const lampB = makePortableLamp("B", 4.55, 1.45, 0xe2b937, 0.32);
const lampC = makePortableLamp("C", 1.35, 3.25, 0x37939b, -0.08);
// -------------------------------------------------------------------------
// Voxel cables and detachable plugs
// -------------------------------------------------------------------------
function buildVoxelCable(points, color, alternateColor) {
const root = new THREE.Group();
scene.add(root);
const segments = [];
for (let i = 0; i < points.length - 1; i++) {
const start = points[i];
const end = points[i + 1];
const direction = end.clone().sub(start);
const length = direction.length();
direction.normalize();
const segmentGroup = new THREE.Group();
root.add(segmentGroup);
segments.push(segmentGroup);
const count = Math.max(1, Math.ceil(length / 0.28));
const step = length / count;
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction
);
for (let j = 0; j < count; j++) {
const voxel = addBox(
segmentGroup,
[step * 0.92, 0.105, 0.105],
[0, 0, 0],
j % 2 ? color : alternateColor,
{ cast: false }
);
voxel.position.copy(start).addScaledVector(direction, (j + 0.5) * step);
voxel.quaternion.copy(quaternion);
}
}
return { root, segments };
}
function buildPlug(position, direction, accent) {
const plug = makeGroup(position);
addBox(plug, [0.28, 0.2, 0.2], [0, 0, 0], 0x192127);
addBox(plug, [0.12, 0.12, 0.14], [-0.17, 0, 0], accent);
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.clone().normalize()
);
plug.quaternion.copy(quaternion);
return plug;
}
const trunkPoints = [
new THREE.Vector3(3.0, 1.15, -4.91),
new THREE.Vector3(3.0, 0.10, -4.91),
new THREE.Vector3(1.05, 0.10, -4.91),
new THREE.Vector3(1.05, 0.10, -1.55),
new THREE.Vector3(0.55, 0.10, -1.55),
new THREE.Vector3(0.55, 0.65, -1.55)
];
const branchPointsA = [
new THREE.Vector3(-0.55, 0.65, 0.12),
new THREE.Vector3(-1.15, 0.65, 0.12),
new THREE.Vector3(-1.15, 0.10, 0.12),
new THREE.Vector3(-1.15, 0.10, 1.55),
new THREE.Vector3(-3.20, 0.10, 1.55),
new THREE.Vector3(-3.20, 0.38, 1.55)
];
const branchPointsB = [
new THREE.Vector3(0.55, 0.65, 0.12),
new THREE.Vector3(1.25, 0.65, 0.12),
new THREE.Vector3(1.25, 0.10, 0.12),
new THREE.Vector3(1.25, 0.10, 1.45),
new THREE.Vector3(4.90, 0.10, 1.45),
new THREE.Vector3(4.90, 0.38, 1.45)
];
const branchPointsC = [
new THREE.Vector3(0, 0.45, 0.12),
new THREE.Vector3(0, 0.45, 0.55),
new THREE.Vector3(0, 0.10, 0.55),
new THREE.Vector3(0, 0.10, 3.25),
new THREE.Vector3(1.70, 0.10, 3.25),
new THREE.Vector3(1.70, 0.38, 3.25)
];
const trunkCable = buildVoxelCable(trunkPoints, 0x222c32, 0x151d22);
const cableA = buildVoxelCable(branchPointsA, 0x222c32, 0x151d22);
const cableB = buildVoxelCable(branchPointsB, 0x222c32, 0x151d22);
const cableC = buildVoxelCable(branchPointsC, 0x222c32, 0x151d22);
const trunkPlug = buildPlug(
trunkPoints[0],
trunkPoints[1].clone().sub(trunkPoints[0]),
0xe9b63f
);
const plugA = buildPlug(
branchPointsA[0],
branchPointsA[1].clone().sub(branchPointsA[0]),
0xe78732
);
const plugB = buildPlug(
branchPointsB[0],
branchPointsB[1].clone().sub(branchPointsB[0]),
0xe2b937
);
const plugC = buildPlug(
branchPointsC[0],
branchPointsC[1].clone().sub(branchPointsC[0]),
0x37939b
);
// -------------------------------------------------------------------------
// Low-profile cable covers with open center grooves
// -------------------------------------------------------------------------
function makeCableCover(centerX, centerZ, length, axis) {
const group = makeGroup([centerX, 0, centerZ]);
const alongX = axis === "x";
const baseSize = alongX ? [length, 0.045, 0.46] : [0.46, 0.045, length];
addBox(group, baseSize, [0, 0.028, 0], 0x20272c, { cast: false });
const railSize = alongX ? [length, 0.12, 0.16] : [0.16, 0.12, length];
for (const side of [-1, 1]) {
const position = alongX ? [0, 0.1, side * 0.15] : [side * 0.15, 0.1, 0];
addBox(group, railSize, position, 0xe4a82e, { cast: false });
const stripeCount = Math.floor(length / 0.36);
for (let i = 0; i < stripeCount; i++) {
const offset = -length / 2 + 0.18 + i * 0.36;
const stripePosition = alongX
? [offset, 0.168, side * 0.15]
: [side * 0.15, 0.168, offset];
const stripeSize = alongX ? [0.14, 0.025, 0.17] : [0.17, 0.025, 0.14];
addBox(group, stripeSize, stripePosition, 0x252b2f, { cast: false });
}
}
}
makeCableCover(-2.3, 1.55, 2.15, "x");
makeCableCover(3.05, 1.45, 3.0, "x");
makeCableCover(0.85, 3.25, 1.15, "x");
makeCableCover(1.05, -3.2, 3.45, "z");
// -------------------------------------------------------------------------
// Energy pulses that make the complete cable route visible
// -------------------------------------------------------------------------
const pulseMaterial = new THREE.MeshBasicMaterial({ color: 0xfff19a });
function createPulses(points, count, speed, offset) {
const pulses = [];
for (let i = 0; i < count; i++) {
const mesh = new THREE.Mesh(unitBox, pulseMaterial);
mesh.scale.set(0.16, 0.16, 0.16);
scene.add(mesh);
pulses.push({ mesh, phase: offset + i / count });
}
return { pulses, points, speed };
}
function pointOnPath(points, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let remaining = ((t % 1) + 1) % 1 * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i]) {
const direction = points[i + 1].clone().sub(points[i]).normalize();
return points[i].clone().addScaledVector(direction, remaining);
}
remaining -= lengths[i];
}
return points[points.length - 1].clone();
}
const trunkPulses = createPulses(trunkPoints, 3, 0.13, 0);
const pulsesA = createPulses(branchPointsA, 2, 0.18, 0.1);
const pulsesB = createPulses(branchPointsB, 2, 0.18, 0.42);
const pulsesC = createPulses(branchPointsC, 2, 0.18, 0.72);
// -------------------------------------------------------------------------
// Logical connections and UI
// -------------------------------------------------------------------------
let boardOn = true;
const branches = [
{
id: "A",
lamp: lampA,
points: branchPointsA,
cable: cableA,
plug: plugA,
connected: true
},
{
id: "B",
lamp: lampB,
points: branchPointsB,
cable: cableB,
plug: plugB,
connected: true
},
{
id: "C",
lamp: lampC,
points: branchPointsC,
cable: cableC,
plug: plugC,
connected: true
}
];
const powerButton = document.querySelector("#powerButton");
const boardStatus = document.querySelector("#boardStatus");
const boardStatusText = document.querySelector("#boardStatusText");
const routeElements = {
A: document.querySelector("#routeA"),
B: document.querySelector("#routeB"),
C: document.querySelector("#routeC")
};
const lampButtons = {
A: document.querySelector("#lampA"),
B: document.querySelector("#lampB"),
C: document.querySelector("#lampC")
};
function updatePowerState() {
branches.forEach((branch, index) => {
const on = boardOn && branch.connected;
branch.lamp.setOn(on);
const material = socketLEDMaterials[index];
material.color.set(on ? 0x73f5a0 : 0x34413a);
material.emissive.set(on ? 0x44ff77 : 0x173c22);
material.emissiveIntensity = on ? 3 : 0.08;
const route = routeElements[branch.id];
route.classList.toggle("active", on);
route.querySelector("span:last-child").textContent = branch.connected
? (boardOn ? "CONNECTED" : "NO POWER")
: "OPEN AT REEL";
const button = lampButtons[branch.id];
button.classList.toggle("connected", branch.connected);
button.classList.toggle("disconnected", !branch.connected);
button.innerHTML = `LAMP ${branch.id}<br>${
branch.connected ? "CONNECTED" : "DISCONNECTED"
}`;
});
boardLEDMaterial.color.set(boardOn ? 0x73f5a0 : 0x5b2929);
boardLEDMaterial.emissive.set(boardOn ? 0x44ff77 : 0x7a1616);
boardLEDMaterial.emissiveIntensity = boardOn ? 3 : 0.05;
switchLever.rotation.z = boardOn ? 0 : 0.72;
switchLever.position.x = boardOn ? -0.45 : -0.51;
boardStatus.classList.toggle("offline", !boardOn);
boardStatusText.textContent = boardOn ? "ONLINE" : "OFFLINE";
powerButton.textContent = `POWER BOARD: ${boardOn ? "ON" : "OFF"}`;
powerButton.classList.toggle("off", !boardOn);
}
function setBranchConnection(branch, connected) {
branch.connected = connected;
branch.cable.segments[0].visible = connected;
// When open, the plug remains attached to the lamp cable but visibly
// separated from the reel socket.
branch.plug.position.copy(
connected ? branch.points[0] : branch.points[1]
);
updatePowerState();
}
function toggleBoard() {
boardOn = !boardOn;
updatePowerState();
}
powerButton.addEventListener("click", toggleBoard);
for (const branch of branches) {
lampButtons[branch.id].addEventListener("click", () => {
setBranchConnection(branch, !branch.connected);
});
}
updatePowerState();
// -------------------------------------------------------------------------
// Direct object picking
// -------------------------------------------------------------------------
const pickables = [];
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function registerPick(group, action) {
group.traverse((object) => {
if (object.isMesh) {
object.userData.action = action;
pickables.push(object);
}
});
}
registerPick(board, "power");
registerPick(lampA.group, "lamp:A");
registerPick(lampB.group, "lamp:B");
registerPick(lampC.group, "lamp:C");
registerPick(plugA, "lamp:A");
registerPick(plugB, "lamp:B");
registerPick(plugC, "lamp:C");
function pickAction(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(pickables, false);
return hits.length ? hits[0].object.userData.action : null;
}
function activate(action) {
if (!action) return;
if (action === "power") {
toggleBoard();
return;
}
if (action.startsWith("lamp:")) {
const id = action.split(":")[1];
const branch = branches.find((item) => item.id === id);
if (branch) setBranchConnection(branch, !branch.connected);
}
}
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
let pointerDown = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
orbit.yaw = THREE.MathUtils.clamp(orbit.yaw + dx * 0.006, -1.18, 1.28);
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * 0.005, 0.32, 1.08);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) activate(pickAction(event));
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * (event.deltaY > 0 ? 0.91 : 1.1),
0.65,
1.75
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animatePulses(pulseSet, enabled, time) {
for (const pulse of pulseSet.pulses) {
pulse.mesh.visible = enabled;
if (!enabled) continue;
const t = (time * pulseSet.speed + pulse.phase) % 1;
pulse.mesh.position.copy(pointOnPath(pulseSet.points, t));
}
}
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
animatePulses(trunkPulses, boardOn, time);
animatePulses(pulsesA, boardOn && branches[0].connected, time);
animatePulses(pulsesB, boardOn && branches[1].connected, time);
animatePulses(pulsesC, boardOn && branches[2].connected, time);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```