Prompt specification
Build or customize the Three.js 3D scene "Morphology classification teaching tray" 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: Morphology classification teaching tray
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/morphology-classification-teaching-tray-x0804
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a low-poly microbial morphology sorting tray. Provide schematic spheres, rods, curved forms, and chains, with several fictional organism cards sharing the same visible shape. Users drag the models into groups based on observable morphology and arrangement. After sorting, reveal the different fictional identities within a group to show why shape alone does not uniquely identify an organism. Use a shallow tray with clear group regions, a few magnified models, and short labels. Keep sizes explicitly schematic and distinguish single cells from connected arrangements. The sorting result should follow geometry rather than the model's color or hidden name.
Working Three.js Starter (morphology-classification-teaching-tray-x0804):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Morphology Sorting Tray</title>
<style>
:root {
color-scheme: dark;
--bg: #08131b;
--panel: #0d1c27;
--panel-2: #112633;
--line: #244050;
--text: #edf6f7;
--muted: #93aeb9;
--cyan: #64d4e6;
--green: #6ee7a8;
--red: #ff7d7d;
--amber: #ffc866;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
display: grid;
grid-template-columns: minmax(0, 1fr) 340px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 42% 30%, #173342 0, #0b1922 45%, #071119 100%);
}
canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.stage-overlay {
position: absolute;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 22px;
left: 24px;
max-width: 430px;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
font-size: clamp(23px, 3vw, 38px);
line-height: 1.05;
letter-spacing: -.035em;
}
.subtitle {
margin: 0;
max-width: 420px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.scale-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 7px 10px;
border: 1px solid #54717d;
border-radius: 999px;
background: rgba(7, 18, 26, .72);
color: #c4d8de;
font-size: 10px;
font-weight: 800;
letter-spacing: .12em;
}
.scale-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 200, 102, .65);
}
.top-actions {
position: absolute;
top: 22px;
right: 20px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid #315062;
border-radius: 9px;
padding: 9px 12px;
background: #122a38;
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: border-color .18s, background .18s, transform .18s, opacity .18s;
}
button:hover:not(:disabled) {
border-color: var(--cyan);
background: #18394a;
transform: translateY(-1px);
}
button:disabled {
cursor: not-allowed;
opacity: .38;
}
.bottom-bar {
position: absolute;
left: 22px;
right: 22px;
bottom: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
}
.drag-hint {
max-width: 600px;
padding: 11px 14px;
border: 1px solid #2a4655;
border-radius: 11px;
background: rgba(7, 18, 26, .84);
backdrop-filter: blur(12px);
color: #d6e6e9;
font-size: 12px;
line-height: 1.45;
}
.drag-hint strong {
color: white;
}
.legend {
padding: 10px 12px;
border: 1px solid #2a4655;
border-radius: 11px;
background: rgba(7, 18, 26, .78);
color: var(--muted);
font-size: 10px;
line-height: 1.6;
text-align: right;
}
.legend b { color: var(--text); }
#toast {
position: absolute;
left: 50%;
top: 22px;
width: min(420px, calc(100% - 40px));
padding: 12px 15px;
border: 1px solid #3b6173;
border-radius: 11px;
background: rgba(10, 28, 39, .94);
box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
opacity: 0;
transform: translate(-50%, -12px);
transition: opacity .2s, transform .2s;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast-title {
font-size: 13px;
font-weight: 800;
}
#toast-detail {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
aside {
min-width: 0;
min-height: 0;
overflow: auto;
border-left: 1px solid #213b49;
background:
linear-gradient(180deg, rgba(20, 43, 57, .58), transparent 220px),
var(--panel);
padding: 20px 18px 26px;
scrollbar-width: thin;
scrollbar-color: #345365 transparent;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.panel-head h2 {
margin: 4px 0 0;
font-size: 19px;
letter-spacing: -.02em;
}
.mini-button {
padding: 7px 9px;
font-size: 10px;
}
.panel-copy {
margin: 12px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.panel-copy b { color: #d6e6e9; }
.score-card {
padding: 12px;
border: 1px solid #294755;
border-radius: 11px;
background: #102532;
}
.score-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
.score-row strong {
font-size: 19px;
letter-spacing: -.03em;
}
.score-row span {
color: var(--muted);
font-size: 10px;
text-align: right;
}
.progress-track {
height: 5px;
margin-top: 10px;
overflow: hidden;
border-radius: 999px;
background: #071820;
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #49c6d9, #6ee7a8);
transition: width .25s;
}
#reveal-ready {
width: 100%;
margin-top: 10px;
}
.panel-section {
margin-top: 17px;
padding-top: 16px;
border-top: 1px solid #213c4a;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.section-title {
display: flex;
align-items: center;
gap: 8px;
}
.section-title strong {
font-size: 12px;
letter-spacing: .04em;
}
.section-title small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
.reveal-button {
padding: 6px 8px;
border-radius: 7px;
font-size: 9px;
}
.reveal-button.ready {
border-color: #5acb8a;
color: #a5f4c7;
box-shadow: 0 0 18px rgba(110, 231, 168, .12);
}
.cards {
display: grid;
gap: 7px;
margin-top: 10px;
}
.organism-card {
display: grid;
grid-template-columns: 38px minmax(0, 1fr);
gap: 9px;
align-items: center;
min-height: 57px;
padding: 9px;
border: 1px solid #284452;
border-radius: 9px;
background: #102633;
}
.organism-card.revealed {
border-color: #396958;
background: #112b30;
}
.shape-icon {
--specimen: #8ecae6;
position: relative;
display: block;
width: 32px;
height: 28px;
}
.shape-icon.sphere {
width: 21px;
height: 21px;
margin-left: 5px;
border-radius: 50%;
background: var(--specimen);
box-shadow: inset -4px -4px 0 rgba(0, 0, 0, .16);
}
.shape-icon.rod {
width: 27px;
height: 9px;
margin-top: 9px;
border-radius: 999px;
background: var(--specimen);
}
.shape-icon.curved {
width: 29px;
height: 20px;
margin-top: 3px;
border: 5px solid var(--specimen);
border-right-color: transparent;
border-radius: 50%;
transform: rotate(-18deg);
}
.shape-icon.chain {
height: 16px;
margin-top: 6px;
background:
radial-gradient(circle at 3px 8px, var(--specimen) 0 4px, transparent 4.5px),
radial-gradient(circle at 16px 8px, var(--specimen) 0 4px, transparent 4.5px),
radial-gradient(circle at 29px 8px, var(--specimen) 0 4px, transparent 4.5px);
}
.shape-icon.chain::after {
content: "";
position: absolute;
left: 5px;
right: 5px;
top: 7px;
height: 2px;
background: var(--specimen);
}
.card-code {
color: #a8c1ca;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
}
.card-name {
margin-top: 2px;
overflow: hidden;
color: white;
font-size: 12px;
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
.card-name.sealed {
color: #7895a1;
font-weight: 650;
letter-spacing: .04em;
}
.card-meta {
margin-top: 2px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.lesson {
margin-top: 18px;
padding: 13px;
border: 1px solid #42735f;
border-radius: 10px;
background: linear-gradient(135deg, #13332f, #102832);
}
.lesson strong {
color: #b7f7d2;
font-size: 12px;
}
.lesson p {
margin: 6px 0 0;
color: #a9c9c1;
font-size: 11px;
line-height: 1.5;
}
.small-print {
margin: 15px 2px 0;
color: #678591;
font-size: 9px;
line-height: 1.55;
}
@media (max-width: 900px) {
body {
grid-template-columns: 1fr;
grid-template-rows: 64vh 36vh;
}
aside {
border-left: 0;
border-top: 1px solid #213b49;
padding: 14px 16px 22px;
}
.brand { top: 15px; left: 16px; }
.subtitle { display: none; }
.scale-badge { margin-top: 8px; }
.top-actions { top: 14px; right: 14px; }
.bottom-bar { left: 14px; right: 14px; bottom: 12px; }
.legend { display: none; }
.drag-hint { max-width: none; }
#toast { top: 82px; }
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive three-dimensional morphology sorting tray">
<div class="stage-overlay">
<header class="brand">
<div class="eyebrow">Comparative morphology / specimen exercise</div>
<h1>One shape is not one species.</h1>
<p class="subtitle">
Drag the small specimens into matching shape-and-arrangement bays.
The large ringed models are magnified references, not draggable specimens.
</p>
<div class="scale-badge">SCHEMATIC SCALE · SIZE NOT TO SCALE</div>
</header>
<div class="top-actions">
<button id="reset-view" type="button">Reset view</button>
</div>
<div id="toast" role="status" aria-live="polite">
<div id="toast-title"></div>
<div id="toast-detail"></div>
</div>
<div class="bottom-bar">
<div class="drag-hint" id="drag-hint">
<strong>Drag a specimen</strong> into a bay ·
drag empty space to orbit · scroll to zoom<br>
Scoring checks geometry and arrangement only—color and sealed identity are ignored.
</div>
<div class="legend">
<b>Single:</b> one continuous cell or body<br>
<b>Connected:</b> multiple linked cells
</div>
</div>
</div>
</main>
<aside aria-label="Fictional organism identity cards">
<div class="panel-head">
<div>
<div class="eyebrow">Identity index</div>
<h2>Fictional specimen cards</h2>
</div>
<button id="reset-tray" class="mini-button" type="button">Reset tray</button>
</div>
<p class="panel-copy">
Cards with the same silhouette can represent different organisms.
Complete a geometry bay, then <b>reveal its identities</b>.
</p>
<div class="score-card">
<div class="score-row">
<strong id="score-count">0 / 12</strong>
<span>geometry-matched specimens<br>color is not part of scoring</span>
</div>
<div class="progress-track"><div id="progress-fill"></div></div>
<button id="reveal-ready" type="button" disabled>No completed bay yet</button>
</div>
<div id="group-list"></div>
<div id="lesson" class="lesson" hidden>
<strong>Same morphology, different identities.</strong>
<p>
This group contains several fictional organisms that share the same
observable silhouette. Shape narrows the hypothesis; it does not
uniquely identify the organism.
</p>
</div>
<p class="small-print">
All organisms, names, and lineages are fictional. Sizes and spacing are
deliberately exaggerated for comparison. Single cells and connected
arrangements are scored separately.
</p>
</aside>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
Core scene
-------------------------------------------------------------------------- */
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08131b);
scene.fog = new THREE.Fog(0x08131b, 27, 54);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, -0.2);
let yaw = 0.42;
let pitch = 0.86;
let cameraRadius = 25;
let cameraTouched = false;
function updateCamera() {
const horizontal = Math.sin(pitch) * cameraRadius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(yaw),
cameraTarget.y + Math.cos(pitch) * cameraRadius,
cameraTarget.z + horizontal * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xb8e8ff, 0x14201e, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x61c9e8, 1.8);
rimLight.position.set(-9, 7, -8);
scene.add(rimLight);
/* --------------------------------------------------------------------------
Geometry groups
-------------------------------------------------------------------------- */
const groups = [
{
key: "sphere",
title: "SPHERES",
arrangement: "single cells",
x: -6.15,
accent: 0x62d9ee,
accentCss: "#62d9ee",
floor: 0x163744
},
{
key: "rod",
title: "RODS",
arrangement: "single cells",
x: -2.05,
accent: 0x81d6a8,
accentCss: "#81d6a8",
floor: 0x183d36
},
{
key: "curved",
title: "CURVED",
arrangement: "single cells",
x: 2.05,
accent: 0xc39aee,
accentCss: "#c39aee",
floor: 0x342c48
},
{
key: "chain",
title: "CHAINS",
arrangement: "connected cells",
x: 6.15,
accent: 0xf2bd67,
accentCss: "#f2bd67",
floor: 0x443725
}
];
const groupByKey = new Map(groups.map(g => [g.key, g]));
for (const g of groups) {
g.slots = [
new THREE.Vector3(g.x, 0, -1.85),
new THREE.Vector3(g.x, 0, -0.62),
new THREE.Vector3(g.x, 0, 0.57)
];
}
/* --------------------------------------------------------------------------
Tray and reference magnifiers
-------------------------------------------------------------------------- */
const trayBase = new THREE.Mesh(
new THREE.BoxGeometry(17.4, 0.38, 11.5),
new THREE.MeshStandardMaterial({ color: 0x102632, roughness: 0.85, metalness: 0.06 })
);
trayBase.position.y = -0.31;
trayBase.receiveShadow = true;
scene.add(trayBase);
const stageFloor = new THREE.Mesh(
new THREE.BoxGeometry(16.9, 0.08, 2.85),
new THREE.MeshStandardMaterial({ color: 0x112b36, roughness: 0.9 })
);
stageFloor.position.set(0, -0.07, 3.73);
stageFloor.receiveShadow = true;
scene.add(stageFloor);
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x284552,
roughness: 0.72,
metalness: 0.12
});
function addRim(w, h, d, x, z) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), rimMaterial);
mesh.position.set(x, 0.08, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
addRim(0.26, 0.43, 11.45, -8.62, 0);
addRim(0.26, 0.43, 11.45, 8.62, 0);
addRim(17.45, 0.43, 0.26, 0, -5.63);
addRim(17.45, 0.32, 0.22, 0, 5.63);
const dividerMaterial = new THREE.MeshStandardMaterial({
color: 0x31515e,
roughness: 0.75
});
for (const x of [-4.10, 0, 4.10]) {
const divider = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.25, 5.82),
dividerMaterial
);
divider.position.set(x, 0.08, -1.67);
divider.castShadow = true;
scene.add(divider);
}
/* --------------------------------------------------------------------------
Low-poly shape builders
-------------------------------------------------------------------------- */
function makeShape(shape, material) {
const root = new THREE.Group();
const addMesh = geometry => {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
root.add(mesh);
return mesh;
};
if (shape === "sphere") {
const sphere = addMesh(new THREE.IcosahedronGeometry(0.43, 1));
sphere.position.y = 0.48;
}
if (shape === "rod") {
const body = addMesh(new THREE.CylinderGeometry(0.17, 0.17, 0.82, 6, 1, false));
body.rotation.z = Math.PI / 2;
body.position.y = 0.24;
const left = addMesh(new THREE.IcosahedronGeometry(0.17, 1));
left.position.set(-0.41, 0.24, 0);
const right = addMesh(new THREE.IcosahedronGeometry(0.17, 1));
right.position.set(0.41, 0.24, 0);
}
if (shape === "curved") {
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.53, 0.24, -0.19),
new THREE.Vector3(-0.35, 0.24, 0.20),
new THREE.Vector3( 0.00, 0.24, 0.36),
new THREE.Vector3( 0.36, 0.24, 0.22),
new THREE.Vector3( 0.53, 0.24, -0.10)
]);
addMesh(new THREE.TubeGeometry(curve, 12, 0.14, 6, false));
}
if (shape === "chain") {
const points = [
new THREE.Vector3(-0.72, 0.22, 0.00),
new THREE.Vector3(-0.36, 0.22, 0.08),
new THREE.Vector3( 0.00, 0.22, -0.06),
new THREE.Vector3( 0.36, 0.22, 0.05),
new THREE.Vector3( 0.72, 0.22, -0.02)
];
for (const p of points) {
const bead = addMesh(new THREE.IcosahedronGeometry(0.175, 1));
bead.position.copy(p);
}
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const direction = b.clone().sub(a);
const connector = addMesh(
new THREE.CylinderGeometry(0.052, 0.052, direction.length(), 6)
);
connector.position.copy(a).add(b).multiplyScalar(0.5);
connector.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
}
}
return root;
}
/* --------------------------------------------------------------------------
Text sprites made entirely with canvas textures
-------------------------------------------------------------------------- */
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function createLabelSprite(firstLine, secondLine, accentCss) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 30;
sprite.scale.set(2.75, 0.77, 1);
function draw(a, b) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 4, 4, 504, 136, 24);
ctx.fillStyle = "rgba(7, 20, 28, 0.91)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accentCss;
ctx.stroke();
ctx.fillStyle = accentCss;
ctx.fillRect(24, 25, 7, 94);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f2fafb";
ctx.font = "800 39px system-ui, sans-serif";
ctx.fillText(a, 266, 51);
ctx.fillStyle = "#a9c2ca";
ctx.font = "700 22px system-ui, sans-serif";
ctx.fillText(b, 266, 99);
texture.needsUpdate = true;
}
draw(firstLine, secondLine);
return { sprite, update: draw };
}
function createCodeSprite(code) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 72;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 3, 3, 250, 66, 16);
ctx.fillStyle = "rgba(6, 17, 24, 0.86)";
ctx.fill();
ctx.strokeStyle = "rgba(180, 220, 230, 0.35)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 34px system-ui, sans-serif";
ctx.fillStyle = "#e8f6f8";
ctx.fillText(code, 128, 37);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(0.64, 0.18, 1);
sprite.renderOrder = 32;
return sprite;
}
for (const g of groups) {
const floor = new THREE.Mesh(
new THREE.BoxGeometry(3.93, 0.10, 5.78),
new THREE.MeshStandardMaterial({
color: g.floor,
roughness: 0.9,
emissive: 0x000000,
emissiveIntensity: 0
})
);
floor.position.set(g.x, -0.045, -1.66);
floor.receiveShadow = true;
scene.add(floor);
g.floorMesh = floor;
const borderMaterial = new THREE.MeshStandardMaterial({
color: g.accent,
emissive: g.accent,
emissiveIntensity: 0.14,
transparent: true,
opacity: 0.82,
roughness: 0.6
});
g.borderMaterial = borderMaterial;
const borderParts = [
[3.96, 0.05, 0.055, g.x, -4.52],
[3.96, 0.05, 0.055, g.x, 1.20],
[0.055, 0.05, 5.72, g.x - 1.98, -1.66],
[0.055, 0.05, 5.72, g.x + 1.98, -1.66]
];
for (const [w, h, d, x, z] of borderParts) {
const border = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), borderMaterial);
border.position.set(x, 0.045, z);
scene.add(border);
}
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(1.15, 1.15, 0.07, 32),
new THREE.MeshStandardMaterial({
color: 0x0c202a,
roughness: 0.82,
metalness: 0.08
})
);
platform.position.set(g.x, 0.02, -3.30);
platform.receiveShadow = true;
scene.add(platform);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.13, 0.025, 6, 40),
new THREE.MeshBasicMaterial({ color: g.accent, transparent: true, opacity: 0.88 })
);
ring.rotation.x = Math.PI / 2;
ring.position.set(g.x, 0.075, -3.30);
scene.add(ring);
const referenceMaterial = new THREE.MeshStandardMaterial({
color: g.accent,
roughness: 0.42,
metalness: 0.05,
flatShading: true
});
const reference = makeShape(g.key, referenceMaterial);
const referenceScale = g.key === "chain" ? 1.22 : 1.48;
reference.scale.setScalar(referenceScale);
reference.position.set(g.x, 0, -3.30);
scene.add(reference);
const referenceLabel = createLabelSprite(
"MAGNIFIED ×3",
"REFERENCE VIEW",
g.accentCss
);
referenceLabel.sprite.scale.set(1.75, 0.49, 1);
referenceLabel.sprite.position.set(g.x, 0.34, -4.27);
scene.add(referenceLabel.sprite);
const label = createLabelSprite(
g.title,
g.arrangement.toUpperCase(),
g.accentCss
);
label.sprite.position.set(g.x, 0.32, 1.04);
scene.add(label.sprite);
g.label = label;
}
const stagingLabel = createLabelSprite(
"UNSORTED SPECIMENS",
"DRAG SMALL MODELS INTO A BAY",
"#9fc3ce"
);
stagingLabel.sprite.scale.set(3.1, 0.65, 1);
stagingLabel.sprite.position.set(0, 0.18, 5.18);
scene.add(stagingLabel.sprite);
/* --------------------------------------------------------------------------
Fictional identity data
-------------------------------------------------------------------------- */
const identitySets = {
sphere: [
{ name: "Vitreococcus lumen", lineage: "shelf-water lineage" },
{ name: "Amberglobulus tors", lineage: "soil-biofilm lineage" },
{ name: "Pearlsphaera nimbus", lineage: "cave-isolate lineage" }
],
rod: [
{ name: "Rectobacillus venn", lineage: "sediment lineage" },
{ name: "Cylindrovora pallor", lineage: "saline-microfilm lineage" },
{ name: "Bacilliforma silex", lineage: "dust-community lineage" }
],
curved: [
{ name: "Arcospirula minna", lineage: "hydrothermal-film lineage" },
{ name: "Flexicoccus caelum", lineage: "upper-water lineage" },
{ name: "Spiracella umbra", lineage: "dark-sediment lineage" }
],
chain: [
{ name: "Stellacoccus fila", lineage: "rope-colony lineage" },
{ name: "Vinculabacillus nodus", lineage: "chain-forming strain" },
{ name: "Catenavermis rubra", lineage: "matted-biofilm lineage" }
]
};
let randomSeed = 912734;
function random() {
randomSeed |= 0;
randomSeed = randomSeed + 0x6D2B79F5 | 0;
let t = Math.imul(randomSeed ^ randomSeed >>> 15, 1 | randomSeed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
const definitions = [];
for (const g of groups) {
identitySets[g.key].forEach(identity => {
definitions.push({ shape: g.key, identity });
});
}
/* Shuffle so color, IDs, and staging order do not reveal the answer. */
for (let i = definitions.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[definitions[i], definitions[j]] = [definitions[j], definitions[i]];
}
const palette = [
0xffc857, 0x8ecae6, 0xb388eb, 0x90be6d, 0xf28482,
0xf4978e, 0x43aa8b, 0x577590, 0x9c89b8, 0xf6bd60,
0x76c893, 0xe76f51
];
const homePositions = [];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 6; col++) {
homePositions.push(new THREE.Vector3(
-6.8 + col * 2.72,
0,
3.10 + row * 1.42
));
}
}
const models = [];
definitions.forEach((definition, index) => {
const id = `M${String(index + 1).padStart(2, "0")}`;
const color = new THREE.Color(palette[Math.floor(random() * palette.length)]);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.48,
metalness: 0.03,
flatShading: true,
emissive: color,
emissiveIntensity: 0.035
});
const root = new THREE.Group();
const shape = makeShape(definition.shape, material);
root.add(shape);
const codeSprite = createCodeSprite(id);
codeSprite.position.set(0, 0.08, 0.57);
root.add(codeSprite);
const home = homePositions[index].clone();
root.position.copy(home);
scene.add(root);
const model = {
id,
shape: definition.shape,
identity: definition.identity,
color: color.getHexString(),
root,
material,
home,
target: home.clone(),
sortedGroup: null,
slot: -1,
scaleTarget: 1
};
root.userData.candidateModel = model;
models.push(model);
});
/* --------------------------------------------------------------------------
Identity card UI
-------------------------------------------------------------------------- */
const groupList = document.getElementById("group-list");
const cardReferences = new Map();
const revealedGroups = new Set();
const visibleShapeText = {
sphere: "sphere · single",
rod: "rod · single",
curved: "curved · single",
chain: "linked cells · chain"
};
for (const g of groups) {
const section = document.createElement("section");
section.className = "panel-section";
section.innerHTML = `
<div class="section-head">
<div class="section-title">
<div>
<strong>${g.title}</strong>
<small class="group-count">0 / 3 placed</small>
</div>
</div>
<button class="reveal-button" type="button" disabled>Reveal · 0/3</button>
</div>
<div class="cards"></div>
`;
const cardsHost = section.querySelector(".cards");
const refs = [];
for (const identity of identitySets[g.key]) {
const model = models.find(m => m.shape === g.key && m.identity === identity);
const card = document.createElement("article");
card.className = "organism-card";
card.innerHTML = `
<span class="shape-icon ${g.key}" style="--specimen:#${model.color}" aria-hidden="true"></span>
<div>
<div class="card-code">${model.id}</div>
<div class="card-name sealed">IDENTITY SEALED</div>
<div class="card-meta">Visible: ${visibleShapeText[g.key]}</div>
</div>
`;
cardsHost.appendChild(card);
refs.push({
card,
name: card.querySelector(".card-name"),
meta: card.querySelector(".card-meta")
});
}
g.cardRefs = refs;
g.countElement = section.querySelector(".group-count");
g.revealButton = section.querySelector(".reveal-button");
g.revealButton.addEventListener("click", () => revealGroup(g.key));
groupList.appendChild(section);
cardReferences.set(g.key, refs);
}
const scoreCount = document.getElementById("score-count");
const progressFill = document.getElementById("progress-fill");
const revealReady = document.getElementById("reveal-ready");
const lesson = document.getElementById("lesson");
function groupCount(g) {
return models.filter(m =>
m.sortedGroup === g.key && m.shape === g.key
).length;
}
function updateUI() {
let total = 0;
let eligible = 0;
for (const g of groups) {
const count = groupCount(g);
total += count;
g.countElement.textContent = `${count} / 3 placed`;
const isRevealed = revealedGroups.has(g.key);
g.revealButton.disabled = count < 3 || isRevealed;
g.revealButton.classList.toggle("ready", count === 3 && !isRevealed);
g.revealButton.textContent = isRevealed
? "Identities revealed"
: `Reveal · ${count}/3`;
if (count === 3 && !isRevealed) eligible++;
}
scoreCount.textContent = `${total} / ${models.length}`;
progressFill.style.width = `${100 * total / models.length}%`;
revealReady.disabled = eligible === 0;
revealReady.textContent = eligible
? `Reveal ${eligible} completed group${eligible === 1 ? "" : "s"}`
: "No completed bay yet";
}
function revealGroup(key) {
const g = groupByKey.get(key);
if (groupCount(g) < 3 || revealedGroups.has(key)) return;
revealedGroups.add(key);
for (const ref of g.cardRefs) {
const model = models.find(m =>
m.shape === key && m.id === ref.card.querySelector(".card-code").textContent
);
ref.card.classList.add("revealed");
ref.name.classList.remove("sealed");
ref.name.textContent = model.identity.name;
ref.meta.textContent = model.identity.lineage;
}
const arrangement = key === "chain" ? "CONNECTED" : "SINGLE";
g.label.update(g.title, `${arrangement} · 3 IDENTITIES`);
lesson.hidden = false;
showToast(
`${g.title}: three identities revealed`,
"These fictional organisms share the same observable morphology."
);
updateUI();
}
revealReady.addEventListener("click", () => {
for (const g of groups) {
if (groupCount(g) === 3 && !revealedGroups.has(g.key)) revealGroup(g.key);
}
});
/* --------------------------------------------------------------------------
Dragging and geometry-only scoring
-------------------------------------------------------------------------- */
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.12);
const planeHit = new THREE.Vector3();
let draggedModel = null;
let hoveredModel = null;
let hoveredGroup = null;
let orbit = null;
let dragOffset = new THREE.Vector3();
let toastTimer = null;
function setPointer(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;
}
function pickModel(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(models.map(m => m.root), true);
for (const hit of hits) {
let object = hit.object;
while (object && !object.userData.candidateModel) {
object = object.parent;
}
if (object?.userData.candidateModel) {
return object.userData.candidateModel;
}
}
return null;
}
function findGroupAt(x, z) {
return groups.find(g =>
x >= g.x - 1.98 &&
x <= g.x + 1.98 &&
z >= -4.53 &&
z <= 1.22
) || null;
}
function updateRegionFeedback(group, model = null) {
for (const g of groups) {
if (g === group) {
const matches = model && model.shape === g.key;
g.borderMaterial.color.set(matches ? 0x6ee7a8 : 0xff7d7d);
g.borderMaterial.emissive.set(matches ? 0x6ee7a8 : 0xff7d7d);
g.borderMaterial.emissiveIntensity = 0.35;
g.floorMesh.material.emissive.set(matches ? 0x184f3b : 0x5a2020);
g.floorMesh.material.emissiveIntensity = 0.35;
} else {
g.borderMaterial.color.set(g.accent);
g.borderMaterial.emissive.set(g.accent);
g.borderMaterial.emissiveIntensity = 0.14;
g.floorMesh.material.emissive.set(0x000000);
g.floorMesh.material.emissiveIntensity = 0;
}
}
}
function releaseOldSlot(model) {
model.sortedGroup = null;
model.slot = -1;
}
function placeInGroup(model, group) {
if (model.sortedGroup !== group.key) releaseOldSlot(model);
const occupied = new Set(
models
.filter(m => m !== model && m.sortedGroup === group.key)
.map(m => m.slot)
);
let slot = group.slots.findIndex((_, index) => !occupied.has(index));
if (slot < 0) slot = 0;
model.sortedGroup = group.key;
model.slot = slot;
model.target.copy(group.slots[slot]);
}
function showToast(title, detail) {
clearTimeout(toastTimer);
document.getElementById("toast-title").textContent = title;
document.getElementById("toast-detail").textContent = detail;
document.getElementById("toast").classList.add("show");
toastTimer = setTimeout(() => {
document.getElementById("toast").classList.remove("show");
}, 3100);
}
function setDragHint(html) {
document.getElementById("drag-hint").innerHTML = html;
}
renderer.domElement.addEventListener("pointerdown", event => {
event.preventDefault();
renderer.domElement.setPointerCapture(event.pointerId);
if (event.button === 0) {
const model = pickModel(event);
if (model) {
draggedModel = model;
model.scaleTarget = 1.10;
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
dragOffset.set(
model.root.position.x - planeHit.x,
0,
model.root.position.z - planeHit.z
);
} else {
dragOffset.set(0, 0, 0);
}
renderer.domElement.style.cursor = "grabbing";
setDragHint(
`<strong>Dragging ${model.id}</strong> · release in a matching morphology bay.`
);
return;
}
}
orbit = {
x: event.clientX,
y: event.clientY,
yaw,
pitch
};
cameraTouched = true;
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (draggedModel) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
draggedModel.root.position.set(
THREE.MathUtils.clamp(planeHit.x + dragOffset.x, -8.0, 8.0),
0,
THREE.MathUtils.clamp(planeHit.z + dragOffset.z, -4.8, 5.0)
);
draggedModel.target.copy(draggedModel.root.position);
}
const group = findGroupAt(
draggedModel.root.position.x,
draggedModel.root.position.z
);
hoveredGroup = group;
updateRegionFeedback(group, draggedModel);
if (group) {
const match = draggedModel.shape === group.key;
setDragHint(
`<strong>${draggedModel.id}</strong> → ${group.title} / ${group.arrangement} · ` +
(match
? "geometry matches"
: "this bay expects a different silhouette")
);
} else {
setDragHint(
`<strong>${draggedModel.id}</strong> · release over a bay, or return it to the staging strip.`
);
}
return;
}
if (orbit) {
const dx = event.clientX - orbit.x;
const dy = event.clientY - orbit.y;
yaw = orbit.yaw - dx * 0.006;
pitch = THREE.MathUtils.clamp(orbit.pitch + dy * 0.0045, 0.48, 1.25);
updateCamera();
return;
}
const model = pickModel(event);
if (model !== hoveredModel) {
if (hoveredModel) hoveredModel.scaleTarget = 1;
hoveredModel = model;
renderer.domElement.style.cursor = model ? "grab" : "default";
}
});
function finishPointer(event) {
if (draggedModel) {
const model = draggedModel;
const group = findGroupAt(model.root.position.x, model.root.position.z);
/*
Scoring intentionally uses ONLY observable geometry.
Neither model.color nor model.identity participates in this test.
*/
const geometryMatches = group && model.shape === group.key;
if (geometryMatches) {
placeInGroup(model, group);
showToast(
`${model.id} matched ${group.title.toLowerCase()}`,
"Geometry and arrangement satisfy the geometry-only score."
);
} else if (group) {
if (model.sortedGroup) {
const previous = groupByKey.get(model.sortedGroup);
placeInGroup(model, previous);
} else {
model.target.copy(model.home);
}
showToast(
"That bay does not match the silhouette",
"Color and sealed identity are ignored; only shape and arrangement count."
);
} else {
releaseOldSlot(model);
model.target.copy(model.home);
showToast(
`${model.id} returned to staging`,
"Drop a specimen inside one of the four morphology bays."
);
}
model.scaleTarget = 1;
draggedModel = null;
hoveredGroup = null;
updateRegionFeedback(null);
updateUI();
}
orbit = null;
renderer.domElement.style.cursor = hoveredModel ? "grab" : "default";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", finishPointer);
renderer.domElement.addEventListener("pointercancel", finishPointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (event.deltaY > 0 ? 0.91 : 1.10),
17,
42
);
cameraTouched = true;
updateCamera();
}, { passive: false });
document.getElementById("reset-view").addEventListener("click", () => {
yaw = 0.42;
pitch = 0.86;
cameraTouched = false;
resize();
});
document.getElementById("reset-tray").addEventListener("click", () => {
for (const model of models) {
releaseOldSlot(model);
model.target.copy(model.home);
model.scaleTarget = 1;
}
revealedGroups.clear();
for (const g of groups) {
const arrangement = g.key === "chain" ? "CONNECTED CELLS" : "SINGLE CELLS";
g.label.update(g.title, arrangement);
for (const ref of g.cardRefs) {
ref.card.classList.remove("revealed");
ref.name.classList.add("sealed");
ref.name.textContent = "IDENTITY SEALED";
ref.meta.textContent = `Visible: ${visibleShapeText[g.key]}`;
}
}
lesson.hidden = true;
updateRegionFeedback(null);
updateUI();
showToast("Tray reset", "All specimens and sealed identities have been restored.");
});
/* --------------------------------------------------------------------------
Direct camera controls: no OrbitControls or other addons are used.
-------------------------------------------------------------------------- */
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const fitRadius = Math.max(
24,
20.5 / (2 * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)) * camera.aspect)
);
if (!cameraTouched) cameraRadius = fitRadius;
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateUI();
/* --------------------------------------------------------------------------
Animation
-------------------------------------------------------------------------- */
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const lerpAlpha = 1 - Math.exp(-12 * dt);
for (const model of models) {
if (model !== draggedModel) {
model.root.position.lerp(model.target, lerpAlpha);
}
const nextScale = THREE.MathUtils.lerp(
model.root.scale.x,
model.scaleTarget,
lerpAlpha
);
model.root.scale.setScalar(nextScale);
const isActive = model === hoveredModel || model === draggedModel;
const targetEmissive = isActive ? 0.19 : 0.035;
model.material.emissiveIntensity = THREE.MathUtils.lerp(
model.material.emissiveIntensity,
targetEmissive,
lerpAlpha
);
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```