Prompt specification
Build or customize the Three.js 3D scene "Tree cavity entrance section" 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: Tree cavity entrance section
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tree-cavity-entrance-section-x0717
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: tree cavity entrance section. Model a tree trunk segment with a rounded nest cavity and entrance tunnel; show a stylized woodpecker beside it to establish relative body and opening sizes. Return one self-contained HTML file.
Working Three.js Starter (tree-cavity-entrance-section-x0717):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tree Cavity — Stylized Scale Study</title>
<style>
:root {
color-scheme: light;
--ink: #263a33;
--muted: #617068;
--panel: rgba(255, 252, 240, 0.78);
--line: rgba(38, 58, 51, 0.15);
--accent: #d7663d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 28% 18%, rgba(255, 250, 222, 0.98), transparent 42%),
linear-gradient(145deg, #d8e6d8 0%, #b8d0c1 52%, #9eb9aa 100%);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 46%, rgba(42, 66, 57, 0.12) 100%);
}
.title-card {
position: fixed;
top: clamp(18px, 4vw, 42px);
left: clamp(18px, 4vw, 48px);
width: min(360px, calc(100vw - 36px));
padding: 17px 19px 16px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 14px 45px rgba(50, 70, 60, 0.13);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 4vw, 34px);
font-weight: 500;
line-height: 1.04;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #b87939;
box-shadow: 0 0 0 3px rgba(184, 121, 57, 0.12);
}
.dot.bird {
background: var(--accent);
box-shadow: 0 0 0 3px rgba(215, 102, 61, 0.12);
}
.controls {
position: fixed;
right: clamp(16px, 3vw, 34px);
bottom: clamp(16px, 3vw, 30px);
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 999px;
color: rgba(38, 58, 51, 0.72);
background: rgba(248, 247, 231, 0.58);
box-shadow: 0 8px 25px rgba(50, 70, 60, 0.09);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.035em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #d8e6d8;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
@media (max-width: 640px) {
.title-card {
padding: 14px 16px;
}
.subtitle {
display: none;
}
.legend {
margin-top: 9px;
padding-top: 9px;
}
.controls {
right: 50%;
transform: translateX(50%);
white-space: nowrap;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive stylized tree cavity and woodpecker scene"></div>
<div class="vignette"></div>
<header class="title-card">
<p class="eyebrow">Natural Habitat Study</p>
<h1>Tree Cavity</h1>
<p class="subtitle">
A rounded nest entrance with a recessed tunnel. The nearby woodpecker
provides a clear visual scale reference.
</p>
<div class="legend">
<span><i class="dot"></i> Nest opening</span>
<span><i class="dot bird"></i> Adult woodpecker</span>
</div>
</header>
<div class="controls">Drag to orbit · Scroll or pinch to zoom · Double-click to reset</div>
<div id="loading">Growing the woodland scene…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(container.clientWidth, container.clientHeight);
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;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd3dfd2, 12, 23);
const camera = new THREE.PerspectiveCamera(
38,
container.clientWidth / container.clientHeight,
0.1,
50
);
const target = new THREE.Vector3(0.25, 2.5, 0.45);
const controls = {
yaw: 0.31,
pitch: 0.18,
distance: 10.6
};
function updateCamera() {
const horizontal = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
target.x + Math.sin(controls.yaw) * horizontal,
target.y + Math.sin(controls.pitch) * controls.distance,
target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xf4f5df, 0x6f4933, 2.15));
const sun = new THREE.DirectionalLight(0xffddb0, 3.25);
sun.position.set(-4.5, 9, 7);
sun.target.position.set(0, 2, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -6;
sun.shadow.camera.right = 6;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -3;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0xa8ced7, 1.1);
fill.position.set(5, 5, -4);
scene.add(fill);
const cavityLight = new THREE.PointLight(0xffbf79, 1.15, 2.5, 2);
cavityLight.position.set(0.12, 2.92, 0.28);
scene.add(cavityLight);
// Shared materials
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
const barkMaterial = material(0x553525, { flatShading: true });
const darkBarkMaterial = material(0x39251d, { flatShading: true });
const cutWoodMaterial = material(0xc88849, { roughness: 0.9 });
const paleWoodMaterial = material(0xdfaa68, { roughness: 0.82 });
const grainMaterial = material(0x98572e, { roughness: 1 });
const lightGrainMaterial = material(0xb66e37, { roughness: 1 });
const tunnelMaterial = material(0x5b321f, {
roughness: 1,
side: THREE.DoubleSide
});
const cavityBackMaterial = material(0x24150f, { roughness: 1 });
const redMaterial = material(0xc84b32, { roughness: 0.78 });
const redLightMaterial = material(0xe1693d, { roughness: 0.75 });
const creamMaterial = material(0xf0ddb2, { roughness: 0.86 });
const darkFeatherMaterial = material(0x263a36, { roughness: 0.82 });
const beakMaterial = material(0xd4ad68, { roughness: 0.72 });
const eyeMaterial = material(0x101713, { roughness: 0.42 });
const unitSphere = new THREE.SphereGeometry(1, 24, 16);
function addMesh(
geometry,
mat,
position = [0, 0, 0],
scale = [1, 1, 1],
rotation = [0, 0, 0]
) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addSphere(mat, position, scale, rotation = [0, 0, 0]) {
return addMesh(unitSphere, mat, position, scale, rotation);
}
function cylinderBetween(start, end, startRadius, endRadius, mat, segments = 9) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
endRadius,
startRadius,
length,
segments,
1,
false
);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.copy(a).add(b).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;
}
// Diorama base and ground
const ground = addMesh(
new THREE.PlaneGeometry(40, 40),
material(0xbacbb8, { roughness: 1 }),
[0, -0.48, 0],
[1, 1, 1],
[-Math.PI / 2, 0, 0]
);
ground.castShadow = false;
const base = addMesh(
new THREE.CylinderGeometry(3.55, 3.72, 0.36, 72),
material(0x91aa91, { roughness: 1, flatShading: true }),
[0.25, -0.29, 0.15],
[1, 1, 0.84]
);
base.castShadow = false;
const soilPatch = addMesh(
new THREE.CircleGeometry(1.65, 48),
material(0x8f6b47, { roughness: 1 }),
[0.05, -0.092, 0.18],
[1.2, 0.78, 1],
[-Math.PI / 2, 0, 0]
);
soilPatch.castShadow = false;
// Stylized trunk section: an extruded, irregular outline with a true opening.
const trunkShape = new THREE.Shape();
trunkShape.moveTo(-1.10, 0.06);
trunkShape.lineTo(1.06, 0.06);
trunkShape.bezierCurveTo(1.36, 0.42, 1.42, 1.31, 1.34, 2.14);
trunkShape.bezierCurveTo(1.27, 2.95, 1.39, 3.73, 1.25, 4.51);
trunkShape.bezierCurveTo(1.15, 5.06, 0.64, 5.34, 0.02, 5.30);
trunkShape.bezierCurveTo(-0.58, 5.28, -1.13, 4.98, -1.24, 4.48);
trunkShape.bezierCurveTo(-1.35, 3.80, -1.27, 3.04, -1.36, 2.28);
trunkShape.bezierCurveTo(-1.44, 1.48, -1.38, 0.51, -1.10, 0.06);
const cavityHole = new THREE.Path();
cavityHole.absellipse(
0.12,
2.92,
0.59,
0.75,
0,
Math.PI * 2,
true
);
trunkShape.holes.push(cavityHole);
const trunkGeometry = new THREE.ExtrudeGeometry(trunkShape, {
depth: 1.55,
steps: 1,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.075,
bevelThickness: 0.075,
curveSegments: 24
});
trunkGeometry.translate(0, 0, -0.775);
const trunk = new THREE.Mesh(
trunkGeometry,
[cutWoodMaterial, barkMaterial]
);
trunk.castShadow = true;
trunk.receiveShadow = true;
scene.add(trunk);
// Bark frame around the cut trunk.
const barkFramePoints = [
[-1.08, 0.08, 0.86],
[1.04, 0.08, 0.86],
[1.31, 1.05, 0.86],
[1.34, 2.13, 0.86],
[1.27, 3.30, 0.86],
[1.23, 4.50, 0.86],
[0.83, 5.08, 0.86],
[0.12, 5.25, 0.86],
[-0.61, 5.15, 0.86],
[-1.14, 4.68, 0.86],
[-1.30, 3.75, 0.86],
[-1.29, 2.70, 0.86],
[-1.34, 1.62, 0.86],
[-1.30, 0.66, 0.86]
].map((p) => new THREE.Vector3(...p));
const barkFrameCurve = new THREE.CatmullRomCurve3(
barkFramePoints,
true,
"catmullrom",
0.25
);
addMesh(
new THREE.TubeGeometry(barkFrameCurve, 140, 0.062, 8, true),
darkBarkMaterial
);
// Subtle wood grain on the cut face.
function addGrain(points, mat = grainMaterial, radius = 0.012) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
return addMesh(
new THREE.TubeGeometry(curve, points.length * 8, radius, 5, false),
mat
);
}
addGrain([
[-0.91, 0.35, 0.865],
[-0.83, 1.12, 0.865],
[-0.91, 1.88, 0.865],
[-0.82, 2.60, 0.865],
[-0.88, 3.37, 0.865],
[-0.79, 4.18, 0.865],
[-0.82, 4.87, 0.865]
]);
addGrain([
[-1.10, 0.52, 0.864],
[-1.02, 1.35, 0.864],
[-1.07, 2.10, 0.864],
[-1.01, 3.10, 0.864],
[-1.04, 4.18, 0.864]
], lightGrainMaterial, 0.009);
addGrain([
[0.98, 0.35, 0.865],
[1.03, 1.18, 0.865],
[0.96, 1.95, 0.865],
[1.01, 2.83, 0.865],
[0.95, 3.55, 0.865],
[0.92, 4.36, 0.865]
]);
addGrain([
[-0.50, 4.26, 0.865],
[-0.12, 4.43, 0.865],
[0.32, 4.47, 0.865],
[0.72, 4.35, 0.865]
], lightGrainMaterial, 0.010);
addGrain([
[-0.55, 1.79, 0.865],
[-0.13, 1.66, 0.865],
[0.37, 1.73, 0.865],
[0.78, 1.89, 0.865]
], lightGrainMaterial, 0.010);
addGrain([
[-0.34, 0.45, 0.865],
[0.02, 0.36, 0.865],
[0.46, 0.50, 0.865]
], lightGrainMaterial, 0.009);
// Small knots in the exposed wood.
addMesh(
new THREE.TorusGeometry(0.15, 0.014, 6, 32),
grainMaterial,
[-0.69, 1.22, 0.873],
[1.35, 0.78, 1],
[0, 0, -0.25]
);
addMesh(
new THREE.TorusGeometry(0.095, 0.011, 6, 28),
grainMaterial,
[-0.69, 1.22, 0.875],
[1.35, 0.78, 1],
[0, 0, -0.25]
);
addMesh(
new THREE.TorusGeometry(0.12, 0.012, 6, 28),
grainMaterial,
[0.98, 4.02, 0.873],
[1.2, 0.85, 1],
[0, 0, 0.35]
);
// Recessed tunnel and rounded entrance lips.
const tunnel = addMesh(
new THREE.CylinderGeometry(0.44, 0.36, 1.25, 48, 1, true),
tunnelMaterial,
[0.12, 2.92, 0.205],
[1.18, 1, 1.36],
[Math.PI / 2, 0, 0]
);
tunnel.castShadow = false;
addMesh(
new THREE.CircleGeometry(0.36, 48),
cavityBackMaterial,
[0.12, 2.92, -0.424],
[1.18, 1.36, 1]
);
addMesh(
new THREE.TorusGeometry(0.375, 0.022, 7, 48),
material(0x8c4f2d, { roughness: 1 }),
[0.12, 2.92, -0.405],
[1.18, 1.36, 1]
);
const outerLip = addMesh(
new THREE.TorusGeometry(0.635, 0.115, 12, 72),
material(0x9a5c31, { roughness: 0.95 }),
[0.12, 2.92, 0.835],
[1, 1.17, 1]
);
outerLip.castShadow = false;
const innerLip = addMesh(
new THREE.TorusGeometry(0.595, 0.078, 12, 72),
paleWoodMaterial,
[0.12, 2.92, 0.91],
[1, 1.18, 1]
);
innerLip.castShadow = false;
// Root flares.
cylinderBetween(
[-0.05, 0.08, 0.10],
[-1.55, -0.055, 0.58],
0.19,
0.035,
barkMaterial
);
cylinderBetween(
[0.06, 0.08, 0.02],
[1.47, -0.055, 0.52],
0.18,
0.035,
barkMaterial
);
cylinderBetween(
[0.00, 0.08, 0.06],
[-0.62, -0.06, -1.05],
0.17,
0.03,
barkMaterial
);
cylinderBetween(
[0.04, 0.08, 0.03],
[1.12, -0.06, -0.82],
0.16,
0.025,
barkMaterial
);
// A small branch behind the bird.
cylinderBetween(
[1.25, 2.02, 0.42],
[1.72, 2.04, 0.68],
0.10,
0.075,
barkMaterial
);
cylinderBetween(
[1.72, 2.04, 0.68],
[2.20, 2.08, 0.88],
0.075,
0.035,
barkMaterial
);
cylinderBetween(
[1.57, 2.04, 0.60],
[1.76, 2.37, 0.67],
0.05,
0.018,
barkMaterial
);
// Upper twig and broad stylized leaves.
cylinderBetween(
[0.72, 4.69, 0.08],
[1.91, 5.06, -0.02],
0.095,
0.035,
barkMaterial
);
cylinderBetween(
[1.90, 5.06, -0.02],
[2.37, 4.88, 0.02],
0.035,
0.014,
barkMaterial
);
const leafMaterial = material(0x6f9466, { roughness: 0.9 });
const leafLightMaterial = material(0x94aa72, { roughness: 0.9 });
function addLeaf(position, scale, rotation, mat = leafMaterial) {
const leaf = addSphere(
mat,
position,
scale,
rotation
);
leaf.castShadow = true;
return leaf;
}
addLeaf([1.39, 5.06, -0.01], [0.28, 0.07, 0.49], [0.15, 0.65, 0.32], leafLightMaterial);
addLeaf([1.73, 5.22, -0.05], [0.28, 0.07, 0.48], [0.05, -0.25, -0.12]);
addLeaf([2.08, 5.19, 0.00], [0.27, 0.07, 0.46], [0.08, 0.55, 0.22], leafLightMaterial);
addLeaf([2.32, 4.91, 0.02], [0.25, 0.065, 0.42], [0.05, -0.25, 0.12]);
// Woodpecker, placed beside the opening as a scale reference.
// Body
addSphere(
redMaterial,
[1.58, 2.55, 0.62],
[0.36, 0.54, 0.30],
[0.05, 0, -0.13]
);
// Cream belly
addSphere(
creamMaterial,
[1.48, 2.51, 0.885],
[0.235, 0.39, 0.055],
[0.03, 0, -0.10]
);
// Dark folded wing
addSphere(
darkFeatherMaterial,
[1.67, 2.55, 0.895],
[0.14, 0.43, 0.075],
[0.04, 0.03, -0.18]
);
// Pale wing spots
addSphere(
creamMaterial,
[1.59, 2.73, 0.973],
[0.047, 0.070, 0.018],
[0, 0, -0.15]
);
addSphere(
creamMaterial,
[1.62, 2.54, 0.975],
[0.047, 0.066, 0.018],
[0, 0, -0.15]
);
addSphere(
creamMaterial,
[1.65, 2.35, 0.973],
[0.043, 0.058, 0.018],
[0, 0, -0.15]
);
// Neck and head
addSphere(
darkFeatherMaterial,
[1.51, 3.02, 0.66],
[0.25, 0.31, 0.25]
);
addSphere(
darkFeatherMaterial,
[1.43, 3.20, 0.70],
[0.30, 0.30, 0.29]
);
// Pale facial patch
addSphere(
creamMaterial,
[1.36, 3.18, 0.963],
[0.20, 0.175, 0.052],
[0, 0, -0.04]
);
// Eye
addSphere(
creamMaterial,
[1.31, 3.255, 1.018],
[0.073, 0.073, 0.030]
);
addSphere(
eyeMaterial,
[1.305, 3.255, 1.045],
[0.035, 0.038, 0.020]
);
// Long, pointed beak aimed toward the cavity.
addMesh(
new THREE.ConeGeometry(0.09, 0.48, 7),
beakMaterial,
[0.93, 3.19, 0.84],
[1, 1, 0.72],
[0, 0, Math.PI / 2]
);
// Red crest feathers.
addMesh(
new THREE.ConeGeometry(0.09, 0.27, 5),
redLightMaterial,
[1.25, 3.54, 0.69],
[1, 1, 0.75],
[0, 0, -0.20]
);
addMesh(
new THREE.ConeGeometry(0.10, 0.31, 5),
redMaterial,
[1.42, 3.58, 0.69],
[1, 1, 0.75],
[0, 0, 0.02]
);
addMesh(
new THREE.ConeGeometry(0.085, 0.25, 5),
redLightMaterial,
[1.57, 3.49, 0.68],
[1, 1, 0.75],
[0, 0, 0.18]
);
// Tail feathers.
addMesh(
new THREE.ConeGeometry(0.13, 0.74, 5),
darkFeatherMaterial,
[1.68, 1.72, 0.54],
[0.76, 1, 0.42],
[0, 0, Math.PI]
);
addMesh(
new THREE.ConeGeometry(0.115, 0.69, 5),
redMaterial,
[1.80, 1.76, 0.52],
[0.72, 1, 0.40],
[0, 0, Math.PI + 0.05]
);
addMesh(
new THREE.ConeGeometry(0.105, 0.62, 5),
darkFeatherMaterial,
[1.89, 1.80, 0.49],
[0.70, 1, 0.38],
[0, 0, Math.PI - 0.05]
);
// Feet gripping the branch.
cylinderBetween(
[1.46, 2.13, 0.62],
[1.46, 2.045, 0.58],
0.035,
0.026,
darkFeatherMaterial,
7
);
cylinderBetween(
[1.76, 2.13, 0.68],
[1.76, 2.055, 0.72],
0.035,
0.026,
darkFeatherMaterial,
7
);
addSphere(darkFeatherMaterial, [1.42, 2.04, 0.58], [0.045, 0.025, 0.025]);
addSphere(darkFeatherMaterial, [1.50, 2.04, 0.58], [0.045, 0.025, 0.025]);
addSphere(darkFeatherMaterial, [1.72, 2.05, 0.72], [0.045, 0.025, 0.025]);
addSphere(darkFeatherMaterial, [1.80, 2.05, 0.72], [0.045, 0.025, 0.025]);
// Small woodland plants around the base.
const grassMaterial = material(0x6f8d63, { roughness: 1 });
const grassLightMaterial = material(0x91a36d, { roughness: 1 });
const grassPositions = [
[-2.25, -0.03, 0.8, -0.25],
[-2.52, -0.03, 0.25, 0.18],
[2.42, -0.03, 0.8, 0.32],
[2.74, -0.03, 0.05, -0.18],
[-1.72, -0.03, -1.05, 0.22],
[1.65, -0.03, -1.15, -0.28],
[-0.45, -0.03, 1.55, 0.16]
];
grassPositions.forEach((p, index) => {
const [x, y, z, tilt] = p;
addMesh(
new THREE.ConeGeometry(0.055, 0.44 + (index % 3) * 0.08, 4),
index % 2 ? grassMaterial : grassLightMaterial,
[x, y + 0.24, z],
[1, 1, 0.72],
[0, 0, tilt]
);
});
// Soft floating pollen.
const moteCount = 34;
const motePositions = new Float32Array(moteCount * 3);
const moteSpeeds = new Float32Array(moteCount);
for (let i = 0; i < moteCount; i++) {
motePositions[i * 3] = (Math.random() - 0.5) * 6.2;
motePositions[i * 3 + 1] = 0.35 + Math.random() * 5.2;
motePositions[i * 3 + 2] = -1.4 + Math.random() * 3.4;
moteSpeeds[i] = 0.018 + Math.random() * 0.027;
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.BufferAttribute(motePositions, 3)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0xffe4a4,
size: 0.045,
transparent: true,
opacity: 0.66,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(motes);
// Direct, addon-free camera controls.
const pointers = new Map();
const canvas = renderer.domElement;
function resetControls() {
controls.yaw = 0.31;
controls.pitch = 0.18;
controls.distance = 10.6;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.04,
0.72
);
} else {
const before = Array.from(pointers.values());
const beforeCenterX = (before[0].x + before[1].x) * 0.5;
const beforeCenterY = (before[0].y + before[1].y) * 0.5;
const beforeDistance = Math.hypot(
before[0].x - before[1].x,
before[0].y - before[1].y
);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const after = Array.from(pointers.values());
const afterCenterX = (after[0].x + after[1].x) * 0.5;
const afterCenterY = (after[0].y + after[1].y) * 0.5;
const afterDistance = Math.hypot(
after[0].x - after[1].x,
after[0].y - after[1].y
);
controls.yaw += (afterCenterX - beforeCenterX) * 0.005;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + (afterCenterY - beforeCenterY) * 0.004,
0.04,
0.72
);
if (beforeDistance > 0 && afterDistance > 0) {
controls.distance = THREE.MathUtils.clamp(
controls.distance * (beforeDistance / afterDistance),
7.2,
15.5
);
}
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance + event.deltaY * 0.008,
7.2,
15.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetControls);
window.addEventListener("resize", () => {
const width = container.clientWidth;
const height = container.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
});
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const positionAttribute = moteGeometry.getAttribute("position");
for (let i = 0; i < moteCount; i++) {
const index = i * 3;
positionAttribute.array[index + 1] += moteSpeeds[i] * delta * 10;
positionAttribute.array[index] +=
Math.sin(elapsed * 0.45 + i) * delta * 0.006;
if (positionAttribute.array[index + 1] > 5.9) {
positionAttribute.array[index + 1] = 0.25;
}
}
positionAttribute.needsUpdate = true;
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 450);
}
});
</script>
</body>
</html>
```