Prompt specification
Build or customize the Three.js 3D scene "High Line planting-edge and rail fragment" 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: High Line planting-edge and rail fragment
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/high-line-planting-edge-and-rail-fragment-x2769
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: High Line planting-edge and rail fragment. Build a referenced High Line paving fragment with retained rail, planting edge, and bench detail. Keep the old rail distinct from the current pedestrian surface. Return one self-contained HTML file.
Working Three.js Starter (high-line-planting-edge-and-rail-fragment-x2769):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>High Line — Retained Rail & Planting Edge</title>
<style>
:root {
--ink: #25302d;
--muted: #67706a;
--paper: rgba(247, 245, 236, 0.86);
--line: rgba(37, 48, 45, 0.2);
--rail: #515a56;
--path: #bd9d6d;
--plant: #71805f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d7cc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.masthead {
position: fixed;
z-index: 10;
top: 28px;
left: 32px;
width: min(390px, calc(100vw - 64px));
pointer-events: none;
text-shadow: 0 1px 12px rgba(245, 243, 234, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #59625c;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 1px;
background: currentColor;
content: "";
}
h1 {
max-width: 360px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 52px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro {
max-width: 330px;
margin: 16px 0 0;
color: #58615b;
font-size: 12px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 10;
left: 32px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: 500px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
min-height: 31px;
padding: 7px 11px;
border: 1px solid rgba(62, 69, 61, 0.13);
border-radius: 999px;
background: rgba(247, 245, 236, 0.76);
box-shadow: 0 8px 24px rgba(55, 58, 49, 0.07);
backdrop-filter: blur(8px);
color: #555e57;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.swatch {
width: 17px;
height: 4px;
border-radius: 2px;
}
.swatch.rail {
background: var(--rail);
}
.swatch.path {
background: var(--path);
}
.swatch.plant {
background: var(--plant);
}
.controls {
position: fixed;
z-index: 12;
right: 28px;
bottom: 27px;
display: flex;
align-items: center;
gap: 10px;
}
.hint {
padding: 8px 11px;
border: 1px solid rgba(62, 69, 61, 0.12);
border-radius: 8px;
background: rgba(247, 245, 236, 0.68);
color: #6b726c;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
backdrop-filter: blur(8px);
pointer-events: none;
}
button {
display: grid;
width: 38px;
height: 38px;
padding: 0;
place-items: center;
border: 1px solid rgba(48, 58, 52, 0.18);
border-radius: 50%;
background: rgba(248, 246, 237, 0.88);
box-shadow: 0 8px 24px rgba(48, 54, 45, 0.1);
color: #3e4943;
cursor: pointer;
backdrop-filter: blur(8px);
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffdf5;
}
button svg {
width: 16px;
height: 16px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.7;
}
.hotspot {
position: fixed;
z-index: 8;
width: 14px;
height: 14px;
border: 1px solid rgba(40, 49, 44, 0.7);
border-radius: 50%;
background: rgba(250, 248, 239, 0.76);
box-shadow: 0 4px 14px rgba(45, 49, 42, 0.12);
opacity: 0;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 180ms ease;
}
.hotspot::before {
position: absolute;
top: 50%;
left: 50%;
width: 4px;
height: 4px;
border-radius: 50%;
background: #39443e;
content: "";
transform: translate(-50%, -50%);
}
.hotspot span {
position: absolute;
top: 50%;
left: 20px;
width: max-content;
max-width: 180px;
padding: 6px 9px;
border: 1px solid rgba(45, 55, 49, 0.11);
border-radius: 5px;
background: rgba(248, 246, 238, 0.82);
box-shadow: 0 7px 18px rgba(44, 50, 42, 0.07);
color: #4e5952;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
line-height: 1.3;
text-transform: uppercase;
transform: translateY(-50%);
backdrop-filter: blur(7px);
}
.hotspot.visible {
opacity: 1;
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #dedcd1;
color: #5c655f;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.masthead {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
h1 {
max-width: 280px;
font-size: 34px;
}
.intro,
.legend,
.hint,
.hotspot span {
display: none;
}
.controls {
right: 18px;
bottom: 18px;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Constructing the High Line fragment</div>
<header class="masthead">
<div class="eyebrow">High Line / Planting Edge Study</div>
<h1>Between track<br />and garden</h1>
<p class="intro">
A fragment of the retained 1934 rail line set apart from the clean,
contemporary pedestrian promenade.
</p>
</header>
<div class="legend" aria-label="Scene legend">
<div class="legend-item"><span class="swatch rail"></span>Retained rail</div>
<div class="legend-item"><span class="swatch path"></span>Current paving</div>
<div class="legend-item"><span class="swatch plant"></span>Planting edge</div>
</div>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<button id="resetView" type="button" title="Reset view" aria-label="Reset view">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 12a8 8 0 1 0 2.34-5.66L4 8.68"></path>
<path d="M4 4v4.68h4.68"></path>
</svg>
</button>
</div>
<div class="hotspot" id="railHotspot"><span>Retained rail</span></div>
<div class="hotspot" id="plantHotspot"><span>Planting edge</span></div>
<div class="hotspot" id="benchHotspot"><span>Public bench</span></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d7cc);
scene.fog = new THREE.Fog(0xd9d7cc, 31, 64);
const camera = new THREE.PerspectiveCamera(
37,
innerWidth / innerHeight,
0.1,
120
);
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(0xf4f0df, 0x69736c, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(-10, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9ccd0, 0.65);
fill.position.set(9, 8, -11);
scene.add(fill);
let seed = 1934;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(a, b) {
return a + (b - a) * random();
}
const materials = {
deck: new THREE.MeshStandardMaterial({ color: 0xaaa89b, roughness: 0.94 }),
deckEdge: new THREE.MeshStandardMaterial({ color: 0x8e9087, roughness: 0.97 }),
steel: new THREE.MeshStandardMaterial({
color: 0x3e4642,
roughness: 0.56,
metalness: 0.55
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x303835,
roughness: 0.48,
metalness: 0.68
}),
railHead: new THREE.MeshStandardMaterial({
color: 0x606762,
roughness: 0.36,
metalness: 0.82
}),
tie: new THREE.MeshStandardMaterial({ color: 0x59493b, roughness: 1 }),
ballast: new THREE.MeshStandardMaterial({ color: 0x68665b, roughness: 1 }),
grout: new THREE.MeshStandardMaterial({ color: 0x817d70, roughness: 1 }),
soil: new THREE.MeshStandardMaterial({ color: 0x48483a, roughness: 1 }),
curb: new THREE.MeshStandardMaterial({ color: 0xb7b3a4, roughness: 0.92 }),
wood: new THREE.MeshStandardMaterial({ color: 0x946d47, roughness: 0.82 }),
woodDark: new THREE.MeshStandardMaterial({ color: 0x674b34, roughness: 0.93 }),
tactile: new THREE.MeshStandardMaterial({ color: 0xb69769, roughness: 0.92 }),
ground: new THREE.MeshStandardMaterial({ color: 0xc9c7ba, roughness: 1 })
};
const pavingMaterials = [
new THREE.MeshStandardMaterial({ color: 0xc4b38f, roughness: 0.94 }),
new THREE.MeshStandardMaterial({ color: 0xbba783, roughness: 0.96 }),
new THREE.MeshStandardMaterial({ color: 0xc8b997, roughness: 0.92 }),
new THREE.MeshStandardMaterial({ color: 0xb3a17d, roughness: 0.97 }),
new THREE.MeshStandardMaterial({ color: 0xc1ad88, roughness: 0.95 })
];
function addMesh(geometry, material, position, cast = true, receive = true) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
function pathCenter(z) {
return 2.15 + 0.42 * Math.sin(z * 0.23);
}
function pathDerivative(z) {
return 0.42 * 0.23 * Math.cos(z * 0.23);
}
function railCenter(z) {
return -3.15 + 0.38 * Math.sin(z * 0.21 + 0.7);
}
function railDerivative(z) {
return 0.38 * 0.21 * Math.cos(z * 0.21 + 0.7);
}
function plantCenter(z) {
return pathCenter(z) - 2.93;
}
function outerPlantCenter(z) {
return pathCenter(z) + 2.96;
}
function appendPrism(positions, indices, corners, bottom, top) {
const base = positions.length / 3;
for (const [x, z] of corners) positions.push(x, bottom, z);
for (const [x, z] of corners) positions.push(x, top, z);
indices.push(
base + 4, base + 5, base + 6,
base + 4, base + 6, base + 7,
base, base + 2, base + 1,
base, base + 3, base + 2,
base, base + 1, base + 5,
base, base + 5, base + 4,
base + 1, base + 2, base + 6,
base + 1, base + 6, base + 5,
base + 2, base + 3, base + 7,
base + 2, base + 7, base + 6,
base + 3, base, base + 4,
base + 3, base + 4, base + 7
);
}
function prismGeometry(corners, bottom, top) {
const positions = [];
const indices = [];
appendPrism(positions, indices, corners, bottom, top);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function ribbonGeometry(centerFn, halfWidth, bottom, top, start = -11.45, end = 11.45, segments = 64) {
const positions = [];
const indices = [];
for (let i = 0; i < segments; i++) {
const z0 = start + (end - start) * (i / segments);
const z1 = start + (end - start) * ((i + 1) / segments);
const corners = [
[centerFn(z0) - halfWidth, z0],
[centerFn(z0) - halfWidth, z1],
[centerFn(z1) + halfWidth, z1],
[centerFn(z1) + halfWidth, z0]
];
appendPrism(positions, indices, corners, bottom, top);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// Elevated structural fragment.
const deck = addMesh(
new THREE.BoxGeometry(12.8, 0.58, 23.5),
materials.deck,
[0, -0.325, 0]
);
deck.receiveShadow = true;
addMesh(
new THREE.BoxGeometry(12.92, 0.12, 23.62),
materials.deckEdge,
[0, -0.59, 0]
);
// Dark steel supports and cross members.
for (const x of [-4.8, 4.8]) {
for (const z of [-7.7, 7.7]) {
addMesh(
new THREE.BoxGeometry(0.34, 2.8, 0.34),
materials.steel,
[x, -2.0, z]
);
addMesh(
new THREE.BoxGeometry(0.72, 0.14, 0.72),
materials.darkSteel,
[x, -3.37, z]
);
}
}
for (const z of [-7.7, 7.7]) {
addMesh(
new THREE.BoxGeometry(9.95, 0.24, 0.32),
materials.steel,
[0, -0.82, z]
);
}
// Ground and restrained city context.
const ground = addMesh(
new THREE.PlaneGeometry(120, 120),
materials.ground,
[0, -3.46, 0],
false,
true
);
ground.rotation.x = -Math.PI / 2;
const cityMaterials = [
new THREE.MeshStandardMaterial({ color: 0xb9b8ad, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xc4c1b4, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xaaa99f, roughness: 1 })
];
const cityBlocks = [
[-9.5, -23, 5.2, 6.5, 5.0],
[-4.2, -24, 5.8, 8.4, 4.8],
[2.1, -23.5, 5.4, 5.7, 5.2],
[8.2, -24, 6.1, 7.2, 4.7],
[14.0, -17, 4.5, 4.6, 5.4]
];
cityBlocks.forEach(([x, z, w, h, d], i) => {
addMesh(
new THREE.BoxGeometry(w, h, d),
cityMaterials[i % cityMaterials.length],
[x, -3.46 + h / 2, z]
);
addMesh(
new THREE.BoxGeometry(w * 0.42, 0.34, d * 0.48),
cityMaterials[(i + 1) % cityMaterials.length],
[x - w * 0.12, -3.46 + h + 0.17, z]
);
});
// Distinct, lower rail corridor.
addMesh(
ribbonGeometry(railCenter, 1.48, 0.005, 0.075),
materials.ballast
);
// The contemporary pedestrian surface.
addMesh(
ribbonGeometry(pathCenter, 2.56, 0.075, 0.205),
materials.grout
);
const rowLength = 1.37;
const rowGap = 0.035;
const columnWidth = 5.0 / 3;
for (let z = -10.88, row = 0; z < 10.9; z += rowLength, row++) {
const z0 = z + rowGap;
const z1 = z + rowLength - rowGap;
for (let column = 0; column < 3; column++) {
const offset = -2.5 + (column + 0.5) * columnWidth;
const left = offset - columnWidth / 2 + 0.018;
const right = offset + columnWidth / 2 - 0.018;
const top = 0.265 + range(-0.006, 0.006);
const corners = [
[pathCenter(z0) + left, z0],
[pathCenter(z0) + left, z1],
[pathCenter(z1) + right, z1],
[pathCenter(z1) + right, z0]
];
addMesh(
prismGeometry(corners, 0.185, top),
pavingMaterials[Math.floor(random() * pavingMaterials.length)]
);
}
}
// A narrow tactile inlay along the planting-side edge.
addMesh(
ribbonGeometry((z) => pathCenter(z) - 2.31, 0.16, 0.267, 0.279, -10.9, 10.9, 72),
materials.tactile
);
const tactileGeometry = new THREE.BoxGeometry(0.265, 0.012, 0.032);
const tactileCount = 98;
const tactile = new THREE.InstancedMesh(tactileGeometry, materials.tactile, tactileCount);
const dummy = new THREE.Object3D();
for (let i = 0; i < tactileCount; i++) {
const z = -10.8 + i * (21.6 / (tactileCount - 1));
dummy.position.set(pathCenter(z) - 2.31, 0.286, z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tactile.setMatrixAt(i, dummy.matrix);
}
tactile.receiveShadow = true;
scene.add(tactile);
// Raised planting strips, with curbs separating old and new surfaces.
addMesh(
ribbonGeometry(plantCenter, 0.39, 0.09, 0.265),
materials.soil
);
addMesh(
ribbonGeometry((z) => plantCenter(z) - 0.43, 0.075, 0.12, 0.345),
materials.curb
);
addMesh(
ribbonGeometry((z) => plantCenter(z) + 0.43, 0.075, 0.12, 0.345),
materials.curb
);
addMesh(
ribbonGeometry(outerPlantCenter, 0.32, 0.09, 0.25),
materials.soil
);
addMesh(
ribbonGeometry((z) => outerPlantCenter(z) - 0.36, 0.065, 0.11, 0.31),
materials.curb
);
addMesh(
ribbonGeometry((z) => outerPlantCenter(z) + 0.36, 0.065, 0.11, 0.31),
materials.curb
);
// Timber sleepers and steel rail plates.
for (let z = -10.8; z <= 10.8; z += 0.72) {
const angle = Math.atan2(railDerivative(z), 1);
const tie = addMesh(
new THREE.BoxGeometry(2.18, 0.11, 0.25),
materials.tie,
[railCenter(z), 0.145, z]
);
tie.rotation.y = angle;
for (const side of [-1, 1]) {
const plate = addMesh(
new THREE.BoxGeometry(0.27, 0.035, 0.25),
materials.darkSteel,
[railCenter(z) + side * 0.72, 0.21, z]
);
plate.rotation.y = angle;
}
}
// Continuous low-poly rail head and lower flange.
function createRailCurve(side) {
const points = [];
for (let z = -11.35; z <= 11.35; z += 0.42) {
points.push(new THREE.Vector3(railCenter(z) + side * 0.72, 0.29, z));
}
return new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.18);
}
for (const side of [-1, 1]) {
const headCurve = createRailCurve(side);
addMesh(
new THREE.TubeGeometry(headCurve, 150, 0.075, 4, false),
materials.railHead
);
const flangePoints = headCurve.points.map((p) => new THREE.Vector3(p.x, 0.165, p.z));
const flangeCurve = new THREE.CatmullRomCurve3(flangePoints, false, "catmullrom", 0.18);
addMesh(
new THREE.TubeGeometry(flangeCurve, 150, 0.046, 4, false),
materials.darkSteel
);
}
// Rectangular rail webs add a readable industrial profile.
const webGeometry = new THREE.BoxGeometry(0.052, 0.14, 0.43);
const webCount = 104;
const webs = new THREE.InstancedMesh(webGeometry, materials.darkSteel, webCount);
for (const side of [-1, 1]) {
for (let i = 0; i < 52; i++) {
const z = -10.95 + i * 0.425;
dummy.position.set(railCenter(z) + side * 0.72, 0.215, z);
dummy.rotation.set(0, Math.atan2(railDerivative(z), 1), 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
webs.setMatrixAt(side === -1 ? i : i + 52, dummy.matrix);
}
}
webs.castShadow = true;
scene.add(webs);
// Low-poly ballast stones.
const stoneGeometry = new THREE.DodecahedronGeometry(0.105, 0);
const stoneCount = 300;
const stones = new THREE.InstancedMesh(stoneGeometry, materials.ballast, stoneCount);
const stoneColor = new THREE.Color();
for (let i = 0; i < stoneCount; i++) {
const z = range(-11.2, 11.2);
const x = railCenter(z) + range(-1.35, 1.35);
const s = range(0.55, 1.45);
dummy.position.set(x, range(0.085, 0.15), z);
dummy.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
dummy.scale.set(s * range(0.7, 1.2), s * range(0.45, 0.8), s * range(0.7, 1.2));
dummy.updateMatrix();
stones.setMatrixAt(i, dummy.matrix);
stoneColor.setHSL(0.12, range(0.03, 0.1), range(0.34, 0.49));
stones.setColorAt(i, stoneColor);
}
stones.castShadow = true;
stones.receiveShadow = true;
scene.add(stones);
// Instanced faceted planting.
const shrubData = [];
for (let z = -10.65; z < 10.8; z += 0.78) {
for (let i = 0; i < 3; i++) {
shrubData.push({
x: plantCenter(z) + range(-0.25, 0.25),
z: z + range(-0.18, 0.18),
sx: range(0.22, 0.42),
sy: range(0.19, 0.43),
sz: range(0.22, 0.42),
hue: range(0.19, 0.27),
light: range(0.28, 0.43)
});
}
}
for (let z = -10.5; z < 10.8; z += 1.03) {
for (let i = 0; i < 2; i++) {
shrubData.push({
x: outerPlantCenter(z) + range(-0.18, 0.18),
z: z + range(-0.2, 0.2),
sx: range(0.18, 0.33),
sy: range(0.14, 0.28),
sz: range(0.18, 0.33),
hue: range(0.18, 0.25),
light: range(0.3, 0.42)
});
}
}
const shrubGeometry = new THREE.IcosahedronGeometry(1, 0);
const shrubMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const shrubs = new THREE.InstancedMesh(shrubGeometry, shrubMaterial, shrubData.length);
shrubData.forEach((s, i) => {
dummy.position.set(s.x, 0.27 + s.sy * 0.67, s.z);
dummy.rotation.set(random() * 0.5, random() * Math.PI * 2, random() * 0.4);
dummy.scale.set(s.sx, s.sy, s.sz);
dummy.updateMatrix();
shrubs.setMatrixAt(i, dummy.matrix);
stoneColor.setHSL(s.hue, 0.25, s.light);
shrubs.setColorAt(i, stoneColor);
});
shrubs.castShadow = true;
shrubs.receiveShadow = true;
scene.add(shrubs);
// Angular ornamental grass blades.
function makeGrassTuft() {
const positions = [];
const colors = [];
const color = new THREE.Color();
for (let i = 0; i < 9; i++) {
const angle = random() * Math.PI * 2;
const h = range(0.34, 0.69);
const width = range(0.018, 0.035);
const lean = range(0.06, 0.2);
const baseRadius = range(0, 0.08);
const bx = Math.cos(angle) * baseRadius;
const bz = Math.sin(angle) * baseRadius;
const sideX = Math.cos(angle + Math.PI / 2) * width;
const sideZ = Math.sin(angle + Math.PI / 2) * width;
const tx = bx + Math.cos(angle) * lean;
const tz = bz + Math.sin(angle) * lean;
positions.push(
bx - sideX, 0, bz - sideZ,
bx + sideX, 0, bz + sideZ,
tx, h, tz
);
color.setHSL(range(0.17, 0.24), range(0.28, 0.46), range(0.34, 0.53));
for (let j = 0; j < 3; j++) colors.push(color.r, color.g, color.b);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
return geometry;
}
const grassMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
side: THREE.DoubleSide,
roughness: 1
});
const grasses = [];
for (let z = -10.45; z < 10.7; z += 0.72) {
const tuft = new THREE.Mesh(makeGrassTuft(), grassMaterial);
tuft.position.set(plantCenter(z) + range(-0.27, 0.27), 0.27, z);
tuft.rotation.y = random() * Math.PI * 2;
tuft.userData.phase = random() * Math.PI * 2;
tuft.userData.baseZ = tuft.rotation.z;
tuft.receiveShadow = true;
grasses.push(tuft);
scene.add(tuft);
}
for (let z = -10.1; z < 10.7; z += 1.2) {
const tuft = new THREE.Mesh(makeGrassTuft(), grassMaterial);
tuft.position.set(outerPlantCenter(z) + range(-0.17, 0.17), 0.25, z);
tuft.rotation.y = random() * Math.PI * 2;
tuft.userData.phase = random() * Math.PI * 2;
tuft.userData.baseZ = tuft.rotation.z;
grasses.push(tuft);
scene.add(tuft);
}
// Bench, oriented along the path with its back toward the outer planter.
const bench = new THREE.Group();
const benchZ = 2.15;
bench.position.set(pathCenter(benchZ) + 1.33, 0.275, benchZ);
bench.rotation.y = Math.atan2(pathDerivative(benchZ), 1);
scene.add(bench);
function benchBox(size, position, material) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
bench.add(mesh);
return mesh;
}
for (let i = 0; i < 4; i++) {
benchBox([0.135, 0.085, 3.25], [-0.27 + i * 0.18, 0.47, 0], materials.wood);
}
for (let i = 0; i < 3; i++) {
benchBox([0.085, 0.125, 3.25], [0.39, 0.76 + i * 0.19, 0], materials.wood);
}
for (const z of [-1.18, 1.18]) {
benchBox([0.09, 0.48, 0.09], [0.38, 0.6, z], materials.darkSteel);
benchBox([0.09, 0.48, 0.09], [-0.25, 0.22, z], materials.darkSteel);
benchBox([0.72, 0.09, 0.09], [0.05, 0.39, z], materials.darkSteel);
benchBox([0.08, 0.08, 0.55], [0.27, 0.71, z + Math.sign(z) * 0.22], materials.darkSteel);
}
// A seated visitor adds human scale to the fragment.
const seated = new THREE.Group();
seated.position.set(-0.03, 0, 0.82);
bench.add(seated);
const coatMaterial = new THREE.MeshStandardMaterial({
color: 0x9b5d4e,
roughness: 0.92,
flatShading: true
});
const trouserMaterial = new THREE.MeshStandardMaterial({
color: 0x46535b,
roughness: 0.96
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xc89472,
roughness: 0.9,
flatShading: true
});
function cylinderBetween(a, b, radius, material, parent, radialSegments = 6) {
const av = new THREE.Vector3(...a);
const bv = new THREE.Vector3(...b);
const direction = bv.clone().sub(av);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 0.9, length, radialSegments),
material
);
mesh.position.copy(av).add(bv).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
const seatedTorso = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.25, 0.58, 7),
coatMaterial
);
seatedTorso.position.set(0, 0.94, 0);
seatedTorso.castShadow = true;
seated.add(seatedTorso);
const seatedHead = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.145, 1),
skinMaterial
);
seatedHead.position.set(-0.025, 1.38, 0);
seatedHead.castShadow = true;
seated.add(seatedHead);
cylinderBetween([-0.08, 0.61, 0.12], [-0.46, 0.56, 0.12], 0.085, trouserMaterial, seated);
cylinderBetween([-0.46, 0.56, 0.12], [-0.53, 0.12, 0.12], 0.07, trouserMaterial, seated);
cylinderBetween([-0.08, 0.61, -0.12], [-0.45, 0.56, -0.12], 0.085, trouserMaterial, seated);
cylinderBetween([-0.45, 0.56, -0.12], [-0.52, 0.12, -0.12], 0.07, trouserMaterial, seated);
cylinderBetween([-0.2, 1.09, 0.13], [-0.34, 0.68, 0.13], 0.055, coatMaterial, seated);
// Small standing visitor farther along the promenade.
function makeStandingPerson(x, z, coatColor, facing = 0) {
const group = new THREE.Group();
group.position.set(x, 0.275, z);
group.rotation.y = facing;
scene.add(group);
const coat = new THREE.MeshStandardMaterial({
color: coatColor,
roughness: 0.94,
flatShading: true
});
const trousers = new THREE.MeshStandardMaterial({
color: 0x4c5353,
roughness: 1
});
const skin = new THREE.MeshStandardMaterial({
color: 0xb97f5d,
roughness: 0.95,
flatShading: true
});
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.09, 0.7, 6),
trousers
);
leg.position.set(side * 0.095, 0.36, 0);
leg.castShadow = true;
group.add(leg);
const shoe = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.08, 0.23),
materials.darkSteel
);
shoe.position.set(side * 0.095, 0.035, -0.035);
shoe.castShadow = true;
group.add(shoe);
}
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.205, 0.27, 0.68, 7),
coat
);
torso.position.y = 1.04;
torso.castShadow = true;
group.add(torso);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.15, 1),
skin
);
head.position.y = 1.56;
head.castShadow = true;
group.add(head);
for (const side of [-1, 1]) {
cylinderBetween(
[side * 0.22, 1.27, 0],
[side * 0.3, 0.79, 0.02],
0.057,
coat,
group,
5
);
}
const bag = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.25, 0.09),
new THREE.MeshStandardMaterial({ color: 0x8c795b, roughness: 1 })
);
bag.position.set(0.32, 0.76, 0.02);
bag.castShadow = true;
group.add(bag);
return group;
}
makeStandingPerson(pathCenter(-4.7) + 0.55, -4.7, 0xb78a54, -0.35);
// Slim path lights along the outer edge.
for (const z of [-8.4, -3.7, 6.2, 9.2]) {
const lightGroup = new THREE.Group();
lightGroup.position.set(pathCenter(z) + 3.37, 0.27, z);
lightGroup.rotation.y = Math.atan2(pathDerivative(z), 1);
scene.add(lightGroup);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.06, 0.95, 6),
materials.darkSteel
);
post.position.y = 0.475;
post.castShadow = true;
lightGroup.add(post);
const head = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.11, 0.14),
materials.railHead
);
head.position.y = 0.98;
head.castShadow = true;
lightGroup.add(head);
}
// Direct camera controls implemented without external addons.
const controls = {
theta: 0.72,
phi: 0.98,
radius: 27,
target: new THREE.Vector3(0, 0.1, 0),
desiredTheta: 0.72,
desiredPhi: 0.98,
desiredRadius: 27,
desiredTarget: new THREE.Vector3(0, 0.1, 0)
};
const initialControls = {
theta: 0.72,
phi: 0.98,
radius: 27,
target: new THREE.Vector3(0, 0.1, 0)
};
let dragging = false;
let dragButton = 0;
let previousX = 0;
let previousY = 0;
const raycaster = new THREE.Raycaster();
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragButton = event.button;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragButton === 2 || event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = controls.desiredRadius * 0.00135;
controls.desiredTarget.addScaledVector(right, -dx * scale);
controls.desiredTarget.addScaledVector(up, dy * scale);
} else {
controls.desiredTheta -= dx * 0.0052;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.0045,
0.28,
1.43
);
}
});
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(
"wheel",
(event) => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
13,
43
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
function resetView() {
controls.desiredTheta = initialControls.theta;
controls.desiredPhi = initialControls.phi;
controls.desiredRadius = initialControls.radius;
controls.desiredTarget.copy(initialControls.target);
}
document.getElementById("resetView").addEventListener("click", resetView);
// Screen-space interpretive labels.
const hotspots = [
{
element: document.getElementById("railHotspot"),
point: new THREE.Vector3(railCenter(4.3), 0.55, 4.3)
},
{
element: document.getElementById("plantHotspot"),
point: new THREE.Vector3(plantCenter(-1.5), 0.85, -1.5)
},
{
element: document.getElementById("benchHotspot"),
point: new THREE.Vector3(pathCenter(benchZ) + 1.55, 1.35, benchZ + 0.35)
}
];
function updateHotspots() {
for (const hotspot of hotspots) {
const projected = hotspot.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
hotspot.element.classList.toggle("visible", visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
hotspot.element.style.left = `${x}px`;
hotspot.element.style.top = `${y}px`;
}
}
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
controls.theta += (controls.desiredTheta - controls.theta) * 0.085;
controls.phi += (controls.desiredPhi - controls.phi) * 0.085;
controls.radius += (controls.desiredRadius - controls.radius) * 0.085;
controls.target.lerp(controls.desiredTarget, 0.085);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
grasses.forEach((grass) => {
grass.rotation.z =
grass.userData.baseZ + Math.sin(elapsed * 0.85 + grass.userData.phase) * 0.035;
grass.rotation.x =
Math.cos(elapsed * 0.67 + grass.userData.phase) * 0.018;
});
updateHotspots();
renderer.render(scene, camera);
}
animate();
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
</script>
</body>
</html>
```