Prompt specification
Build or customize the Three.js 3D scene "Power-adapter concept cutaway 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: Power-adapter concept cutaway exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/power-adapter-concept-cutaway-exhibit-x1619
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a scene with a fictional adapter shell around separate transformer, rectifier, and smoothing diagrams; label these conceptual stages without providing a buildable mains circuit. Voxel style.
Working Three.js Starter (power-adapter-concept-cutaway-exhibit-x1619):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WATT-01 — Fictional Voxel Adapter</title>
<style>
:root {
--ink: #eaf6f7;
--muted: #91aeb9;
--copper: #f3a45d;
--pink: #ff7081;
--cyan: #55d7c7;
--panel: rgba(8, 19, 29, 0.82);
--line: rgba(145, 174, 185, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 36%, #142b39 0%, #09151f 45%, #050b12 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
z-index: 0;
pointer-events: none;
opacity: 0.18;
background-image:
linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
background-size: 32px 32px;
mask-image: radial-gradient(circle at center, black, transparent 78%);
}
#scene {
position: fixed;
inset: 0;
z-index: 1;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
header {
position: absolute;
top: 28px;
left: 30px;
width: min(380px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
background: var(--cyan);
box-shadow: 0 0 18px rgba(85, 215, 199, 0.75);
}
h1 {
margin: 0;
font: 800 clamp(38px, 5vw, 64px)/0.92 ui-monospace, SFMono-Regular, Menlo,
Consolas, monospace;
letter-spacing: -0.07em;
text-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}
.subtitle {
max-width: 340px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid rgba(243, 164, 93, 0.35);
background: rgba(243, 164, 93, 0.08);
color: #ffd0a8;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.14em;
}
.status::before {
content: "";
width: 6px;
height: 6px;
background: var(--copper);
}
#reset {
position: absolute;
top: 28px;
right: 30px;
pointer-events: auto;
display: inline-flex;
align-items: center;
gap: 9px;
border: 1px solid var(--line);
padding: 10px 13px;
background: var(--panel);
color: var(--ink);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.12em;
cursor: pointer;
backdrop-filter: blur(12px);
}
#reset:hover {
border-color: rgba(85, 215, 199, 0.6);
color: var(--cyan);
}
#reset span {
color: var(--cyan);
font-size: 15px;
}
.stage-key {
position: absolute;
left: 30px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: min(680px, calc(100vw - 60px));
}
.stage-card {
display: grid;
grid-template-columns: 28px 1fr;
gap: 9px;
min-width: 180px;
padding: 10px 12px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(12px);
}
.stage-card b {
display: grid;
place-items: center;
width: 28px;
height: 28px;
color: #08131c;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.stage-card:nth-child(1) b { background: var(--copper); }
.stage-card:nth-child(2) b { background: var(--pink); }
.stage-card:nth-child(3) b { background: var(--cyan); }
.stage-card strong {
display: block;
margin-bottom: 3px;
font: 700 11px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stage-card small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.notice {
position: absolute;
right: 30px;
bottom: 28px;
max-width: 330px;
padding: 10px 12px;
border-left: 3px solid var(--copper);
background: rgba(8, 19, 29, 0.76);
color: #b8cbd1;
font-size: 10px;
line-height: 1.45;
backdrop-filter: blur(12px);
}
.notice strong {
color: #ffd0a8;
}
.hint {
position: absolute;
left: 50%;
bottom: 33px;
transform: translateX(-50%);
color: rgba(205, 224, 229, 0.5);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
@media (max-width: 920px) {
.hint {
display: none;
}
.notice {
max-width: 270px;
}
}
@media (max-width: 700px) {
header {
top: 18px;
left: 18px;
}
h1 {
font-size: 38px;
}
.subtitle {
display: none;
}
.status {
margin-top: 10px;
}
#reset {
top: 18px;
right: 18px;
}
.stage-key {
left: 18px;
bottom: 18px;
right: 18px;
max-width: none;
gap: 5px;
}
.stage-card {
flex: 1 1 30%;
min-width: 92px;
grid-template-columns: 1fr;
padding: 8px;
}
.stage-card b {
width: 22px;
height: 22px;
}
.stage-card small {
display: none;
}
.notice {
left: 18px;
right: 18px;
bottom: 88px;
max-width: none;
font-size: 9px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel-style conceptual adapter scene"></main>
<div class="ui">
<header>
<div class="eyebrow">Concept object / 01</div>
<h1>WATT–01</h1>
<p class="subtitle">
A fictional adapter shell, opened like a toy to reveal three separate
energy-transformation ideas.
</p>
<div class="status">NON-OPERATIONAL CONCEPT</div>
</header>
<button id="reset" type="button" aria-label="Reset the camera view">
<span>↺</span> RESET VIEW
</button>
<div class="stage-key" aria-label="Conceptual stages">
<div class="stage-card">
<b>01</b>
<div>
<strong>Transformer</strong>
<small>magnetic coupling</small>
</div>
</div>
<div class="stage-card">
<b>02</b>
<div>
<strong>Rectifier</strong>
<small>alternating → one-way</small>
</div>
</div>
<div class="stage-card">
<b>03</b>
<div>
<strong>Smoothing</strong>
<small>reserve + level</small>
</div>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Shift-drag to pan</div>
<div class="notice">
<strong>Concept model only.</strong>
No mains wiring, voltages, ratings, component values, or buildable circuit
is provided.
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.querySelector("#scene");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x07111d, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Voxel cutaway of a fictional adapter showing transformer, rectifier, and smoothing concepts"
);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111d, 0.015);
const camera = new THREE.OrthographicCamera(-8, 8, 5.5, -5.5, 0.1, 100);
const controls = {
theta: 0.48,
phi: 1.11,
zoom: 1,
target: new THREE.Vector3(0, 0.15, 0)
};
const clock = new THREE.Clock();
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.06,
flatShading: true,
...options
});
}
const materials = {
shell: standard(0x214154, { metalness: 0.16 }),
shellDark: standard(0x142b39, { metalness: 0.18 }),
shellEdge: standard(0x3c6674, { metalness: 0.22 }),
inner: standard(0x0d1c28),
panel: standard(0x102431),
grid: standard(0x1b3645),
black: standard(0x081018),
core: standard(0x8199a4, { roughness: 0.42, metalness: 0.45 }),
copper: standard(0xf3a45d, { roughness: 0.58 }),
copperDark: standard(0xb9683f),
pink: standard(0xff7081),
cyan: standard(0x55d7c7),
blue: standard(0x4e8dff),
white: standard(0xdbecef),
ground: standard(0x08131d, { roughness: 0.96 })
};
const glowCopper = standard(0xffb568, {
emissive: 0xf07b2f,
emissiveIntensity: 1.4,
roughness: 0.4
});
const glowPink = standard(0xff8190, {
emissive: 0xff4963,
emissiveIntensity: 1.25,
roughness: 0.4
});
const glowCyan = standard(0x72eadc, {
emissive: 0x25bfae,
emissiveIntensity: 1.25,
roughness: 0.4
});
function addBox(parent, size, position, material, outlined = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x06101a,
transparent: true,
opacity: 0.55
})
);
mesh.add(edges);
}
return mesh;
}
function addLabel(parent, position, size, title, subtitle, accent) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 1024, 256);
ctx.fillStyle = "#091723";
ctx.fillRect(0, 0, 1024, 256);
ctx.fillStyle = accent;
ctx.fillRect(28, 47, 14, 160);
ctx.fillStyle = "#effbfc";
ctx.font = "700 67px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.fillText(title, 72, 112);
ctx.fillStyle = "#9db8c1";
ctx.font = "600 31px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.fillText(subtitle, 74, 173);
ctx.fillStyle = accent;
ctx.fillRect(950, 48, 42, 42);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const group = new THREE.Group();
group.position.set(position[0], position[1], position[2]);
addBox(
group,
[size[0], size[1], 0.10],
[0, 0, 0],
materials.black,
true
);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(size[0] - 0.08, size[1] - 0.08),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false
})
);
face.position.z = 0.056;
group.add(face);
parent.add(group);
return group;
}
// Lighting
scene.add(new THREE.HemisphereLight(0x9ddcf2, 0x071019, 2.0));
const keyLight = new THREE.DirectionalLight(0xffe6c4, 3.6);
keyLight.position.set(7, 12, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x54a8ff, 2.1);
rimLight.position.set(-9, 5, -6);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff7b45, 22, 12, 2);
warmFill.position.set(-4, 1, 4);
scene.add(warmFill);
const coolFill = new THREE.PointLight(0x4be4d0, 18, 12, 2);
coolFill.position.set(4, 1, 3);
scene.add(coolFill);
// Ground and voxel grid
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.72;
ground.receiveShadow = true;
scene.add(ground);
const gridMaterial = standard(0x17303d, { roughness: 1 });
for (let i = -9; i <= 9; i++) {
addBox(scene, [0.018, 0.018, 20], [i * 1.15, -2.69, 0], gridMaterial);
addBox(scene, [20, 0.018, 0.018], [0, -2.685, i * 1.15], gridMaterial);
}
// Fictional adapter shell
const shell = new THREE.Group();
scene.add(shell);
addBox(shell, [11.9, 0.46, 5.25], [0, -2.36, 0], materials.shell, true);
addBox(shell, [11.45, 5.75, 0.44], [0, 0.36, -2.39], materials.shellDark, true);
addBox(shell, [11.9, 0.40, 5.25], [0, 3.32, 0], materials.shell, true);
// Rear side walls leave the front open like a cutaway.
addBox(shell, [0.42, 5.55, 3.55], [-5.68, 0.35, -0.65], materials.shell, true);
addBox(shell, [0.42, 5.55, 3.55], [5.68, 0.35, -0.65], materials.shell, true);
// Front frame
addBox(shell, [0.38, 5.48, 0.40], [-5.48, 0.36, 2.37], materials.shellEdge, true);
addBox(shell, [0.38, 5.48, 0.40], [5.48, 0.36, 2.37], materials.shellEdge, true);
addBox(shell, [11.25, 0.36, 0.40], [0, 2.96, 2.37], materials.shellEdge, true);
addBox(shell, [11.25, 0.28, 0.40], [0, -2.00, 2.37], materials.shellEdge, true);
// Interior floor and bay dividers
addBox(shell, [10.95, 0.16, 4.40], [0, -2.03, -0.15], materials.inner);
addBox(shell, [0.16, 4.85, 3.70], [-1.78, 0.38, -0.58], materials.shellEdge);
addBox(shell, [0.16, 4.85, 3.70], [1.78, 0.38, -0.58], materials.shellEdge);
// Feet and blocky fasteners
const footPositions = [
[-4.8, -2.68, -1.85],
[4.8, -2.68, -1.85],
[-4.8, -2.68, 1.85],
[4.8, -2.68, 1.85]
];
footPositions.forEach((p) => {
addBox(shell, [0.82, 0.28, 0.82], p, materials.black, true);
});
const fastenerPositions = [
[-5.28, 2.78, 2.59],
[5.28, 2.78, 2.59],
[-5.28, -1.82, 2.59],
[5.28, -1.82, 2.59]
];
fastenerPositions.forEach((p) => {
addBox(shell, [0.15, 0.15, 0.08], p, materials.core);
});
// Side vents, made only from voxel blocks.
for (let i = 0; i < 6; i++) {
addBox(
shell,
[0.08, 0.10, 0.70],
[5.91, 0.25 + i * 0.30, -0.88],
materials.black
);
}
addLabel(
shell,
[0, 2.96, 2.62],
[4.70, 0.72],
"WATT—01",
"FICTIONAL ADAPTER / CONCEPT CUTAWAY",
"#55d7c7"
);
const stageX = [-3.55, 0, 3.55];
const stageTitles = [
["01 TRANSFORMER", "MAGNETIC COUPLING", "#f3a45d"],
["02 RECTIFIER", "ALTERNATING → ONE-WAY", "#ff7081"],
["03 SMOOTHING", "RESERVE + LEVEL", "#55d7c7"]
];
// Three independent diagram bays
stageX.forEach((x, index) => {
addBox(
shell,
[3.16, 4.18, 0.16],
[x, 0.08, -2.08],
materials.panel,
true
);
addBox(
shell,
[3.02, 4.02, 0.07],
[x, 0.08, -1.97],
materials.inner
);
// Fine voxel grid on the back of each bay
for (let gx = -1; gx <= 1; gx++) {
addBox(
shell,
[0.018, 3.40, 0.012],
[x + gx * 0.78, 0.24, -1.925],
materials.grid
);
}
for (let gy = -1; gy <= 1; gy++) {
addBox(
shell,
[2.78, 0.018, 0.012],
[x, 0.20 + gy * 0.73, -1.92],
materials.grid
);
}
addBox(
shell,
[3.08, 0.18, 2.76],
[x, -1.85, -0.33],
materials.shellDark,
true
);
addLabel(
shell,
[x, -1.30, -1.82],
[3.02, 0.78],
stageTitles[index][0],
stageTitles[index][1],
stageTitles[index][2]
);
});
// Stage 1: abstract magnetic coupling
const transformer = new THREE.Group();
transformer.position.set(stageX[0], 0.38, -0.48);
shell.add(transformer);
addBox(transformer, [0.20, 2.02, 0.28], [-0.76, 0, 0], materials.core, true);
addBox(transformer, [0.20, 2.02, 0.28], [0.76, 0, 0], materials.core, true);
addBox(transformer, [1.72, 0.20, 0.28], [0, 0.91, 0], materials.core, true);
addBox(transformer, [1.72, 0.20, 0.28], [0, -0.91, 0], materials.core, true);
[-1, 1].forEach((side) => {
for (let i = 0; i < 6; i++) {
addBox(
transformer,
[0.44, 0.17, 0.43],
[side * 0.51 + (i % 2 ? 0.035 : -0.035), -0.72 + i * 0.29, 0.20],
i % 2 ? materials.copper : materials.copperDark,
true
);
addBox(
transformer,
[0.35, 0.13, 0.31],
[side * 0.51, -0.72 + i * 0.29, -0.11],
materials.copperDark
);
}
});
const couplingBlocks = [];
for (let i = 0; i < 5; i++) {
const mat = glowCopper.clone();
const block = addBox(
transformer,
[0.13, 0.13, 0.13],
[-0.22 + i * 0.11, 0, 0.48],
mat
);
couplingBlocks.push(block);
}
addBox(transformer, [0.07, 0.58, 0.07], [0, 0, 0.28], materials.glowCopper);
addBox(transformer, [0.58, 0.07, 0.07], [0, 0, 0.28], materials.glowCopper);
// Stage 2: abstract conversion from alternating to one-way
const rectifier = new THREE.Group();
rectifier.position.set(stageX[1], 0.38, -0.48);
shell.add(rectifier);
for (let i = 0; i < 5; i++) {
addBox(
rectifier,
[0.32, 0.22, 0.32],
[-1.04, -0.68 + i * 0.34, 0.18],
i % 2 ? materials.blue : materials.pink,
true
);
}
const converterMaterial = glowPink.clone();
addBox(
rectifier,
[0.56, 0.82, 0.56],
[-0.22, 0, 0.20],
converterMaterial,
true
);
// A block-built directional gesture, not a schematic connection.
addBox(rectifier, [0.13, 0.13, 0.13], [0.20, 0, 0.48], materials.pink);
addBox(rectifier, [0.13, 0.13, 0.13], [0.34, 0, 0.48], materials.pink);
addBox(rectifier, [0.13, 0.13, 0.13], [0.48, 0, 0.48], materials.pink);
for (let i = 0; i < 3; i++) {
addBox(
rectifier,
[0.40, 0.20, 0.40],
[0.93, -0.31 + i * 0.31, 0.20],
materials.pink,
true
);
}
// Stage 3: abstract reservoir and leveled output
const smoother = new THREE.Group();
smoother.position.set(stageX[2], 0.38, -0.48);
shell.add(smoother);
const jitterHeights = [-0.68, 0.22, -0.36, 0.53, -0.08];
jitterHeights.forEach((y, i) => {
addBox(
smoother,
[0.31, 0.20, 0.31],
[-1.12, y, 0.20],
i % 2 ? materials.blue : materials.cyan,
true
);
});
// Open voxel basin
addBox(smoother, [1.42, 0.17, 0.72], [-0.06, -0.61, 0.12], materials.core, true);
addBox(smoother, [0.16, 0.62, 0.72], [-0.72, -0.33, 0.12], materials.core, true);
addBox(smoother, [0.16, 0.62, 0.72], [0.60, -0.33, 0.12], materials.core, true);
addBox(smoother, [1.36, 0.48, 0.13], [-0.06, -0.35, -0.23], materials.shellEdge);
const fillBlocks = [];
for (let i = 0; i < 4; i++) {
const fill = addBox(
smoother,
[0.23, 0.32, 0.43],
[-0.51 + i * 0.30, -0.37, 0.14],
glowCyan.clone(),
true
);
fillBlocks.push(fill);
}
const outputBlocks = [];
for (let i = 0; i < 3; i++) {
const output = addBox(
smoother,
[0.25, 0.18, 0.28],
[0.88 + i * 0.29, -0.17, 0.19],
glowCyan.clone(),
true
);
outputBlocks.push(output);
}
// A conceptual overhead sequence made from separated voxels
const flowPieces = [];
const flowMaterials = [glowCopper, glowPink, glowCyan];
for (let i = 0; i < 24; i++) {
const x = -4.83 + i * 0.42;
const groupIndex = x < -1.78 ? 0 : x < 1.78 ? 1 : 2;
const mat = flowMaterials[groupIndex].clone();
mat.emissiveIntensity = 0.55;
mat.transparent = true;
mat.opacity = 0.55;
const piece = addBox(
shell,
[0.13, 0.13, 0.13],
[x, 2.48, 0.10],
mat
);
flowPieces.push(piece);
}
const packets = [];
for (let i = 0; i < 3; i++) {
const packet = addBox(
shell,
[0.22, 0.22, 0.22],
[-4 + i * 3, 2.65, 0.10],
[glowCopper, glowPink, glowCyan][i].clone()
);
packets.push(packet);
}
// Sparse background voxels
const backgroundVoxels = new THREE.Group();
scene.add(backgroundVoxels);
const backgroundMaterials = [
standard(0x183344),
standard(0x214758),
standard(0x17303e)
];
for (let i = 0; i < 26; i++) {
const size = 0.12 + (i % 4) * 0.055;
const x = -8.5 + ((i * 1.73) % 17);
const y = -1.4 + ((i * 0.91) % 6.5);
const z = -5.5 - (i % 3) * 0.55;
addBox(
backgroundVoxels,
[size, size, size],
[x, y, z],
backgroundMaterials[i % backgroundMaterials.length]
);
}
// Custom camera controls; no Three.js addons are used.
function updateCamera() {
const spherical = new THREE.Spherical(18, controls.phi, controls.theta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
camera.updateProjectionMatrix();
}
function resize() {
const aspect = innerWidth / innerHeight;
const viewHeight = Math.max(10.6, 13.2 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
resize();
updateCamera();
const pointers = new Map();
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
let panning = false;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
lastX = event.clientX;
lastY = event.clientY;
panning = event.shiftKey || event.button === 2;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (distance / pinchDistance),
0.65,
2.5
);
camera.updateProjectionMatrix();
}
pinchDistance = distance;
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
camera.updateMatrixWorld();
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 pixelsToWorld =
(camera.top - camera.bottom) / camera.zoom / canvas.clientHeight;
controls.target.addScaledVector(right, -dx * pixelsToWorld);
controls.target.addScaledVector(up, dy * pixelsToWorld);
controls.target.y = THREE.MathUtils.clamp(
controls.target.y,
-2.2,
2.6
);
} else {
controls.theta -= dx * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0055,
0.68,
1.46
);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) panning = false;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.5
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
function resetView() {
controls.theta = 0.48;
controls.phi = 1.11;
controls.target.set(0, 0.15, 0);
camera.zoom = 1;
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
} else if (key === "arrowleft") {
controls.theta += 0.08;
} else if (key === "arrowright") {
controls.theta -= 0.08;
} else if (key === "arrowup") {
controls.phi = Math.max(0.68, controls.phi - 0.06);
} else if (key === "arrowdown") {
controls.phi = Math.min(1.46, controls.phi + 0.06);
} else if (key === "+" || key === "=") {
camera.zoom = Math.min(2.5, camera.zoom * 1.08);
} else if (key === "-") {
camera.zoom = Math.max(0.65, camera.zoom / 1.08);
} else {
return;
}
updateCamera();
});
function animate() {
requestAnimationFrame(animate);
const time = reducedMotion ? 0 : clock.getElapsedTime();
couplingBlocks.forEach((block, i) => {
const pulse = 1 + 0.38 * Math.sin(time * 3.2 - i * 0.7);
block.scale.setScalar(pulse);
block.material.emissiveIntensity =
0.65 + 0.95 * (0.5 + 0.5 * Math.sin(time * 3.2 - i * 0.7));
});
const conversionMix = 0.5 + 0.5 * Math.sin(time * 2.1);
converterMaterial.color.lerpColors(
materials.pink.color,
materials.cyan.color,
conversionMix
);
converterMaterial.emissive.copy(converterMaterial.color);
converterMaterial.emissiveIntensity = 0.55 + conversionMix * 0.55;
fillBlocks.forEach((block, i) => {
block.position.y = -0.37 + Math.sin(time * 1.8 + i * 0.8) * 0.035;
});
outputBlocks.forEach((block, i) => {
block.position.y = -0.17 + Math.sin(time * 2.4 - i * 0.7) * 0.035;
});
packets.forEach((packet, i) => {
const progress = (time * 0.115 + i / packets.length) % 1;
packet.position.x = -4.7 + progress * 9.4;
packet.position.y = 2.65 + Math.sin(time * 2.8 + i) * 0.055;
packet.rotation.y = time * 0.9 + i;
packet.rotation.z = time * 0.55;
});
flowPieces.forEach((piece, i) => {
piece.material.opacity =
0.38 + 0.22 * (0.5 + 0.5 * Math.sin(time * 2 - i * 0.18));
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```