Prompt specification
Build or customize the Three.js 3D scene "Vine tendril around a trellis" 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: Vine tendril around a trellis
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/vine-tendril-around-a-trellis-x1113
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: vine tendril around a trellis. Model a vine segment with one curling tendril around a horizontal support and another unattached tendril; show plant and structure as separate connected systems. Return one self-contained HTML file.
Working Three.js Starter (vine-tendril-around-a-trellis-x1113):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vine & Trellis — Botanical Structure Study</title>
<style>
:root {
--ink: #19352d;
--muted: #5f746d;
--panel: rgba(248, 252, 249, 0.82);
--line: rgba(31, 67, 55, 0.14);
--plant: #4f8a48;
--structure: #b87942;
--shadow: 0 18px 50px rgba(33, 68, 57, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background:
radial-gradient(circle at 50% 32%, #f8fcf7 0%, #dcece5 52%, #b9d4cc 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.title-block {
position: fixed;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
z-index: 5;
}
.eyebrow {
margin-bottom: 9px;
color: #547269;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4.2vw, 58px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 335px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.control-panel {
position: fixed;
top: 28px;
right: 28px;
z-index: 10;
width: 268px;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.panel-heading strong {
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-heading span {
color: #80938c;
font-size: 10px;
}
.legend {
display: grid;
gap: 9px;
padding-bottom: 14px;
border-bottom: 1px solid var(--line);
}
.legend-row {
display: grid;
grid-template-columns: 10px 1fr;
gap: 9px;
align-items: start;
}
.legend-dot {
width: 8px;
height: 8px;
margin-top: 4px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7);
}
.legend-dot.plant {
background: var(--plant);
}
.legend-dot.structure {
background: var(--structure);
}
.legend-dot.link {
background: linear-gradient(90deg, var(--plant) 50%, var(--structure) 50%);
}
.legend-copy {
color: var(--ink);
font-size: 11px;
font-weight: 750;
line-height: 1.25;
}
.legend-copy small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 450;
}
.mode-label {
margin: 14px 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.modes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
button {
min-height: 34px;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 9px;
color: #496158;
background: rgba(255, 255, 255, 0.46);
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
color: var(--ink);
border-color: rgba(31, 67, 55, 0.28);
transform: translateY(-1px);
}
button.active {
color: #f8fff8;
border-color: #315d4e;
background: #315d4e;
}
button:focus-visible {
outline: 2px solid #73a590;
outline-offset: 2px;
}
.hint {
margin: 13px 0 0;
color: #7b8e87;
font-size: 9px;
line-height: 1.45;
text-align: center;
}
.scene-label {
position: fixed;
top: 0;
left: 0;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 999px;
color: #345047;
background: rgba(250, 253, 250, 0.84);
box-shadow: 0 7px 24px rgba(37, 73, 61, 0.11);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
pointer-events: none;
white-space: nowrap;
will-change: transform;
}
.scene-label::before {
content: "";
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--plant);
}
.scene-label.structure-label::before {
background: var(--structure);
}
.scene-label.free-label::before {
background: #91b85a;
}
[hidden] {
display: none !important;
}
.footer-note {
position: fixed;
bottom: 24px;
left: 30px;
z-index: 4;
display: flex;
align-items: center;
gap: 9px;
color: rgba(35, 66, 56, 0.72);
font-size: 10px;
font-weight: 650;
pointer-events: none;
}
.footer-note::before {
content: "";
width: 31px;
height: 1px;
background: rgba(35, 66, 56, 0.35);
}
@media (max-width: 760px) {
.title-block {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.control-panel {
top: 104px;
right: 14px;
width: 230px;
padding: 13px;
}
.footer-note {
bottom: 16px;
left: 18px;
max-width: 180px;
line-height: 1.4;
}
.scene-label {
font-size: 8px;
padding: 5px 7px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="title-block">
<div class="eyebrow">Botanical structure / study 01</div>
<h1>Vine &<br>Trellis</h1>
<p class="subtitle">
A stylized study of two connected systems: a climbing plant and the wooden
structure that supports it.
</p>
</header>
<aside class="control-panel" aria-label="Scene controls">
<div class="panel-heading">
<strong>System map</strong>
<span>01 / 03</span>
</div>
<div class="legend">
<div class="legend-row">
<span class="legend-dot plant"></span>
<div class="legend-copy">
Plant system
<small>Stem, leaves, attached and free tendrils</small>
</div>
</div>
<div class="legend-row">
<span class="legend-dot structure"></span>
<div class="legend-copy">
Structure system
<small>Posts, braces, joints and horizontal rail</small>
</div>
</div>
<div class="legend-row">
<span class="legend-dot link"></span>
<div class="legend-copy">
Physical connection
<small>One tendril wraps the rail; one remains free</small>
</div>
</div>
</div>
<div class="mode-label">View system</div>
<div class="modes" role="group" aria-label="Visible system">
<button type="button" class="active" data-mode="all">Together</button>
<button type="button" data-mode="plant">Plant</button>
<button type="button" data-mode="structure">Trellis</button>
</div>
<p class="hint">Drag to orbit · Scroll to zoom<br>Double-click to reset</p>
</aside>
<div id="label-wrapped" class="scene-label">Wrapped tendril</div>
<div id="label-free" class="scene-label free-label">Free tendril</div>
<div id="label-structure" class="scene-label structure-label">Support rail</div>
<div class="footer-note">Separate groups, visibly connected by the climbing tendril.</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional vine wrapped around a wooden trellis."
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd8e9e3, 11, 24);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
60
);
const environment = new THREE.Group();
environment.name = "Environment";
const plantSystem = new THREE.Group();
plantSystem.name = "PlantSystem";
const structureSystem = new THREE.Group();
structureSystem.name = "StructureSystem";
scene.add(environment, plantSystem, structureSystem);
plantSystem.userData.description =
"Stem, leaves, one rail-wrapping tendril and one unattached tendril.";
structureSystem.userData.description =
"Connected posts, braces, joints and horizontal support rail.";
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf6fff8, 0x9d8267, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dc, 4.4);
keyLight.position.set(4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0005;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e9ff, 1.15);
fillLight.position.set(-5, 4, -4);
scene.add(fillLight);
// Materials
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xd8d2b9,
roughness: 0.95,
metalness: 0
});
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x776047,
roughness: 1
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x9b6841,
roughness: 0.78,
metalness: 0,
flatShading: true
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x704b35,
roughness: 0.85,
metalness: 0,
flatShading: true
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0xc28a55,
roughness: 0.67,
metalness: 0,
flatShading: true
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0x5c4435,
roughness: 0.72,
metalness: 0.04,
flatShading: true
});
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x356f3c,
roughness: 0.7,
metalness: 0
});
const tendrilMaterial = new THREE.MeshStandardMaterial({
color: 0x78a84d,
roughness: 0.64,
metalness: 0
});
const branchMaterial = new THREE.MeshStandardMaterial({
color: 0x427d40,
roughness: 0.72
});
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x4d914c,
roughness: 0.67,
side: THREE.DoubleSide,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x63a755,
roughness: 0.65,
side: THREE.DoubleSide,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x397c43,
roughness: 0.7,
side: THREE.DoubleSide,
flatShading: true
})
];
const veinMaterial = new THREE.MeshStandardMaterial({
color: 0xa2bd69,
roughness: 0.78
});
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x9eaa9c,
roughness: 1,
flatShading: true
});
// Helpers
function cylinderBetween(start, end, radius, material, radialSegments = 12) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
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;
return mesh;
}
function tubeFromPoints(points, radius, material, tubularSegments = 100) {
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.45
);
const geometry = new THREE.TubeGeometry(
curve,
tubularSegments,
radius,
9,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// Stylized ground and small planting details
const ground = new THREE.Mesh(
new THREE.CylinderGeometry(4.65, 4.95, 0.2, 72),
groundMaterial
);
ground.position.y = -0.12;
ground.receiveShadow = true;
environment.add(ground);
const soil = new THREE.Mesh(
new THREE.CircleGeometry(0.55, 40),
soilMaterial
);
soil.rotation.x = -Math.PI / 2;
soil.position.set(-0.08, 0.002, 0.27);
soil.receiveShadow = true;
environment.add(soil);
const pebbleGeometry = new THREE.DodecahedronGeometry(0.09, 0);
const pebblePositions = [
[-0.46, 0.05, 0.44, 0.8],
[-0.67, 0.045, 0.2, 0.6],
[0.28, 0.045, 0.38, 0.72],
[0.46, 0.04, 0.24, 0.55],
[-0.27, 0.04, 0.62, 0.45]
];
pebblePositions.forEach(([x, y, z, scale]) => {
const pebble = new THREE.Mesh(pebbleGeometry, stoneMaterial);
pebble.position.set(x, y, z);
pebble.scale.set(scale, scale * 0.65, scale);
pebble.rotation.set(0.2, x * 3.1, z);
pebble.castShadow = true;
pebble.receiveShadow = true;
environment.add(pebble);
});
// Structure system: all trellis parts are contained in this group.
const postLeft = new THREE.Vector3(-2.7, 0, -0.25);
const postRight = new THREE.Vector3(2.7, 0, -0.25);
const postLeftTop = new THREE.Vector3(-2.7, 3.65, -0.25);
const postRightTop = new THREE.Vector3(2.7, 3.65, -0.25);
structureSystem.add(
cylinderBetween(postLeft, postLeftTop, 0.14, woodMaterial, 12),
cylinderBetween(postRight, postRightTop, 0.14, woodMaterial, 12)
);
structureSystem.add(
cylinderBetween(
new THREE.Vector3(-2.8, 3.6, -0.25),
new THREE.Vector3(2.8, 3.6, -0.25),
0.13,
darkWoodMaterial
),
cylinderBetween(
new THREE.Vector3(-2.75, 0.62, -0.28),
new THREE.Vector3(2.75, 0.62, -0.28),
0.11,
woodMaterial
)
);
// Rear lattice slats and diagonal braces.
structureSystem.add(
cylinderBetween(
new THREE.Vector3(-1.15, 0.62, -0.37),
new THREE.Vector3(-1.15, 3.58, -0.37),
0.075,
darkWoodMaterial,
10
),
cylinderBetween(
new THREE.Vector3(1.15, 0.62, -0.37),
new THREE.Vector3(1.15, 3.58, -0.37),
0.075,
darkWoodMaterial,
10
),
cylinderBetween(
new THREE.Vector3(-2.55, 0.72, -0.42),
new THREE.Vector3(2.48, 3.48, -0.42),
0.055,
woodMaterial,
9
),
cylinderBetween(
new THREE.Vector3(2.55, 0.72, -0.42),
new THREE.Vector3(-2.48, 3.48, -0.42),
0.055,
woodMaterial,
9
)
);
// The main horizontal support. Its axis is X, so the attached tendril
// can wrap around it in the Y/Z plane.
const railY = 2.15;
structureSystem.add(
cylinderBetween(
new THREE.Vector3(-3.15, railY, 0),
new THREE.Vector3(3.15, railY, 0),
0.15,
railMaterial,
16
)
);
// Short connectors physically join the rail to the posts.
structureSystem.add(
cylinderBetween(
new THREE.Vector3(-2.7, railY, -0.25),
new THREE.Vector3(-2.7, railY, 0),
0.11,
darkWoodMaterial
),
cylinderBetween(
new THREE.Vector3(2.7, railY, -0.25),
new THREE.Vector3(2.7, railY, 0),
0.11,
darkWoodMaterial
)
);
const jointGeometry = new THREE.SphereGeometry(0.17, 12, 8);
[
[-2.7, 3.6, -0.25],
[2.7, 3.6, -0.25],
[-2.7, 0.62, -0.28],
[2.7, 0.62, -0.28],
[-2.7, railY, 0],
[2.7, railY, 0]
].forEach(([x, y, z]) => {
const joint = new THREE.Mesh(jointGeometry, jointMaterial);
joint.position.set(x, y, z);
joint.scale.set(1, 0.82, 1);
joint.castShadow = true;
structureSystem.add(joint);
});
// Plant system: main climbing stem.
const stemCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.12, 0.015, 0.29),
new THREE.Vector3(-0.21, 0.46, 0.31),
new THREE.Vector3(0.025, 0.94, 0.3),
new THREE.Vector3(-0.12, 1.43, 0.32),
new THREE.Vector3(0.075, 1.94, 0.31),
new THREE.Vector3(-0.075, 2.53, 0.32),
new THREE.Vector3(0.055, 3.1, 0.3),
new THREE.Vector3(-0.02, 3.42, 0.27)
],
false,
"catmullrom",
0.45
);
const stemGeometry = new THREE.TubeGeometry(
stemCurve,
150,
0.067,
9,
false
);
const stem = new THREE.Mesh(stemGeometry, stemMaterial);
stem.castShadow = true;
stem.receiveShadow = true;
plantSystem.add(stem);
// Attached tendril: its path makes more than two complete turns around
// the horizontal rail, then gently unwinds at the tip.
const wrappedPoints = [];
const wrappedBase = stemCurve.getPointAt(0.565);
wrappedPoints.push(wrappedBase.clone());
wrappedPoints.push(
wrappedBase.clone().add(new THREE.Vector3(0.07, 0.22, 0.01))
);
const helixTurns = 2.2;
const helixStartAngle = 0.58;
const helixRadius = 0.218;
for (let i = 0; i <= 110; i++) {
const u = i / 110;
const angle = helixStartAngle + u * Math.PI * 2 * helixTurns;
const x = 0.16 + u * 0.98;
const radius = helixRadius - u * 0.012;
const y = railY + radius * Math.sin(angle);
const z = radius * Math.cos(angle);
wrappedPoints.push(new THREE.Vector3(x, y, z));
}
wrappedPoints.push(new THREE.Vector3(1.25, 2.42, 0.19));
wrappedPoints.push(new THREE.Vector3(1.34, 2.6, 0.25));
plantSystem.add(
tubeFromPoints(wrappedPoints, 0.041, tendrilMaterial, 240)
);
// Unattached tendril: a separate spiral suspended in open air.
const freePoints = [];
const freeBase = stemCurve.getPointAt(0.775);
freePoints.push(freeBase.clone());
freePoints.push(
freeBase.clone().add(new THREE.Vector3(0.16, 0.2, 0.035))
);
freePoints.push(new THREE.Vector3(0.43, 3.1, 0.34));
const spiralCenter = new THREE.Vector3(0.67, 3.08, 0.34);
const spiralStartAngle = 2.4;
for (let i = 0; i <= 105; i++) {
const u = i / 105;
const angle = spiralStartAngle + u * Math.PI * 3.8;
const radius = 0.4 * (1 - 0.78 * u);
freePoints.push(
new THREE.Vector3(
spiralCenter.x + radius * Math.cos(angle),
spiralCenter.y + radius * Math.sin(angle),
spiralCenter.z + 0.012 * Math.sin(angle * 0.5)
)
);
}
plantSystem.add(
tubeFromPoints(freePoints, 0.034, tendrilMaterial, 220)
);
// Shared stylized leaf geometry.
const leafShape = new THREE.Shape();
leafShape.moveTo(0, 0);
leafShape.bezierCurveTo(0.12, 0.13, 0.4, 0.19, 0.72, 0);
leafShape.bezierCurveTo(0.41, -0.17, 0.14, -0.12, 0, 0);
leafShape.closePath();
const leafGeometry = new THREE.ExtrudeGeometry(leafShape, {
depth: 0.035,
bevelEnabled: true,
bevelSize: 0.022,
bevelThickness: 0.014,
bevelSegments: 1,
curveSegments: 12
});
leafGeometry.translate(0, 0, -0.0175);
leafGeometry.computeVertexNormals();
const veinGeometry = new THREE.TubeGeometry(
new THREE.CatmullRomCurve3([
new THREE.Vector3(0.01, 0, 0.035),
new THREE.Vector3(0.26, 0.008, 0.04),
new THREE.Vector3(0.6, 0, 0.035)
]),
18,
0.009,
5,
false
);
const animatedLeaves = [];
function addLeaf(t, angle, length, materialIndex, phase) {
const base = stemCurve.getPointAt(t);
const direction = new THREE.Vector3(
Math.cos(angle),
Math.sin(angle),
0
);
const end = base.clone().addScaledVector(direction, length);
end.z += 0.09;
const middle = base.clone().addScaledVector(direction, length * 0.47);
middle.z += 0.13;
middle.y += 0.025;
const branch = tubeFromPoints(
[base.clone(), middle, end.clone()],
0.027,
branchMaterial,
28
);
plantSystem.add(branch);
const leafGroup = new THREE.Group();
leafGroup.position.copy(end);
leafGroup.rotation.z = angle;
leafGroup.rotation.y = phase % 2 === 0 ? 0.15 : -0.17;
leafGroup.rotation.x = phase % 3 === 0 ? 0.08 : -0.06;
leafGroup.userData.baseRotationZ = angle;
leafGroup.userData.phase = phase;
const leafMesh = new THREE.Mesh(
leafGeometry,
leafMaterials[materialIndex % leafMaterials.length]
);
leafMesh.castShadow = true;
leafMesh.receiveShadow = true;
leafGroup.add(leafMesh);
const vein = new THREE.Mesh(veinGeometry, veinMaterial);
vein.castShadow = true;
leafGroup.add(vein);
plantSystem.add(leafGroup);
animatedLeaves.push(leafGroup);
}
addLeaf(0.17, 2.62, 0.78, 0, 0.4);
addLeaf(0.31, 0.38, 0.86, 1, 1.3);
addLeaf(0.46, 2.83, 0.74, 2, 2.1);
addLeaf(0.61, 0.2, 0.81, 1, 3.2);
addLeaf(0.76, 2.7, 0.63, 0, 4.5);
// Small terminal bud.
const bud = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 14, 10),
leafMaterials[1]
);
bud.position.copy(stemCurve.getPointAt(1));
bud.scale.set(0.8, 1.55, 0.75);
bud.rotation.z = -0.25;
bud.castShadow = true;
plantSystem.add(bud);
// Manual camera controls — no addon imports.
const cameraTarget = new THREE.Vector3(0, 1.68, 0);
const desired = {
yaw: 0.56,
pitch: 1.12,
radius: 8.8
};
const current = {
yaw: desired.yaw,
pitch: desired.pitch,
radius: desired.radius
};
function updateCamera() {
const horizontal = Math.sin(current.pitch) * current.radius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(current.yaw),
cameraTarget.y + Math.cos(current.pitch) * current.radius,
cameraTarget.z + horizontal * Math.cos(current.yaw)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
desired.yaw = 0.56;
desired.pitch = 1.12;
desired.radius = 8.8;
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desired.yaw -= deltaX * 0.006;
desired.pitch = THREE.MathUtils.clamp(
desired.pitch - deltaY * 0.005,
0.46,
1.43
);
});
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);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.007,
5.7,
13.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// System visibility controls.
const modeButtons = [...document.querySelectorAll("[data-mode]")];
const wrappedLabel = document.getElementById("label-wrapped");
const freeLabel = document.getElementById("label-free");
const structureLabel = document.getElementById("label-structure");
function setMode(mode) {
plantSystem.visible = mode !== "structure";
structureSystem.visible = mode !== "plant";
wrappedLabel.hidden = mode === "structure";
freeLabel.hidden = mode === "structure";
structureLabel.hidden = mode === "plant";
modeButtons.forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
modeButtons.forEach((button) => {
button.setAttribute("aria-pressed", String(button.classList.contains("active")));
button.addEventListener("click", () => setMode(button.dataset.mode));
});
// Screen-space annotations projected directly from Three.js.
const labelAnchors = {
wrappedLabel: new THREE.Vector3(0.7, railY + 0.04, 0.14),
freeLabel: new THREE.Vector3(0.75, 3.13, 0.36),
structureLabel: new THREE.Vector3(2.68, railY + 0.05, 0.02)
};
function positionLabel(element, anchor) {
const projected = anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!visible) {
element.style.visibility = "hidden";
return;
}
element.style.visibility = "visible";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(-50%, -50%) translate(${x.toFixed(1)}px, ${y.toFixed(1)}px)`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const smoothing = 1 - Math.exp(-7 * delta);
current.yaw = THREE.MathUtils.lerp(current.yaw, desired.yaw, smoothing);
current.pitch = THREE.MathUtils.lerp(current.pitch, desired.pitch, smoothing);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, smoothing);
updateCamera();
if (!reducedMotion) {
animatedLeaves.forEach((leaf) => {
leaf.rotation.z =
leaf.userData.baseRotationZ +
Math.sin(time * 0.8 + leaf.userData.phase) * 0.018;
});
}
positionLabel(wrappedLabel, labelAnchors.wrappedLabel);
positionLabel(freeLabel, labelAnchors.freeLabel);
positionLabel(structureLabel, labelAnchors.structureLabel);
renderer.render(scene, camera);
}
setMode("all");
updateCamera();
animate();
</script>
</body>
</html>
```