Prompt specification
Build or customize the Three.js 3D scene "Scale-matching exploration board" 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: Scale-matching exploration board
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/scale-matching-exploration-board-x0812
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows biological size scales. Let users match objects to order-of-magnitude scale bands using illustrative values; show uncertainty where biological sizes vary and prevent decorative model size from implying actual dimensions. Low-poly.
Working Three.js Starter (scale-matching-exploration-board-x0812):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta
name="description"
content="An interactive, low-poly atlas for matching biological specimens to order-of-magnitude size bands."
>
<title>Biological Size Atlas</title>
<style>
:root {
--ink: #172725;
--muted: #68746f;
--paper: #f6f3e9;
--panel: #fbf9f2;
--stage: #e8e7df;
--line: #d7d3c7;
--green: #24695d;
--green-light: #dcebe4;
--red: #b84e3e;
--amber: #b87923;
--shadow: 0 12px 34px rgba(29, 45, 41, 0.08);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
article {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
article:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(36, 105, 93, 0.34);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
.topbar {
position: relative;
z-index: 10;
height: 82px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
color: #f7f3e8;
background:
radial-gradient(circle at 82% 20%, rgba(111, 160, 142, 0.16), transparent 30%),
#132421;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand {
min-width: 0;
}
.kicker {
display: block;
margin-bottom: 4px;
color: #a7c2b7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(19px, 2vw, 28px);
font-weight: 500;
letter-spacing: -0.025em;
white-space: nowrap;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
flex: 0 0 auto;
}
.metric {
min-width: 74px;
padding: 8px 12px;
text-align: right;
border-left: 1px solid rgba(255, 255, 255, 0.12);
}
.metric span,
.metric small {
display: block;
}
.metric span {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
font-weight: 750;
}
.metric small {
margin-top: 2px;
color: #9eb0aa;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.quiet-button {
min-height: 38px;
padding: 0 14px;
color: #eef4ef;
background: rgba(255, 255, 255, 0.07);
border: 1px solid rgba(255, 255, 255, 0.19);
border-radius: 999px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.quiet-button:hover {
background: rgba(255, 255, 255, 0.13);
border-color: rgba(255, 255, 255, 0.35);
transform: translateY(-1px);
}
.workspace {
height: calc(100vh - 82px);
min-height: 0;
display: grid;
grid-template-columns:
minmax(270px, 0.9fr)
minmax(440px, 1.55fr)
minmax(285px, 0.92fr);
}
.panel {
min-width: 0;
min-height: 0;
background: var(--panel);
border-right: 1px solid var(--line);
}
.catalog {
display: flex;
flex-direction: column;
background: #f2efe5;
}
.panel-heading {
flex: 0 0 auto;
padding: 20px 20px 15px;
border-bottom: 1px solid var(--line);
}
.panel-heading h2 {
margin: 0 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.micro-legend {
display: flex;
flex-wrap: wrap;
gap: 10px 15px;
margin-top: 12px;
color: #5f6d67;
font-size: 10px;
font-weight: 650;
}
.micro-legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.micro-legend i {
width: 16px;
height: 4px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.8);
border: 1px solid rgba(65, 80, 74, 0.25);
}
.micro-legend .dot-key {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--ink);
border: 0;
}
.object-list {
min-height: 0;
display: grid;
align-content: start;
gap: 9px;
overflow-y: auto;
padding: 13px;
scrollbar-width: thin;
scrollbar-color: #b6b7ac transparent;
}
.object-card {
position: relative;
padding: 12px;
background: rgba(255, 253, 247, 0.92);
border: 1px solid #dad6ca;
border-radius: 12px;
box-shadow: 0 3px 12px rgba(40, 48, 42, 0.025);
cursor: grab;
user-select: none;
transition:
border-color 150ms ease,
box-shadow 150ms ease,
transform 150ms ease,
background 150ms ease;
}
.object-card:hover {
transform: translateY(-1px);
border-color: #aeb8b1;
box-shadow: 0 7px 18px rgba(40, 48, 42, 0.07);
}
.object-card.is-dragging {
opacity: 0.42;
transform: scale(0.98);
}
.object-card.selected {
border-color: var(--green);
box-shadow: 0 0 0 2px rgba(36, 105, 93, 0.14);
}
.object-card.missed {
border-color: #d38a7f;
animation: soft-shake 300ms ease;
}
.object-card.solved {
border-color: #82aa95;
background: #f2f8f2;
cursor: default;
}
.object-card.solved:hover {
transform: none;
}
.object-top {
display: grid;
grid-template-columns: 38px minmax(0, 1fr) 24px;
align-items: center;
gap: 10px;
}
.specimen-chip {
width: 38px;
height: 38px;
display: grid;
place-items: center;
color: #f4f1e8;
background: #334b47;
border-radius: 9px 9px 9px 2px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
}
.object-card h3 {
margin: 0;
font-size: 13px;
line-height: 1.25;
font-weight: 760;
}
.object-value {
margin: 3px 0 0;
color: #53645e;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
.drag-grip {
color: #98a19b;
font-size: 17px;
text-align: center;
transform: rotate(90deg);
}
.object-card.solved .drag-grip {
color: var(--green);
font-size: 14px;
font-weight: 900;
transform: none;
}
.range-track {
position: relative;
height: 8px;
margin-top: 11px;
overflow: visible;
border-radius: 999px;
background:
repeating-linear-gradient(
90deg,
rgba(48, 69, 62, 0.2) 0 1px,
transparent 1px 8.333%
),
#e7e4da;
border: 1px solid #d5d1c5;
}
.range-window {
position: absolute;
top: -2px;
height: 10px;
min-width: 2px;
background: rgba(255, 255, 255, 0.58);
border: 1px solid rgba(63, 81, 74, 0.32);
border-radius: 999px;
}
.value-dot {
position: absolute;
top: 50%;
width: 8px;
height: 8px;
background: #263d38;
border: 2px solid #fffdf7;
border-radius: 50%;
box-shadow: 0 0 0 1px rgba(38, 61, 56, 0.35);
transform: translate(-50%, -50%);
}
.range-caption {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 7px;
color: #6d7872;
font-size: 9px;
}
.uncertainty-badge {
flex: 0 0 auto;
padding: 3px 6px;
color: #8b5b1e;
background: #f4e5c7;
border-radius: 999px;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--stage);
border-right: 1px solid var(--line);
isolation: isolate;
}
#canvasHost,
#sceneLabels {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#canvasHost canvas:active {
cursor: grabbing;
}
.stage-heading {
position: absolute;
z-index: 3;
top: 19px;
left: 20px;
max-width: 290px;
pointer-events: none;
}
.stage-heading .stage-kicker {
color: #6f7d77;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.stage-heading h2 {
margin: 7px 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
letter-spacing: -0.03em;
}
.stage-heading p {
margin: 0;
color: #69756f;
font-size: 11px;
line-height: 1.45;
}
#sceneLabels {
z-index: 2;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 80px;
padding: 7px 9px;
color: #263c37;
background: rgba(251, 249, 242, 0.9);
border: 1px solid rgba(70, 88, 80, 0.19);
border-top: 3px solid var(--band-color);
border-radius: 8px;
box-shadow: 0 6px 18px rgba(36, 48, 42, 0.09);
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
transition:
background 140ms ease,
box-shadow 140ms ease,
transform 140ms ease;
}
.scene-label:hover,
.scene-label.selected {
background: rgba(255, 254, 249, 0.98);
box-shadow: 0 8px 24px rgba(36, 48, 42, 0.16);
}
.scene-label.selected {
outline: 2px solid color-mix(in srgb, var(--band-color), transparent 55%);
outline-offset: 2px;
}
.scene-label b {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
.scene-label small {
display: block;
margin-top: 2px;
color: #69766f;
font-size: 8px;
white-space: nowrap;
}
.stage-controls {
position: absolute;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 8px;
}
.stage-controls button {
min-height: 32px;
padding: 0 11px;
color: #42564f;
background: rgba(251, 249, 242, 0.85);
border: 1px solid rgba(68, 83, 76, 0.19);
border-radius: 999px;
cursor: pointer;
backdrop-filter: blur(8px);
}
.stage-controls span {
display: none;
color: #627069;
font-size: 9px;
}
.model-disclosure {
position: absolute;
z-index: 4;
right: 18px;
bottom: 17px;
left: 18px;
display: flex;
align-items: flex-start;
gap: 10px;
max-width: 590px;
margin: 0 auto;
padding: 10px 12px;
color: #43554e;
background: rgba(248, 246, 238, 0.91);
border: 1px solid rgba(65, 83, 74, 0.17);
border-radius: 10px;
font-size: 10px;
line-height: 1.45;
box-shadow: 0 8px 26px rgba(35, 48, 42, 0.08);
backdrop-filter: blur(9px);
pointer-events: none;
}
.model-disclosure strong {
color: #263c37;
}
.disclosure-icon {
flex: 0 0 auto;
width: 21px;
height: 21px;
display: grid;
place-items: center;
color: #fffdf7;
background: #344d47;
border-radius: 50%;
font-size: 12px;
font-weight: 900;
}
.bands-panel {
display: flex;
flex-direction: column;
background: #f7f4eb;
border-right: 0;
}
.band-list {
min-height: 0;
display: grid;
align-content: start;
gap: 8px;
overflow-y: auto;
padding: 13px;
scrollbar-width: thin;
scrollbar-color: #b6b7ac transparent;
}
.band-card {
position: relative;
display: grid;
grid-template-columns: 30px minmax(0, 1fr) 25px;
align-items: center;
gap: 10px;
min-height: 68px;
padding: 10px 11px;
overflow: hidden;
background: rgba(255, 253, 247, 0.92);
border: 1px solid #d9d5c9;
border-radius: 11px;
cursor: pointer;
transition:
border-color 150ms ease,
box-shadow 150ms ease,
transform 150ms ease,
background 150ms ease;
}
.band-card::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
background: var(--band-color);
}
.band-card:hover,
.band-card.selected {
border-color: var(--band-color);
box-shadow: 0 7px 20px rgba(35, 48, 42, 0.08);
transform: translateY(-1px);
}
.band-card.selected {
background: color-mix(in srgb, var(--band-color), white 93%);
}
.band-card.drag-over {
border-color: var(--band-color);
box-shadow:
0 0 0 3px color-mix(in srgb, var(--band-color), transparent 73%),
0 8px 24px rgba(35, 48, 42, 0.12);
transform: scale(1.015);
}
.band-index {
width: 28px;
height: 28px;
display: grid;
place-items: center;
color: var(--band-color);
background: color-mix(in srgb, var(--band-color), white 88%);
border-radius: 8px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
}
.band-copy strong,
.band-copy small {
display: block;
}
.band-copy strong {
color: #2b3d38;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.band-copy small {
margin-top: 4px;
color: #68756f;
font-size: 9px;
line-height: 1.35;
}
.band-count {
min-width: 24px;
height: 24px;
display: grid;
place-items: center;
color: #69756f;
background: #ece9df;
border-radius: 50%;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
}
.feedback {
flex: 0 0 auto;
min-height: 112px;
margin: 0 13px 13px;
padding: 13px;
background: #ebe8de;
border: 1px solid #d6d1c4;
border-radius: 12px;
color: #5d6a64;
font-size: 11px;
line-height: 1.55;
}
.feedback strong {
display: block;
margin-bottom: 4px;
color: #2d413b;
font-size: 12px;
}
.feedback.success {
background: #e2eee5;
border-color: #b9d0c2;
}
.feedback.success strong {
color: #24695d;
}
.feedback.error {
background: #f3e2dc;
border-color: #dfb8ae;
}
.feedback.error strong {
color: #a24537;
}
.modal {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
padding: 22px;
background: rgba(17, 32, 28, 0.58);
backdrop-filter: blur(8px);
}
.modal-card {
width: min(460px, 100%);
padding: 28px;
color: var(--ink);
background: #fbf8ee;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 20px;
box-shadow: 0 30px 90px rgba(13, 29, 24, 0.34);
text-align: center;
}
.modal-mark {
width: 62px;
height: 62px;
display: grid;
place-items: center;
margin: 0 auto 16px;
color: #f8f4e9;
background: #315d53;
border-radius: 50% 50% 50% 18%;
font-size: 27px;
font-weight: 900;
}
.modal-card h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 500;
letter-spacing: -0.025em;
}
.modal-card p {
margin: 11px 0 20px;
color: #61706a;
font-size: 13px;
line-height: 1.65;
}
.modal-actions {
display: flex;
justify-content: center;
gap: 9px;
}
.modal-actions button {
min-height: 42px;
padding: 0 17px;
border-radius: 999px;
cursor: pointer;
}
.modal-primary {
color: #fffdf7;
background: #285e52;
border: 1px solid #285e52;
}
.modal-secondary {
color: #3e514b;
background: transparent;
border: 1px solid #c8c5ba;
}
.fallback {
height: 100%;
display: grid;
place-items: center;
padding: 40px;
color: #43564f;
text-align: center;
}
@keyframes soft-shake {
0%, 100% { transform: translateX(0); }
33% { transform: translateX(-3px); }
66% { transform: translateX(3px); }
}
@media (max-width: 1100px) {
.workspace {
grid-template-columns:
minmax(250px, 0.82fr)
minmax(390px, 1.35fr)
minmax(270px, 0.9fr);
}
.panel-heading {
padding: 17px 16px 13px;
}
.object-list,
.band-list {
padding: 10px;
}
}
@media (max-width: 900px) {
body {
height: auto;
overflow: auto;
}
.topbar {
height: auto;
min-height: 82px;
flex-wrap: wrap;
padding: 14px 17px;
}
.brand h1 {
white-space: normal;
}
.workspace {
height: auto;
min-height: 0;
grid-template-columns: 1fr 1fr;
}
.catalog {
max-height: 640px;
}
.stage {
min-height: 640px;
}
.bands-panel {
grid-column: 1 / -1;
}
.band-list {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.feedback {
min-height: 90px;
}
}
@media (max-width: 620px) {
.topbar {
align-items: flex-start;
}
.brand h1 {
font-size: 20px;
}
.header-actions {
width: 100%;
justify-content: space-between;
}
.workspace {
display: block;
}
.stage {
height: 62vh;
min-height: 500px;
border-bottom: 1px solid var(--line);
}
.catalog {
max-height: 560px;
border-right: 0;
}
.band-list {
grid-template-columns: 1fr;
}
.stage-heading {
top: 15px;
left: 15px;
}
.stage-heading h2 {
font-size: 20px;
}
.stage-controls {
top: 13px;
right: 12px;
}
.stage-controls button {
width: 34px;
padding: 0;
overflow: hidden;
color: transparent;
}
.stage-controls button::before {
content: "↺";
color: #42564f;
}
.scene-label {
min-width: 59px;
padding: 5px 6px;
}
.scene-label small {
display: none;
}
.model-disclosure {
right: 10px;
bottom: 10px;
left: 10px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<span class="kicker">Biological Size Atlas · Field Exercise 01</span>
<h1>One continuum. Many orders of magnitude.</h1>
</div>
<div class="header-actions">
<div class="metric">
<span id="progressText">0 / 12</span>
<small>matched</small>
</div>
<div class="metric">
<span id="attemptText">0</span>
<small>attempts</small>
</div>
<button class="quiet-button" id="restartButton" type="button">
Restart exercise
</button>
</div>
</header>
<main class="workspace">
<section class="panel catalog" aria-labelledby="catalogTitle">
<div class="panel-heading">
<h2 id="catalogTitle">Specimen tray</h2>
<p>
Match each specimen using its representative value. The interval shows
natural variation, not measurement precision.
</p>
<div class="micro-legend" aria-hidden="true">
<span><i></i> typical interval</span>
<span><i class="dot-key"></i> representative value</span>
</div>
</div>
<div class="object-list" id="objectList"></div>
</section>
<section class="stage" aria-label="Interactive logarithmic biological scale atlas">
<div id="canvasHost"></div>
<div id="sceneLabels" aria-hidden="false"></div>
<div class="stage-heading">
<span class="stage-kicker">Logarithmic order ruler</span>
<h2>Six visual steps, ×100 each</h2>
<p>
Neighboring bands differ by two orders of magnitude. Their on-screen
spacing is intentionally equal.
</p>
</div>
<div class="stage-controls">
<button id="resetCamera" type="button" title="Reset camera">
Reset view
</button>
<span>Drag to orbit · Scroll to zoom</span>
</div>
<div class="model-disclosure">
<span class="disclosure-icon" aria-hidden="true">i</span>
<div>
<strong>Symbols are not to scale.</strong>
Every low-poly specimen has the same normalized footprint. Only the
labels and logarithmic bands encode actual magnitude.
</div>
</div>
</section>
<section class="panel bands-panel" aria-labelledby="bandsTitle">
<div class="panel-heading">
<h2 id="bandsTitle">Order-of-magnitude bands</h2>
<p>
Select a specimen, then choose a band. On desktop, you can also drag a
specimen directly onto a band.
</p>
</div>
<div class="band-list" id="bandList"></div>
<div class="feedback" id="feedback" aria-live="polite">
<strong>Start with one specimen.</strong>
Choose its representative value and place it in the appropriate
order-of-magnitude band.
</div>
</section>
</main>
<div class="modal" id="completeModal" role="dialog" aria-modal="true" aria-labelledby="completeTitle" hidden>
<div class="modal-card">
<div class="modal-mark" aria-hidden="true">✓</div>
<h2 id="completeTitle">Scale map complete</h2>
<p id="completeText"></p>
<div class="modal-actions">
<button class="modal-secondary" id="reviewButton" type="button">
Review map
</button>
<button class="modal-primary" id="modalRestart" type="button">
Match again
</button>
</div>
</div>
</div>
<noscript>This interactive atlas requires JavaScript.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------
const bands = [
{
id: "molecular",
name: "Molecular scale",
min: 1e-10,
max: 1e-8,
minExp: "−10",
maxExp: "−8",
anchor: "1 nm",
anchorExp: "−9",
cue: "Small molecules, proteins and molecular complexes",
color: "#7868c9"
},
{
id: "viral",
name: "Viral / nano scale",
min: 1e-8,
max: 1e-6,
minExp: "−8",
maxExp: "−6",
anchor: "100 nm",
anchorExp: "−7",
cue: "Viruses and engineered nanoscale structures",
color: "#4e83d7"
},
{
id: "cellular",
name: "Cellular scale",
min: 1e-6,
max: 1e-4,
minExp: "−6",
maxExp: "−4",
anchor: "10 µm",
anchorExp: "−5",
cue: "Bacteria, organelles and most individual cells",
color: "#269b8d"
},
{
id: "millimetric",
name: "Millimetre scale",
min: 1e-4,
max: 1e-2,
minExp: "−4",
maxExp: "−2",
anchor: "1 mm",
anchorExp: "−3",
cue: "Eggs, tissues, embryos and small animals",
color: "#d69b35"
},
{
id: "organismal",
name: "Organismal scale",
min: 1e-2,
max: 1e0,
minExp: "−2",
maxExp: "0",
anchor: "10 cm",
anchorExp: "−1",
cue: "Mice and other decimetre-scale animals",
color: "#d66e50"
},
{
id: "large",
name: "Large-organism scale",
min: 1e0,
max: 1e2,
minExp: "0",
maxExp: "2",
anchor: "10 m",
anchorExp: "1",
cue: "People, whales and other large animals",
color: "#466c65"
}
];
const objects = [
{
id: "atp",
code: "ATP",
name: "ATP molecule",
value: 2e-9,
min: 1e-9,
max: 3e-9,
display: "2 nm",
range: "1–3 nm"
},
{
id: "influenza",
code: "FLU",
name: "Influenza virion",
value: 1e-7,
min: 8e-8,
max: 1.5e-7,
display: "100 nm",
range: "80–150 nm"
},
{
id: "ecoli",
code: "EC",
name: "E. coli bacterium",
value: 2e-6,
min: 1e-6,
max: 5e-6,
display: "2 µm",
range: "1–5 µm"
},
{
id: "chloroplast",
code: "CHL",
name: "Chloroplast",
value: 5e-6,
min: 2e-6,
max: 1e-5,
display: "5 µm",
range: "2–10 µm"
},
{
id: "rbc",
code: "RBC",
name: "Red blood cell",
value: 8e-6,
min: 7e-6,
max: 9e-6,
display: "8 µm",
range: "7–9 µm"
},
{
id: "pollen",
code: "POL",
name: "Pollen grain",
value: 8e-5,
min: 2.5e-5,
max: 2e-4,
display: "80 µm",
range: "25–200 µm"
},
{
id: "egg",
code: "EGG",
name: "Human egg cell",
value: 1.3e-4,
min: 1.1e-4,
max: 1.5e-4,
display: "130 µm",
range: "110–150 µm"
},
{
id: "fly",
code: "FLY",
name: "Fruit fly",
value: 3e-3,
min: 2e-3,
max: 4e-3,
display: "3 mm",
range: "2–4 mm"
},
{
id: "nematode",
code: "NEM",
name: "Tiny soil nematode",
value: 2e-3,
min: 3e-4,
max: 1.2e-2,
display: "2 mm",
range: "0.3–12 mm"
},
{
id: "mouse",
code: "MOU",
name: "House mouse",
value: 9e-2,
min: 8e-2,
max: 1.1e-1,
display: "9 cm",
range: "8–11 cm"
},
{
id: "human",
code: "HUM",
name: "Human",
value: 1.7,
min: 1.5,
max: 2,
display: "1.7 m",
range: "1.5–2.0 m"
},
{
id: "whale",
code: "WHL",
name: "Blue whale",
value: 25,
min: 20,
max: 30,
display: "25 m",
range: "20–30 m"
}
];
const objectList = document.getElementById("objectList");
const bandList = document.getElementById("bandList");
const feedback = document.getElementById("feedback");
const progressText = document.getElementById("progressText");
const attemptText = document.getElementById("attemptText");
const completeModal = document.getElementById("completeModal");
const completeText = document.getElementById("completeText");
const labelButtons = [];
const bandBaseMeshes = [];
const state = {
selectedObject: null,
selectedBand: null,
attempts: 0,
solved: new Set(),
counts: bands.map(() => 0)
};
const logMin = Math.log10(bands[0].min);
const logMax = Math.log10(bands[bands.length - 1].max);
const logSpan = logMax - logMin;
function logPercent(value) {
return ((Math.log10(value) - logMin) / logSpan) * 100;
}
function bandForValue(value) {
const index = bands.findIndex(
band => value >= band.min && value < band.max
);
return index === -1 ? bands.length - 1 : index;
}
function bandsCovered(min, max) {
return bands
.map((band, index) => ({ band, index }))
.filter(item => max >= item.band.min && min <= item.band.max);
}
function spansBoundary(object) {
return bandsCovered(object.min, object.max).length > 1;
}
function renderObjects() {
objectList.innerHTML = objects.map(object => {
const left = Math.max(0, logPercent(object.min));
const right = Math.min(100, logPercent(object.max));
const width = Math.max(1.2, right - left);
const marker = logPercent(object.value);
const boundary = spansBoundary(object);
return `
<article
class="object-card"
draggable="true"
tabindex="0"
role="button"
aria-pressed="false"
data-id="${object.id}"
aria-label="${object.name}, representative size ${object.display}, range ${object.range}"
>
<div class="object-top">
<span class="specimen-chip" aria-hidden="true">${object.code}</span>
<div>
<h3>${object.name}</h3>
<p class="object-value">≈ ${object.display}</p>
</div>
<span class="drag-grip" aria-hidden="true">⋮⋮</span>
</div>
<div
class="range-track"
aria-hidden="true"
title="Representative value and typical range on a logarithmic scale"
>
<span
class="range-window"
style="left:${left}%;width:${width}%"
></span>
<span
class="value-dot"
style="left:${marker}%"
></span>
</div>
<div class="range-caption">
<span>range ${object.range}</span>
${
boundary
? `<span class="uncertainty-badge">spans a boundary</span>`
: `<span>typical range</span>`
}
</div>
</article>
`;
}).join("");
}
function renderBands() {
bandList.innerHTML = bands.map((band, index) => `
<article
class="band-card"
tabindex="0"
role="button"
data-band="${index}"
style="--band-color:${band.color}"
aria-label="Match to ${band.name}, 10 to the ${band.minExp} through 10 to the ${band.maxExp} metres"
>
<span class="band-index" aria-hidden="true">
${String(index + 1).padStart(2, "0")}
</span>
<span class="band-copy">
<strong>10<sup>${band.minExp}</sup>–10<sup>${band.maxExp}</sup> m</strong>
<small>${band.name}<br>${band.cue}</small>
</span>
<span class="band-count" aria-label="matches in this band">0</span>
</article>
`).join("");
document.querySelectorAll(".band-card").forEach(card => {
wireDropTarget(card, Number(card.dataset.band));
});
}
function setFeedback(type, title, message) {
feedback.className = `feedback ${type}`;
feedback.innerHTML = `
<strong>${title}</strong>
${message}
`;
}
function selectObject(id) {
const object = objects.find(item => item.id === id);
if (!object || state.solved.has(id)) return;
state.selectedObject = state.selectedObject === id ? null : id;
document.querySelectorAll(".object-card").forEach(card => {
const selected = card.dataset.id === state.selectedObject;
card.classList.toggle("selected", selected);
card.setAttribute("aria-pressed", String(selected));
});
if (state.selectedObject) {
setFeedback(
"neutral",
`${object.name} selected`,
`Its representative length is ≈ ${object.display}. Now choose a scale band.`
);
} else {
setFeedback(
"neutral",
"Specimen cleared",
"Choose another specimen or drag one directly onto a band."
);
}
}
function updateSelectionVisuals() {
document.querySelectorAll(".object-card").forEach(card => {
const selected = card.dataset.id === state.selectedObject;
card.classList.toggle("selected", selected);
card.setAttribute("aria-pressed", String(selected));
});
document.querySelectorAll(".band-card").forEach(card => {
card.classList.toggle(
"selected",
Number(card.dataset.band) === state.selectedBand
);
});
labelButtons.forEach((button, index) => {
button.classList.toggle("selected", index === state.selectedBand);
});
bandBaseMeshes.forEach((mesh, index) => {
mesh.material.emissive.set(bands[index].color);
mesh.material.emissiveIntensity =
index === state.selectedBand ? 0.28 : 0.018;
});
}
function chooseBand(index) {
state.selectedBand = index;
updateSelectionVisuals();
if (state.selectedObject) {
submitMatch(state.selectedObject, index);
} else {
setFeedback(
"neutral",
`${bands[index].name} selected`,
`Choose a specimen from the tray. You can also drag one onto this band.`
);
}
}
function submitMatch(objectId, bandIndex) {
const object = objects.find(item => item.id === objectId);
if (!object || state.solved.has(objectId)) return;
state.attempts += 1;
attemptText.textContent = state.attempts;
const correctIndex = bandForValue(object.value);
const correctBand = bands[correctIndex];
const card = document.querySelector(
`.object-card[data-id="${objectId}"]`
);
if (bandIndex === correctIndex) {
state.solved.add(objectId);
state.counts[bandIndex] += 1;
state.selectedObject = null;
card.classList.remove("missed");
card.classList.add("solved");
card.setAttribute("draggable", "false");
card.querySelector(".drag-grip").textContent = "✓";
const countElement = document.querySelector(
`.band-card[data-band="${bandIndex}"] .band-count`
);
countElement.textContent = state.counts[bandIndex];
progressText.textContent = `${state.solved.size} / ${objects.length}`;
const covered = bandsCovered(object.min, object.max);
const uncertaintyMessage = covered.length > 1
? `Its ${object.range} range reaches into ${
covered
.filter(item => item.index !== correctIndex)
.map(item => item.band.name.toLowerCase())
.join(" and ")
}, so the match uses the representative value rather than a hard biological limit.`
: `Its ${object.range} range remains within this band.`;
setFeedback(
"success",
"Correct match",
`${object.name} at ≈ ${object.display} fits the ${
correctBand.name.toLowerCase()
}. ${uncertaintyMessage}`
);
updateSelectionVisuals();
if (state.solved.size === objects.length) {
window.setTimeout(showCompletion, 520);
}
} else {
card.classList.add("missed");
window.setTimeout(() => card.classList.remove("missed"), 800);
const selectedBand = bands[bandIndex];
setFeedback(
"error",
"Try another band",
`The representative value for ${object.name} (≈ ${
object.display
}) sits in the ${correctBand.name.toLowerCase()}, not ${
selectedBand.name.toLowerCase()
}. The value is illustrative, so compare the order of magnitude.`
);
}
}
function showCompletion() {
const boundaryCount = objects.filter(spansBoundary).length;
const grade =
state.attempts <= objects.length + 3
? "Sharp scale sense."
: state.attempts <= objects.length + 8
? "A solid scale sense."
: "The map is complete; review the intervals that cross boundaries.";
completeText.textContent =
`${grade} You matched all ${objects.length} specimens in ` +
`${state.attempts} attempts. ${boundaryCount} specimens have intervals ` +
`that cross a scale boundary, illustrating why the representative values ` +
`must be interpreted as guides rather than exact limits.`;
completeModal.hidden = false;
document.getElementById("modalRestart").focus();
}
function resetExercise() {
state.selectedObject = null;
state.selectedBand = null;
state.attempts = 0;
state.solved.clear();
state.counts = bands.map(() => 0);
document.querySelectorAll(".object-card").forEach(card => {
card.className = "object-card";
card.setAttribute("draggable", "true");
card.setAttribute("aria-pressed", "false");
card.querySelector(".drag-grip").textContent = "⋮⋮";
});
document.querySelectorAll(".band-count").forEach(count => {
count.textContent = "0";
});
progressText.textContent = `0 / ${objects.length}`;
attemptText.textContent = "0";
completeModal.hidden = true;
setFeedback(
"neutral",
"Start with one specimen.",
"Choose its representative value and place it in the appropriate order-of-magnitude band."
);
updateSelectionVisuals();
}
function wireDropTarget(element, index) {
element.addEventListener("dragover", event => {
event.preventDefault();
event.dataTransfer.dropEffect = "move";
element.classList.add("drag-over");
});
element.addEventListener("dragleave", () => {
element.classList.remove("drag-over");
});
element.addEventListener("drop", event => {
event.preventDefault();
element.classList.remove("drag-over");
const id =
event.dataTransfer.getData("text/plain") || draggedObjectId;
if (id) submitMatch(id, index);
});
}
let draggedObjectId = null;
let suppressNextClick = false;
renderObjects();
renderBands();
objectList.addEventListener("dragstart", event => {
const card = event.target.closest(".object-card");
if (!card || card.classList.contains("solved")) {
event.preventDefault();
return;
}
draggedObjectId = card.dataset.id;
event.dataTransfer.setData("text/plain", draggedObjectId);
event.dataTransfer.effectAllowed = "move";
window.requestAnimationFrame(() => card.classList.add("is-dragging"));
});
objectList.addEventListener("dragend", event => {
const card = event.target.closest(".object-card");
if (card) card.classList.remove("is-dragging");
draggedObjectId = null;
suppressNextClick = true;
window.setTimeout(() => {
suppressNextClick = false;
}, 80);
document.querySelectorAll(".drag-over").forEach(element => {
element.classList.remove("drag-over");
});
});
objectList.addEventListener("click", event => {
if (suppressNextClick) return;
const card = event.target.closest(".object-card");
if (card) selectObject(card.dataset.id);
});
objectList.addEventListener("keydown", event => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
const card = event.target.closest(".object-card");
if (card) selectObject(card.dataset.id);
}
});
bandList.addEventListener("click", event => {
const card = event.target.closest(".band-card");
if (card) chooseBand(Number(card.dataset.band));
});
bandList.addEventListener("keydown", event => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
const card = event.target.closest(".band-card");
if (card) chooseBand(Number(card.dataset.band));
}
});
document.getElementById("restartButton").addEventListener("click", resetExercise);
document.getElementById("modalRestart").addEventListener("click", resetExercise);
document.getElementById("reviewButton").addEventListener("click", () => {
completeModal.hidden = true;
});
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
function initThree() {
const host = document.getElementById("canvasHost");
const sceneLabels = document.getElementById("sceneLabels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e7df);
scene.fog = new THREE.Fog(0xe8e7df, 21, 42);
const camera = new THREE.PerspectiveCamera(
45,
Math.max(1, host.clientWidth) / Math.max(1, host.clientHeight),
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(
Math.max(1, host.clientWidth),
Math.max(1, host.clientHeight),
false
);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly biological scale symbols. Drag to orbit, scroll to zoom, and use arrow keys for camera movement."
);
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xfffbef,
0x7d8b83,
2.1
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff6df, 3.2);
keyLight.position.set(-5, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9d8db, 1.1);
rimLight.position.set(8, 5, -8);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xe4e2d8,
roughness: 1,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 20),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.115;
floor.receiveShadow = true;
scene.add(floor);
const axisMaterial = new THREE.LineBasicMaterial({
color: 0x69766f,
transparent: true,
opacity: 0.3
});
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-8.1, -0.055, 0.65),
new THREE.Vector3(8.1, -0.055, 0.65)
]);
const axisLine = new THREE.Line(axisGeometry, axisMaterial);
scene.add(axisLine);
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-8.1, -0.045, 0.65),
16.2,
0x69766f,
0.23,
0.14
);
scene.add(arrow);
const interactiveMeshes = [];
const anchors = [];
const spacing = 2.7;
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...extra
});
}
function addMesh(parent, geometry, mat, position = [0, 0, 0], scale = [1, 1, 1]) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function buildMolecular() {
const group = new THREE.Group();
const dark = material(0x4d6b75);
const light = material(0x9fc1bd);
const warm = material(0xd8b467);
addMesh(group, new THREE.IcosahedronGeometry(0.22, 0), light, [-0.25, 0.02, 0]);
addMesh(group, new THREE.IcosahedronGeometry(0.24, 0), dark, [0.03, 0.13, 0.02]);
addMesh(group, new THREE.IcosahedronGeometry(0.19, 0), warm, [0.29, -0.08, 0]);
addMesh(group, new THREE.IcosahedronGeometry(0.15, 0), light, [-0.12, -0.28, 0.06]);
addMesh(group, new THREE.IcosahedronGeometry(0.13, 0), warm, [0.25, 0.25, 0.08]);
return group;
}
function buildVirus() {
const group = new THREE.Group();
const bodyMaterial = material(0xd67855);
const spikeMaterial = material(0xf0c47c);
addMesh(
group,
new THREE.IcosahedronGeometry(0.29, 1),
bodyMaterial
);
const count = 14;
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < count; i++) {
const y = 1 - 2 * ((i + 0.5) / count);
const radius = Math.sqrt(1 - y * y);
const theta = goldenAngle * i;
const direction = new THREE.Vector3(
Math.cos(theta) * radius,
y,
Math.sin(theta) * radius
);
const spike = addMesh(
group,
new THREE.ConeGeometry(0.045, 0.18, 5),
spikeMaterial,
direction.clone().multiplyScalar(0.385).toArray()
);
spike.quaternion.setFromUnitVectors(up, direction);
}
return group;
}
function buildCell() {
const group = new THREE.Group();
const membrane = material(0x5db4a4, { transparent: true, opacity: 0.92 });
const nucleus = material(0x335f69);
const organelle = material(0xe2b66e);
addMesh(group, new THREE.IcosahedronGeometry(0.43, 1), membrane);
addMesh(group, new THREE.IcosahedronGeometry(0.18, 0), nucleus, [0.08, 0.04, 0.03]);
addMesh(group, new THREE.IcosahedronGeometry(0.055, 0), organelle, [-0.23, 0.14, 0.24]);
addMesh(group, new THREE.IcosahedronGeometry(0.045, 0), organelle, [0.25, -0.18, 0.18]);
return group;
}
function buildPollen() {
const group = new THREE.Group();
const core = material(0xd6a246);
const spikeMaterial = material(0xb98235);
addMesh(group, new THREE.IcosahedronGeometry(0.34, 1), core);
const up = new THREE.Vector3(0, 1, 0);
const count = 12;
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
for (let i = 0; i < count; i++) {
const y = 1 - 2 * ((i + 0.5) / count);
const radius = Math.sqrt(1 - y * y);
const theta = goldenAngle * i;
const direction = new THREE.Vector3(
Math.cos(theta) * radius,
y,
Math.sin(theta) * radius
);
const spike = addMesh(
group,
new THREE.ConeGeometry(0.035, 0.15, 5),
spikeMaterial,
direction.clone().multiplyScalar(0.4).toArray()
);
spike.quaternion.setFromUnitVectors(up, direction);
}
return group;
}
function buildFly() {
const group = new THREE.Group();
const bodyMaterial = material(0x6c4939);
const headMaterial = material(0x3d312d);
const wingMaterial = material(0xb5d4d0, {
transparent: true,
opacity: 0.68,
side: THREE.DoubleSide
});
addMesh(
group,
new THREE.SphereGeometry(0.28, 8, 6),
bodyMaterial,
[0, 0, 0],
[0.8, 0.72, 1.25]
);
addMesh(
group,
new THREE.SphereGeometry(0.16, 8, 6),
headMaterial,
[0, 0.1, 0.31]
);
const wingGeometry = new THREE.BufferGeometry();
wingGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.03, 0.02, 0.03,
-0.61, 0.06, -0.19,
-0.12, -0.01, -0.22
],
3
)
);
wingGeometry.computeVertexNormals();
const leftWing = new THREE.Mesh(wingGeometry, wingMaterial);
leftWing.castShadow = true;
group.add(leftWing);
const rightWing = leftWing.clone();
rightWing.scale.x = -1;
group.add(rightWing);
const legMaterial = material(0x3d312d);
addMesh(group, new THREE.CylinderGeometry(0.012, 0.012, 0.42, 5), legMaterial, [-0.14, -0.22, 0.02], [1, 1, 1]).rotation.z = -0.3;
addMesh(group, new THREE.CylinderGeometry(0.012, 0.012, 0.42, 5), legMaterial, [0.14, -0.22, 0.02], [1, 1, 1]).rotation.z = 0.3;
return group;
}
function buildMouse() {
const group = new THREE.Group();
const fur = material(0x9b8071);
const dark = material(0x584b45);
const pink = material(0xd6a19a);
addMesh(
group,
new THREE.SphereGeometry(0.33, 8, 6),
fur,
[0, 0, 0],
[0.8, 0.75, 1.1]
);
addMesh(
group,
new THREE.SphereGeometry(0.21, 8, 6),
fur,
[0, 0.02, 0.31]
);
addMesh(
group,
new THREE.SphereGeometry(0.095, 7, 5),
pink,
[-0.14, 0.18, 0.31],
[1, 1, 0.45]
);
addMesh(
group,
new THREE.SphereGeometry(0.095, 7, 5),
pink,
[0.14, 0.18, 0.31],
[1, 1, 0.45]
);
addMesh(group, new THREE.SphereGeometry(0.035, 6, 5), dark, [0, 0.02, 0.51]);
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, -0.02, -0.3),
new THREE.Vector3(0.13, -0.08, -0.48),
new THREE.Vector3(0.26, -0.02, -0.6)
]);
addMesh(group, new THREE.TubeGeometry(curve, 10, 0.018, 5, false), dark);
return group;
}
function buildWhale() {
const group = new THREE.Group();
const blue = material(0x537d8b);
const underside = material(0xb4c2bf);
const fin = material(0x486c79);
addMesh(
group,
new THREE.SphereGeometry(0.38, 9, 7),
blue,
[0, 0, 0],
[1.65, 0.65, 0.72]
);
addMesh(
group,
new THREE.SphereGeometry(0.26, 8, 6),
underside,
[0.18, -0.16, 0],
[1.35, 0.35, 0.68]
);
addMesh(
group,
new THREE.ConeGeometry(0.19, 0.38, 5),
fin,
[-0.67, 0.02, 0]
).rotation.z = Math.PI / 2;
const tailGeometry = new THREE.BufferGeometry();
tailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.56, 0, 0,
-0.95, 0.35, -0.26,
-0.82, 0.02, 0
],
3
)
);
tailGeometry.computeVertexNormals();
const tailMaterial = material(0x486c79, { side: THREE.DoubleSide });
const tailTop = new THREE.Mesh(tailGeometry, tailMaterial);
tailTop.castShadow = true;
group.add(tailTop);
const tailBottom = tailTop.clone();
tailBottom.scale.z = -1;
group.add(tailBottom);
const finGeometry = new THREE.BufferGeometry();
finGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.05, -0.12, 0.22,
-0.28, -0.42, 0.5,
0.22, -0.2, 0.28
],
3
)
);
finGeometry.computeVertexNormals();
const sideFin = new THREE.Mesh(finGeometry, tailMaterial);
sideFin.castShadow = true;
group.add(sideFin);
return group;
}
function normalizeIcon(rawGroup, targetSize = 1.08) {
const bounds = new THREE.Box3().setFromObject(rawGroup);
const size = bounds.getSize(new THREE.Vector3());
const center = bounds.getCenter(new THREE.Vector3());
rawGroup.position.sub(center);
const largestDimension = Math.max(size.x, size.y, size.z);
rawGroup.scale.setScalar(targetSize / Math.max(largestDimension, 0.001));
return rawGroup;
}
const iconBuilders = [
buildMolecular,
buildVirus,
buildCell,
buildPollen,
buildFly,
buildWhale
];
bands.forEach((band, index) => {
const x = (index - 2.5) * spacing;
const baseMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(band.color).lerp(new THREE.Color(0xe8e7df), 0.62),
roughness: 0.84,
metalness: 0,
flatShading: true,
emissive: band.color,
emissiveIntensity: 0.018
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.65, 0.68, 0.19, 6),
baseMaterial
);
base.position.set(x, 0, 0);
base.castShadow = true;
base.receiveShadow = true;
base.userData.bandIndex = index;
scene.add(base);
bandBaseMeshes.push(base);
interactiveMeshes.push(base);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.022, 4, 6),
new THREE.MeshStandardMaterial({
color: band.color,
roughness: 0.72,
flatShading: true
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.105, 0);
ring.userData.bandIndex = index;
scene.add(ring);
interactiveMeshes.push(ring);
const iconWrapper = new THREE.Group();
iconWrapper.position.set(x, 1.02, 0);
const normalizedIcon = normalizeIcon(iconBuilders[index]());
iconWrapper.add(normalizedIcon);
scene.add(iconWrapper);
iconWrapper.traverse(child => {
if (child.isMesh) {
child.userData.bandIndex = index;
interactiveMeshes.push(child);
}
});
anchors.push(iconWrapper);
const label = document.createElement("button");
label.type = "button";
label.className = "scene-label";
label.style.setProperty("--band-color", band.color);
label.dataset.band = String(index);
label.setAttribute(
"aria-label",
`${band.name}, anchor ${band.anchor}, 10 to the ${band.anchorExp} metres`
);
label.innerHTML = `
<b>${band.anchor}</b>
<small>${band.name} · 10<sup>${band.anchorExp}</sup> m</small>
`;
label.addEventListener("click", () => chooseBand(index));
sceneLabels.appendChild(label);
labelButtons.push(label);
wireDropTarget(label, index);
});
// -------------------------------------------------------------------
// Camera controls implemented directly, without camera-control addons.
// -------------------------------------------------------------------
const orbit = {
azimuth: 0.16,
polar: 1.14,
distance: 22,
target: new THREE.Vector3(0, 0.76, 0)
};
function updateCamera() {
const sinPolar = Math.sin(orbit.polar);
camera.position.set(
orbit.target.x + orbit.distance * sinPolar * Math.sin(orbit.azimuth),
orbit.target.y + orbit.distance * Math.cos(orbit.polar),
orbit.target.z + orbit.distance * sinPolar * Math.cos(orbit.azimuth)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.azimuth = 0.16;
orbit.polar = 1.14;
orbit.distance = 22;
updateCamera();
}
document.getElementById("resetCamera").addEventListener("click", resetCamera);
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const drag = {
active: false,
moved: false,
x: 0,
y: 0,
pointerId: null
};
function updateRay(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pickBand(event) {
updateRay(event);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (hits.length) {
const index = hits[0].object.userData.bandIndex;
if (Number.isInteger(index)) chooseBand(index);
}
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
drag.active = true;
drag.moved = false;
drag.x = event.clientX;
drag.y = event.clientY;
drag.pointerId = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!drag.active) {
updateRay(event);
const hovering = raycaster.intersectObjects(interactiveMeshes, false).length > 0;
renderer.domElement.style.cursor = hovering ? "pointer" : "grab";
return;
}
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (Math.abs(dx) + Math.abs(dy) > 4) {
drag.moved = true;
}
orbit.azimuth -= dx * 0.006;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar + dy * 0.005,
0.56,
1.43
);
drag.x = event.clientX;
drag.y = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (!drag.active) return;
if (!drag.moved) {
pickBand(event);
}
drag.active = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance + event.deltaY * 0.012,
14,
30
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.azimuth -= 0.12;
break;
case "ArrowRight":
orbit.azimuth += 0.12;
break;
case "ArrowUp":
orbit.polar = Math.max(0.56, orbit.polar - 0.08);
break;
case "ArrowDown":
orbit.polar = Math.min(1.43, orbit.polar + 0.08);
break;
case "+":
case "=":
orbit.distance = Math.max(14, orbit.distance - 1);
break;
case "-":
case "_":
orbit.distance = Math.min(30, orbit.distance + 1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
renderer.domElement.addEventListener("dblclick", resetCamera);
const resizeObserver = new ResizeObserver(() => {
const width = Math.max(1, host.clientWidth);
const height = Math.max(1, host.clientHeight);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
});
resizeObserver.observe(host);
const projected = new THREE.Vector3();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
const width = host.clientWidth;
const height = host.clientHeight;
anchors.forEach((anchor, index) => {
anchor.getWorldPosition(projected);
projected.y += 0.82;
projected.project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
const button = labelButtons[index];
button.style.visibility = visible ? "visible" : "hidden";
button.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
button.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
});
}
try {
initThree();
} catch (error) {
console.error(error);
document.getElementById("canvasHost").innerHTML = `
<div class="fallback">
<div>
<h2>3D view unavailable</h2>
<p>The matching exercise remains usable, but this browser could not start WebGL.</p>
</div>
</div>
`;
}
resetExercise();
</script>
</body>
</html>
```