Prompt specification
Build or customize the Three.js 3D scene "Hooked fruit and winged seed" 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: Hooked fruit and winged seed
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hooked-fruit-and-winged-seed-x0781
Scene Description Prompt:
Show enlarged hooked fruit and winged seed models beside scale references; emphasize attachment hooks and aerodynamic surface area as distinct structural features with different functions. Use Three.js from cdnjs in a single HTML file, with stylized solid shapes.
Working Three.js Starter (hooked-fruit-and-winged-seed-x0781):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seed Dispersal — Hooks vs. Wings</title>
<style>
:root {
--ink: #24332f;
--muted: #62706b;
--paper: #eef1e9;
--hook: #ed694c;
--wing: #20a797;
--air: #3aa9c8;
--line: rgba(36, 51, 47, 0.16);
}
* {
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;
}
body {
user-select: none;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
header {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
max-width: 570px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 29px;
height: 3px;
content: "";
background: linear-gradient(
90deg,
var(--hook) 0 48%,
var(--wing) 52% 100%
);
border-radius: 10px;
}
h1 {
margin: 0;
font-size: clamp(32px, 4vw, 58px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.96;
}
header p {
max-width: 470px;
margin: 14px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.study-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.55);
color: #53635d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.study-badge span {
width: 6px;
height: 6px;
border-radius: 50%;
background: #52635d;
}
#camera-hint {
position: fixed;
top: 30px;
right: 32px;
z-index: 5;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.58);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(10px);
}
#annotation-layer {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
width: 218px;
padding: 12px 13px 13px;
border: 1px solid rgba(36, 51, 47, 0.13);
border-left: 4px solid var(--feature);
border-radius: 9px;
background: rgba(255, 255, 255, 0.91);
box-shadow: 0 12px 34px rgba(38, 50, 46, 0.12);
opacity: 0;
transform: translate(-50%, calc(-100% - 22px));
transition: opacity 180ms ease;
backdrop-filter: blur(10px);
}
.annotation::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 22px;
content: "";
background: var(--feature);
}
.annotation::before {
position: absolute;
top: calc(100% + 19px);
left: calc(50% - 4px);
width: 8px;
height: 8px;
content: "";
border: 2px solid white;
border-radius: 50%;
background: var(--feature);
box-shadow: 0 0 0 1px var(--feature);
}
.annotation.visible {
opacity: 1;
}
.annotation .number {
color: var(--feature);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.annotation strong {
display: block;
margin-top: 4px;
font-size: 13px;
letter-spacing: -0.01em;
}
.annotation small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
#hook-annotation {
--feature: var(--hook);
}
#wing-annotation {
--feature: var(--wing);
}
#legend {
position: fixed;
bottom: 28px;
left: 32px;
z-index: 5;
display: flex;
align-items: stretch;
gap: 10px;
pointer-events: none;
}
.feature-card {
width: 278px;
padding: 14px 15px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.72);
box-shadow: 0 10px 30px rgba(38, 50, 46, 0.07);
backdrop-filter: blur(10px);
}
.feature-card .tag {
display: flex;
align-items: center;
gap: 8px;
color: var(--feature);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.feature-card .tag i {
display: inline-block;
width: 18px;
height: 4px;
border-radius: 4px;
background: var(--feature);
}
.feature-card h2 {
margin: 8px 0 5px;
font-size: 16px;
letter-spacing: -0.025em;
}
.feature-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#hook-card {
--feature: var(--hook);
}
#wing-card {
--feature: var(--wing);
}
#function-divider {
display: grid;
width: 42px;
place-items: center;
color: #73817c;
font-size: 20px;
font-weight: 300;
}
#controls {
position: fixed;
right: 32px;
bottom: 28px;
z-index: 6;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 10px 30px rgba(38, 50, 46, 0.08);
backdrop-filter: blur(12px);
}
button {
padding: 9px 12px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, color 150ms ease,
transform 150ms ease;
}
button:hover {
background: #e4e9e1;
}
button:active {
transform: translateY(1px);
}
button.primary {
background: var(--ink);
color: white;
}
button.primary:hover {
background: #354740;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--paper);
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
header {
top: 20px;
left: 20px;
max-width: 440px;
}
#camera-hint {
top: 20px;
right: 20px;
}
#legend {
left: 20px;
bottom: 20px;
}
.feature-card {
width: 235px;
}
#controls {
right: 20px;
bottom: 20px;
}
}
@media (max-width: 680px) {
header {
right: 18px;
}
header p {
display: none;
}
.study-badge {
margin-top: 12px;
}
#camera-hint {
display: none;
}
#legend {
right: 14px;
bottom: 74px;
left: 14px;
gap: 6px;
}
.feature-card {
flex: 1;
width: auto;
padding: 10px;
}
.feature-card h2 {
font-size: 13px;
}
.feature-card p {
font-size: 10px;
}
#function-divider {
display: none;
}
#controls {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: center;
}
button {
flex: 1;
padding: 9px 6px;
font-size: 9px;
}
.annotation {
width: 168px;
padding: 9px 10px;
}
.annotation small {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="loading">Building comparative morphology…</div>
<header>
<div class="eyebrow">Comparative seed dispersal</div>
<h1>Two ways to<br>leave the parent.</h1>
<p>
A hooked fruit grips an animal. A winged seed uses a broad surface
to resist the air. The structures solve different transport problems.
</p>
<div class="study-badge">
<span></span>
Enlarged models · centimeter references
</div>
</header>
<div id="camera-hint">Drag orbit · Wheel zoom · Shift-drag pan</div>
<div id="annotation-layer">
<div id="hook-annotation" class="annotation">
<div class="number">01 · Attachment structure</div>
<strong>Curved hook / grip</strong>
<small>The tip catches fur and anchors the fruit to a moving carrier.</small>
</div>
<div id="wing-annotation" class="annotation">
<div class="number">02 · Aerodynamic structure</div>
<strong>Broad wing / drag</strong>
<small>Planar surface area increases air resistance and slows descent.</small>
</div>
</div>
<div id="legend">
<div class="feature-card" id="hook-card">
<div class="tag"><i></i>Hook · Animal attachment</div>
<h2>Grip and carry</h2>
<p>Hook geometry mechanically engages fur instead of using airflow.</p>
</div>
<div id="function-divider">≠</div>
<div class="feature-card" id="wing-card">
<div class="tag"><i></i>Wing · Aerodynamic drag</div>
<h2>Slow and drift</h2>
<p>Wing area acts against moving air, extending airborne travel.</p>
</div>
</div>
<div id="controls">
<button id="focus-hook">Hook</button>
<button id="focus-wing">Wing</button>
<button id="reset-view" class="primary">Compare</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeef1e9);
scene.fog = new THREE.Fog(0xeef1e9, 15, 30);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive comparison of a hooked fruit and a winged seed"
);
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf8fff8, 0x71695d, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff5df, 3.2);
keyLight.position.set(-5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc6e9ff, 1.25);
fillLight.position.set(7, 5, -6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffffff, 0.8);
rimLight.position.set(0, 4, -8);
scene.add(rimLight);
const material = {
ground: new THREE.MeshStandardMaterial({
color: 0xdfe5dc,
roughness: 0.95
}),
plinth: new THREE.MeshStandardMaterial({
color: 0xf4f0e6,
roughness: 0.76
}),
fruitBody: new THREE.MeshStandardMaterial({
color: 0x795038,
roughness: 0.76
}),
hook: new THREE.MeshStandardMaterial({
color: 0xed694c,
roughness: 0.48,
metalness: 0.03
}),
seedBody: new THREE.MeshStandardMaterial({
color: 0x4d382e,
roughness: 0.68
}),
wing: new THREE.MeshStandardMaterial({
color: 0x20a797,
roughness: 0.58
}),
wingVein: new THREE.MeshStandardMaterial({
color: 0x08786f,
roughness: 0.55
}),
air: new THREE.MeshStandardMaterial({
color: 0x3aa9c8,
roughness: 0.45
}),
metal: new THREE.MeshStandardMaterial({
color: 0x7b8983,
roughness: 0.38,
metalness: 0.48
}),
ruler: new THREE.MeshStandardMaterial({
color: 0xfbf8ee,
roughness: 0.78
}),
tick: new THREE.MeshStandardMaterial({
color: 0x44534e,
roughness: 0.6
})
};
function mesh(geometry, mat, position, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
if (position) object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function makeTextSprite(
text,
color = "#42524c",
width = 0.55,
height = 0.25
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = color;
ctx.font = "800 74px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 10;
return sprite;
}
function makePlaque(title, subtitle, accent, x, z, width = 3.6) {
const canvas = document.createElement("canvas");
canvas.width = 1200;
canvas.height = 300;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f7f3e9";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 24, canvas.height);
ctx.fillStyle = accent;
ctx.font = "900 52px Arial, sans-serif";
ctx.fillText(title, 72, 92);
ctx.fillStyle = "#53615c";
ctx.font = "600 32px Arial, sans-serif";
ctx.fillText(subtitle, 72, 164);
ctx.fillStyle = "#7a8782";
ctx.font = "700 25px Arial, sans-serif";
ctx.fillText("ENLARGED MODEL • SCALE REFERENCE: CM", 72, 232);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const plaque = mesh(
new THREE.PlaneGeometry(width, width * 0.25),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
}),
[x, 0.255, z]
);
plaque.castShadow = false;
return plaque;
}
function makeRuler(x) {
const group = new THREE.Group();
group.position.set(x, 0, 0.85);
scene.add(group);
const board = mesh(
new THREE.BoxGeometry(0.52, 3.45, 0.12),
material.ruler,
[0, 2.13, 0],
group
);
const bottom = 0.48;
const height = 3.3;
for (let i = 0; i <= 12; i++) {
const major = i % 4 === 0;
const tickWidth = major ? 0.34 : 0.19;
mesh(
new THREE.BoxGeometry(tickWidth, 0.026, 0.025),
material.tick,
[
major ? -0.04 : -0.13,
bottom + (i / 12) * height,
0.078
],
group
);
if (major) {
const number = makeTextSprite(
String(i / 4),
"#52615b",
0.28,
0.16
);
number.position.set(0.31, bottom + (i / 12) * height, 0.1);
group.add(number);
}
}
const cm = makeTextSprite("cm", "#52615b", 0.32, 0.18);
cm.position.set(0, 3.86, 0.1);
group.add(cm);
const reference = makeTextSprite(
"REFERENCE",
"#73817c",
0.82,
0.13
);
reference.position.set(0, 0.27, 0.1);
group.add(reference);
return group;
}
function makeSupport(x, top, z = -0.04) {
const height = top - 0.48;
const rod = mesh(
new THREE.CylinderGeometry(0.035, 0.045, height, 16),
material.metal,
[x, 0.48 + height / 2, z]
);
rod.castShadow = true;
return rod;
}
// Ground and display plinths
const ground = mesh(
new THREE.PlaneGeometry(50, 50),
material.ground,
[0, -0.02, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
mesh(
new THREE.BoxGeometry(5.1, 0.48, 3.35),
material.plinth,
[-3.4, 0.23, 0]
);
mesh(
new THREE.BoxGeometry(5.35, 0.48, 3.35),
material.plinth,
[2.8, 0.23, 0]
);
makePlaque(
"HOOKED FRUIT",
"Curved attachment structure",
"#ed694c",
-3.4,
1.682,
3.55
);
makePlaque(
"WINGED SEED",
"Broad aerodynamic surface",
"#20a797",
2.8,
1.682,
3.55
);
makeRuler(-5.43);
makeRuler(0.55);
makeSupport(-3.45, 1.34);
makeSupport(1.75, 1.65);
// Hooked fruit
const fruitGroup = new THREE.Group();
fruitGroup.position.set(-3.45, 2.03, 0);
fruitGroup.rotation.set(-0.04, 0.25, -0.07);
scene.add(fruitGroup);
const fruitBody = mesh(
new THREE.SphereGeometry(1, 48, 32),
material.fruitBody,
[0, 0, 0],
fruitGroup
);
fruitBody.scale.set(0.69, 0.82, 0.69);
const stem = mesh(
new THREE.CylinderGeometry(0.075, 0.11, 0.42, 18),
material.seedBody,
[0, 0.86, 0],
fruitGroup
);
stem.rotation.z = -0.08;
const pickables = [];
const hookMeshes = [];
let hookAnchor = null;
for (let i = 0; i < 12; i++) {
const theta = (i / 12) * Math.PI * 2 + 0.17;
const baseY = -0.51 + (i % 4) * 0.31;
const radial = new THREE.Vector3(
Math.cos(theta),
0,
Math.sin(theta)
);
const points = [
radial.clone().multiplyScalar(0.55).setY(baseY),
radial.clone().multiplyScalar(0.92).setY(baseY + 0.03),
radial.clone().multiplyScalar(1.25).setY(baseY + 0.26),
radial.clone().multiplyScalar(0.96).setY(baseY + 0.53),
radial.clone().multiplyScalar(0.73).setY(baseY + 0.58)
];
const curve = new THREE.CatmullRomCurve3(points);
const hook = mesh(
new THREE.TubeGeometry(curve, 28, 0.066, 9, false),
material.hook,
[0, 0, 0],
fruitGroup
);
hook.userData.focus = "hook";
pickables.push(hook);
hookMeshes.push(hook);
const tip = mesh(
new THREE.SphereGeometry(0.077, 16, 12),
material.hook,
points[points.length - 1].toArray(),
fruitGroup
);
tip.scale.set(1, 1.25, 1);
if (i === 2) {
hookAnchor = new THREE.Object3D();
hookAnchor.position.copy(points[points.length - 1]);
fruitGroup.add(hookAnchor);
}
}
fruitBody.userData.focus = "hook";
pickables.push(fruitBody);
// Winged seed
const seedGroup = new THREE.Group();
seedGroup.position.set(2.0, 2.0, 0);
seedGroup.rotation.set(0.04, -0.12, -0.08);
scene.add(seedGroup);
const seedBody = mesh(
new THREE.SphereGeometry(1, 48, 32),
material.seedBody,
[-0.26, 0, 0],
seedGroup
);
seedBody.scale.set(0.57, 0.36, 0.35);
seedBody.userData.focus = "wing";
pickables.push(seedBody);
const wingShape = new THREE.Shape();
wingShape.moveTo(0, -0.18);
wingShape.bezierCurveTo(
0.88, -0.55,
2.26, -0.43,
3.16, 0.12
);
wingShape.bezierCurveTo(
2.26, 0.65,
0.88, 0.69,
0, 0.22
);
wingShape.closePath();
const wingGeometry = new THREE.ExtrudeGeometry(wingShape, {
depth: 0.12,
bevelEnabled: true,
bevelThickness: 0.045,
bevelSize: 0.045,
bevelSegments: 3,
steps: 1,
curveSegments: 24
});
const wing = mesh(
wingGeometry,
material.wing,
[0, 0, -0.06],
seedGroup
);
wing.userData.focus = "wing";
pickables.push(wing);
function addVein(points, radius = 0.017) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
return mesh(
new THREE.TubeGeometry(curve, 24, radius, 7, false),
material.wingVein,
[0, 0, 0],
seedGroup
);
}
addVein([
[0.05, 0.02, 0.17],
[0.78, 0.10, 0.17],
[1.66, 0.08, 0.17],
[2.53, 0.18, 0.17],
[3.08, 0.12, 0.17]
], 0.021);
addVein([
[0.72, 0.09, 0.17],
[1.04, -0.25, 0.17]
]);
addVein([
[1.40, 0.08, 0.17],
[1.83, -0.24, 0.17]
]);
addVein([
[2.08, 0.12, 0.17],
[2.58, -0.12, 0.17]
]);
// Surface-area bracket beneath the wing
const areaColor = new THREE.MeshStandardMaterial({
color: 0x168f83,
roughness: 0.5
});
mesh(
new THREE.BoxGeometry(2.55, 0.024, 0.024),
areaColor,
[1.54, -0.76, 0.03],
seedGroup
);
mesh(
new THREE.BoxGeometry(0.024, 0.17, 0.024),
areaColor,
[0.27, -0.70, 0.03],
seedGroup
);
mesh(
new THREE.BoxGeometry(0.024, 0.17, 0.024),
areaColor,
[2.81, -0.70, 0.03],
seedGroup
);
const areaLabel = makeTextSprite(
"DRAG AREA",
"#168f83",
0.83,
0.16
);
areaLabel.position.set(1.54, -0.95, 0.05);
seedGroup.add(areaLabel);
function makeAirArrow(x, y, z, length) {
const arrow = new THREE.Group();
arrow.position.set(x, y, z);
seedGroup.add(arrow);
const shaft = mesh(
new THREE.CylinderGeometry(0.024, 0.024, length, 12),
material.air,
[length / 2, 0, 0],
arrow
);
shaft.rotation.z = -Math.PI / 2;
const head = mesh(
new THREE.ConeGeometry(0.09, 0.24, 16),
material.air,
[length + 0.10, 0, 0],
arrow
);
head.rotation.z = -Math.PI / 2;
return arrow;
}
const airArrows = [
makeAirArrow(0.46, 0.86, 0.1, 0.62),
makeAirArrow(1.35, 1.00, 0.12, 0.72),
makeAirArrow(2.26, 0.82, 0.08, 0.62)
];
const wingAnchor = new THREE.Object3D();
wingAnchor.position.set(1.72, 0.38, 0.18);
seedGroup.add(wingAnchor);
// Direct camera controls: orbit, wheel zoom, shift/right-button pan,
// and two-finger pinch zoom. No addons are used.
const controls = {
target: new THREE.Vector3(0, 1.75, 0),
desiredTarget: new THREE.Vector3(0, 1.75, 0),
azimuth: 0.08,
desiredAzimuth: 0.08,
polar: 1.22,
desiredPolar: 1.22,
radius: 11.8,
desiredRadius: 11.8
};
const clamp = THREE.MathUtils.clamp;
const pointers = new Map();
let gestureMode = null;
let previousPinchDistance = 0;
let downX = 0;
let downY = 0;
let dragDistance = 0;
function resetView() {
controls.desiredTarget.set(0, 1.75, 0);
controls.desiredAzimuth = 0.08;
controls.desiredPolar = 1.22;
controls.desiredRadius = 11.8;
}
function focusFeature(feature) {
if (feature === "hook") {
controls.desiredTarget.set(-3.35, 2.0, 0);
controls.desiredAzimuth = 0.22;
controls.desiredPolar = 1.18;
controls.desiredRadius = 5.8;
} else {
controls.desiredTarget.set(2.45, 2.0, 0);
controls.desiredAzimuth = -0.18;
controls.desiredPolar = 1.18;
controls.desiredRadius = 6.0;
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
downX = event.clientX;
downY = event.clientY;
dragDistance = 0;
if (pointers.size === 1) {
gestureMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
} else if (pointers.size === 2) {
gestureMode = "pinch";
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[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.hypot(dx, dy);
if (gestureMode === "orbit" && pointers.size === 1) {
controls.desiredAzimuth -= dx * 0.006;
controls.desiredPolar = clamp(
controls.desiredPolar - dy * 0.005,
0.48,
1.48
);
} else if (gestureMode === "pan" && pointers.size === 1) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrix.extractBasis(right, up, new THREE.Vector3());
const factor = controls.radius * 0.0015;
controls.desiredTarget.addScaledVector(right, -dx * factor);
controls.desiredTarget.addScaledVector(up, dy * factor);
} else if (gestureMode === "pinch" && pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
controls.desiredRadius = clamp(
controls.desiredRadius *
(previousPinchDistance / Math.max(distance, 1)),
4.3,
18
);
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
const wasClick = dragDistance < 5;
pointers.delete(event.pointerId);
if (pointers.size === 0) {
gestureMode = null;
} else if (pointers.size === 1) {
gestureMode = "orbit";
}
if (wasClick && event.type === "pointerup") {
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2(
(event.clientX / innerWidth) * 2 - 1,
-(event.clientY / innerHeight) * 2 + 1
);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
focusFeature(hits[0].object.userData.focus);
}
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredRadius = clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
4.3,
18
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#focus-hook").addEventListener("click", () => {
focusFeature("hook");
});
document.querySelector("#focus-wing").addEventListener("click", () => {
focusFeature("wing");
});
document.querySelector("#reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
const annotations = [
{
element: document.querySelector("#hook-annotation"),
object: hookAnchor
},
{
element: document.querySelector("#wing-annotation"),
object: wingAnchor
}
];
const worldPoint = new THREE.Vector3();
function updateAnnotations() {
for (const annotation of annotations) {
worldPoint.set(0, 0, 0);
annotation.object.getWorldPosition(worldPoint);
worldPoint.project(camera);
const visible =
worldPoint.z > -1 &&
worldPoint.z < 1 &&
Math.abs(worldPoint.x) < 1.15 &&
Math.abs(worldPoint.y) < 1.15;
annotation.element.classList.toggle("visible", visible);
if (visible) {
const x = (worldPoint.x * 0.5 + 0.5) * innerWidth;
const y = (-worldPoint.y * 0.5 + 0.5) * innerHeight;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
}
}
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-8 * dt);
controls.azimuth = THREE.MathUtils.lerp(
controls.azimuth,
controls.desiredAzimuth,
damping
);
controls.polar = THREE.MathUtils.lerp(
controls.polar,
controls.desiredPolar,
damping
);
controls.radius = THREE.MathUtils.lerp(
controls.radius,
controls.desiredRadius,
damping
);
controls.target.lerp(controls.desiredTarget, damping);
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x +
controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y +
controls.radius * Math.cos(controls.polar),
controls.target.z +
controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
const time = clock.elapsedTime;
airArrows.forEach((arrow, index) => {
arrow.position.z =
0.08 +
Math.sin(time * 1.25 + index * 1.3) * 0.045;
});
updateAnnotations();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```