Prompt specification
Build or customize the Three.js 3D scene "Mesopotamian grain store 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: Mesopotamian grain store courtyard
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mesopotamian-grain-store-courtyard-x2299
Scene Description Prompt:
A low-poly Mesopotamian grain-store courtyard with sacks, measured portions, and a record keeper matching goods to ledger tokens. Three.js from cdnjs, one HTML file.
Working Three.js Starter (mesopotamian-grain-store-courtyard-x2299):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mesopotamian Grain Store</title>
<style>
:root {
--ink: #35271d;
--paper: rgba(239, 215, 166, 0.92);
--line: rgba(71, 47, 29, 0.28);
--accent: #a75232;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b88b5c;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(55, 34, 19, 0.2);
backdrop-filter: blur(7px);
}
#title {
top: 22px;
left: 22px;
max-width: 390px;
padding: 18px 20px 16px;
border-radius: 3px;
}
#title .eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
font-weight: 500;
line-height: 1;
}
#title p {
margin: 11px 0 0;
font-size: 14px;
line-height: 1.5;
}
#views {
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
gap: 6px;
max-width: 370px;
padding: 8px;
border-radius: 3px;
}
button {
appearance: none;
border: 1px solid transparent;
padding: 9px 11px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
transition: background 140ms ease, border-color 140ms ease;
}
button:hover,
button.active {
border-color: var(--line);
background: rgba(255, 248, 226, 0.58);
}
#hint {
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 10px 15px;
border-radius: 3px;
color: #513827;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
letter-spacing: 0.035em;
text-align: center;
white-space: nowrap;
}
#legend {
right: 22px;
bottom: 20px;
padding: 12px 14px;
border-radius: 3px;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
line-height: 1.7;
letter-spacing: 0.035em;
}
#legend strong {
color: var(--accent);
letter-spacing: 0.12em;
text-transform: uppercase;
}
.swatch {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 6px;
border-radius: 50%;
vertical-align: -1px;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #b88b5c;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#title {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
#title p {
display: none;
}
#views {
top: 103px;
right: 12px;
left: 12px;
max-width: none;
}
#hint {
bottom: 12px;
max-width: calc(100vw - 24px);
white-space: normal;
}
#legend {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="title" class="panel">
<div class="eyebrow">A courtyard tally</div>
<h1>The Grain Store</h1>
<p>
Sacks are measured, portions are weighed, and the keeper matches each
delivery to its clay token and ledger entry.
</p>
</section>
<nav id="views" class="panel" aria-label="Camera views">
<button data-view="courtyard" class="active">Courtyard</button>
<button data-view="sacks">Grain sacks</button>
<button data-view="scale">Measured portions</button>
<button data-view="keeper">Record keeper</button>
</nav>
<div id="hint" class="panel">
Drag to orbit · Shift/right-drag to pan · Scroll or pinch to zoom · 1–4 views
</div>
<div id="legend" class="panel">
<strong>Clay tally</strong><br>
<span class="swatch" style="background:#b75e3c"></span>new measure<br>
<span class="swatch" style="background:#554033"></span>stored measure<br>
<span class="swatch" style="background:#d1a64c"></span>dispensed grain
</div>
<div id="loading">Building the grain courtyard…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -----------------------------------------------------------------------
// Basic setup
// -----------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc6a273);
scene.fog = new THREE.Fog(0xc6a273, 24, 48);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.getElementById("scene").appendChild(renderer.domElement);
let seed = 481516;
function random() {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
function range(a, b) {
return a + (b - a) * random();
}
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.94,
flatShading: true,
...extra
});
}
const materials = {
wall: standard(0xb77f4e),
wallLight: standard(0xc18b57),
wallDark: standard(0xa96e43),
earth: standard(0xb99160),
wood: standard(0x65422b),
woodLight: standard(0x896040),
reed: standard(0xa88848),
sack: standard(0xb58b52),
sackLight: standard(0xc39b62),
sackDark: standard(0x98703f),
grain: standard(0xd2a44b),
grainLight: standard(0xe0b85e),
basket: standard(0x8a6038),
clay: standard(0xa65335),
clayLight: standard(0xc16b42),
charcoal: standard(0x4b392e),
robe: standard(0x496665),
robeDark: standard(0x344a4b),
skin: standard(0x8e5938),
hair: standard(0x30251f),
black: standard(0x241c18)
};
function addMesh(geometry, material, x = 0, y = 0, z = 0, 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 cylinderBetween(a, b, radius, material, parent = scene, sides = 7) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), sides),
material,
0,
0,
0,
parent
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// -----------------------------------------------------------------------
// Lighting
// -----------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffe8bc, 0x5c4434, 2.15));
const sunlight = new THREE.DirectionalLight(0xffd08a, 3.6);
sunlight.position.set(-9, 15, 9);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -18;
sunlight.shadow.camera.right = 18;
sunlight.shadow.camera.top = 18;
sunlight.shadow.camera.bottom = -18;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 42;
sunlight.shadow.bias = -0.00035;
scene.add(sunlight);
const bounce = new THREE.DirectionalLight(0x8fb8b1, 0.42);
bounce.position.set(10, 6, -8);
scene.add(bounce);
// -----------------------------------------------------------------------
// Procedural textures
// -----------------------------------------------------------------------
function createWovenTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#a9844f";
ctx.fillRect(0, 0, 256, 256);
for (let y = 0; y < 256; y += 8) {
ctx.fillStyle = y % 16 === 0 ? "#b18b51" : "#8f6e40";
ctx.fillRect(0, y, 256, 3);
}
for (let x = 0; x < 256; x += 10) {
ctx.fillStyle = "rgba(60,39,22,.15)";
ctx.fillRect(x, 0, 2, 256);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(4, 4);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createLedgerTexture() {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 384;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#6e4b30";
ctx.fillRect(0, 0, 640, 384);
ctx.strokeStyle = "#b9975f";
ctx.lineWidth = 3;
ctx.strokeRect(18, 18, 604, 348);
ctx.beginPath();
ctx.moveTo(18, 94);
ctx.lineTo(622, 94);
ctx.moveTo(18, 188);
ctx.lineTo(622, 188);
ctx.moveTo(18, 282);
ctx.lineTo(622, 282);
ctx.moveTo(150, 18);
ctx.lineTo(150, 366);
ctx.moveTo(410, 18);
ctx.lineTo(410, 366);
ctx.stroke();
function wedge(x, y, size, vertical = false) {
ctx.beginPath();
if (vertical) {
ctx.moveTo(x - size * 0.45, y - size);
ctx.lineTo(x + size * 0.55, y);
ctx.lineTo(x - size * 0.45, y + size);
} else {
ctx.moveTo(x - size, y - size * 0.45);
ctx.lineTo(x, y + size * 0.55);
ctx.lineTo(x + size, y - size * 0.45);
}
ctx.closePath();
ctx.fill();
}
ctx.fillStyle = "#d4b878";
for (let row = 0; row < 4; row++) {
const cy = 54 + row * 94;
for (let i = 0; i < 7; i++) {
const x = 54 + i * 22 + range(-3, 3);
wedge(x, cy + range(-8, 8), 8, random() > 0.52);
}
for (let i = 0; i < 6; i++) {
const x = 185 + i * 30 + range(-4, 4);
wedge(x, cy + range(-9, 9), 10, random() > 0.48);
}
for (let i = 0; i < 3; i++) {
const x = 455 + i * 43;
ctx.beginPath();
ctx.arc(x, cy, 10, 0, Math.PI * 2);
ctx.fill();
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createPlaqueTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#c59b64";
ctx.fillRect(0, 0, 512, 256);
ctx.strokeStyle = "#604126";
ctx.lineWidth = 7;
ctx.strokeRect(17, 17, 478, 222);
ctx.fillStyle = "#604126";
const signs = [
[100, 90], [185, 90], [270, 90], [355, 90],
[100, 165], [185, 165], [270, 165], [355, 165]
];
signs.forEach(([x, y], i) => {
if (i % 3 === 0) {
ctx.beginPath();
ctx.moveTo(x - 20, y + 24);
ctx.lineTo(x, y - 26);
ctx.lineTo(x + 20, y + 24);
ctx.closePath();
ctx.fill();
ctx.fillRect(x - 4, y - 28, 8, 56);
} else if (i % 3 === 1) {
ctx.fillRect(x - 5, y - 30, 10, 60);
for (let j = 0; j < 3; j++) {
ctx.beginPath();
ctx.moveTo(x, y - 18 + j * 16);
ctx.lineTo(x + 23, y - 8 + j * 16);
ctx.lineTo(x, y + 2 + j * 16);
ctx.closePath();
ctx.fill();
}
} else {
ctx.beginPath();
ctx.arc(x, y, 22, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#c59b64";
ctx.beginPath();
ctx.arc(x, y, 8, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#604126";
}
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// -----------------------------------------------------------------------
// Courtyard floor
// -----------------------------------------------------------------------
const floorGeometry = new THREE.PlaneGeometry(19, 16, 18, 15);
floorGeometry.rotateX(-Math.PI / 2);
const floorPositions = floorGeometry.attributes.position;
for (let i = 0; i < floorPositions.count; i++) {
floorPositions.setY(i, range(-0.025, 0.025));
}
floorGeometry.computeVertexNormals();
const floor = addMesh(floorGeometry, materials.earth);
floor.receiveShadow = true;
floor.castShadow = false;
const wovenTexture = createWovenTexture();
const sackMat = addMesh(
new THREE.PlaneGeometry(6.8, 5.2),
standard(0xffffff, { map: wovenTexture }),
-3.5,
0.025,
-1.55
);
sackMat.rotation.x = -Math.PI / 2;
sackMat.castShadow = false;
const recordMat = addMesh(
new THREE.PlaneGeometry(4.2, 3.4),
standard(0xffffff, { map: wovenTexture }),
4.3,
0.028,
-1.35
);
recordMat.rotation.x = -Math.PI / 2;
recordMat.castShadow = false;
// -----------------------------------------------------------------------
// Mud-brick courtyard walls
// -----------------------------------------------------------------------
function brickWallX(x1, x2, z, height = 3.25) {
const rows = 4;
const rowHeight = height / rows;
const choices = [materials.wall, materials.wallLight, materials.wallDark];
for (let row = 0; row < rows; row++) {
let x = x1;
while (x < x2) {
const length = Math.min(range(1.0, 1.55), x2 - x);
const material = choices[Math.floor(random() * choices.length)];
const brick = box(
Math.max(0.1, length - 0.045),
rowHeight - 0.045,
0.42,
material,
x + length / 2,
row * rowHeight + rowHeight / 2,
z
);
brick.rotation.z = range(-0.006, 0.006);
x += length;
}
}
}
function brickWallZ(z1, z2, x, height = 3.25) {
const rows = 4;
const rowHeight = height / rows;
const choices = [materials.wall, materials.wallLight, materials.wallDark];
for (let row = 0; row < rows; row++) {
let z = z1;
while (z < z2) {
const length = Math.min(range(1.0, 1.55), z2 - z);
const material = choices[Math.floor(random() * choices.length)];
const brick = box(
0.42,
rowHeight - 0.045,
Math.max(0.1, length - 0.045),
material,
x,
row * rowHeight + rowHeight / 2,
z + length / 2
);
brick.rotation.x = range(-0.006, 0.006);
z += length;
}
}
}
// Back wall, leaving a store entrance at x = -3.4 to -1.0.
brickWallX(-8.3, -3.4, -6.35);
brickWallX(-1.0, 8.3, -6.35);
brickWallZ(-6.3, 5.8, -8.35);
brickWallZ(-6.3, 5.8, 8.35);
// Low front returns leave the courtyard open to the camera.
brickWallX(-8.3, -6.7, 5.85, 1.1);
brickWallX(6.7, 8.3, 5.85, 1.1);
// Dark recess beyond the doorway.
box(2.38, 2.85, 0.15, standard(0x49352a), -2.2, 1.425, -6.63);
box(2.75, 0.22, 0.58, materials.wood, -2.2, 2.98, -6.27);
box(0.20, 2.85, 0.52, materials.wood, -3.43, 1.43, -6.28);
box(0.20, 2.85, 0.52, materials.wood, -0.97, 1.43, -6.28);
// A modest reed canopy marks the store area.
const canopy = new THREE.Group();
scene.add(canopy);
box(6.8, 0.16, 2.7, materials.reed, -4.6, 3.08, -4.62, canopy);
box(0.18, 2.9, 0.18, materials.wood, -7.65, 1.45, -3.35, canopy);
box(0.18, 2.9, 0.18, materials.wood, -1.55, 1.45, -3.35, canopy);
box(6.35, 0.16, 0.18, materials.wood, -4.6, 2.84, -3.35, canopy);
for (let i = 0; i < 14; i++) {
box(
range(0.06, 0.12),
0.05,
2.78,
i % 2 ? materials.woodLight : materials.reed,
-7.75 + i * 0.48,
3.19,
-4.62,
canopy
);
}
// Wall plaque with stylized grain/account symbols.
box(1.65, 0.92, 0.08, materials.wood, 1.0, 2.05, -6.08);
const plaque = addMesh(
new THREE.PlaneGeometry(1.5, 0.78),
standard(0xffffff, { map: createPlaqueTexture() }),
1.0,
2.05,
-6.025
);
plaque.castShadow = false;
// -----------------------------------------------------------------------
// Sacks, baskets, grain, jars and other courtyard goods
// -----------------------------------------------------------------------
const sackProfile = [
new THREE.Vector2(0.08, -0.58),
new THREE.Vector2(0.38, -0.55),
new THREE.Vector2(0.52, -0.30),
new THREE.Vector2(0.55, 0.05),
new THREE.Vector2(0.48, 0.35),
new THREE.Vector2(0.30, 0.53),
new THREE.Vector2(0.18, 0.57),
new THREE.Vector2(0.16, 0.64),
new THREE.Vector2(0.08, 0.65)
];
const sackGeometry = new THREE.LatheGeometry(sackProfile, 9);
const ropeGeometry = new THREE.CylinderGeometry(0.17, 0.20, 0.10, 8);
const knotGeometry = new THREE.DodecahedronGeometry(0.095, 0);
function addSack(x, z, scale = 1, rotation = 0, horizontal = false, material = materials.sack) {
const outer = new THREE.Group();
outer.position.set(x, horizontal ? 0.49 : 0, z);
outer.rotation.y = rotation;
outer.scale.setScalar(scale);
scene.add(outer);
const laid = new THREE.Group();
if (horizontal) laid.rotation.z = Math.PI / 2;
outer.add(laid);
addMesh(sackGeometry, material, 0, 0.62, 0, laid);
addMesh(ropeGeometry, materials.reed, 0, 1.22, 0, laid);
addMesh(knotGeometry, materials.reed, 0, 1.30, 0, laid);
return outer;
}
const sackMaterials = [materials.sack, materials.sackLight, materials.sackDark];
addSack(-6.3, -3.4, 1.05, 0.18, false, sackMaterials[0]);
addSack(-5.2, -3.55, 1.18, -0.25, false, sackMaterials[1]);
addSack(-4.05, -3.35, 0.98, 0.42, false, sackMaterials[2]);
addSack(-6.45, -2.1, 0.92, -0.3, true, sackMaterials[1]);
addSack(-5.35, -2.15, 1.03, 0.5, true, sackMaterials[0]);
addSack(-4.15, -2.2, 0.88, -0.4, true, sackMaterials[2]);
addSack(-3.0, -3.2, 1.1, 0.12, false, sackMaterials[1]);
addSack(-1.95, -3.4, 0.88, -0.5, false, sackMaterials[0]);
addSack(-6.6, -0.8, 1.02, 0.5, false, sackMaterials[2]);
addSack(-5.5, -0.55, 1.1, -0.18, false, sackMaterials[0]);
addSack(-4.45, -0.72, 0.88, 0.28, false, sackMaterials[1]);
addSack(-3.35, -0.65, 1.08, -0.32, false, sackMaterials[2]);
addSack(-2.3, -0.85, 0.9, 0.52, false, sackMaterials[0]);
addSack(-5.75, 0.55, 0.92, 0.2, true, sackMaterials[1]);
addSack(-4.75, 0.6, 1.0, -0.4, true, sackMaterials[2]);
addSack(-3.65, 0.48, 0.86, 0.3, true, sackMaterials[0]);
const basketProfile = [
new THREE.Vector2(0.28, 0.04),
new THREE.Vector2(0.48, 0.06),
new THREE.Vector2(0.62, 0.40),
new THREE.Vector2(0.69, 0.51),
new THREE.Vector2(0.64, 0.53),
new THREE.Vector2(0.56, 0.40),
new THREE.Vector2(0.43, 0.13),
new THREE.Vector2(0.28, 0.07)
];
const basketGeometry = new THREE.LatheGeometry(basketProfile, 12);
function addBasket(x, z, scale = 1, filled = true) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addMesh(basketGeometry, materials.basket, 0, 0, 0, group);
const rim = addMesh(
new THREE.TorusGeometry(0.65, 0.035, 6, 14),
materials.woodLight,
0,
0.52,
0,
group
);
rim.rotation.x = Math.PI / 2;
if (filled) {
addMesh(
new THREE.CylinderGeometry(0.55, 0.48, 0.055, 12),
materials.grain,
0,
0.39,
0,
group
);
}
return group;
}
addBasket(-2.65, 1.65, 1.15, true);
addBasket(-4.15, 1.55, 0.82, false);
addBasket(-0.65, 2.25, 0.9, true);
// Loose mound of grain.
const grainMound = addMesh(
new THREE.ConeGeometry(1.05, 0.42, 13),
materials.grain,
-2.7,
0.22,
1.65
);
grainMound.scale.z = 0.75;
addMesh(
new THREE.DodecahedronGeometry(0.22, 0),
materials.grainLight,
-2.65,
0.42,
1.62
);
// Ceramic measuring bowls.
function addMeasure(x, z, scale = 1) {
const profile = [
new THREE.Vector2(0.16, 0),
new THREE.Vector2(0.24, 0.04),
new THREE.Vector2(0.39, 0.23),
new THREE.Vector2(0.43, 0.30),
new THREE.Vector2(0.38, 0.31),
new THREE.Vector2(0.33, 0.22),
new THREE.Vector2(0.19, 0.06)
];
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addMesh(new THREE.LatheGeometry(profile, 10), materials.clay, 0, 0, 0, group);
addMesh(
new THREE.CylinderGeometry(0.31, 0.25, 0.035, 10),
materials.grain,
0,
0.17,
0,
group
);
return group;
}
addMeasure(0.0, 2.35, 0.8);
addMeasure(0.72, 2.65, 0.66);
// Storage jars.
const jarProfile = [
new THREE.Vector2(0.12, 0),
new THREE.Vector2(0.32, 0.08),
new THREE.Vector2(0.51, 0.36),
new THREE.Vector2(0.47, 0.72),
new THREE.Vector2(0.29, 0.92),
new THREE.Vector2(0.20, 1.04),
new THREE.Vector2(0.23, 1.17),
new THREE.Vector2(0.19, 1.19)
];
const jarGeometry = new THREE.LatheGeometry(jarProfile, 11);
function addJar(x, z, scale = 1, material = materials.clay) {
const jar = addMesh(jarGeometry, material, x, 0, z);
jar.scale.setScalar(scale);
const band = addMesh(
new THREE.TorusGeometry(0.215 * scale, 0.025 * scale, 5, 12),
materials.wood,
x,
1.09 * scale,
z
);
band.rotation.x = Math.PI / 2;
return jar;
}
addJar(7.1, 2.35, 1.0, materials.clay);
addJar(6.25, 3.25, 0.72, materials.clayLight);
addJar(-7.0, 3.2, 0.68, materials.clay);
// Reed bundles leaning in a corner.
for (let i = 0; i < 10; i++) {
const x = -7.2 + i * 0.045;
const z = 4.0 + range(-0.15, 0.15);
cylinderBetween(
[x, 0.05, z],
[x + range(-0.35, 0.35), range(1.4, 1.9), z - range(0.1, 0.4)],
0.025,
materials.reed
);
}
// -----------------------------------------------------------------------
// Balance scale and measured portions
// -----------------------------------------------------------------------
const scaleGroup = new THREE.Group();
scaleGroup.position.set(1.6, 0, 1.65);
scene.add(scaleGroup);
box(1.15, 0.13, 0.65, materials.wood, 0, 0.10, 0, scaleGroup);
cylinderBetween([0, 0.1, 0], [0, 2.0, 0], 0.075, materials.wood, scaleGroup);
box(2.2, 0.10, 0.10, materials.woodLight, 0, 1.96, 0, scaleGroup);
function addScalePan(x, filled) {
cylinderBetween([x, 1.92, 0], [x, 1.18, 0], 0.012, materials.reed, scaleGroup, 5);
cylinderBetween([x, 1.92, 0], [x, 1.18, 0], 0.012, materials.reed, scaleGroup, 5);
const pan = addMesh(
basketGeometry,
materials.basket,
x,
0.68,
0,
scaleGroup
);
pan.scale.set(0.56, 0.55, 0.56);
if (filled) {
addMesh(
new THREE.CylinderGeometry(0.32, 0.27, 0.05, 10),
materials.grain,
x,
0.88,
0,
scaleGroup
);
}
}
addScalePan(-0.88, true);
addScalePan(0.88, false);
// A small work table for portions.
const measureTable = new THREE.Group();
measureTable.position.set(-0.05, 0, 3.25);
scene.add(measureTable);
box(1.75, 0.13, 0.85, materials.woodLight, 0, 0.74, 0, measureTable);
box(0.12, 0.68, 0.12, materials.wood, -0.68, 0.37, -0.28, measureTable);
box(0.12, 0.68, 0.12, materials.wood, 0.68, 0.37, -0.28, measureTable);
box(0.12, 0.68, 0.12, materials.wood, -0.68, 0.37, 0.28, measureTable);
box(0.12, 0.68, 0.12, materials.wood, 0.68, 0.37, 0.28, measureTable);
addMesh(
new THREE.CylinderGeometry(0.24, 0.18, 0.28, 10),
materials.clayLight,
-0.35,
0.94,
0,
measureTable
);
// Wooden scoop.
const scoop = new THREE.Group();
scoop.position.set(0.43, 0.86, 0.05);
scoop.rotation.y = -0.5;
measureTable.add(scoop);
addMesh(
new THREE.SphereGeometry(0.19, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2),
materials.woodLight,
0,
0,
0,
scoop
);
box(0.72, 0.055, 0.07, materials.wood, 0.3, 0.015, 0, scoop);
// -----------------------------------------------------------------------
// Record keeper's table and ledger
// -----------------------------------------------------------------------
const desk = new THREE.Group();
desk.position.set(4.3, 0, -1.42);
scene.add(desk);
box(2.5, 0.14, 1.55, materials.woodLight, 0, 1.02, 0, desk);
box(0.15, 0.96, 0.15, materials.wood, -1.0, 0.5, -0.55, desk);
box(0.15, 0.96, 0.15, materials.wood, 1.0, 0.5, -0.55, desk);
box(0.15, 0.96, 0.15, materials.wood, -1.0, 0.5, 0.55, desk);
box(0.15, 0.96, 0.15, materials.wood, 1.0, 0.5, 0.55, desk);
box(1.8, 0.08, 1.02, materials.wood, -0.15, 1.13, 0, desk);
const ledger = addMesh(
new THREE.PlaneGeometry(1.65, 0.94),
standard(0xffffff, { map: createLedgerTexture() }),
-0.15,
1.177,
0,
desk
);
ledger.rotation.x = -Math.PI / 2;
ledger.castShadow = false;
// Clay tokens on the ledger and in a sorting tray.
const tokenGeometry = new THREE.CylinderGeometry(0.075, 0.075, 0.035, 10);
const tokenMaterials = [materials.clay, materials.charcoal, materials.clayLight];
for (let i = 0; i < 7; i++) {
const token = addMesh(
tokenGeometry,
tokenMaterials[i % 3],
-0.78 + i * 0.21,
1.205,
-0.25 + (i % 2) * 0.18,
desk
);
token.rotation.y = range(0, Math.PI);
}
box(1.0, 0.10, 0.72, materials.wood, 1.35, 1.17, 0.05, desk);
box(0.86, 0.05, 0.58, materials.woodDark || materials.charcoal, 1.35, 1.23, 0.05, desk);
for (let i = 0; i < 12; i++) {
const token = addMesh(
tokenGeometry,
tokenMaterials[(i + 1) % 3],
1.02 + (i % 4) * 0.22,
1.27,
-0.15 + Math.floor(i / 4) * 0.20,
desk
);
token.rotation.y = range(0, Math.PI);
}
// A stylus, reed pen and sealing jar.
cylinderBetween(
[-0.95, 1.22, 0.48],
[-0.45, 1.22, 0.62],
0.016,
materials.reed,
desk,
6
);
addMesh(
new THREE.CylinderGeometry(0.14, 0.16, 0.25, 9),
materials.clay,
-0.95,
1.25,
-0.48,
desk
);
// -----------------------------------------------------------------------
// Low-poly record keeper
// -----------------------------------------------------------------------
const keeper = new THREE.Group();
keeper.position.set(4.3, 0, -2.72);
scene.add(keeper);
// Stool.
box(0.85, 0.13, 0.7, materials.wood, 0, 0.66, -0.18, keeper);
box(0.12, 0.62, 0.12, materials.wood, -0.3, 0.33, -0.35, keeper);
box(0.12, 0.62, 0.12, materials.wood, 0.3, 0.33, -0.35, keeper);
// Seated robe and torso.
addMesh(
new THREE.ConeGeometry(0.56, 0.9, 8),
materials.robe,
0,
0.63,
0.05,
keeper
);
addMesh(
new THREE.CylinderGeometry(0.34, 0.42, 0.62, 8),
materials.robeDark,
0,
1.13,
0,
keeper
);
addMesh(
new THREE.TorusGeometry(0.34, 0.055, 5, 12),
materials.reed,
0,
0.91,
0,
keeper
).rotation.x = Math.PI / 2;
// Head, hair, nose and eyes.
addMesh(
new THREE.DodecahedronGeometry(0.285, 1),
materials.skin,
0,
1.65,
0.02,
keeper
);
addMesh(
new THREE.CylinderGeometry(0.285, 0.31, 0.18, 9),
materials.hair,
0,
1.83,
-0.01,
keeper
);
const nose = addMesh(
new THREE.ConeGeometry(0.065, 0.18, 5),
materials.skin,
0,
1.64,
0.30,
keeper
);
nose.rotation.x = Math.PI / 2;
addMesh(
new THREE.SphereGeometry(0.026, 6, 4),
materials.black,
-0.095,
1.72,
0.255,
keeper
);
addMesh(
new THREE.SphereGeometry(0.026, 6, 4),
materials.black,
0.095,
1.72,
0.255,
keeper
);
// Arms pointing toward the ledger.
cylinderBetween(
[-0.31, 1.32, 0.02],
[-0.57, 1.12, 0.73],
0.105,
materials.robe,
keeper
);
cylinderBetween(
[-0.57, 1.12, 0.73],
[-0.45, 1.12, 1.03],
0.085,
materials.skin,
keeper
);
addMesh(
new THREE.SphereGeometry(0.10, 7, 5),
materials.skin,
-0.45,
1.12,
1.03,
keeper
);
cylinderBetween(
[0.31, 1.32, 0.02],
[0.48, 1.17, 0.62],
0.105,
materials.robe,
keeper
);
cylinderBetween(
[0.48, 1.17, 0.62],
[0.44, 1.13, 0.95],
0.085,
materials.skin,
keeper
);
// Hand-held clay token, gently lifted toward the ledger.
const tallyHand = new THREE.Group();
tallyHand.position.set(0.44, 1.13, 0.95);
keeper.add(tallyHand);
addMesh(
new THREE.SphereGeometry(0.10, 7, 5),
materials.skin,
0,
0,
0,
tallyHand
);
addMesh(
tokenGeometry,
materials.clay,
0,
0.105,
0.02,
tallyHand
);
// -----------------------------------------------------------------------
// Loose grains and stones
// -----------------------------------------------------------------------
const grainGeometry = new THREE.DodecahedronGeometry(0.035, 0);
const grainCount = 150;
const scatteredGrains = new THREE.InstancedMesh(
grainGeometry,
materials.grainLight,
grainCount
);
scatteredGrains.castShadow = true;
scatteredGrains.receiveShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < grainCount; i++) {
const angle = range(0, Math.PI * 2);
const radius = Math.sqrt(random()) * 1.25;
dummy.position.set(
-2.65 + Math.cos(angle) * radius,
0.035 + random() * 0.04,
1.65 + Math.sin(angle) * radius * 0.72
);
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
dummy.scale.setScalar(range(0.7, 1.25));
dummy.updateMatrix();
scatteredGrains.setMatrixAt(i, dummy.matrix);
}
scene.add(scatteredGrains);
const stoneGeometry = new THREE.DodecahedronGeometry(0.13, 0);
for (let i = 0; i < 42; i++) {
const stone = addMesh(
stoneGeometry,
i % 3 ? materials.wallDark : materials.wall,
range(-8.0, 8.0),
0.07,
range(-5.8, 5.7)
);
stone.scale.set(
range(0.5, 1.5),
range(0.25, 0.65),
range(0.5, 1.3)
);
stone.rotation.set(range(0, 3), range(0, 3), range(0, 3));
}
// -----------------------------------------------------------------------
// Suspended dust motes
// -----------------------------------------------------------------------
const dustCount = 150;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = range(-9, 9);
dustPositions[i * 3 + 1] = range(0.4, 5.8);
dustPositions[i * 3 + 2] = range(-6, 6);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffe0a2,
size: 0.035,
transparent: true,
opacity: 0.36,
depthWrite: false
})
);
scene.add(dust);
// -----------------------------------------------------------------------
// Custom camera controls — no external control modules
// -----------------------------------------------------------------------
const desired = {
target: new THREE.Vector3(-0.5, 1.0, 0),
radius: 18.5,
theta: 0.48,
phi: 0.85
};
const current = {
target: desired.target.clone(),
radius: desired.radius,
theta: desired.theta,
phi: desired.phi
};
const views = {
courtyard: {
target: new THREE.Vector3(-0.5, 1.0, 0),
radius: 18.5,
theta: 0.48,
phi: 0.85
},
sacks: {
target: new THREE.Vector3(-3.4, 1.0, -1.7),
radius: 9.6,
theta: 0.28,
phi: 0.84
},
scale: {
target: new THREE.Vector3(0.7, 0.9, 1.8),
radius: 6.8,
theta: 0.40,
phi: 0.86
},
keeper: {
target: new THREE.Vector3(4.25, 1.05, -1.65),
radius: 6.5,
theta: 0.23,
phi: 0.91
}
};
const pointerMap = new Map();
let previousPinchDistance = 0;
let previousPinchCenter = { x: 0, y: 0 };
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function panCamera(dx, dy) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const amount = desired.radius * 0.00145;
desired.target.addScaledVector(right, -dx * amount);
desired.target.addScaledVector(up, dy * amount);
desired.target.x = clamp(desired.target.x, -7.5, 7.5);
desired.target.y = clamp(desired.target.y, 0.35, 3.2);
desired.target.z = clamp(desired.target.z, -5.8, 5.8);
}
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
previousPinchCenter = {
x: (points[0].x + points[1].x) / 2,
y: (points[0].y + points[1].y) / 2
};
}
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointerMap.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 1) {
if (event.shiftKey || event.buttons === 2) {
panCamera(dx, dy);
} else {
desired.theta -= dx * 0.0052;
desired.phi = clamp(desired.phi + dy * 0.0045, 0.30, 1.34);
}
} else if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
const center = {
x: (points[0].x + points[1].x) / 2,
y: (points[0].y + points[1].y) / 2
};
if (previousPinchDistance > 0) {
desired.radius = clamp(
desired.radius * (previousPinchDistance / Math.max(distance, 1)),
4.8,
30
);
panCamera(
center.x - previousPinchCenter.x,
center.y - previousPinchCenter.y
);
}
previousPinchDistance = distance;
previousPinchCenter = center;
}
});
function releasePointer(event) {
pointerMap.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desired.radius = clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
4.8,
30
);
},
{ passive: false }
);
function setView(name) {
const view = views[name];
if (!view) return;
desired.target.copy(view.target);
desired.radius = view.radius;
desired.theta = view.theta;
desired.phi = view.phi;
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (key === "1") setView("courtyard");
if (key === "2") setView("sacks");
if (key === "3") setView("scale");
if (key === "4") setView("keeper");
if (key === "r") setView("courtyard");
});
// -----------------------------------------------------------------------
// Resize and animation
// -----------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const smoothing = 0.085;
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.radius += (desired.radius - current.radius) * smoothing;
current.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
dust.rotation.y = elapsed * 0.012;
dust.position.y = Math.sin(elapsed * 0.28) * 0.08;
tallyHand.position.y = 1.13 + Math.sin(elapsed * 1.5) * 0.018;
tallyHand.rotation.y = Math.sin(elapsed * 0.8) * 0.08;
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```