Prompt specification
Build or customize the Three.js 3D scene "Residential court with shared amenities" 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: Residential court with shared amenities
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/residential-court-with-shared-amenities-x2231
Scene Description Prompt:
Residential court with shared amenities. Build a small residential courtyard with entrances, trees, play space, and service access. Keep shared paths connected and show how ground-floor openings relate to the common space. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (residential-court-with-shared-amenities-x2231):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Residential Courtyard Commons</title>
<style>
:root {
--ink: #18313a;
--muted: #597078;
--panel: rgba(250, 249, 244, 0.92);
--line: rgba(24, 49, 58, 0.15);
--accent: #d86f42;
--teal: #267a78;
--shadow: 0 12px 36px rgba(28, 45, 49, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8eb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.panel {
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(380px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 16px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#legend {
position: absolute;
left: 22px;
bottom: 22px;
width: 245px;
padding: 14px 16px;
border-radius: 14px;
pointer-events: auto;
}
.legend-title {
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 8px;
color: #52666d;
font-size: 12px;
}
.swatch {
width: 11px;
height: 11px;
flex: 0 0 11px;
border-radius: 3px;
border: 1px solid rgba(0, 0, 0, 0.08);
}
.swatch.path {
background: #d9c8aa;
}
.swatch.entry {
background: #e8a14a;
}
.swatch.play {
background: #d97955;
}
.swatch.service {
background: #69757b;
}
.swatch.green {
background: #7d9b63;
}
#view-controls {
position: absolute;
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(440px, calc(100vw - 44px));
pointer-events: auto;
}
.view-button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
padding: 10px 14px;
background: rgba(250, 249, 244, 0.91);
color: var(--ink);
box-shadow: 0 7px 20px rgba(28, 45, 49, 0.11);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 700;
transition: transform 150ms ease, background 150ms ease;
}
.view-button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
.view-button.active {
color: white;
background: var(--ink);
}
#info-panel {
position: absolute;
right: 22px;
bottom: 22px;
width: min(340px, calc(100vw - 44px));
padding: 18px;
border-radius: 16px;
pointer-events: auto;
transform: translateY(18px);
opacity: 0;
visibility: hidden;
transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
}
#info-panel.open {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
#info-category {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#info-title {
margin: 7px 30px 8px 0;
font-size: 20px;
line-height: 1.15;
letter-spacing: -0.025em;
}
#info-text {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
#close-info {
position: absolute;
top: 12px;
right: 12px;
width: 29px;
height: 29px;
border: 0;
border-radius: 50%;
background: #e7ece9;
color: var(--ink);
cursor: pointer;
font-size: 19px;
line-height: 1;
}
#help {
position: absolute;
right: 22px;
top: 78px;
padding: 8px 12px;
border-radius: 999px;
background: rgba(250, 249, 244, 0.8);
color: #63747a;
font-size: 11px;
box-shadow: 0 5px 16px rgba(28, 45, 49, 0.08);
}
@media (max-width: 700px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
#view-controls {
top: 112px;
left: 12px;
right: 12px;
justify-content: flex-start;
}
.view-button {
padding: 8px 11px;
font-size: 11px;
}
#help {
display: none;
}
#legend {
left: 12px;
bottom: 12px;
width: 205px;
padding: 11px 13px;
}
#info-panel {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="hud">
<section id="title-card" class="panel">
<p class="eyebrow">Shared ground plan</p>
<h1>Courtyard Commons</h1>
<p class="subtitle">
A compact residential court organized around a continuous accessible path,
direct apartment thresholds, a shared play garden, and a separate service edge.
</p>
</section>
<nav id="view-controls" aria-label="Camera views">
<button class="view-button active" data-view="overview">Overview</button>
<button class="view-button" data-view="entrance">Entrances</button>
<button class="view-button" data-view="play">Play court</button>
<button class="view-button" data-view="service">Service access</button>
</nav>
<div id="help">Drag to orbit · Scroll to zoom · Click to inspect</div>
<section id="legend" class="panel">
<div class="legend-title">Site key</div>
<div class="legend-row"><span class="swatch path"></span>Continuous shared paths</div>
<div class="legend-row"><span class="swatch entry"></span>Recessed ground-floor entries</div>
<div class="legend-row"><span class="swatch play"></span>Shared play surface</div>
<div class="legend-row"><span class="swatch service"></span>Service lane and gate</div>
<div class="legend-row"><span class="swatch green"></span>Common gardens</div>
</section>
<aside id="info-panel" class="panel" aria-live="polite">
<button id="close-info" aria-label="Close information">×</button>
<div id="info-category"></div>
<h2 id="info-title"></h2>
<p id="info-text"></p>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8eb);
scene.fog = new THREE.Fog(0xdce8eb, 95, 185);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
240
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xeaf5ff, 0x69725a, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d6, 3.1);
sun.position.set(-38, 62, 34);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -68;
sun.shadow.camera.right = 68;
sun.shadow.camera.top = 62;
sun.shadow.camera.bottom = -62;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd9ea, 0.65);
fill.position.set(45, 25, -40);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and primitive helpers
// -------------------------------------------------------------------------
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
const material = {
base: standard(0xc9c2af),
grass: standard(0x829a69),
grassDark: standard(0x71875e),
path: standard(0xd9c8aa),
pathEdge: standard(0xb9aa91),
road: standard(0x697479),
roadDark: standard(0x596468),
curb: standard(0xc3c4bc),
line: standard(0xe6d984),
white: standard(0xf1eee4),
dark: standard(0x304047),
window: standard(0x486773, { roughness: 0.34, metalness: 0.12 }),
glass: standard(0x86a8ac, { roughness: 0.2, metalness: 0.15 }),
warm: standard(0xffd28f, {
emissive: 0xffb75f,
emissiveIntensity: 0.9,
roughness: 0.45
}),
wood: standard(0x9b714d),
woodLight: standard(0xc59a69),
metal: standard(0x445158, { roughness: 0.48, metalness: 0.3 }),
trunk: standard(0x75533d),
leaf1: standard(0x66885a),
leaf2: standard(0x76985f),
leaf3: standard(0x587b55),
play: standard(0xd97955),
playDark: standard(0xa95642),
teal: standard(0x367d78),
orange: standard(0xe8a14a),
planter: standard(0x9e8265),
soil: standard(0x655447),
bin: standard(0x4d6862),
binLid: standard(0x38524d)
};
function box(parent, w, h, d, matOrColor, x = 0, y = 0, z = 0, options = {}) {
const mat =
matOrColor && matOrColor.isMaterial
? matOrColor
: standard(matOrColor, options.material || {});
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
radialSegments,
matOrColor,
x = 0,
y = 0,
z = 0,
options = {}
) {
const mat =
matOrColor && matOrColor.isMaterial
? matOrColor
: standard(matOrColor, options.material || {});
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, radialSegments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, matOrColor, radialSegments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = cylinder(
parent,
radius,
radius,
direction.length(),
radialSegments,
matOrColor
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeTextTexture(title, subtitle = "", background = "#18313a") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 4, 504, 184, 24);
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,.23)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#ffffff";
ctx.font = "800 48px system-ui, sans-serif";
ctx.fillText(title, 256, subtitle ? 75 : 96);
if (subtitle) {
ctx.fillStyle = "rgba(255,255,255,.74)";
ctx.font = "500 28px system-ui, sans-serif";
ctx.fillText(subtitle, 256, 132);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeSpriteLabel(title, subtitle = "", color = "#18313a") {
const texture = makeTextTexture(title, subtitle, color);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(11.5, 4.3, 1);
return sprite;
}
function makeUnitSign(text) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#18313a";
ctx.fillRect(0, 0, 256, 128);
ctx.fillStyle = "#ffffff";
ctx.font = "800 65px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(1.35, 0.68),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
return sign;
}
// -------------------------------------------------------------------------
// Interactive elements
// -------------------------------------------------------------------------
const interactiveMeshes = [];
function registerInteractive(object, info) {
object.userData.info = info;
object.traverse((child) => {
if (child.isMesh) interactiveMeshes.push(child);
});
}
let selectionHelper = null;
function clearSelection() {
if (selectionHelper) {
scene.remove(selectionHelper);
selectionHelper.geometry.dispose();
selectionHelper.material.dispose();
selectionHelper = null;
}
}
function selectObject(object) {
clearSelection();
let current = object;
let info = null;
while (current) {
if (current.userData && current.userData.info) {
info = current.userData.info;
break;
}
current = current.parent;
}
if (!info) return;
selectionHelper = new THREE.BoxHelper(object, 0xf07c42);
selectionHelper.material.depthTest = false;
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = 0.95;
selectionHelper.renderOrder = 100;
scene.add(selectionHelper);
document.getElementById("info-category").textContent = info.category;
document.getElementById("info-title").textContent = info.title;
document.getElementById("info-text").textContent = info.text;
document.getElementById("info-panel").classList.add("open");
}
// -------------------------------------------------------------------------
// Site ground, paths, and service edge
// -------------------------------------------------------------------------
const site = new THREE.Group();
scene.add(site);
box(site, 96, 0.7, 86, material.base, 0, -0.42, 0, { castShadow: false });
box(site, 59, 0.16, 46, material.grass, 0, -0.015, 0, { castShadow: false });
// Soft planting beds and raised common gardens.
const gardenBeds = [
[-18, 14, 9, 5],
[15, 14, 10, 5],
[-18, -13, 8, 4],
[16, -13, 8, 4]
];
gardenBeds.forEach(([x, z, w, d]) => {
box(site, w, 0.26, d, material.grassDark, x, 0.08, z, { castShadow: false });
box(site, w + 0.4, 0.22, 0.25, material.planter, x, 0.18, z - d / 2);
box(site, w + 0.4, 0.22, 0.25, material.planter, x, 0.18, z + d / 2);
box(site, 0.25, 0.22, d, material.planter, x - w / 2, 0.18, z);
box(site, 0.25, 0.22, d, material.planter, x + w / 2, 0.18, z);
});
const pathGroup = new THREE.Group();
scene.add(pathGroup);
function pathSegment(w, d, x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
pathGroup.add(group);
box(group, w + 0.34, 0.09, d + 0.34, material.pathEdge, 0, 0.07, 0, {
castShadow: false
});
box(group, w, 0.1, d, material.path, 0, 0.11, 0, {
castShadow: false
});
return group;
}
// Continuous perimeter loop.
pathSegment(52, 3.6, 0, -18.5);
pathSegment(52, 3.6, 0, 20.5);
pathSegment(3.6, 39, -25.5, 1);
pathSegment(3.6, 39, 25.5, 1);
// Connected internal routes.
pathSegment(3.2, 39, 4, 1);
pathSegment(51, 3.2, 0, 8.5);
registerInteractive(pathGroup, {
category: "Circulation",
title: "Continuous shared-path loop",
text:
"A 3.2–3.6 m clear shared route circles the court and connects to every residential entry. " +
"Internal cross-paths keep the play garden, gardens, and seating within short, step-free walking distances."
});
// Service lane outside the east residential wing.
box(site, 7.4, 0.12, 78, material.road, 44, 0.015, 3, {
castShadow: false
});
box(site, 0.45, 0.2, 78, material.curb, 39.95, 0.12, 3);
box(site, 0.45, 0.2, 78, material.curb, 48.05, 0.12, 3);
for (let z = -32; z <= 39; z += 7) {
box(site, 0.16, 0.025, 3.2, material.line, 44, 0.09, z, {
castShadow: false
});
}
// Service gate.
const serviceGate = new THREE.Group();
serviceGate.position.set(44, 0, 38.5);
scene.add(serviceGate);
box(serviceGate, 0.48, 2.5, 0.48, material.metal, -3.25, 1.25, 0);
box(serviceGate, 0.48, 2.5, 0.48, material.metal, 3.25, 1.25, 0);
box(serviceGate, 6.5, 0.34, 0.34, material.white, 0, 1.25, 0);
for (let x = -2.6; x <= 2.6; x += 1.3) {
box(serviceGate, 0.58, 0.36, 0.38, material.orange, x, 1.25, 0.02);
}
const serviceSign = makeUnitSign("S");
serviceSign.scale.set(0.8, 0.4, 1);
serviceSign.position.set(3.25, 2.15, 0.27);
serviceGate.add(serviceSign);
registerInteractive(serviceGate, {
category: "Operations",
title: "Separate service gate",
text:
"The controlled service edge opens from the southeast and connects to the outer east lane. " +
"It remains physically separate from the resident-facing courtyard loop."
});
// Waste and maintenance area.
const serviceYard = new THREE.Group();
serviceYard.position.set(40.8, 0, 25.2);
scene.add(serviceYard);
box(serviceYard, 7.5, 0.1, 7.3, material.roadDark, 0, 0.12, 0, {
castShadow: false
});
function makeBin(x, z, color) {
const bin = new THREE.Group();
bin.position.set(x, 0, z);
serviceYard.add(bin);
box(bin, 2.1, 1.65, 1.45, color, 0, 0.95, 0);
box(bin, 2.22, 0.18, 1.55, material.binLid, 0, 1.82, 0);
box(bin, 0.12, 1.45, 0.08, material.dark, -0.55, 0.94, 0.75);
box(bin, 0.12, 1.45, 0.08, material.dark, 0.55, 0.94, 0.75);
cylinder(bin, 0.18, 0.18, 0.16, 8, material.dark, -0.75, 0.18, 0.35);
cylinder(bin, 0.18, 0.18, 0.16, 8, material.dark, 0.75, 0.18, 0.35);
registerInteractive(bin, {
category: "Operations",
title: "Shared waste enclosure",
text:
"Waste containers are grouped beside the service gate so collection vehicles do not cross " +
"the pedestrian courtyard or residential entrance paths."
});
}
makeBin(-1.3, -1.25, material.bin);
makeBin(1.3, -1.25, standard(0x68746c));
// -------------------------------------------------------------------------
// Residential wings and entrances
// -------------------------------------------------------------------------
function addWindow(parent, x, y, z, width = 1.8, height = 1.7) {
box(parent, width + 0.28, height + 0.28, 0.15, material.white, x, y, z + 0.08);
box(parent, width, height, 0.1, material.window, x, y, z + 0.19);
box(parent, 0.07, height, 0.07, material.white, x, y, z + 0.26);
}
function addBalcony(parent, x, y, z) {
box(parent, 2.8, 0.16, 1.25, material.white, x, y - 0.95, z + 0.57);
box(parent, 2.8, 0.09, 0.09, material.metal, x, y - 0.38, z + 1.12);
box(parent, 0.09, 1.2, 0.09, material.metal, x - 1.35, y - 0.38, z + 1.12);
box(parent, 0.09, 1.2, 0.09, material.metal, x + 1.35, y - 0.38, z + 1.12);
}
function addEntrance(buildingGroup, offset, depth, id, wingName, rotation) {
const entrance = new THREE.Group();
entrance.position.set(offset, 0, depth / 2 + 0.03);
buildingGroup.add(entrance);
// Recessed warm lobby surface.
box(entrance, 2.45, 2.75, 0.08, material.warm, 0, 1.48, 0.07);
// Portal jambs and lintel.
box(entrance, 0.28, 3.15, 0.34, material.dark, -1.32, 1.58, 0.16);
box(entrance, 0.28, 3.15, 0.34, material.dark, 1.32, 1.58, 0.16);
box(entrance, 2.95, 0.3, 0.36, material.dark, 0, 3.08, 0.16);
// Glazed double doors.
box(entrance, 1.02, 2.45, 0.1, material.glass, -0.58, 1.4, 0.29);
box(entrance, 1.02, 2.45, 0.1, material.glass, 0.58, 1.4, 0.29);
box(entrance, 0.08, 2.5, 0.14, material.metal, 0, 1.4, 0.34);
box(entrance, 0.38, 0.08, 0.1, material.metal, -0.28, 1.35, 0.39);
box(entrance, 0.38, 0.08, 0.1, material.metal, 0.28, 1.35, 0.39);
// Threshold projects directly into the shared path.
box(entrance, 3.1, 0.13, 1.45, material.pathEdge, 0, 0.09, 0.5);
// Canopy establishes a protected common threshold.
box(entrance, 3.45, 0.17, 1.55, material.teal, 0, 3.3, 0.67);
box(entrance, 0.09, 0.72, 0.09, material.metal, -1.4, 2.93, 1.3);
box(entrance, 0.09, 0.72, 0.09, material.metal, 1.4, 2.93, 1.3);
const sign = makeUnitSign(id);
sign.position.set(0, 3.72, 0.36);
entrance.add(sign);
box(entrance, 0.22, 0.22, 0.15, material.warm, -1.15, 2.95, 0.43);
box(entrance, 0.22, 0.22, 0.15, material.warm, 1.15, 2.95, 0.43);
const start = new THREE.Vector3(offset, 0, depth / 2 + 0.03)
.applyAxisAngle(new THREE.Vector3(0, 1, 0), rotation)
.add(buildingGroup.position);
const inward = new THREE.Vector3(0, 0, 1)
.applyAxisAngle(new THREE.Vector3(0, 1, 0), rotation);
let pathLength = 4;
if (Math.abs(rotation) < 0.01) pathLength = 5;
else if (Math.abs(Math.abs(rotation) - Math.PI) < 0.01) pathLength = 4;
const pathCenter = start.clone().addScaledVector(inward, pathLength / 2);
const spur = pathSegment(2.8, pathLength, pathCenter.x, pathCenter.z, rotation);
registerInteractive(entrance, {
category: "Residential entrance",
title: `${wingName} · Entry ${id}`,
text:
`The recessed glazed lobby opens directly onto a ${pathLength.toFixed(1)} m spur that meets the continuous shared-path loop. ` +
"The projecting canopy, threshold paving, and illuminated opening make the transition from private dwelling to common ground legible."
});
registerInteractive(spur, {
category: "Circulation",
title: `${wingName} entrance connection`,
text:
"This direct approach keeps every apartment threshold connected to the common route without passing through parking or a service lane."
});
}
function createBuilding({
name,
subtitle,
width,
depth,
height,
position,
rotation,
doorOffsets,
ids,
bodyColor,
trimColor
}) {
const group = new THREE.Group();
group.position.set(...position);
group.rotation.y = rotation;
scene.add(group);
box(group, width, height, depth, bodyColor, 0, height / 2, 0);
// Roof cap and shallow parapet.
box(group, width + 0.45, 0.34, depth + 0.45, trimColor, 0, height + 0.14, 0);
box(group, width + 0.25, 0.65, 0.22, trimColor, 0, height + 0.5, depth / 2);
box(group, width + 0.25, 0.65, 0.22, trimColor, 0, height + 0.5, -depth / 2);
box(group, 0.22, 0.65, depth + 0.25, trimColor, width / 2, height + 0.5, 0);
box(group, 0.22, 0.65, depth + 0.25, trimColor, -width / 2, height + 0.5, 0);
// Floor bands.
for (let y = 3.4; y < height - 0.5; y += 3.4) {
box(group, width + 0.1, 0.16, depth + 0.1, trimColor, 0, y, 0);
}
const frontZ = depth / 2 + 0.01;
// Upper-floor residential openings.
for (let y = 5.25; y < height - 1; y += 3.4) {
let column = 0;
for (let x = -width / 2 + 3.4; x < width / 2 - 2; x += 5.4) {
addWindow(group, x, y, frontZ);
if (column % 3 === 1 && y < height - 2) {
addBalcony(group, x, y, frontZ);
}
column++;
}
}
// Ground-floor openings, excluding door positions.
for (let x = -width / 2 + 3.3; x < width / 2 - 2; x += 5.4) {
const nearDoor = doorOffsets.some((offset) => Math.abs(offset - x) < 2.65);
if (!nearDoor) {
addWindow(group, x, 1.7, frontZ, 2.15, 1.95);
}
}
// Entrances and matching path spurs.
doorOffsets.forEach((offset, index) => {
addEntrance(group, offset, depth, ids[index], name, rotation);
});
const label = makeSpriteLabel(name.toUpperCase(), subtitle, "#24424a");
label.position.set(0, height + 3, 0);
group.add(label);
return group;
}
const northWing = createBuilding({
name: "North Wing",
subtitle: "Entries A1–A4",
width: 54,
depth: 11,
height: 14.6,
position: [-3, 0, -29],
rotation: 0,
doorOffsets: [-19, -7, 7, 19],
ids: ["A1", "A2", "A3", "A4"],
bodyColor: standard(0xc6b9a4),
trimColor: standard(0xe0d8c8)
});
const westWing = createBuilding({
name: "West Wing",
subtitle: "Entries B1–B3",
width: 42,
depth: 11,
height: 14.6,
position: [-35, 0, 1],
rotation: Math.PI / 2,
doorOffsets: [-14, 0, 14],
ids: ["B1", "B2", "B3"],
bodyColor: standard(0xb9c0b6),
trimColor: standard(0xd8ddd3)
});
const eastWing = createBuilding({
name: "East Wing",
subtitle: "Entries C1–C3",
width: 38,
depth: 11,
height: 11.2,
position: [35, 0, -1],
rotation: -Math.PI / 2,
doorOffsets: [-13, 0, 13],
ids: ["C1", "C2", "C3"],
bodyColor: standard(0xc4b3a1),
trimColor: standard(0xe3d6c5)
});
const southWing = createBuilding({
name: "South Wing",
subtitle: "Entries D1–D3",
width: 46,
depth: 11,
height: 11.2,
position: [-7, 0, 30],
rotation: Math.PI,
doorOffsets: [-16, -5, 7],
ids: ["D1", "D2", "D3"],
bodyColor: standard(0xb8bdb5),
trimColor: standard(0xd8ddd2)
});
// A maintenance opening on the outer face of the east wing.
const eastServiceDoor = new THREE.Group();
eastServiceDoor.position.set(9, 0, -5.55);
eastWing.add(eastServiceDoor);
box(eastServiceDoor, 1.35, 2.45, 0.12, material.dark, 0, 1.3, 0);
box(eastServiceDoor, 0.08, 0.3, 0.09, material.metal, 0.4, 1.3, 0.12);
registerInteractive(eastServiceDoor, {
category: "Operations",
title: "East Wing maintenance access",
text:
"The maintenance door faces the service lane and yard, keeping building operations away from the resident-facing entrance sequence."
});
// -------------------------------------------------------------------------
// Shared play court
// -------------------------------------------------------------------------
const playGroup = new THREE.Group();
scene.add(playGroup);
const playSurface = cylinder(
playGroup,
10.2,
10.2,
0.14,
12,
material.play,
-7,
0.14,
-1,
{ castShadow: false }
);
cylinder(
playGroup,
10.55,
10.55,
0.1,
12,
material.playDark,
-7,
0.07,
-1,
{ castShadow: false }
);
registerInteractive(playGroup, {
category: "Shared amenity",
title: "Common play court",
text:
"A low-impact shared play surface sits inside the loop, directly connected to the cross-path. " +
"The open center supports informal play while the perimeter path allows caregivers to circulate around the equipment."
});
// Play tower.
const tower = new THREE.Group();
tower.position.set(-11.5, 0.2, -5.5);
playGroup.add(tower);
cylinderBetween(tower, [-1.05, 0, -1], [-1.05, 2.75, -1], 0.11, material.wood);
cylinderBetween(tower, [1.05, 0, -1], [1.05, 2.75, -1], 0.11, material.wood);
cylinderBetween(tower, [-1.05, 0, 1], [-1.05, 2.75, 1], 0.11, material.wood);
cylinderBetween(tower, [1.05, 0, 1], [1.05, 2.75, 1], 0.11, material.wood);
box(tower, 2.45, 0.18, 2.45, material.woodLight, 0, 2.5, 0);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.8, 0.75, 4),
material.teal
);
roof.position.y = 3.28;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
tower.add(roof);
// Ladder.
cylinderBetween(tower, [-0.55, 0.1, 1.25], [-0.55, 2.6, 1.25], 0.07, material.metal);
cylinderBetween(tower, [0.55, 0.1, 1.25], [0.55, 2.6, 1.25], 0.07, material.metal);
for (let y = 0.45; y < 2.5; y += 0.45) {
cylinderBetween(tower, [-0.55, y, 1.25], [0.55, y, 1.25], 0.055, material.metal);
}
// Slide.
const slide = box(
playGroup,
1.35,
0.16,
5.7,
material.orange,
-11.5,
1.45,
-1.65,
{ rotation: [0.45, 0, 0] }
);
box(playGroup, 0.13, 0.65, 5.6, material.orange, -10.82, 1.66, -1.65, {
rotation: [0.45, 0, 0]
});
// Swing frame.
const swing = new THREE.Group();
swing.position.set(-2.2, 0.22, -5.3);
playGroup.add(swing);
cylinderBetween(swing, [-1.65, 0, -1.1], [-0.85, 2.7, 0], 0.09, material.teal);
cylinderBetween(swing, [1.65, 0, -1.1], [0.85, 2.7, 0], 0.09, material.teal);
cylinderBetween(swing, [-1.65, 0, 1.1], [-0.85, 2.7, 0], 0.09, material.teal);
cylinderBetween(swing, [1.65, 0, 1.1], [0.85, 2.7, 0], 0.09, material.teal);
cylinderBetween(swing, [-1, 2.7, 0], [1, 2.7, 0], 0.09, material.teal);
cylinderBetween(swing, [-0.62, 2.55, 0], [-0.62, 0.65, 0], 0.025, material.metal);
cylinderBetween(swing, [0.62, 2.55, 0], [0.62, 0.65, 0], 0.025, material.metal);
box(swing, 1.55, 0.13, 0.48, material.teal, 0, 0.62, 0);
// Seesaw.
const seesaw = new THREE.Group();
seesaw.position.set(-8.3, 0.25, 5.1);
playGroup.add(seesaw);
box(seesaw, 0.7, 0.35, 0.7, material.teal, 0, 0.25, 0);
box(seesaw, 4.5, 0.18, 0.55, material.orange, 0, 0.65, 0, {
rotation: [0, 0, 0.12]
});
box(seesaw, 0.65, 0.35, 0.65, material.playDark, 2.05, 0.98, 0);
box(seesaw, 0.65, 0.35, 0.65, material.playDark, -2.05, 0.36, 0);
// Spring rider.
const rider = new THREE.Group();
rider.position.set(-2.9, 0.25, 2.3);
playGroup.add(rider);
box(rider, 1.1, 0.7, 0.8, material.metal, 0, 0.4, 0);
cylinder(rider, 0.1, 0.1, 1.2, 8, material.metal, 0, 1.25, 0);
box(rider, 1.15, 0.18, 0.5, material.orange, 0, 1.82, 0);
// -------------------------------------------------------------------------
// Trees, planting, seating, bikes, and lighting
// -------------------------------------------------------------------------
function makeTree(x, z, scale = 1, variation = 0) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
cylinder(tree, 0.24, 0.4, 3.6, 6, material.trunk, 0, 1.8, 0);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(2.05, 0),
variation === 1 ? material.leaf2 : variation === 2 ? material.leaf3 : material.leaf1
);
crown.position.set(0, 4.15, 0);
crown.scale.set(1, 1.1, 0.92);
crown.rotation.set(0.2, variation * 0.7, 0.1);
crown.castShadow = true;
tree.add(crown);
const crown2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.45, 0),
variation === 1 ? material.leaf1 : material.leaf3
);
crown2.position.set(1.05, 3.75, 0.25);
crown2.castShadow = true;
tree.add(crown2);
const crown3 = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.2, 0),
material.leaf2
);
crown3.position.set(-0.9, 3.7, -0.35);
crown3.castShadow = true;
tree.add(crown3);
}
const treePositions = [
[-20.5, -11.5, 1.05, 0],
[-21, 10.5, 1.15, 1],
[-15.5, 15, 0.88, 2],
[15.8, -14.5, 1.02, 1],
[18.5, 14, 1.12, 2],
[13.5, 15, 0.85, 0],
[-29, -25, 1.12, 2],
[30, -26, 1.08, 1],
[29, 22, 0.92, 0],
[38.5, -31, 1.05, 2],
[-38, 31, 1.1, 1],
[49, 10, 1.05, 0]
];
treePositions.forEach((values) => makeTree(...values));
function makeShrub(x, z, scale = 1) {
const shrub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.8, 0),
material.leaf2
);
shrub.position.set(x, 0.72, z);
shrub.scale.set(scale, scale * 0.8, scale);
shrub.rotation.y = x * 0.37;
shrub.castShadow = true;
scene.add(shrub);
}
[
[-20.5, 12.3], [-18, 12.3], [-15.5, 12.3],
[11.5, 12.3], [14.5, 12.3], [17.5, 12.3],
[-20, -13], [-17, -13], [14, -14], [17, -14]
].forEach(([x, z]) => makeShrub(x, z, 0.85));
function makeBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
scene.add(bench);
box(bench, 3.1, 0.16, 0.72, material.woodLight, 0, 0.72, 0);
box(bench, 3.1, 0.68, 0.14, material.woodLight, 0, 1.12, -0.32, {
rotation: [-0.12, 0, 0]
});
box(bench, 0.18, 0.7, 0.58, material.metal, -1.15, 0.36, 0);
box(bench, 0.18, 0.7, 0.58, material.metal, 1.15, 0.36, 0);
registerInteractive(bench, {
category: "Shared amenity",
title: "Common courtyard bench",
text:
"Seating is positioned beside the continuous route, allowing residents to pause while remaining connected to the entrances and play court."
});
}
makeBench(11.7, -16.7, Math.PI / 2);
makeBench(10.4, 12.9, 0);
makeBench(-21.8, 3.2, Math.PI / 2);
makeBench(22.7, 4.4, -Math.PI / 2);
// Bicycle racks.
const bikeRack = new THREE.Group();
bikeRack.position.set(17, 0, 4.6);
scene.add(bikeRack);
for (let x = -1.8; x <= 1.8; x += 1.2) {
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.055, 5, 12, Math.PI),
material.metal
);
hoop.position.set(x, 0.65, 0);
hoop.rotation.y = Math.PI / 2;
hoop.castShadow = true;
bikeRack.add(hoop);
}
registerInteractive(bikeRack, {
category: "Shared amenity",
title: "Resident bicycle parking",
text:
"Cycle parking sits directly on the common path edge, keeping bicycles available without occupying the entrance aprons or play area."
});
// Communal planter tables.
function makePlanterTable(x, z) {
const table = new THREE.Group();
table.position.set(x, 0, z);
scene.add(table);
box(table, 3.2, 0.25, 1.45, material.woodLight, 0, 1.05, 0);
box(table, 3.2, 0.22, 0.18, material.wood, 0, 0.75, -0.6);
box(table, 3.2, 0.22, 0.18, material.wood, 0, 0.75, 0.6);
box(table, 0.22, 1, 1.15, material.metal, -1.15, 0.5, 0);
box(table, 0.22, 1, 1.15, material.metal, 1.15, 0.5, 0);
registerInteractive(table, {
category: "Shared amenity",
title: "Communal garden table",
text:
"Garden tables extend the usable common space into the planted edges of the courtyard and remain close to the main walking route."
});
}
makePlanterTable(-16.7, 14.6);
makePlanterTable(15.1, 14.7);
function makeLamp(x, z) {
const lamp = new THREE.Group();
lamp.position.set(x, 0, z);
scene.add(lamp);
cylinder(lamp, 0.09, 0.12, 4.4, 6, material.metal, 0, 2.2, 0);
box(lamp, 0.7, 0.12, 0.7, material.metal, 0, 4.43, 0);
box(lamp, 0.48, 0.18, 0.48, material.warm, 0, 4.29, 0);
}
[
[-22.3, -16.2], [22.3, -16.2], [-22.3, 18.1], [22.3, 18.1],
[6.8, -15.9], [6.8, 17.7], [19.2, 8.3]
].forEach(([x, z]) => makeLamp(x, z));
// -------------------------------------------------------------------------
// Zone labels and north marker
// -------------------------------------------------------------------------
const playLabel = makeSpriteLabel("PLAY COURT", "Shared amenity", "#984f3e");
playLabel.position.set(-7, 4.6, -8.5);
playLabel.scale.set(9.3, 3.5, 1);
scene.add(playLabel);
const pathLabel = makeSpriteLabel("SHARED LOOP", "Connected resident route", "#4d665d");
pathLabel.position.set(12.2, 2.1, 12.7);
pathLabel.scale.set(8.8, 3.3, 1);
scene.add(pathLabel);
const serviceLabel = makeSpriteLabel("SERVICE EDGE", "Controlled access", "#4e5a5f");
serviceLabel.position.set(44, 4.1, 31.5);
serviceLabel.scale.set(9.4, 3.5, 1);
scene.add(serviceLabel);
// Ground compass.
const compass = new THREE.Group();
compass.position.set(31.2, 0.16, -11.8);
scene.add(compass);
cylinder(compass, 1.25, 1.25, 0.12, 12, material.curb, 0, 0, 0, {
castShadow: false
});
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 1.05);
arrowShape.lineTo(-0.45, -0.55);
arrowShape.lineTo(0, -0.28);
arrowShape.lineTo(0.45, -0.55);
arrowShape.closePath();
const arrow = new THREE.Mesh(
new THREE.ShapeGeometry(arrowShape),
new THREE.MeshBasicMaterial({ color: 0x304047, side: THREE.DoubleSide })
);
arrow.rotation.x = -Math.PI / 2;
arrow.position.y = 0.08;
compass.add(arrow);
const northLabel = makeSpriteLabel("N", "", "#304047");
northLabel.position.set(31.2, 1.1, -13.1);
northLabel.scale.set(2.2, 2.2, 1);
scene.add(northLabel);
// -------------------------------------------------------------------------
// Custom camera controls: no addons or examples are used
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0.6, 0),
radius: 91,
theta: 0.72,
phi: 0.82
};
const presets = {
overview: {
target: new THREE.Vector3(0, 0.6, 0),
radius: 91,
theta: 0.72,
phi: 0.82
},
entrance: {
target: new THREE.Vector3(-3, 4.5, -20),
radius: 39,
theta: 0.13,
phi: 1.08
},
play: {
target: new THREE.Vector3(-7, 1.1, -1),
radius: 31,
theta: 0.55,
phi: 0.98
},
service: {
target: new THREE.Vector3(42, 1.2, 23),
radius: 40,
theta: 0.66,
phi: 1.03
}
};
let cameraTween = null;
function applyOrbit() {
const offset = new THREE.Vector3().setFromSphericalCoords(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.copy(orbit.target).add(offset);
camera.lookAt(orbit.target);
}
function goToPreset(name) {
const target = presets[name];
if (!target) return;
let targetTheta = target.theta;
const difference = Math.atan2(
Math.sin(targetTheta - orbit.theta),
Math.cos(targetTheta - orbit.theta)
);
targetTheta = orbit.theta + difference;
cameraTween = {
startTime: performance.now(),
duration: 950,
from: {
target: orbit.target.clone(),
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
},
to: {
target: target.target.clone(),
radius: target.radius,
theta: targetTheta,
phi: target.phi
}
};
document.querySelectorAll(".view-button").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let dragMoved = false;
let previousPointer = { x: 0, y: 0 };
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
cameraTween = null;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.28, 1.38);
previousPointer = { x: event.clientX, y: event.clientY };
applyOrbit();
return;
}
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);
const hit = raycaster.intersectObjects(interactiveMeshes, false)[0];
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (dragMoved) return;
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);
const hit = raycaster.intersectObjects(interactiveMeshes, false)[0];
if (hit) selectObject(hit.object);
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
18,
135
);
applyOrbit();
},
{ passive: false }
);
document.querySelectorAll(".view-button").forEach((button) => {
button.addEventListener("click", () => goToPreset(button.dataset.view));
});
document.getElementById("close-info").addEventListener("click", () => {
document.getElementById("info-panel").classList.remove("open");
clearSelection();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function animate(now) {
if (cameraTween) {
const raw = Math.min((now - cameraTween.startTime) / cameraTween.duration, 1);
const eased = raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
orbit.target.lerpVectors(cameraTween.from.target, cameraTween.to.target, eased);
orbit.radius = THREE.MathUtils.lerp(
cameraTween.from.radius,
cameraTween.to.radius,
eased
);
orbit.theta = THREE.MathUtils.lerp(
cameraTween.from.theta,
cameraTween.to.theta,
eased
);
orbit.phi = THREE.MathUtils.lerp(
cameraTween.from.phi,
cameraTween.to.phi,
eased
);
applyOrbit();
if (raw >= 1) cameraTween = null;
}
renderer.render(scene, camera);
}
applyOrbit();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```