Prompt specification
Build or customize the Three.js 3D scene "Seed coat embryo and reserves" 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: Seed coat embryo and reserves
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/seed-coat-embryo-and-reserves-x0785
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows seed anatomy and stored reserves. Display two enlarged generic seed sections with embryo, protective coat, and storage tissue clearly labeled; avoid implying that all plant seeds have identical internal organization. Voxel style.
Working Three.js Starter (seed-coat-embryo-and-reserves-x0785):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Inside a Seed — Voxel Anatomy</title>
<style>
:root {
--bg: #06141c;
--panel: rgba(11, 31, 40, 0.88);
--line: rgba(139, 190, 199, 0.2);
--text: #edf7f5;
--muted: #9fb8bd;
--teal: #55c7c1;
--gold: #edc25f;
--green: #8bd59c;
--orange: #dd8c53;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow-x: hidden;
background:
radial-gradient(circle at 50% 36%, rgba(28, 72, 78, 0.22), transparent 45%),
linear-gradient(180deg, #071820 0%, #061118 100%);
}
.page {
min-height: 100svh;
display: flex;
flex-direction: column;
}
header {
width: min(1480px, 100%);
margin: 0 auto;
padding: 25px 32px 18px;
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(280px, 390px);
gap: 30px;
align-items: end;
}
.eyebrow {
margin: 0 0 8px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(32px, 4vw, 57px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
}
.lede {
max-width: 680px;
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.header-note {
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(9, 26, 34, 0.74);
}
.header-note strong {
display: block;
margin-bottom: 5px;
color: var(--text);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.header-note p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.stage {
position: relative;
flex: 1;
min-height: 540px;
height: calc(100svh - 292px);
max-height: 760px;
overflow: hidden;
isolation: isolate;
}
.stage::before {
content: "";
position: absolute;
inset: 0;
z-index: -2;
background:
radial-gradient(circle at 25% 48%, rgba(55, 130, 133, 0.09), transparent 30%),
radial-gradient(circle at 75% 48%, rgba(171, 127, 51, 0.08), transparent 30%);
}
.stage::after {
content: "";
position: absolute;
top: 8%;
bottom: 7%;
left: 50%;
z-index: -1;
width: 1px;
background: linear-gradient(transparent, var(--line), transparent);
pointer-events: none;
}
#canvasMount {
position: absolute;
inset: 0;
}
#canvasMount canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#canvasMount canvas:active {
cursor: grabbing;
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.leader-line {
stroke-width: 1.25;
opacity: 0.8;
}
.anchor-dot {
stroke: #071820;
stroke-width: 2;
}
.callout {
position: absolute;
z-index: 5;
width: 178px;
padding: 9px 11px 10px;
border: 1px solid rgba(159, 196, 201, 0.22);
border-left: 3px solid var(--accent);
border-radius: 8px;
background: rgba(7, 23, 31, 0.9);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(9px);
pointer-events: none;
}
.callout strong {
display: block;
color: var(--accent);
font-size: 11px;
line-height: 1.15;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.callout span {
display: block;
margin-top: 5px;
color: #c5d7d8;
font-size: 10.5px;
line-height: 1.35;
}
.model-tag {
position: absolute;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px 6px 6px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 23, 31, 0.82);
color: #dce9e8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
}
.model-tag b {
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 50%;
background: var(--teal);
color: #052027;
font-size: 11px;
}
.model-tag.b b {
background: var(--gold);
}
.stage-tools {
position: absolute;
z-index: 8;
left: 24px;
right: 24px;
bottom: 17px;
display: flex;
justify-content: space-between;
align-items: center;
pointer-events: none;
}
.drag-hint,
.section-note {
color: #718f96;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.reset {
pointer-events: auto;
border: 1px solid var(--line);
border-radius: 8px;
padding: 8px 11px;
background: rgba(8, 25, 33, 0.84);
color: #c6d8da;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.reset:hover,
.reset:focus-visible {
border-color: var(--teal);
color: var(--text);
outline: none;
}
.takeaways {
width: min(1480px, 100%);
margin: 0 auto;
padding: 0 32px 28px;
display: grid;
grid-template-columns: 1fr 1fr 1.15fr;
gap: 12px;
}
.takeaway {
min-height: 122px;
padding: 16px 17px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(10, 28, 36, 0.78);
}
.takeaway-header {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
}
.takeaway-index {
display: grid;
place-items: center;
width: 27px;
height: 27px;
border-radius: 50%;
background: var(--teal);
color: #052027;
font-size: 11px;
font-weight: 900;
}
.takeaway:nth-child(2) .takeaway-index {
background: var(--gold);
}
.takeaway h2 {
margin: 0;
font-size: 11px;
line-height: 1.2;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.takeaway p {
margin: 0;
color: var(--muted);
font-size: 11.5px;
line-height: 1.5;
}
.takeaway.caveat {
border-color: rgba(237, 194, 95, 0.32);
background: rgba(44, 37, 21, 0.28);
}
.takeaway.caveat h2 {
color: var(--gold);
}
@media (max-width: 900px) {
header {
grid-template-columns: 1fr;
gap: 15px;
}
.header-note {
max-width: 620px;
}
.stage {
height: 670px;
max-height: none;
}
.takeaways {
grid-template-columns: 1fr 1fr;
}
.takeaway.caveat {
grid-column: 1 / -1;
}
}
@media (max-width: 680px) {
header {
padding: 22px 18px 14px;
}
.lede {
font-size: 13px;
}
.stage {
min-height: 700px;
height: 700px;
}
.stage::after {
display: none;
}
.callout {
width: 136px;
padding: 7px 8px 8px;
}
.callout strong {
font-size: 9px;
}
.callout span {
font-size: 9px;
}
.model-tag {
font-size: 8px;
}
.stage-tools {
left: 15px;
right: 15px;
}
.section-note {
display: none;
}
.takeaways {
padding: 0 18px 25px;
grid-template-columns: 1fr;
}
.takeaway.caveat {
grid-column: auto;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<div class="page">
<header>
<div>
<p class="eyebrow">Plant Biology / Seed Anatomy</p>
<h1>Inside a seed</h1>
<p class="lede">
Two enlarged voxel-style sections compare common reserve strategies:
food held in cotyledons, or food held in persistent endosperm.
</p>
</div>
<aside class="header-note">
<strong>Representative models</strong>
<p>
These are generalized teaching examples, not universal blueprints.
Actual seed anatomy and reserve chemistry vary greatly.
</p>
</aside>
</header>
<main class="stage" id="stage">
<div id="canvasMount"></div>
<svg id="leaders" aria-hidden="true"></svg>
<div class="model-tag" id="tagA"><b>A</b> Dicot-like example</div>
<div class="model-tag b" id="tagB"><b>B</b> Monocot-like example</div>
<div class="stage-tools">
<span class="drag-hint">Drag the section to rotate</span>
<span class="section-note">Enlarged cutaway / not to scale</span>
<button class="reset" id="reset" type="button">Reset view</button>
</div>
</main>
<section class="takeaways" aria-label="Comparison notes">
<article class="takeaway">
<div class="takeaway-header">
<span class="takeaway-index">A</span>
<h2>Dicot-like / bean-type</h2>
</div>
<p>
The embryo is large, and the two cotyledons often contain much of the
stored food. Endosperm is commonly consumed during seed development.
</p>
</article>
<article class="takeaway">
<div class="takeaway-header">
<span class="takeaway-index">B</span>
<h2>Monocot-like / cereal-type</h2>
</div>
<p>
A smaller embryo lies beside a persistent endosperm. The scutellum
helps absorb and transfer reserves from the endosperm to the embryo.
</p>
</article>
<article class="takeaway caveat">
<div class="takeaway-header">
<span class="takeaway-index">!</span>
<h2>Compare examples, not rules</h2>
</div>
<p>
Seeds differ in embryo form, tissue proportions, reserve location,
and whether reserves are starch, oil, protein, or a mixture. Some
mature seeds have little or no endosperm; others store reserves in
other tissues.
</p>
</article>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const canvasMount = document.querySelector("#canvasMount");
const leaders = document.querySelector("#leaders");
const tagA = document.querySelector("#tagA");
const tagB = document.querySelector("#tagB");
const resetButton = document.querySelector("#reset");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x071820, 13, 25);
const camera = new THREE.OrthographicCamera(-6, 6, 4, -4, 0.1, 100);
camera.position.set(0, 2.6, 13);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x071820, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
canvasMount.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional comparison of two generalized seed sections"
);
renderer.domElement.setAttribute("role", "img");
const hemisphere = new THREE.HemisphereLight(0xd8f1f0, 0x081015, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3d8, 3.1);
keyLight.position.set(5, 8, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x67cdd0, 1.5);
rimLight.position.set(-7, 2, 5);
scene.add(rimLight);
const models = new THREE.Group();
scene.add(models);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(26, 16),
new THREE.MeshStandardMaterial({
color: 0x071820,
roughness: 1,
metalness: 0,
transparent: true,
opacity: 0.84
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.42;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0x31545e, 0x18343e);
grid.position.y = -2.405;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
class VoxelBatch {
constructor() {
this.items = [];
}
box(x, y, z, sx, sy, sz, color) {
this.items.push({ x, y, z, sx, sy, sz, color });
return this;
}
build(parent) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0.015,
flatShading: true
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
this.items.length
);
const dummy = new THREE.Object3D();
const tint = new THREE.Color();
this.items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
tint.set(item.color);
mesh.setColorAt(index, tint);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
}
function shade(hex, amount) {
const color = new THREE.Color(hex);
color.offsetHSL(0, 0, amount);
return `#${color.getHexString()}`;
}
function insideDicot(ix, iy) {
const nx = ix / 6.35;
const ny = iy / 8.15;
const ellipse = nx * nx + ny * ny <= 1;
const upperNotch = ix < -2 && iy > 5;
return ellipse && !upperNotch;
}
function insideMonocot(ix, iy) {
const nx = ix / 6.65;
const ny = iy / 7.75;
return nx * nx + ny * ny <= 1;
}
function makeDicot() {
const group = new THREE.Group();
group.rotation.y = -0.12;
const shell = new VoxelBatch();
const reserve = new VoxelBatch();
const embryo = new VoxelBatch();
const shoot = new VoxelBatch();
const spacing = 0.28;
for (let iy = -8; iy <= 8; iy++) {
for (let ix = -6; ix <= 6; ix++) {
if (!insideDicot(ix, iy)) continue;
const x = ix * spacing;
const y = iy * spacing;
const boundary =
!insideDicot(ix + 1, iy) ||
!insideDicot(ix - 1, iy) ||
!insideDicot(ix, iy + 1) ||
!insideDicot(ix, iy - 1);
if (boundary) {
const coatColor = (ix + iy) % 2 === 0 ? "#287b80" : "#329297";
shell.box(x, y, 0.16, 0.294, 0.294, 0.31, coatColor);
} else {
// A narrow central groove makes the embryonic axis readable.
if (Math.abs(ix) === 0 && Math.abs(iy) <= 5) continue;
const base = ix < 0 ? "#f0c765" : "#e7b64e";
const variation = ((ix * 7 + iy * 3) % 5 - 2) * 0.012;
reserve.box(
x,
y,
-0.065,
0.256,
0.256,
0.235,
shade(base, variation)
);
}
}
}
// Embryonic axis.
for (let j = -4; j <= 3; j++) {
embryo.box(
0,
j * 0.255,
0.31,
0.205,
0.235,
0.225,
j % 2 ? "#dcecc2" : "#e9f3d1"
);
}
// Plumule: a tiny forked young shoot.
shoot.box(-0.13, 0.97, 0.34, 0.22, 0.24, 0.22, "#84d39b");
shoot.box(0.13, 0.97, 0.34, 0.22, 0.24, 0.22, "#9adfa7");
shoot.box(0, 1.12, 0.35, 0.22, 0.25, 0.22, "#69bd83");
// Radicle: the young root tip bends toward one side.
embryo.box(-0.10, -1.18, 0.34, 0.22, 0.25, 0.22, "#dcecc2");
embryo.box(-0.27, -1.36, 0.35, 0.23, 0.25, 0.22, "#cce2b2");
embryo.box(-0.42, -1.50, 0.35, 0.22, 0.23, 0.21, "#b9d5a3");
shell.build(group);
reserve.build(group);
embryo.build(group);
shoot.build(group);
return group;
}
function makeMonocot() {
const group = new THREE.Group();
group.rotation.y = 0.12;
const shell = new VoxelBatch();
const endosperm = new VoxelBatch();
const embryo = new VoxelBatch();
const scutellum = new VoxelBatch();
const shoot = new VoxelBatch();
const spacing = 0.28;
for (let iy = -7; iy <= 7; iy++) {
for (let ix = -6; ix <= 6; ix++) {
if (!insideMonocot(ix, iy)) continue;
const x = ix * spacing;
const y = iy * spacing;
const boundary =
!insideMonocot(ix + 1, iy) ||
!insideMonocot(ix - 1, iy) ||
!insideMonocot(ix, iy + 1) ||
!insideMonocot(ix, iy - 1);
if (boundary) {
const coatColor = (ix + iy) % 2 === 0 ? "#8b6634" : "#a1783e";
shell.box(x, y, 0.16, 0.294, 0.294, 0.31, coatColor);
} else {
const base = "#e9ca69";
const variation = ((ix * 5 + iy * 11) % 7 - 3) * 0.009;
endosperm.box(
x,
y,
-0.065,
0.256,
0.256,
0.235,
shade(base, variation)
);
}
}
}
// Scutellum: a shield-like transfer tissue next to the endosperm.
for (let j = 0; j < 4; j++) {
scutellum.box(
0.30 + (j % 2) * 0.035,
0.18 - j * 0.265,
0.30,
0.29,
0.25,
0.225,
j % 2 ? "#d9854e" : "#e3975c"
);
}
// Smaller embryo axis.
for (let j = -2; j <= 3; j++) {
embryo.box(
0.68,
j * 0.245 - 0.05,
0.34,
0.205,
0.225,
0.225,
j % 2 ? "#e4f0cb" : "#f1f5dc"
);
}
// Coleoptile: a protective young shoot.
shoot.box(0.68, 0.69, 0.35, 0.23, 0.31, 0.23, "#77c98b");
shoot.box(0.68, 0.91, 0.35, 0.23, 0.24, 0.23, "#92d89f");
// Radicle: young root.
embryo.box(0.64, -0.65, 0.35, 0.22, 0.26, 0.22, "#e4f0cb");
embryo.box(0.57, -0.86, 0.36, 0.23, 0.25, 0.22, "#d1e4b9");
embryo.box(0.49, -1.04, 0.36, 0.22, 0.24, 0.21, "#bcd4a7");
shell.build(group);
endosperm.build(group);
scutellum.build(group);
embryo.build(group);
shoot.build(group);
return group;
}
const dicot = makeDicot();
const monocot = makeMonocot();
models.add(dicot, monocot);
const labelDefinitions = [
{
group: dicot,
title: "Protective coat",
detail: "Testa around the seed",
anchor: new THREE.Vector3(-1.42, 0.78, 0.28),
color: "#55c7c1",
dx: -205,
dy: -30,
mobileDx: -128
},
{
group: dicot,
title: "Cotyledon reserve",
detail: "Food tissue in the embryo’s lobes",
anchor: new THREE.Vector3(-0.69, -0.13, 0.02),
color: "#edc25f",
dx: -210,
dy: 68,
mobileDx: -132
},
{
group: dicot,
title: "Embryo",
detail: "Plumule (shoot) + radicle (root)",
anchor: new THREE.Vector3(0.03, 0.42, 0.46),
color: "#8bd59c",
dx: 42,
dy: 103,
mobileDx: 28
},
{
group: monocot,
title: "Protective coat",
detail: "Testa around the seed",
anchor: new THREE.Vector3(1.43, 0.77, 0.28),
color: "#d9a55f",
dx: 205,
dy: -30,
mobileDx: 128
},
{
group: monocot,
title: "Endosperm reserve",
detail: "Persistent food-storage tissue",
anchor: new THREE.Vector3(-0.44, 0.22, 0.02),
color: "#edc25f",
dx: 210,
dy: 68,
mobileDx: 132
},
{
group: monocot,
title: "Scutellum",
detail: "Transfers reserve to the embryo",
anchor: new THREE.Vector3(0.31, -0.35, 0.44),
color: "#dd8c53",
dx: 210,
dy: 68,
mobileDx: 132
},
{
group: monocot,
title: "Embryo",
detail: "Coleoptile (shoot) + radicle (root)",
anchor: new THREE.Vector3(0.68, 0.42, 0.48),
color: "#8bd59c",
dx: -42,
dy: 103,
mobileDx: -28
}
];
const svgNS = "http://www.w3.org/2000/svg";
const callouts = [];
labelDefinitions.forEach((definition) => {
const element = document.createElement("div");
element.className = "callout";
element.style.setProperty("--accent", definition.color);
element.innerHTML = `
<strong>${definition.title}</strong>
<span>${definition.detail}</span>
`;
stage.appendChild(element);
const line = document.createElementNS(svgNS, "line");
line.setAttribute("class", "leader-line");
line.setAttribute("stroke", definition.color);
leaders.appendChild(line);
const dot = document.createElementNS(svgNS, "circle");
dot.setAttribute("class", "anchor-dot");
dot.setAttribute("r", "4");
dot.setAttribute("fill", definition.color);
leaders.appendChild(dot);
callouts.push({ ...definition, element, line, dot });
});
let isMobile = window.innerWidth < 680;
let rotationX = -0.055;
let rotationY = 0;
let dragging = false;
let dragX = 0;
let dragY = 0;
let startRotationX = 0;
let startRotationY = 0;
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
isMobile = width < 680;
renderer.setSize(width, height, false);
if (isMobile) {
const viewHeight = 9.3;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.left = (-viewHeight * width) / height / 2;
camera.right = (viewHeight * width) / height / 2;
dicot.position.set(0, 1.47, 0);
monocot.position.set(0, -1.62, 0.15);
dicot.scale.setScalar(0.76);
monocot.scale.setScalar(0.76);
} else {
const aspect = width / height;
const viewHeight = Math.max(6.65, 10.8 / aspect);
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
dicot.position.set(-2.48, -0.04, 0);
monocot.position.set(2.48, -0.04, 0);
dicot.scale.setScalar(0.96);
monocot.scale.setScalar(0.96);
}
camera.updateProjectionMatrix();
}
function projectLocal(group, localPoint) {
const worldPoint = group.localToWorld(localPoint.clone());
worldPoint.project(camera);
return {
x: (worldPoint.x * 0.5 + 0.5) * stage.clientWidth,
y: (-worldPoint.y * 0.5 + 0.5) * stage.clientHeight
};
}
function placeTag(element, group, localPoint) {
const point = projectLocal(group, localPoint);
element.style.left = `${point.x}px`;
element.style.top = `${point.y}px`;
}
function updateCallouts() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const spread = Math.min(1, width / 1050);
callouts.forEach((callout) => {
const point = projectLocal(callout.group, callout.anchor);
const dx = isMobile
? callout.mobileDx
: callout.dx * spread;
const dy = callout.dy;
const boxWidth = callout.element.offsetWidth;
const boxHeight = callout.element.offsetHeight;
const left = THREE.MathUtils.clamp(
point.x + dx,
8,
Math.max(8, width - boxWidth - 8)
);
const top = THREE.MathUtils.clamp(
point.y + dy,
8,
Math.max(8, height - boxHeight - 8)
);
callout.element.style.left = `${left}px`;
callout.element.style.top = `${top}px`;
const centerX = left + boxWidth / 2;
const centerY = top + boxHeight / 2;
const lineToLeft = point.x < centerX;
const endX = lineToLeft ? left + boxWidth : left;
const endY = top + Math.min(boxHeight / 2, 28);
callout.line.setAttribute("x1", point.x);
callout.line.setAttribute("y1", point.y);
callout.line.setAttribute("x2", endX);
callout.line.setAttribute("y2", endY);
callout.dot.setAttribute("cx", point.x);
callout.dot.setAttribute("cy", point.y);
});
placeTag(tagA, dicot, new THREE.Vector3(0, 2.18, 0));
placeTag(tagB, monocot, new THREE.Vector3(0, 2.28, 0));
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
startRotationX = rotationX;
startRotationY = rotationY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - dragX;
const deltaY = event.clientY - dragY;
rotationY = startRotationY + deltaX * 0.006;
rotationX = THREE.MathUtils.clamp(
startRotationX + deltaY * 0.003,
-0.25,
0.22
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
function resetView() {
rotationX = -0.055;
rotationY = 0;
}
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
window.addEventListener("resize", resize);
resize();
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
const floatAmount = reducedMotion ? 0 : Math.sin(time * 0.8) * 0.025;
models.position.y = floatAmount;
models.rotation.x = rotationX;
models.rotation.y = rotationY;
updateCallouts();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```