Prompt specification
Build or customize the Three.js 3D scene "Urban courtyard linking study and exchange" 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: Urban courtyard linking study and exchange
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/urban-courtyard-linking-study-and-exchange-x2399
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Build a compact Timbuktu-inspired courtyard beside a trading lane. Show manuscript handling, household activity, and goods movement without portraying scholarship as isolated from ordinary urban life.
Working Three.js Starter (urban-courtyard-linking-study-and-exchange-x2399):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Courtyard & the Lane</title>
<style>
:root {
--ink: #30251d;
--paper: #f2e2bd;
--paper-soft: rgba(244, 229, 194, 0.92);
--accent: #b85f35;
--line: rgba(61, 43, 29, 0.25);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8bd8a;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#title-card {
position: fixed;
top: 20px;
left: 22px;
z-index: 10;
max-width: 390px;
padding: 16px 18px 15px;
background: var(--paper-soft);
border: 1px solid var(--line);
border-left: 4px solid var(--accent);
box-shadow: 0 8px 30px rgba(55, 37, 22, 0.12);
pointer-events: none;
backdrop-filter: blur(8px);
}
#title-card h1 {
margin: 0 0 5px;
font-size: clamp(20px, 2.1vw, 31px);
line-height: 1;
letter-spacing: 0.055em;
text-transform: uppercase;
}
#title-card p {
margin: 7px 0 0;
font-size: 13px;
line-height: 1.45;
}
#title-card .small {
font-family: Arial, sans-serif;
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
opacity: 0.66;
}
#controls {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 20;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
align-items: center;
gap: 8px;
width: min(510px, calc(100vw - 36px));
padding: 10px;
background: var(--paper-soft);
border: 1px solid var(--line);
box-shadow: 0 8px 30px rgba(55, 37, 22, 0.13);
backdrop-filter: blur(8px);
}
button {
appearance: none;
border: 1px solid rgba(62, 43, 28, 0.3);
background: #ead29c;
color: var(--ink);
padding: 8px 11px;
font: 600 11px Arial, sans-serif;
letter-spacing: 0.04em;
cursor: pointer;
}
button:hover {
background: #fff0c7;
}
button.active {
color: #fff5d9;
background: #805137;
border-color: #805137;
}
.time-control {
display: flex;
align-items: center;
gap: 7px;
font: 11px Arial, sans-serif;
white-space: nowrap;
}
#time {
width: 100px;
accent-color: var(--accent);
}
#story {
position: fixed;
left: 22px;
bottom: 20px;
z-index: 9;
max-width: 390px;
padding: 11px 14px;
background: rgba(244, 229, 194, 0.87);
border: 1px solid var(--line);
font-size: 12px;
line-height: 1.45;
box-shadow: 0 6px 22px rgba(55, 37, 22, 0.1);
pointer-events: none;
}
#story strong {
display: block;
margin-bottom: 3px;
font-size: 10px;
font-family: Arial, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.marker {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
transform: translate(-50%, -50%);
padding: 6px 9px;
color: #35271d;
background: rgba(249, 235, 199, 0.88);
border: 1px solid rgba(73, 50, 32, 0.22);
box-shadow: 0 3px 12px rgba(53, 37, 26, 0.12);
font: 600 10px Arial, sans-serif;
letter-spacing: 0.075em;
text-transform: uppercase;
white-space: nowrap;
transition: opacity 160ms ease;
}
.marker::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
background: #a65232;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(166, 82, 50, 0.14);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d8bd8a;
font: 13px Arial, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#title-card {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
padding: 12px 14px;
}
#title-card p {
display: none;
}
#story {
display: none;
}
#controls {
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
justify-content: center;
}
.marker {
font-size: 8px;
padding: 5px 7px;
}
}
</style>
</head>
<body>
<div id="loading">Building the courtyard…</div>
<div id="title-card">
<div class="small">A procedural voxel scene</div>
<h1>The Courtyard & the Lane</h1>
<p>
Manuscript work, cooking, grinding, fetching water, trade, and travel
occupy the same compact urban space.
</p>
</div>
<div id="labels">
<div class="marker" data-marker="workshop">Manuscript workshop</div>
<div class="marker" data-marker="household">Household courtyard</div>
<div class="marker" data-marker="lane">Trading lane</div>
</div>
<div id="story">
<strong>One connected street life</strong>
A folio passes from the courtyard workshop to a trader while grain is ground,
a meal is prepared, water is carried, and a caravan moves goods along the lane.
</div>
<div id="controls">
<button id="pause" type="button">Pause motion</button>
<button id="labels-toggle" class="active" type="button">Labels</button>
<button data-view="overview" type="button">Overview</button>
<button data-view="courtyard" type="button">Courtyard</button>
<button data-view="lane" type="button">Lane</button>
<label class="time-control">
Hour
<input id="time" type="range" min="7" max="19" step="0.25" value="15.5">
<output id="time-output">15:30</output>
</label>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d8c39a");
scene.fog = new THREE.Fog("#d8c39a", 25, 52);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#f7e7c1", "#765139", 1.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#ffe0a5", 2.1);
sun.position.set(-10, 16, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00035;
scene.add(sun);
scene.add(sun.target);
sun.target.position.set(0, 0, -2);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0
})
);
}
return materialCache.get(color);
}
function cube(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const material =
typeof color === "string" || typeof color === "number"
? getMaterial(color)
: color;
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(x = 0, y = 0, z = 0, parent = scene) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
function makeGlowMaterial(color, intensity = 1.4) {
return new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: intensity,
roughness: 0.65
});
}
// -------------------------------------------------------------------------
// Ground and architecture
// -------------------------------------------------------------------------
cube(31, 0.45, 27, "#ba8a52", 0, -0.28, -1);
cube(29, 0.07, 4.8, "#aa7847", 0, 0.01, 5.35);
cube(2.25, 0.075, 4.1, "#c09258", 0, 0.025, 2.7);
cube(9.3, 0.075, 7.7, "#cf9d60", -1.8, 0.025, -1.8);
// Irregular paving stones at the lane edges.
for (let i = 0; i < 48; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = -14 + (i * 0.61) % 28;
const z = 5.35 + side * (2.18 + Math.random() * 0.15);
cube(
0.28 + Math.random() * 0.26,
0.12,
0.22 + Math.random() * 0.2,
i % 3 === 0 ? "#8f6743" : "#a77b50",
x,
0.08,
z
);
}
function adobeWallX(cx, z, length, height, depth = 0.48, color = "#bd7f43") {
cube(length, height, depth, color, cx, height / 2, z);
cube(length + 0.1, 0.18, depth + 0.12, "#d59b57", cx, height + 0.02, z);
for (let row = 0; row < Math.floor(height / 0.48); row++) {
const count = Math.max(2, Math.floor(length / 1.5));
for (let j = 0; j < count; j++) {
if ((row + j) % 3 !== 0) continue;
const bx = cx - length / 2 + 0.45 + j * (length - 0.9) / Math.max(1, count - 1);
cube(
0.48,
0.12,
0.035,
j % 2 ? "#d09250" : "#a96d3b",
bx,
0.27 + row * 0.48,
z + depth / 2 + 0.018
);
}
}
}
function adobeWallZ(x, cz, length, height, depth = 0.48, color = "#bd7f43") {
cube(depth, height, length, color, x, height / 2, cz);
cube(depth + 0.12, 0.18, length + 0.1, "#d59b57", x, height + 0.02, cz);
}
// Courtyard enclosure, with an open gate onto the lane.
adobeWallZ(-6.85, -1.65, 7.2, 1.85);
adobeWallZ(6.85, -1.65, 7.2, 1.35);
adobeWallX(-3.85, 2.0, 6.0, 1.25);
adobeWallX(3.85, 2.0, 6.0, 1.25);
cube(0.36, 2.0, 0.55, "#805035", -0.77, 1.0, 2.0);
cube(0.36, 2.0, 0.55, "#805035", 0.77, 1.0, 2.0);
// Cutaway manuscript room.
adobeWallX(-2.0, -8.75, 8.8, 3.15, 0.52, "#c28547");
adobeWallZ(-6.4, -6.7, 4.3, 3.15, 0.5, "#bd7d40");
adobeWallZ(2.4, -6.7, 4.3, 2.05, 0.48, "#bd7d40");
// Roof beams and a small surviving roof strip make the room legible as a roofed space.
for (const z of [-7.8, -6.45, -5.05]) {
cube(8.65, 0.17, 0.19, "#68432c", -2.0, 3.22, z);
}
cube(8.85, 0.24, 1.35, "#9a6036", -2.0, 3.43, -8.15);
cube(0.25, 3.3, 0.25, "#70462e", -6.35, 1.65, -5.02);
cube(0.25, 3.3, 0.25, "#70462e", 2.35, 1.65, -5.02);
// Door, niche and shelf inside the workshop.
cube(1.05, 2.05, 0.09, "#65412e", 0.95, 1.03, -8.46);
cube(1.25, 0.16, 0.18, "#74452c", 0.95, 2.1, -8.39);
cube(0.08, 0.07, 0.05, "#c5a35c", 1.28, 1.05, -8.38);
cube(3.2, 0.13, 0.48, "#71462d", -1.65, 1.15, -8.28);
cube(3.2, 0.13, 0.48, "#71462d", -1.65, 1.78, -8.28);
cube(3.2, 0.13, 0.48, "#71462d", -1.65, 2.42, -8.28);
function manuscriptStack(parent, x, y, z, count = 4, width = 0.65) {
for (let i = 0; i < count; i++) {
const cover = i % 3 === 0 ? "#8f5b37" : "#c2a064";
const booklet = group(
x + (i % 2 ? 0.025 : -0.025),
y + i * 0.075,
z + (i % 2 ? -0.02 : 0.02),
parent
);
cube(width, 0.055, 0.43, cover, 0, 0, 0, booklet);
cube(width * 0.88, 0.018, 0.37, "#ead9a9", 0, 0.038, 0, booklet);
cube(0.045, 0.025, 0.44, "#5e3b2a", 0, 0.048, 0, booklet);
}
}
for (let shelf = 0; shelf < 3; shelf++) {
for (let i = 0; i < 7; i++) {
manuscriptStack(
scene,
-2.9 + i * 0.4,
1.22 + shelf * 0.63,
-8.19,
2 + ((i + shelf) % 3),
0.28
);
}
}
// Writing desk.
cube(1.65, 0.16, 1.08, "#74482d", -4.2, 1.0, -5.92);
for (const dx of [-0.62, 0.62]) {
for (const dz of [-0.35, 0.35]) {
cube(0.13, 0.94, 0.13, "#5c3827", -4.2 + dx, 0.47, -5.92 + dz);
}
}
function openFolio(parent, x, y, z, scale = 1) {
const folio = group(x, y, z, parent);
folio.scale.setScalar(scale);
cube(0.36, 0.035, 0.54, "#e8d4a1", -0.185, 0, 0, folio);
cube(0.36, 0.035, 0.54, "#e8d4a1", 0.185, 0, 0, folio);
cube(0.035, 0.045, 0.55, "#765037", 0, 0.006, 0, folio);
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
cube(
0.22,
0.012,
0.018,
i === 0 ? "#9b5738" : "#76543a",
side * 0.185,
0.025,
-0.16 + i * 0.095,
folio
);
}
}
return folio;
}
openFolio(scene, -4.2, 1.105, -5.77, 0.86);
// Oil lamp on the desk.
cube(0.28, 0.06, 0.28, "#69452d", -3.15, 1.11, -6.1);
cube(0.1, 0.23, 0.1, "#69452d", -3.15, 1.24, -6.1);
cube(
0.12,
0.16,
0.12,
makeGlowMaterial("#f0a640", 1.2),
-3.15,
1.45,
-6.1
);
// -------------------------------------------------------------------------
// Background urban facades
// -------------------------------------------------------------------------
function facade(x, z, width, depth, height, color) {
cube(width, height, depth, color, x, height / 2, z);
cube(width + 0.18, 0.22, depth + 0.18, "#d29a58", x, height + 0.06, z);
cube(width - 0.35, 0.42, 0.22, color, x, height + 0.3, z + depth / 2);
const front = z + depth / 2 + 0.025;
const doorWidth = Math.min(0.95, width * 0.24);
cube(doorWidth, 1.8, 0.08, "#5d3c29", x - width * 0.18, 0.9, front);
cube(doorWidth + 0.22, 0.13, 0.16, "#74472e", x - width * 0.18, 1.84, front + 0.03);
const windowCount = width > 5 ? 2 : 1;
for (let i = 0; i < windowCount; i++) {
const wx = x + width * (0.08 + i * 0.25);
cube(0.55, 0.62, 0.08, "#4f392c", wx, height * 0.63, front);
cube(0.68, 0.11, 0.17, "#74472e", wx, height * 0.63 + 0.35, front + 0.02);
cube(0.08, 0.63, 0.13, "#74472e", wx, height * 0.63, front + 0.03);
}
// Flat-roof parapet, vessels and bundled goods.
cube(0.22, 0.55, depth, color, x - width / 2 + 0.1, height + 0.35, z);
cube(0.22, 0.55, depth, color, x + width / 2 - 0.1, height + 0.35, z);
cube(0.75, 0.55, 0.65, "#a45f3b", x - width * 0.24, height + 0.42, z - 0.1);
cube(0.55, 0.35, 0.48, "#c17a43", x + width * 0.2, height + 0.3, z - 0.12);
}
facade(-9.0, -11.25, 4.7, 2.7, 4.25, "#b8783f");
facade(-1.2, -11.35, 6.4, 2.8, 4.8, "#c28545");
facade(6.6, -11.1, 5.2, 2.6, 3.7, "#b6753d");
facade(11.0, -11.0, 4.0, 2.8, 4.55, "#c18245");
// -------------------------------------------------------------------------
// Props
// -------------------------------------------------------------------------
function pot(parent, x, y, z, scale = 1, color = "#a75836") {
const p = group(x, y, z, parent);
p.scale.setScalar(scale);
cube(0.46, 0.44, 0.46, color, 0, 0.22, 0, p);
cube(0.32, 0.18, 0.32, color, 0, 0.51, 0, p);
cube(0.39, 0.08, 0.39, "#74412c", 0, 0.62, 0, p);
cube(0.25, 0.025, 0.25, "#4f3328", 0, 0.665, 0, p);
return p;
}
function basket(parent, x, y, z, scale = 1) {
const b = group(x, y, z, parent);
b.scale.setScalar(scale);
cube(0.62, 0.42, 0.52, "#a9763d", 0, 0.21, 0, b);
cube(0.47, 0.035, 0.38, "#68442b", 0, 0.43, 0, b);
for (const sx of [-0.28, -0.09, 0.1, 0.28]) {
cube(0.035, 0.47, 0.54, "#d09a55", sx, 0.23, 0, b);
}
cube(0.66, 0.06, 0.07, "#d09a55", 0, 0.28, 0.27, b);
cube(0.66, 0.06, 0.07, "#d09a55", 0, 0.28, -0.27, b);
return b;
}
function gourd(parent, x, y, z, scale = 1) {
const g = group(x, y, z, parent);
g.scale.setScalar(scale);
cube(0.4, 0.38, 0.4, "#b47b39", 0, 0.19, 0, g);
cube(0.27, 0.28, 0.27, "#c49345", 0, 0.49, 0, g);
cube(0.09, 0.13, 0.09, "#665037", 0, 0.68, 0, g);
return g;
}
function rolledTextile(parent, x, y, z, color = "#486b72", rotation = 0) {
const roll = cube(0.27, 0.27, 1.1, color, x, y, z, parent);
roll.rotation.y = rotation;
cube(0.29, 0.29, 0.08, "#d4ae68", x, y, z + 0.51, parent);
return roll;
}
// Well and water bucket.
cube(1.2, 0.72, 1.2, "#9c7957", 5.05, 0.36, -6.25);
cube(0.88, 0.035, 0.88, "#3f352d", 5.05, 0.73, -6.25);
cube(0.14, 1.55, 0.14, "#67462e", 4.52, 0.78, -6.25);
cube(0.14, 1.55, 0.14, "#67462e", 5.58, 0.78, -6.25);
cube(1.25, 0.13, 0.13, "#67462e", 5.05, 1.5, -6.25);
cube(0.05, 0.65, 0.05, "#4d3829", 5.05, 1.1, -6.25);
cube(0.42, 0.35, 0.42, "#765035", 5.05, 0.72, -6.25);
// Hearth and cooking area.
cube(1.65, 0.16, 1.45, "#6f4d35", 4.65, 0.1, -3.65);
cube(0.75, 0.18, 0.65, "#4d352a", 4.65, 0.22, -3.65);
cube(0.22, 0.2, 0.22, makeGlowMaterial("#ef6c27", 2.2), 4.65, 0.35, -3.65);
cube(0.16, 0.3, 0.16, makeGlowMaterial("#ffbf4f", 1.8), 4.82, 0.4, -3.55);
pot(scene, 4.65, 0.31, -3.65, 0.82, "#965337");
const hearthLight = new THREE.PointLight("#ff8b36", 1.2, 4.5, 2);
hearthLight.position.set(4.65, 0.75, -3.65);
scene.add(hearthLight);
// Grinding stone.
cube(0.75, 0.68, 0.75, "#8d8068", 5.45, 0.34, -1.05);
cube(0.9, 0.16, 0.85, "#aa9b7d", 5.45, 0.73, -1.05);
cube(0.22, 0.36, 0.2, "#765b43", 5.45, 0.99, -1.05);
basket(scene, 4.35, 0, -0.65, 0.72);
// Laundry line and hanging cloth.
cube(0.11, 2.1, 0.11, "#6f472e", -5.9, 1.05, -0.15);
cube(0.11, 2.1, 0.11, "#6f472e", -2.6, 1.05, -0.15);
cube(3.35, 0.035, 0.035, "#58402d", -4.25, 1.95, -0.15);
cube(0.62, 0.82, 0.035, "#d5c9a8", -5.15, 1.51, -0.15);
cube(0.55, 0.7, 0.035, "#71898a", -4.3, 1.58, -0.15);
cube(0.48, 0.9, 0.035, "#a96347", -3.45, 1.48, -0.15);
// -------------------------------------------------------------------------
// People
// -------------------------------------------------------------------------
function createPerson(options = {}) {
const g = group(options.x || 0, 0, options.z || 0);
g.rotation.y = options.rotation || 0;
g.scale.setScalar(options.scale || 1);
const skin = options.skin || "#75472f";
const tunic = options.tunic || "#a85f3e";
const wrap = options.wrap || "#d7c7a0";
const trousers = options.trousers || "#4d4438";
cube(0.43, 0.62, 0.3, tunic, 0, 1.08, 0, g);
cube(0.35, 0.3, 0.33, skin, 0, 1.57, 0.035, g);
cube(0.39, 0.12, 0.38, wrap, 0, 1.76, 0.02, g);
cube(0.35, 0.12, 0.13, wrap, 0, 1.69, -0.22, g);
cube(0.055, 0.055, 0.035, "#30241e", -0.09, 1.59, 0.205, g);
cube(0.055, 0.055, 0.035, "#30241e", 0.09, 1.59, 0.205, g);
const leftLeg = group(-0.13, 0.76, 0, g);
const rightLeg = group(0.13, 0.76, 0, g);
cube(0.17, 0.66, 0.19, trousers, 0, -0.33, 0, leftLeg);
cube(0.17, 0.66, 0.19, trousers, 0, -0.33, 0, rightLeg);
cube(0.19, 0.1, 0.29, "#493429", 0, -0.68, 0.06, leftLeg);
cube(0.19, 0.1, 0.29, "#493429", 0, -0.68, 0.06, rightLeg);
const leftArm = group(-0.31, 1.34, 0, g);
const rightArm = group(0.31, 1.34, 0, g);
cube(0.15, 0.55, 0.17, tunic, 0, -0.23, 0, leftArm);
cube(0.15, 0.55, 0.17, tunic, 0, -0.23, 0, rightArm);
cube(0.14, 0.17, 0.15, skin, 0, -0.57, 0.02, leftArm);
cube(0.14, 0.17, 0.15, skin, 0, -0.57, 0.02, rightArm);
if (options.belt) {
cube(0.46, 0.08, 0.33, options.belt, 0, 0.81, 0, g);
}
return {
group: g,
leftLeg,
rightLeg,
leftArm,
rightArm
};
}
function createSeatedPerson(options = {}) {
const g = group(options.x || 0, 0, options.z || 0);
g.rotation.y = options.rotation || 0;
const skin = options.skin || "#70442e";
const tunic = options.tunic || "#526b69";
cube(0.45, 0.62, 0.32, tunic, 0, 0.76, 0, g);
cube(0.35, 0.31, 0.34, skin, 0, 1.24, 0.03, g);
cube(0.39, 0.12, 0.38, "#d5c5a0", 0, 1.43, 0.02, g);
cube(0.45, 0.2, 0.58, "#5a4937", 0, 0.23, 0.23, g);
cube(0.45, 0.18, 0.2, "#49382d", 0, 0.16, 0.47, g);
const leftArm = group(-0.3, 1.02, 0.02, g);
const rightArm = group(0.3, 1.02, 0.02, g);
cube(0.14, 0.45, 0.15, tunic, 0, -0.19, 0, leftArm);
cube(0.14, 0.45, 0.15, tunic, 0, -0.19, 0, rightArm);
cube(0.13, 0.15, 0.14, skin, 0, -0.45, 0.05, leftArm);
cube(0.13, 0.15, 0.14, skin, 0, -0.45, 0.05, rightArm);
return { group: g, leftArm, rightArm };
}
const scribe = createSeatedPerson({
x: -4.2,
z: -6.6,
tunic: "#536d69",
skin: "#6f402a"
});
const assistant = createPerson({
x: -1.65,
z: -5.3,
tunic: "#b67a3e",
wrap: "#e2d3aa",
skin: "#885437"
});
const manuscriptTrader = createPerson({
x: -0.65,
z: -5.02,
rotation: Math.PI,
tunic: "#607c78",
wrap: "#c7b993",
skin: "#70442e"
});
const cook = createPerson({
x: 3.65,
z: -3.55,
rotation: Math.PI / 2,
tunic: "#a85d43",
wrap: "#d8c49a",
skin: "#76452e"
});
const grinder = createPerson({
x: 4.65,
z: -1.15,
rotation: -Math.PI / 2,
tunic: "#c08a47",
wrap: "#e0d1aa",
skin: "#8c5737"
});
const child = createPerson({
x: -5.35,
z: -1.2,
rotation: 0.7,
tunic: "#a15a45",
wrap: "#d4c39d",
skin: "#855238",
scale: 0.66
});
const leftSeller = createPerson({
x: -4.5,
z: 2.12,
rotation: 0,
tunic: "#526f70",
wrap: "#d8c49a",
skin: "#71452e"
});
const rightSeller = createPerson({
x: 4.5,
z: 2.12,
rotation: 0,
tunic: "#ad6a3d",
wrap: "#e3d2a9",
skin: "#8a5235"
});
// Quill and hand above the open manuscript.
const quillPivot = group(-3.95, 1.38, -5.72);
cube(0.035, 0.54, 0.035, "#e9dfbd", 0, 0.2, 0, quillPivot);
quillPivot.rotation.z = -0.45;
// A folio exchange bridges the workshop and the courtyard.
const exchangedFolio = openFolio(scene, -1.15, 1.27, -5.08, 1.05);
exchangedFolio.rotation.y = -0.08;
// The cook's hand and the grinder's hand are animated later.
const cookHand = cook.rightArm;
const grindingHand = grinder.rightArm;
// -------------------------------------------------------------------------
// Market stalls
// -------------------------------------------------------------------------
function marketStall(x, z, kind) {
const g = group(x, 0, z);
cube(3.8, 0.055, 1.8, "#b8864e", 0, 0.04, 0, g);
for (const px of [-1.7, 1.7]) {
cube(0.12, 2.25, 0.12, "#69452e", px, 1.12, -0.62, g);
cube(0.12, 1.45, 0.12, "#69452e", px, 0.72, 0.65, g);
}
const clothA = kind === "manuscript" ? "#496d70" : "#a85c3c";
const clothB = kind === "manuscript" ? "#c6a05f" : "#d4b26d";
for (let i = 0; i < 5; i++) {
cube(
0.78,
0.08,
1.25,
i % 2 ? clothA : clothB,
-1.56 + i * 0.78,
2.2,
-0.42,
g
);
}
cube(2.9, 0.13, 0.9, "#765035", 0, 0.67, 0.12, g);
for (const dx of [-1.2, 1.2]) {
cube(0.12, 0.62, 0.12, "#5d402c", dx, 0.3, 0.12, g);
}
if (kind === "manuscript") {
manuscriptStack(g, -0.95, 0.76, 0.12, 6, 0.8);
manuscriptStack(g, -0.05, 0.76, 0.12, 4, 0.7);
openFolio(g, 0.95, 0.78, 0.12, 0.82);
pot(g, 1.32, 0.04, 0.43, 0.7);
} else {
basket(g, -1.0, 0.04, 0.25, 0.95);
pot(g, -0.15, 0.74, 0.12, 0.7);
pot(g, 0.42, 0.74, 0.15, 0.58, "#b6683e");
gourd(g, 1.12, 0.04, 0.3, 0.9);
rolledTextile(g, 1.12, 0.85, 0.13, "#667e7c", Math.PI / 2);
}
return g;
}
marketStall(-4.5, 3.15, "manuscript");
marketStall(4.45, 3.15, "household");
// Smaller central display, leaving the gate and walking route open.
cube(1.2, 0.08, 0.85, "#c49358", 0.75, 0.05, 3.45);
basket(scene, 0.45, 0.1, 3.45, 0.6);
pot(scene, 1.05, 0.1, 3.43, 0.6);
// -------------------------------------------------------------------------
// Movers
// -------------------------------------------------------------------------
function createCamel() {
const g = group();
g.rotation.y = Math.PI / 2;
cube(1.85, 0.72, 0.72, "#a86e3d", 0, 1.45, 0, g);
cube(0.76, 0.62, 0.62, "#956039", -0.08, 1.95, 0, g);
cube(0.42, 0.48, 0.45, "#a86e3d", -0.05, 2.28, 0, g);
cube(0.36, 1.45, 0.38, "#a86e3d", 0, 2.0, 0.66, g);
cube(0.38, 0.32, 0.67, "#9e6337", 0, 2.78, 0.79, g);
cube(0.29, 0.2, 0.32, "#70442d", 0, 2.67, 1.13, g);
cube(0.08, 0.15, 0.08, "#3e3026", -0.12, 2.84, 1.11, g);
cube(0.08, 0.15, 0.08, "#3e3026", 0.12, 2.84, 1.11, g);
const legs = [];
for (const lx of [-0.62, 0.62]) {
for (const lz of [-0.5, 0.5]) {
const leg = group(lx, 1.28, lz, g);
cube(0.2, 0.78, 0.22, "#9e6337", 0, -0.38, 0, leg);
cube(0.24, 0.12, 0.3, "#65412e", 0, -0.81, 0.05, leg);
legs.push(leg);
}
}
cube(1.2, 0.12, 1.0, "#7f4d38", 0, 1.86, 0, g);
cube(0.58, 0.65, 0.7, "#d0a55d", -0.72, 1.7, 0.02, g);
cube(0.5, 0.58, 0.65, "#8b5e3c", 0.72, 1.67, 0.02, g);
cube(0.55, 0.08, 0.7, "#477074", -0.72, 2.04, 0.02, g);
cube(0.55, 0.08, 0.7, "#477074", 0.72, 2.0, 0.02, g);
return { group: g, legs };
}
const camel = createCamel();
camel.group.position.set(8.5, 0, 6.55);
const porter = createPerson({
x: -9,
z: 4.55,
rotation: Math.PI / 2,
tunic: "#526f70",
wrap: "#dfcea5",
skin: "#75462f"
});
manuscriptStack(porter.group, 0, 1.54, 0.27, 3, 0.58);
const textilePorter = createPerson({
x: 8,
z: 7.0,
rotation: -Math.PI / 2,
tunic: "#a95e40",
wrap: "#d7c69e",
skin: "#8b5638"
});
rolledTextile(textilePorter.group, 0, 1.32, 0.28, "#55777a", 0);
const waterCarrier = createPerson({
x: -5.7,
z: 0.65,
rotation: Math.PI / 2,
tunic: "#b47b42",
wrap: "#e1d0a8",
skin: "#76452f"
});
cube(1.15, 0.08, 0.08, "#6f4b31", 0, 1.9, 0, waterCarrier.group);
pot(waterCarrier.group, -0.49, 1.12, 0, 0.58, "#8d5036");
pot(waterCarrier.group, 0.49, 1.12, 0, 0.58, "#8d5036");
// A manuscript courier leaving the courtyard for the lane.
const courier = createPerson({
x: 0.4,
z: 1.1,
rotation: Math.PI / 2,
tunic: "#b66f3d",
wrap: "#eadbb3",
skin: "#8d5839"
});
manuscriptStack(courier.group, 0, 2.13, 0, 2, 0.62);
// -------------------------------------------------------------------------
// Small environmental details
// -------------------------------------------------------------------------
// A ladder leaning against the rear facade.
cube(0.1, 3.4, 0.1, "#6e4930", 4.8, 1.7, -9.72);
cube(0.1, 3.4, 0.1, "#6e4930", 5.65, 1.7, -9.72);
for (let i = 0; i < 8; i++) {
cube(0.9, 0.08, 0.08, "#805735", 5.23, 0.35 + i * 0.42, -9.72);
}
// Scattered tufts and small stones.
for (let i = 0; i < 65; i++) {
const x = -14 + Math.random() * 28;
const z = -9.8 + Math.random() * 19.5;
if (Math.abs(x) < 7.2 && z < 2.1 && z > -8.9) continue;
if (Math.random() > 0.55) {
cube(0.05, 0.22, 0.05, "#7b6842", x, 0.12, z);
cube(0.04, 0.14, 0.04, "#8e7547", x + 0.08, 0.08, z + 0.03);
} else {
cube(
0.13 + Math.random() * 0.16,
0.09,
0.13 + Math.random() * 0.13,
"#8d704e",
x,
0.06,
z
);
}
}
// Dust motes drifting through the lane.
const dust = [];
for (let i = 0; i < 32; i++) {
const mote = cube(
0.025,
0.025,
0.025,
new THREE.MeshBasicMaterial({
color: "#f2d7a1",
transparent: true,
opacity: 0.35
}),
-13 + Math.random() * 26,
0.3 + Math.random() * 2.6,
3.5 + Math.random() * 4.3
);
dust.push({
mesh: mote,
speed: 0.1 + Math.random() * 0.16,
phase: Math.random() * Math.PI * 2
});
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const animatedPeople = [];
const movers = [];
function pingPong(object, min, max, speed, axis = "x") {
const span = max - min;
const phase = (elapsed * speed / span) * Math.PI * 2;
const value = (Math.sin(phase - Math.PI / 2) + 1) * 0.5;
const previous = object.position[axis];
object.position[axis] = min + value * span;
return Math.sign(object.position[axis] - previous) || 1;
}
function walkPose(person, time, amount = 1) {
const stride = Math.sin(time * 7.5) * 0.58 * amount;
person.leftLeg.rotation.x = stride;
person.rightLeg.rotation.x = -stride;
person.leftArm.rotation.x = -stride * 0.72;
person.rightArm.rotation.x = stride * 0.72;
person.group.position.y = Math.abs(Math.sin(time * 7.5)) * 0.045 * amount;
}
movers.push(
{ object: porter.group, person: porter, min: -10, max: 8.6, speed: 1.0 },
{ object: textilePorter.group, person: textilePorter, min: -9.5, max: 8.8, speed: 0.78 },
{ object: camel.group, min: -9.5, max: 9.5, speed: 0.48 },
{ object: waterCarrier.group, person: waterCarrier, min: -5.9, max: -2.55, speed: 0.42 },
{ object: courier.group, person: courier, min: -2.2, max: 4.4, speed: 0.5 }
);
let elapsed = 0;
let paused = false;
function animateScene(dt) {
if (!paused) elapsed += dt;
// Scripted domestic gestures.
quillPivot.rotation.z = -0.45 + Math.sin(elapsed * 5.2) * 0.14;
quillPivot.position.y = 1.38 + Math.sin(elapsed * 5.2) * 0.025;
scribe.rightArm.rotation.x = -0.78 + Math.sin(elapsed * 4.6) * 0.12;
assistant.rightArm.rotation.x = -1.05 + Math.sin(elapsed * 2.2) * 0.08;
manuscriptTrader.leftArm.rotation.x = -0.92 + Math.sin(elapsed * 2.2 + 0.5) * 0.08;
exchangedFolio.position.y = 1.27 + Math.sin(elapsed * 2.2) * 0.025;
grindingHand.rotation.x = -0.85 + Math.sin(elapsed * 4.4) * 0.42;
grinder.group.rotation.z = Math.sin(elapsed * 4.4) * 0.035;
cookHand.rotation.x = -0.8 + Math.sin(elapsed * 3.6) * 0.28;
leftSeller.leftArm.rotation.x = -0.45 + Math.sin(elapsed * 2.8) * 0.16;
rightSeller.rightArm.rotation.x = -0.5 + Math.sin(elapsed * 2.4 + 1) * 0.2;
// Child wanders in a short loop near the laundry.
child.group.position.x = -5.35 + Math.sin(elapsed * 0.7) * 0.48;
child.group.position.z = -1.15 + Math.sin(elapsed * 0.47) * 0.35;
child.leftLeg.rotation.x = Math.sin(elapsed * 4.2) * 0.12;
child.rightLeg.rotation.x = -Math.sin(elapsed * 4.2) * 0.12;
// Moving people and camel.
for (const mover of movers) {
const direction = pingPong(mover.object, mover.min, mover.max, mover.speed);
if (mover.person) {
walkPose(mover.person, elapsed + mover.min * 0.17);
mover.object.rotation.y = direction > 0 ? Math.PI / 2 : -Math.PI / 2;
} else {
mover.object.rotation.y = direction > 0 ? Math.PI / 2 : -Math.PI / 2;
camel.legs.forEach((leg, i) => {
leg.rotation.x = Math.sin(elapsed * 4.2 + i * Math.PI) * 0.35;
});
camel.group.position.y = Math.abs(Math.sin(elapsed * 4.2)) * 0.025;
}
}
// Basket and load on the porter remain approximately level.
porter.group.children.forEach((childObject) => {
if (childObject.type === "Group") {
childObject.rotation.x = -porter.group.rotation.y * 0.15;
}
});
// Fire flicker.
hearthLight.intensity = 1.05 + Math.sin(elapsed * 11) * 0.16 + Math.sin(elapsed * 17) * 0.08;
// Dust drift.
for (const d of dust) {
d.mesh.position.x += d.speed * dt;
d.mesh.position.y += Math.sin(elapsed * 0.7 + d.phase) * 0.002;
if (d.mesh.position.x > 14) d.mesh.position.x = -14;
}
}
// -------------------------------------------------------------------------
// Custom camera controls: no external controls addon
// -------------------------------------------------------------------------
const view = {
theta: 0.69,
phi: 1.02,
radius: 24,
target: new THREE.Vector3(0, 1, -1)
};
const desired = {
theta: 0.69,
phi: 1.02,
radius: 24,
target: new THREE.Vector3(0, 1, -1)
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (event.shiftKey) {
desired.target.x -= dx * 0.018;
desired.target.z += dy * 0.014;
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.48,
1.42
);
}
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
10,
36
);
},
{ passive: false }
);
const presets = {
overview: {
theta: 0.69,
phi: 1.02,
radius: 24,
target: new THREE.Vector3(0, 1, -1)
},
courtyard: {
theta: 0.57,
phi: 1.08,
radius: 15.5,
target: new THREE.Vector3(-0.6, 1, -3.25)
},
lane: {
theta: 0.75,
phi: 1.18,
radius: 14.5,
target: new THREE.Vector3(0, 1, 4.9)
}
};
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
const preset = presets[button.dataset.view];
desired.theta = preset.theta;
desired.phi = preset.phi;
desired.radius = preset.radius;
desired.target.copy(preset.target);
});
});
// -------------------------------------------------------------------------
// Labels, time and UI
// -------------------------------------------------------------------------
const markerData = [
{
element: document.querySelector('[data-marker="workshop"]'),
position: new THREE.Vector3(-2.3, 3.65, -6.6)
},
{
element: document.querySelector('[data-marker="household"]'),
position: new THREE.Vector3(2.4, 2.25, -2.0)
},
{
element: document.querySelector('[data-marker="lane"]'),
position: new THREE.Vector3(0.4, 2.55, 5.3)
}
];
let labelsVisible = true;
function updateLabels() {
for (const marker of markerData) {
const projected = marker.position.clone().project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
marker.element.style.opacity = visible ? "1" : "0";
marker.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
marker.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
document.getElementById("labels-toggle").addEventListener("click", (event) => {
labelsVisible = !labelsVisible;
event.currentTarget.classList.toggle("active", labelsVisible);
});
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
pauseButton.classList.toggle("active", paused);
});
const timeInput = document.getElementById("time");
const timeOutput = document.getElementById("time-output");
function updateTime() {
const hour = Number(timeInput.value);
const normalized = (hour - 7) / 12;
const angle = normalized * Math.PI;
const elevation = Math.sin(angle);
sun.position.set(
Math.cos(angle) * 18,
Math.max(3, elevation * 19),
8
);
sun.intensity = 0.65 + elevation * 1.55;
hemisphere.intensity = 0.8 + elevation * 0.75;
const dawn = new THREE.Color("#d2a479");
const noon = new THREE.Color("#dfd0a6");
const dusk = new THREE.Color("#c98767");
const sky = normalized < 0.5
? dawn.clone().lerp(noon, normalized * 2)
: noon.clone().lerp(dusk, (normalized - 0.5) * 2);
scene.background.copy(sky);
scene.fog.color.copy(sky);
const minutes = Math.round((hour % 1) * 60);
timeOutput.textContent = `${String(Math.floor(hour)).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
}
timeInput.addEventListener("input", updateTime);
updateTime();
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function render() {
const dt = Math.min(clock.getDelta(), 0.05);
animateScene(dt);
const smoothing = 1 - Math.exp(-dt * 7.5);
view.theta = THREE.MathUtils.lerp(view.theta, desired.theta, smoothing);
view.phi = THREE.MathUtils.lerp(view.phi, desired.phi, smoothing);
view.radius = THREE.MathUtils.lerp(view.radius, desired.radius, smoothing);
view.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(render);
document.getElementById("loading").remove();
</script>
</body>
</html>
```