Prompt specification
Build or customize the Three.js 3D scene "Correct and mismatched driver test" 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: Correct and mismatched driver test
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/correct-and-mismatched-driver-test-x0302
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: correct and mismatched driver test. Rotate a matching bit inside a screwhead while an incompatible bit visibly fails to seat; emphasize geometric contact without modeling damage or prescribing tool forces. Return one self-contained HTML file.
Working Three.js Starter (correct-and-mismatched-driver-test-x0302):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Driver Fit — Correct and Mismatched Test</title>
<style>
:root {
color-scheme: dark;
--bg: #101827;
--panel: rgba(17, 27, 43, 0.82);
--line: rgba(255, 255, 255, 0.12);
--text: #f4f2eb;
--muted: #aeb9c8;
--green: #64e6b4;
--amber: #ffb45c;
--orange: #f28a48;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
max-width: 570px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #d5dce6;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 10px;
height: 10px;
background: var(--orange);
box-shadow: 0 0 20px rgba(242, 138, 72, 0.45);
}
h1 {
margin: 0;
font-size: clamp(28px, 4.2vw, 54px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.045em;
}
.hero p {
max-width: 520px;
margin: 13px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.mode-badge {
position: fixed;
z-index: 6;
top: 27px;
right: 28px;
min-width: 190px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.18);
pointer-events: none;
}
.mode-badge span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.mode-badge strong {
color: var(--green);
font-size: 13px;
letter-spacing: 0.02em;
}
.world-label {
position: fixed;
z-index: 4;
min-width: 156px;
padding: 9px 12px 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(13, 21, 34, 0.88);
backdrop-filter: blur(12px);
box-shadow: 0 14px 36px rgba(0, 0, 0, 0.24);
transform: translate(-50%, -100%);
pointer-events: none;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 19px;
background: currentColor;
opacity: 0.55;
}
.world-label.ok {
color: var(--green);
}
.world-label.stop {
color: var(--amber);
}
.world-label strong {
display: block;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 3px;
color: #c6cfda;
font-size: 10px;
white-space: nowrap;
}
.summary {
position: fixed;
z-index: 6;
left: 24px;
bottom: 24px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
width: min(610px, calc(100vw - 300px));
pointer-events: none;
}
.summary-card {
min-height: 88px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.18);
}
.summary-card .kicker {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.summary-card .kicker::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.summary-card.ok .kicker {
color: var(--green);
}
.summary-card.stop .kicker {
color: var(--amber);
}
.summary-card b {
display: block;
margin-bottom: 4px;
color: var(--text);
font-size: 14px;
letter-spacing: -0.01em;
}
.summary-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.summary-note {
grid-column: 1 / -1;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(13, 21, 34, 0.72);
color: #aeb9c8;
font-size: 10px;
line-height: 1.45;
backdrop-filter: blur(12px);
}
.summary-note strong {
color: #eef2f6;
}
.controls {
position: fixed;
z-index: 7;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.18);
}
.hint {
padding: 0 10px;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.07);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 720;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.22);
}
button:active {
transform: translateY(1px);
}
button:focus-visible {
outline: 2px solid var(--green);
outline-offset: 2px;
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 18px;
right: 18px;
}
.hero p {
max-width: 390px;
font-size: 12px;
}
.mode-badge {
display: none;
}
.world-label {
min-width: 112px;
padding: 7px 9px;
}
.world-label strong {
font-size: 9px;
}
.world-label small {
display: none;
}
.summary {
left: 12px;
right: 12px;
bottom: 68px;
width: auto;
gap: 7px;
}
.summary-card {
min-height: 74px;
padding: 10px;
}
.summary-card b {
font-size: 12px;
}
.summary-card p {
font-size: 9px;
}
.summary-note {
padding: 7px 9px;
font-size: 9px;
}
.controls {
left: 12px;
right: 12px;
bottom: 12px;
justify-content: center;
}
.hint {
margin-right: auto;
padding-left: 5px;
}
}
</style>
</head>
<body>
<main id="app">
<canvas
id="scene"
aria-label="Low-poly comparison of a correctly seated rotating driver bit and an oversized mismatched bit stopped at the screwhead rim"
></canvas>
<header class="hero">
<div class="eyebrow">Mechanical fit study / 01</div>
<h1>Driver fit,<br>side by side.</h1>
<p>
A matching drive seats inside the socket and rotates. An oversized,
incompatible profile meets the screwhead rim before it can reach the floor.
</p>
</header>
<aside class="mode-badge">
<span>Simulation scope</span>
<strong>Geometry only · no force model</strong>
</aside>
<div id="leftLabel" class="world-label ok">
<strong>01 / Matched</strong>
<small>Seated depth · rotating drive</small>
</div>
<div id="rightLabel" class="world-label stop">
<strong>02 / Mismatched</strong>
<small>Rim contact · no seating depth</small>
</div>
<section class="summary" aria-label="Comparison details">
<article class="summary-card ok">
<div class="kicker">Correct profile</div>
<b>Full seat, then rotation</b>
<p>The faceted round drive clears the bore and reaches the socket floor.</p>
</article>
<article class="summary-card stop">
<div class="kicker">Incorrect profile</div>
<b>Rim contact, zero seat</b>
<p>The oversized hex drive meets the screwhead before entering the bore.</p>
</article>
<div class="summary-note">
<strong>Contact is shown as a geometric state only.</strong>
No damage, torque, or prescribed tool forces are modeled.
</div>
</section>
<nav class="controls" aria-label="Scene controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="pauseButton" type="button">Pause</button>
<button id="resetButton" type="button">Reset test</button>
</nav>
</main>
<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.getElementById("scene");
const leftLabel = document.getElementById("leftLabel");
const rightLabel = document.getElementById("rightLabel");
const pauseButton = document.getElementById("pauseButton");
const resetButton = document.getElementById("resetButton");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101827);
scene.fog = new THREE.Fog(0x101827, 10, 20);
const camera = new THREE.OrthographicCamera(-4, 4, 2.5, -2.5, 0.1, 40);
const target = new THREE.Vector3(0, 0.9, 0);
const hemisphere = new THREE.HemisphereLight(0xdceaff, 0x202839, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d5, 3.4);
keyLight.position.set(-3.8, 7.5, 5.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x75c9ff, 1.55);
rimLight.position.set(5, 3.5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9b5e, 22, 10, 2);
warmLight.position.set(-2.4, 3.8, 3.1);
scene.add(warmLight);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x121c2c,
roughness: 1,
metalness: 0,
flatShading: true
}),
base: new THREE.MeshStandardMaterial({
color: 0x26364a,
roughness: 0.72,
metalness: 0.18,
flatShading: true
}),
baseTop: new THREE.MeshStandardMaterial({
color: 0xd9d5ca,
roughness: 0.88,
metalness: 0.03,
flatShading: true
}),
head: new THREE.MeshStandardMaterial({
color: 0x91a1aa,
roughness: 0.3,
metalness: 0.68,
flatShading: true
}),
cavity: new THREE.MeshStandardMaterial({
color: 0x17212b,
roughness: 0.6,
metalness: 0.38,
side: THREE.DoubleSide,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0xc7d0d3,
roughness: 0.25,
metalness: 0.78,
flatShading: true
}),
steelDark: new THREE.MeshStandardMaterial({
color: 0x53616a,
roughness: 0.36,
metalness: 0.7,
flatShading: true
}),
matchedHandle: new THREE.MeshStandardMaterial({
color: 0xee8741,
roughness: 0.5,
metalness: 0.18,
flatShading: true
}),
matchedCap: new THREE.MeshStandardMaterial({
color: 0xb64e27,
roughness: 0.56,
metalness: 0.2,
flatShading: true
}),
mismatchHandle: new THREE.MeshStandardMaterial({
color: 0xe45f4d,
roughness: 0.5,
metalness: 0.18,
flatShading: true
}),
mismatchCap: new THREE.MeshStandardMaterial({
color: 0xa83a36,
roughness: 0.56,
metalness: 0.2,
flatShading: true
}),
stripe: new THREE.MeshStandardMaterial({
color: 0xf5f1e8,
roughness: 0.55,
metalness: 0.05,
flatShading: true
})
};
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.012;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x3b536d, 0x263b52);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.15;
grid.material.depthWrite = false;
scene.add(grid);
const HEAD_TOP = 0.80;
const FLOOR = 0.50;
const BORE_RADIUS = 0.455;
function makeAnnulus(outerRadius, innerRadius, segments) {
const shape = new THREE.Shape();
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const x = Math.cos(angle) * outerRadius;
const y = Math.sin(angle) * outerRadius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
const hole = new THREE.Path();
for (let i = segments; i >= 0; i--) {
const angle = (i / segments) * Math.PI * 2;
const x = Math.cos(angle) * innerRadius;
const y = Math.sin(angle) * innerRadius;
if (i === segments) hole.moveTo(x, y);
else hole.lineTo(x, y);
}
hole.closePath();
shape.holes.push(hole);
const geometry = new THREE.ShapeGeometry(shape);
geometry.rotateX(-Math.PI / 2);
return geometry;
}
function makeCircleLine(radius, y, color, opacity = 1) {
const points = [];
for (let i = 0; i <= 64; i++) {
const angle = (i / 64) * Math.PI * 2;
points.push(new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
return new THREE.Line(geometry, material);
}
function makeFlatTorus(radius, tube, color, opacity = 1) {
const geometry = new THREE.TorusGeometry(radius, tube, 4, 32);
geometry.rotateX(Math.PI / 2);
const material = new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity,
depthWrite: false
});
return new THREE.Mesh(geometry, material);
}
function createStation(x, accent, isMatched) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const lowerBase = new THREE.Mesh(
new THREE.BoxGeometry(2.25, 0.30, 2.02),
materials.base
);
lowerBase.position.y = 0.15;
lowerBase.castShadow = true;
lowerBase.receiveShadow = true;
group.add(lowerBase);
const upperBase = new THREE.Mesh(
new THREE.BoxGeometry(2.10, 0.16, 1.87),
materials.baseTop
);
upperBase.position.y = 0.38;
upperBase.castShadow = true;
upperBase.receiveShadow = true;
group.add(upperBase);
const inset = new THREE.Mesh(
new THREE.BoxGeometry(1.67, 0.035, 1.46),
materials.base
);
inset.position.y = 0.477;
inset.receiveShadow = true;
group.add(inset);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.57, 0.63, 0.09, 12),
materials.steelDark
);
neck.position.y = 0.505;
neck.castShadow = true;
group.add(neck);
const headHeight = HEAD_TOP - FLOOR;
const headCenter = (HEAD_TOP + FLOOR) * 0.5;
const outerWall = new THREE.Mesh(
new THREE.CylinderGeometry(0.78, 0.78, headHeight, 24, 1, true),
materials.head
);
outerWall.position.y = headCenter;
outerWall.castShadow = true;
group.add(outerWall);
const top = new THREE.Mesh(
makeAnnulus(0.78, BORE_RADIUS, 48),
materials.head
);
top.position.y = HEAD_TOP + 0.001;
top.castShadow = true;
top.receiveShadow = true;
group.add(top);
const innerWall = new THREE.Mesh(
new THREE.CylinderGeometry(
BORE_RADIUS,
BORE_RADIUS,
headHeight + 0.005,
32,
1,
true
),
materials.cavity
);
innerWall.position.y = headCenter;
innerWall.receiveShadow = true;
group.add(innerWall);
const socketFloor = new THREE.Mesh(
new THREE.CylinderGeometry(BORE_RADIUS, BORE_RADIUS, 0.02, 32),
materials.cavity
);
socketFloor.position.y = FLOOR - 0.01;
socketFloor.receiveShadow = true;
group.add(socketFloor);
const edgeRing = makeFlatTorus(0.735, 0.018, 0xdbe3e5, 0.48);
edgeRing.position.y = 0.66;
group.add(edgeRing);
const mouthRing = makeCircleLine(BORE_RADIUS, HEAD_TOP + 0.008, accent, 0.9);
group.add(mouthRing);
const halo = makeFlatTorus(0.505, 0.014, accent, 0.8);
halo.position.y = HEAD_TOP + 0.018;
group.add(halo);
const dotGeometry = new THREE.SphereGeometry(0.018, 6, 4);
const dotMaterial = new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: isMatched ? 0.95 : 0,
depthWrite: false
});
const dotRadius = isMatched ? 0.443 : 0.51;
const dotY = isMatched ? FLOOR + 0.018 : HEAD_TOP + 0.025;
const dotCount = isMatched ? 12 : 6;
for (let i = 0; i < dotCount; i++) {
const angle = (i / dotCount) * Math.PI * 2;
const dot = new THREE.Mesh(dotGeometry, dotMaterial.clone());
dot.position.set(
Math.cos(angle) * dotRadius,
dotY,
Math.sin(angle) * dotRadius
);
dot.userData.baseOpacity = dot.material.opacity;
group.add(dot);
}
for (const sx of [-0.82, 0.82]) {
for (const sz of [-0.65, 0.65]) {
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.028, 8),
materials.steelDark
);
bolt.position.set(sx, 0.482, sz);
bolt.castShadow = true;
group.add(bolt);
}
}
return { group, halo, mouthRing };
}
function createDriver(x, matched) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const tipRadius = matched ? 0.447 : 0.62;
const tipSegments = matched ? 16 : 6;
const tipBottom = matched ? FLOOR + 0.003 : HEAD_TOP + 0.003;
const tipTop = matched ? HEAD_TOP : 1.00;
const tipHeight = tipTop - tipBottom;
const tipGeometry = new THREE.CylinderGeometry(
tipRadius,
tipRadius,
tipHeight,
tipSegments
);
const tip = new THREE.Mesh(tipGeometry, materials.steel);
tip.position.y = (tipTop + tipBottom) * 0.5;
tip.castShadow = true;
tip.receiveShadow = true;
group.add(tip);
const edgeMaterial = new THREE.LineBasicMaterial({
color: matched ? 0xf0f6f6 : 0x4f5c63,
transparent: true,
opacity: matched ? 0.28 : 0.45
});
const tipEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(tipGeometry, 20),
edgeMaterial
);
tipEdges.position.copy(tip.position);
group.add(tipEdges);
const shaftBottom = matched ? 0.79 : 0.98;
const shaftTop = matched ? 1.43 : 1.58;
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(
0.15,
0.15,
shaftTop - shaftBottom,
12
),
materials.steel
);
shaft.position.y = (shaftTop + shaftBottom) * 0.5;
shaft.castShadow = true;
group.add(shaft);
const collarY = matched ? 0.86 : 1.045;
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.24, 0.14, 12),
materials.steelDark
);
collar.position.y = collarY;
collar.castShadow = true;
group.add(collar);
const handleBottom = matched ? 0.99 : 1.12;
const handleTop = matched ? 1.71 : 1.84;
const handle = new THREE.Mesh(
new THREE.CylinderGeometry(
0.33,
0.35,
handleTop - handleBottom,
8
),
matched ? materials.matchedHandle : materials.mismatchHandle
);
handle.position.y = (handleTop + handleBottom) * 0.5;
handle.castShadow = true;
handle.receiveShadow = true;
group.add(handle);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.32, 0.34, 0.075, 8),
matched ? materials.matchedCap : materials.mismatchCap
);
cap.position.y = handleTop + 0.015;
cap.castShadow = true;
group.add(cap);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.052, 0.47, 0.075),
materials.stripe
);
stripe.position.set(0.326, (handleTop + handleBottom) * 0.5, 0);
stripe.castShadow = true;
group.add(stripe);
return group;
}
const matchedStation = createStation(-1.38, 0x64e6b4, true);
const mismatchStation = createStation(1.38, 0xffb45c, false);
const matchedDriver = createDriver(-1.38, true);
const mismatchDriver = createDriver(1.38, false);
let theta = 0.42;
let phi = 0.94;
let zoom = 1;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let playing = true;
let elapsed = 0;
const clock = new THREE.Clock();
function updateCamera() {
const radius = 9;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(4.7, 6.3 / aspect) / zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
}
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resetTest() {
elapsed = 0;
theta = 0.42;
phi = 0.94;
zoom = 1;
matchedDriver.rotation.y = 0;
matchedDriver.position.y = 0;
mismatchDriver.rotation.y = 0;
mismatchDriver.position.y = 0.12;
resize();
}
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Pause" : "Resume";
});
resetButton.addEventListener("click", resetTest);
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi + dy * 0.0045, 0.58, 1.32);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(event.deltaY * 0.001),
0.72,
1.4
);
resize();
},
{ passive: false }
);
window.addEventListener("resize", resize);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetTest();
}
});
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) elapsed += delta;
const smooth = THREE.MathUtils.smoothstep(elapsed, 0.15, 1.25);
matchedDriver.position.y = 0;
matchedDriver.rotation.y = elapsed * 0.95;
mismatchDriver.position.y = 0.12 * (1 - smooth);
mismatchDriver.rotation.y = 0.08;
const pulse = 1 + Math.sin(elapsed * 3.1) * 0.035;
matchedStation.halo.scale.set(pulse, 1, pulse);
mismatchStation.halo.scale.set(pulse, 1, pulse);
mismatchStation.halo.material.opacity =
0.35 + 0.55 * smooth + Math.sin(elapsed * 3.1) * 0.08;
for (const child of mismatchStation.group.children) {
if (
child.material &&
child.material.isMeshBasicMaterial &&
child.material.transparent &&
child.material.opacity < 1
) {
child.material.opacity = 0.15 + 0.8 * smooth;
}
}
placeLabel(
leftLabel,
new THREE.Vector3(-1.38, 1.93 + matchedDriver.position.y, 0)
);
placeLabel(
rightLabel,
new THREE.Vector3(1.38, 2.08 + mismatchDriver.position.y, 0)
);
renderer.render(scene, camera);
}
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```