Prompt specification
Build or customize the Three.js 3D scene "Washer contact-area comparison" 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: Washer contact-area comparison
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/washer-contact-area-comparison-x0317
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Place identical bolts through soft demonstration panels with and without wide washers; highlight the differing contact footprints while keeping fastener size and panel thickness equal.
Working Three.js Starter (washer-contact-area-comparison-x0317):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Washer Contact Footprint Study</title>
<style>
:root {
--ink: #183b35;
--muted: #64736e;
--paper: #f5f1e8;
--card: rgba(255, 252, 245, 0.9);
--accent: #f06445;
--accent-soft: rgba(240, 100, 69, 0.15);
--green: #285d50;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
position: relative;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.intro,
.spec-card,
.footer,
.world-label {
position: fixed;
z-index: 10;
}
.intro {
top: 28px;
left: 32px;
width: min(440px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 11px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
border-radius: 99px;
background: var(--accent);
}
h1 {
max-width: 420px;
margin: 0;
font-size: clamp(31px, 3.6vw, 54px);
font-weight: 730;
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro p {
max-width: 390px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.equation {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 7px;
margin-top: 18px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.equation span {
padding: 6px 9px;
border: 1px solid rgba(24, 59, 53, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.42);
color: var(--ink);
}
.equation i {
color: var(--accent);
font-style: normal;
}
.spec-card {
top: 28px;
right: 28px;
width: 248px;
padding: 17px 18px;
border: 1px solid rgba(24, 59, 53, 0.11);
border-radius: 18px;
background: var(--card);
box-shadow: 0 16px 45px rgba(39, 62, 56, 0.08);
backdrop-filter: blur(14px);
pointer-events: none;
}
.spec-card h2 {
margin: 0 0 13px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.spec-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 9px 0;
border-top: 1px solid rgba(24, 59, 53, 0.09);
font-size: 12px;
}
.spec-row span:first-child {
color: var(--muted);
}
.spec-row strong {
font-weight: 750;
}
.spec-row .equal {
color: var(--green);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.variable {
margin-top: 11px;
padding: 12px;
border-radius: 12px;
background: var(--accent-soft);
color: #773425;
font-size: 11px;
line-height: 1.45;
}
.variable strong {
display: block;
margin-bottom: 2px;
color: var(--accent);
font-size: 12px;
}
.world-label {
left: 0;
top: 0;
transform: translate(-50%, -50%);
pointer-events: none;
transition: opacity 180ms ease;
will-change: left, top;
}
.panel-label {
min-width: 150px;
padding: 9px 12px;
border: 1px solid rgba(24, 59, 53, 0.12);
border-radius: 12px;
background: rgba(255, 252, 245, 0.91);
box-shadow: 0 9px 28px rgba(39, 62, 56, 0.09);
text-align: center;
backdrop-filter: blur(10px);
}
.panel-label small {
display: block;
margin-bottom: 2px;
color: var(--accent);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel-label strong {
font-size: 12px;
font-weight: 780;
letter-spacing: 0.025em;
}
.contact-label {
min-width: 132px;
padding: 9px 11px;
border: 1px solid rgba(240, 100, 69, 0.55);
border-radius: 11px;
background: rgba(255, 249, 242, 0.95);
box-shadow: 0 9px 26px rgba(96, 55, 42, 0.1);
color: #713426;
backdrop-filter: blur(10px;
}
.contact-label strong {
display: block;
color: var(--accent);
font-size: 14px;
font-weight: 820;
}
.contact-label span {
display: block;
margin-top: 2px;
color: #856255;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.world-label.is-off {
opacity: 0 !important;
}
.footer {
left: 30px;
right: 30px;
bottom: 24px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.legend {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.legend-mark {
position: relative;
width: 30px;
height: 18px;
}
.legend-mark::before {
content: "";
position: absolute;
inset: 2px 4px;
border: 2px solid var(--accent);
border-radius: 50%;
background: var(--accent-soft);
}
.legend-mark::after {
content: "";
position: absolute;
top: 8px;
left: 13px;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--accent);
}
.hint {
margin-left: 12px;
padding-left: 12px;
border-left: 1px solid rgba(24, 59, 53, 0.18);
color: #8a918e;
}
.controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(24, 59, 53, 0.14);
border-radius: 999px;
padding: 10px 14px;
background: rgba(255, 252, 245, 0.88);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 24px rgba(39, 62, 56, 0.06);
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(24, 59, 53, 0.28);
background: #fffdf8;
}
button[aria-pressed="true"] {
border-color: rgba(240, 100, 69, 0.4);
background: #fff3ec;
color: #9a432c;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
gap: 12px;
background: var(--paper);
color: var(--muted);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading::before {
content: "";
width: 34px;
height: 34px;
border: 3px solid rgba(24, 59, 53, 0.12);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 850ms linear infinite;
}
#loading span {
margin-top: 58px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 900px) {
.intro {
top: 20px;
left: 20px;
width: min(360px, calc(100vw - 40px));
}
.intro p {
max-width: 320px;
font-size: 12px;
}
.spec-card {
display: none;
}
.footer {
left: 18px;
right: 18px;
bottom: 16px;
}
.hint {
display: none;
}
}
@media (max-width: 560px) {
.intro h1 {
font-size: 32px;
}
.intro p {
display: none;
}
.equation {
margin-top: 12px;
}
.panel-label {
min-width: 112px;
padding: 7px 8px;
}
.panel-label strong {
font-size: 9px;
}
.contact-label {
min-width: 104px;
padding: 7px 8px;
}
.contact-label strong {
font-size: 12px;
}
.contact-label span {
font-size: 8px;
}
.legend {
display: none;
}
.controls {
width: 100%;
justify-content: flex-end;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D comparison of bolt contact footprints"></canvas>
<header class="intro">
<div class="eyebrow">Load distribution study</div>
<h1>Same bolt.<br />Different footprint.</h1>
<p>
Two identical fasteners pass through equal-thickness soft panels.
The wide washer spreads the same load across a much larger contact area.
</p>
<div class="equation">
<span>M12 bolt</span>
<i>×</i>
<span>30 mm panel</span>
<i>×</i>
<span>Equal load</span>
</div>
</header>
<aside class="spec-card">
<h2>Controlled comparison</h2>
<div class="spec-row">
<span>Fastener</span>
<strong>M12</strong>
</div>
<div class="spec-row">
<span>Panel</span>
<strong>30 mm</strong>
</div>
<div class="spec-row">
<span>Clamp load</span>
<strong>100%</strong>
</div>
<div class="spec-row">
<span>All variables</span>
<strong class="equal">Equal</strong>
</div>
<div class="variable">
<strong>Only variable: washer</strong>
A broad bearing surface replaces concentrated head-to-panel contact.
</div>
</aside>
<div id="left-title" class="world-label panel-label">
<small>Case 01</small>
<strong>DIRECT HEAD CONTACT</strong>
</div>
<div id="right-title" class="world-label panel-label">
<small>Case 02</small>
<strong>WIDE WASHER</strong>
</div>
<div id="left-contact" class="world-label contact-label">
<strong>Ø 24 mm</strong>
<span>Head-to-panel contact</span>
</div>
<div id="right-contact" class="world-label contact-label">
<strong>Ø 48 mm</strong>
<span>Washer bearing area</span>
</div>
<footer class="footer">
<div class="legend">
<span class="legend-mark"></span>
<span>Highlighted loaded footprint</span>
<span class="hint">Drag to orbit · scroll to zoom · double-click to reset</span>
</div>
<div class="controls">
<button id="toggle-highlights" type="button" aria-pressed="true">
Footprints on
</button>
<button id="reset-view" type="button">Reset view</button>
</div>
</footer>
<div id="loading"><span>Loading 3D study</span></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf5f1e8);
scene.fog = new THREE.Fog(0xf5f1e8, 13, 27);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const orbit = {
target: new THREE.Vector3(0, 1.78, 0),
radius: 9.8,
theta: 0.055,
phi: 1.47,
minRadius: 7.1,
maxRadius: 17.5,
defaultRadius: 9.8
};
function updateCamera() {
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);
}
// -------------------------------------------------------------------------
// Lighting and studio environment
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfffbef, 0x8ba59c, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.1);
keyLight.position.set(-4.5, 8.5, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00018;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xc9e8df, 1.65);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffb07b, 22, 15, 2);
warmFill.position.set(-5, 3.5, 5);
scene.add(warmFill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xece7dc,
roughness: 0.98,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const backWall = new THREE.Mesh(
new THREE.PlaneGeometry(35, 18),
new THREE.MeshStandardMaterial({
color: 0xeee9df,
roughness: 1
})
);
backWall.position.set(0, 6, -4.2);
backWall.receiveShadow = true;
scene.add(backWall);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
function makeSoftPanelTexture() {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 256;
textureCanvas.height = 256;
const ctx = textureCanvas.getContext("2d");
ctx.fillStyle = "#c7ddd2";
ctx.fillRect(0, 0, 256, 256);
let seed = 17;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
for (let i = 0; i < 1300; i++) {
const x = random() * 256;
const y = random() * 256;
const radius = 0.25 + random() * 0.8;
ctx.fillStyle = random() > 0.55
? "rgba(255,255,255,0.16)"
: "rgba(53,94,80,0.07)";
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.6, 2.8);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const panelMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
map: makeSoftPanelTexture(),
roughness: 0.9,
metalness: 0,
sheen: 0.35,
sheenColor: new THREE.Color(0xeafff6),
sheenRoughness: 0.88
});
const boltMaterial = new THREE.MeshPhysicalMaterial({
color: 0x3b4d57,
metalness: 0.86,
roughness: 0.24,
clearcoat: 0.18,
clearcoatRoughness: 0.3
});
const threadMaterial = new THREE.MeshStandardMaterial({
color: 0x263840,
metalness: 0.88,
roughness: 0.31
});
const washerMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd9a45d,
metalness: 0.72,
roughness: 0.27,
clearcoat: 0.12
});
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x244c42,
roughness: 0.66,
metalness: 0.05
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x172b28,
roughness: 0.9
});
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function roundedBoxGeometry(width, height, depth, radius, segments = 12) {
const geometry = new THREE.BoxGeometry(
width,
height,
depth,
segments,
segments,
segments
);
const position = geometry.attributes.position;
const point = new THREE.Vector3();
const clamped = new THREE.Vector3();
const direction = new THREE.Vector3();
const half = new THREE.Vector3(
width / 2,
height / 2,
depth / 2
);
const inner = new THREE.Vector3(
half.x - radius,
half.y - radius,
half.z - radius
);
for (let i = 0; i < position.count; i++) {
point.fromBufferAttribute(position, i);
clamped.set(
THREE.MathUtils.clamp(point.x, -inner.x, inner.x),
THREE.MathUtils.clamp(point.y, -inner.y, inner.y),
THREE.MathUtils.clamp(point.z, -inner.z, inner.z)
);
direction.copy(point).sub(clamped);
if (direction.lengthSq() > 0.0000001) {
direction.normalize();
point.copy(clamped).addScaledVector(direction, radius);
}
position.setXYZ(i, point.x, point.y, point.z);
}
position.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
function makeSoftPanelGeometry(wideWasher) {
const geometry = roundedBoxGeometry(3, 3.2, 0.34, 0.16, 20);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
const z = position.getZ(i);
const distance = Math.hypot(x, y);
// Only deform the front surface. Nominal panel thickness remains equal.
if (z > 0.08) {
if (wideWasher) {
// Broad, shallow compression plus a subtle displaced ring.
const compression =
0.027 * Math.exp(-Math.pow(distance / 0.58, 4));
const bulge =
0.018 * Math.exp(-Math.pow((distance - 0.82) / 0.17, 2));
position.setZ(i, z - compression + bulge);
} else {
// Concentrated indentation below the bolt head.
const indentation =
0.055 * Math.exp(-Math.pow(distance / 0.29, 4));
position.setZ(i, z - indentation);
}
}
}
position.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
function annulusGeometry(outerRadius, innerRadius, depth) {
const shape = new THREE.Shape();
shape.absarc(0, 0, outerRadius, 0, Math.PI * 2, false);
const hole = new THREE.Path();
hole.absarc(0, 0, innerRadius, 0, Math.PI * 2, true);
shape.holes.push(hole);
return new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 64,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.014,
bevelThickness: 0.014
});
}
function axialCylinder(radius, length, material, radialSegments = 48) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeRoundedOutline(width, height, radius, y, z) {
const shape = new THREE.Shape();
const halfWidth = width / 2;
const halfHeight = height / 2;
shape.moveTo(-halfWidth + radius, -halfHeight);
shape.lineTo(halfWidth - radius, -halfHeight);
shape.quadraticCurveTo(halfWidth, -halfHeight, halfWidth, -halfHeight + radius);
shape.lineTo(halfWidth, halfHeight - radius);
shape.quadraticCurveTo(halfWidth, halfHeight, halfWidth - radius, halfHeight);
shape.lineTo(-halfWidth + radius, halfHeight);
shape.quadraticCurveTo(-halfWidth, halfHeight, -halfWidth, halfHeight - radius);
shape.lineTo(-halfWidth, -halfHeight + radius);
shape.quadraticCurveTo(-halfWidth, -halfHeight, -halfWidth + radius, -halfHeight);
const points = shape.getPoints(14).map(
(point) => new THREE.Vector3(point.x, point.y + y, z)
);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0x4c7b6d,
transparent: true,
opacity: 0.36
});
return new THREE.LineLoop(geometry, material);
}
// -------------------------------------------------------------------------
// Experiment construction
// -------------------------------------------------------------------------
const pulseMaterials = [];
const highlightGroups = [];
function buildExperiment(xPosition, wideWasher) {
const group = new THREE.Group();
group.position.x = xPosition;
scene.add(group);
const panelCenterY = 2.05;
const nominalFront = 0.17;
// Demo base and rear supports.
const base = new THREE.Mesh(
roundedBoxGeometry(3.42, 0.18, 1.5, 0.09, 8),
standMaterial
);
base.position.set(0, 0.09, -0.05);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
for (const side of [-1, 1]) {
const foot = new THREE.Mesh(
roundedBoxGeometry(0.18, 0.8, 0.2, 0.055, 6),
standMaterial
);
foot.position.set(side * 1.08, 0.42, -0.36);
foot.castShadow = true;
group.add(foot);
const rail = new THREE.Mesh(
roundedBoxGeometry(0.12, 2.45, 0.14, 0.045, 6),
standMaterial
);
rail.position.set(side * 1.12, 1.87, -0.39);
rail.castShadow = true;
group.add(rail);
}
// Equal nominal dimensions: 3.0 × 3.2 × 0.34 scene units.
const panel = new THREE.Mesh(
makeSoftPanelGeometry(wideWasher),
panelMaterial
);
panel.position.y = panelCenterY;
panel.castShadow = true;
panel.receiveShadow = true;
group.add(panel);
group.add(
makeRoundedOutline(2.74, 2.94, 0.13, panelCenterY, 0.176)
);
// A dark opening remains visible through the washer hole.
const opening = new THREE.Mesh(
new THREE.CircleGeometry(0.145, 48),
darkMaterial
);
opening.position.set(0, panelCenterY, 0.178);
group.add(opening);
// The same bolt geometry is used in both experiments.
const shaft = axialCylinder(0.125, 1.2, boltMaterial, 48);
shaft.position.set(0, panelCenterY, -0.25);
group.add(shaft);
const nut = axialCylinder(0.255, 0.22, boltMaterial, 6);
nut.position.set(0, panelCenterY, -0.285);
group.add(nut);
// Visible thread ridges on the rear shaft.
for (let i = 0; i < 8; i++) {
const thread = new THREE.Mesh(
new THREE.TorusGeometry(0.126, 0.019, 7, 32),
threadMaterial
);
thread.position.set(0, panelCenterY, -0.46 - i * 0.043);
thread.castShadow = true;
group.add(thread);
}
let headBottom;
let headCenter;
if (wideWasher) {
// Wide annular washer: 48 mm illustrative outside diameter.
const washer = new THREE.Mesh(
annulusGeometry(0.7, 0.15, 0.09),
washerMaterial
);
washer.position.set(0, panelCenterY, 0.145);
washer.castShadow = true;
washer.receiveShadow = true;
group.add(washer);
headBottom = 0.235;
} else {
// The head sits directly against the locally compressed panel.
headBottom = 0.115;
}
headCenter = headBottom + 0.14;
const head = axialCylinder(0.35, 0.28, boltMaterial, 6);
head.position.set(0, panelCenterY, headCenter);
group.add(head);
// Contact-footprint visualization.
const highlightGroup = new THREE.Group();
group.add(highlightGroup);
highlightGroups.push(highlightGroup);
const accent = 0xf06445;
const footprintMaterial = new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: wideWasher ? 0.14 : 0.19,
side: THREE.DoubleSide,
depthWrite: false,
depthTest: false
});
const ringMaterial = new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.94,
side: THREE.DoubleSide,
depthWrite: false,
depthTest: false
});
pulseMaterials.push(
{ material: footprintMaterial, base: footprintMaterial.opacity },
{ material: ringMaterial, base: ringMaterial.opacity }
);
if (wideWasher) {
const footprint = new THREE.Mesh(
new THREE.RingGeometry(0.15, 0.7, 80),
footprintMaterial
);
footprint.position.set(0, panelCenterY, 0.255);
footprint.renderOrder = 90;
highlightGroup.add(footprint);
const outline = new THREE.Mesh(
new THREE.RingGeometry(0.7, 0.77, 80),
ringMaterial
);
outline.position.set(0, panelCenterY, 0.257);
outline.renderOrder = 91;
highlightGroup.add(outline);
} else {
const footprint = new THREE.Mesh(
new THREE.CircleGeometry(0.35, 80),
footprintMaterial
);
footprint.position.set(0, panelCenterY, 0.282);
footprint.renderOrder = 90;
highlightGroup.add(footprint);
const outline = new THREE.Mesh(
new THREE.RingGeometry(0.35, 0.42, 80),
ringMaterial
);
outline.position.set(0, panelCenterY, 0.284);
outline.renderOrder = 91;
highlightGroup.add(outline);
}
// Four cardinal ticks make the measured footprint easy to recognize.
const tickRadius = wideWasher ? 0.75 : 0.405;
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.024, 0.012),
ringMaterial
);
tick.position.set(
Math.cos(angle) * tickRadius,
panelCenterY + Math.sin(angle) * tickRadius,
0.258
);
tick.rotation.z = angle;
tick.renderOrder = 92;
highlightGroup.add(tick);
}
// Leader lines to the projected HTML callouts.
const leaderMaterial = new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.72
});
const leaderPoints = wideWasher
? [
new THREE.Vector3(0.74, panelCenterY, 0.26),
new THREE.Vector3(1.12, panelCenterY + 0.26, 0.34),
new THREE.Vector3(1.67, panelCenterY + 0.48, 0.38)
]
: [
new THREE.Vector3(-0.39, panelCenterY, 0.285),
new THREE.Vector3(-1.05, panelCenterY + 0.28, 0.36),
new THREE.Vector3(-1.67, panelCenterY + 0.48, 0.38)
];
const leader = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(leaderPoints),
leaderMaterial
);
leader.renderOrder = 80;
highlightGroup.add(leader);
const leaderDot = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 16, 12),
new THREE.MeshBasicMaterial({
color: accent,
depthTest: false
})
);
leaderDot.position.copy(leaderPoints[leaderPoints.length - 1]);
leaderDot.renderOrder = 95;
highlightGroup.add(leaderDot);
return {
group,
titleAnchor: new THREE.Vector3(0, 3.92, 0.08),
contactAnchor: leaderPoints[leaderPoints.length - 1].clone()
};
}
const leftExperiment = buildExperiment(-1.85, false);
const rightExperiment = buildExperiment(1.85, true);
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelBindings = [
{
element: document.querySelector("#left-title"),
experiment: leftExperiment,
type: "title"
},
{
element: document.querySelector("#right-title"),
experiment: rightExperiment,
type: "title"
},
{
element: document.querySelector("#left-contact"),
experiment: leftExperiment,
type: "contact"
},
{
element: document.querySelector("#right-contact"),
experiment: rightExperiment,
type: "contact"
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const binding of labelBindings) {
const localAnchor =
binding.type === "title"
? binding.experiment.titleAnchor
: binding.experiment.contactAnchor;
const worldPosition = binding.experiment.group.localToWorld(
localAnchor.clone()
);
const projected = worldPosition.project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -100 &&
x < width + 100 &&
y > -80 &&
y < height + 80;
binding.element.style.left = `${x}px`;
binding.element.style.top = `${y}px`;
binding.element.style.visibility = visible ? "visible" : "hidden";
}
}
// -------------------------------------------------------------------------
// Direct camera controls: no addons or external control libraries
// -------------------------------------------------------------------------
const pointers = new Map();
let singlePointerPrevious = null;
let previousPinchDistance = null;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
singlePointerPrevious = {
x: event.clientX,
y: event.clientY
};
} else {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && singlePointerPrevious) {
const dx = event.clientX - singlePointerPrevious.x;
const dy = event.clientY - singlePointerPrevious.y;
orbit.theta -= dx * 0.0052;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.0045,
0.83,
1.72
);
singlePointerPrevious = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance && distance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (previousPinchDistance / distance),
orbit.minRadius,
orbit.maxRadius
);
}
previousPinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
singlePointerPrevious = null;
previousPinchDistance = null;
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener("lostpointercapture", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
orbit.minRadius,
orbit.maxRadius
);
},
{ passive: false }
);
function resetView() {
orbit.radius = orbit.defaultRadius;
orbit.theta = 0.055;
orbit.phi = 1.47;
orbit.target.set(0, 1.78, 0);
}
canvas.addEventListener("dblclick", resetView);
document.querySelector("#reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") orbit.theta -= 0.06;
if (key === "arrowright") orbit.theta += 0.06;
if (key === "arrowup") orbit.phi = Math.max(0.83, orbit.phi - 0.05);
if (key === "arrowdown") orbit.phi = Math.min(1.72, orbit.phi + 0.05);
if (key === "+" || key === "=") {
orbit.radius = Math.max(orbit.minRadius, orbit.radius - 0.5);
}
if (key === "-") {
orbit.radius = Math.min(orbit.maxRadius, orbit.radius + 0.5);
}
if (key === "r") resetView();
});
let highlightsVisible = true;
const highlightButton = document.querySelector("#toggle-highlights");
highlightButton.addEventListener("click", () => {
highlightsVisible = !highlightsVisible;
for (const highlightGroup of highlightGroups) {
highlightGroup.visible = highlightsVisible;
}
for (const binding of labelBindings) {
if (binding.type === "contact") {
binding.element.classList.toggle("is-off", !highlightsVisible);
}
}
highlightButton.setAttribute("aria-pressed", String(highlightsVisible));
highlightButton.textContent = highlightsVisible
? "Footprints on"
: "Footprints off";
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
if (camera.aspect < 0.8) {
camera.fov = 44;
orbit.defaultRadius = 15.4;
} else if (camera.aspect < 1.25) {
camera.fov = 42;
orbit.defaultRadius = 11.6;
} else {
camera.fov = 40;
orbit.defaultRadius = 9.8;
}
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reduceMotion) {
pulseMaterials.forEach(({ material, base }, index) => {
const pulse = 0.9 + Math.sin(elapsed * 2.1 + index * 0.7) * 0.1;
material.opacity = base * pulse;
});
}
updateCamera();
scene.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
const loading = document.querySelector("#loading");
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 320);
});
</script>
</body>
</html>
```