Prompt specification
Build or customize the Three.js 3D scene "Fruit branch support contact" 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: Fruit branch support contact
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fruit-branch-support-contact-x1089
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: fruit branch support contact. Show a young fruit tree branch with several modeled fruits and a forked prop beneath it; expose the support contact and branch attachment clearly.
Working Three.js Starter (fruit-branch-support-contact-x1089):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fruit Branch — Support Contact Study</title>
<style>
:root {
--ink: #18302d;
--muted: #61716d;
--paper: #edf3ef;
--coral: #f26749;
--teal: #159d96;
--line: rgba(24, 48, 45, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
isolation: isolate;
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
z-index: 0;
}
.masthead {
position: absolute;
z-index: 5;
top: 28px;
left: 30px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 29px;
height: 2px;
background: var(--teal);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 750;
}
.subtitle {
margin: 12px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.view-panel {
position: absolute;
z-index: 5;
right: 24px;
top: 24px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(255,255,255,0.72);
border-radius: 13px;
background: rgba(242, 247, 244, 0.78);
box-shadow: 0 12px 35px rgba(39, 64, 59, 0.11);
backdrop-filter: blur(14px);
}
.view-panel button {
appearance: none;
border: 0;
border-radius: 9px;
padding: 9px 12px;
color: #52635f;
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.025em;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.view-panel button:hover {
background: rgba(21, 157, 150, 0.09);
color: var(--teal);
}
.view-panel button.active {
color: white;
background: var(--teal);
}
.view-panel button:active { transform: translateY(1px); }
#leaders {
position: absolute;
inset: 0;
z-index: 3;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders path {
fill: none;
stroke-width: 1.4;
stroke-dasharray: 4 4;
vector-effect: non-scaling-stroke;
}
#leaders circle {
stroke: white;
stroke-width: 2;
vector-effect: non-scaling-stroke;
}
.callout {
position: absolute;
z-index: 4;
width: 180px;
padding: 11px 13px 12px;
border: 1px solid rgba(255,255,255,0.88);
border-radius: 12px;
background: rgba(246, 249, 247, 0.9);
box-shadow: 0 12px 28px rgba(39, 64, 59, 0.13);
backdrop-filter: blur(12px);
transform: translate(-50%, -50%);
pointer-events: none;
}
.callout::before {
content: "";
display: block;
width: 21px;
height: 3px;
margin-bottom: 8px;
border-radius: 3px;
background: var(--accent);
}
.callout strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
letter-spacing: -0.01em;
}
.callout span {
display: block;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
#contactCallout { --accent: var(--coral); }
#attachmentCallout { --accent: var(--teal); }
.legend {
position: absolute;
z-index: 5;
left: 28px;
bottom: 25px;
display: flex;
align-items: center;
gap: 17px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,0.7);
border-radius: 11px;
background: rgba(242, 247, 244, 0.75);
box-shadow: 0 8px 22px rgba(39, 64, 59, 0.08);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
.swatch.contact { background: var(--coral); }
.swatch.attachment { background: var(--teal); }
.swatch.wood { background: #b97a43; }
.hint {
position: absolute;
z-index: 5;
right: 28px;
bottom: 27px;
color: rgba(24, 48, 45, 0.62);
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
}
@media (max-width: 700px) {
.masthead {
top: 18px;
left: 18px;
max-width: 245px;
}
.subtitle { display: none; }
.view-panel {
top: auto;
right: 14px;
bottom: 67px;
flex-direction: column;
}
.view-panel button { padding: 8px 10px; }
.legend {
left: 14px;
bottom: 14px;
gap: 10px;
}
.hint { display: none; }
.callout {
width: 145px;
padding: 9px 10px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive stylized fruit branch support scene">
<svg id="leaders" aria-hidden="true">
<path id="contactLeader"></path>
<circle id="contactAnchor" r="4.5"></circle>
<path id="attachmentLeader"></path>
<circle id="attachmentAnchor" r="4.5"></circle>
</svg>
<div id="contactCallout" class="callout">
<strong>Support contact</strong>
<span>Orange elastomer pad transfers the branch load into the fork.</span>
</div>
<div id="attachmentCallout" class="callout">
<strong>Branch attachment</strong>
<span>Teal collar marks the branch collar at the tree union.</span>
</div>
</main>
<header class="masthead">
<div class="eyebrow">Botanical support study</div>
<h1>Fruit branch<br>contact points</h1>
<p class="subtitle">
A young fruiting branch, temporarily carried by a forked timber prop.
Contact surfaces and the living branch union are isolated for inspection.
</p>
</header>
<nav class="view-panel" aria-label="Camera views">
<button class="active" data-view="overview">Overview</button>
<button data-view="contact">Support detail</button>
<button data-view="attachment">Attachment detail</button>
</nav>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="swatch contact"></span>support pad</div>
<div class="legend-item"><span class="swatch attachment"></span>branch collar</div>
<div class="legend-item"><span class="swatch wood"></span>forked prop</div>
</div>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · SHIFT-DRAG TO PAN</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.getElementById("stage");
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;
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e5);
scene.fog = new THREE.Fog(0xdce8e5, 9, 18);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.05,
40
);
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf5fff8, 0x6d776c, 2.15));
const key = new THREE.DirectionalLight(0xfff4dc, 3.2);
key.position.set(-4.5, 7, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 18;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xb8e9e2, 1.15);
fill.position.set(5, 3, -4);
scene.add(fill);
const rim = new THREE.PointLight(0xff9b75, 16, 8, 2);
rim.position.set(0.4, 3.1, 2.1);
scene.add(rim);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const barkMaterial = new THREE.MeshStandardMaterial({
color: 0x74462f,
roughness: 0.82,
metalness: 0
});
const barkLightMaterial = new THREE.MeshStandardMaterial({
color: 0x96613c,
roughness: 0.78
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0xc58a4e,
roughness: 0.7
});
const woodEndMaterial = new THREE.MeshStandardMaterial({
color: 0xe0ad6e,
roughness: 0.78
});
const padMaterial = new THREE.MeshStandardMaterial({
color: 0xf26749,
roughness: 0.55,
emissive: 0x7c1608,
emissiveIntensity: 0.16
});
const padSecondaryMaterial = new THREE.MeshStandardMaterial({
color: 0xe99754,
roughness: 0.65
});
const contactRingMaterial = new THREE.MeshStandardMaterial({
color: 0xff8b63,
emissive: 0xf04e25,
emissiveIntensity: 0.85,
roughness: 0.35
});
const collarMaterial = new THREE.MeshStandardMaterial({
color: 0x21b8ad,
emissive: 0x075c56,
emissiveIntensity: 0.42,
roughness: 0.34
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x3f8f55,
roughness: 0.68,
side: THREE.DoubleSide
});
const leafLightMaterial = new THREE.MeshStandardMaterial({
color: 0x76ae58,
roughness: 0.72,
side: THREE.DoubleSide
});
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
function taperedTube(
points,
startRadius,
endRadius,
material,
tubularSegments = 48,
radialSegments = 10
) {
const curve = new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p)),
false,
"catmullrom",
0.45
);
const frames = curve.computeFrenetFrames(tubularSegments, false);
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= tubularSegments; i++) {
const t = i / tubularSegments;
const point = curve.getPointAt(t);
const radius = THREE.MathUtils.lerp(startRadius, endRadius, t);
for (let j = 0; j <= radialSegments; j++) {
const v = j / radialSegments * Math.PI * 2;
const sin = Math.sin(v);
const cos = Math.cos(v);
const normal = frames.normals[i];
const binormal = frames.binormals[i];
const vertex = new THREE.Vector3()
.copy(point)
.addScaledVector(normal, radius * cos)
.addScaledVector(binormal, radius * sin);
positions.push(vertex.x, vertex.y, vertex.z);
uvs.push(t, j / radialSegments);
}
}
for (let i = 1; i <= tubularSegments; i++) {
for (let j = 1; j <= radialSegments; j++) {
const a = (radialSegments + 1) * (i - 1) + (j - 1);
const b = (radialSegments + 1) * i + (j - 1);
const c = (radialSegments + 1) * i + j;
const d = (radialSegments + 1) * (i - 1) + j;
indices.push(a, b, d);
indices.push(b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return { mesh, curve };
}
function cylinderBetween(a, b, radiusA, radiusB, material, segments = 12) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radiusB,
radiusA,
length,
segments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function makeLeaf(position, rotation, scale = 1, light = false) {
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.quadraticCurveTo(0.17, 0.12, 0.43, 0);
shape.quadraticCurveTo(0.20, -0.12, 0, 0);
const geometry = new THREE.ShapeGeometry(shape, 10);
const mesh = new THREE.Mesh(
geometry,
light ? leafLightMaterial : leafMaterial
);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.scale.setScalar(scale);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Display platform
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xd8e3df,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.13;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(4.25, 4.38, 0.12, 96),
new THREE.MeshStandardMaterial({
color: 0xeaf0eb,
roughness: 0.93
})
);
platform.position.set(-0.1, -0.06, 0);
platform.receiveShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(4.03, 0.009, 6, 128),
new THREE.MeshBasicMaterial({
color: 0x9eb5af,
transparent: true,
opacity: 0.55
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.set(-0.1, 0.006, 0);
scene.add(platformRing);
// ---------------------------------------------------------------------
// Young tree trunk and principal fruiting branch
// ---------------------------------------------------------------------
const trunk = taperedTube(
[
[-2.36, 0.02, 0],
[-2.25, 0.62, -0.01],
[-2.08, 1.25, 0.01],
[-1.88, 1.78, 0],
[-1.70, 2.25, 0],
[-1.56, 2.72, -0.02]
],
0.27,
0.115,
barkMaterial,
64,
12
);
const branch = taperedTube(
[
[-1.76, 2.27, 0.00],
[-1.34, 2.41, 0.025],
[-0.78, 2.47, 0.018],
[-0.18, 2.51, 0.02],
[0.43, 2.59, 0.025],
[1.08, 2.67, 0.05],
[1.58, 2.59, 0.075],
[2.04, 2.76, 0.09]
],
0.19,
0.075,
barkMaterial,
72,
12
);
// Root flares make the young tree read as rooted rather than cut off.
taperedTube(
[[-2.36, 0.12, 0], [-2.55, 0.045, 0.08], [-2.78, 0.025, 0.12]],
0.13, 0.025, barkMaterial, 24, 8
);
taperedTube(
[[-2.36, 0.13, 0], [-2.18, 0.05, -0.16], [-2.08, 0.025, -0.29]],
0.12, 0.025, barkMaterial, 24, 8
);
taperedTube(
[[-2.38, 0.18, 0], [-2.42, 0.06, 0.32], [-2.50, 0.025, 0.48]],
0.10, 0.02, barkMaterial, 24, 8
);
// Rounded branch union.
const attachmentJoint = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 24, 18),
barkLightMaterial
);
attachmentJoint.position.set(-1.70, 2.29, 0.015);
attachmentJoint.scale.set(1.05, 0.82, 0.92);
attachmentJoint.castShadow = true;
scene.add(attachmentJoint);
// Teal branch-collar marker.
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.205, 0.024, 10, 48),
collarMaterial
);
collar.position.set(-1.60, 2.35, 0.015);
const collarTangent = branch.curve.getTangentAt(0.025).normalize();
collar.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
collarTangent
);
collar.castShadow = true;
scene.add(collar);
// ---------------------------------------------------------------------
// Forked timber support prop
// ---------------------------------------------------------------------
const propBase = new THREE.Vector3(0.04, 0.02, 0.07);
const propSplit = new THREE.Vector3(0.04, 1.48, 0.08);
const leftContact = new THREE.Vector3(-0.22, 2.39, 0.13);
const rightContact = new THREE.Vector3(0.31, 2.40, 0.12);
cylinderBetween(
propBase.toArray(),
propSplit.toArray(),
0.145,
0.125,
woodMaterial,
16
);
cylinderBetween(
propSplit.toArray(),
leftContact.toArray(),
0.125,
0.095,
woodMaterial,
14
);
cylinderBetween(
propSplit.toArray(),
rightContact.toArray(),
0.125,
0.095,
woodMaterial,
14
);
const propFoot = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.33, 0.12, 28),
woodEndMaterial
);
propFoot.position.set(0.04, 0.055, 0.07);
propFoot.castShadow = true;
propFoot.receiveShadow = true;
scene.add(propFoot);
const splitJoint = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 20, 14),
woodEndMaterial
);
splitJoint.position.copy(propSplit);
splitJoint.scale.set(1, 0.9, 1);
splitJoint.castShadow = true;
scene.add(splitJoint);
const splitBand = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.022, 8, 32),
new THREE.MeshStandardMaterial({
color: 0x966038,
roughness: 0.85
})
);
splitBand.rotation.x = Math.PI / 2;
splitBand.position.set(0.04, 1.44, 0.08);
scene.add(splitBand);
// Orange bearing pads. The left pad is the inspected primary contact.
const leftPad = new THREE.Mesh(
new THREE.SphereGeometry(0.15, 24, 16),
padMaterial
);
leftPad.position.copy(leftContact);
leftPad.scale.set(0.94, 0.46, 0.86);
leftPad.castShadow = true;
scene.add(leftPad);
const rightPad = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 24, 16),
padSecondaryMaterial
);
rightPad.position.copy(rightContact);
rightPad.scale.set(0.94, 0.46, 0.86);
rightPad.castShadow = true;
scene.add(rightPad);
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.125, 0.014, 8, 40),
contactRingMaterial
);
contactRing.position.set(-0.22, 2.39, 0.275);
scene.add(contactRing);
// Sparse timber grain on the front of the upright.
const grainMaterial = new THREE.LineBasicMaterial({
color: 0x8b5933,
transparent: true,
opacity: 0.65
});
[
[-0.055, 0.32, -0.02],
[0.025, 0.27, 0.035],
[0.09, 0.31, -0.015]
].forEach((offset, index) => {
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.04 + offset[0], 0.28 + index * 0.03, 0.219),
new THREE.Vector3(0.04 + offset[0] * 1.25, 0.66, 0.222),
new THREE.Vector3(0.04 + offset[0] * 0.65, 1.03, 0.219),
new THREE.Vector3(0.04 + offset[0] * 1.1, 1.31, 0.214)
]);
const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(32));
scene.add(new THREE.Line(geometry, grainMaterial));
});
// ---------------------------------------------------------------------
// Procedural fruit geometry
// ---------------------------------------------------------------------
const appleProfile = [
[0.00, -0.62],
[0.17, -0.60],
[0.37, -0.43],
[0.48, -0.13],
[0.45, 0.17],
[0.34, 0.39],
[0.17, 0.49],
[0.075, 0.38],
[0.13, 0.55],
[0.00, 0.58]
].map(p => new THREE.Vector2(...p));
const pearProfile = [
[0.00, -0.72],
[0.15, -0.68],
[0.26, -0.43],
[0.37, -0.06],
[0.32, 0.24],
[0.20, 0.46],
[0.16, 0.68],
[0.00, 0.77]
].map(p => new THREE.Vector2(...p));
function makeFruit(kind, center, branchPoint, color, leafLight = false) {
const isPear = kind === "pear";
const topY = isPear ? 0.77 : 0.58;
const profile = isPear ? pearProfile : appleProfile;
const material = new THREE.MeshPhysicalMaterial({
color,
roughness: isPear ? 0.54 : 0.36,
metalness: 0,
clearcoat: 0.32,
clearcoatRoughness: 0.32
});
const fruit = new THREE.Mesh(
new THREE.LatheGeometry(profile, 36),
material
);
fruit.position.set(...center);
fruit.castShadow = true;
fruit.receiveShadow = true;
scene.add(fruit);
// Twig from branch to fruit.
const fruitTop = [
center[0],
center[1] + topY - 0.02,
center[2]
];
const twig = taperedTube(
[
branchPoint,
[
(branchPoint[0] + fruitTop[0]) * 0.5,
Math.max(branchPoint[1], fruitTop[1]) + 0.12,
(branchPoint[2] + fruitTop[2]) * 0.5
],
fruitTop
],
0.047,
0.024,
barkLightMaterial,
28,
8
);
// Short stem above the fruit.
taperedTube(
[
[center[0], center[1] + topY - 0.025, center[2]],
[center[0] + 0.025, center[1] + topY + 0.16, center[2]],
[center[0] + 0.07, center[1] + topY + 0.23, center[2]]
],
0.033,
0.018,
barkMaterial,
16,
7
);
makeLeaf(
[
center[0] + 0.045,
center[1] + topY + 0.12,
center[2] + 0.025
],
[0.35, -0.55, -0.45],
0.72,
leafLight
);
return { fruit, twig };
}
makeFruit(
"apple",
[-0.67, 1.73, 0.43],
[-0.90, 2.47, 0.02],
0xe85b43,
false
);
makeFruit(
"pear",
[0.37, 1.57, -0.47],
[0.05, 2.56, 0.02],
0xc7c94c,
true
);
makeFruit(
"apple",
[0.94, 1.92, 0.40],
[0.78, 2.65, 0.04],
0xd9423e,
true
);
makeFruit(
"pear",
[1.48, 1.79, -0.39],
[1.30, 2.63, 0.05],
0xa8be50,
false
);
makeFruit(
"apple",
[-1.18, 1.64, -0.30],
[-1.25, 2.44, 0.02],
0xf06a45,
false
);
// Additional young shoots and leaves.
taperedTube(
[[-1.47, 2.43, 0.01], [-1.52, 2.78, 0.02], [-1.33, 2.98, 0.04]],
0.055, 0.018, barkLightMaterial, 24, 8
);
taperedTube(
[[1.58, 2.61, 0.07], [1.83, 2.88, 0.10], [2.07, 2.91, 0.12]],
0.045, 0.016, barkLightMaterial, 24, 8
);
makeLeaf([-1.43, 2.72, 0.08], [0.3, 0.55, -0.65], 0.9, true);
makeLeaf([-1.63, 2.56, 0.13], [0.1, -0.4, 0.7], 0.76, false);
makeLeaf([0.47, 2.73, 0.12], [0.15, 0.4, -0.35], 0.83, true);
makeLeaf([1.16, 2.78, 0.16], [0.45, -0.2, 0.6], 0.76, false);
makeLeaf([1.77, 2.77, 0.17], [0.1, 0.7, -0.3], 0.78, true);
makeLeaf([2.00, 2.88, 0.18], [0.25, 0.25, 0.8], 0.64, false);
makeLeaf([-0.16, 2.61, 0.12], [0.2, -0.6, 0.4], 0.72, true);
// ---------------------------------------------------------------------
// Camera controls — implemented without Three.js addons
// ---------------------------------------------------------------------
const views = {
overview: {
target: new THREE.Vector3(-0.12, 1.66, 0),
radius: 7.15,
theta: 0.25,
phi: 1.12
},
contact: {
target: new THREE.Vector3(-0.05, 2.13, 0.06),
radius: 3.05,
theta: 0.18,
phi: 1.27
},
attachment: {
target: new THREE.Vector3(-1.54, 2.24, 0.04),
radius: 2.85,
theta: 0.46,
phi: 1.22
}
};
const current = {
target: views.overview.target.clone(),
radius: views.overview.radius,
theta: views.overview.theta,
phi: views.overview.phi
};
const desired = {
target: views.overview.target.clone(),
radius: views.overview.radius,
theta: views.overview.theta,
phi: views.overview.phi
};
function applyCamera() {
const spherical = new THREE.Spherical(
current.radius,
current.phi,
current.theta
);
camera.position.setFromSpherical(spherical).add(current.target);
camera.lookAt(current.target);
camera.updateMatrixWorld();
}
function setView(name) {
const view = views[name];
desired.target.copy(view.target);
desired.radius = view.radius;
desired.theta = view.theta;
desired.phi = view.phi;
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let dragButton = 0;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragButton === 2 || event.shiftKey) {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const panScale = current.radius * 0.0014;
desired.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.42,
1.47
);
}
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
2.15,
10.5
);
}, { passive: false });
// ---------------------------------------------------------------------
// Projected HTML annotations
// ---------------------------------------------------------------------
const annotations = [
{
point: new THREE.Vector3(-0.22, 2.39, 0.29),
element: document.getElementById("contactCallout"),
path: document.getElementById("contactLeader"),
anchor: document.getElementById("contactAnchor"),
stroke: "#f26749",
fill: "#f26749",
offset: [145, -68]
},
{
point: new THREE.Vector3(-1.61, 2.35, 0.25),
element: document.getElementById("attachmentCallout"),
path: document.getElementById("attachmentLeader"),
anchor: document.getElementById("attachmentAnchor"),
stroke: "#159d96",
fill: "#159d96",
offset: [-145, -76]
}
];
function updateAnnotations() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const narrow = width < 700;
annotations.forEach(annotation => {
const projected = annotation.point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
annotation.element.style.opacity = "0";
annotation.path.style.opacity = "0";
annotation.anchor.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const offsetX = narrow ? annotation.offset[0] * 0.62 : annotation.offset[0];
const offsetY = narrow ? annotation.offset[1] - 20 : annotation.offset[1];
const labelX = x + offsetX;
const labelY = y + offsetY;
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
annotation.element.style.opacity = "1";
annotation.path.setAttribute(
"d",
`M ${x.toFixed(1)} ${y.toFixed(1)} L ${labelX.toFixed(1)} ${labelY.toFixed(1)}`
);
annotation.path.style.stroke = annotation.stroke;
annotation.path.style.opacity = "0.9";
annotation.anchor.setAttribute("cx", x.toFixed(1));
annotation.anchor.setAttribute("cy", y.toFixed(1));
annotation.anchor.setAttribute("fill", annotation.fill);
annotation.anchor.style.opacity = "1";
});
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
const svg = document.getElementById("leaders");
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const damping = 1 - Math.pow(0.0008, 1 / 60);
current.target.lerp(desired.target, damping);
current.radius = THREE.MathUtils.lerp(
current.radius,
desired.radius,
damping
);
current.theta = THREE.MathUtils.lerp(
current.theta,
desired.theta,
damping
);
current.phi = THREE.MathUtils.lerp(
current.phi,
desired.phi,
damping
);
applyCamera();
updateAnnotations();
renderer.render(scene, camera);
}
applyCamera();
animate();
</script>
</body>
</html>
```