Prompt specification
Build or customize the Three.js 3D scene "Rooftop planter layered 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: Rooftop planter layered section
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rooftop-planter-layered-section-x1117
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a stylized rooftop planter in section. Cut away the front of a rectangular container to reveal the drainage layer, growing medium, and plant roots. A small outlet exits the lower side above a tray, while the leaves rise above the container rim. Place the planter beside a simple roof-surface sample so its position is understandable without building a whole house. Use distinct materials for soil, aggregate, container, and foliage. Label the layers briefly and identify the section as illustrative. Keep the emphasis on spatial arrangement; it should not look like a dimensioned structural installation specification.
Working Three.js Starter (rooftop-planter-layered-section-x1117):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rooftop Planter — Illustrative Section</title>
<style>
:root {
color-scheme: light;
--ink: #203b36;
--muted: #64746f;
--paper: rgba(250, 249, 244, 0.9);
--line: rgba(37, 70, 63, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eee7;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.title-block {
position: absolute;
top: 25px;
left: 28px;
max-width: 390px;
}
.eyebrow {
margin: 0 0 7px;
color: #6e8179;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
font-weight: 650;
line-height: 1.02;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.section-badge {
position: absolute;
top: 26px;
right: 28px;
padding: 8px 11px;
border: 1px solid rgba(33, 75, 67, 0.25);
border-radius: 999px;
background: rgba(250, 249, 244, 0.74);
color: #43665d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.legend {
position: absolute;
left: 27px;
bottom: 25px;
display: grid;
grid-template-columns: repeat(2, auto);
gap: 8px 16px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 8px 25px rgba(40, 59, 52, 0.08);
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #53665f;
font-size: 10px;
font-weight: 650;
white-space: nowrap;
}
.swatch {
width: 12px;
height: 12px;
border: 1px solid rgba(0, 0, 0, 0.12);
border-radius: 3px;
}
.help {
position: absolute;
right: 27px;
bottom: 25px;
display: flex;
align-items: center;
gap: 12px;
color: #60716b;
font-size: 10px;
letter-spacing: 0.01em;
}
#reset {
pointer-events: auto;
padding: 8px 11px;
border: 1px solid rgba(33, 75, 67, 0.24);
border-radius: 999px;
background: rgba(250, 249, 244, 0.88);
color: #365b52;
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(8px);
}
#reset:hover {
background: #fffef9;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 5;
overflow: visible;
}
#leaders line {
stroke: rgba(39, 78, 70, 0.46);
stroke-width: 1;
}
#leaders circle {
fill: #f9f8f1;
stroke: rgba(39, 78, 70, 0.72);
stroke-width: 1.2;
}
.tag {
position: absolute;
z-index: 8;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(37, 70, 63, 0.2);
border-radius: 999px;
background: rgba(252, 251, 246, 0.93);
box-shadow: 0 5px 16px rgba(43, 66, 58, 0.09);
color: #35564e;
font-size: 10px;
font-weight: 720;
letter-spacing: 0.015em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.tag::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
background: var(--tag-color, #6a7c74);
vertical-align: 1px;
}
@media (max-width: 720px) {
.title-block {
top: 18px;
left: 18px;
max-width: 260px;
}
.section-badge {
top: 18px;
right: 18px;
}
.subtitle {
max-width: 230px;
}
.legend {
left: 16px;
bottom: 16px;
grid-template-columns: auto;
}
.help {
right: 16px;
bottom: 16px;
}
.help-text {
display: none;
}
.tag {
padding: 5px 7px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="title-block">
<p class="eyebrow">Roof detail study</p>
<h1>Rooftop planter</h1>
<p class="subtitle">
Illustrative cutaway showing the spatial relationship between drainage,
growing medium, roots, outlet, and a simple roof-surface sample.
</p>
</div>
<div class="section-badge">Illustrative section</div>
<div class="legend" aria-label="Material legend">
<div class="legend-item">
<span class="swatch" style="background:#5d7b72"></span>
Container
</div>
<div class="legend-item">
<span class="swatch" style="background:#654733"></span>
Growing medium
</div>
<div class="legend-item">
<span class="swatch" style="background:#858276"></span>
Drainage aggregate
</div>
<div class="legend-item">
<span class="swatch" style="background:#4f8651"></span>
Foliage
</div>
</div>
<div class="help">
<span class="help-text">drag to orbit · wheel to zoom · shift-drag to pan</span>
<button id="reset" type="button">Reset view</button>
</div>
</div>
<svg id="leaders" aria-hidden="true"></svg>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee7);
scene.fog = new THREE.Fog(0xe9eee7, 13, 28);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfffbef, 0x66756c, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d8, 3.1);
sun.position.set(-3.5, 8, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc5dcdf, 1.15);
fill.position.set(6, 4, -5);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xdfe4dc,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
container: new THREE.MeshStandardMaterial({
color: 0x5d7b72,
roughness: 0.78,
metalness: 0.02
}),
containerRim: new THREE.MeshStandardMaterial({
color: 0x739087,
roughness: 0.68,
metalness: 0.02
}),
cutFace: new THREE.MeshStandardMaterial({
color: 0xb7cbc0,
roughness: 0.86
}),
soil: new THREE.MeshStandardMaterial({
color: 0x654733,
roughness: 1,
metalness: 0
}),
soilDark: new THREE.MeshStandardMaterial({
color: 0x3e2c21,
roughness: 1
}),
soilLight: new THREE.MeshStandardMaterial({
color: 0x8a6749,
roughness: 1
}),
aggregate: new THREE.MeshStandardMaterial({
color: 0x858276,
roughness: 0.96
}),
filter: new THREE.MeshStandardMaterial({
color: 0xb7ad8f,
roughness: 0.9,
side: THREE.DoubleSide
}),
root: new THREE.MeshStandardMaterial({
color: 0xd7b981,
emissive: 0x30200e,
emissiveIntensity: 0.12,
roughness: 0.84
}),
stem: new THREE.MeshStandardMaterial({
color: 0x477348,
roughness: 0.85
}),
leafA: new THREE.MeshStandardMaterial({
color: 0x4f8651,
roughness: 0.82,
side: THREE.DoubleSide
}),
leafB: new THREE.MeshStandardMaterial({
color: 0x6e9c5d,
roughness: 0.82,
side: THREE.DoubleSide
}),
leafC: new THREE.MeshStandardMaterial({
color: 0x3f7548,
roughness: 0.84,
side: THREE.DoubleSide
}),
pipe: new THREE.MeshStandardMaterial({
color: 0x415650,
roughness: 0.45,
metalness: 0.42
}),
pipeDark: new THREE.MeshStandardMaterial({
color: 0x182722,
roughness: 0.75
}),
tray: new THREE.MeshStandardMaterial({
color: 0xaa674d,
roughness: 0.84
}),
water: new THREE.MeshStandardMaterial({
color: 0x86b5b1,
roughness: 0.2,
transparent: true,
opacity: 0.66,
metalness: 0.05
}),
roofDeck: new THREE.MeshStandardMaterial({
color: 0xbdb7a6,
roughness: 0.93
}),
roofInsulation: new THREE.MeshStandardMaterial({
color: 0xc9a779,
roughness: 0.95
}),
roofMembrane: new THREE.MeshStandardMaterial({
color: 0x3d4945,
roughness: 0.86
}),
roofSeam: new THREE.MeshStandardMaterial({
color: 0x59645f,
roughness: 0.9
})
};
function addBox(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addTube(points, radius, material, segments = 28, parent = scene) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 7, false),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Planter shell — the front wall is intentionally omitted to expose the cut.
// -------------------------------------------------------------------------
const planterX = -1.0;
const planterWidth = 3.7;
const planterDepth = 1.7;
const planterLeft = planterX - planterWidth / 2;
const planterRight = planterX + planterWidth / 2;
const planterFront = planterDepth / 2;
const planterBack = -planterDepth / 2;
const wallThickness = 0.16;
addBox(
planterWidth,
0.22,
planterDepth,
materials.container,
planterX,
0.11,
0
);
addBox(
wallThickness,
1.5,
planterDepth,
materials.container,
planterLeft + wallThickness / 2,
0.96,
0
);
addBox(
wallThickness,
1.5,
planterDepth,
materials.container,
planterRight - wallThickness / 2,
0.96,
0
);
addBox(
planterWidth,
1.5,
wallThickness,
materials.container,
planterX,
0.96,
planterBack + wallThickness / 2
);
// Rim around the retained walls.
addBox(
planterWidth + 0.08,
0.12,
0.21,
materials.containerRim,
planterX,
1.73,
planterBack + 0.015
);
addBox(
0.21,
0.12,
planterDepth,
materials.containerRim,
planterLeft + 0.015,
1.73,
0
);
addBox(
0.21,
0.12,
planterDepth,
materials.containerRim,
planterRight - 0.015,
1.73,
0
);
// Bright cut edges and a dashed outline identify the removed front face.
addBox(
planterWidth - 0.12,
0.035,
0.035,
materials.cutFace,
planterX,
0.235,
planterFront + 0.004
);
const cutOutlineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(planterLeft + 0.1, 0.24, planterFront + 0.025),
new THREE.Vector3(planterLeft + 0.1, 1.68, planterFront + 0.025),
new THREE.Vector3(planterRight - 0.1, 1.68, planterFront + 0.025),
new THREE.Vector3(planterRight - 0.1, 0.24, planterFront + 0.025)
]);
const cutOutline = new THREE.Line(
cutOutlineGeometry,
new THREE.LineDashedMaterial({
color: 0x42675e,
dashSize: 0.075,
gapSize: 0.055,
transparent: true,
opacity: 0.56
})
);
cutOutline.computeLineDistances();
scene.add(cutOutline);
// -------------------------------------------------------------------------
// Exposed layers
// -------------------------------------------------------------------------
const interiorWidth = 3.36;
addBox(
interiorWidth,
0.36,
1.48,
materials.aggregate,
planterX,
0.40,
-0.02
);
addBox(
interiorWidth,
0.03,
1.49,
materials.filter,
planterX,
0.595,
-0.02
);
addBox(
interiorWidth,
0.87,
1.48,
materials.soil,
planterX,
1.045,
-0.02
);
// Small aggregate stones on the exposed drainage face.
const stoneGeometry = new THREE.DodecahedronGeometry(0.072, 0);
const stoneMaterial = materials.aggregate.clone();
const stones = new THREE.InstancedMesh(stoneGeometry, stoneMaterial, 42);
const stoneDummy = new THREE.Object3D();
for (let i = 0; i < 42; i++) {
stoneDummy.position.set(
planterX - 1.55 + Math.random() * 3.1,
0.27 + Math.random() * 0.25,
0.735 + Math.random() * 0.018
);
stoneDummy.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
const s = 0.55 + Math.random() * 0.85;
stoneDummy.scale.set(s, s * (0.7 + Math.random() * 0.4), s);
stoneDummy.updateMatrix();
stones.setMatrixAt(i, stoneDummy.matrix);
stones.setColorAt(
i,
new THREE.Color().setHSL(
0.12,
0.06 + Math.random() * 0.06,
0.39 + Math.random() * 0.16
)
);
}
stones.castShadow = true;
stones.receiveShadow = true;
scene.add(stones);
// Soil grains across the cut face.
const grainGeometry = new THREE.SphereGeometry(0.016, 6, 5);
const grainMaterial = materials.soilLight.clone();
const grains = new THREE.InstancedMesh(grainGeometry, grainMaterial, 80);
const grainDummy = new THREE.Object3D();
for (let i = 0; i < 80; i++) {
grainDummy.position.set(
planterX - 1.54 + Math.random() * 3.08,
0.64 + Math.random() * 0.80,
0.724 + Math.random() * 0.012
);
grainDummy.scale.setScalar(0.55 + Math.random() * 1.15);
grainDummy.updateMatrix();
grains.setMatrixAt(i, grainDummy.matrix);
grains.setColorAt(
i,
new THREE.Color().setHSL(
0.075,
0.22 + Math.random() * 0.12,
0.23 + Math.random() * 0.17
)
);
}
grains.receiveShadow = true;
scene.add(grains);
// A few surface fragments keep the soil plane from reading as a solid block.
const surfaceStoneGeometry = new THREE.IcosahedronGeometry(0.035, 0);
const surfaceStones = new THREE.InstancedMesh(
surfaceStoneGeometry,
materials.soilDark,
24
);
for (let i = 0; i < 24; i++) {
grainDummy.position.set(
planterX - 1.55 + Math.random() * 3.1,
1.49,
-0.60 + Math.random() * 1.2
);
grainDummy.rotation.set(
Math.random() * 2,
Math.random() * 2,
Math.random() * 2
);
grainDummy.scale.set(
0.7 + Math.random(),
0.35 + Math.random() * 0.4,
0.7 + Math.random()
);
grainDummy.updateMatrix();
surfaceStones.setMatrixAt(i, grainDummy.matrix);
}
surfaceStones.castShadow = true;
surfaceStones.receiveShadow = true;
scene.add(surfaceStones);
// -------------------------------------------------------------------------
// Root network, shown against the soil cut face
// -------------------------------------------------------------------------
addTube(
[
[-1.05, 1.48, 0.745],
[-1.02, 1.27, 0.748],
[-0.94, 1.08, 0.752],
[-1.04, 0.82, 0.754],
[-1.01, 0.55, 0.756],
[-0.92, 0.38, 0.758]
],
0.025,
materials.root,
38
);
const rootBranches = [
[
[-1.02, 1.27, 0.75],
[-1.28, 1.13, 0.752],
[-1.53, 0.95, 0.754],
[-1.72, 0.78, 0.756]
],
[
[-0.95, 1.08, 0.754],
[-0.68, 0.97, 0.756],
[-0.48, 0.79, 0.758],
[-0.36, 0.63, 0.76]
],
[
[-1.03, 0.82, 0.756],
[-1.32, 0.73, 0.758],
[-1.53, 0.58, 0.76]
],
[
[-1.02, 0.88, 0.757],
[-0.82, 0.70, 0.759],
[-0.78, 0.49, 0.761]
],
[
[-1.28, 1.13, 0.754],
[-1.32, 1.31, 0.756],
[-1.43, 1.40, 0.758]
],
[
[-0.68, 0.97, 0.758],
[-0.62, 1.14, 0.76],
[-0.55, 1.23, 0.762]
],
[
[-1.53, 0.95, 0.756],
[-1.62, 1.05, 0.758],
[-1.78, 1.08, 0.76]
],
[
[-0.48, 0.79, 0.76],
[-0.42, 0.91, 0.762],
[-0.30, 0.96, 0.764]
]
];
rootBranches.forEach((points) =>
addTube(points, 0.014, materials.root, 24)
);
// -------------------------------------------------------------------------
// Stylized plant and leaf construction
// -------------------------------------------------------------------------
function makeLeafGeometry(length, width) {
const rows = 12;
const columns = 7;
const positions = [];
const indices = [];
for (let i = 0; i <= rows; i++) {
const u = i / rows;
const halfWidth =
Math.max(0.006, Math.pow(Math.sin(Math.PI * u), 0.72)) * width;
for (let j = 0; j <= columns; j++) {
const v = (j / columns) * 2 - 1;
positions.push(
v * halfWidth,
u * length,
0.13 * Math.sin(Math.PI * u) * (1 - v * v)
);
}
}
for (let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
const a = i * (columns + 1) + j;
const b = a + columns + 1;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const leafMaterials = [
materials.leafA,
materials.leafB,
materials.leafC
];
function addLeaf(base, direction, length, width, materialIndex, twist) {
const leaf = new THREE.Mesh(
makeLeafGeometry(length, width),
leafMaterials[materialIndex % leafMaterials.length]
);
leaf.position.set(...base);
const alignment = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(...direction).normalize()
);
const localTwist = new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 1, 0),
twist
);
leaf.quaternion.copy(alignment).multiply(localTwist);
leaf.castShadow = true;
leaf.receiveShadow = true;
scene.add(leaf);
const vein = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0.015, 0.025),
new THREE.Vector3(0, length * 0.48, 0.15),
new THREE.Vector3(0, length * 0.94, 0.035)
]),
18,
0.009,
5,
false
),
materials.stem
);
leaf.add(vein);
return leaf;
}
addTube(
[
[-1.05, 1.47, -0.02],
[-1.12, 1.83, -0.03],
[-1.05, 2.20, 0.02],
[-1.11, 2.61, -0.03],
[-1.02, 3.14, 0.00]
],
0.037,
materials.stem,
42
);
const leaves = [
{
branch: [-1.10, 1.71, -0.01],
base: [-1.56, 1.93, 0.11],
direction: [-0.80, 0.48, 0.18],
length: 0.88,
width: 0.31,
material: 0,
twist: 0.18
},
{
branch: [-1.08, 1.93, 0.00],
base: [-0.59, 2.15, 0.14],
direction: [0.82, 0.42, 0.14],
length: 0.91,
width: 0.30,
material: 1,
twist: -0.25
},
{
branch: [-1.07, 2.14, 0.01],
base: [-1.56, 2.34, -0.10],
direction: [-0.73, 0.52, -0.28],
length: 0.82,
width: 0.28,
material: 2,
twist: 0.42
},
{
branch: [-1.08, 2.33, 0.00],
base: [-0.60, 2.57, 0.06],
direction: [0.74, 0.50, -0.12],
length: 0.84,
width: 0.29,
material: 0,
twist: -0.18
},
{
branch: [-1.09, 2.54, -0.01],
base: [-1.48, 2.78, 0.12],
direction: [-0.66, 0.58, 0.28],
length: 0.77,
width: 0.27,
material: 1,
twist: 0.27
},
{
branch: [-1.07, 2.72, -0.01],
base: [-0.63, 2.95, -0.10],
direction: [0.68, 0.56, -0.20],
length: 0.75,
width: 0.26,
material: 2,
twist: -0.36
},
{
branch: [-1.05, 2.88, 0.00],
base: [-1.28, 3.18, 0.04],
direction: [-0.35, 0.82, 0.12],
length: 0.62,
width: 0.23,
material: 0,
twist: 0.1
},
{
branch: [-1.04, 2.91, 0.00],
base: [-0.76, 3.25, -0.04],
direction: [0.38, 0.80, -0.12],
length: 0.59,
width: 0.22,
material: 1,
twist: -0.12
}
];
leaves.forEach((leaf) => {
addTube(
[
leaf.branch,
[
(leaf.branch[0] + leaf.base[0]) * 0.5,
(leaf.branch[1] + leaf.base[1]) * 0.5 + 0.02,
(leaf.branch[2] + leaf.base[2]) * 0.5
],
leaf.base
],
0.021,
materials.stem,
20
);
addLeaf(
leaf.base,
leaf.direction,
leaf.length,
leaf.width,
leaf.material,
leaf.twist
);
});
// -------------------------------------------------------------------------
// Lower side outlet and shallow tray
// -------------------------------------------------------------------------
const outletY = 0.39;
const outletZ = 0;
const flange = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.045, 10, 28),
materials.pipe
);
flange.position.set(planterRight + 0.025, outletY, outletZ);
flange.rotation.y = Math.PI / 2;
flange.castShadow = true;
scene.add(flange);
const outletPipe = new THREE.Mesh(
new THREE.CylinderGeometry(0.125, 0.125, 0.72, 24, 1, true),
materials.pipe
);
outletPipe.position.set(1.19, outletY, outletZ);
outletPipe.rotation.z = Math.PI / 2;
outletPipe.castShadow = true;
outletPipe.receiveShadow = true;
scene.add(outletPipe);
const outletOpening = new THREE.Mesh(
new THREE.CircleGeometry(0.105, 24),
materials.pipeDark
);
outletOpening.position.set(1.557, outletY, outletZ);
outletOpening.rotation.y = Math.PI / 2;
scene.add(outletOpening);
const trayX = 1.56;
const trayZ = 0;
addBox(0.84, 0.055, 0.64, materials.tray, trayX, 0.028, trayZ);
addBox(0.055, 0.15, 0.64, materials.tray, trayX - 0.39, 0.105, trayZ);
addBox(0.055, 0.15, 0.64, materials.tray, trayX + 0.39, 0.105, trayZ);
addBox(0.84, 0.15, 0.055, materials.tray, trayX, 0.105, trayZ - 0.29);
addBox(0.84, 0.15, 0.055, materials.tray, trayX, 0.105, trayZ + 0.29);
const trayWater = new THREE.Mesh(
new THREE.PlaneGeometry(0.72, 0.51),
materials.water
);
trayWater.rotation.x = -Math.PI / 2;
trayWater.position.set(trayX, 0.083, trayZ);
trayWater.receiveShadow = true;
scene.add(trayWater);
// A single droplet makes the outlet's relationship to the tray legible.
const droplet = new THREE.Mesh(
new THREE.SphereGeometry(0.042, 12, 10),
materials.water
);
droplet.scale.set(0.78, 1.4, 0.78);
droplet.position.set(1.56, 0.265, outletZ);
scene.add(droplet);
// -------------------------------------------------------------------------
// Adjacent roof-surface sample
// -------------------------------------------------------------------------
const roofX = 3.05;
const roofZ = -1.08;
addBox(
2.35,
0.16,
1.55,
materials.roofDeck,
roofX,
0.08,
roofZ
);
addBox(
2.35,
0.10,
1.55,
materials.roofInsulation,
roofX,
0.21,
roofZ
);
addBox(
2.35,
0.07,
1.55,
materials.roofMembrane,
roofX,
0.295,
roofZ
);
// Quiet seam lines make it recognizable as a simple roofing surface sample.
addBox(
0.022,
0.008,
1.49,
materials.roofSeam,
roofX - 0.34,
0.335,
roofZ
);
addBox(
0.022,
0.008,
1.49,
materials.roofSeam,
roofX + 0.57,
0.335,
roofZ
);
// -------------------------------------------------------------------------
// Projected HTML labels and SVG leader lines
// -------------------------------------------------------------------------
const labelDefinitions = [
{
text: "growing medium",
target: new THREE.Vector3(-1.92, 1.09, 0.735),
offset: [-145, -63],
color: "#654733"
},
{
text: "drainage aggregate",
target: new THREE.Vector3(-0.28, 0.39, 0.74),
offset: [-80, 83],
color: "#858276"
},
{
text: "separating filter",
target: new THREE.Vector3(-2.20, 0.60, 0.735),
offset: [-112, 52],
color: "#b7ad8f"
},
{
text: "root network",
target: new THREE.Vector3(-0.96, 1.04, 0.758),
offset: [66, -51],
color: "#c3a56d"
},
{
text: "outlet + tray",
target: new THREE.Vector3(1.48, 0.39, 0),
offset: [80, 76],
color: "#415650"
},
{
text: "roof surface sample",
target: new THREE.Vector3(2.93, 0.34, roofZ),
offset: [83, -67],
color: "#3d4945"
}
];
const svg = document.getElementById("leaders");
const svgNS = "http://www.w3.org/2000/svg";
labelDefinitions.forEach((label) => {
const element = document.createElement("div");
element.className = "tag";
element.textContent = label.text;
element.style.setProperty("--tag-color", label.color);
document.body.appendChild(element);
label.element = element;
const line = document.createElementNS(svgNS, "line");
svg.appendChild(line);
label.line = line;
const dot = document.createElementNS(svgNS, "circle");
dot.setAttribute("r", "3");
svg.appendChild(dot);
label.dot = dot;
});
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
const compact = width < 760;
labelDefinitions.forEach((label) => {
const projected = label.target.clone().project(camera);
const targetX = (projected.x * 0.5 + 0.5) * width;
const targetY = (-projected.y * 0.5 + 0.5) * height;
const offsetScale = compact ? 0.7 : 1;
const labelX = THREE.MathUtils.clamp(
targetX + label.offset[0] * offsetScale,
75,
width - 75
);
const labelY = THREE.MathUtils.clamp(
targetY + label.offset[1] * offsetScale,
92,
height - 80
);
label.element.style.left = `${labelX}px`;
label.element.style.top = `${labelY}px`;
label.line.setAttribute("x1", targetX);
label.line.setAttribute("y1", targetY);
label.line.setAttribute("x2", labelX);
label.line.setAttribute("y2", labelY);
label.dot.setAttribute("cx", targetX);
label.dot.setAttribute("cy", targetY);
});
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, wheel zoom, and pinch zoom
// -------------------------------------------------------------------------
const defaultTarget = new THREE.Vector3(-0.15, 1.34, -0.12);
const target = defaultTarget.clone();
let radius = 10.7;
let theta = 0.58;
let phi = 1.16;
function updateCamera() {
const sinPhi = Math.sin(phi);
const offset = new THREE.Vector3(
radius * sinPhi * Math.sin(theta),
radius * Math.cos(phi),
radius * sinPhi * Math.cos(theta)
);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
function resetView() {
target.copy(defaultTarget);
radius = 10.7;
theta = 0.58;
phi = 1.16;
updateCamera();
}
const pointers = new Map();
let dragMode = "orbit";
let pinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
dragMode = "pinch";
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY
};
pointers.set(event.pointerId, current);
if (pointers.size >= 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / distance),
6.2,
16
);
updateCamera();
}
pinchDistance = distance;
return;
}
const dx = current.x - previous.x;
const dy = current.y - previous.y;
if (dragMode === "orbit") {
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.35, 1.48);
} else if (dragMode === "pan") {
const forward = target.clone().sub(camera.position).normalize();
const right = forward.clone().cross(camera.up).normalize();
const up = right.clone().cross(forward).normalize();
const panScale = radius * 0.00125;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(up, dy * panScale);
target.x = THREE.MathUtils.clamp(target.x, -3.5, 4.5);
target.y = THREE.MathUtils.clamp(target.y, 0.45, 3.2);
target.z = THREE.MathUtils.clamp(target.z, -2.2, 2.2);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragMode = "orbit";
pinchDistance = 0;
} else if (pointers.size === 1) {
dragMode = "orbit";
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
6.2,
16
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
svg.setAttribute("viewBox", `0 0 ${innerWidth} ${innerHeight}`);
}
addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```