Prompt specification
Build or customize the Three.js 3D scene "Aksum settlement and trading courtyard" 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: Aksum settlement and trading courtyard
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/aksum-settlement-and-trading-courtyard-x2267
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: Aksum settlement and trading courtyard. Build a referenced Aksum-inspired street segment with stone buildings, a trading courtyard, and distant stela silhouettes. Show ordinary exchange without reducing the society to monuments alone.
Working Three.js Starter (aksum-settlement-and-trading-courtyard-x2267):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Aksum — The Courtyard Exchange</title>
<style>
:root {
--ink: #30271f;
--paper: rgba(248, 239, 216, 0.88);
--line: rgba(73, 55, 37, 0.24);
--accent: #9c4936;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d6c39e;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 43%, transparent 45%, rgba(65, 43, 26, 0.12)),
linear-gradient(to bottom, rgba(255, 244, 213, 0.06), transparent 45%);
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
background: var(--paper);
border: 1px solid var(--line);
border-radius: 4px;
box-shadow: 0 14px 36px rgba(63, 42, 23, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #765b40;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 11px 0 0;
color: #665442;
font-size: 12px;
line-height: 1.55;
}
.badge {
position: fixed;
top: 24px;
right: 24px;
padding: 9px 12px;
background: rgba(55, 43, 30, 0.76);
color: #f8edd2;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 999px;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
pointer-events: none;
}
.help {
position: fixed;
right: 24px;
bottom: 20px;
padding: 9px 12px;
background: rgba(250, 239, 214, 0.8);
border: 1px solid var(--line);
border-radius: 3px;
color: #5f4e3c;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #d6c39e;
color: #5b4936;
font-size: 12px;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: opacity 0.45s ease;
pointer-events: none;
}
.loading.hidden {
opacity: 0;
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
width: min(320px, calc(100vw - 28px));
padding: 14px 16px;
}
.subtitle {
font-size: 11px;
}
.badge {
display: none;
}
.help {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="title-card">
<div class="eyebrow">Aksum-inspired reconstruction</div>
<h1>The Courtyard Exchange</h1>
<p class="subtitle">
A lived-in street segment of stone houses, food stalls, household traffic,
and trade. The distant stelae mark the monumental landscape; the courtyard
shows how the community actually spent its day.
</p>
</header>
<div class="badge">Interpretive low-poly model</div>
<div class="help">Drag to orbit · Scroll or pinch to zoom</div>
<div class="loading" 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";
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
// ---------------------------------------------------------------------
// Renderer, scene, light, and camera
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7c49f);
scene.fog = new THREE.Fog(0xd7c49f, 25, 58);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly scene of an Aksum-inspired trading courtyard"
);
renderer.domElement.tabIndex = 0;
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0.2, 1.45, 0.5),
radius: 24.5,
theta: 0.57,
phi: 1.08,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff0cc, 0x786651, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3a4, 3.4);
sun.position.set(-11, 19, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fa6ae, 0.45);
fill.position.set(10, 8, -12);
scene.add(fill);
// ---------------------------------------------------------------------
// Utilities
// ---------------------------------------------------------------------
let randomSeed = 94721;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function pick(items) {
return items[Math.floor(random() * items.length)];
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...options
});
}
function mesh(geometry, mat, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, mat, x, y, z, parent = scene) {
const object = mesh(new THREE.BoxGeometry(w, h, d), mat, parent);
object.position.set(x, y, z);
return object;
}
function cylinder(
rTop,
rBottom,
h,
mat,
x,
y,
z,
segments = 8,
parent = scene
) {
const object = mesh(
new THREE.CylinderGeometry(rTop, rBottom, h, segments),
mat,
parent
);
object.position.set(x, y, z);
return object;
}
function limb(a, b, radius, mat, parent) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const object = mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 6),
mat,
parent
);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function roofGeometry(w, d, rise) {
const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array([
-w / 2, 0, -d / 2,
w / 2, 0, -d / 2,
0, rise, -d / 2,
-w / 2, 0, d / 2,
w / 2, 0, d / 2,
0, rise, d / 2
]);
geometry.setAttribute(
"position",
new THREE.BufferAttribute(vertices, 3)
);
geometry.setIndex([
0, 1, 2,
3, 5, 4,
0, 2, 5,
0, 5, 3,
1, 4, 5,
1, 5, 2,
0, 3, 4,
0, 4, 1
]);
geometry.computeVertexNormals();
return geometry;
}
const mat = {
ground: material(0xbda77f),
road: material(0xb49a70),
earth: material(0xa98c63),
wood: material(0x59402c),
darkWood: material(0x3d2e23),
thatch: material(0x9b713d),
thatchDark: material(0x7e582f),
plaster: material(0xd4c19c),
plasterRed: material(0xb46d50),
door: material(0x3e3026),
basket: material(0xa47a3c),
basketDark: material(0x78552d),
terracotta: material(0xa9563c),
terracottaLight: material(0xc2764f),
grain: material(0xd7b86a),
spiceRed: material(0xa3472f),
spiceGold: material(0xc58a31),
green: material(0x657747),
darkGreen: material(0x46543a),
leaf: material(0x718052),
leafLight: material(0x89905a),
black: material(0x26231f),
water: material(0x627d79, { roughness: 0.48 }),
stela: material(0x716958),
stelaDark: material(0x554d42)
};
const stoneMaterials = [
material(0xb5a487),
material(0xc0af91),
material(0xa9987b),
material(0xc8b697),
material(0xad9a7d)
];
const clothMaterials = [
material(0x9e4935),
material(0x56777a),
material(0xc39343),
material(0x7c6a83),
material(0xc7b987)
];
const skinMaterials = [
material(0x754a31),
material(0x8c5b3b),
material(0x9b6947),
material(0x68402c),
material(0xa87651)
];
const robeMaterials = [
material(0xeee0bd),
material(0x9c4935),
material(0x607b78),
material(0xb37b39),
material(0x766477),
material(0x6f7350),
material(0xd0c6ab)
];
// ---------------------------------------------------------------------
// Ground, street, and courtyard paving
// ---------------------------------------------------------------------
const ground = mesh(new THREE.PlaneGeometry(90, 90), mat.ground);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.castShadow = false;
box(39, 0.08, 3.6, mat.road, 0, 0, -0.35);
const pavingMaterial = material(0xffffff, { vertexColors: true });
const pavingGeometry = new THREE.BoxGeometry(0.66, 0.065, 0.61);
const pavingColumns = 18;
const pavingRows = 11;
const paving = new THREE.InstancedMesh(
pavingGeometry,
pavingMaterial,
pavingColumns * pavingRows
);
const dummy = new THREE.Object3D();
const pavingColors = [0xbbaa8b, 0xc4b395, 0xaa987b, 0xcdbb9d, 0xb09d7e];
let pavingIndex = 0;
for (let row = 0; row < pavingRows; row++) {
for (let col = 0; col < pavingColumns; col++) {
dummy.position.set(
-1.2 + col * 0.72 + (row % 2) * 0.035,
0.025,
1.15 + row * 0.67
);
dummy.rotation.set(0, (random() - 0.5) * 0.06, 0);
dummy.scale.set(
0.93 + random() * 0.09,
1,
0.92 + random() * 0.1
);
dummy.updateMatrix();
paving.setMatrixAt(pavingIndex, dummy.matrix);
paving.setColorAt(
pavingIndex,
new THREE.Color(pick(pavingColors))
);
pavingIndex++;
}
}
paving.instanceMatrix.needsUpdate = true;
if (paving.instanceColor) paving.instanceColor.needsUpdate = true;
paving.receiveShadow = true;
scene.add(paving);
// ---------------------------------------------------------------------
// Stone buildings
// ---------------------------------------------------------------------
function makeBuilding({
x,
z,
w,
d,
h,
upper = true,
roof = mat.thatch,
wall = mat.plaster
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(w, h, d, stoneMaterials[1], 0, h / 2, 0, group);
// Irregular exposed masonry on the street-facing side.
const rows = Math.max(5, Math.floor(h / 0.43));
const rowHeight = h / rows;
for (let row = 0; row < rows; row++) {
let cursor = -w / 2 + 0.08;
while (cursor < w / 2 - 0.12) {
const length = Math.min(
0.72 + random() * 0.5,
w / 2 - 0.08 - cursor
);
if (length > 0.16) {
box(
Math.max(0.12, length - 0.045),
rowHeight * 0.82,
0.105,
pick(stoneMaterials),
cursor + length / 2,
rowHeight * (row + 0.5),
d / 2 + 0.025,
group
);
}
cursor += length;
}
}
// Masonry on the visible eastern side.
for (let row = 0; row < rows; row++) {
let cursor = -d / 2 + 0.1;
while (cursor < d / 2 - 0.12) {
const length = Math.min(
0.7 + random() * 0.45,
d / 2 - 0.08 - cursor
);
if (length > 0.16) {
box(
0.105,
rowHeight * 0.8,
Math.max(0.12, length - 0.04),
pick(stoneMaterials),
w / 2 + 0.025,
rowHeight * (row + 0.5),
cursor + length / 2,
group
);
}
cursor += length;
}
}
// Door, threshold, and wooden lintel.
const doorX = -w * 0.2;
box(0.9, 1.62, 0.11, mat.door, doorX, 0.82, d / 2 + 0.075, group);
box(1.08, 0.16, 0.16, mat.darkWood, doorX, 1.7, d / 2 + 0.08, group);
box(1.05, 0.13, 0.5, stoneMaterials[0], doorX, 0.065, d / 2 + 0.22, group);
// Small ground-level window.
box(
0.48,
0.46,
0.08,
mat.door,
w * 0.24,
1.65,
d / 2 + 0.07,
group
);
let upperHeight = 0;
if (upper) {
upperHeight = 1.4;
box(
w * 0.91,
upperHeight,
d * 0.91,
wall,
0,
h + upperHeight / 2,
0,
group
);
// Timber framing.
box(w * 0.94, 0.13, d * 0.94, mat.darkWood, 0, h + 0.05, 0, group);
box(w * 0.94, 0.13, d * 0.94, mat.darkWood, 0, h + upperHeight - 0.04, 0, group);
for (const side of [-1, 1]) {
box(
0.13,
upperHeight,
0.15,
mat.darkWood,
side * w * 0.45,
h + upperHeight / 2,
d * 0.46,
group
);
box(
0.13,
upperHeight,
0.15,
mat.darkWood,
side * w * 0.45,
h + upperHeight / 2,
-d * 0.46,
group
);
}
// Upper windows.
for (const wx of [-w * 0.23, w * 0.22]) {
box(
0.55,
0.52,
0.09,
mat.door,
wx,
h + 0.72,
d * 0.46 + 0.04,
group
);
}
}
const roofObject = mesh(
roofGeometry(w + 0.48, d + 0.42, 1.15),
roof,
group
);
roofObject.position.y = h + upperHeight;
// A few dark rafters emphasize the low-poly thatch.
for (let i = 0; i < 5; i++) {
const z = -d * 0.37 + (i / 4) * d * 0.74;
const rafter = box(0.075, 0.075, d + 0.48, mat.thatchDark, 0, h + upperHeight + 0.05, z, group);
rafter.rotation.z = 0;
}
// A cloth shade over the doorway.
const shade = box(
1.65,
0.055,
0.82,
pick(clothMaterials),
doorX,
1.98,
d / 2 + 0.43,
group
);
shade.rotation.x = 0.08;
return group;
}
makeBuilding({
x: -8.6,
z: -3.7,
w: 5.8,
d: 4.8,
h: 3.1,
roof: mat.thatch,
wall: mat.plaster
});
makeBuilding({
x: -2.0,
z: -4.0,
w: 5.6,
d: 4.6,
h: 3.4,
roof: mat.thatchDark,
wall: mat.plasterRed
});
makeBuilding({
x: 5.0,
z: -3.8,
w: 5.3,
d: 4.7,
h: 3.15,
roof: mat.thatch,
wall: mat.plaster
});
makeBuilding({
x: 11.4,
z: -3.9,
w: 4.8,
d: 4.8,
h: 2.85,
upper: false,
roof: mat.thatchDark
});
// Low compound wall and a gatepost define the courtyard edge.
box(0.48, 1.05, 5.1, stoneMaterials[1], 11.7, 0.53, 3.45);
box(0.48, 1.05, 3.1, stoneMaterials[2], 11.7, 0.53, 8.6);
cylinder(0.34, 0.38, 1.55, stoneMaterials[0], 11.7, 0.78, 6.35, 8);
// ---------------------------------------------------------------------
// Market goods
// ---------------------------------------------------------------------
function makeBasket(parent, x, y, z, scale = 1, filled = true) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
const body = mesh(
new THREE.CylinderGeometry(0.44, 0.32, 0.4, 10, 1, true),
mat.basket,
group
);
body.material.side = THREE.DoubleSide;
const rim = mesh(new THREE.TorusGeometry(0.43, 0.035, 5, 12), mat.basketDark, group);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.2;
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const strip = box(
0.026,
0.39,
0.035,
mat.basketDark,
Math.cos(angle) * 0.39,
0,
Math.sin(angle) * 0.39,
group
);
strip.rotation.y = -angle;
}
if (filled) {
const contents = mesh(
new THREE.DodecahedronGeometry(0.36, 0),
mat.grain,
group
);
contents.scale.set(1, 0.22, 1);
contents.position.y = 0.17;
}
return group;
}
function makeJar(parent, x, y, z, scale = 1, light = false) {
const profile = [
new THREE.Vector2(0.08, 0),
new THREE.Vector2(0.24, 0.06),
new THREE.Vector2(0.39, 0.29),
new THREE.Vector2(0.38, 0.58),
new THREE.Vector2(0.25, 0.82),
new THREE.Vector2(0.16, 0.94),
new THREE.Vector2(0.21, 1.03),
new THREE.Vector2(0.14, 1.08)
];
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
const jar = mesh(
new THREE.LatheGeometry(profile, 9),
light ? mat.terracottaLight : mat.terracotta,
group
);
const band = mesh(
new THREE.TorusGeometry(0.29, 0.026, 5, 10),
mat.basketDark,
group
);
band.rotation.x = Math.PI / 2;
band.position.y = 0.48;
return group;
}
function makeSack(parent, x, y, z, scale = 1) {
const sack = mesh(
new THREE.DodecahedronGeometry(0.34, 1),
mat.plaster,
parent
);
sack.position.set(x, y + 0.28, z);
sack.scale.set(0.8 * scale, 1.2 * scale, 0.75 * scale);
return sack;
}
function makeTextile(parent, x, y, z, color, w = 1.1, d = 0.75) {
return box(w, 0.055, d, color, x, y, z, parent);
}
function makeScale(parent) {
const group = new THREE.Group();
group.position.set(0.82, 0.78, 0);
parent.add(group);
cylinder(0.035, 0.05, 0.85, mat.darkWood, 0, 0.42, 0, 6, group);
const beam = box(0.92, 0.045, 0.045, mat.darkWood, 0, 0.83, 0, group);
beam.rotation.z = -0.07;
for (const side of [-1, 1]) {
limb(
[side * 0.38, 0.79, 0],
[side * 0.38, 0.48, 0],
0.009,
mat.wood,
group
);
const pan = cylinder(
0.13,
0.09,
0.035,
mat.terracottaLight,
side * 0.38,
0.46,
0,
8,
group
);
pan.scale.z = 0.7;
}
}
function makeStall(x, z, cloth, width = 2.5) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const poleMaterial = mat.wood;
for (const px of [-width / 2, width / 2]) {
for (const pz of [-0.55, 0.55]) {
cylinder(0.045, 0.055, 2.25, poleMaterial, px, 1.12, pz, 6, group);
}
}
const stripeWidth = width / 6;
for (let i = 0; i < 6; i++) {
const stripe = box(
stripeWidth + 0.015,
0.055,
1.48,
i % 2 === 0 ? cloth : mat.clothMaterials
? clothMaterials[(clothMaterials.indexOf(cloth) + 1) % clothMaterials.length]
: cloth,
-width / 2 + stripeWidth * (i + 0.5),
2.24,
0,
group
);
stripe.rotation.x = -0.025;
}
// Hanging valance.
for (let i = 0; i < 6; i++) {
box(
stripeWidth,
0.2,
0.035,
i % 2 === 0 ? cloth : mat.plaster,
-width / 2 + stripeWidth * (i + 0.5),
2.11,
0.72,
group
);
}
// Table.
box(width * 0.9, 0.12, 0.82, mat.wood, 0, 0.75, 0, group);
for (const px of [-width * 0.36, width * 0.36]) {
box(0.1, 0.7, 0.1, mat.darkWood, px, 0.37, 0, group);
}
return group;
}
const stallA = makeStall(-2.15, 4.05, clothMaterials[0], 2.55);
makeBasket(stallA, -0.72, 0.82, 0, 0.7, true);
makeBasket(stallA, 0.0, 0.82, 0, 0.62, true);
makeJar(stallA, 0.77, 0.82, 0.05, 0.48, true);
makeTextile(stallA, -0.35, 0.84, 0.12, clothMaterials[3], 0.55, 0.42);
makeScale(stallA);
const stallB = makeStall(2.55, 5.35, clothMaterials[1], 2.5);
makeBasket(stallB, -0.65, 0.82, 0, 0.66, true);
makeBasket(stallB, 0.05, 0.82, 0.02, 0.58, true);
makeJar(stallB, 0.72, 0.82, 0, 0.52);
makeSack(stallB, -1.1, 0.02, 0.72, 1.1);
const stallC = makeStall(7.0, 4.55, clothMaterials[2], 2.35);
makeTextile(stallC, -0.55, 0.84, 0, clothMaterials[4], 0.8, 0.55);
makeTextile(stallC, 0.05, 0.92, 0.02, clothMaterials[3], 0.65, 0.45);
makeJar(stallC, 0.72, 0.82, 0, 0.55, true);
makeBasket(stallC, 0.7, 0.02, 0.85, 0.9, true);
// Household storage outside the buildings.
makeJar(scene, -10.9, 0.05, -0.95, 1.15);
makeJar(scene, -10.15, 0.05, -0.8, 0.83, true);
makeBasket(scene, -4.9, 0.04, -0.75, 0.85, true);
makeJar(scene, 0.2, 0.05, -1.0, 1.05);
makeJar(scene, 0.85, 0.05, -1.15, 0.72, true);
makeSack(scene, 3.8, 0.02, -1.05, 1.2);
// ---------------------------------------------------------------------
// People
// ---------------------------------------------------------------------
const animatedPeople = [];
function makePerson({
x,
z,
rotation = 0,
robe = robeMaterials[0],
skin = skinMaterials[1],
pose = "idle",
headWrap = false,
basket = false,
jar = false,
scale = 1
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.27, 0.39, 0.82, robe, 0, 0.59, 0, 8, group);
cylinder(0.29, 0.26, 0.36, robe, 0, 1.08, 0, 8, group);
cylinder(0.085, 0.09, 0.16, skin, 0, 1.31, 0, 7, group);
const head = mesh(
new THREE.SphereGeometry(0.19, 8, 6),
skin,
group
);
head.position.set(0, 1.5, 0);
if (headWrap) {
const wrap = mesh(
new THREE.SphereGeometry(0.2, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2),
pick(clothMaterials),
group
);
wrap.position.set(0, 1.52, 0);
} else {
const hair = mesh(
new THREE.SphereGeometry(0.195, 8, 5, 0, Math.PI * 2, 0, Math.PI * 0.48),
mat.darkWood,
group
);
hair.position.set(0, 1.52, 0);
}
// Small eyes help orient the figures.
for (const side of [-1, 1]) {
box(0.032, 0.032, 0.018, mat.black, side * 0.065, 1.51, 0.177, group);
}
// Feet.
box(0.13, 0.08, 0.25, mat.darkWood, -0.13, 0.06, 0.035, group);
box(0.13, 0.08, 0.25, mat.darkWood, 0.13, 0.06, 0.035, group);
if (pose === "exchange") {
limb([-0.27, 1.18, 0], [-0.31, 1.01, 0.25], 0.075, robe, group);
limb([-0.31, 1.01, 0.25], [-0.18, 1.04, 0.51], 0.065, skin, group);
limb([0.27, 1.18, 0], [0.31, 1.0, 0.23], 0.075, robe, group);
limb([0.31, 1.0, 0.23], [0.19, 1.02, 0.48], 0.065, skin, group);
} else if (pose === "talk") {
limb([-0.27, 1.18, 0], [-0.32, 0.91, 0.04], 0.075, robe, group);
limb([-0.32, 0.91, 0.04], [-0.26, 0.7, 0.12], 0.065, skin, group);
limb([0.27, 1.18, 0], [0.38, 1.06, 0.22], 0.075, robe, group);
limb([0.38, 1.06, 0.22], [0.48, 1.17, 0.36], 0.065, skin, group);
} else if (pose === "carry") {
limb([-0.27, 1.18, 0], [-0.32, 0.95, 0.12], 0.075, robe, group);
limb([-0.32, 0.95, 0.12], [-0.24, 0.76, 0.24], 0.065, skin, group);
limb([0.27, 1.18, 0], [0.36, 1.3, 0.08], 0.075, robe, group);
limb([0.36, 1.3, 0.08], [0.25, 1.48, 0.1], 0.065, skin, group);
} else {
limb([-0.27, 1.18, 0], [-0.34, 0.72, 0.02], 0.075, robe, group);
limb([-0.34, 0.72, 0.02], [-0.3, 0.46, 0.05], 0.065, skin, group);
limb([0.27, 1.18, 0], [0.34, 0.73, 0.02], 0.075, robe, group);
limb([0.34, 0.73, 0.02], [0.3, 0.46, 0.05], 0.065, skin, group);
}
// A shawl across some shoulders.
if (random() > 0.42) {
const shawl = box(0.54, 0.12, 0.31, pick(clothMaterials), 0, 1.18, 0.01, group);
shawl.rotation.z = (random() - 0.5) * 0.18;
}
if (basket) makeBasket(group, 0.43, 0.28, 0.18, 0.68, true);
if (jar) makeJar(group, 0.26, 1.57, 0.1, 0.45);
group.userData.phase = random() * Math.PI * 2;
group.userData.baseY = group.position.y;
animatedPeople.push(group);
return group;
}
// Seller and customer exchanging goods at the grain stall.
makePerson({
x: -2.15,
z: 2.86,
rotation: 0,
robe: robeMaterials[2],
skin: skinMaterials[2],
pose: "exchange",
headWrap: true
});
makePerson({
x: -1.68,
z: 4.93,
rotation: Math.PI,
robe: robeMaterials[6],
skin: skinMaterials[0],
pose: "exchange",
headWrap: true
});
makePerson({
x: 2.5,
z: 4.15,
rotation: 0,
robe: robeMaterials[3],
skin: skinMaterials[3],
pose: "talk",
headWrap: false
});
makePerson({
x: 3.14,
z: 6.48,
rotation: Math.PI,
robe: robeMaterials[4],
skin: skinMaterials[1],
pose: "exchange",
headWrap: true
});
makePerson({
x: 6.9,
z: 3.35,
rotation: 0,
robe: robeMaterials[0],
skin: skinMaterials[4],
pose: "talk"
});
makePerson({
x: 7.75,
z: 5.67,
rotation: Math.PI * 0.85,
robe: robeMaterials[5],
skin: skinMaterials[2],
pose: "idle",
basket: true
});
makePerson({
x: -0.15,
z: 4.25,
rotation: 1.1,
robe: robeMaterials[0],
skin: skinMaterials[3],
pose: "talk",
scale: 0.72
});
makePerson({
x: 4.55,
z: 7.6,
rotation: 2.4,
robe: robeMaterials[2],
skin: skinMaterials[0],
pose: "carry",
jar: true
});
makePerson({
x: -5.45,
z: 0.65,
rotation: 1.55,
robe: robeMaterials[3],
skin: skinMaterials[4],
pose: "carry",
jar: true
});
makePerson({
x: 5.85,
z: 0.8,
rotation: -1.15,
robe: robeMaterials[6],
skin: skinMaterials[1],
pose: "idle",
basket: true
});
makePerson({
x: 9.15,
z: 3.05,
rotation: -0.5,
robe: robeMaterials[4],
skin: skinMaterials[2],
pose: "talk"
});
// ---------------------------------------------------------------------
// Goats and household animals
// ---------------------------------------------------------------------
function makeGoat(x, z, rotation, dark = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const coat = dark ? material(0x4b4038) : material(0xa99b83);
const body = mesh(new THREE.DodecahedronGeometry(0.56, 0), coat, group);
body.position.y = 0.72;
body.scale.set(0.9, 0.78, 1.35);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
cylinder(
0.055,
0.07,
0.56,
coat,
sx * 0.29,
0.32,
sz * 0.39,
6,
group
);
}
}
const neck = mesh(new THREE.DodecahedronGeometry(0.26, 0), coat, group);
neck.position.set(0, 0.95, 0.63);
neck.scale.set(0.8, 1.2, 0.85);
const head = mesh(new THREE.DodecahedronGeometry(0.25, 0), coat, group);
head.position.set(0, 1.13, 0.79);
head.scale.set(0.75, 0.9, 1.1);
for (const side of [-1, 1]) {
const ear = mesh(new THREE.ConeGeometry(0.09, 0.25, 5), coat, group);
ear.position.set(side * 0.22, 1.18, 0.76);
ear.rotation.z = side * 0.8;
limb(
[side * 0.1, 1.32, 0.76],
[side * 0.18, 1.57, 0.66],
0.035,
mat.basketDark,
group
);
}
const tail = mesh(new THREE.ConeGeometry(0.07, 0.33, 5), coat, group);
tail.position.set(0, 0.78, -0.75);
tail.rotation.x = -1.1;
return group;
}
makeGoat(-4.35, 0.7, 0.5, false);
makeGoat(-3.25, 0.3, -0.3, true);
makeGoat(9.0, 7.35, 2.0, false);
// ---------------------------------------------------------------------
// Courtyard furniture, textiles, well, and tree
// ---------------------------------------------------------------------
// Low bench.
box(2.1, 0.16, 0.55, mat.wood, 0.25, 0.54, 8.0);
for (const x of [-0.55, 1.05]) {
box(0.18, 0.5, 0.45, mat.darkWood, x, 0.25, 8.0);
}
// Woven mats and folded cloth.
makeTextile(scene, 0.5, 0.075, 7.35, clothMaterials[4], 1.5, 0.9);
makeTextile(scene, 0.55, 0.14, 7.4, clothMaterials[0], 0.85, 0.6);
makeTextile(scene, 5.2, 0.075, 7.5, clothMaterials[1], 1.25, 0.85);
makeTextile(scene, 5.25, 0.135, 7.55, clothMaterials[3], 0.72, 0.55);
// Small courtyard well.
const well = new THREE.Group();
well.position.set(8.95, 0, 8.25);
scene.add(well);
const wellMaterial = stoneMaterials[1];
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const stone = box(0.38, 0.52, 0.26, wellMaterial, Math.cos(angle) * 0.65, 0.27, Math.sin(angle) * 0.65, well);
stone.rotation.y = -angle;
}
cylinder(0.57, 0.57, 0.05, mat.water, 0, 0.17, 0, 12, well);
cylinder(0.055, 0.07, 1.3, mat.wood, -0.55, 0.7, 0, 6, well);
cylinder(0.055, 0.07, 1.3, mat.wood, 0.55, 0.7, 0, 6, well);
box(1.35, 0.09, 0.12, mat.wood, 0, 1.32, 0, well);
// Tree at the edge of the trading space.
function makeTree(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
cylinder(0.18, 0.3, 2.65, mat.wood, 0, 1.33, 0, 7, group);
limb([0, 1.8, 0], [-0.8, 2.7, 0.1], 0.11, mat.wood, group);
limb([0, 2.05, 0], [0.8, 2.8, -0.1], 0.1, mat.wood, group);
const canopyA = mesh(new THREE.DodecahedronGeometry(1.1, 0), mat.darkGreen, group);
canopyA.position.set(0, 3.05, 0);
canopyA.scale.set(1.25, 0.6, 1);
const canopyB = mesh(new THREE.DodecahedronGeometry(0.85, 0), mat.leaf, group);
canopyB.position.set(-0.85, 2.75, 0.15);
canopyB.scale.set(1.1, 0.55, 0.9);
const canopyC = mesh(new THREE.DodecahedronGeometry(0.8, 0), mat.leafLight, group);
canopyC.position.set(0.75, 2.9, -0.1);
canopyC.scale.set(1, 0.55, 0.9);
}
makeTree(10.35, 8.55);
// Firewood and a stool near a house.
for (let i = 0; i < 5; i++) {
const log = cylinder(0.07, 0.09, 0.95, mat.wood, -11.3 + i * 0.15, 0.13, 1.0 + (i % 2) * 0.15, 6);
log.rotation.z = Math.PI / 2;
}
cylinder(0.28, 0.31, 0.46, mat.wood, -5.7, 0.24, 1.7, 8);
// ---------------------------------------------------------------------
// Distant stela silhouettes
// ---------------------------------------------------------------------
function stelaGeometry(bottomWidth, topWidth, depth, height) {
const bw = bottomWidth / 2;
const tw = topWidth / 2;
const bd = depth / 2;
const td = depth * 0.36;
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-bw, 0, -bd,
bw, 0, -bd,
bw, 0, bd,
-bw, 0, bd,
-tw, height, -td,
tw, height, -td,
tw, height, td,
-tw, height, td
], 3)
);
geometry.setIndex([
3, 2, 6, 3, 6, 7,
0, 4, 5, 0, 5, 1,
0, 3, 7, 0, 7, 4,
1, 5, 6, 1, 6, 2,
4, 7, 6, 4, 6, 5
]);
geometry.computeVertexNormals();
return geometry;
}
function makeStela(x, z, height, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(1.8, 0.28, 1.35, mat.stelaDark, 0, 0.14, 0, group);
const slab = mesh(
stelaGeometry(1.15, 0.68, 0.58, height),
mat.stela,
group
);
slab.position.y = 0.27;
// Restrained false-door and arm-like bands.
box(0.38, height * 0.46, 0.055, mat.stelaDark, 0, 0.27 + height * 0.23, 0.205, group);
box(0.73, 0.105, 0.07, mat.stelaDark, 0, 0.27 + height * 0.59, 0.23, group);
box(0.95, 0.09, 0.07, mat.stelaDark, 0, 0.27 + height * 0.68, 0.205, group);
box(0.24, 0.36, 0.055, mat.stelaDark, 0, 0.27 + height * 0.8, 0.18, group);
}
makeStela(-9.7, -15.4, 6.6, 0.08);
makeStela(-5.3, -18.2, 7.8, -0.06);
makeStela(-1.2, -16.3, 5.7, 0.04);
makeStela(2.7, -19.1, 8.3, -0.03);
makeStela(6.4, -16.8, 6.2, 0.08);
makeStela(10.2, -20.0, 7.4, -0.08);
// Low ridges beyond the settlement.
const ridgeMaterial = material(0x9f9073);
for (let i = 0; i < 8; i++) {
const ridge = mesh(
new THREE.ConeGeometry(8 + random() * 4, 6 + random() * 5, 5),
ridgeMaterial
);
ridge.position.set(-28 + i * 8, 1.8, -33 - random() * 9);
ridge.scale.set(1.5, 0.65, 0.7);
ridge.castShadow = false;
}
// A muted sun disc.
const sunDisc = mesh(
new THREE.CircleGeometry(2.2, 24),
new THREE.MeshBasicMaterial({ color: 0xffe4a0, fog: false })
);
sunDisc.position.set(-15, 18, -34);
sunDisc.lookAt(camera.position);
sunDisc.castShadow = false;
// ---------------------------------------------------------------------
// Dust motes
// ---------------------------------------------------------------------
const dustCount = 75;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = -13 + random() * 27;
dustPositions[i * 3 + 1] = 0.4 + random() * 5;
dustPositions[i * 3 + 2] = -8 + random() * 19;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xf2d9a2,
size: 0.045,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
scene.add(dust);
// ---------------------------------------------------------------------
// Direct camera controls: drag to orbit and wheel/pinch to zoom
// ---------------------------------------------------------------------
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.48,
1.3
);
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", () => {
controls.dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.015,
14,
35
);
updateCamera();
},
{ passive: false }
);
// Simple two-pointer pinch zoom.
const activePointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius + (pinchDistance - distance) * 0.035,
14,
35
);
updateCamera();
}
pinchDistance = distance;
}
});
canvas.addEventListener("pointerup", (event) => {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
});
canvas.addEventListener("pointercancel", (event) => {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
});
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") controls.theta -= step;
if (event.key === "ArrowRight") controls.theta += step;
if (event.key === "ArrowUp") {
controls.phi = Math.max(0.48, controls.phi - step * 0.5);
}
if (event.key === "ArrowDown") {
controls.phi = Math.min(1.3, controls.phi + step * 0.5);
}
if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(14, controls.radius - 1);
}
if (event.key === "-") {
controls.radius = Math.min(35, controls.radius + 1);
}
updateCamera();
});
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
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Almost imperceptible human movement keeps the courtyard from feeling frozen.
for (const person of animatedPeople) {
person.position.y =
person.userData.baseY +
Math.sin(elapsed * 1.7 + person.userData.phase) * 0.012;
}
const dustAttribute = dust.geometry.getAttribute("position");
for (let i = 0; i < dustCount; i++) {
const baseY = dustAttribute.getY(i);
dustAttribute.setY(
i,
0.4 + ((baseY - 0.4 + elapsed * 0.025) % 5)
);
}
dustAttribute.needsUpdate = true;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```