Prompt specification
Build or customize the Three.js 3D scene "Swahili coast courtyard receiving goods" 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: Swahili coast courtyard receiving goods
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/swahili-coast-courtyard-receiving-goods-x2394
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: Swahili coast courtyard receiving goods. Create a historically referenced domestic courtyard with shaded storage and a small delivery entrance. Animate goods passing from street to store while keeping household circulation clear.
Working Three.js Starter (swahili-coast-courtyard-receiving-goods-x2394):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Swahili Coast Courtyard — Goods Reception</title>
<style>
:root {
--ink: #292820;
--muted: #6f695d;
--paper: rgba(249, 245, 235, 0.9);
--line: rgba(72, 64, 49, 0.18);
--sand: #d8c7a7;
--coral: #a95f43;
--teal: #386d68;
--gold: #b68538;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8cdb8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 16px 45px rgba(60, 47, 29, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.title-panel {
top: 24px;
left: 24px;
width: min(410px, calc(100vw - 48px));
padding: 20px 22px 18px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--coral);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 36px);
font-weight: 500;
line-height: 1.05;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.title-meta {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.chip {
padding: 5px 8px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.35);
color: #625b4f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-panel {
top: 24px;
right: 24px;
width: 294px;
padding: 16px 17px;
}
.status-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(56, 109, 104, 0.12);
animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
50% { box-shadow: 0 0 0 8px rgba(56, 109, 104, 0.03); }
}
#phase {
min-height: 40px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
line-height: 1.2;
}
.progress {
height: 4px;
margin: 14px 0 8px;
overflow: hidden;
background: rgba(62, 56, 45, 0.11);
}
#progress-fill {
width: 0;
height: 100%;
transform-origin: left;
background: linear-gradient(90deg, var(--coral), var(--gold));
}
.progress-caption {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
}
.history-panel {
bottom: 24px;
left: 24px;
width: 330px;
padding: 16px 18px;
}
.history-panel h2 {
margin: 0 0 9px;
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.history-panel p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.history-panel strong {
color: var(--ink);
font-weight: 700;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
margin-top: 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #5e584d;
font-size: 10px;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border: 1px solid rgba(0, 0, 0, 0.12);
}
.swatch.delivery { background: #a98864; }
.swatch.household { background: #dfd2b8; }
.swatch.shade { background: #6f6758; }
.swatch.store { background: #9b6a43; }
.control-panel {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
}
button {
min-height: 35px;
padding: 0 12px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 650;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fffdf7;
transform: translateY(-1px);
}
button.primary {
border-color: var(--teal);
background: var(--teal);
color: white;
}
.hint {
position: fixed;
right: 25px;
bottom: 80px;
z-index: 4;
color: rgba(50, 44, 35, 0.68);
font-size: 10px;
letter-spacing: 0.03em;
text-shadow: 0 1px rgba(255, 255, 255, 0.65);
}
.tag {
position: fixed;
z-index: 3;
left: 0;
top: 0;
padding: 5px 8px;
border: 1px solid rgba(68, 57, 40, 0.2);
background: rgba(250, 246, 235, 0.88);
box-shadow: 0 4px 16px rgba(50, 40, 25, 0.1);
color: #50483b;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
}
.tag::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 13px;
background: rgba(68, 57, 40, 0.4);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #ded2bb;
color: #5d5140;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
transition: opacity 500ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.title-panel .subtitle,
.title-meta,
.history-panel,
.hint,
.tag {
display: none;
}
.status-panel {
top: auto;
right: 12px;
bottom: 70px;
width: 230px;
padding: 12px 13px;
}
#phase { font-size: 16px; min-height: 34px; }
.control-panel {
right: 12px;
bottom: 12px;
}
button {
min-height: 34px;
padding: 0 10px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="app" aria-label="Interactive cutaway of a Swahili coast courtyard"></div>
<section class="panel title-panel">
<div class="eyebrow">Historically informed interpretation · Swahili coast</div>
<h1>The receiving courtyard</h1>
<p class="subtitle">
A cutaway domestic compound inspired by coral-rag courtyard houses recorded
in Zanzibar and Lamu during the late nineteenth and early twentieth centuries.
</p>
<div class="title-meta">
<span class="chip">Coral-rag masonry</span>
<span class="chip">Makuti veranda</span>
<span class="chip">Inward-facing court</span>
</div>
</section>
<section class="panel status-panel">
<div class="status-heading">
<span>Goods reception</span>
<span class="status-dot"></span>
</div>
<div id="phase">01 · Goods on the street</div>
<div class="progress"><div id="progress-fill"></div></div>
<div class="progress-caption">
<span>Street</span>
<span>Shaded store</span>
</div>
</section>
<section class="panel history-panel">
<h2>Reading the model</h2>
<p>
Goods use a narrow edge lane through a small delivery gate. The pale
household route remains open across the central court. Deep shade and
shelving protect stores along the rear veranda.
</p>
<div class="legend">
<div class="legend-item"><span class="swatch delivery"></span>Delivery lane</div>
<div class="legend-item"><span class="swatch household"></span>Household route</div>
<div class="legend-item"><span class="swatch shade"></span>Shaded veranda</div>
<div class="legend-item"><span class="swatch store"></span>Storage goods</div>
</div>
<p style="margin-top:12px">
<strong>Interpretive, not a surveyed reconstruction.</strong>
Architectural features summarize regional building traditions rather than
reproduce one documented property.
</p>
</section>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Double-click to reset</div>
<nav class="panel control-panel" aria-label="Scene controls">
<button id="pause" class="primary" type="button">Pause</button>
<button id="replay" type="button">Replay delivery</button>
<button id="home" type="button">Reset view</button>
</nav>
<div id="loading">Building the courtyard…</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, and architectural camera
// ------------------------------------------------------------
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8cdb8);
scene.fog = new THREE.Fog(0xd8cdb8, 31, 58);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.05, 1.0);
let cameraYaw = 0.64;
let cameraPitch = 0.57;
let cameraZoom = 1;
function updateCamera() {
const distance = 33;
const horizontal = Math.cos(cameraPitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * distance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const height = 15.9;
camera.left = (-height * aspect) / 2;
camera.right = (height * aspect) / 2;
camera.top = height / 2;
camera.bottom = -height / 2;
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// Direct camera controls; no addons are used.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey) {
cameraTarget.x -= dx * 0.012;
cameraTarget.z -= dy * 0.012;
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -6, 6);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -5, 7);
} else {
cameraYaw -= dx * 0.005;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.004, 0.32, 1.08);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.55
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
function resetView() {
cameraYaw = 0.64;
cameraPitch = 0.57;
cameraZoom = 1;
cameraTarget.set(0, 1.05, 1.0);
updateCamera();
}
window.addEventListener("keydown", (event) => {
if (event.code === "ArrowLeft") cameraYaw += 0.08;
if (event.code === "ArrowRight") cameraYaw -= 0.08;
if (event.code === "ArrowUp") cameraPitch = Math.min(1.08, cameraPitch + 0.06);
if (event.code === "ArrowDown") cameraPitch = Math.max(0.32, cameraPitch - 0.06);
if (event.code === "Equal") cameraZoom = Math.min(1.55, cameraZoom + 0.08);
if (event.code === "Minus") cameraZoom = Math.max(0.68, cameraZoom - 0.08);
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
updateCamera();
});
// ------------------------------------------------------------
// Procedural materials: no image assets are required
// ------------------------------------------------------------
let randomSeed = 81273;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function makeTexture(kind, repeatX = 1, repeatY = 1) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 512;
const context = canvas.getContext("2d");
if (kind === "coral") {
context.fillStyle = "#bca98b";
context.fillRect(0, 0, 512, 512);
const rowHeight = 64;
for (let row = 0; row < 8; row++) {
const offset = row % 2 ? -38 : 0;
for (let column = -1; column < 5; column++) {
const x = column * 128 + offset;
const y = row * rowHeight;
const width = 118 + random() * 8;
const height = 54 + random() * 6;
const shade = 178 + Math.floor(random() * 36);
context.fillStyle = `rgb(${shade + 17}, ${shade + 3}, ${shade - 28})`;
context.fillRect(x + 3, y + 3, width, height);
context.strokeStyle = "rgba(255,255,255,0.15)";
context.strokeRect(x + 7, y + 7, width - 8, height - 8);
}
}
}
if (kind === "plaster") {
context.fillStyle = "#e4dac5";
context.fillRect(0, 0, 512, 512);
for (let i = 0; i < 3600; i++) {
const x = random() * 512;
const y = random() * 512;
const radius = 0.4 + random() * 3.2;
const shade = random() > 0.5 ? 255 : 92;
context.fillStyle = `rgba(${shade},${shade},${shade},${0.015 + random() * 0.055})`;
context.beginPath();
context.arc(x, y, radius, 0, Math.PI * 2);
context.fill();
}
context.fillStyle = "rgba(135,106,72,0.08)";
context.fillRect(0, 392, 512, 120);
}
if (kind === "thatch") {
context.fillStyle = "#98703a";
context.fillRect(0, 0, 512, 512);
for (let x = 0; x < 512; x += 7) {
context.strokeStyle = `rgba(${50 + random() * 55},${35 + random() * 35},10,${0.2 + random() * 0.55})`;
context.lineWidth = 1 + random() * 3;
context.beginPath();
context.moveTo(x + random() * 4, 0);
context.lineTo(x + random() * 5 - 2, 512);
context.stroke();
}
for (let i = 0; i < 250; i++) {
context.fillStyle = "rgba(255,220,145,0.12)";
context.fillRect(random() * 512, random() * 512, 1 + random() * 3, 8 + random() * 40);
}
}
if (kind === "paving") {
context.fillStyle = "#b7a98d";
context.fillRect(0, 0, 512, 512);
const cell = 64;
for (let row = 0; row < 8; row++) {
for (let column = -1; column < 9; column++) {
const offset = row % 2 ? -32 : 0;
const x = column * cell + offset;
const y = row * cell;
const shade = 194 + Math.floor(random() * 24);
context.fillStyle = `rgb(${shade + 14},${shade + 5},${shade - 17})`;
context.fillRect(x + 2, y + 2, cell - 5, cell - 5);
}
}
}
if (kind === "earth") {
context.fillStyle = "#9a7958";
context.fillRect(0, 0, 512, 512);
for (let i = 0; i < 4200; i++) {
const shade = 80 + Math.floor(random() * 100);
context.fillStyle = `rgba(${shade},${shade - 15},${shade - 38},${0.12 + random() * 0.35})`;
context.fillRect(random() * 512, random() * 512, 1 + random() * 3, 1 + random() * 3);
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeatX, repeatY);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const coralTexture = makeTexture("coral", 2.5, 1.4);
const plasterTexture = makeTexture("plaster", 1.4, 1.4);
const thatchTexture = makeTexture("thatch", 3.5, 1.2);
const pavingTexture = makeTexture("paving", 4, 4);
const earthTexture = makeTexture("earth", 2, 5);
const materials = {
coral: new THREE.MeshStandardMaterial({
map: coralTexture,
bumpMap: coralTexture,
bumpScale: 0.045,
roughness: 0.96
}),
plaster: new THREE.MeshStandardMaterial({
map: plasterTexture,
bumpMap: plasterTexture,
bumpScale: 0.025,
roughness: 0.9
}),
thatch: new THREE.MeshStandardMaterial({
map: thatchTexture,
roughness: 1
}),
paving: new THREE.MeshStandardMaterial({
map: pavingTexture,
roughness: 0.97
}),
street: new THREE.MeshStandardMaterial({
map: earthTexture,
color: 0xc8b18c,
roughness: 1
}),
lane: new THREE.MeshStandardMaterial({
map: earthTexture,
color: 0x927253,
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: 0x65442b,
roughness: 0.84
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x38291e,
roughness: 0.92
}),
paleStone: new THREE.MeshStandardMaterial({
color: 0xd9c9aa,
roughness: 0.98
}),
ochre: new THREE.MeshStandardMaterial({
color: 0xa87546,
roughness: 0.92
}),
basket: new THREE.MeshStandardMaterial({
color: 0x9a6b39,
roughness: 0.96
}),
sack: new THREE.MeshStandardMaterial({
color: 0xb69c6d,
roughness: 1
}),
pottery: new THREE.MeshStandardMaterial({
color: 0x9a593c,
roughness: 0.76
}),
dark: new THREE.MeshStandardMaterial({
color: 0x302920,
roughness: 1
}),
teal: new THREE.MeshStandardMaterial({
color: 0x315d62,
roughness: 0.84
}),
skin: new THREE.MeshStandardMaterial({
color: 0x74492f,
roughness: 0.88
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x4e6546,
roughness: 0.94
})
};
function addMesh(geometry, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, material, x, y, z, parent = scene) {
return addMesh(new THREE.BoxGeometry(w, h, d), material, x, y, z, parent);
}
function cylinder(rt, rb, h, material, x, y, z, parent = scene, segments = 16) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material, x, y, z, parent
);
}
function sphere(radius, material, x, y, z, parent = scene, segments = 18) {
return addMesh(
new THREE.SphereGeometry(radius, segments, 12),
material, x, y, z, parent
);
}
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff3dc, 0x675b4b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc7, 3.25);
sun.position.set(-11, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d2d1, 0.72);
fill.position.set(13, 9, -8);
scene.add(fill);
// ------------------------------------------------------------
// Site, paving, and circulation
// ------------------------------------------------------------
box(22.5, 0.62, 23.4, materials.earth, 0, -0.42, 1.5);
box(18.5, 0.16, 15.0, materials.paving, 0, -0.03, -0.72);
box(21.3, 0.12, 6.25, materials.street, 0, -0.03, 9.72);
// Dark compacted edge lane, separate from the open household route.
box(1.42, 0.045, 14.25, materials.lane, -5.65, 0.07, 2.28);
// Subtle wheel ruts in the delivery lane.
for (const x of [-5.93, -5.37]) {
box(0.035, 0.018, 12.6, materials.ochre, x, 0.101, 2.5);
}
// Pale stepping-stone household route from the pedestrian gate to the veranda.
for (let i = 0; i < 9; i++) {
const z = 5.45 - i * 1.03;
const x = 1.78 + Math.sin(i * 0.8) * 0.18;
const stone = cylinder(0.56, 0.61, 0.075, materials.paleStone, x, 0.085, z, scene, 6);
stone.scale.x = 1.22 + random() * 0.18;
stone.rotation.y = random() * 0.6;
}
// ------------------------------------------------------------
// Rear range, veranda, and shaded store
// ------------------------------------------------------------
box(18.5, 4.45, 0.42, materials.coral, 0, 2.20, -8.28);
box(0.42, 4.45, 2.35, materials.coral, -9.12, 2.20, -7.08);
box(0.42, 4.45, 2.35, materials.coral, 9.12, 2.20, -7.08);
// Flat roof over the enclosed rear rooms.
box(18.8, 0.28, 2.12, materials.plaster, 0, 4.48, -7.24);
// Deep makuti-thatch veranda canopy.
const canopy = box(18.5, 0.22, 1.85, materials.thatch, 0, 3.92, -4.55);
canopy.rotation.x = -0.055;
for (let x = -8.5; x <= 8.5; x += 1.7) {
const rafter = box(0.12, 0.14, 2.0, materials.wood, x, 3.73, -4.48);
rafter.rotation.x = -0.055;
}
box(18.5, 0.20, 0.26, materials.darkWood, 0, 3.60, -4.05);
function verandaPost(x, z) {
cylinder(0.19, 0.25, 0.35, materials.plaster, x, 0.23, z);
cylinder(0.13, 0.16, 3.0, materials.wood, x, 1.88, z);
box(0.39, 0.16, 0.39, materials.darkWood, x, 3.47, z);
}
for (const x of [-8.55, -4.28, 0, 4.28, 8.55]) {
verandaPost(x, -4.02);
}
// Plastered beam ends and a narrow decorative frieze.
box(18.25, 0.18, 0.38, materials.plaster, 0, 3.78, -4.03);
for (let x = -8; x <= 8; x += 0.55) {
box(0.13, 0.13, 0.08, materials.ochre, x, 3.75, -3.81);
}
// Storage shelving in the left rear bay.
for (const x of [-7.3, -4.85]) {
box(0.10, 3.0, 0.10, materials.darkWood, x, 1.65, -7.82);
}
for (const y of [0.62, 1.35, 2.08, 2.78]) {
box(2.65, 0.10, 0.58, materials.wood, -6.08, y, -7.65);
}
// A receiving mat beneath the route's final position.
const receivingMat = cylinder(0.82, 0.86, 0.055, materials.basket, -5.52, 0.105, -5.52, scene, 24);
receivingMat.scale.z = 1.22;
// ------------------------------------------------------------
// Cutaway residential wing
// ------------------------------------------------------------
box(2.55, 0.12, 9.2, materials.plaster, -7.68, 0.04, 1.05);
box(0.42, 3.25, 9.35, materials.coral, -9.02, 1.63, 1.12);
box(2.72, 3.25, 0.34, materials.coral, -7.65, 1.63, -3.43);
// Only the rear portion of the wing roof remains, revealing the interior.
box(2.94, 0.25, 1.78, materials.plaster, -7.66, 3.33, -2.57);
// Exposed cut face.
box(2.95, 0.25, 0.055, materials.ochre, -7.66, 3.33, -1.67);
// Column at the courtyard edge.
cylinder(0.16, 0.21, 3.0, materials.wood, -6.38, 1.58, 1.70);
box(0.34, 0.14, 0.34, materials.darkWood, -6.38, 3.16, 1.70);
// Bench and chest in the exposed room.
box(1.35, 0.14, 0.58, materials.wood, -8.0, 0.58, 2.60);
box(0.12, 0.55, 0.48, materials.wood, -8.52, 0.27, 2.60);
box(0.12, 0.55, 0.48, materials.wood, -7.48, 0.27, 2.60);
box(0.92, 0.58, 0.68, materials.darkWood, -7.58, 0.39, -0.35);
box(0.98, 0.09, 0.73, materials.wood, -7.58, 0.72, -0.35);
// ------------------------------------------------------------
// Street wall, delivery gate, and pedestrian entrance
// ------------------------------------------------------------
// Front boundary wall with two deliberate openings.
box(2.25, 1.15, 0.38, materials.coral, -7.875, 0.57, 6.18);
box(5.58, 1.15, 0.38, materials.coral, -2.16, 0.57, 6.18);
box(5.95, 1.15, 0.38, materials.coral, 6.075, 0.57, 6.18);
// Small arched delivery entrance.
box(0.28, 1.72, 0.44, materials.coral, -6.48, 0.86, 6.18);
box(0.28, 1.72, 0.44, materials.coral, -4.82, 0.86, 6.18);
const deliveryArch = addMesh(
new THREE.TorusGeometry(0.83, 0.14, 9, 32, Math.PI),
materials.coral,
-5.65,
1.72,
6.18
);
const timberArch = addMesh(
new THREE.TorusGeometry(0.67, 0.045, 8, 30, Math.PI),
materials.darkWood,
-5.65,
1.72,
6.32
);
// A narrow gate leaf rests open against the wall.
const deliveryDoor = new THREE.Group();
deliveryDoor.position.set(-6.33, 0, 6.15);
deliveryDoor.rotation.y = -1.18;
scene.add(deliveryDoor);
box(1.42, 1.48, 0.11, materials.wood, 0.71, 0.86, 0, deliveryDoor);
for (let x = 0.17; x < 1.4; x += 0.22) {
box(0.035, 1.36, 0.025, materials.darkWood, x, 0.86, 0.07, deliveryDoor);
}
// Larger pedestrian opening for household circulation.
box(0.30, 2.15, 0.42, materials.plaster, 0.48, 1.075, 6.18);
box(0.30, 2.15, 0.42, materials.plaster, 3.12, 1.075, 6.18);
box(2.95, 0.22, 0.42, materials.plaster, 1.80, 2.17, 6.18);
const pedestrianDoor = new THREE.Group();
pedestrianDoor.position.set(0.62, 0, 6.18);
pedestrianDoor.rotation.y = -1.30;
scene.add(pedestrianDoor);
box(1.08, 1.86, 0.13, materials.darkWood, 0.54, 0.99, 0, pedestrianDoor);
// Low right boundary, cut away to expose the court.
box(0.36, 1.15, 10.0, materials.coral, 9.0, 0.56, 1.05);
// ------------------------------------------------------------
// Domestic objects and storage goods
// ------------------------------------------------------------
function makeJar(x, z, scale = 1, material = materials.pottery) {
const profile = [
new THREE.Vector2(0.00, 0.00),
new THREE.Vector2(0.24, 0.00),
new THREE.Vector2(0.34, 0.12),
new THREE.Vector2(0.46, 0.50),
new THREE.Vector2(0.38, 0.78),
new THREE.Vector2(0.22, 0.91),
new THREE.Vector2(0.24, 1.00)
];
const jar = addMesh(
new THREE.LatheGeometry(profile, 20),
material,
x,
0.12,
z
);
jar.scale.setScalar(scale);
return jar;
}
function makeBasket(x, y, z, scale = 1, parent = scene) {
const basket = new THREE.Group();
basket.position.set(x, y, z);
basket.scale.setScalar(scale);
parent.add(basket);
cylinder(0.34, 0.27, 0.50, materials.basket, 0, 0.25, 0, basket, 14);
addMesh(new THREE.TorusGeometry(0.34, 0.035, 7, 20), materials.ochre, 0, 0.50, 0, basket);
return basket;
}
function makeSack(x, y, z, scale = 1, parent = scene) {
const sack = new THREE.Group();
sack.position.set(x, y, z);
sack.scale.setScalar(scale);
parent.add(sack);
const body = sphere(0.35, materials.sack, 0, 0.34, 0, sack);
body.scale.set(0.9, 1.20, 0.85);
cylinder(0.07, 0.11, 0.14, materials.sack, 0, 0.70, 0, sack, 9);
return sack;
}
function makeDoor(x, z, width = 1.45, height = 2.55, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.14, z);
group.rotation.y = rotation;
scene.add(group);
box(width + 0.18, height + 0.12, 0.16, materials.coral, 0, height / 2, 0, group);
box(width, height, 0.13, materials.darkWood, 0, height / 2, 0.09, group);
for (let px = -width * 0.36; px <= width * 0.36; px += 0.21) {
box(0.045, height - 0.18, 0.035, materials.wood, px, height / 2, 0.17, group);
}
for (const y of [0.38, height - 0.38]) {
box(width - 0.10, 0.08, 0.04, materials.ochre, 0, y, 0.19, group);
}
sphere(0.045, materials.ochre, width * 0.27, height * 0.52, 0.22, group, 10);
return group;
}
// Carved door facing the open room.
makeDoor(-7.45, -3.20, 1.38, 2.48, 0);
// A rear-room door and small niches.
makeDoor(-6.65, -8.03, 1.35, 2.48, 0);
makeDoor(1.25, -8.03, 1.35, 2.48, 0);
for (const x of [-2.7, 4.3, 7.0]) {
box(0.72, 1.08, 0.12, materials.darkWood, x, 2.1, -8.02);
box(0.53, 0.89, 0.10, materials.ochre, x, 2.1, -7.94);
}
// Stored jars, sacks, and baskets.
makeJar(-7.0, -7.35, 0.68);
makeJar(-4.98, -7.38, 0.58, materials.ochre);
makeSack(-6.55, 0.72, -7.28, 0.72);
makeSack(-5.95, 0.72, -7.28, 0.66);
makeBasket(-7.0, 1.42, -7.28, 0.72);
makeBasket(-5.2, 2.15, -7.28, 0.67);
makeSack(-6.7, 2.15, -7.25, 0.65);
// Household items placed well outside the main route.
makeJar(7.35, 0.9, 1.08);
makeJar(7.9, -0.6, 0.70, materials.ochre);
box(1.55, 0.16, 0.52, materials.wood, 6.75, 0.67, -2.18);
box(0.13, 0.64, 0.43, materials.darkWood, 6.08, 0.31, -2.18);
box(0.13, 0.64, 0.43, materials.darkWood, 7.42, 0.31, -2.18);
function makePlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.1, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.30, 0.24, 0.46, materials.pottery, 0, 0.23, 0, group, 14);
for (let i = 0; i < 7; i++) {
const leaf = sphere(0.27, materials.leaf, 0, 0.72, 0, group, 12);
leaf.scale.set(0.38, 1.55, 0.24);
leaf.position.x = Math.sin(i * 1.9) * 0.15;
leaf.position.z = Math.cos(i * 1.9) * 0.15;
leaf.rotation.z = Math.sin(i) * 0.48;
leaf.rotation.x = Math.cos(i * 1.4) * 0.42;
}
}
makePlant(7.65, 3.85, 0.92);
makePlant(8.15, -1.80, 0.72);
// Street-side bundles waiting near, but not in, the household gate.
makeSack(-7.45, 0.10, 9.55, 0.92);
makeSack(-6.95, 0.10, 9.78, 0.78);
makeBasket(-7.40, 0.10, 8.52, 0.9);
// ------------------------------------------------------------
// Animated handcart and porter
// ------------------------------------------------------------
const cart = new THREE.Group();
scene.add(cart);
// Platform and handles.
box(0.92, 0.13, 1.42, materials.wood, 0, 0.72, 0.02, cart);
box(0.98, 0.10, 0.13, materials.darkWood, 0, 0.62, 0.72, cart);
for (const x of [-0.36, 0.36]) {
const handle = box(0.09, 0.10, 1.76, materials.darkWood, x, 0.79, -1.0, cart);
handle.rotation.x = -0.08;
}
// Two wheels on x-axis pivots.
const wheelPivots = [];
for (const x of [-0.54, 0.54]) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.43, -0.08);
cart.add(pivot);
const wheel = cylinder(0.34, 0.34, 0.11, materials.darkWood, 0, 0, 0, pivot, 20);
wheel.rotation.z = Math.PI / 2;
const hub = cylinder(0.105, 0.105, 0.13, materials.ochre, 0, 0, 0, pivot, 14);
hub.rotation.z = Math.PI / 2;
for (let i = 0; i < 6; i++) {
const spoke = box(0.055, 0.055, 0.58, materials.wood, 0, 0, 0, pivot);
spoke.rotation.x = i * Math.PI / 3;
}
wheelPivots.push(pivot);
}
// Axle.
const axle = cylinder(0.055, 0.055, 1.18, materials.darkWood, 0, 0.43, -0.08, cart, 12);
axle.rotation.z = Math.PI / 2;
// Cargo parent; this group slides toward the store at the end.
const cargoGroup = new THREE.Group();
cart.add(cargoGroup);
makeSack(-0.19, 0.79, -0.22, 0.78, cargoGroup);
makeSack(0.20, 0.79, -0.25, 0.76, cargoGroup);
makeSack(-0.13, 0.79, 0.28, 0.70, cargoGroup);
makeBasket(0.23, 0.78, 0.28, 0.66, cargoGroup);
// Porter walking behind the cart.
const porter = new THREE.Group();
porter.position.set(0, 0.02, -1.78);
cart.add(porter);
cylinder(0.23, 0.28, 0.64, materials.teal, 0, 1.18, 0, porter, 12);
cylinder(0.25, 0.20, 0.17, materials.ochre, 0, 0.84, 0, porter, 12);
sphere(0.20, materials.skin, 0, 1.69, 0, porter, 16);
const headWrap = cylinder(0.205, 0.215, 0.13, materials.paleStone, 0, 1.81, 0, porter, 14);
headWrap.scale.z = 0.85;
// Arms reach toward the cart handles.
for (const x of [-0.23, 0.23]) {
const arm = cylinder(0.065, 0.075, 0.62, materials.skin, x, 1.21, 0.27, porter, 10);
arm.rotation.x = -0.88;
}
const legPivots = [];
for (const x of [-0.13, 0.13]) {
const legPivot = new THREE.Group();
legPivot.position.set(x, 0.82, 0);
porter.add(legPivot);
cylinder(0.075, 0.085, 0.68, materials.darkWood, 0, -0.32, 0, legPivot, 10);
box(0.16, 0.10, 0.25, materials.darkWood, 0, -0.65, 0.055, legPivot);
legPivots.push(legPivot);
}
// Delivery route: street -> small gate -> edge lane -> shaded store.
const deliveryCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-5.65, 0, 10.85),
new THREE.Vector3(-5.65, 0, 7.55),
new THREE.Vector3(-5.65, 0, 4.15),
new THREE.Vector3(-5.65, 0, -1.25),
new THREE.Vector3(-5.52, 0, -2.55),
new THREE.Vector3(-5.48, 0, -3.75),
new THREE.Vector3(-5.48, 0, -5.32)
], false, "centripetal");
const CYCLE = 14;
let deliveryTime = 0;
let paused = false;
let traveledDistance = 0;
let previousCartPosition = new THREE.Vector3();
function updateDelivery() {
const travelProgress = THREE.MathUtils.clamp(deliveryTime / 0.82, 0, 1);
const position = deliveryCurve.getPointAt(travelProgress);
const tangent = deliveryCurve.getTangentAt(travelProgress);
position.y = 0.105;
cart.position.copy(position);
cart.rotation.y = Math.atan2(tangent.x, tangent.z);
if (previousCartPosition.lengthSq() > 0) {
traveledDistance += position.distanceTo(previousCartPosition);
}
previousCartPosition.copy(position);
const wheelRotation = -traveledDistance / 0.34;
for (const wheel of wheelPivots) {
wheel.rotation.x = wheelRotation;
}
const walkingAmount = 1 - THREE.MathUtils.smoothstep(deliveryTime, 0.79, 0.84);
const stride = Math.sin(traveledDistance * 5.2) * 0.42 * walkingAmount;
legPivots[0].rotation.x = stride;
legPivots[1].rotation.x = -stride;
porter.position.y = 0.02 + Math.abs(Math.sin(traveledDistance * 5.2)) * 0.025 * walkingAmount;
const unload = THREE.MathUtils.smoothstep(deliveryTime, 0.82, 0.94);
cargoGroup.position.z = unload * 1.05;
cargoGroup.position.y = -unload * 0.08;
let phase;
if (deliveryTime < 0.11) {
phase = "01 · Goods on the street";
} else if (position.z > 5.25) {
phase = "02 · Through the delivery gate";
} else if (deliveryTime < 0.80) {
phase = "03 · Along the screened edge lane";
} else {
phase = "04 · Unloading in the shade";
}
document.getElementById("phase").textContent = phase;
document.getElementById("progress-fill").style.width =
`${Math.min(deliveryTime / 0.94, 1) * 100}%`;
}
const pauseButton = document.getElementById("pause");
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
}
pauseButton.addEventListener("click", togglePause);
document.getElementById("replay").addEventListener("click", () => {
deliveryTime = 0;
traveledDistance = 0;
previousCartPosition.set(0, 0, 0);
cargoGroup.position.set(0, 0, 0);
paused = false;
pauseButton.textContent = "Pause";
});
document.getElementById("home").addEventListener("click", resetView);
// ------------------------------------------------------------
// World-anchored explanatory labels
// ------------------------------------------------------------
const labelData = [
{
element: document.createElement("div"),
text: "Street unloading",
position: new THREE.Vector3(-5.65, 1.35, 10.55)
},
{
element: document.createElement("div"),
text: "Small delivery gate",
position: new THREE.Vector3(-5.65, 2.85, 6.15)
},
{
element: document.createElement("div"),
text: "Shaded store",
position: new THREE.Vector3(-5.65, 3.32, -5.55)
},
{
element: document.createElement("div"),
text: "Household route · kept clear",
position: new THREE.Vector3(1.8, 0.52, 2.1)
}
];
for (const label of labelData) {
label.element.className = "tag";
label.element.textContent = label.text;
document.body.appendChild(label.element);
}
function updateLabels() {
for (const label of labelData) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
deliveryTime = (deliveryTime + delta) % CYCLE;
}
updateDelivery();
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
updateDelivery();
updateCamera();
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("done");
setTimeout(() => loading.remove(), 550);
});
</script>
</body>
</html>
```