Prompt specification
Build or customize the Three.js 3D scene "Magnetic braking museum track" 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: Magnetic braking museum track
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/magnetic-braking-museum-track-x1643
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a voxel magnetic-braking exhibit. A copper-colored plate travels along a straight museum track through the gap of a large magnet assembly. Expose the plate face and mark the field region with a translucent rectangular volume. As the leading and trailing edges cross that region, show illustrative current loops and drag arrows opposing the motion. The arrows explain the direction of braking; their lengths must be labeled schematic rather than calculated forces. Add a slow-motion control and a return track beneath the exhibit so visitors can inspect repeated passes from either side.
Working Three.js Starter (magnetic-braking-museum-track-x1643):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Magnetic-Braking Exhibit</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf7f7;
--muted: #91a8ad;
--panel: rgba(7, 17, 24, 0.82);
--line: rgba(137, 218, 221, 0.2);
--cyan: #58e0e7;
--copper: #d9844b;
--orange: #ffb15e;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071018;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 22px;
left: 26px;
display: flex;
align-items: center;
gap: 12px;
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
color: var(--muted);
text-transform: uppercase;
}
.brand::before {
content: "";
width: 9px;
height: 9px;
background: var(--copper);
box-shadow: 0 0 18px rgba(217, 132, 75, 0.8);
}
.story {
position: absolute;
top: 62px;
left: 26px;
width: min(340px, calc(100vw - 52px));
padding: 20px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 20px 65px rgba(0, 0, 0, 0.28);
pointer-events: auto;
}
.eyebrow {
color: var(--cyan);
font: 700 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 9px 0 10px;
font-size: clamp(25px, 3vw, 37px);
line-height: 1.02;
letter-spacing: -0.04em;
}
.story p {
margin: 0;
color: #b8c9cc;
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 9px;
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #c8d7d9;
font-size: 11px;
}
.swatch {
width: 24px;
height: 4px;
flex: 0 0 auto;
border-radius: 4px;
}
.swatch.copper { background: var(--copper); }
.swatch.field { background: var(--cyan); }
.swatch.drag { background: var(--orange); }
.notice {
margin-top: 15px;
padding: 11px 12px;
border-left: 3px solid var(--orange);
background: rgba(255, 177, 94, 0.075);
color: #d8c9b8;
font-size: 11px;
line-height: 1.45;
}
.notice strong {
display: block;
margin-bottom: 2px;
color: #ffd4a7;
font: 700 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout {
position: absolute;
top: 24px;
right: 26px;
min-width: 250px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(7, 17, 24, 0.72);
backdrop-filter: blur(14px);
font: 700 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout::before {
content: "LIVE MODEL / ";
color: var(--muted);
}
#statusText { color: var(--cyan); }
.controls {
position: absolute;
right: 26px;
bottom: 24px;
width: min(340px, calc(100vw - 52px));
padding: 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
pointer-events: auto;
box-shadow: 0 20px 65px rgba(0, 0, 0, 0.3);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(137, 218, 221, 0.22);
border-radius: 9px;
padding: 10px 12px;
background: rgba(22, 49, 57, 0.7);
color: var(--ink);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(37, 78, 87, 0.9);
border-color: rgba(88, 224, 231, 0.55);
}
button:active { transform: translateY(1px); }
button.active {
background: rgba(50, 138, 145, 0.48);
border-color: var(--cyan);
}
.speed-label {
display: flex;
justify-content: space-between;
margin: 17px 0 8px;
color: #c6d6d8;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#speedValue { color: var(--cyan); }
input[type="range"] {
width: 100%;
height: 4px;
appearance: none;
border-radius: 10px;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--range-fill, 31%),
rgba(255, 255, 255, 0.13) var(--range-fill, 31%),
rgba(255, 255, 255, 0.13) 100%
);
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 15px;
border: 2px solid #dffafa;
border-radius: 50%;
background: #163f48;
box-shadow: 0 0 12px rgba(88, 224, 231, 0.45);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #dffafa;
border-radius: 50%;
background: #163f48;
cursor: pointer;
}
.view-title {
margin: 17px 0 8px;
color: var(--muted);
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.views {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.views button {
padding: 9px 5px;
font-size: 9px;
}
.hint {
margin-top: 12px;
color: #71898e;
font: 500 9px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
@media (max-width: 760px) {
.story {
top: 54px;
width: 270px;
padding: 15px;
}
.story p { font-size: 11px; }
.legend, .notice { display: none; }
.readout { top: auto; bottom: 214px; right: 16px; min-width: 0; }
.controls { right: 16px; bottom: 16px; width: 300px; }
.brand { top: 18px; left: 18px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel magnetic-braking museum exhibit"></canvas>
<div class="hud">
<div class="brand">Voxel Lab / Exhibit 04</div>
<section class="story">
<div class="eyebrow">Magnetic braking</div>
<h1>Copper in a field.</h1>
<p>
A copper plate travels left to right through the gap between the rear
north pole and the cutaway south pole. The magnetic field is normal to
the plate. As its leading and trailing edges enter and leave the field,
circulating eddy currents appear and produce a braking force.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch copper"></span>
<span>Copper conducting plate</span>
</div>
<div class="legend-row">
<span class="swatch field"></span>
<span>Field region and illustrative eddy currents</span>
</div>
<div class="legend-row">
<span class="swatch drag"></span>
<span>Drag direction opposing plate motion</span>
</div>
</div>
<div class="notice">
<strong>Schematic force display</strong>
Drag-arrow lengths are intentionally fixed. They indicate direction
only and are not calculated force magnitudes.
</div>
</section>
<div class="readout" role="status" aria-live="polite">
<span id="statusText">Initializing exhibit</span>
</div>
<section class="controls" aria-label="Exhibit controls">
<div class="button-row">
<button id="playBtn" type="button">Pause</button>
<button id="resetBtn" type="button">Restart pass</button>
</div>
<label class="speed-label" for="speed">
<span>Playback / slow motion</span>
<span id="speedValue">×0.35</span>
</label>
<input id="speed" type="range" min="0.10" max="1.00" step="0.05" value="0.35" />
<div class="view-title">Inspection viewpoints</div>
<div class="views">
<button type="button" data-view="overview" class="active">Overview</button>
<button type="button" data-view="face">Plate face</button>
<button type="button" data-view="gap">Field gap</button>
<button type="button" data-view="visitor">Visitor</button>
<button type="button" data-view="drive">Drive side</button>
<button type="button" data-view="return">Return run</button>
</div>
<div class="hint">
Drag to orbit · wheel/pinch to zoom · right-drag to pan
</div>
</section>
</div>
<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 playBtn = document.querySelector("#playBtn");
const resetBtn = document.querySelector("#resetBtn");
const speedInput = document.querySelector("#speed");
const speedValue = document.querySelector("#speedValue");
const statusText = document.querySelector("#statusText");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.FogExp2(0x071018, 0.018);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const clock = new THREE.Clock();
const X_AXIS = new THREE.Vector3(1, 0, 0);
const Y_AXIS = new THREE.Vector3(0, 1, 0);
// ---------------------------------------------------------------------
// Camera controls implemented locally, without Three.js add-ons.
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.25, 0),
radius: 24,
theta: 0.72,
phi: 1.06
};
function applyCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
applyCamera();
const views = {
overview: {
target: [0, 0.25, 0],
radius: 24,
theta: 0.72,
phi: 1.06
},
face: {
target: [0, 1.35, 0],
radius: 9.3,
theta: 0.30,
phi: 1.38
},
gap: {
target: [0, 1.25, 0],
radius: 11.5,
theta: 1.15,
phi: 1.20
},
visitor: {
target: [0, 0.55, 0],
radius: 18,
theta: 0.02,
phi: 1.25
},
drive: {
target: [0, 0.55, 0],
radius: 18,
theta: Math.PI,
phi: 1.23
},
return: {
target: [0, -2.15, 0],
radius: 11,
theta: 0.48,
phi: 1.36
}
};
function setView(name) {
const v = views[name];
if (!v) return;
cameraState.target.set(...v.target);
cameraState.radius = v.radius;
cameraState.theta = v.theta;
cameraState.phi = v.phi;
applyCamera();
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const activePointers = new Map();
let pointerMode = "rotate";
let lastPointer = { x: 0, y: 0 };
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...activePointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
event.preventDefault();
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 1) {
pointerMode =
event.button === 2 || event.shiftKey ? "pan" : "rotate";
lastPointer = { x: event.clientX, y: event.clientY };
} else {
pointerMode = "pinch";
lastPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
event.preventDefault();
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (lastPinchDistance / distance),
5.5,
42
);
applyCamera();
}
lastPinchDistance = distance;
return;
}
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
if (pointerMode === "rotate") {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.18,
Math.PI - 0.18
);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const scale = cameraState.radius * 0.0015;
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
}
applyCamera();
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 1) {
const remaining = [...activePointers.values()][0];
lastPointer = { x: remaining.x, y: remaining.y };
pointerMode = "rotate";
} else if (activePointers.size === 0) {
lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
5.5,
42
);
applyCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Materials and procedural textures.
// ---------------------------------------------------------------------
function makeCopperTexture() {
const c = document.createElement("canvas");
c.width = c.height = 512;
const ctx = c.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 512, 0);
gradient.addColorStop(0, "#8f3f21");
gradient.addColorStop(0.22, "#c36d3d");
gradient.addColorStop(0.5, "#b85d31");
gradient.addColorStop(0.76, "#d58a53");
gradient.addColorStop(1, "#8d4227");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 512, 512);
let seed = 417;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
for (let i = 0; i < 1900; i++) {
const x = Math.floor(random() * 512);
const y = Math.floor(random() * 512);
const length = 4 + Math.floor(random() * 46);
const alpha = 0.025 + random() * 0.085;
ctx.fillStyle =
random() > 0.45
? `rgba(255,196,139,${alpha})`
: `rgba(55,18,8,${alpha})`;
ctx.fillRect(x, y, 1, length);
}
for (let i = 0; i < 130; i++) {
ctx.fillStyle = `rgba(255,211,159,${0.03 + random() * 0.08})`;
ctx.fillRect(
Math.floor(random() * 512),
Math.floor(random() * 512),
2 + Math.floor(random() * 8),
2
);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const copperTexture = makeCopperTexture();
const materials = {
copper: new THREE.MeshStandardMaterial({
map: copperTexture,
color: 0xe0a06f,
metalness: 0.74,
roughness: 0.34
}),
copperDark: new THREE.MeshStandardMaterial({
color: 0x71331e,
metalness: 0.72,
roughness: 0.4
}),
steel: new THREE.MeshStandardMaterial({
color: 0x34444d,
metalness: 0.76,
roughness: 0.32
}),
steelDark: new THREE.MeshStandardMaterial({
color: 0x17232b,
metalness: 0.65,
roughness: 0.42
}),
rail: new THREE.MeshStandardMaterial({
color: 0x9eb4b8,
metalness: 0.92,
roughness: 0.2
}),
north: new THREE.MeshStandardMaterial({
color: 0x9e3f39,
emissive: 0x37100d,
metalness: 0.5,
roughness: 0.48
}),
south: new THREE.MeshStandardMaterial({
color: 0x2f6683,
emissive: 0x092733,
metalness: 0.52,
roughness: 0.46
}),
floor: new THREE.MeshStandardMaterial({
color: 0x0c171e,
metalness: 0.18,
roughness: 0.82
})
};
function addBox(size, position, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...size),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0xdba06d, opacity = 0.8) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
// ---------------------------------------------------------------------
// Labels made entirely from canvas textures and Three.js sprites.
// ---------------------------------------------------------------------
function makeLabel(lines, options = {}) {
const width = options.canvasWidth || 1024;
const lineHeight = options.lineHeight || 49;
const height = lines.length * lineHeight + 38;
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
const radius = 20;
ctx.beginPath();
ctx.moveTo(radius, 2);
ctx.lineTo(width - radius, 2);
ctx.quadraticCurveTo(width - 2, 2, width - 2, radius);
ctx.lineTo(width - 2, height - radius);
ctx.quadraticCurveTo(
width - 2,
height - 2,
width - radius,
height - 2
);
ctx.lineTo(radius, height - 2);
ctx.quadraticCurveTo(2, height - 2, 2, height - radius);
ctx.lineTo(2, radius);
ctx.quadraticCurveTo(2, 2, radius, 2);
ctx.closePath();
ctx.fillStyle = options.background || "rgba(5, 16, 23, 0.84)";
ctx.fill();
ctx.strokeStyle = options.border || "rgba(88, 224, 231, 0.55)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `700 ${options.fontSize || 34}px ui-monospace, monospace`;
lines.forEach((line, index) => {
ctx.fillStyle =
index === 0
? options.color || "#dfffff"
: options.secondaryColor || "#91a8ad";
ctx.fillText(
line,
width / 2,
27 + index * lineHeight
);
});
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
const worldWidth = options.worldWidth || 3;
sprite.scale.set(
worldWidth,
worldWidth * height / width,
1
);
sprite.renderOrder = 30;
return sprite;
}
// ---------------------------------------------------------------------
// Museum floor and lighting.
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 32),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.16;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x31505a, 0x19313a);
grid.position.y = -3.145;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
scene.add(new THREE.HemisphereLight(0xd9f6ff, 0x172028, 1.65));
const keyLight = new THREE.DirectionalLight(0xfff1db, 3.2);
keyLight.position.set(8, 13, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -17;
keyLight.shadow.camera.right = 17;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 42;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x44dce7, 18, 13, 2);
cyanLight.position.set(0, 2.2, 3.6);
scene.add(cyanLight);
const copperLight = new THREE.PointLight(0xff8d4d, 12, 10, 2);
copperLight.position.set(-4.2, 2.6, 3);
scene.add(copperLight);
// ---------------------------------------------------------------------
// Large magnet assembly. The front pole is a cutaway frame so the
// copper face remains exposed to visitors.
// ---------------------------------------------------------------------
const magnet = new THREE.Group();
scene.add(magnet);
const rearPole = addBox(
[5.2, 3.6, 0.85],
[0, 1.35, -1.78],
materials.north,
magnet
);
addEdges(rearPole, 0xd96858, 0.42);
addBox(
[5.2, 0.48, 0.85],
[0, 2.92, 1.78],
materials.south,
magnet
);
addBox(
[5.2, 0.48, 0.85],
[0, -0.22, 1.78],
materials.south,
magnet
);
addBox(
[0.50, 2.65, 0.85],
[-2.35, 1.35, 1.78],
materials.south,
magnet
);
addBox(
[0.50, 2.65, 0.85],
[2.35, 1.35, 1.78],
materials.south,
magnet
);
// Side yoke blocks give the assembly a large, architectural silhouette.
addBox(
[0.56, 3.72, 4.0],
[-2.78, 1.35, 0],
materials.steelDark,
magnet
);
addBox(
[0.56, 3.72, 4.0],
[2.78, 1.35, 0],
materials.steelDark,
magnet
);
addBox(
[5.55, 0.55, 4.0],
[0, 3.25, 0],
materials.steelDark,
magnet
);
addBox(
[5.55, 0.55, 4.0],
[0, -0.55, 0],
materials.steelDark,
magnet
);
// Voxel-like pole-face markers.
for (let x = -2.15; x <= 2.2; x += 0.43) {
addBox(
[0.20, 0.20, 0.10],
[x, 2.92, 2.24],
materials.copper,
magnet
);
addBox(
[0.20, 0.20, 0.10],
[x, -0.22, 2.24],
materials.copper,
magnet
);
}
const northLabel = makeLabel(
["N / REAR POLE", "FIELD LEAVES THIS FACE"],
{
worldWidth: 3.0,
color: "#ffd5ca",
border: "rgba(220, 99, 78, 0.65)"
}
);
northLabel.position.set(-1.8, 3.78, -1.55);
scene.add(northLabel);
const southLabel = makeLabel(
["S / CUTAWAY POLE", "VIEW WINDOW EXPOSES PLATE"],
{
worldWidth: 3.35,
color: "#c9f1ff",
border: "rgba(88, 180, 224, 0.65)"
}
);
southLabel.position.set(2.15, 3.77, 1.7);
scene.add(southLabel);
// ---------------------------------------------------------------------
// Translucent field region and field-direction arrows.
// ---------------------------------------------------------------------
const fieldBounds = {
minX: -2.25,
maxX: 2.25
};
const fieldGeometry = new THREE.BoxGeometry(4.5, 2.7, 3.3);
const fieldVolume = new THREE.Mesh(
fieldGeometry,
new THREE.MeshPhysicalMaterial({
color: 0x44dce7,
transparent: true,
opacity: 0.085,
roughness: 0.2,
metalness: 0,
transmission: 0.12,
side: THREE.DoubleSide,
depthWrite: false
})
);
fieldVolume.position.set(0, 1.35, 0);
fieldVolume.renderOrder = 2;
scene.add(fieldVolume);
const fieldEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(fieldGeometry),
new THREE.LineDashedMaterial({
color: 0x5de8ed,
transparent: true,
opacity: 0.64,
dashSize: 0.18,
gapSize: 0.11
})
);
fieldEdges.position.copy(fieldVolume.position);
fieldEdges.computeLineDistances();
scene.add(fieldEdges);
const fieldArrows = new THREE.Group();
scene.add(fieldArrows);
const fieldArrowMaterialParts = [];
for (const x of [-1.65, 0, 1.65]) {
for (const y of [0.48, 1.92]) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(x, y, -1.35),
2.65,
0x54dfe8,
0.18,
0.13
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.28;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.36;
arrow.cone.material.depthWrite = false;
fieldArrowMaterialParts.push(arrow.line.material, arrow.cone.material);
fieldArrows.add(arrow);
}
}
const fieldLabel = makeLabel(
["FIELD REGION", "B NORMAL TO COPPER FACE"],
{
worldWidth: 3.25,
color: "#c9ffff"
}
);
fieldLabel.position.set(-2.95, 2.88, 0.35);
scene.add(fieldLabel);
// ---------------------------------------------------------------------
// Continuous museum track. Its upper run is the exhibit track; its lower
// run returns beneath the exhibit for another pass.
// ---------------------------------------------------------------------
class MuseumLoopCurve extends THREE.Curve {
constructor() {
super();
this.topY = 1.35;
this.bottomY = -2.55;
this.radius = (this.topY - this.bottomY) * 0.5;
this.middleY = (this.topY + this.bottomY) * 0.5;
this.halfSpan = 8.7;
const lineLength = this.halfSpan * 2;
const arcLength = Math.PI * this.radius;
this.topFraction = lineLength / (lineLength * 2 + arcLength * 2);
this.arcFraction = arcLength / (lineLength * 2 + arcLength * 2);
}
getPoint(t, target = new THREE.Vector3()) {
const {
topY,
bottomY,
radius,
middleY,
halfSpan,
topFraction,
arcFraction
} = this;
if (t < topFraction) {
const u = t / topFraction;
return target.set(
-halfSpan + u * halfSpan * 2,
topY,
0
);
}
if (t < topFraction + arcFraction) {
const u = (t - topFraction) / arcFraction;
const theta = Math.PI / 2 - u * Math.PI;
return target.set(
halfSpan + Math.cos(theta) * radius,
middleY + Math.sin(theta) * radius,
0
);
}
if (t < topFraction * 2 + arcFraction) {
const u =
(t - topFraction - arcFraction) / topFraction;
return target.set(
halfSpan - u * halfSpan * 2,
bottomY,
0
);
}
const u =
(t - topFraction * 2 - arcFraction) / arcFraction;
const theta = -Math.PI / 2 - u * Math.PI;
return target.set(
-halfSpan + Math.cos(theta) * radius,
middleY + Math.sin(theta) * radius,
0
);
}
}
class OffsetCurve extends THREE.Curve {
constructor(baseCurve, zOffset) {
super();
this.baseCurve = baseCurve;
this.zOffset = zOffset;
}
getPoint(t, target = new THREE.Vector3()) {
this.baseCurve.getPoint(t, target);
target.z += this.zOffset;
return target;
}
}
const routeCurve = new MuseumLoopCurve();
const routeLength = routeCurve.getLength();
const railNear = new THREE.Mesh(
new THREE.TubeGeometry(
new OffsetCurve(routeCurve, -0.18),
360,
0.055,
6,
true
),
materials.rail
);
railNear.castShadow = true;
scene.add(railNear);
const railFar = new THREE.Mesh(
new THREE.TubeGeometry(
new OffsetCurve(routeCurve, -0.72),
360,
0.055,
6,
true
),
materials.rail
);
railFar.castShadow = true;
scene.add(railFar);
const tieCount = 36;
const tieGeometry = new THREE.BoxGeometry(0.12, 0.12, 0.72);
const ties = new THREE.InstancedMesh(
tieGeometry,
materials.steelDark,
tieCount
);
ties.receiveShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < tieCount; i++) {
const t = i / tieCount;
const point = routeCurve.getPoint(t);
const tangent = routeCurve.getTangent(t).normalize();
dummy.position.set(point.x, point.y, -0.45);
dummy.quaternion.setFromUnitVectors(X_AXIS, tangent);
dummy.updateMatrix();
ties.setMatrixAt(i, dummy.matrix);
}
scene.add(ties);
const returnLabel = makeLabel(
["LOWER RETURN TRACK", "REPEAT PASS / INSPECTION LEVEL"],
{
worldWidth: 4.7,
color: "#c6d8dc",
border: "rgba(143, 182, 191, 0.42)"
}
);
returnLabel.position.set(0, -3.02, 1.3);
scene.add(returnLabel);
// ---------------------------------------------------------------------
// Copper plate and its local visualization groups.
// Local X is the direction of travel; local Y is vertical; local Z is
// the exposed copper-face normal.
// ---------------------------------------------------------------------
const plateRig = new THREE.Group();
scene.add(plateRig);
const plate = new THREE.Mesh(
new THREE.BoxGeometry(3.1, 2.25, 0.14),
materials.copper
);
plate.castShadow = true;
plate.receiveShadow = true;
plateRig.add(plate);
addEdges(plate, 0xf2b07c, 0.95);
// Darker voxel tabs and fasteners make the face readable.
for (const x of [-1.34, 1.34]) {
for (const y of [-0.91, 0.91]) {
addBox(
[0.085, 0.085, 0.055],
[x, y, 0.095],
materials.copperDark,
plateRig
);
}
}
addBox(
[0.48, 0.15, 0.08],
[0, -1.15, -0.02],
materials.steelDark,
plateRig
);
function createCurrentLoop(leading) {
const group = new THREE.Group();
const opacityMaterials = [];
const centerX = leading ? 1.18 : -1.18;
for (let ring = 0; ring < 2; ring++) {
const rx = 0.34 - ring * 0.075;
const ry = 0.62 - ring * 0.11;
const points = [];
for (let i = 0; i <= 72; i++) {
const theta = (i / 72) * Math.PI * 2;
const x =
centerX + Math.cos(theta) * rx;
const y =
leading
? -Math.sin(theta) * ry
: Math.sin(theta) * ry;
points.push(new THREE.Vector3(x, y, 0.145));
}
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x60f1f1,
transparent: true,
opacity: 0.9,
depthWrite: false
});
opacityMaterials.push(lineMaterial);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
lineMaterial
);
line.renderOrder = 8;
group.add(line);
}
// Directional arrowheads are illustrative current-direction markers.
const arrowAngles = leading ? [0, Math.PI * 0.55] : [Math.PI, Math.PI * 0.45];
for (const theta of arrowAngles) {
const rx = 0.34;
const ry = 0.62;
const point = new THREE.Vector3(
centerX + Math.cos(theta) * rx,
leading
? -Math.sin(theta) * ry
: Math.sin(theta) * ry,
0.17
);
const tangent = new THREE.Vector3(
-Math.sin(theta) * rx,
leading
? -Math.cos(theta) * ry
: Math.cos(theta) * ry,
0
).normalize();
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xb8ffff,
transparent: true,
opacity: 0.95,
depthWrite: false
});
opacityMaterials.push(arrowMaterial);
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.20, 6),
arrowMaterial
);
cone.position.copy(point);
cone.quaternion.setFromUnitVectors(Y_AXIS, tangent);
cone.renderOrder = 9;
group.add(cone);
}
group.userData.opacityMaterials = opacityMaterials;
plateRig.add(group);
return group;
}
const leadingLoop = createCurrentLoop(true);
const trailingLoop = createCurrentLoop(false);
leadingLoop.visible = false;
trailingLoop.visible = false;
const dragGroup = new THREE.Group();
plateRig.add(dragGroup);
const dragMaterials = [];
function addDragArrow(origin, length) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
origin,
length,
0xffad5c,
0.24,
0.14
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.95;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.98;
arrow.cone.material.depthWrite = false;
dragMaterials.push(arrow.line.material, arrow.cone.material);
dragGroup.add(arrow);
}
// These lengths are deliberately constant and schematic.
addDragArrow(new THREE.Vector3(0.75, -0.67, 0.19), 1.28);
addDragArrow(new THREE.Vector3(0.90, 0.35, 0.19), 1.05);
const dragLabel = makeLabel(
["DRAG"],
{
worldWidth: 1.05,
color: "#ffd0a0",
border: "rgba(255, 173, 92, 0.72)",
canvasWidth: 512,
fontSize: 42
}
);
dragLabel.position.set(-0.22, 0.72, 0.22);
dragGroup.add(dragLabel);
const plateLabel = makeLabel(
["COPPER PLATE"],
{
worldWidth: 1.65,
color: "#ffd1a9",
border: "rgba(217, 132, 75, 0.58)",
canvasWidth: 640,
fontSize: 39
}
);
plateLabel.position.set(0, -1.32, 0.18);
plateRig.add(plateLabel);
// A stationary +X arrow establishes the direction of travel.
const motionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-4.9, 2.70, 0.75),
1.45,
0xdff7f7,
0.25,
0.16
);
scene.add(motionArrow);
const motionLabel = makeLabel(
["PLATE MOTION →"],
{
worldWidth: 2.55,
color: "#e8ffff",
border: "rgba(210, 243, 243, 0.4)",
canvasWidth: 700,
fontSize: 39
}
);
motionLabel.position.set(-4.15, 2.96, 0.78);
scene.add(motionLabel);
const schematicLabel = makeLabel(
["SCHEMATIC DRAG ARROWS", "direction only • length is not a calculated force"],
{
worldWidth: 5.8,
color: "#ffd0a0",
secondaryColor: "#beaa94",
border: "rgba(255, 173, 92, 0.68)",
fontSize: 31
}
);
schematicLabel.position.set(0, -1.02, 2.55);
scene.add(schematicLabel);
// ---------------------------------------------------------------------
// Playback and status.
// ---------------------------------------------------------------------
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let playing = !reducedMotion;
let playbackRate = Number(speedInput.value);
let routeU = 0.06;
function updateSpeedUI() {
speedValue.textContent = `×${playbackRate.toFixed(2)}`;
const percent =
((playbackRate - Number(speedInput.min)) /
(Number(speedInput.max) - Number(speedInput.min))) *
100;
speedInput.style.setProperty("--range-fill", `${percent}%`);
}
function updatePlayButton() {
playBtn.textContent = playing ? "Pause" : "Play";
playBtn.classList.toggle("active", !playing);
}
speedInput.addEventListener("input", () => {
playbackRate = Number(speedInput.value);
updateSpeedUI();
});
playBtn.addEventListener("click", () => {
playing = !playing;
updatePlayButton();
});
resetBtn.addEventListener("click", () => {
routeU = 0.06;
leadingLoop.visible = false;
trailingLoop.visible = false;
dragGroup.visible = false;
});
updateSpeedUI();
updatePlayButton();
let previousStatus = "";
let wasLeading = false;
let wasTrailing = false;
let leadingPulse = 0;
let trailingPulse = 0;
const routePoint = new THREE.Vector3();
const routeTangent = new THREE.Vector3();
const leadingWorld = new THREE.Vector3();
const trailingWorld = new THREE.Vector3();
function edgeStrength(edgeX) {
if (
edgeX < fieldBounds.minX ||
edgeX > fieldBounds.maxX
) {
return 0;
}
const distanceInside = Math.min(
edgeX - fieldBounds.minX,
fieldBounds.maxX - edgeX
);
return THREE.MathUtils.smoothstep(distanceInside, 0, 0.34);
}
function setOpacity(group, opacity) {
group.userData.opacityMaterials.forEach((material) => {
material.opacity = opacity;
});
}
function animateExhibit(dt) {
if (playing) {
routeU =
(routeU + (dt * playbackRate * 1.85) / routeLength) % 1;
}
routeCurve.getPointAt(routeU, routePoint);
routeCurve.getTangentAt(routeU, routeTangent).normalize();
plateRig.position.copy(routePoint);
plateRig.quaternion.setFromUnitVectors(X_AXIS, routeTangent);
const onExhibitRun =
routeU < routeCurve.topFraction &&
routeTangent.x > 0.8;
leadingWorld
.set(1.55, 0, 0)
.applyQuaternion(plateRig.quaternion)
.add(plateRig.position);
trailingWorld
.set(-1.55, 0, 0)
.applyQuaternion(plateRig.quaternion)
.add(plateRig.position);
const leadingStrength = onExhibitRun
? edgeStrength(leadingWorld.x)
: 0;
const trailingStrength = onExhibitRun
? edgeStrength(trailingWorld.x)
: 0;
const leadingActive = leadingStrength > 0.008;
const trailingActive = trailingStrength > 0.008;
if (leadingActive && !wasLeading) leadingPulse = 1;
if (trailingActive && !wasTrailing) trailingPulse = 1;
wasLeading = leadingActive;
wasTrailing = trailingActive;
leadingPulse = Math.max(0, leadingPulse - dt * 2.4);
trailingPulse = Math.max(0, trailingPulse - dt * 2.4);
leadingLoop.visible = leadingActive;
trailingLoop.visible = trailingActive;
setOpacity(leadingLoop, leadingStrength);
setOpacity(trailingLoop, trailingStrength);
leadingLoop.scale.setScalar(1 + leadingPulse * 0.075);
trailingLoop.scale.setScalar(1 + trailingPulse * 0.075);
const brakingActive = leadingActive || trailingActive;
dragGroup.visible = brakingActive;
let status;
if (brakingActive) {
status =
leadingActive && trailingActive
? "both edges in field • eddy-current loops"
: leadingActive
? "leading edge crossing field • eddy-current loop"
: "trailing edge crossing field • eddy-current loop";
} else if (onExhibitRun) {
status = "plate clear of field";
} else {
status = "lower return run • awaiting next pass";
}
if (status !== previousStatus) {
statusText.textContent = status;
previousStatus = status;
}
}
// ---------------------------------------------------------------------
// Resize and render loop.
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
function render() {
const dt = Math.min(clock.getDelta(), 0.05);
animateExhibit(dt);
renderer.render(scene, camera);
requestAnimationFrame(render);
}
render();
</script>
</body>
</html>
```