Prompt specification
Build or customize the Three.js 3D scene "Wire-drawing and metal-sheet teaching 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: Wire-drawing and metal-sheet teaching exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wire-drawing-and-metal-sheet-teaching-exhibit-x1959
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Compose a metal wire, sheet, and enlarged lattice inset with separate conductivity and deformation labels; distinguish electrical transport from the mechanical ability to change shape.
Working Three.js Starter (wire-drawing-and-metal-sheet-teaching-exhibit-x1959):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark" />
<title>Voxel Metal Study — Electrical Transport vs. Deformation</title>
<style>
:root {
--bg: #071019;
--panel: rgba(8, 18, 28, 0.86);
--line: rgba(151, 196, 215, 0.2);
--text: #edf8fb;
--muted: #91a8b5;
--charge: #ffc857;
--charge-rgb: 255, 200, 87;
--deform: #55e5ef;
--deform-rgb: 85, 229, 239;
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
--sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: var(--sans);
}
body::before {
content: "";
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
opacity: 0.18;
background:
radial-gradient(circle at 18% 20%, rgba(84, 160, 184, 0.08), transparent 30%),
repeating-linear-gradient(
0deg,
rgba(255, 255, 255, 0.015) 0,
rgba(255, 255, 255, 0.015) 1px,
transparent 1px,
transparent 4px
);
mix-blend-mode: screen;
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#leaders {
position: fixed;
inset: 0;
z-index: 1;
width: 100%;
height: 100%;
pointer-events: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.topbar {
position: absolute;
top: 22px;
left: 28px;
right: 28px;
display: flex;
align-items: center;
justify-content: space-between;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
letter-spacing: 0.08em;
font-family: var(--mono);
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 7px);
grid-template-rows: repeat(3, 7px);
gap: 2px;
transform: rotate(-6deg);
}
.brand-mark i {
display: block;
width: 7px;
height: 7px;
background: var(--deform);
box-shadow: 0 0 12px rgba(var(--deform-rgb), 0.3);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
background: var(--charge);
box-shadow: 0 0 12px rgba(var(--charge-rgb), 0.35);
}
.brand small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 500;
letter-spacing: 0.13em;
}
.live {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(6, 14, 22, 0.6);
color: #bfd0d8;
font: 9px var(--mono);
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--deform);
box-shadow: 0 0 12px var(--deform);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.4;
transform: scale(0.75);
}
}
.intro {
position: absolute;
top: 96px;
left: 30px;
width: 390px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--charge);
font: 10px var(--mono);
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: var(--charge);
box-shadow: 0 0 8px rgba(var(--charge-rgb), 0.55);
}
h1 {
margin: 0;
font-size: clamp(34px, 3.3vw, 56px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 650;
text-shadow: 0 4px 28px rgba(0, 0, 0, 0.38);
}
h1 span {
display: block;
color: #91aab7;
font-weight: 420;
}
.intro-copy {
max-width: 355px;
margin: 17px 0 0;
color: #a5bac5;
font-size: 13px;
line-height: 1.55;
}
.mode-switch {
display: inline-flex;
gap: 3px;
margin-top: 19px;
padding: 4px;
pointer-events: auto;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(7, 17, 27, 0.76);
backdrop-filter: blur(12px);
}
.mode-switch button {
min-width: 72px;
padding: 8px 12px;
border: 0;
border-radius: 5px;
background: transparent;
color: #8fa5b0;
cursor: pointer;
font: 9px var(--mono);
letter-spacing: 0.1em;
text-transform: uppercase;
transition: 160ms ease;
}
.mode-switch button:hover {
color: white;
background: rgba(255, 255, 255, 0.05);
}
.mode-switch button.active {
color: #071019;
background: #dceff3;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.inset-viewport {
position: absolute;
top: 91px;
right: 28px;
width: 420px;
height: 304px;
pointer-events: auto;
touch-action: none;
border: 1px solid rgba(142, 199, 220, 0.26);
border-radius: 10px;
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.38),
inset 0 0 35px rgba(81, 164, 190, 0.04);
}
.inset-heading,
.inset-footer {
position: absolute;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 11px 13px;
background: rgba(6, 14, 23, 0.86);
backdrop-filter: blur(10px);
font-family: var(--mono);
}
.inset-heading {
top: 0;
border-bottom: 1px solid rgba(142, 199, 220, 0.17);
color: #d9e9ee;
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.inset-heading span:last-child {
color: var(--deform);
}
.inset-footer {
bottom: 0;
justify-content: flex-start;
gap: 13px;
border-top: 1px solid rgba(142, 199, 220, 0.17);
color: #91a9b5;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.inset-footer .note {
margin-left: auto;
color: #dce9ed;
}
.dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 5px;
border-radius: 1px;
vertical-align: 1px;
}
.dot.charge {
background: var(--charge);
box-shadow: 0 0 9px rgba(var(--charge-rgb), 0.75);
}
.dot.deform {
background: var(--deform);
box-shadow: 0 0 9px rgba(var(--deform-rgb), 0.75);
}
.callout {
position: absolute;
bottom: 83px;
width: 316px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 9px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 48%),
var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
transition: opacity 180ms ease, border-color 180ms ease;
}
.callout::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
border-radius: 9px 0 0 9px;
}
.callout.conductivity {
left: 28px;
}
.callout.conductivity::before {
background: var(--charge);
box-shadow: 0 0 18px rgba(var(--charge-rgb), 0.45);
}
.callout.deformation {
right: 28px;
}
.callout.deformation::before {
background: var(--deform);
box-shadow: 0 0 18px rgba(var(--deform-rgb), 0.45);
}
.callout.dimmed {
opacity: 0.34;
}
.callout-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font: 9px var(--mono);
letter-spacing: 0.13em;
text-transform: uppercase;
}
.conductivity .callout-top {
color: var(--charge);
}
.deformation .callout-top {
color: var(--deform);
}
.callout-index {
color: #718792;
}
.callout h2 {
margin: 0 0 7px;
font-size: 20px;
line-height: 1.1;
letter-spacing: -0.025em;
font-weight: 620;
}
.callout p {
margin: 0;
color: #9cb1bc;
font-size: 12px;
line-height: 1.5;
}
.mechanism {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid rgba(151, 196, 215, 0.13);
font: 8px var(--mono);
letter-spacing: 0.11em;
text-transform: uppercase;
}
.mechanism span {
color: #718792;
}
.conductivity .mechanism b {
color: var(--charge);
}
.deformation .mechanism b {
color: var(--deform);
}
.hint {
position: absolute;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
white-space: nowrap;
color: #647c88;
font: 9px var(--mono);
letter-spacing: 0.09em;
text-transform: uppercase;
}
.hint b {
color: #a9bec8;
font-weight: 500;
}
@media (max-width: 1080px) {
.intro {
width: 330px;
}
.inset-viewport {
width: 345px;
height: 275px;
}
.callout {
width: 285px;
}
}
@media (max-width: 760px) {
.topbar {
top: 16px;
left: 17px;
right: 17px;
}
.brand small,
.live span {
display: none;
}
.intro {
top: 70px;
left: 18px;
width: calc(100% - 36px);
}
h1 {
font-size: 34px;
}
.intro-copy {
display: none;
}
.mode-switch {
margin-top: 13px;
}
.mode-switch button {
min-width: 60px;
padding: 7px 9px;
}
.inset-viewport {
top: 215px;
right: 16px;
width: 270px;
height: 225px;
}
.inset-footer .note {
display: none;
}
.callout {
bottom: 57px;
width: calc(50vw - 24px);
padding: 12px;
}
.callout.conductivity {
left: 16px;
}
.callout.deformation {
right: 16px;
}
.callout h2 {
font-size: 15px;
}
.callout p,
.mechanism {
display: none;
}
.callout-top {
margin-bottom: 6px;
font-size: 7px;
}
.hint {
bottom: 19px;
width: 90%;
text-align: center;
white-space: normal;
line-height: 1.5;
font-size: 8px;
}
#leaders {
display: none;
}
}
@media (max-height: 620px) {
.intro-copy,
.mode-switch,
.hint {
display: none;
}
.inset-viewport {
top: 66px;
height: 220px;
}
.callout {
bottom: 24px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel metal scene"></canvas>
<svg id="leaders" aria-hidden="true">
<line id="charge-line" stroke="rgba(255,200,87,.62)" stroke-width="1.3" />
<line id="deform-line" stroke="rgba(85,229,239,.62)" stroke-width="1.3" />
<circle id="charge-point" r="4" fill="#ffc857" />
<circle id="deform-point" r="4" fill="#55e5ef" />
</svg>
<main class="ui">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
Material Mechanics / 01
<small>Voxel-scale electrical and mechanical study</small>
</div>
</div>
<div class="live">
<i class="live-dot"></i>
<span>Interactive model</span>
</div>
</header>
<section class="intro">
<div class="eyebrow">Metal / Macro → Micro</div>
<h1>
Electric flow.
<span>Shape change.</span>
</h1>
<p class="intro-copy">
A conductivity-driven current and a stress-driven deformation are
different phenomena. Isolate either mechanism to see how each acts
independently on the metal lattice.
</p>
<div class="mode-switch" aria-label="Isolate a mechanism">
<button class="active" data-mode="both" aria-pressed="true">Both</button>
<button data-mode="current" aria-pressed="false">Charge</button>
<button data-mode="shape" aria-pressed="false">Shape</button>
</div>
</section>
<section class="inset-viewport" id="inset-viewport" aria-label="Enlarged atomic lattice inset">
<div class="inset-heading">
<span>Atomic lattice / enlarged</span>
<span>× 12</span>
</div>
<div class="inset-footer">
<span><i class="dot charge"></i>Carrier drift</span>
<span><i class="dot deform"></i>Plane shift</span>
<span class="note">Movement ≠ rearrangement</span>
</div>
</section>
<section class="callout conductivity" id="conductivity-card">
<div class="callout-top">
<span>01 / Conductivity</span>
<span class="callout-index">e⁻ transport</span>
</div>
<h2>Electrical transport</h2>
<p>
Mobile charge carriers move through an essentially fixed atomic
framework. The current does not require the metal to change shape.
</p>
<div class="mechanism">
<span>Mechanism</span>
<b>Charge carriers move</b>
</div>
</section>
<section class="callout deformation" id="deformation-card">
<div class="callout-top">
<span>02 / Mechanical response</span>
<span class="callout-index">σ loading</span>
</div>
<h2>Deformation</h2>
<p>
Applied stress displaces atomic planes and changes the lattice
geometry. This shape change does not depend on charge transport.
</p>
<div class="mechanism">
<span>Mechanism</span>
<b>Atomic planes rearrange</b>
</div>
</section>
<div class="hint">
<b>Drag</b> orbit · <b>Wheel</b> zoom · <b>Right-drag</b> pan
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and shared settings
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.autoClear = true;
const mainScene = new THREE.Scene();
mainScene.background = new THREE.Color(0x071019);
mainScene.fog = new THREE.FogExp2(0x071019, 0.027);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const insetScene = new THREE.Scene();
const insetCamera = new THREE.PerspectiveCamera(35, 1, 0.1, 30);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
mainScene.add(new THREE.HemisphereLight(0xb9e2ff, 0x101722, 2.1));
const keyLight = new THREE.DirectionalLight(0xffe2b3, 4.2);
keyLight.position.set(-4, 7, 5);
mainScene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58cce5, 3.1);
rimLight.position.set(5, 3, -6);
mainScene.add(rimLight);
const fillLight = new THREE.PointLight(0xffb94f, 18, 13, 2);
fillLight.position.set(-4, 1.3, 1.2);
mainScene.add(fillLight);
insetScene.add(new THREE.HemisphereLight(0xc9edff, 0x111a27, 2.5));
const insetKey = new THREE.DirectionalLight(0xffd49c, 4.5);
insetKey.position.set(-2, 4, 5);
insetScene.add(insetKey);
const insetRim = new THREE.DirectionalLight(0x55e5ef, 3.4);
insetRim.position.set(4, 2, -3);
insetScene.add(insetRim);
// ------------------------------------------------------------
// Floor and technical grid
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x08131d,
metalness: 0.15,
roughness: 0.9,
transparent: true,
opacity: 0.88
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.57;
mainScene.add(floor);
const grid = new THREE.GridHelper(22, 44, 0x2c7182, 0x153342);
grid.position.y = -0.55;
grid.material.transparent = true;
grid.material.opacity = 0.32;
mainScene.add(grid);
// ------------------------------------------------------------
// Voxel metal wire
// ------------------------------------------------------------
const wireCount = 28;
const wireStartX = -4.45;
const wireSpacing = 0.225;
const wireGeometry = new THREE.BoxGeometry(0.208, 0.208, 0.208);
const wireMaterial = new THREE.MeshStandardMaterial({
color: 0xd99a46,
metalness: 0.88,
roughness: 0.23
});
const wire = new THREE.InstancedMesh(wireGeometry, wireMaterial, wireCount);
const dummy = new THREE.Object3D();
const instanceColor = new THREE.Color();
for (let i = 0; i < wireCount; i++) {
dummy.position.set(
wireStartX + i * wireSpacing,
0.04 + Math.sin(i * 0.4) * 0.025,
0.02 + Math.cos(i * 0.32) * 0.035
);
dummy.rotation.set(0, i * 0.018, 0);
dummy.updateMatrix();
wire.setMatrixAt(i, dummy.matrix);
instanceColor.setHSL(0.095, 0.62, 0.51 + (i % 3) * 0.035);
wire.setColorAt(i, instanceColor);
}
wire.instanceMatrix.needsUpdate = true;
wire.instanceColor.needsUpdate = true;
mainScene.add(wire);
const connectorMaterial = new THREE.MeshStandardMaterial({
color: 0x263c49,
metalness: 0.75,
roughness: 0.32
});
for (const x of [-4.62, -1.18]) {
const connector = new THREE.Mesh(
new THREE.BoxGeometry(0.31, 0.31, 0.31),
connectorMaterial
);
connector.position.set(x, 0.04, 0.02);
mainScene.add(connector);
}
// Bright carrier voxels travel over the wire surface.
const currentGroup = new THREE.Group();
const currentGeometry = new THREE.BoxGeometry(0.09, 0.09, 0.09);
const currentMaterial = new THREE.MeshStandardMaterial({
color: 0xffdf76,
emissive: 0xffb600,
emissiveIntensity: 3.4,
metalness: 0.15,
roughness: 0.3
});
const mainCarriers = [];
for (let i = 0; i < 10; i++) {
const carrier = new THREE.Mesh(currentGeometry, currentMaterial);
carrier.userData.phase = i * 0.61;
mainCarriers.push(carrier);
currentGroup.add(carrier);
}
mainScene.add(currentGroup);
const currentArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-4.15, 0.48, 0),
2.95,
0xffc857,
0.22,
0.13
);
currentArrow.line.material.transparent = true;
currentArrow.line.material.opacity = 0.72;
currentArrow.cone.material.transparent = true;
currentArrow.cone.material.opacity = 0.9;
mainScene.add(currentArrow);
// ------------------------------------------------------------
// Voxel sheet and mechanical deformation
// ------------------------------------------------------------
const sheetColumns = 20;
const sheetRows = 13;
const sheetSpacing = 0.205;
const sheetStartX = -0.55;
const sheetStartZ = -1.23;
const sheetCenterX = sheetStartX + ((sheetColumns - 1) * sheetSpacing) / 2;
const sheetCount = sheetColumns * sheetRows;
const sheetGeometry = new THREE.BoxGeometry(0.19, 0.12, 0.19);
const sheetMaterial = new THREE.MeshStandardMaterial({
color: 0x8ba5b3,
metalness: 0.82,
roughness: 0.3
});
const sheet = new THREE.InstancedMesh(sheetGeometry, sheetMaterial, sheetCount);
sheet.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mainScene.add(sheet);
const sheetPositions = [];
for (let row = 0; row < sheetRows; row++) {
for (let column = 0; column < sheetColumns; column++) {
const x = sheetStartX + column * sheetSpacing;
const z = sheetStartZ + row * sheetSpacing;
sheetPositions.push({ x, z, column, row });
const radial = Math.min(
1,
Math.hypot((x - sheetCenterX) / 1.8, z / 1.25)
);
const strain = Math.max(0, 1 - radial);
const color = new THREE.Color(0x809baa).lerp(
new THREE.Color(0x4fcbd7),
strain * 0.72
);
sheet.setColorAt(sheetPositions.length - 1, color);
}
}
sheet.instanceColor.needsUpdate = true;
const undeformedOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(sheetStartX - 0.09, 0.06, sheetStartZ - 0.09),
new THREE.Vector3(sheetStartX + 3.9, 0.06, sheetStartZ - 0.09),
new THREE.Vector3(sheetStartX + 3.9, 0.06, sheetStartZ + 1.32),
new THREE.Vector3(sheetStartX - 0.09, 0.06, sheetStartZ + 1.32),
new THREE.Vector3(sheetStartX - 0.09, 0.06, sheetStartZ - 0.09)
]),
new THREE.LineDashedMaterial({
color: 0x55e5ef,
dashSize: 0.13,
gapSize: 0.09,
transparent: true,
opacity: 0.48
})
);
undeformedOutline.computeLineDistances();
mainScene.add(undeformedOutline);
const loadArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(sheetCenterX, 1.48, 0),
0.95,
0x55e5ef,
0.23,
0.14
);
loadArrow.line.material.transparent = true;
loadArrow.line.material.opacity = 0.84;
loadArrow.cone.material.transparent = true;
loadArrow.cone.material.opacity = 0.95;
mainScene.add(loadArrow);
// ------------------------------------------------------------
// Procedural text sprites
// ------------------------------------------------------------
function makeTextSprite(text, color) {
const spriteCanvas = document.createElement("canvas");
spriteCanvas.width = 512;
spriteCanvas.height = 96;
const context = spriteCanvas.getContext("2d");
context.clearRect(0, 0, 512, 96);
context.fillStyle = "rgba(5, 13, 21, 0.88)";
context.fillRect(0, 0, 512, 96);
context.strokeStyle = color;
context.lineWidth = 3;
context.strokeRect(2, 2, 508, 92);
context.fillStyle = color;
context.font = "600 38px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(spriteCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
})
);
sprite.scale.set(1.45, 0.27, 1);
sprite.renderOrder = 10;
return sprite;
}
const driftLabel = makeTextSprite("e⁻ DRIFT", "#ffc857");
driftLabel.position.set(-2.8, 0.82, 0);
mainScene.add(driftLabel);
const loadLabel = makeTextSprite("σ / LOAD", "#55e5ef");
loadLabel.position.set(sheetCenterX, 1.72, 0);
loadLabel.scale.set(1.1, 0.205, 1);
mainScene.add(loadLabel);
// ------------------------------------------------------------
// Enlarged lattice inset
// ------------------------------------------------------------
const atomGeometry = new THREE.BoxGeometry(0.15, 0.15, 0.15);
const copperAtomMaterial = new THREE.MeshStandardMaterial({
color: 0xc78a49,
metalness: 0.88,
roughness: 0.27
});
const shiftedAtomMaterial = new THREE.MeshStandardMaterial({
color: 0x55e5ef,
emissive: 0x164b55,
emissiveIntensity: 0.7,
metalness: 0.62,
roughness: 0.26
});
const latticeSpacing = 0.29;
const latticeBase = [];
const shiftedPlane = [];
// Two stationary planes remain in their original positions.
for (const yLayer of [0, 2]) {
for (let x = 0; x < 7; x++) {
for (let z = 0; z < 5; z++) {
latticeBase.push(
new THREE.Vector3(
(x - 3) * latticeSpacing,
(yLayer - 1) * latticeSpacing,
(z - 2) * latticeSpacing
)
);
}
}
}
// The middle plane has slipped sideways: mechanical rearrangement.
for (let x = 0; x < 7; x++) {
for (let z = 0; z < 5; z++) {
shiftedPlane.push(
new THREE.Vector3(
(x - 3) * latticeSpacing + 0.2,
0,
(z - 2) * latticeSpacing
)
);
}
}
const baseAtoms = new THREE.InstancedMesh(
atomGeometry,
copperAtomMaterial,
latticeBase.length
);
const shiftedAtoms = new THREE.InstancedMesh(
atomGeometry,
shiftedAtomMaterial,
shiftedPlane.length
);
latticeBase.forEach((position, index) => {
dummy.position.copy(position);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
baseAtoms.setMatrixAt(index, dummy.matrix);
});
shiftedPlane.forEach((position, index) => {
dummy.position.copy(position);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
shiftedAtoms.setMatrixAt(index, dummy.matrix);
});
insetScene.add(baseAtoms, shiftedAtoms);
function addBondSegments(points, color, opacity) {
const segments = [];
const pointMap = new Map();
points.forEach((point) => {
const key = `${point.x.toFixed(3)},${point.y.toFixed(3)},${point.z.toFixed(3)}`;
pointMap.set(key, point);
});
for (const point of points) {
const neighbors = [
[latticeSpacing, 0, 0],
[0, 0, latticeSpacing]
];
for (const [dx, dy, dz] of neighbors) {
const neighbor = point.clone().add(new THREE.Vector3(dx, dy, dz));
const key = `${neighbor.x.toFixed(3)},${neighbor.y.toFixed(3)},${neighbor.z.toFixed(3)}`;
if (pointMap.has(key)) {
segments.push(point.x, point.y, point.z, neighbor.x, neighbor.y, neighbor.z);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(segments, 3)
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
insetScene.add(new THREE.LineSegments(geometry, material));
}
addBondSegments(latticeBase, 0xa77b50, 0.42);
addBondSegments(shiftedPlane, 0x55e5ef, 0.62);
// Vertical links between the stationary outer layers.
const verticalSegments = [];
for (let x = 0; x < 7; x++) {
for (let z = 0; z < 5; z++) {
const lower = new THREE.Vector3(
(x - 3) * latticeSpacing,
-latticeSpacing,
(z - 2) * latticeSpacing
);
const upper = new THREE.Vector3(
(x - 3) * latticeSpacing,
latticeSpacing,
(z - 2) * latticeSpacing
);
verticalSegments.push(
lower.x, lower.y, lower.z,
upper.x, upper.y, upper.z
);
}
}
const verticalGeometry = new THREE.BufferGeometry();
verticalGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(verticalSegments, 3)
);
insetScene.add(
new THREE.LineSegments(
verticalGeometry,
new THREE.LineBasicMaterial({
color: 0x92704e,
transparent: true,
opacity: 0.24
})
)
);
const insetCarriers = [];
const insetCurrentGroup = new THREE.Group();
for (let i = 0; i < 4; i++) {
const carrier = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.09),
currentMaterial
);
carrier.userData.phase = i * 0.72;
insetCarriers.push(carrier);
insetCurrentGroup.add(carrier);
}
insetScene.add(insetCurrentGroup);
const insetSlipArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-0.48, -0.66, 0.78),
0.96,
0x55e5ef,
0.17,
0.1
);
insetScene.add(insetSlipArrow);
// ------------------------------------------------------------
// Custom camera controls: no Three.js addons are used.
// ------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0.12, 0),
theta: 0.72,
phi: 0.98,
radius: window.innerWidth < 760 ? 20.5 : 10.6
};
function updateMainCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateMainCamera();
const mainPointers = new Map();
let mainDragMode = "orbit";
let lastPointerX = 0;
let lastPointerY = 0;
let previousPinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
mainPointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (mainPointers.size === 2) {
const points = [...mainPointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
mainDragMode = "pinch";
} else {
mainDragMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastPointerX = event.clientX;
lastPointerY = event.clientY;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!mainPointers.has(event.pointerId)) return;
mainPointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (mainPointers.size === 2) {
const points = [...mainPointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (previousPinchDistance / distance),
6.8,
24
);
updateMainCamera();
}
previousPinchDistance = distance;
return;
}
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (mainDragMode === "orbit") {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.27,
1.48
);
} else if (mainDragMode === "pan") {
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();
orbit.target
.addScaledVector(right, -dx * orbit.radius * 0.0015)
.addScaledVector(up, dy * orbit.radius * 0.0015);
}
updateMainCamera();
});
function endMainPointer(event) {
mainPointers.delete(event.pointerId);
previousPinchDistance = 0;
mainDragMode = mainPointers.size ? "orbit" : null;
}
canvas.addEventListener("pointerup", endMainPointer);
canvas.addEventListener("pointercancel", endMainPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
6.8,
24
);
updateMainCamera();
},
{ passive: false }
);
// Separate direct controls for the enlarged lattice inset.
const insetOrbit = {
theta: 0.61,
phi: 1.17,
radius: 4.1
};
function updateInsetCamera() {
insetCamera.position.set(
insetOrbit.radius * Math.sin(insetOrbit.phi) * Math.sin(insetOrbit.theta),
insetOrbit.radius * Math.cos(insetOrbit.phi),
insetOrbit.radius * Math.sin(insetOrbit.phi) * Math.cos(insetOrbit.theta)
);
insetCamera.lookAt(0, 0, 0);
}
updateInsetCamera();
const insetElement = document.querySelector("#inset-viewport");
let insetDragging = false;
let insetLastX = 0;
let insetLastY = 0;
insetElement.addEventListener("pointerdown", (event) => {
insetDragging = true;
insetLastX = event.clientX;
insetLastY = event.clientY;
insetElement.setPointerCapture(event.pointerId);
event.stopPropagation();
});
insetElement.addEventListener("pointermove", (event) => {
if (!insetDragging) return;
const dx = event.clientX - insetLastX;
const dy = event.clientY - insetLastY;
insetLastX = event.clientX;
insetLastY = event.clientY;
insetOrbit.theta -= dx * 0.008;
insetOrbit.phi = THREE.MathUtils.clamp(
insetOrbit.phi + dy * 0.007,
0.35,
1.42
);
updateInsetCamera();
});
insetElement.addEventListener("pointerup", () => {
insetDragging = false;
});
insetElement.addEventListener("pointercancel", () => {
insetDragging = false;
});
insetElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
insetOrbit.radius = THREE.MathUtils.clamp(
insetOrbit.radius * Math.exp(event.deltaY * 0.001),
3.2,
6
);
updateInsetCamera();
},
{ passive: false }
);
// Keyboard camera support.
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta += 0.08;
break;
case "ArrowRight":
orbit.theta -= 0.08;
break;
case "ArrowUp":
orbit.phi = Math.max(0.27, orbit.phi - 0.06);
break;
case "ArrowDown":
orbit.phi = Math.min(1.48, orbit.phi + 0.06);
break;
case "+":
case "=":
orbit.radius = Math.max(6.8, orbit.radius - 0.5);
break;
case "-":
orbit.radius = Math.min(24, orbit.radius + 0.5);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateMainCamera();
}
});
// ------------------------------------------------------------
// Mechanism isolation controls
// ------------------------------------------------------------
const conductivityCard = document.querySelector("#conductivity-card");
const deformationCard = document.querySelector("#deformation-card");
const modeButtons = [...document.querySelectorAll("[data-mode]")];
let showCurrent = true;
let showLoad = true;
function setMode(mode) {
showCurrent = mode !== "shape";
showLoad = mode !== "current";
currentGroup.visible = showCurrent;
currentArrow.visible = showCurrent;
driftLabel.visible = showCurrent;
insetCurrentGroup.visible = showCurrent;
loadArrow.visible = showLoad;
loadLabel.visible = showLoad;
undeformedOutline.visible = showLoad;
insetSlipArrow.visible = showLoad;
conductivityCard.classList.toggle("dimmed", !showCurrent);
deformationCard.classList.toggle("dimmed", !showLoad);
modeButtons.forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
// ------------------------------------------------------------
// Leader lines connecting HTML labels to their 3D mechanisms
// ------------------------------------------------------------
const chargeLine = document.querySelector("#charge-line");
const deformLine = document.querySelector("#deform-line");
const chargePoint = document.querySelector("#charge-point");
const deformPoint = document.querySelector("#deform-point");
const svg = document.querySelector("#leaders");
const wireAnchor = new THREE.Vector3(-2.65, 0.16, 0.05);
const sheetAnchor = new THREE.Vector3(sheetCenterX, 0.38, 0.05);
const projected = new THREE.Vector3();
function projectToScreen(position) {
projected.copy(position).project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight
};
}
function updateLeaders() {
const chargeRect = conductivityCard.getBoundingClientRect();
const deformRect = deformationCard.getBoundingClientRect();
const chargeScreen = projectToScreen(wireAnchor);
const deformScreen = projectToScreen(sheetAnchor);
chargeLine.setAttribute("x1", chargeRect.right);
chargeLine.setAttribute("y1", chargeRect.top + chargeRect.height * 0.34);
chargeLine.setAttribute("x2", chargeScreen.x);
chargeLine.setAttribute("y2", chargeScreen.y);
deformLine.setAttribute("x1", deformRect.left);
deformLine.setAttribute("y1", deformRect.top + deformRect.height * 0.34);
deformLine.setAttribute("x2", deformScreen.x);
deformLine.setAttribute("y2", deformScreen.y);
chargePoint.setAttribute("cx", chargeScreen.x);
chargePoint.setAttribute("cy", chargeScreen.y);
deformPoint.setAttribute("cx", deformScreen.x);
deformPoint.setAttribute("cy", deformScreen.y);
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animateSheet(time) {
let index = 0;
for (const position of sheetPositions) {
const normalizedX = (position.x - sheetCenterX) / 1.8;
const normalizedZ = position.z / 1.25;
const sag = -0.48 * Math.exp(
-2.25 * (normalizedX * normalizedX + normalizedZ * normalizedZ)
);
const edgeCurl = 0.035 * normalizedX * normalizedX;
const breathing = showLoad
? Math.sin(time * 1.35) *
0.045 *
Math.exp(-1.9 * (normalizedX * normalizedX + normalizedZ * normalizedZ))
: 0;
const y = 0.05 + sag + edgeCurl + breathing;
dummy.position.set(position.x, y, position.z);
dummy.rotation.set(
0,
0,
normalizedX * (showLoad ? -0.065 : 0)
);
dummy.updateMatrix();
sheet.setMatrixAt(index++, dummy.matrix);
}
sheet.instanceMatrix.needsUpdate = true;
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Charge transport through the main wire.
for (const carrier of mainCarriers) {
const travel = (elapsed * 0.85 + carrier.userData.phase) % 3.08;
carrier.position.set(
-4.28 + travel,
0.17 + Math.sin(elapsed * 4 + carrier.userData.phase) * 0.015,
0.04 + Math.cos(elapsed * 2.2 + carrier.userData.phase) * 0.018
);
carrier.rotation.y += 0.025;
}
// Charge transport in the microscopic lattice.
for (const carrier of insetCarriers) {
const travel = (elapsed * 0.58 + carrier.userData.phase) % 2.5;
carrier.position.set(
-1.25 + travel,
0.03 + Math.sin(elapsed * 3.3 + carrier.userData.phase) * 0.035,
0.78
);
carrier.rotation.x += 0.018;
carrier.rotation.y += 0.022;
}
animateSheet(elapsed);
updateLeaders();
// Main viewport.
renderer.setScissorTest(false);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
renderer.setClearColor(0x071019, 1);
renderer.clear(true, true, true);
renderer.render(mainScene, camera);
// Enlarged lattice inset, rendered as a scissored viewport.
const insetRect = insetElement.getBoundingClientRect();
const insetX = Math.floor(insetRect.left);
const insetY = Math.floor(window.innerHeight - insetRect.bottom);
const insetWidth = Math.floor(insetRect.width);
const insetHeight = Math.floor(insetRect.height);
insetCamera.aspect = insetWidth / insetHeight;
insetCamera.updateProjectionMatrix();
renderer.setScissorTest(true);
renderer.setScissor(insetX, insetY, insetWidth, insetHeight);
renderer.setViewport(insetX, insetY, insetWidth, insetHeight);
renderer.setClearColor(0x07131e, 1);
renderer.clear(true, true, true);
renderer.render(insetScene, insetCamera);
renderer.setScissorTest(false);
}
// ------------------------------------------------------------
// Resize handling
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = width < 760 ? 52 : 38;
camera.updateProjectionMatrix();
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
updateMainCamera();
}
window.addEventListener("resize", resize);
resize();
setMode("both");
animate();
</script>
</body>
</html>
```