Prompt specification
Build or customize the Three.js 3D scene "Park model with a measuring cord" 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: Park model with a measuring cord
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/park-model-with-a-measuring-cord-x1322
Scene Description Prompt:
Park model with a measuring cord. Arrange a pond, gate, and kiosk on a scaled park tile. A draggable measuring cord reports ground distance without changing when the camera zooms. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (park-model-with-a-measuring-cord-x1322):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Park Scale — Measuring Cord</title>
<style>
:root {
--ink: #173f35;
--muted: #587068;
--paper: rgba(249, 247, 235, 0.92);
--line: rgba(28, 75, 61, 0.16);
--gold: #f6b83f;
--gold-dark: #a9680c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow:
0 14px 36px rgba(30, 67, 53, 0.14),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: auto;
}
#title-card {
position: absolute;
top: 18px;
left: 18px;
width: 292px;
padding: 16px 17px;
border-radius: 17px;
}
.eyebrow {
color: #547568;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 7px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.scale-note {
display: flex;
gap: 8px;
align-items: center;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #355e50;
font-size: 11px;
font-weight: 700;
}
.grid-icon {
width: 19px;
height: 19px;
border: 1px solid #658c79;
background:
linear-gradient(#658c79 1px, transparent 1px),
linear-gradient(90deg, #658c79 1px, transparent 1px);
background-size: 6px 6px;
opacity: 0.8;
}
#view-controls {
position: absolute;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border-radius: 15px;
}
button {
min-width: 38px;
height: 36px;
border: 1px solid rgba(30, 80, 63, 0.18);
border-radius: 10px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font: inherit;
font-size: 13px;
font-weight: 800;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button.text-button {
padding: 0 12px;
font-size: 11px;
}
#measure-card {
position: absolute;
left: 18px;
bottom: 18px;
width: 310px;
padding: 16px 17px;
border-radius: 17px;
}
.measure-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.locked {
display: inline-flex;
align-items: center;
gap: 5px;
color: #4d715f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.locked::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #4e9d6e;
box-shadow: 0 0 0 3px rgba(78, 157, 110, 0.14);
}
.distance-row {
display: flex;
align-items: baseline;
gap: 8px;
margin: 7px 0 3px;
}
#distance-value {
font-size: 42px;
line-height: 1;
font-weight: 850;
letter-spacing: -0.055em;
font-variant-numeric: tabular-nums;
}
.unit {
color: #5d766c;
font-size: 17px;
font-weight: 750;
}
#distance-delta {
color: #61776f;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.measure-hint {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #45685b;
font-size: 11px;
line-height: 1.4;
}
.gold-dot {
flex: 0 0 auto;
width: 11px;
height: 11px;
border: 3px solid #ffe19a;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 1px var(--gold-dark);
}
#help-card {
position: absolute;
right: 18px;
bottom: 18px;
max-width: 315px;
padding: 12px 14px;
border-radius: 14px;
color: #49675d;
font-size: 11px;
line-height: 1.55;
}
#help-card strong {
color: var(--ink);
}
kbd {
padding: 1px 5px;
border: 1px solid rgba(30, 80, 63, 0.2);
border-bottom-width: 2px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
}
#labels-toggle {
display: inline-flex;
align-items: center;
gap: 6px;
margin-left: 2px;
color: #4d685e;
font-size: 10px;
font-weight: 750;
white-space: nowrap;
cursor: pointer;
}
#labels-toggle input {
accent-color: #2f7359;
}
#poi-layer {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.poi-label {
position: absolute;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 8px;
background: rgba(248, 247, 232, 0.85);
box-shadow: 0 4px 12px rgba(26, 61, 48, 0.12);
color: #315648;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 100ms linear;
}
.poi-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -10px;
width: 1px;
height: 9px;
background: rgba(42, 87, 70, 0.4);
}
#measure-label {
position: absolute;
min-width: 82px;
padding: 7px 10px;
border: 2px solid #ffe3a0;
border-radius: 10px;
background: var(--gold);
box-shadow:
0 5px 14px rgba(104, 68, 8, 0.2),
0 0 0 1px rgba(139, 87, 8, 0.18);
color: #563704;
font-size: 12px;
font-weight: 900;
text-align: center;
white-space: nowrap;
transform: translate(-50%, -50%);
font-variant-numeric: tabular-nums;
pointer-events: none;
}
#measure-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -8px;
width: 2px;
height: 7px;
background: var(--gold-dark);
opacity: 0.55;
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: 245px;
padding: 13px 14px;
}
h1 {
font-size: 21px;
}
#view-controls {
top: 12px;
right: 12px;
gap: 5px;
padding: 6px;
}
#view-controls button {
min-width: 34px;
height: 34px;
}
#view-controls .text-button {
display: none;
}
#measure-card {
left: 12px;
bottom: 12px;
width: calc(100% - 24px);
max-width: 330px;
padding: 13px 14px;
}
#distance-value {
font-size: 34px;
}
#help-card {
display: none;
}
#labels-toggle {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="poi-layer">
<div id="pond-label" class="poi-label">POND</div>
<div id="gate-label" class="poi-label">GATE</div>
<div id="kiosk-label" class="poi-label">KIOSK</div>
<div id="measure-label">0.00 m</div>
</div>
<div id="hud">
<section id="title-card" class="glass">
<div class="eyebrow">Interactive scale model</div>
<h1>Park Scale</h1>
<p class="subtitle">
A low-poly park tile with a live, zoom-independent ground measurement.
</p>
<div class="scale-note">
<span class="grid-icon"></span>
<span>2 m grid · 10 m scale bar · 1 unit = 1 meter</span>
</div>
</section>
<section id="view-controls" class="glass" aria-label="View controls">
<button id="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
<button id="reset-view" class="text-button" title="Reset camera">
Reset view
</button>
<button id="reset-cord" class="text-button" title="Reset measurement">
Reset cord
</button>
<label id="labels-toggle">
<input id="show-labels" type="checkbox" checked>
Labels
</label>
</section>
<section id="measure-card" class="glass">
<div class="measure-heading">
<div class="eyebrow">Live ground distance</div>
<div class="locked">Zoom independent</div>
</div>
<div class="distance-row" aria-live="polite">
<span id="distance-value">0.00</span>
<span class="unit">m</span>
</div>
<div id="distance-delta">Δx 0.00 m · Δz 0.00 m</div>
<div class="measure-hint">
<span class="gold-dot"></span>
<span>
Drag a gold endpoint to resize. Drag the gold cord to move the
entire measurement.
</span>
</div>
</section>
<aside id="help-card" class="glass">
<strong>Camera</strong><br>
Left-drag to orbit · <kbd>Shift</kbd> or right-drag to pan ·
wheel to zoom.<br>
<strong>Shortcuts:</strong> <kbd>R</kbd> reset view ·
<kbd>M</kbd> reset cord · <kbd>+</kbd>/<kbd>−</kbd> zoom.
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene and renderer
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e2);
scene.fog = new THREE.Fog(0xdce8e2, 105, 190);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
250
);
const cameraTarget = new THREE.Vector3(0, 0, -1);
function resetCamera() {
const portrait = window.innerWidth / window.innerHeight < 0.9;
const radius = portrait ? 92 : 66;
const direction = new THREE.Vector3(1, 0.86, 1.15).normalize();
cameraTarget.set(0, 0, -1);
camera.position.copy(cameraTarget).addScaledVector(direction, radius);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
resetCamera();
const hemi = new THREE.HemisphereLight(0xf5fbff, 0x65775e, 1.65);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d1, 2.7);
sun.position.set(-24, 38, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.normalBias = 0.025;
scene.add(sun);
// One world unit represents one meter.
const PARK_WIDTH = 48;
const PARK_DEPTH = 36;
const GRID_SIZE = 2;
const MEASURE_Y = 0.24;
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
flatShading: true,
...options
});
}
const materials = {
ground: makeMaterial(0x91bd79),
groundSide: makeMaterial(0x789d65),
path: makeMaterial(0xd9c68d),
pathEdge: makeMaterial(0xc4ae78),
fence: makeMaterial(0xe9e2ca),
fencePost: makeMaterial(0xd5ccb0),
wood: makeMaterial(0x9b6b42),
woodDark: makeMaterial(0x68472f),
roof: makeMaterial(0xb95f42),
wall: makeMaterial(0xf0dfb4),
window: makeMaterial(0x315c59, {
roughness: 0.32,
metalness: 0.08
}),
trunk: makeMaterial(0x78533b),
pine: makeMaterial(0x397455),
leaf: makeMaterial(0x4f8a58),
leafLight: makeMaterial(0x6ca365),
pondEdge: makeMaterial(0xc8b982),
water: makeMaterial(0x4ca7b6, {
roughness: 0.28,
metalness: 0.04
}),
rock: makeMaterial(0x91988b),
lamp: makeMaterial(0xffe4a3, {
emissive: 0xffb83f,
emissiveIntensity: 0.55
}),
gold: makeMaterial(0xf6b83f, {
roughness: 0.5,
emissive: 0x7d4300,
emissiveIntensity: 0.12
}),
scaleDark: makeMaterial(0x35594d),
scaleLight: makeMaterial(0xefe8cf)
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(
parent,
width,
height,
depth,
x,
y,
z,
material
) {
const mesh = addMesh(
new THREE.BoxGeometry(width, height, depth),
material,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function createTextTexture(
text,
foreground = "#234c3f",
background = "#efe5c5"
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(28,70,55,0.15)";
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
let fontSize = 58;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
while (
context.measureText(text).width > 455 &&
fontSize > 25
) {
fontSize -= 2;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
}
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addTextPlane(
text,
width,
height,
foreground,
background
) {
const texture = createTextTexture(
text,
foreground,
background
);
const material = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
});
return addMesh(
new THREE.PlaneGeometry(width, height),
material
);
}
function addTextSprite(text, width = 2.4) {
const texture = createTextTexture(
text,
"#244d40",
"#e9dfbf"
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 5;
return sprite;
}
// ------------------------------------------------------------
// Park tile, metric grid, and surrounding table
// ------------------------------------------------------------
const table = addMesh(
new THREE.PlaneGeometry(240, 240),
makeMaterial(0xd4ddd3)
);
table.rotation.x = -Math.PI / 2;
table.position.y = -0.48;
table.castShadow = false;
const tile = addBox(
scene,
PARK_WIDTH,
0.45,
PARK_DEPTH,
0,
-0.225,
0,
materials.groundSide
);
tile.castShadow = false;
const tileTop = addBox(
scene,
PARK_WIDTH - 0.08,
0.04,
PARK_DEPTH - 0.08,
0,
-0.005,
0,
materials.ground
);
tileTop.castShadow = false;
// Custom two-color grid: minor lines every 2 m, major lines every 10 m.
const gridPositions = [];
const gridColors = [];
const minorColor = new THREE.Color(0x73996f);
const majorColor = new THREE.Color(0x4d7757);
function appendGridSegment(x1, z1, x2, z2, color) {
gridPositions.push(x1, 0.018, z1, x2, 0.018, z2);
gridColors.push(
color.r, color.g, color.b,
color.r, color.g, color.b
);
}
for (let x = -PARK_WIDTH / 2; x <= PARK_WIDTH / 2; x += GRID_SIZE) {
const color = x % 10 === 0 ? majorColor : minorColor;
appendGridSegment(
x, -PARK_DEPTH / 2,
x, PARK_DEPTH / 2,
color
);
}
for (let z = -PARK_DEPTH / 2; z <= PARK_DEPTH / 2; z += GRID_SIZE) {
const color = z % 10 === 0 ? majorColor : minorColor;
appendGridSegment(
-PARK_WIDTH / 2, z,
PARK_WIDTH / 2, z,
color
);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
gridGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(gridColors, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.42
})
);
scene.add(grid);
// Paths from the gate through the park to the kiosk.
addBox(scene, 3.2, 0.065, 27.5, 0, 0.035, 3.5, materials.path);
addBox(scene, 15.8, 0.065, 3.1, 7.3, 0.036, -7, materials.path);
addBox(scene, 9.6, 0.065, 2.4, -4.4, 0.037, 5.5, materials.path);
// ------------------------------------------------------------
// Low-park perimeter
// ------------------------------------------------------------
function addFenceRail(width, depth, x, z) {
addBox(scene, width, 0.12, depth, x, 0.72, z, materials.fence);
addBox(scene, width, 0.12, depth, x, 1.28, z, materials.fence);
}
addFenceRail(PARK_WIDTH - 0.7, 0.14, 0, -17.6);
addFenceRail(0.14, PARK_DEPTH - 0.7, -23.6, 0);
addFenceRail(0.14, PARK_DEPTH - 0.7, 23.6, 0);
addFenceRail(20.0, 0.14, -13.55, 17.6);
addFenceRail(20.0, 0.14, 13.55, 17.6);
function addFencePost(x, z) {
addBox(scene, 0.24, 1.65, 0.24, x, 0.825, z, materials.fencePost);
addBox(scene, 0.32, 0.16, 0.32, x, 1.66, z, materials.fence);
}
for (let x = -22; x <= 22; x += 4) {
addFencePost(x, -17.6);
}
for (let z = -15.5; z <= 15.5; z += 4) {
addFencePost(-23.6, z);
addFencePost(23.6, z);
}
for (let x = -22; x <= -4; x += 4) {
addFencePost(x, 17.6);
}
for (let x = 4; x <= 22; x += 4) {
addFencePost(x, 17.6);
}
// ------------------------------------------------------------
// Pond
// ------------------------------------------------------------
const pondX = -10;
const pondZ = -2;
const pondEdge = addMesh(
new THREE.CylinderGeometry(1, 1, 0.12, 14),
materials.pondEdge
);
pondEdge.position.set(pondX, 0.05, pondZ);
pondEdge.scale.set(7.65, 1, 4.85);
const pondWater = addMesh(
new THREE.CylinderGeometry(1, 1, 0.08, 14),
materials.water
);
pondWater.position.set(pondX, 0.14, pondZ);
pondWater.scale.set(7.05, 1, 4.3);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const rock = addMesh(
new THREE.DodecahedronGeometry(0.32, 0),
materials.rock
);
rock.position.set(
pondX + Math.cos(angle) * 7.45,
0.2,
pondZ + Math.sin(angle) * 4.65
);
rock.scale.set(
0.8 + (i % 3) * 0.15,
0.55 + (i % 2) * 0.15,
0.9
);
rock.rotation.set(i * 0.31, i * 0.57, i * 0.13);
}
for (let i = 0; i < 7; i++) {
const pad = addMesh(
new THREE.CylinderGeometry(0.28, 0.28, 0.025, 8),
makeMaterial(i % 2 ? 0x5e9a57 : 0x79a75d)
);
pad.position.set(
pondX - 3.2 + i * 1.05,
0.19,
pondZ + Math.sin(i * 1.7) * 1.25
);
}
// ------------------------------------------------------------
// Entrance gate
// ------------------------------------------------------------
const gate = new THREE.Group();
gate.position.set(0, 0, 16.2);
scene.add(gate);
addBox(gate, 0.62, 3.25, 0.62, -2.65, 1.625, 0, materials.fencePost);
addBox(gate, 0.62, 3.25, 0.62, 2.65, 1.625, 0, materials.fencePost);
addBox(gate, 6.05, 0.48, 0.7, 0, 3.0, 0, materials.fencePost);
addBox(gate, 6.65, 0.2, 0.9, 0, 3.37, 0, materials.scaleDark);
const gateSign = addTextPlane(
"PARK GATE",
3.6,
0.72,
"#f8edca",
"#285648"
);
gateSign.position.set(0, 2.62, 0.37);
gate.add(gateSign);
// ------------------------------------------------------------
// Information kiosk
// ------------------------------------------------------------
const kiosk = new THREE.Group();
kiosk.position.set(12, 0, -7);
scene.add(kiosk);
addBox(kiosk, 4.25, 2.8, 3.4, 0, 1.4, 0, materials.wall);
addBox(kiosk, 4.55, 0.18, 3.7, 0, 0.09, 0, materials.woodDark);
const kioskRoof = addMesh(
new THREE.ConeGeometry(3.45, 1.35, 4),
materials.roof,
kiosk
);
kioskRoof.rotation.y = Math.PI / 4;
kioskRoof.position.y = 3.45;
addBox(kiosk, 3.45, 1.25, 0.1, 0, 1.42, 1.74, materials.window);
addBox(kiosk, 3.8, 0.16, 0.65, 0, 0.85, 1.98, materials.wood);
addBox(kiosk, 0.1, 1.8, 1.1, 2.15, 1.25, -0.5, materials.woodDark);
const kioskSign = addTextPlane(
"INFO KIOSK",
2.9,
0.62,
"#fff0ca",
"#2d5c50"
);
kioskSign.position.set(0, 2.38, 1.81);
kiosk.add(kioskSign);
// ------------------------------------------------------------
// Trees, shrubs, benches, and lamps
// ------------------------------------------------------------
function addTree(x, z, type = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
const trunk = addMesh(
new THREE.CylinderGeometry(0.18, 0.29, 1.6, 6),
materials.trunk,
group
);
trunk.position.y = 0.8;
if (type === 0) {
const crown = addMesh(
new THREE.ConeGeometry(1.25, 2.9, 7),
materials.pine,
group
);
crown.position.y = 2.35;
} else {
const crown = addMesh(
new THREE.IcosahedronGeometry(1.3, 0),
materials.leaf,
group
);
crown.position.y = 2.35;
crown.scale.y = 1.12;
crown.rotation.y = x * 0.17;
const crownTop = addMesh(
new THREE.IcosahedronGeometry(0.9, 0),
materials.leafLight,
group
);
crownTop.position.set(0.35, 3.15, -0.12);
}
}
const treeLocations = [
[-19, 12, 0, 1.05],
[-20, 5, 1, 1.1],
[-18, -4, 0, 1.15],
[-17, -12, 1, 1.0],
[-8, -13, 0, 0.95],
[7, -13, 1, 1.0],
[19, 10, 0, 1.1],
[20, 2, 1, 1.05],
[18, -13, 0, 1.0],
[10, 12, 1, 0.95],
[-10, 11, 0, 0.8]
];
treeLocations.forEach(([x, z, type, scale]) => {
addTree(x, z, type, scale);
});
function addShrub(x, z, scale = 1) {
const shrub = addMesh(
new THREE.IcosahedronGeometry(0.55, 0),
materials.leafLight
);
shrub.position.set(x, 0.43, z);
shrub.scale.set(scale * 1.15, scale, scale);
shrub.rotation.y = x * 0.31;
}
[
[-16, 8], [-5, -10], [5, -9], [16, -2],
[17, 7], [-4, 12], [4, 9], [8, 10]
].forEach(([x, z], index) => {
addShrub(x, z, 0.85 + (index % 3) * 0.12);
});
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
addBox(group, 2.25, 0.16, 0.62, 0, 0.7, 0, materials.wood);
addBox(group, 2.25, 0.68, 0.13, 0, 1.08, -0.26, materials.wood);
addBox(group, 0.16, 0.65, 0.55, -0.78, 0.34, 0, materials.woodDark);
addBox(group, 0.16, 0.65, 0.55, 0.78, 0.34, 0, materials.woodDark);
}
addBench(-3.3, 10.1, 0);
addBench(3.2, -7.2, Math.PI / 2);
addBench(15, -0.7, 0);
addBench(-15.2, 6.8, Math.PI / 2);
function addLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const pole = addMesh(
new THREE.CylinderGeometry(0.055, 0.08, 2.55, 6),
materials.scaleDark,
group
);
pole.position.y = 1.275;
addBox(group, 0.38, 0.48, 0.38, 0, 2.72, 0, materials.lamp);
addBox(group, 0.52, 0.08, 0.52, 0, 3.0, 0, materials.scaleDark);
}
addLamp(-2.2, 11.5);
addLamp(2.2, 3);
addLamp(-2.2, -7.5);
addLamp(8.5, -5.1);
addLamp(16, 5.5);
// ------------------------------------------------------------
// Ten-meter scale bar and north marker
// ------------------------------------------------------------
const scaleBar = new THREE.Group();
scaleBar.position.set(-18, 0.09, 14.1);
scene.add(scaleBar);
for (let i = 0; i < 5; i++) {
addBox(
scaleBar,
2,
0.08,
0.46,
i * 2 + 1,
0,
0,
i % 2 ? materials.scaleDark : materials.scaleLight
);
}
for (let i = 0; i <= 5; i++) {
addBox(
scaleBar,
0.08,
0.16,
0.66,
i * 2,
0.04,
0,
materials.scaleDark
);
}
const scaleText = addTextSprite("10 m", 2.1);
scaleText.position.set(5, 0.7, 0);
scaleBar.add(scaleText);
const compass = new THREE.Group();
compass.position.set(19, 0.14, 13);
scene.add(compass);
const northArrow = addMesh(
new THREE.ConeGeometry(0.43, 1.55, 3),
materials.scaleDark,
compass
);
northArrow.rotation.x = -Math.PI / 2;
northArrow.position.y = 0.08;
const northText = addTextSprite("N", 0.75);
northText.position.set(0, 0.7, -1.2);
compass.add(northText);
// ------------------------------------------------------------
// Measuring cord and endpoints
// ------------------------------------------------------------
const initialA = new THREE.Vector3(0, MEASURE_Y, 8);
const initialB = new THREE.Vector3(11.5, MEASURE_Y, -4.8);
const endpoints = [initialA.clone(), initialB.clone()];
const ropeMaterial = makeMaterial(0xf6b83f, {
roughness: 0.62,
emissive: 0x754000,
emissiveIntensity: 0.1
});
const rope = addMesh(
new THREE.CylinderGeometry(0.055, 0.055, 1, 8),
ropeMaterial
);
// A wider invisible cylinder makes the rope itself easy to grab.
const invisibleMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const ropeHit = new THREE.Mesh(
new THREE.CylinderGeometry(0.4, 0.4, 1, 8),
invisibleMaterial
);
ropeHit.userData.control = "cord";
scene.add(ropeHit);
const endpointGroups = [];
const endpointHitTargets = [];
for (let i = 0; i < 2; i++) {
const group = new THREE.Group();
scene.add(group);
const puck = addMesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.18, 12),
materials.gold,
group
);
const ring = addMesh(
new THREE.TorusGeometry(0.48, 0.075, 6, 16),
materials.gold,
group
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.015;
const hit = new THREE.Mesh(
new THREE.SphereGeometry(0.72, 10, 8),
invisibleMaterial
);
hit.userData.control = "endpoint";
hit.userData.index = i;
scene.add(hit);
endpointGroups.push(group);
endpointHitTargets.push(hit);
}
const tickMeshes = [];
for (let i = 0; i < 30; i++) {
const tick = addMesh(
new THREE.CylinderGeometry(0.027, 0.027, 1, 6),
ropeMaterial
);
tick.visible = false;
tickMeshes.push(tick);
}
const yAxis = new THREE.Vector3(0, 1, 0);
function alignCylinderBetween(mesh, start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.scale.set(1, length, 1);
}
function updateMeasurement() {
const a = endpoints[0];
const b = endpoints[1];
endpointGroups[0].position.copy(a);
endpointGroups[1].position.copy(b);
endpointHitTargets[0].position.copy(a);
endpointHitTargets[1].position.copy(b);
alignCylinderBetween(rope, a, b);
alignCylinderBetween(ropeHit, a, b);
const dx = b.x - a.x;
const dz = b.z - a.z;
const distance = Math.hypot(dx, dz);
const direction = new THREE.Vector3(dx, 0, dz).normalize();
const perpendicular = new THREE.Vector3(
-direction.z,
0,
direction.x
);
let visibleTick = 0;
for (let distanceAlong = 0;
distanceAlong <= distance + 0.001;
distanceAlong += 2
) {
const tick = tickMeshes[visibleTick++];
if (!tick) break;
tick.visible = true;
tick.position.copy(a).addScaledVector(direction, distanceAlong);
tick.position.y = MEASURE_Y + 0.01;
tick.quaternion.setFromUnitVectors(yAxis, perpendicular);
const major = Math.round(distanceAlong / 2) % 5 === 0;
tick.scale.set(1, major ? 0.78 : 0.42, 1);
}
for (let i = visibleTick; i < tickMeshes.length; i++) {
tickMeshes[i].visible = false;
}
document.getElementById("distance-value").textContent =
distance.toFixed(2);
document.getElementById("distance-delta").textContent =
`Δx ${Math.abs(dx).toFixed(2)} m · ` +
`Δz ${Math.abs(dz).toFixed(2)} m`;
document.getElementById("measure-label").textContent =
`${distance.toFixed(2)} m`;
}
updateMeasurement();
// ------------------------------------------------------------
// HTML labels projected from world positions
// ------------------------------------------------------------
const poiDefinitions = [
{
element: document.getElementById("pond-label"),
position: new THREE.Vector3(pondX, 0.65, pondZ)
},
{
element: document.getElementById("gate-label"),
position: new THREE.Vector3(0, 4.15, 16.2)
},
{
element: document.getElementById("kiosk-label"),
position: new THREE.Vector3(12, 4.45, -7)
}
];
let showLabels = true;
function positionProjectedLabel(element, worldPosition, visible = true) {
const projected = worldPosition.clone().project(camera);
const inView =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.opacity = visible && inView ? "1" : "0";
if (!inView) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
poiDefinitions.forEach((definition) => {
positionProjectedLabel(
definition.element,
definition.position,
showLabels
);
});
const midpoint = new THREE.Vector3()
.addVectors(endpoints[0], endpoints[1])
.multiplyScalar(0.5);
midpoint.y += 0.72;
positionProjectedLabel(
document.getElementById("measure-label"),
midpoint,
true
);
}
// ------------------------------------------------------------
// Custom camera and measuring-cord controls
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 1, 0),
-MEASURE_Y
);
const controlTargets = [
...endpointHitTargets,
ropeHit
];
let dragging = null;
let previousPointer = { x: 0, y: 0 };
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pickControl() {
const intersections = raycaster.intersectObjects(
controlTargets,
false
);
return intersections.length ? intersections[0] : null;
}
function clampEndpoint(endpoint) {
endpoint.x = THREE.MathUtils.clamp(
endpoint.x,
-PARK_WIDTH / 2 + 1,
PARK_WIDTH / 2 - 1
);
endpoint.z = THREE.MathUtils.clamp(
endpoint.z,
-PARK_DEPTH / 2 + 1,
PARK_DEPTH / 2 - 1
);
endpoint.y = MEASURE_Y;
}
function orbitCamera(deltaX, deltaY) {
const offset = camera.position.clone().sub(cameraTarget);
const spherical = new THREE.Spherical().setFromVector3(offset);
spherical.theta -= deltaX * 0.006;
spherical.phi -= deltaY * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.18,
Math.PI / 2 - 0.08
);
offset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
function panCamera(deltaX, deltaY) {
camera.updateMatrixWorld();
const scale =
2 *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) *
camera.position.distanceTo(cameraTarget) /
window.innerHeight;
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3()
.subVectors(cameraTarget, camera.position);
forward.y = 0;
forward.normalize();
cameraTarget
.addScaledVector(right, -deltaX * scale)
.addScaledVector(forward, deltaY * scale);
cameraTarget.x = THREE.MathUtils.clamp(
cameraTarget.x,
-18,
18
);
cameraTarget.z = THREE.MathUtils.clamp(
cameraTarget.z,
-14,
14
);
camera.lookAt(cameraTarget);
}
function zoomBy(factor) {
const offset = camera.position.clone().sub(cameraTarget);
const distance = THREE.MathUtils.clamp(
offset.length() * factor,
25,
125
);
offset.setLength(distance);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
renderer.domElement.setPointerCapture(event.pointerId);
updatePointer(event);
previousPointer = {
x: event.clientX,
y: event.clientY
};
const hit = pickControl();
if (
hit &&
hit.object.userData.control === "endpoint"
) {
const index = hit.object.userData.index;
dragging = {
type: "endpoint",
index
};
endpointGroups[index].scale.setScalar(1.18);
renderer.domElement.style.cursor = "grabbing";
return;
}
if (
hit &&
hit.object.userData.control === "cord"
) {
const grabPoint = new THREE.Vector3();
if (raycaster.ray.intersectPlane(dragPlane, grabPoint)) {
dragging = {
type: "cord",
grabPoint: grabPoint.clone(),
startA: endpoints[0].clone(),
startB: endpoints[1].clone()
};
renderer.domElement.style.cursor = "grabbing";
}
return;
}
dragging = {
type:
event.button === 2 || event.shiftKey
? "pan"
: "orbit"
};
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) {
updatePointer(event);
const hit = pickControl();
if (!hit) {
renderer.domElement.style.cursor = "grab";
} else if (
hit.object.userData.control === "endpoint"
) {
renderer.domElement.style.cursor = "pointer";
} else {
renderer.domElement.style.cursor = "grab";
}
return;
}
const deltaX = event.clientX - previousPointer.x;
const deltaY = event.clientY - previousPointer.y;
previousPointer = {
x: event.clientX,
y: event.clientY
};
if (dragging.type === "orbit") {
orbitCamera(deltaX, deltaY);
} else if (dragging.type === "pan") {
panCamera(deltaX, deltaY);
} else if (dragging.type === "endpoint") {
updatePointer(event);
const point = new THREE.Vector3();
if (raycaster.ray.intersectPlane(dragPlane, point)) {
endpoints[dragging.index].copy(point);
clampEndpoint(endpoints[dragging.index]);
updateMeasurement();
}
} else if (dragging.type === "cord") {
updatePointer(event);
const point = new THREE.Vector3();
if (raycaster.ray.intersectPlane(dragPlane, point)) {
let moveX = point.x - dragging.grabPoint.x;
let moveZ = point.z - dragging.grabPoint.z;
const minX =
-PARK_WIDTH / 2 + 1 -
Math.min(dragging.startA.x, dragging.startB.x);
const maxX =
PARK_WIDTH / 2 - 1 -
Math.max(dragging.startA.x, dragging.startB.x);
const minZ =
-PARK_DEPTH / 2 + 1 -
Math.min(dragging.startA.z, dragging.startB.z);
const maxZ =
PARK_DEPTH / 2 - 1 -
Math.max(dragging.startA.z, dragging.startB.z);
moveX = THREE.MathUtils.clamp(moveX, minX, maxX);
moveZ = THREE.MathUtils.clamp(moveZ, minZ, maxZ);
endpoints[0].copy(dragging.startA);
endpoints[1].copy(dragging.startB);
endpoints[0].x += moveX;
endpoints[0].z += moveZ;
endpoints[1].x += moveX;
endpoints[1].z += moveZ;
updateMeasurement();
}
}
});
function endDrag(event) {
if (
dragging &&
dragging.type === "endpoint"
) {
endpointGroups[dragging.index].scale.setScalar(1);
}
dragging = null;
renderer.domElement.style.cursor = "grab";
if (
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const normalizedDelta =
event.deltaMode === 1
? event.deltaY * 16
: event.deltaY;
zoomBy(
Math.exp(
THREE.MathUtils.clamp(normalizedDelta, -120, 120) *
0.001
)
);
},
{ passive: false }
);
// ------------------------------------------------------------
// Interface buttons and keyboard shortcuts
// ------------------------------------------------------------
document.getElementById("zoom-in").addEventListener(
"click",
() => zoomBy(0.82)
);
document.getElementById("zoom-out").addEventListener(
"click",
() => zoomBy(1.18)
);
document.getElementById("reset-view").addEventListener(
"click",
resetCamera
);
document.getElementById("reset-cord").addEventListener(
"click",
() => {
endpoints[0].copy(initialA);
endpoints[1].copy(initialB);
updateMeasurement();
}
);
document.getElementById("show-labels").addEventListener(
"change",
(event) => {
showLabels = event.target.checked;
}
);
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
const key = event.key.toLowerCase();
if (key === "r") {
resetCamera();
} else if (key === "m") {
endpoints[0].copy(initialA);
endpoints[1].copy(initialB);
updateMeasurement();
} else if (key === "+" || key === "=") {
zoomBy(0.82);
} else if (key === "-") {
zoomBy(1.18);
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
renderer.setSize(
window.innerWidth,
window.innerHeight
);
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
renderer.setAnimationLoop(() => {
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```