Prompt specification
Build or customize the Three.js 3D scene "Electricity distribution concept 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: Electricity distribution concept exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/electricity-distribution-concept-exhibit-x1675
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a scene with a schematic generator, transmission link, and transformer stations with symbolic values; explain the role of voltage transformation without giving real power-grid wiring instructions. Voxel style.
Working Three.js Starter (electricity-distribution-concept-exhibit-x1675):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Voltage Transformation Schematic</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 23, 39, 0.88);
--border: rgba(139, 196, 231, 0.2);
--text: #e8f3fb;
--muted: #91a9bd;
--amber: #f6ba4b;
--teal: #42d8c3;
--blue: #68a9ff;
--violet: #b58aff;
--green: #72df91;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
}
#ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
position: absolute;
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 14px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(470px, calc(100vw - 44px));
padding: 18px 20px;
border-left: 4px solid var(--teal);
}
.eyebrow {
margin-bottom: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(20px, 3vw, 32px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-family: system-ui, sans-serif;
font-size: 13px;
line-height: 1.45;
}
.info-panel {
top: 22px;
right: 22px;
width: 345px;
padding: 17px;
pointer-events: auto;
}
.info-panel h2 {
margin: 0 0 12px;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.stage-list {
display: grid;
gap: 7px;
}
.stage {
display: grid;
grid-template-columns: 12px 1fr auto;
gap: 9px;
align-items: center;
min-height: 29px;
color: var(--muted);
font-size: 10px;
}
.stage strong {
color: var(--text);
font-size: 11px;
}
.stage .value {
color: var(--text);
text-align: right;
white-space: nowrap;
}
.swatch {
width: 8px;
height: 8px;
box-shadow: 0 0 12px currentColor;
}
.divider {
height: 1px;
margin: 15px 0;
background: var(--border);
}
.explanation {
color: #b7c9d8;
font-family: system-ui, sans-serif;
font-size: 12px;
line-height: 1.5;
}
.explanation p {
margin: 0 0 10px;
}
.explanation b { color: var(--text); }
.formula {
display: inline-block;
margin: 1px 0 7px;
padding: 6px 9px;
color: #d8ecff;
background: rgba(104, 169, 255, 0.09);
border: 1px solid rgba(104, 169, 255, 0.2);
font-family: ui-monospace, monospace;
font-size: 12px;
}
.caution {
margin-top: 13px;
padding: 9px 10px;
color: #d8c9a9;
background: rgba(246, 186, 75, 0.08);
border: 1px solid rgba(246, 186, 75, 0.18);
font-family: system-ui, sans-serif;
font-size: 10px;
line-height: 1.45;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
min-width: 130px;
padding: 8px 10px 9px;
transform: translate(-50%, -100%);
background: rgba(7, 17, 31, 0.91);
border: 1px solid rgba(145, 181, 207, 0.25);
border-top: 3px solid var(--label-color);
box-shadow: 0 7px 22px rgba(0, 0, 0, 0.32);
white-space: nowrap;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 16px;
background: var(--label-color);
opacity: 0.7;
}
.label-index {
display: inline-block;
margin-right: 7px;
color: var(--label-color);
font-size: 9px;
font-weight: 800;
}
.label-title {
color: #eef7ff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.label-value {
margin-top: 4px;
color: var(--label-color);
font-size: 10px;
}
.controls {
position: absolute;
left: 50%;
bottom: 20px;
display: flex;
align-items: center;
gap: 14px;
padding: 9px 12px;
transform: translateX(-50%);
background: rgba(7, 17, 31, 0.82);
border: 1px solid var(--border);
color: var(--muted);
font-size: 10px;
white-space: nowrap;
pointer-events: auto;
}
button {
padding: 6px 9px;
color: var(--text);
background: rgba(104, 169, 255, 0.1);
border: 1px solid rgba(104, 169, 255, 0.3);
font: inherit;
font-size: 10px;
cursor: pointer;
}
button:hover {
background: rgba(104, 169, 255, 0.2);
}
.concept-badge {
position: absolute;
left: 22px;
bottom: 20px;
padding: 8px 10px;
color: #f6d38c;
background: rgba(7, 17, 31, 0.78);
border: 1px solid rgba(246, 186, 75, 0.25);
font-size: 9px;
letter-spacing: 0.12em;
}
@media (max-width: 820px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.info-panel {
top: auto;
right: 12px;
bottom: 58px;
width: min(340px, calc(100vw - 24px));
max-height: 36vh;
overflow-y: auto;
padding: 13px;
}
.info-panel .stage-list,
.info-panel .divider:first-of-type {
display: none;
}
.info-panel h2 {
margin-bottom: 8px;
}
.controls {
bottom: 12px;
}
.concept-badge {
display: none;
}
.scene-label {
min-width: 105px;
padding: 6px 7px;
}
.label-title,
.label-value {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="ui">
<header class="panel title-panel">
<div class="eyebrow">Conceptual power-system schematic</div>
<h1>Voltage Transformation</h1>
<p class="subtitle">
A voxel-style illustration of a generator, a high-voltage link,
and two transformer stations. Values and geometry are symbolic.
</p>
</header>
<aside class="panel info-panel">
<h2>Symbolic voltage stages</h2>
<div class="stage-list">
<div class="stage">
<span class="swatch" style="color:var(--amber);background:var(--amber)"></span>
<strong>Generator</strong>
<span class="value">12 kV</span>
</div>
<div class="stage">
<span class="swatch" style="color:var(--teal);background:var(--teal)"></span>
<strong>Transformer A</strong>
<span class="value">12 → 132 kV</span>
</div>
<div class="stage">
<span class="swatch" style="color:var(--blue);background:var(--blue)"></span>
<strong>Transmission link</strong>
<span class="value">132 kV</span>
</div>
<div class="stage">
<span class="swatch" style="color:var(--violet);background:var(--violet)"></span>
<strong>Transformer B</strong>
<span class="value">132 → 33 kV</span>
</div>
<div class="stage">
<span class="swatch" style="color:var(--green);background:var(--green)"></span>
<strong>Utilization side</strong>
<span class="value">33 kV</span>
</div>
</div>
<div class="divider"></div>
<div class="explanation">
<p>
<b>What a transformer does:</b> alternating current in one winding
creates changing magnetic flux in a core, inducing voltage in a
separate winding. Energy is transferred magnetically rather than by
an electrical connection between the windings.
</p>
<p>
Transformer A steps the voltage up for the long link. In an ideal
three-phase representation,
</p>
<div class="formula">P ≈ √3 · V · I · cos(φ)</div>
<p>
comparable transferred power at higher voltage generally means lower
current. Transformer B then reduces the voltage for the utilization
side. Real systems also include losses, regulation, and other factors.
</p>
</div>
<div class="caution">
Conceptual illustration only. This is not a wiring or construction
guide: no conductor routing, phase sequence, grounding, protection,
clearances, interlocks, isolation, or switching procedure is provided.
</div>
</aside>
<div class="controls">
<span>DRAG TO ORBIT · SCROLL / PINCH TO ZOOM</span>
<button id="reset" type="button">RESET VIEW</button>
</div>
<div class="concept-badge">SCHEMATIC VALUES — NOT AN OPERATIONAL PLAN</div>
</div>
<div id="labels"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, camera, and lighting
// ---------------------------------------------------------------------
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;
renderer.domElement.id = "scene";
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 24, 48);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const target = new THREE.Vector3(0, 1.45, 0);
scene.add(new THREE.HemisphereLight(0xaed8ff, 0x10202b, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4baeff, 1.4);
rimLight.position.set(10, 7, -12);
scene.add(rimLight);
const palette = {
navy: 0x10253a,
navy2: 0x173149,
steel: 0x42637a,
steelLight: 0x8fb0c2,
dark: 0x091522,
copper: 0xd88a4a,
amber: 0xf6ba4b,
teal: 0x42d8c3,
blue: 0x68a9ff,
violet: 0xb58aff,
green: 0x72df91,
white: 0xe7f4fb
};
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.08,
flatShading: true,
...options
});
const materials = {
base: standard(palette.navy, { roughness: 0.9 }),
navy: standard(palette.navy2),
dark: standard(palette.dark, { roughness: 0.9 }),
steel: standard(palette.steel, { metalness: 0.35 }),
steelLight: standard(palette.steelLight, { metalness: 0.3 }),
copper: standard(palette.copper, { metalness: 0.55, roughness: 0.42 }),
amber: standard(palette.amber, { emissive: palette.amber, emissiveIntensity: 0.18 }),
teal: standard(palette.teal, { emissive: palette.teal, emissiveIntensity: 0.18 }),
violet: standard(palette.violet, { emissive: palette.violet, emissiveIntensity: 0.18 }),
green: standard(palette.green, { emissive: palette.green, emissiveIntensity: 0.18 }),
white: standard(palette.white),
pathUnder: new THREE.MeshBasicMaterial({ color: 0x19384d }),
glowAmber: standard(palette.amber, {
emissive: palette.amber,
emissiveIntensity: 1.2,
roughness: 0.35
}),
glowTeal: standard(palette.teal, {
emissive: palette.teal,
emissiveIntensity: 1.2,
roughness: 0.35
}),
glowBlue: standard(palette.blue, {
emissive: palette.blue,
emissiveIntensity: 1.35,
roughness: 0.35
}),
glowViolet: standard(palette.violet, {
emissive: palette.violet,
emissiveIntensity: 1.2,
roughness: 0.35
}),
glowGreen: standard(palette.green, {
emissive: palette.green,
emissiveIntensity: 1.2,
roughness: 0.35
})
};
// ---------------------------------------------------------------------
// Basic voxel construction helpers
// ---------------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, thickness, material, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, length, thickness),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeAccentPad(x, z, color, width = 3.0, depth = 2.8) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.09,
depthWrite: false
});
const pad = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.025, depth),
material
);
pad.position.set(x, 0.055, z);
scene.add(pad);
}
// ---------------------------------------------------------------------
// Tiled voxel diorama
// ---------------------------------------------------------------------
box(24, 0.5, 10, materials.base, 0, -0.45, 0);
let seed = 137;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const tileGeometry = new THREE.BoxGeometry(0.94, 0.16, 0.94);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0.02,
flatShading: true
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
23 * 9
);
tiles.receiveShadow = true;
const matrixHelper = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let x = -11; x <= 11; x++) {
for (let z = -4; z <= 4; z++) {
matrixHelper.position.set(x, -0.08 + random() * 0.025, z);
matrixHelper.updateMatrix();
tiles.setMatrixAt(tileIndex, matrixHelper.matrix);
const shade = 0.085 + random() * 0.025;
tileColor.setHSL(0.56, 0.36, shade);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// ---------------------------------------------------------------------
// Generator
// ---------------------------------------------------------------------
const generatorX = -8.3;
makeAccentPad(generatorX, 0, palette.amber, 3.3, 3.2);
box(3.15, 0.22, 2.9, materials.dark, generatorX, 0.09, 0);
box(2.3, 1.55, 1.75, materials.teal, generatorX, 0.98, 0);
box(2.45, 0.22, 1.9, materials.steel, generatorX, 1.82, 0);
// Ribbed top.
for (let i = 0; i < 5; i++) {
box(
0.16,
0.18,
1.45,
materials.steelLight,
generatorX - 0.85 + i * 0.43,
2.02,
0
);
}
// Front panel.
box(1.8, 0.82, 0.08, materials.dark, generatorX, 1.0, 0.91);
box(0.8, 0.16, 0.1, materials.amber, generatorX - 0.3, 1.25, 0.98);
box(0.8, 0.1, 0.1, materials.steelLight, generatorX - 0.3, 0.92, 0.98);
// Rotating square rotor.
const rotor = new THREE.Group();
rotor.position.set(generatorX, 1.0, 1.04);
scene.add(rotor);
box(0.34, 0.34, 0.16, materials.copper, 0, 0, 0, rotor);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
const blade = box(
0.66,
0.14,
0.13,
materials.amber,
Math.cos(angle) * 0.22,
Math.sin(angle) * 0.22,
0,
rotor
);
blade.rotation.z = angle;
}
// Output block.
box(0.48, 0.48, 0.48, materials.amber, -6.95, 1.18, 0);
// ---------------------------------------------------------------------
// Transformer stations
// ---------------------------------------------------------------------
function makeTransformer(x, accentMaterial, accentColor) {
makeAccentPad(x, 0, accentColor, 3.15, 3.0);
box(2.9, 0.22, 2.7, materials.dark, x, 0.08, 0);
box(2.35, 0.16, 2.2, accentMaterial, x, 0.27, 0);
box(1.55, 0.26, 1.45, materials.steel, x, 0.48, 0);
// Central magnetic core.
box(0.42, 2.05, 0.62, materials.dark, x, 1.48, 0);
// Voxel winding stacks on both sides of the core.
for (let side = -1; side <= 1; side += 2) {
for (let i = 0; i < 7; i++) {
box(
0.34,
0.19,
0.92,
i % 2 ? materials.copper : materials.amber,
x + side * 0.47,
0.75 + i * 0.25,
0
);
}
}
// Top yoke and simplified terminals.
box(1.32, 0.28, 0.72, materials.steelLight, x, 2.52, 0);
for (let i = -1; i <= 1; i++) {
box(0.15, 0.42, 0.15, accentMaterial, x + i * 0.38, 2.87, 0);
box(0.23, 0.12, 0.23, materials.steelLight, x + i * 0.38, 3.1, 0);
}
// Front identification panel.
box(1.12, 0.36, 0.07, accentMaterial, x, 1.03, 0.72);
box(0.64, 0.08, 0.08, materials.dark, x, 1.03, 0.77);
}
makeTransformer(-4.1, materials.teal, palette.teal);
makeTransformer(4.7, materials.violet, palette.violet);
// ---------------------------------------------------------------------
// Voxel transmission-link pylons
// ---------------------------------------------------------------------
function makePylon(x) {
box(1.55, 0.2, 1.4, materials.dark, x, 0.08, 0);
for (const side of [-1, 1]) {
const legX = x + side * 0.48;
box(0.17, 4.05, 0.17, materials.steel, legX, 2.25, 0);
box(0.14, 3.9, 0.14, materials.steelLight, legX, 2.22, 0.36);
}
// Lattice braces.
for (let level = 0; level < 4; level++) {
const y0 = 0.45 + level * 0.9;
const y1 = y0 + 0.9;
beamBetween(
[x - 0.48, y0, 0],
[x + 0.48, y1, 0],
0.075,
materials.steelLight
);
beamBetween(
[x + 0.48, y0, 0],
[x - 0.48, y1, 0],
0.075,
materials.steelLight
);
}
box(2.25, 0.18, 0.2, materials.steelLight, x, 4.33, 0);
box(1.55, 0.14, 0.16, materials.steel, x, 3.72, 0);
// Small symbolic link supports.
box(0.09, 0.24, 0.09, materials.glowBlue, x - 0.38, 4.18, 0);
box(0.09, 0.24, 0.09, materials.glowBlue, x + 0.38, 4.18, 0);
}
makePylon(-1.7);
makePylon(2.3);
// ---------------------------------------------------------------------
// Symbolic link routes
// ---------------------------------------------------------------------
function drawRoute(points, glowMaterial) {
for (let i = 0; i < points.length - 1; i++) {
const a = new THREE.Vector3(...points[i]);
const b = new THREE.Vector3(...points[i + 1]);
const direction = b.clone().sub(a);
const length = direction.length();
direction.normalize();
beamBetween(points[i], points[i + 1], 0.075, materials.pathUnder);
const count = Math.max(1, Math.floor(length / 0.42));
const cell = length / count;
const dashLength = cell * 0.62;
for (let j = 0; j < count; j++) {
const centerDistance = j * cell + dashLength / 2;
const center = a.clone().addScaledVector(direction, centerDistance);
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.09, dashLength, 0.09),
glowMaterial
);
dash.position.copy(center);
dash.quaternion.setFromUnitVectors(Y_AXIS, direction);
scene.add(dash);
}
}
}
const generatorPath = [
[-6.72, 1.18, 0],
[-5.05, 1.18, 0]
];
const stepUpPath = [
[-3.08, 2.62, 0],
[-1.7, 4.12, 0]
];
const highVoltagePath = [
[-1.7, 4.12, 0],
[2.3, 4.12, 0]
];
const stepDownPath = [
[2.3, 4.12, 0],
[3.46, 2.57, 0]
];
const utilizationPath = [
[6.04, 1.18, 0],
[7.48, 1.18, 0]
];
drawRoute(generatorPath, materials.glowAmber);
drawRoute(stepUpPath, materials.glowTeal);
drawRoute(highVoltagePath, materials.glowBlue);
drawRoute(stepDownPath, materials.glowViolet);
drawRoute(utilizationPath, materials.glowGreen);
// ---------------------------------------------------------------------
// Utilization-side voxel structure
// ---------------------------------------------------------------------
const loadX = 8.7;
makeAccentPad(loadX, 0, palette.green, 2.9, 2.8);
box(2.75, 0.22, 2.5, materials.dark, loadX, 0.08, 0);
box(1.8, 1.35, 1.7, materials.steel, loadX, 0.88, 0);
box(1.35, 0.45, 1.25, materials.steelLight, loadX, 1.77, 0);
box(0.85, 0.3, 0.82, materials.green, loadX, 2.12, 0);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
box(
0.22,
0.22,
0.06,
materials.green,
loadX - 0.55 + col * 0.55,
0.65 + row * 0.48,
0.87
);
}
}
box(0.48, 0.48, 0.48, materials.green, 7.43, 1.18, 0);
// ---------------------------------------------------------------------
// Small voxel landscape elements
// ---------------------------------------------------------------------
function makeTree(x, z, scale = 1) {
box(
0.18 * scale,
0.85 * scale,
0.18 * scale,
materials.copper,
x,
0.42 * scale,
z
);
box(
0.78 * scale,
0.55 * scale,
0.78 * scale,
materials.teal,
x,
0.92 * scale,
z
);
box(
0.55 * scale,
0.42 * scale,
0.55 * scale,
materials.green,
x,
1.32 * scale,
z
);
}
[
[-10.1, -3.5, 0.8],
[-6.2, -3.5, 0.65],
[-0.8, -3.55, 0.75],
[5.5, -3.45, 0.72],
[10.0, -3.3, 0.9],
[-10.0, 3.45, 0.65],
[0.2, 3.5, 0.58],
[10.1, 3.35, 0.7]
].forEach(([x, z, s]) => makeTree(x, z, s));
// ---------------------------------------------------------------------
// Animated energy markers
// ---------------------------------------------------------------------
const particles = [];
function samplePolyline(points, t) {
const vectors = points.map(p => new THREE.Vector3(...p));
const lengths = [];
let total = 0;
for (let i = 0; i < vectors.length - 1; i++) {
const length = vectors[i].distanceTo(vectors[i + 1]);
lengths.push(length);
total += length;
}
let distance = t * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i] || i === lengths.length - 1) {
const u = lengths[i] === 0 ? 0 : distance / lengths[i];
return vectors[i].clone().lerp(vectors[i + 1], u);
}
distance -= lengths[i];
}
return vectors[0].clone();
}
function addParticles(points, material, count, speed) {
for (let i = 0; i < count; i++) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.2, 0.2, 0.2),
material
);
mesh.castShadow = true;
scene.add(mesh);
particles.push({
mesh,
points,
offset: i / count,
speed
});
}
}
addParticles(generatorPath, materials.glowAmber, 2, 0.22);
addParticles(stepUpPath, materials.glowTeal, 2, 0.18);
addParticles(highVoltagePath, materials.glowBlue, 4, 0.12);
addParticles(stepDownPath, materials.glowViolet, 2, 0.18);
addParticles(utilizationPath, materials.glowGreen, 2, 0.22);
// ---------------------------------------------------------------------
// Projected HTML scene labels
// ---------------------------------------------------------------------
const labels = [];
function addLabel(index, title, value, color, anchor) {
const element = document.createElement("div");
element.className = "scene-label";
element.style.setProperty("--label-color", color);
element.innerHTML = `
<div class="label-title">
<span class="label-index">${index}</span>${title}
</div>
<div class="label-value">${value}</div>
`;
document.getElementById("labels").appendChild(element);
labels.push({ element, anchor: new THREE.Vector3(...anchor) });
}
addLabel(
"01",
"GENERATOR",
"12 kV · symbolic",
"#f6ba4b",
[-8.3, 3.25, 0]
);
addLabel(
"02",
"TRANSFORMER A",
"12 → 132 kV",
"#42d8c3",
[-4.1, 3.65, 0]
);
addLabel(
"03",
"TRANSMISSION LINK",
"132 kV · symbolic",
"#68a9ff",
[0.3, 5.05, 0]
);
addLabel(
"04",
"TRANSFORMER B",
"132 → 33 kV",
"#b58aff",
[4.7, 3.65, 0]
);
addLabel(
"05",
"UTILIZATION",
"33 kV · symbolic",
"#72df91",
[8.7, 2.75, 0]
);
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of labels) {
const projected = label.anchor.clone().project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom, and pinch zoom
// ---------------------------------------------------------------------
const controls = {
theta: 0.48,
phi: 1.02,
zoom: 1
};
function updateCamera() {
const radius = 24;
camera.position.set(
target.x + radius * Math.sin(controls.phi) * Math.sin(controls.theta),
target.y + radius * Math.cos(controls.phi),
target.z + radius * Math.sin(controls.phi) * Math.cos(controls.theta)
);
camera.lookAt(target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = aspect < 1 ? 24 / aspect : 13;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
if (pointers.size === 1) {
const dx = previous.x - event.clientX;
const dy = previous.y - event.clientY;
controls.theta -= dx * 0.005;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0035,
0.62,
1.34
);
updateCamera();
} else if (pointers.size === 2) {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * (distance / pinchDistance),
0.62,
2.35
);
updateCamera();
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2
? (() => {
const [a, b] = [...pointers.values()];
return Math.hypot(a.x - b.x, a.y - b.y);
})()
: 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.35
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
controls.theta = 0.48;
controls.phi = 1.02;
controls.zoom = 1;
updateCamera();
});
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
rotor.rotation.z = elapsed * 1.25;
for (const particle of particles) {
const t = (elapsed * particle.speed + particle.offset) % 1;
particle.mesh.position.copy(samplePolyline(particle.points, t));
particle.mesh.rotation.x += delta * 2.4;
particle.mesh.rotation.y += delta * 3.1;
const pulse = 0.88 + Math.sin(elapsed * 5 + particle.offset * 9) * 0.12;
particle.mesh.scale.setScalar(pulse);
}
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```