Prompt specification
Build or customize the Three.js 3D scene "Model-house lighting topology exhibit" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Model-house lighting topology exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/model-house-lighting-topology-exhibit-x1667
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing resistors connected in series and parallel. Compose three miniature rooms with virtual lamps and exposed schematic connections; compare independent parallel branches with a series chain while avoiding real household-wiring instructions. Voxel style.
Working Three.js Starter (model-house-lighting-topology-exhibit-x1667):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Circuit Rooms</title>
<style>
:root {
color-scheme: dark;
--bg: #080d19;
--panel: rgba(15, 23, 42, 0.82);
--panel-border: rgba(255, 255, 255, 0.12);
--text: #f4f7ff;
--muted: #a8b4cc;
--cyan: #63ddff;
--amber: #ffc45b;
--violet: #b99cff;
--green: #72efb1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 18%, #1a2844 0%, #0c1324 40%, #070b14 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
.hero {
position: absolute;
top: 28px;
left: 30px;
z-index: 5;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 3px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(99, 221, 255, 0.7);
}
h1 {
margin: 0;
max-width: 360px;
font-size: clamp(31px, 3.6vw, 54px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 800;
}
.hero p {
max-width: 350px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 28px;
right: 30px;
z-index: 6;
width: 284px;
padding: 16px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(16px);
}
.control-title {
margin-bottom: 12px;
color: #dce6fb;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 11px;
padding: 10px 11px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: 650 12px/1.2 inherit;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.22);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button.active {
border-color: rgba(99, 221, 255, 0.48);
background: rgba(99, 221, 255, 0.13);
color: #dff8ff;
}
.focus-row {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 9px;
}
.focus-row button {
padding: 9px 5px;
font-size: 11px;
}
.legend {
display: grid;
gap: 7px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 11px;
}
.legend-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: 0 0 10px currentColor;
}
.legend-dot.amber {
color: var(--amber);
background: var(--amber);
}
.legend-dot.cyan {
color: var(--cyan);
background: var(--cyan);
}
.legend-dot.green {
color: var(--green);
background: var(--green);
}
.safety-note {
position: absolute;
left: 50%;
bottom: 22px;
z-index: 5;
width: min(920px, calc(100vw - 40px));
transform: translateX(-50%);
padding: 12px 16px;
border: 1px solid rgba(114, 239, 177, 0.2);
border-radius: 13px;
background: rgba(8, 14, 27, 0.78);
color: #bdc9dd;
text-align: center;
font-size: 11px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(12px);
}
.safety-note strong {
color: var(--green);
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.room-label,
.module-label {
position: absolute;
transform: translate(-50%, -100%);
will-change: left, top;
white-space: nowrap;
}
.room-label {
min-width: 150px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-top: 3px solid var(--accent);
border-radius: 10px;
background: rgba(8, 14, 27, 0.78);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(9px);
text-align: center;
}
.room-label .number {
display: block;
margin-bottom: 2px;
color: var(--accent);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
}
.room-label strong {
display: block;
color: #f7f9ff;
font-size: 12px;
letter-spacing: 0.02em;
}
.room-label small {
display: block;
margin-top: 3px;
color: #8f9db5;
font-size: 9px;
}
.module-label {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 6px;
background: rgba(9, 15, 28, 0.72);
color: #dfe8f9;
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint {
position: absolute;
right: 30px;
bottom: 25px;
z-index: 4;
color: rgba(213, 223, 241, 0.52);
font: 600 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
@media (max-width: 820px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 260px;
font-size: 32px;
}
.hero p {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 74px;
width: 224px;
padding: 12px;
}
.legend {
display: none;
}
.room-label {
min-width: 108px;
padding: 6px 8px;
}
.room-label small {
display: none;
}
.safety-note {
bottom: 12px;
width: calc(100vw - 24px);
font-size: 9px;
}
.hint {
display: none;
}
}
@media (max-width: 520px) {
.controls {
right: 12px;
bottom: 78px;
width: 196px;
}
.control-title {
margin-bottom: 8px;
}
.button-row {
gap: 6px;
}
button {
padding: 9px 7px;
font-size: 10px;
}
.focus-row {
gap: 4px;
}
.focus-row button {
padding: 8px 3px;
font-size: 9px;
}
.module-label {
font-size: 7px;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive three-dimensional voxel circuit rooms"></canvas>
<header class="hero">
<div class="eyebrow">Topology playground</div>
<h1>Three rooms.<br>Two kinds of paths.</h1>
<p>
Follow the moving current markers through a single series chain,
independent parallel branches, and a direct visual comparison.
</p>
</header>
<aside class="controls" aria-label="Scene controls">
<div class="control-title">Observation controls</div>
<div class="button-row">
<button id="powerButton" class="active" aria-pressed="true">
Current: ON
</button>
<button id="orbitButton" class="active" aria-pressed="true">
Auto orbit: ON
</button>
</div>
<div class="focus-row" aria-label="Camera focus">
<button data-focus="all">All</button>
<button data-focus="-6.7">Series</button>
<button data-focus="0">Parallel</button>
<button data-focus="6.7">Compare</button>
</div>
<div class="legend">
<div class="legend-item">
<span class="legend-dot amber"></span>
Series route: one shared path
</div>
<div class="legend-item">
<span class="legend-dot cyan"></span>
Parallel routes: independent branches
</div>
<div class="legend-item">
<span class="legend-dot green"></span>
Moving cubes represent conceptual current
</div>
</div>
</aside>
<div id="labels" aria-hidden="true"></div>
<div class="hint">
Drag to orbit · Wheel/pinch to zoom<br />
Double-click to reset
</div>
<footer class="safety-note">
<strong>Abstract teaching model only.</strong>
All sources, lamps, and connections are virtual. This is not a household-wiring
guide and must not be used for real electrical installations or mains voltage.
</footer>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const powerButton = document.querySelector("#powerButton");
const orbitButton = document.querySelector("#orbitButton");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x080d19, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x080d19, 0.017);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const COLORS = {
amber: 0xffc45b,
cyan: 0x63ddff,
violet: 0xb99cff,
green: 0x72efb1,
white: 0xf4f7ff,
dark: 0x121a2c,
darker: 0x090f1c
};
const materialCache = new Map();
function standardMaterial(color, roughness = 0.76, metalness = 0.05) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
function makeBox(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
options = {}
) {
const material = options.material || standardMaterial(color);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.rotationY) {
mesh.rotation.y = options.rotationY;
}
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, color = "#dfe9ff", scale = 1) {
const textCanvas = document.createElement("canvas");
textCanvas.width = 384;
textCanvas.height = 96;
const context = textCanvas.getContext("2d");
context.clearRect(0, 0, textCanvas.width, textCanvas.height);
context.fillStyle = "rgba(8, 14, 27, 0.74)";
context.fillRect(8, 12, 368, 72);
context.strokeStyle = "rgba(255, 255, 255, 0.14)";
context.lineWidth = 2;
context.strokeRect(9, 13, 366, 70);
context.fillStyle = color;
context.font = "700 30px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 192, 49);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.5 * scale, 0.375 * scale, 1);
return sprite;
}
function addDOMLabel(text, detail, accent, position, type = "room") {
const element = document.createElement("div");
element.className = type === "room" ? "room-label" : "module-label";
element.style.setProperty("--accent", accent);
if (type === "room") {
element.innerHTML = `
<span class="number">ROOM ${text.number}</span>
<strong>${text.title}</strong>
<small>${detail}</small>
`;
} else {
element.textContent = text.title;
}
labelsLayer.appendChild(element);
return { element, position };
}
function createRoomShell(centerX, accentHex, index) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
makeBox(6.05, 0.34, 5.05, COLORS.dark, 0, -0.27, 0, group);
makeBox(5.85, 0.08, 4.85, COLORS.darker, 0, -0.055, 0, group);
const tileColors = [0x18243a, 0x1b2942];
for (let x = 0; x < 8; x++) {
for (let z = 0; z < 6; z++) {
const tile = makeBox(
0.69,
0.075,
0.69,
tileColors[(x + z) % 2],
(x - 3.5) * 0.72,
0.015,
(z - 2.5) * 0.72,
group,
{ castShadow: false }
);
tile.receiveShadow = true;
}
}
makeBox(5.9, 2.55, 0.18, 0x111b2e, 0, 1.23, -2.37, group);
makeBox(0.18, 1.28, 4.75, 0x111a2b, -2.88, 0.61, 0, group);
makeBox(5.95, 0.11, 0.23, accentHex, 0, 0.12, -2.35, group);
makeBox(0.23, 0.11, 4.8, accentHex, -2.85, 0.12, 0, group);
makeBox(0.15, 2.65, 0.25, 0x273550, -2.86, 1.28, -2.27, group);
makeBox(0.26, 2.65, 0.15, 0x273550, 2.86, 1.28, -2.27, group);
// Small voxel wall details.
for (let i = 0; i < 3; i++) {
makeBox(
0.42,
0.42,
0.16,
i === index ? accentHex : 0x273550,
-1.9 + i * 0.63,
2.0,
-2.23,
group
);
}
makeBox(1.45, 0.12, 0.48, 0x26344f, 1.55, 0.37, -2.05, group);
makeBox(0.38, 0.42, 0.32, accentHex, 1.22, 0.57, -2.05, group);
makeBox(0.38, 0.42, 0.32, 0x3c4d6c, 1.70, 0.57, -2.05, group);
const outlinePoints = [
new THREE.Vector3(-2.93, 0.075, -2.39),
new THREE.Vector3(2.93, 0.075, -2.39),
new THREE.Vector3(2.93, 0.075, 2.39),
new THREE.Vector3(-2.93, 0.075, 2.39)
];
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
new THREE.LineBasicMaterial({
color: accentHex,
transparent: true,
opacity: 0.35
})
);
group.add(outline);
return group;
}
function addWireSegment(parent, a, b, color) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) return;
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.32,
roughness: 0.45,
metalness: 0.12
});
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.075, 0.075),
material
);
segment.position.set(
(a.x + b.x) * 0.5,
(a.y + b.y) * 0.5,
(a.z + b.z) * 0.5
);
segment.rotation.y = -Math.atan2(dz, dx);
segment.castShadow = true;
segment.receiveShadow = true;
parent.add(segment);
}
function addWireRoute(parent, points, color) {
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const changesX = Math.abs(b.x - a.x) > 0.001;
const changesZ = Math.abs(b.z - a.z) > 0.001;
if (changesX && changesZ) {
const elbow = new THREE.Vector3(b.x, a.y, a.z);
addWireSegment(parent, a, elbow, color);
addWireSegment(parent, elbow, b, color);
} else {
addWireSegment(parent, a, b, color);
}
}
}
function addJunction(parent, x, y, z, color) {
makeBox(0.18, 0.18, 0.18, color, x, y, z, parent);
makeBox(0.26, 0.055, 0.26, 0xf4f7ff, x, y + 0.09, z, parent);
}
function createSource(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
makeBox(1.05, 0.72, 0.78, 0x202d46, 0, 0.39, 0, group);
makeBox(0.85, 0.12, 0.62, 0x354763, 0, 0.81, 0, group);
makeBox(0.16, 0.45, 0.12, 0x72efb1, 0, 0.43, 0.42, group);
makeBox(0.5, 0.08, 0.12, 0x26364f, 0, 0.24, 0.42, group);
const positive = new THREE.Vector3(x - 0.25, 0.29, z - 0.5);
const negative = new THREE.Vector3(x + 0.25, 0.29, z + 0.5);
makeBox(0.2, 0.18, 0.2, COLORS.green, positive.x, positive.y, positive.z, parent);
makeBox(0.2, 0.18, 0.2, 0xff7d9b, negative.x, negative.y, negative.z, parent);
const label = makeTextSprite("VIRTUAL DC", "#72efb1", 0.72);
label.position.set(x, 1.18, z);
parent.add(label);
const plus = makeTextSprite("+", "#72efb1", 0.28);
plus.position.set(positive.x, 0.58, positive.z);
parent.add(plus);
const minus = makeTextSprite("−", "#ff91a8", 0.28);
minus.position.set(negative.x, 0.58, negative.z);
parent.add(minus);
return { group, positive, negative };
}
function createLamp(parent, x, z, accentHex, name) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
makeBox(1.02, 0.18, 0.78, 0x27354f, 0, 0.14, 0, group);
makeBox(0.8, 0.11, 0.62, accentHex, 0, 0.285, 0, group);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0xfff4c9,
emissive: 0xffc45b,
emissiveIntensity: 2.5,
roughness: 0.2,
metalness: 0,
transparent: true,
opacity: 0.88
});
const glass = makeBox(
0.58,
0.58,
0.58,
0xffffff,
0,
0.69,
0,
group,
{ material: glassMaterial }
);
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0xffdd83,
emissiveIntensity: 4,
roughness: 0.18
});
makeBox(
0.22,
0.22,
0.22,
0xffffff,
0,
0.69,
0,
group,
{ material: coreMaterial }
);
makeBox(0.74, 0.14, 0.74, 0x32435f, 0, 1.055, 0, group);
makeBox(0.16, 0.16, 0.16, accentHex, 0, 1.18, 0, group);
const glowMaterial = new THREE.MeshBasicMaterial({
color: accentHex,
transparent: true,
opacity: 0.11,
blending: THREE.AdditiveBlending,
depthWrite: false
});
makeBox(
0.95,
0.95,
0.95,
0xffffff,
0,
0.7,
0,
group,
{
material: glowMaterial,
castShadow: false,
receiveShadow: false
}
);
makeBox(0.19, 0.17, 0.19, accentHex, -0.55, 0.29, 0, group);
makeBox(0.19, 0.17, 0.19, accentHex, 0.55, 0.29, 0, group);
const label = makeTextSprite(name, "#f6f9ff", 0.28);
label.position.set(0, 1.46, 0);
group.add(label);
const light = new THREE.PointLight(accentHex, 10, 2.5, 2);
light.position.set(0, 0.72, 0);
group.add(light);
return {
group,
glass,
glassMaterial,
coreMaterial,
glowMaterial,
light
};
}
class FlowPath {
constructor(parent, points, color, particleCount = 8) {
this.parent = parent;
this.points = points.map((point) => point.clone());
this.color = color;
this.phase = 0;
this.particleCount = particleCount;
this.segments = [];
this.totalLength = 0;
for (let i = 0; i < this.points.length - 1; i++) {
const length = this.points[i].distanceTo(this.points[i + 1]);
this.segments.push(length);
this.totalLength += length;
}
const geometry = new THREE.BoxGeometry(0.13, 0.13, 0.13);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 2.2,
roughness: 0.3
});
this.particles = [];
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(geometry, material);
particle.castShadow = false;
parent.add(particle);
this.particles.push(particle);
}
}
sample(normalizedDistance, output) {
let remaining = normalizedDistance * this.totalLength;
for (let i = 0; i < this.segments.length; i++) {
const length = this.segments[i];
if (remaining <= length || i === this.segments.length - 1) {
const t = length > 0 ? Math.min(remaining / length, 1) : 0;
output.lerpVectors(this.points[i], this.points[i + 1], t);
return output;
}
remaining -= length;
}
output.copy(this.points[this.points.length - 1]);
return output;
}
update(delta, powered) {
this.phase = (
this.phase + (delta * 2.45) / Math.max(this.totalLength, 1)
) % 1;
const temp = new THREE.Vector3();
this.particles.forEach((particle, index) => {
particle.visible = powered;
const t = (this.phase + index / this.particles.length) % 1;
this.sample(t, temp);
particle.position.copy(temp);
particle.rotation.x += delta * 4;
particle.rotation.y += delta * 5;
});
}
}
function buildSeriesCircuit(
parent,
{
sourceX,
sourceZ,
lampXs,
lampZ,
accent,
names
}
) {
const source = createSource(parent, sourceX, sourceZ);
const lamps = [];
lampXs.forEach((lampX, index) => {
lamps.push(createLamp(parent, lampX, lampZ, accent, names[index]));
});
const route = [
source.positive,
new THREE.Vector3(lampXs[0] - 0.9, source.positive.y, source.positive.z),
new THREE.Vector3(lampXs[0] - 0.9, 0.29, lampZ)
];
lamps.forEach((lamp, index) => {
const lampX = lampXs[index];
route.push(new THREE.Vector3(lampX - 0.55, 0.29, lampZ));
route.push(new THREE.Vector3(lampX, 0.29, lampZ));
route.push(new THREE.Vector3(lampX + 0.55, 0.29, lampZ));
});
const finalRight = lampXs[lampXs.length - 1] + 0.55;
route.push(
new THREE.Vector3(finalRight + 0.35, 0.29, lampZ),
new THREE.Vector3(finalRight + 0.35, source.negative.y, source.negative.z),
source.negative
);
addWireRoute(parent, route, accent);
const flow = new FlowPath(parent, route, COLORS.green, 12);
return { lamps, flow, route };
}
function buildParallelCircuit(
parent,
{
sourceX,
sourceZ,
lampX,
lampZs,
accent,
names
}
) {
const source = createSource(parent, sourceX, sourceZ);
const lamps = [];
const flows = [];
lampZs.forEach((lampZ, index) => {
lamps.push(createLamp(parent, lampX, lampZ, accent, names[index]));
});
const left = lampX - 0.55;
const right = lampX + 0.55;
const junctionA = new THREE.Vector3(left - 0.3, source.positive.y, source.positive.z);
const junctionB = new THREE.Vector3(2.0, source.negative.y, source.negative.z);
addWireRoute(
parent,
[source.positive, junctionA],
accent
);
addWireRoute(
parent,
[junctionB, source.negative],
accent
);
addJunction(parent, junctionA.x, junctionA.y, junctionA.z, accent);
addJunction(parent, junctionB.x, junctionB.y, junctionB.z, accent);
lampZs.forEach((lampZ, index) => {
const inputLane = left - 0.3 - index * 0.48;
const outputLane = index === 0
? junctionB.x - 0.45
: junctionB.x + 0.3;
const route = [
source.positive,
junctionA,
new THREE.Vector3(inputLane, junctionA.y, junctionA.z),
new THREE.Vector3(inputLane, 0.29, lampZ),
new THREE.Vector3(left, 0.29, lampZ),
new THREE.Vector3(lampX, 0.29, lampZ),
new THREE.Vector3(right, 0.29, lampZ),
new THREE.Vector3(outputLane, 0.29, lampZ),
new THREE.Vector3(outputLane, junctionB.y, junctionB.z),
junctionB,
source.negative
];
addWireRoute(parent, route, accent);
flows.push(new FlowPath(parent, route, COLORS.green, 8));
});
return { lamps, flows, route: null };
}
const roomLabels = [];
const allLamps = [];
const allFlows = [];
// ROOM 1 — Series chain.
const seriesRoom = createRoomShell(-6.7, COLORS.amber, 0);
const seriesCircuit = buildSeriesCircuit(seriesRoom, {
sourceX: -1.72,
sourceZ: 1.18,
lampXs: [-0.25, 1.25],
lampZ: -0.9,
accent: COLORS.amber,
names: ["A", "B"]
});
allLamps.push(...seriesCircuit.lamps);
allFlows.push(seriesCircuit.flow);
roomLabels.push(
addDOMLabel(
{ number: "01", title: "SERIES CHAIN" },
"One route · both lamps in sequence",
"#ffc45b",
new THREE.Vector3(-6.7, 3.25, -1.9)
)
);
// ROOM 2 — Independent parallel branches.
const parallelRoom = createRoomShell(0, COLORS.cyan, 1);
const parallelCircuit = buildParallelCircuit(parallelRoom, {
sourceX: -1.8,
sourceZ: 0,
lampX: 0.45,
lampZs: [-1.35, 1.25],
accent: COLORS.cyan,
names: ["A", "B"]
});
allLamps.push(...parallelCircuit.lamps);
allFlows.push(...parallelCircuit.flows);
roomLabels.push(
addDOMLabel(
{ number: "02", title: "PARALLEL BRANCHES" },
"Split routes · each branch is independent",
"#63ddff",
new THREE.Vector3(0, 3.25, -1.9)
)
);
// ROOM 3 — Side-by-side comparison.
const compareRoom = createRoomShell(6.7, COLORS.violet, 2);
const compareSeries = buildSeriesCircuit(compareRoom, {
sourceX: -2.1,
sourceZ: -1.1,
lampXs: [-0.65, 0.65],
lampZ: -1.15,
accent: COLORS.amber,
names: ["A", "B"]
});
const compareParallel = buildParallelCircuit(compareRoom, {
sourceX: -2.1,
sourceZ: 1.1,
lampX: 0.1,
lampZs: [0.65, 1.65],
accent: COLORS.cyan,
names: ["A", "B"]
});
allLamps.push(...compareSeries.lamps, ...compareParallel.lamps);
allFlows.push(compareSeries.flow, ...compareParallel.flows);
roomLabels.push(
addDOMLabel(
{ number: "03", title: "COMPARE THE PATHS" },
"Same idea, side by side",
"#b99cff",
new THREE.Vector3(6.7, 3.25, -1.9)
)
);
roomLabels.push(
addDOMLabel(
{ title: "Series · one route" },
"",
"#ffc45b",
new THREE.Vector3(6.7, 1.85, -1.45),
"module"
)
);
roomLabels.push(
addDOMLabel(
{ title: "Parallel · split routes" },
"",
"#63ddff",
new THREE.Vector3(6.7, 1.85, 1.48),
"module"
)
);
// Lighting.
scene.add(new THREE.HemisphereLight(0xa9c9ff, 0x182035, 1.65));
const keyLight = new THREE.DirectionalLight(0xfff0d6, 3.1);
keyLight.position.set(5, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x6e8eff, 55, 32, 2);
rimLight.position.set(-9, 6, -6);
scene.add(rimLight);
const frontLight = new THREE.PointLight(0x54d6ff, 38, 26, 2);
frontLight.position.set(8, 4, 8);
scene.add(frontLight);
// Subtle central stage beneath the three rooms.
makeBox(
21.4,
0.2,
6.5,
0x0b1220,
0,
-0.55,
0,
scene,
{ castShadow: false }
);
// Camera and custom controls.
const initialRadius =
window.innerWidth / window.innerHeight < 1 ? 34 : 24;
const target = new THREE.Vector3(0, 0.8, 0);
const targetGoal = target.clone();
let yaw = 0.28;
let pitch = 0.53;
let radius = initialRadius;
let yawGoal = yaw;
let pitchGoal = pitch;
let radiusGoal = radius;
let powered = true;
let autoOrbit = true;
let dragging = false;
const pointers = new Map();
let previousPinchDistance = 0;
function resetCamera() {
targetGoal.set(0, 0.8, 0);
yawGoal = 0.28;
pitchGoal = 0.53;
radiusGoal =
window.innerWidth / window.innerHeight < 1 ? 34 : 24;
}
function focusRoom(x) {
if (x === "all") {
resetCamera();
return;
}
targetGoal.set(Number(x), 0.75, 0);
yawGoal = 0.18;
pitchGoal = 0.49;
radiusGoal = 10.8;
}
document.querySelectorAll("[data-focus]").forEach((button) => {
button.addEventListener("click", () => {
focusRoom(button.dataset.focus);
});
});
powerButton.addEventListener("click", () => {
powered = !powered;
powerButton.textContent = powered ? "Current: ON" : "Current: OFF";
powerButton.classList.toggle("active", powered);
powerButton.setAttribute("aria-pressed", String(powered));
});
orbitButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
orbitButton.textContent = autoOrbit ? "Auto orbit: ON" : "Auto orbit: OFF";
orbitButton.classList.toggle("active", autoOrbit);
orbitButton.setAttribute("aria-pressed", String(autoOrbit));
});
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragging = true;
canvas.classList.add("dragging");
previousPinchDistance = pointerDistance();
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
yawGoal -= deltaX * 0.006;
pitchGoal = THREE.MathUtils.clamp(
pitchGoal + deltaY * 0.004,
0.18,
1.05
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0) {
radiusGoal = THREE.MathUtils.clamp(
radiusGoal * (previousPinchDistance / distance),
6,
42
);
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointerDistance();
if (pointers.size === 0) {
dragging = false;
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radiusGoal = THREE.MathUtils.clamp(
radiusGoal * Math.exp(event.deltaY * 0.001),
6,
42
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
roomLabels.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
});
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (autoOrbit && !dragging && pointers.size === 0) {
yawGoal += delta * 0.075;
}
const damping = 1 - Math.exp(-delta * 7);
target.lerp(targetGoal, damping);
yaw = THREE.MathUtils.lerp(yaw, yawGoal, damping);
pitch = THREE.MathUtils.lerp(pitch, pitchGoal, damping);
radius = THREE.MathUtils.lerp(radius, radiusGoal, damping);
const horizontalRadius = radius * Math.cos(pitch);
camera.position.set(
target.x + Math.sin(yaw) * horizontalRadius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontalRadius
);
camera.lookAt(target);
allFlows.forEach((flow) => flow.update(delta, powered));
allLamps.forEach((lamp) => {
lamp.coreMaterial.emissiveIntensity = powered ? 4 : 0.08;
lamp.glassMaterial.emissiveIntensity = powered ? 2.5 : 0.03;
lamp.glowMaterial.opacity = powered ? 0.11 : 0.015;
lamp.light.intensity = powered ? 10 : 0;
});
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```