Prompt specification
Build or customize the Three.js 3D scene "Fictional crop variation field" 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: Fictional crop variation field
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fictional-crop-variation-field-x0951
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows polygenic traits. Compose plants with a continuous range of heights beside token combinations and environmental offsets; avoid associating real crop performance with invented genotype values. Voxel style.
Working Three.js Starter (fictional-crop-variation-field-x0951):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, viewport-fit=cover"
/>
<title>Polygenic Traits — Voxel Explorer</title>
<style>
:root {
--ink: #27332f;
--muted: #69726d;
--paper: #f3efe7;
--panel: rgba(255, 253, 248, 0.94);
--line: rgba(39, 51, 47, 0.14);
--accent: #e4775e;
--teal: #4e918c;
--moss: #78925d;
--amber: #d6a649;
--shadow: 0 18px 50px rgba(46, 55, 49, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.header {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
max-width: 560px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #52645d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 30px;
height: 3px;
background: var(--accent);
content: "";
}
h1 {
max-width: 540px;
margin: 0;
font-size: clamp(34px, 4.1vw, 62px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.header p {
max-width: 490px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.header p strong {
color: var(--ink);
font-weight: 700;
}
.panel {
position: fixed;
z-index: 8;
top: 28px;
right: 28px;
width: min(340px, calc(100vw - 40px));
padding: 20px;
overflow: auto;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.panel-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 20px;
}
.panel-kicker {
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 25px;
letter-spacing: -0.035em;
}
.selected-dot {
flex: 0 0 auto;
width: 13px;
height: 13px;
margin-top: 5px;
border: 3px solid #f8e3dc;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(228, 119, 94, 0.25);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 20px;
}
.metric {
min-width: 0;
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(243, 239, 231, 0.56);
}
.metric-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
overflow: hidden;
font-size: 24px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.045em;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.section {
margin-top: 18px;
}
.section-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.section-heading label,
.section-title {
font-size: 12px;
font-weight: 780;
letter-spacing: 0.02em;
}
.section-heading output {
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.token-row {
display: flex;
gap: 8px;
min-height: 43px;
}
.token {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
gap: 7px;
min-width: 0;
padding: 9px 7px;
border: 1px solid var(--line);
border-radius: 10px;
background: #fffdf8;
font-size: 11px;
font-weight: 750;
white-space: nowrap;
}
.token-glyph {
font-size: 18px;
line-height: 1;
}
.token-0 {
color: var(--teal);
}
.token-1 {
color: var(--accent);
}
.token-2 {
color: #b3852f;
}
.hint {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 10px 0 4px;
border-radius: 999px;
outline: none;
background: #d9d5cc;
cursor: pointer;
accent-color: var(--accent);
appearance: none;
-webkit-appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fffdf8;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(39, 51, 47, 0.18);
appearance: none;
-webkit-appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #fffdf8;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(39, 51, 47, 0.18);
}
.model-note {
margin-top: 19px;
padding: 12px;
border-left: 3px solid var(--amber);
border-radius: 0 10px 10px 0;
background: #f3ead6;
color: #64563d;
font-size: 10px;
line-height: 1.55;
}
.model-note strong {
color: #4f432d;
}
.footer {
position: fixed;
z-index: 7;
bottom: 25px;
left: 30px;
display: flex;
align-items: center;
gap: 18px;
max-width: calc(100vw - 430px);
padding: 11px 14px 11px 17px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 15px;
background: rgba(255, 253, 248, 0.9);
box-shadow: 0 10px 35px rgba(46, 55, 49, 0.1);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.footer-title {
flex: 0 0 auto;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
line-height: 1.35;
text-transform: uppercase;
}
.specimen-nav {
display: flex;
gap: 6px;
overflow-x: auto;
scrollbar-width: none;
}
.specimen-nav::-webkit-scrollbar {
display: none;
}
.specimen-button {
position: relative;
width: 44px;
height: 34px;
flex: 0 0 auto;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 800;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.specimen-button:hover {
color: var(--ink);
transform: translateY(-1px);
}
.specimen-button.active {
border-color: var(--accent);
background: var(--accent);
color: white;
}
.legend {
position: fixed;
z-index: 6;
right: 31px;
bottom: 29px;
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 10px;
}
.legend span {
white-space: nowrap;
}
.legend button {
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 253, 248, 0.9);
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 700;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.header {
top: 18px;
left: 18px;
max-width: 48vw;
}
h1 {
font-size: clamp(30px, 6vw, 48px);
}
.header p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 76px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 16px;
border-radius: 17px;
}
.panel-top {
margin-bottom: 13px;
}
.metrics {
margin-bottom: 13px;
}
.model-note {
margin-top: 13px;
}
.footer {
right: 12px;
bottom: 12px;
left: 12px;
max-width: none;
padding: 8px 10px;
}
.footer-title {
display: none;
}
.legend {
display: none;
}
}
@media (max-height: 700px) and (min-width: 901px) {
.panel {
top: 14px;
right: 14px;
max-height: calc(100vh - 28px);
padding: 15px;
}
.header {
top: 18px;
left: 20px;
}
.model-note {
margin-top: 12px;
}
.footer {
bottom: 14px;
left: 20px;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive voxel visualization of abstract polygenic traits"></div>
<header class="header">
<div class="eyebrow">Polygenic / Voxel Explorer</div>
<h1>Many tokens.<br />One continuous trait.</h1>
<p>
Symbolic token rows stand in for many genetic inputs.
<strong>Height remains a continuous visual coordinate</strong>,
shown beside an independent context offset.
</p>
</header>
<aside class="panel" aria-label="Selected specimen details">
<div class="panel-top">
<div>
<div class="panel-kicker">Selected specimen</div>
<h2 id="selectedTitle">P04</h2>
</div>
<span class="selected-dot" aria-hidden="true"></span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Trait coordinate</span>
<strong id="heightValue">1.86</strong>
<small>abstract trait units</small>
</div>
<div class="metric">
<span class="metric-label">Context offset</span>
<strong id="envValue">−0.11</strong>
<small>display units · visual only</small>
</div>
</div>
<section class="section">
<div class="section-heading">
<span class="section-title">Symbolic token row</span>
<span class="section-heading" style="margin: 0">
<output id="tokenCount">3 tokens</output>
</span>
</div>
<div id="tokenRow" class="token-row"></div>
<p class="hint">
Shape and order are symbolic. These are not allele counts, scores,
or measured genotypes.
</p>
</section>
<section class="section">
<div class="section-heading">
<label for="traitRange">Visual trait scrub</label>
<output id="rangeReadout">1.86</output>
</div>
<input
id="traitRange"
type="range"
min="0.60"
max="3.40"
step="0.01"
value="1.86"
/>
<p class="hint">
Moves only the selected voxel; its token row stays fixed.
</p>
</section>
<section class="section">
<div class="section-heading">
<label for="envRange">Context offset</label>
<output id="envReadout">−0.11</output>
</div>
<input
id="envRange"
type="range"
min="-0.25"
max="0.25"
step="0.01"
value="-0.11"
/>
<p class="hint">
Moves the nearby gauge only. No height or performance response is inferred.
</p>
</section>
<div class="model-note">
<strong>Teaching schematic, not a crop model.</strong>
Tokens are toy shapes, offsets are not calibrated environmental responses,
and trait height is not yield, vigor, fitness, or real-crop performance.
</div>
</aside>
<footer class="footer">
<div class="footer-title">Height<br />specimens</div>
<nav id="specimenNav" class="specimen-nav" aria-label="Select a specimen"></nav>
</footer>
<div class="legend" aria-hidden="true">
<span>Drag to orbit · Shift-drag to pan · Wheel to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="loading">Building voxel continuum</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xede8de);
scene.fog = new THREE.Fog(0xede8de, 22, 42);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Abstract voxel plants with symbolic token rows and context offset gauges"
);
viewport.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xfffbef, 0x66756b, 2.2);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff7df, 3.1);
keyLight.position.set(-6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xc9e1df, 1.15);
rimLight.position.set(8, 6, -8);
scene.add(rimLight);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xede8de,
roughness: 1
}),
plinth: new THREE.MeshStandardMaterial({
color: 0xb9b1a3,
roughness: 0.9
}),
plinthTop: new THREE.MeshStandardMaterial({
color: 0xe8e0d3,
roughness: 0.95
}),
soil: new THREE.MeshStandardMaterial({
color: 0x3d4b40,
roughness: 1
}),
stem: new THREE.MeshStandardMaterial({
color: 0x536b42,
roughness: 0.9
}),
leafDark: new THREE.MeshStandardMaterial({
color: 0x5f8057,
roughness: 0.85
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x91a45d,
roughness: 0.85
}),
leafWarm: new THREE.MeshStandardMaterial({
color: 0x78945b,
roughness: 0.85
}),
bud: new THREE.MeshStandardMaterial({
color: 0xc7a553,
roughness: 0.75
}),
rail: new THREE.MeshStandardMaterial({
color: 0x48514d,
roughness: 0.8
}),
neutral: new THREE.MeshStandardMaterial({
color: 0x7b8179,
roughness: 0.65
}),
negative: new THREE.MeshStandardMaterial({
color: 0x5d8fa0,
roughness: 0.65
}),
positive: new THREE.MeshStandardMaterial({
color: 0xe4775e,
roughness: 0.65
}),
tokenBase: new THREE.MeshStandardMaterial({
color: 0x3c4541,
roughness: 0.8
}),
tick: new THREE.MeshStandardMaterial({
color: 0x817b70,
roughness: 1
})
};
const tokenDefinitions = [
{
glyph: "■",
name: "Cube",
color: 0x4e918c,
css: "#4e918c"
},
{
glyph: "▰",
name: "Bar",
color: 0xe4775e,
css: "#e4775e"
},
{
glyph: "▣",
name: "Tall",
color: 0xd6a649,
css: "#b3852f"
}
];
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabelSprite(
text,
{
background = "rgba(255,253,248,0.94)",
foreground = "#27332f",
scale = [1.2, 0.28],
fontSize = 48
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 630, 118, 22);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = "rgba(39,51,47,0.14)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = `700 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
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.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 5;
sprite.userData.isLabel = true;
return sprite;
}
const samples = [
{
id: "P01",
height: 0.72,
tokens: [0, 0, 2],
offset: -0.18
},
{
id: "P02",
height: 1.05,
tokens: [0, 1, 0],
offset: 0.04
},
{
id: "P03",
height: 1.42,
tokens: [0, 1, 2],
offset: 0.16
},
{
id: "P04",
height: 1.86,
tokens: [1, 0, 1],
offset: -0.11
},
{
id: "P05",
height: 2.31,
tokens: [1, 1, 2],
offset: 0.22
},
{
id: "P06",
height: 2.78,
tokens: [2, 0, 1],
offset: -0.07
},
{
id: "P07",
height: 3.28,
tokens: [2, 2, 0],
offset: 0.1
}
];
const world = new THREE.Group();
scene.add(world);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.52;
floor.receiveShadow = true;
scene.add(floor);
const plinthCenterX = -0.8;
addBox(
world,
[11.8, 0.46, 4.15],
[plinthCenterX, -0.25, 0],
materials.plinth
);
addBox(
world,
[11.55, 0.12, 3.92],
[plinthCenterX, 0.035, 0],
materials.plinthTop
);
const axis = new THREE.Group();
world.add(axis);
addBox(
axis,
[9.25, 0.045, 0.075],
[-1.0, 0.13, 1.48],
materials.rail,
false
);
for (let i = 0; i <= 24; i++) {
const x = -5.62 + (9.25 * i) / 24;
addBox(
axis,
[0.035, 0.035, i % 4 === 0 ? 0.22 : 0.12],
[x, 0.16, 1.48],
materials.tick,
false
);
}
const axisLabel = makeLabelSprite("CONTINUOUS TRAIT AXIS", {
scale: [2.45, 0.37],
fontSize: 42
});
axisLabel.position.set(-4.8, 0.35, 1.5);
axis.add(axisLabel);
const plantsRoot = new THREE.Group();
const tokensRoot = new THREE.Group();
const environmentsRoot = new THREE.Group();
world.add(plantsRoot, tokensRoot, environmentsRoot);
const plantVisuals = [];
const tokenVisuals = [];
const environmentVisuals = [];
const xStart = -5.2;
const xSpacing = 1.4;
function sampleX(index) {
return xStart + index * xSpacing;
}
function buildPlant(sample, index) {
const group = new THREE.Group();
group.position.set(sampleX(index), 0.1, 0.05);
group.userData.specimenIndex = index;
const leaves = [];
addBox(
group,
[0.62, 0.07, 0.7],
[0, 0.02, 0],
materials.soil
);
const stemTop = Math.max(0.2, sample.height - 0.25);
const segmentCount = Math.max(3, Math.round(stemTop / 0.17));
const segmentHeight = stemTop / segmentCount;
for (let i = 0; i < segmentCount; i++) {
addBox(
group,
[0.13, segmentHeight + 0.006, 0.13],
[0, (i + 0.5) * segmentHeight, 0],
materials.stem
);
}
const levels = [0.28, 0.46, 0.64, 0.79];
const leafMaterials = [
materials.leafDark,
materials.leafLight,
materials.leafWarm
];
levels.forEach((level, leafIndex) => {
const direction = leafIndex % 2 === 0 ? 1 : -1;
const y = stemTop * level;
const leafMaterial = leafMaterials[(index + leafIndex) % leafMaterials.length];
const pivot = new THREE.Group();
pivot.position.set(0, y, 0);
group.add(pivot);
addBox(
pivot,
[0.29, 0.09, 0.13],
[direction * 0.13, 0, 0],
materials.stem
);
addBox(
pivot,
[0.29, 0.22, 0.28],
[direction * 0.31, 0.055, 0],
leafMaterial
);
addBox(
pivot,
[0.18, 0.14, 0.19],
[direction * 0.46, 0.105, 0.025],
leafMaterial
);
pivot.userData.phase = index * 0.72 + leafIndex * 0.9;
leaves.push(pivot);
});
addBox(
group,
[0.25, 0.24, 0.25],
[0, sample.height - 0.12, 0],
materials.bud
);
addBox(
group,
[0.14, 0.14, 0.14],
[0.1, sample.height - 0.02, 0.035],
materials.leafLight
);
const label = makeLabelSprite(sample.id, {
scale: [0.62, 0.2],
fontSize: 54
});
label.position.set(0, sample.height + 0.25, 0);
group.add(label);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xe4775e,
emissive: 0xe4775e,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.95,
roughness: 0.55
});
const marker = new THREE.Group();
group.add(marker);
const corners = [
[-0.37, -0.37],
[0.37, -0.37],
[-0.37, 0.37],
[0.37, 0.37]
];
corners.forEach(([x, z]) => {
addBox(
marker,
[0.1, 0.07, 0.1],
[x, 0.095, z],
markerMaterial,
false
);
});
return { group, leaves, marker, markerMaterial };
}
function buildTokens(sample, index) {
const group = new THREE.Group();
group.position.set(sampleX(index) + 0.53, 0.1, -0.78);
group.userData.specimenIndex = index;
addBox(
group,
[0.36, 0.07, 0.34],
[0, 0.03, 0],
materials.tokenBase
);
const tokenMeshes = [];
sample.tokens.forEach((tokenIndex, order) => {
const definition = tokenDefinitions[tokenIndex];
const material = new THREE.MeshStandardMaterial({
color: definition.color,
roughness: 0.72
});
let size;
if (tokenIndex === 0) {
size = [0.19, 0.18, 0.19];
} else if (tokenIndex === 1) {
size = [0.28, 0.11, 0.18];
} else {
size = [0.16, 0.21, 0.16];
}
const mesh = addBox(
group,
size,
[0, 0.15 + order * 0.21, 0],
material
);
mesh.userData.baseY = mesh.position.y;
mesh.userData.phase = index * 0.55 + order * 1.1;
tokenMeshes.push(mesh);
});
const glyphs = sample.tokens
.map((tokenIndex) => tokenDefinitions[tokenIndex].glyph)
.join(" ");
const label = makeLabelSprite(glyphs, {
scale: [0.65, 0.18],
fontSize: 52
});
label.position.set(0, 0.84, 0);
group.add(label);
return { group, tokenMeshes };
}
function buildEnvironment(sample, index) {
const group = new THREE.Group();
group.position.set(sampleX(index) + 0.53, 0.1, 0.84);
group.userData.specimenIndex = index;
addBox(
group,
[0.34, 0.07, 0.34],
[0, 0.025, 0],
materials.tokenBase
);
addBox(
group,
[0.035, 0.68, 0.035],
[0, 0.39, 0],
materials.rail,
false
);
addBox(
group,
[0.17, 0.035, 0.17],
[0, 0.07, 0],
materials.rail,
false
);
addBox(
group,
[0.17, 0.035, 0.17],
[0, 0.73, 0],
materials.rail,
false
);
const markerMaterial = materials.neutral.clone();
const marker = addBox(
group,
[0.2, 0.13, 0.2],
[0, 0.39 + sample.offset * 1.4, 0],
markerMaterial
);
const label = makeLabelSprite("E", {
scale: [0.35, 0.2],
fontSize: 64
});
label.position.set(0, 0.91, 0);
group.add(label);
return {
group,
marker,
markerMaterial,
visualOffset: sample.offset
};
}
function disposeLabels(group) {
group.traverse((object) => {
if (object.userData.isLabel) {
object.material.map?.dispose();
object.material.dispose();
}
});
}
function rebuildPlant(index) {
const old = plantVisuals[index];
if (!old) return;
plantsRoot.remove(old.group);
disposeLabels(old.group);
old.markerMaterial.dispose();
plantVisuals[index] = buildPlant(samples[index], index);
plantsRoot.add(plantVisuals[index].group);
}
samples.forEach((sample, index) => {
const plant = buildPlant(sample, index);
const tokens = buildTokens(sample, index);
const environment = buildEnvironment(sample, index);
plantVisuals.push(plant);
tokenVisuals.push(tokens);
environmentVisuals.push(environment);
plantsRoot.add(plant.group);
tokensRoot.add(tokens.group);
environmentsRoot.add(environment.group);
});
// --------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, and touch pinch.
// No examples/addons are used.
// --------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-1.45, 1.25, 0),
radius: window.innerWidth < 900 ? 18.5 : 15.4,
theta: 0.62,
phi: 1.1
};
const defaultControls = {
radius: controls.radius,
theta: controls.theta,
phi: controls.phi,
target: controls.target.clone()
};
function updateCamera() {
const offset = new THREE.Spherical(
controls.radius,
controls.phi,
controls.theta
);
camera.position.setFromSpherical(offset).add(controls.target);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
updateCamera();
const pointers = new Map();
let dragDistance = 0;
let lastPointer = null;
let pinchDistance = 0;
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function getInteractiveRoots() {
return [
...plantVisuals.map((visual) => visual.group),
...tokenVisuals.map((visual) => visual.group),
...environmentVisuals.map((visual) => visual.group)
];
}
function specimenIndexFromObject(object) {
let current = object;
while (current) {
if (Number.isInteger(current.userData.specimenIndex)) {
return current.userData.specimenIndex;
}
current = current.parent;
}
return -1;
}
function pick(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(
getInteractiveRoots(),
true
);
if (!hits.length) return;
const index = specimenIndexFromObject(hits[0].object);
if (index >= 0) {
selectSample(index);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragDistance = 0;
if (pointers.size === 1) {
lastPointer = {
x: event.clientX,
y: event.clientY
};
}
if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragDistance += Math.abs(dx) + Math.abs(dy);
if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0 && distance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (pinchDistance / distance),
8,
27
);
}
pinchDistance = distance;
updateCamera();
return;
}
if (event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
controls.target.addScaledVector(
right,
-dx * controls.radius * 0.00125
);
controls.target.addScaledVector(
up,
dy * controls.radius * 0.00125
);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-5,
3
);
controls.target.y = THREE.MathUtils.clamp(
controls.target.y,
0.45,
3
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-1.5,
1.5
);
} else {
controls.theta -= dx * 0.006;
controls.phi -= dy * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi,
0.45,
1.43
);
}
updateCamera();
});
function endPointer(event, cancelled = false) {
const wasSinglePointer = pointers.size === 1;
pointers.delete(event.pointerId);
if (!cancelled && wasSinglePointer && dragDistance < 7) {
pick(event);
}
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 1) {
const only = [...pointers.values()][0];
lastPointer = { x: only.x, y: only.y };
}
}
renderer.domElement.addEventListener("pointerup", (event) => {
endPointer(event);
});
renderer.domElement.addEventListener("pointercancel", (event) => {
endPointer(event, true);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
8,
27
);
updateCamera();
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
controls.radius = defaultControls.radius;
controls.theta = defaultControls.theta;
controls.phi = defaultControls.phi;
controls.target.copy(defaultControls.target);
updateCamera();
});
// --------------------------------------------------------------------
// Inspector and selection.
// --------------------------------------------------------------------
const selectedTitle = document.getElementById("selectedTitle");
const heightValue = document.getElementById("heightValue");
const envValue = document.getElementById("envValue");
const tokenRow = document.getElementById("tokenRow");
const tokenCount = document.getElementById("tokenCount");
const traitRange = document.getElementById("traitRange");
const envRange = document.getElementById("envRange");
const rangeReadout = document.getElementById("rangeReadout");
const envReadout = document.getElementById("envReadout");
const specimenNav = document.getElementById("specimenNav");
let activeIndex = 3;
const specimenButtons = samples.map((sample, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "specimen-button";
button.textContent = sample.id;
button.title = `Select ${sample.id}`;
button.setAttribute("aria-label", `Select specimen ${sample.id}`);
button.addEventListener("click", () => {
selectSample(index);
});
specimenNav.appendChild(button);
return button;
});
function formatOffset(value) {
if (Math.abs(value) < 0.005) return "0.00";
const sign = value > 0 ? "+" : "−";
return `${sign}${Math.abs(value).toFixed(2)}`;
}
function updateInspector() {
const sample = samples[activeIndex];
selectedTitle.textContent = sample.id;
heightValue.textContent = sample.height.toFixed(2);
envValue.textContent = formatOffset(sample.offset);
rangeReadout.textContent = sample.height.toFixed(2);
envReadout.textContent = formatOffset(sample.offset);
traitRange.value = sample.height.toFixed(2);
envRange.value = sample.offset.toFixed(2);
tokenRow.replaceChildren();
tokenCount.textContent = `${sample.tokens.length} tokens`;
sample.tokens.forEach((tokenIndex) => {
const definition = tokenDefinitions[tokenIndex];
const token = document.createElement("span");
token.className = `token token-${tokenIndex}`;
const glyph = document.createElement("span");
glyph.className = "token-glyph";
glyph.textContent = definition.glyph;
const name = document.createElement("span");
name.textContent = definition.name;
token.append(glyph, name);
tokenRow.appendChild(token);
});
specimenButtons.forEach((button, index) => {
button.classList.toggle("active", index === activeIndex);
button.setAttribute("aria-pressed", String(index === activeIndex));
});
plantVisuals.forEach((visual, index) => {
visual.marker.visible = index === activeIndex;
});
}
function selectSample(index) {
activeIndex = index;
updateInspector();
}
traitRange.addEventListener("input", () => {
const value = Number(traitRange.value);
samples[activeIndex].height = value;
rebuildPlant(activeIndex);
updateInspector();
});
envRange.addEventListener("input", () => {
const value = Number(envRange.value);
samples[activeIndex].offset = value;
updateInspector();
});
updateInspector();
// --------------------------------------------------------------------
// Animation.
// --------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.04);
tokenVisuals.forEach((visual) => {
visual.tokenMeshes.forEach((mesh) => {
mesh.position.y =
mesh.userData.baseY +
Math.sin(elapsed * 1.2 + mesh.userData.phase) * 0.012;
});
});
plantVisuals.forEach((visual, index) => {
visual.leaves.forEach((leaf) => {
leaf.rotation.z =
Math.sin(elapsed * 0.72 + leaf.userData.phase) * 0.024;
});
if (index === activeIndex) {
visual.markerMaterial.emissiveIntensity =
0.35 + Math.sin(elapsed * 2.4) * 0.15;
}
});
environmentVisuals.forEach((visual, index) => {
const sample = samples[index];
visual.visualOffset = THREE.MathUtils.lerp(
visual.visualOffset,
sample.offset,
1 - Math.exp(-delta * 9)
);
visual.marker.position.y = 0.39 + visual.visualOffset * 1.4;
if (sample.offset < -0.005) {
visual.markerMaterial.color.copy(materials.negative.color);
} else if (sample.offset > 0.005) {
visual.markerMaterial.color.copy(materials.positive.color);
} else {
visual.markerMaterial.color.copy(materials.neutral.color);
}
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```