Prompt specification
Build or customize the Three.js 3D scene "Two Uses of One Courtyard Model" 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: Two Uses of One Courtyard Model
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-uses-of-one-courtyard-model-x3213
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Place quiet reading seats and a ball-play area on overlapping courtyard footprints. Use transparent boundaries to expose the spatial conflict without assigning blame to either group.
Working Three.js Starter (two-uses-of-one-courtyard-model-x3213):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shared Courtyard — Spatial Study</title>
<style>
:root {
--ink: #26332f;
--muted: #66716b;
--paper: rgba(249, 247, 239, 0.92);
--quiet: #4f8f87;
--play: #c78b3d;
--shared: #8d70a5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce3dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage,
#stage canvas {
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(38, 51, 47, 0.13);
border-radius: 999px;
background: rgba(250, 248, 241, 0.9);
box-shadow: 0 5px 18px rgba(47, 60, 54, 0.1);
color: var(--ink);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
will-change: left, top;
}
.scene-label::before {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--label-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--label-color) 18%, transparent);
}
#panel {
position: fixed;
z-index: 5;
top: 20px;
left: 20px;
width: min(355px, calc(100vw - 40px));
padding: 18px;
border: 1px solid rgba(38, 51, 47, 0.12);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(45, 58, 52, 0.14);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: #78827d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 30px);
font-weight: 750;
letter-spacing: -0.035em;
line-height: 1.08;
}
#panel p {
margin: 10px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 8px;
margin-bottom: 16px;
padding: 12px;
border: 1px solid rgba(38, 51, 47, 0.09);
border-radius: 12px;
background: rgba(255, 255, 255, 0.36);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #52605a;
font-size: 12px;
}
.swatch {
width: 22px;
height: 12px;
flex: 0 0 auto;
border: 1px solid rgba(38, 51, 47, 0.12);
border-radius: 3px;
}
.swatch.quiet {
background: rgba(79, 143, 135, 0.28);
border-color: rgba(79, 143, 135, 0.65);
}
.swatch.play {
background: rgba(199, 139, 61, 0.25);
border-color: rgba(199, 139, 61, 0.65);
}
.swatch.shared {
background:
repeating-linear-gradient(
135deg,
rgba(141, 112, 165, 0.55) 0 2px,
rgba(141, 112, 165, 0.12) 2px 5px
);
border-color: rgba(141, 112, 165, 0.75);
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
min-height: 34px;
padding: 7px 11px;
border: 1px solid rgba(38, 51, 47, 0.16);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: #46534d;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: #fff;
border-color: rgba(38, 51, 47, 0.3);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--shared);
outline-offset: 2px;
}
button.active {
border-color: #52675f;
background: #52675f;
color: #fff;
}
button[aria-pressed="false"] {
opacity: 0.58;
}
#hint {
position: fixed;
z-index: 5;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid rgba(38, 51, 47, 0.1);
border-radius: 9px;
background: rgba(249, 247, 239, 0.76);
color: #5b6761;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.035em;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 680px) {
#panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
#panel p {
display: none;
}
.legend {
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin-bottom: 10px;
padding: 8px;
}
.legend-row {
gap: 5px;
font-size: 9px;
line-height: 1.2;
}
.swatch {
width: 14px;
height: 10px;
}
#hint {
right: 10px;
bottom: 10px;
max-width: calc(100vw - 20px);
text-align: right;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels" aria-hidden="true"></div>
<section id="panel" aria-label="Scene information and controls">
<div class="eyebrow">Spatial study 01</div>
<h1>Shared courtyard</h1>
<p>
Reading seats and ball play occupy overlapping courtyard footprints.
Translucent envelopes make the shared ground legible without assigning
responsibility to either use.
</p>
<div class="legend" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch quiet"></span>
<span>Quiet reading</span>
</div>
<div class="legend-row">
<span class="swatch play"></span>
<span>Ball play</span>
</div>
<div class="legend-row">
<span class="swatch shared"></span>
<span>Shared edge</span>
</div>
</div>
<div class="controls">
<button id="oblique" class="active" type="button">Oblique</button>
<button id="plan" type="button">Plan</button>
<button id="reset" type="button">Reset</button>
<button id="shared-toggle" type="button" aria-pressed="true">
Shared edge
</button>
</div>
</section>
<div id="hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom · Double-click to reset
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const labelsRoot = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce3dc);
scene.fog = new THREE.Fog(0xdce3dc, 28, 55);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly courtyard showing overlapping reading and ball-play areas"
);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const desired = {
theta: 0.72,
phi: 0.86,
zoom: 1,
target: new THREE.Vector3(0, 0.35, 0)
};
const current = {
theta: desired.theta,
phi: desired.phi,
zoom: desired.zoom,
target: desired.target.clone()
};
const hemisphere = new THREE.HemisphereLight(0xfff7e6, 0x617168, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.2);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcbdce5, 0.7);
fill.position.set(8, 6, -9);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
plinth: material(0x9c8e76),
site: material(0xc4b89f),
quietFloor: material(0xd7c9af),
playFloor: material(0xaab7a1),
wall: material(0xd9d0be),
wallShade: material(0xb9ad98),
wood: material(0x916241),
woodLight: material(0xb98558),
frame: material(0x3e514b),
window: material(0x506965, { roughness: 0.48 }),
soil: material(0x695442),
leaf: material(0x6d8760),
leafLight: material(0x8ca171),
leafDark: material(0x4e6950),
trunk: material(0x74533b),
cream: material(0xf0eadc),
orange: material(0xd87c3f),
cone: material(0xe09b48),
bookBlue: material(0x668f9a),
bookRust: material(0xb4674d)
};
function box(w, h, d, x, y, z, mat, parent = scene, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
topRadius,
bottomRadius,
height,
x,
y,
z,
mat,
parent = scene,
segments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function line(points, mat, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const object = new THREE.Line(geometry, mat);
object.computeLineDistances();
parent.add(object);
return object;
}
function rectanglePoints(rect, y) {
return [
new THREE.Vector3(rect.minX, y, rect.minZ),
new THREE.Vector3(rect.maxX, y, rect.minZ),
new THREE.Vector3(rect.maxX, y, rect.maxZ),
new THREE.Vector3(rect.minX, y, rect.maxZ),
new THREE.Vector3(rect.minX, y, rect.minZ)
];
}
function makeLineMaterial(color, opacity = 0.5, dashed = false) {
if (dashed) {
return new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.2,
gapSize: 0.12,
depthWrite: false
});
}
return new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
}
function floorOverlay(rect, color, opacity, y, parent = scene) {
const width = rect.maxX - rect.minX;
const depth = rect.maxZ - rect.minZ;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(
(rect.minX + rect.maxX) * 0.5,
y,
(rect.minZ + rect.maxZ) * 0.5
);
mesh.renderOrder = 1;
parent.add(mesh);
return mesh;
}
function verticalPanel(a, b, height, color, opacity, parent = scene) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
a.x, 0.17, a.z,
b.x, 0.17, b.z,
b.x, 0.17 + height, b.z,
a.x, 0.17, a.z,
b.x, 0.17 + height, b.z,
a.x, 0.17 + height, a.z
],
3
)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.renderOrder = 2;
parent.add(mesh);
return mesh;
}
const quietRect = {
minX: -6.3,
maxX: 1.1,
minZ: -3.7,
maxZ: 3.7
};
const playRect = {
minX: -0.1,
maxX: 7.3,
minZ: -3.7,
maxZ: 3.7
};
const sharedRect = {
minX: -0.1,
maxX: 1.1,
minZ: -3.7,
maxZ: 3.7
};
// Site and courtyard footprints.
box(
80,
0.2,
80,
0,
-0.82,
0,
material(0xd4ddd5),
scene,
false
);
box(16.4, 0.52, 10.4, 0, -0.3, 0, M.plinth);
box(16, 0.12, 10, 0, 0.02, 0, M.site);
const quietWidth = quietRect.maxX - quietRect.minX;
const quietDepth = quietRect.maxZ - quietRect.minZ;
box(
quietWidth,
0.08,
quietDepth,
(quietRect.minX + quietRect.maxX) * 0.5,
0.13,
0,
M.quietFloor,
scene,
false
);
const playWidth = playRect.maxX - playRect.minX;
const playDepth = playRect.maxZ - playRect.minZ;
box(
playWidth,
0.06,
playDepth,
(playRect.minX + playRect.maxX) * 0.5,
0.12,
0,
M.playFloor,
scene,
false
);
// Quiet courtyard paving joints.
const quietGridPoints = [];
for (let x = quietRect.minX + 0.8; x < quietRect.maxX; x += 0.8) {
quietGridPoints.push(
new THREE.Vector3(x, 0.176, quietRect.minZ),
new THREE.Vector3(x, 0.176, quietRect.maxZ)
);
}
for (let z = quietRect.minZ + 0.8; z < quietRect.maxZ; z += 0.8) {
quietGridPoints.push(
new THREE.Vector3(quietRect.minX, 0.176, z),
new THREE.Vector3(quietRect.maxX, 0.176, z)
);
}
scene.add(
new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(quietGridPoints),
new THREE.LineBasicMaterial({
color: 0x8e816c,
transparent: true,
opacity: 0.22
})
)
);
// Low, transparent use envelopes.
floorOverlay(quietRect, 0x4f8f87, 0.075, 0.181);
floorOverlay(playRect, 0xc78b3d, 0.075, 0.171);
line(
rectanglePoints(quietRect, 0.205),
makeLineMaterial(0x4f8f87, 0.48, true)
);
line(
rectanglePoints(playRect, 0.205),
makeLineMaterial(0xc78b3d, 0.48, true)
);
const quietEdges = [
[
new THREE.Vector3(quietRect.minX, 0.17, quietRect.minZ),
new THREE.Vector3(quietRect.maxX, 0.17, quietRect.minZ)
],
[
new THREE.Vector3(quietRect.maxX, 0.17, quietRect.minZ),
new THREE.Vector3(quietRect.maxX, 0.17, quietRect.maxZ)
],
[
new THREE.Vector3(quietRect.maxX, 0.17, quietRect.maxZ),
new THREE.Vector3(quietRect.minX, 0.17, quietRect.maxZ)
],
[
new THREE.Vector3(quietRect.minX, 0.17, quietRect.maxZ),
new THREE.Vector3(quietRect.minX, 0.17, quietRect.minZ)
]
];
const playEdges = [
[
new THREE.Vector3(playRect.minX, 0.17, playRect.minZ),
new THREE.Vector3(playRect.maxX, 0.17, playRect.minZ)
],
[
new THREE.Vector3(playRect.maxX, 0.17, playRect.minZ),
new THREE.Vector3(playRect.maxX, 0.17, playRect.maxZ)
],
[
new THREE.Vector3(playRect.maxX, 0.17, playRect.maxZ),
new THREE.Vector3(playRect.minX, 0.17, playRect.maxZ)
],
[
new THREE.Vector3(playRect.minX, 0.17, playRect.maxZ),
new THREE.Vector3(playRect.minX, 0.17, playRect.minZ)
]
];
quietEdges.forEach(([a, b]) =>
verticalPanel(a, b, 0.9, 0x4f8f87, 0.022)
);
playEdges.forEach(([a, b]) =>
verticalPanel(a, b, 0.9, 0xc78b3d, 0.022)
);
// Shared-edge group: deliberately neutral and independently toggleable.
const sharedGroup = new THREE.Group();
scene.add(sharedGroup);
floorOverlay(sharedRect, 0x8d70a5, 0.17, 0.193, sharedGroup);
const sharedLeft = new THREE.Vector3(sharedRect.minX, 0.19, sharedRect.minZ);
const sharedLeftEnd = new THREE.Vector3(sharedRect.minX, 0.19, sharedRect.maxZ);
const sharedRight = new THREE.Vector3(sharedRect.maxX, 0.19, sharedRect.minZ);
const sharedRightEnd = new THREE.Vector3(sharedRect.maxX, 0.19, sharedRect.maxZ);
verticalPanel(sharedLeft, sharedLeftEnd, 1.05, 0x8d70a5, 0.12, sharedGroup);
verticalPanel(sharedRight, sharedRightEnd, 1.05, 0x8d70a5, 0.12, sharedGroup);
line(
rectanglePoints(sharedRect, 0.213),
makeLineMaterial(0x8d70a5, 0.85, true),
sharedGroup
);
// Diagonal hatch clipped to the narrow shared strip.
const hatchPositions = [];
const hatchStart = sharedRect.minZ - sharedRect.maxX;
const hatchEnd = sharedRect.maxZ - sharedRect.minX;
for (let c = hatchStart; c <= hatchEnd; c += 0.32) {
const candidates = [];
const leftZ = sharedRect.minX + c;
if (leftZ >= sharedRect.minZ && leftZ <= sharedRect.maxZ) {
candidates.push(new THREE.Vector2(sharedRect.minX, leftZ));
}
const rightZ = sharedRect.maxX + c;
if (rightZ >= sharedRect.minZ && rightZ <= sharedRect.maxZ) {
candidates.push(new THREE.Vector2(sharedRect.maxX, rightZ));
}
const bottomX = sharedRect.minZ - c;
if (bottomX >= sharedRect.minX && bottomX <= sharedRect.maxX) {
candidates.push(new THREE.Vector2(bottomX, sharedRect.minZ));
}
const topX = sharedRect.maxZ - c;
if (topX >= sharedRect.minX && topX <= sharedRect.maxX) {
candidates.push(new THREE.Vector2(topX, sharedRect.maxZ));
}
if (candidates.length < 2) continue;
let farthest = candidates[0];
let maxDistance = -1;
for (const candidate of candidates) {
const distance = candidate.distanceTo(candidates[0]);
if (distance > maxDistance) {
maxDistance = distance;
farthest = candidate;
}
}
const a = candidates[0];
const b = farthest;
hatchPositions.push(
a.x, 0.202, a.y,
b.x, 0.202, b.y
);
}
const hatchGeometry = new THREE.BufferGeometry();
hatchGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(hatchPositions, 3)
);
sharedGroup.add(
new THREE.LineSegments(
hatchGeometry,
new THREE.LineBasicMaterial({
color: 0x75578e,
transparent: true,
opacity: 0.43,
depthWrite: false
})
)
);
// Perimeter architecture.
box(6.9, 1.42, 0.3, -2.75, 0.79, -4.02, M.wall);
box(0.3, 1.12, 5.45, -6.94, 0.64, -1.25, M.wallShade);
box(5.55, 0.82, 0.27, 4.22, 0.49, -4.02, M.wall);
box(1.05, 1.9, 0.9, 6.72, 1.03, -3.65, M.wallShade);
// Recessed windows.
[-5.35, -3.8, -2.25].forEach((x, index) => {
box(
0.84,
0.6,
0.035,
x,
0.93,
-3.852,
index === 1 ? M.bookBlue : M.window,
scene,
false
);
box(0.045, 0.62, 0.055, x, 0.93, -3.825, M.cream, scene, false);
});
// Pergola over the reading edge.
const pergola = new THREE.Group();
scene.add(pergola);
[-5.45, -2.55].forEach((x) => {
box(0.14, 2.55, 0.14, x, 1.43, -3.18, M.wood, pergola);
});
box(3.05, 0.16, 0.18, -4, 2.67, -3.18, M.wood, pergola);
for (let x = -5.4; x <= -2.6; x += 0.42) {
box(0.13, 0.13, 1.65, x, 2.75, -3.12, M.woodLight, pergola);
}
function makeBench(x, z, rotation = 0, withBook = false) {
const group = new THREE.Group();
group.position.set(x, 0.16, z);
group.rotation.y = rotation;
scene.add(group);
[-0.57, 0.57].forEach((legX) => {
[-0.17, 0.17].forEach((legZ) => {
box(0.12, 0.43, 0.12, legX, 0.22, legZ, M.frame, group);
});
});
[-0.17, 0, 0.17].forEach((slatZ) => {
box(1.7, 0.08, 0.13, 0, 0.48, slatZ, M.wood, group);
});
[-0.62, 0.62].forEach((postX) => {
box(0.09, 0.65, 0.09, postX, 0.75, 0.25, M.frame, group);
});
box(1.7, 0.13, 0.08, 0, 0.77, 0.25, M.wood, group);
box(1.7, 0.13, 0.08, 0, 1.01, 0.25, M.woodLight, group);
if (withBook) {
const book = box(
0.32,
0.035,
0.23,
-0.23,
0.54,
-0.04,
M.bookBlue,
group
);
book.rotation.y = -0.12;
box(0.025, 0.04, 0.235, -0.23, 0.56, -0.04, M.cream, group);
}
return group;
}
function makeChair(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.16, z);
group.rotation.y = rotation;
scene.add(group);
[-0.28, 0.28].forEach((legX) => {
[-0.27, 0.27].forEach((legZ) => {
box(0.07, 0.46, 0.07, legX, 0.23, legZ, M.frame, group);
});
});
box(0.76, 0.1, 0.7, 0, 0.48, 0, M.woodLight, group);
box(0.76, 0.65, 0.09, 0, 0.79, 0.3, M.wood, group);
const leftPage = box(0.19, 0.035, 0.24, -0.1, 0.56, -0.02, M.cream, group);
const rightPage = box(0.19, 0.035, 0.24, 0.1, 0.56, -0.02, M.cream, group);
leftPage.rotation.y = -0.12;
rightPage.rotation.y = 0.12;
box(0.025, 0.04, 0.25, 0, 0.575, -0.02, M.bookRust, group);
}
makeBench(-4.85, 1.72, 0, true);
makeBench(-4.82, -1.08, 0, false);
makeBench(-2.68, -2.67, 0, true);
makeBench(-0.42, 2.35, 0, true);
makeChair(-2.35, 1.28, 0.28);
function makePlanter(x, z, width = 1.35, depth = 0.65) {
box(width, 0.35, depth, x, 0.34, z, M.wallShade);
box(width - 0.14, 0.05, depth - 0.14, x, 0.535, z, M.soil);
const shrubCount = Math.max(2, Math.round(width / 0.48));
for (let i = 0; i < shrubCount; i++) {
const shrub = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.3, 0),
i % 2 ? M.leaf : M.leafLight
);
shrub.position.set(
x - width * 0.36 + (i / Math.max(1, shrubCount - 1)) * width * 0.72,
0.68,
z + (i % 2 ? 0.07 : -0.07)
);
shrub.scale.set(1, 0.72, 0.85);
shrub.castShadow = true;
shrub.receiveShadow = true;
scene.add(shrub);
}
}
makePlanter(-5.65, 3.02, 1.7, 0.72);
makePlanter(-3.45, 3.12, 1.25, 0.68);
makePlanter(5.9, -3.12, 1.8, 0.72);
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.16, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.11, 0.17, 1.45, 0, 0.72, 0, M.trunk, group, 6);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.95, 0),
M.leafDark
);
crown.position.set(0, 1.82, 0);
crown.scale.set(1, 0.93, 0.92);
crown.castShadow = true;
group.add(crown);
const crownTop = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.68, 0),
M.leaf
);
crownTop.position.set(0.27, 2.42, 0.12);
crownTop.scale.set(1.08, 0.9, 1);
crownTop.castShadow = true;
group.add(crownTop);
const crownSide = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.62, 0),
M.leafLight
);
crownSide.position.set(-0.48, 2.02, 0.18);
crownSide.castShadow = true;
group.add(crownSide);
}
makeTree(-5.77, -2.65, 0.94);
makeTree(6.83, -2.62, 0.8);
function makeLamp(x, z) {
cylinder(0.055, 0.075, 2.45, x, 1.38, z, M.frame, scene, 6);
box(0.28, 0.3, 0.28, x, 2.66, z, M.cream);
box(0.32, 0.055, 0.32, x, 2.83, z, M.frame);
}
makeLamp(-6.15, 2.25);
makeLamp(7.05, 2.8);
// Ball-play field markings.
const fieldRect = {
minX: 0.38,
maxX: 6.83,
minZ: -2.78,
maxZ: 2.78
};
line(
rectanglePoints(fieldRect, 0.166),
makeLineMaterial(0xf4f1df, 0.74)
);
line(
[
new THREE.Vector3(3.61, 0.167, -2.78),
new THREE.Vector3(3.61, 0.167, 2.78)
],
makeLineMaterial(0xf4f1df, 0.62)
);
const circlePoints = [];
for (let i = 0; i <= 48; i++) {
const angle = (i / 48) * Math.PI * 2;
circlePoints.push(
new THREE.Vector3(
3.61 + Math.cos(angle) * 1.33,
0.168,
Math.sin(angle) * 1.33
)
);
}
line(circlePoints, makeLineMaterial(0xf4f1df, 0.72));
const goalArea = {
minX: 0.38,
maxX: 1.75,
minZ: -1.35,
maxZ: 1.35
};
line(
rectanglePoints(goalArea, 0.167),
makeLineMaterial(0xf4f1df, 0.48)
);
const secondGoalArea = {
minX: 5.46,
maxX: 6.83,
minZ: -1.35,
maxZ: 1.35
};
line(
rectanglePoints(secondGoalArea, 0.167),
makeLineMaterial(0xf4f1df, 0.48)
);
function makeGoal(x) {
const group = new THREE.Group();
scene.add(group);
[-0.72, 0.72].forEach((z) => {
box(0.11, 1.38, 0.11, x, 0.84, z, M.cream, group);
});
box(0.11, 0.11, 1.55, x, 1.5, 0, M.cream, group);
const netPoints = [];
for (let y = 0.22; y <= 1.42; y += 0.24) {
netPoints.push(
new THREE.Vector3(x + 0.02, y, -0.67),
new THREE.Vector3(x + 0.02, y, 0.67)
);
}
for (let z = -0.6; z <= 0.61; z += 0.24) {
netPoints.push(
new THREE.Vector3(x + 0.02, 0.2, z),
new THREE.Vector3(x + 0.02, 1.43, z)
);
}
group.add(
new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(netPoints),
new THREE.LineBasicMaterial({
color: 0x6e7a73,
transparent: true,
opacity: 0.5
})
)
);
}
makeGoal(0.22);
makeGoal(6.95);
function makeBall(x, z, radius = 0.21, color = M.orange) {
const ball = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 1),
color
);
ball.position.set(x, 0.17 + radius, z);
ball.rotation.set(0.3, 0.6, 0.15);
ball.castShadow = true;
ball.receiveShadow = true;
scene.add(ball);
return ball;
}
// One ball rests within the shared footprint, making the spatial relation visible.
makeBall(0.43, 0.55, 0.22);
makeBall(4.4, -1.3, 0.2);
makeBall(5.55, 1.62, 0.18, M.cream);
function makeCone(x, z) {
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.15, 0.42, 4),
M.cone
);
cone.position.set(x, 0.39, z);
cone.rotation.y = Math.PI * 0.25;
cone.castShadow = true;
scene.add(cone);
box(0.31, 0.045, 0.31, x, 0.19, z, M.cone);
}
[
[0.55, -2.55],
[0.55, 2.55],
[6.67, -2.55],
[6.67, 2.55]
].forEach(([x, z]) => makeCone(x, z));
// Neutral threshold pavers emphasize circulation through the overlap.
for (let z = -3.2; z <= 3.2; z += 0.8) {
const paver = box(
0.48,
0.035,
0.55,
0.5,
0.22,
z,
material(0xc7b9a5),
scene,
false
);
paver.rotation.y = z % 1.6 === 0 ? 0.03 : -0.03;
}
// Scene labels.
const labelItems = [];
function makeLabel(text, position, color, group = scene) {
const element = document.createElement("div");
element.className = "scene-label";
element.textContent = text;
element.style.setProperty("--label-color", color);
labelsRoot.appendChild(element);
const item = {
element,
position: position.clone(),
group,
visible: true
};
labelItems.push(item);
return item;
}
makeLabel(
"Quiet reading",
new THREE.Vector3(-3.45, 2.95, -2.5),
"#4f8f87"
);
makeLabel(
"Ball play",
new THREE.Vector3(4.25, 2.65, -2.55),
"#c78b3d"
);
const sharedLabel = makeLabel(
"Shared edge",
new THREE.Vector3(0.5, 1.35, 3.35),
"#8d70a5",
sharedGroup
);
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of labelItems) {
const projected = item.position.clone().project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
const parentVisible =
!item.group || item.group.visible || item.group === sharedGroup;
item.element.style.display =
onScreen && item.visible && parentVisible ? "flex" : "none";
item.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// Direct camera controls: orbit, pan, zoom, and touch pinch.
const pointers = new Map();
let gestureMode = null;
let previousPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
gestureMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
gestureMode = "pinch";
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (gestureMode === "orbit" && pointers.size === 1) {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.035,
1.28
);
} else if (gestureMode === "pan" && pointers.size === 1) {
const scale = (11.5 / current.zoom) * 0.00145;
desired.target.x -= dx * scale * Math.cos(desired.theta);
desired.target.z += dx * scale * Math.sin(desired.theta);
desired.target.x -= dy * scale * Math.sin(desired.theta);
desired.target.z -= dy * scale * Math.cos(desired.theta);
clampTarget();
} else if (gestureMode === "pinch" && pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * (distance / previousPinchDistance),
0.65,
2.35
);
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) gestureMode = null;
else if (pointers.size === 1) gestureMode = "orbit";
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) =>
event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.35
);
},
{ passive: false }
);
function clampTarget() {
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -6, 6);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -5, 5);
}
function resetCamera() {
desired.theta = 0.72;
desired.phi = 0.86;
desired.zoom = 1;
desired.target.set(0, 0.35, 0);
setViewButton("oblique");
}
renderer.domElement.addEventListener("dblclick", resetCamera);
const obliqueButton = document.querySelector("#oblique");
const planButton = document.querySelector("#plan");
const resetButton = document.querySelector("#reset");
const sharedButton = document.querySelector("#shared-toggle");
function setViewButton(active) {
obliqueButton.classList.toggle("active", active === "oblique");
planButton.classList.toggle("active", active === "plan");
obliqueButton.setAttribute(
"aria-pressed",
String(active === "oblique")
);
planButton.setAttribute("aria-pressed", String(active === "plan"));
}
obliqueButton.addEventListener("click", () => {
desired.theta = 0.72;
desired.phi = 0.86;
desired.zoom = 1;
desired.target.set(0, 0.35, 0);
setViewButton("oblique");
});
planButton.addEventListener("click", () => {
desired.theta = 0;
desired.phi = 0.035;
desired.zoom = 1;
desired.target.set(0, 0.1, 0);
setViewButton("plan");
});
resetButton.addEventListener("click", resetCamera);
sharedButton.addEventListener("click", () => {
sharedGroup.visible = !sharedGroup.visible;
sharedButton.setAttribute(
"aria-pressed",
String(sharedGroup.visible)
);
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const verticalSpan = Math.max(11.5, 18.4 / aspect);
camera.left = (-verticalSpan * aspect) / 2;
camera.right = (verticalSpan * aspect) / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
let lastTime = performance.now();
function animate(now) {
const dt = Math.min(0.05, (now - lastTime) / 1000);
lastTime = now;
const smoothing = 1 - Math.exp(-dt * 8);
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.zoom += (desired.zoom - current.zoom) * smoothing;
current.target.lerp(desired.target, smoothing);
const radius = 23;
camera.position.set(
current.target.x + radius * Math.sin(current.phi) * Math.sin(current.theta),
current.target.y + radius * Math.cos(current.phi),
current.target.z + radius * Math.sin(current.phi) * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.zoom = current.zoom;
camera.updateProjectionMatrix();
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```