Prompt specification
Build or customize the Three.js 3D scene "Scholarly courtyard with copying and discussion" 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: Scholarly courtyard with copying and discussion
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/scholarly-courtyard-with-copying-and-discussion-x2327
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: Scholarly courtyard with copying and discussion. Build a modest historically informed Baghdad courtyard linking book storage, copying, and collaborative discussion. Avoid asserting a precise layout for an institution whose reconstruction is uncertain.
Working Three.js Starter (scholarly-courtyard-with-copying-and-discussion-x2327):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Courtyard of the Pen — Interpretive Baghdad</title>
<style>
:root {
color-scheme: light;
--ink: #30271f;
--paper: rgba(250, 244, 226, 0.91);
--accent: #176b73;
--line: rgba(48, 39, 31, 0.24);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9c8a4;
font-family: Georgia, "Times New Roman", serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#title-card {
position: fixed;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
background: var(--paper);
border: 1px solid var(--line);
border-radius: 4px;
box-shadow: 0 12px 35px rgba(60, 43, 25, 0.14);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3.3vw, 36px);
line-height: 1.04;
font-weight: 500;
letter-spacing: -0.025em;
}
#title-card p:last-child {
margin: 10px 0 0;
font: 12px/1.52 Arial, sans-serif;
color: rgba(48, 39, 31, 0.76);
}
#toolbar {
position: fixed;
top: 22px;
right: 22px;
display: flex;
gap: 7px;
}
button {
appearance: none;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
color: var(--ink);
font: 600 11px/1 Arial, sans-serif;
letter-spacing: 0.03em;
cursor: pointer;
box-shadow: 0 5px 18px rgba(60, 43, 25, 0.1);
}
button:hover {
background: #fffaf0;
}
button[aria-pressed="false"] {
opacity: 0.58;
}
#hint {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(48, 39, 31, 0.15);
border-radius: 3px;
background: rgba(250, 244, 226, 0.84);
color: rgba(48, 39, 31, 0.75);
font: 11px/1.2 Arial, sans-serif;
white-space: nowrap;
pointer-events: none;
}
.marker {
position: fixed;
left: 0;
top: 0;
z-index: 3;
padding: 6px 9px;
border: 1px solid rgba(48, 39, 31, 0.25);
border-radius: 2px;
background: rgba(250, 244, 226, 0.92);
box-shadow: 0 5px 15px rgba(60, 43, 25, 0.12);
font: 700 10px/1 Arial, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, calc(-100% - 16px));
transition: opacity 140ms ease;
}
.marker::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: rgba(48, 39, 31, 0.45);
}
.marker::before {
content: "";
position: absolute;
left: calc(50% - 3px);
top: calc(100% + 13px);
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 3px rgba(250, 244, 226, 0.75);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 10;
background: #d9c8a4;
font: 600 12px/1 Arial, sans-serif;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
@media (max-width: 700px) {
#title-card {
top: 12px;
left: 12px;
width: min(320px, calc(100vw - 24px));
padding: 13px 14px;
}
#title-card p:last-child {
font-size: 11px;
}
#toolbar {
top: auto;
right: 12px;
bottom: 54px;
flex-direction: column;
}
#hint {
bottom: 12px;
font-size: 10px;
}
.marker {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive low-poly scholarly courtyard in Baghdad"></canvas>
<section id="title-card">
<p class="eyebrow">Historically informed interpretive vignette</p>
<h1>Courtyard of the Pen</h1>
<p>
A composite Baghdad courtyard linking book storage, manuscript copying, and
discussion. Its furnishings and arrangement are deliberately conjectural,
not a reconstruction of any specific institution.
</p>
</section>
<div id="toolbar">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" type="button" aria-pressed="true">Labels</button>
</div>
<div class="marker" id="marker-storage">Book storage</div>
<div class="marker" id="marker-copying">Copying</div>
<div class="marker" id="marker-discussion">Discussion</div>
<div id="hint">Drag to orbit · Scroll or pinch to zoom · Arrow keys to move</div>
<div id="loading">Opening 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 canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9c8a4);
scene.fog = new THREE.Fog(0xd9c8a4, 31, 68);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemi = new THREE.HemisphereLight(0xf9e7bd, 0x6d6654, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe3ad, 3.1);
sun.position.set(-12, 21, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc4c3, 0.48);
fill.position.set(10, 8, -12);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
flatShading: true,
...options
});
}
const M = {
earth: material(0xa88962),
paving: material(0xc7b18c),
paving2: material(0xbda47f),
paving3: material(0xd0bc99),
plaster: material(0xd8bd88),
plaster2: material(0xc9aa79),
plaster3: material(0xe1caa0),
brick: material(0x9e5d42),
brick2: material(0xb36c4d),
wood: material(0x70452b),
woodLight: material(0x95623b),
woodDark: material(0x4b2f22),
recess: material(0x342b25),
stone: material(0xb9aa90),
stone2: material(0x9e907a),
turquoise: material(0x3c8587),
cobalt: material(0x355b78),
parchment: material(0xe9d6a9),
ink: material(0x241d19),
robeBlue: material(0x526d78),
robeBrown: material(0x82604b),
robeOchre: material(0xb28b51),
robeCream: material(0xcdbb91),
robeGreen: material(0x63765d),
skin: material(0xa87551),
skin2: material(0x7d563d),
leaf: material(0x64764c, { side: THREE.DoubleSide }),
leaf2: material(0x83905b, { side: THREE.DoubleSide }),
palmTrunk: material(0x836447),
pot: material(0xa65f42),
water: material(0x4d9697, {
transparent: true,
opacity: 0.78,
roughness: 0.25,
metalness: 0.08,
depthWrite: false
}),
lamp: material(0xffce78, {
emissive: 0xd48632,
emissiveIntensity: 1.25,
transparent: true,
opacity: 0.86
})
};
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 = 0, y = 0, z = 0, parent = scene) {
const object = mesh(new THREE.BoxGeometry(w, h, d), mat, parent);
object.position.set(x, y, z);
return object;
}
function cylinder(rt, rb, h, segments, mat, x = 0, y = 0, z = 0, parent = scene) {
const object = mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat,
parent
);
object.position.set(x, y, z);
return object;
}
function sphere(radius, mat, x = 0, y = 0, z = 0, parent = scene) {
const object = mesh(
new THREE.SphereGeometry(radius, 9, 6),
mat,
parent
);
object.position.set(x, y, z);
return object;
}
function rod(parent, start, end, radius, mat, segments = 6) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const middle = a.clone().add(b).multiplyScalar(0.5);
const object = cylinder(
radius,
radius,
length,
segments,
mat,
middle.x,
middle.y,
middle.z,
parent
);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
let seed = 8247;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function randomBetween(a, b) {
return a + (b - a) * random();
}
// Courtyard ground and paving.
box(100, 0.18, 100, M.earth, 0, -0.34, 0);
box(21.2, 0.28, 16.8, M.stone2, 0, -0.15, 0);
const tileMaterials = [M.paving, M.paving2, M.paving3];
for (let ix = 0; ix < 9; ix++) {
for (let iz = 0; iz < 7; iz++) {
const mat = tileMaterials[Math.floor(random() * tileMaterials.length)];
box(
1.82,
0.055,
1.82,
mat,
-7.45 + ix * 1.86,
0.005,
-5.58 + iz * 1.86
);
}
}
// Main walls. The south and east sides are visually cut down to reveal the court.
box(19.1, 4.75, 0.48, M.plaster, 0, 2.375, -7.0);
box(0.48, 4.4, 14.45, M.plaster2, -9.0, 2.2, 0);
box(0.48, 1.15, 14.45, M.plaster3, 9.0, 0.575, 0);
// South wall with an entrance gap.
box(1.6, 1.25, 0.48, M.plaster3, -8.35, 0.625, 7.0);
box(13.15, 1.25, 0.48, M.plaster3, 2.65, 0.625, 7.0);
// Brick courses and a restrained turquoise dado.
for (let x = -8.8; x <= 8.8; x += 0.72) {
box(
0.66,
0.22,
0.12,
random() > 0.5 ? M.brick : M.brick2,
x,
0.25,
-6.72
);
}
for (let z = -6.6; z <= 6.6; z += 0.72) {
box(
0.12,
0.22,
0.66,
random() > 0.5 ? M.brick : M.brick2,
-8.72,
0.25,
z
);
}
box(18.7, 0.12, 0.12, M.turquoise, 0, 0.77, -6.71);
box(0.12, 0.12, 13.9, M.turquoise, -8.71, 0.77, 0);
// Wall buttresses and minor irregular plaster panels.
for (const x of [-8.3, -3.0, 3.0, 8.3]) {
box(0.52, 4.85, 0.68, M.plaster2, x, 2.425, -6.88);
box(0.68, 0.18, 0.82, M.plaster3, x, 4.84, -6.88);
}
for (const z of [-6.25, -0.25, 5.9]) {
box(0.68, 4.5, 0.5, M.plaster, -8.86, 2.25, z);
}
// Entrance portal and an open timber door.
box(0.52, 3.25, 0.72, M.plaster2, -7.45, 1.625, 6.9);
box(0.52, 3.25, 0.72, M.plaster2, -4.0, 1.625, 6.9);
box(3.95, 0.4, 0.78, M.plaster3, -5.72, 3.35, 6.9);
const doorHinge = new THREE.Group();
doorHinge.position.set(-7.15, 0, 6.78);
doorHinge.rotation.y = -0.72;
scene.add(doorHinge);
box(1.42, 2.7, 0.13, M.wood, 0.71, 1.35, 0, doorHinge);
for (let i = 0; i < 4; i++) {
box(1.24, 0.055, 0.06, M.woodDark, 0.71, 0.35 + i * 0.65, 0.09, doorHinge);
}
sphere(0.08, M.cobalt, 1.25, 1.35, 0.13, doorHinge);
// Timber arcade along the book wall.
const northPostX = [-7.8, -2.85, 2.85, 7.8];
for (const x of northPostX) {
cylinder(0.16, 0.2, 3.35, 8, M.wood, x, 1.675, -5.62);
cylinder(0.27, 0.27, 0.16, 8, M.woodDark, x, 0.08, -5.62);
box(0.75, 0.14, 0.72, M.woodLight, x, 3.31, -5.62);
}
box(17.1, 0.22, 0.24, M.wood, 0, 3.47, -5.62);
// A light open arcade on the near side suggests the complete enclosure.
for (const z of [-5.6, 0, 5.6]) {
cylinder(0.14, 0.18, 2.75, 8, M.wood, 8.2, 1.375, z);
box(0.65, 0.13, 0.65, M.woodLight, 8.2, 2.77, z);
}
box(0.22, 0.2, 12.0, M.wood, 8.2, 2.86, 0);
for (let z = -5.4; z <= 5.4; z += 1.2) {
box(1.05, 0.1, 0.16, M.woodDark, 8.55, 2.94, z);
}
// Pointed niche panels.
function archPanel(parent, width = 3.45, height = 3.72) {
const shape = new THREE.Shape();
shape.moveTo(-width / 2, 0);
shape.lineTo(width / 2, 0);
shape.lineTo(width / 2, height * 0.57);
shape.quadraticCurveTo(width * 0.33, height * 0.86, 0, height);
shape.quadraticCurveTo(-width * 0.33, height * 0.86, -width / 2, height * 0.57);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.075,
bevelEnabled: false,
curveSegments: 5
});
const panel = mesh(geometry, M.recess, parent);
panel.position.y = 0.52;
return panel;
}
function archTrim(parent, width = 3.55, height = 3.82) {
const spring = 0.52 + height * 0.57;
const points = [
new THREE.Vector3(-width / 2, spring, 0.18),
new THREE.Vector3(-width * 0.34, 0.52 + height * 0.86, 0.18),
new THREE.Vector3(0, 0.52 + height, 0.18),
new THREE.Vector3(width * 0.34, 0.52 + height * 0.86, 0.18),
new THREE.Vector3(width / 2, spring, 0.18)
];
const curve = new THREE.CatmullRomCurve3(points);
mesh(
new THREE.TubeGeometry(curve, 18, 0.075, 5, false),
M.woodLight,
parent
);
box(0.16, spring - 0.52, 0.18, M.woodLight,
-width / 2, (spring + 0.52) / 2, 0.18, parent);
box(0.16, spring - 0.52, 0.18, M.woodLight,
width / 2, (spring + 0.52) / 2, 0.18, parent);
box(0.24, 0.3, 0.2, M.woodDark, 0, 0.52 + height - 0.03, 0.2, parent);
}
const bookColors = [
M.cobalt,
M.turquoise,
M.brick,
M.ochre || M.robeOchre,
M.robeCream,
M.woodLight
];
function bookshelf(parent, width = 2.75) {
const shelf = new THREE.Group();
shelf.position.z = 0.28;
parent.add(shelf);
box(width, 2.75, 0.08, M.woodDark, 0, 1.82, -0.18, shelf);
box(0.13, 2.85, 0.44, M.wood, -width / 2, 1.8, 0, shelf);
box(0.13, 2.85, 0.44, M.wood, width / 2, 1.8, 0, shelf);
const levels = [0.53, 1.28, 2.03, 2.78];
for (const y of levels) {
box(width + 0.1, 0.09, 0.47, M.woodLight, 0, y, 0, shelf);
}
for (let row = 0; row < 3; row++) {
let x = -width / 2 + 0.15;
while (x < width / 2 - 0.2) {
const w = randomBetween(0.11, 0.2);
const h = randomBetween(0.36, 0.57);
const mat = bookColors[Math.floor(random() * bookColors.length)];
box(w, h, 0.25, mat, x + w / 2, levels[row] + 0.05 + h / 2, 0.03, shelf);
box(w * 0.72, h * 0.12, 0.012, M.parchment,
x + w / 2, levels[row] + 0.05 + h * 0.53, 0.16, shelf);
x += w + randomBetween(0.025, 0.055);
}
}
// A few horizontal volumes.
for (let i = 0; i < 3; i++) {
const mat = bookColors[(i + 2) % bookColors.length];
box(0.42, 0.08, 0.27, mat,
-0.65 + i * 0.55, levels[3] + 0.12 + i * 0.09, 0.02, shelf);
}
return shelf;
}
function storageNiche(x, z, rotation = 0) {
const niche = new THREE.Group();
niche.position.set(x, 0, z);
niche.rotation.y = rotation;
scene.add(niche);
archPanel(niche);
archTrim(niche);
bookshelf(niche);
return niche;
}
storageNiche(-5.7, -6.72);
storageNiche(0, -6.72);
storageNiche(5.7, -6.72);
storageNiche(-8.73, -2.4, Math.PI / 2);
storageNiche(-8.73, 2.6, Math.PI / 2);
// Small latticed window high on the west wall.
box(0.09, 1.05, 1.55, M.recess, -8.71, 3.35, -5.35);
for (let z = -6.03; z <= -4.68; z += 0.27) {
box(0.1, 1.0, 0.055, M.wood, -8.61, 3.35, z);
}
for (let y = 2.92; y <= 3.78; y += 0.29) {
box(0.1, 0.055, 1.45, M.wood, -8.6, y, -5.35);
}
// Writing desks.
function writingDesk(parent) {
box(1.42, 0.12, 0.76, M.woodLight, 0, 0.74, 0, parent);
for (const x of [-0.57, 0.57]) {
for (const z of [-0.25, 0.25]) {
box(0.1, 0.68, 0.1, M.woodDark, x, 0.36, z, parent);
}
}
const paper = box(0.66, 0.018, 0.43, M.parchment, -0.12, 0.812, 0.06, parent);
paper.rotation.y = -0.08;
// Suggest lines of writing without external textures.
for (let i = 0; i < 5; i++) {
box(0.38 - random() * 0.1, 0.008, 0.012, M.ink,
-0.18, 0.824, -0.06 + i * 0.058, parent);
}
cylinder(0.075, 0.09, 0.12, 8, M.ink, 0.48, 0.86, 0.13, parent);
rod(parent, [0.48, 0.91, 0.13], [0.55, 1.13, 0.08], 0.012, M.woodLight, 5);
const scroll = cylinder(0.045, 0.045, 0.46, 8,
M.parchment, 0.2, 0.84, -0.2, parent);
scroll.rotation.z = Math.PI / 2;
box(0.37, 0.065, 0.28, M.cobalt, 0.35, 0.825, -0.18, parent);
}
// Stylized seated and standing scholars.
function scholar({
x = 0,
z = 0,
rotation = 0,
robe = M.robeBrown,
skin = M.skin,
gesturing = false,
standing = false,
parent = scene
}) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = rotation;
parent.add(person);
if (standing) {
cylinder(0.24, 0.43, 1.58, 7, robe, 0, 0.79, 0, person);
sphere(0.23, skin, 0, 1.78, 0.01, person);
cylinder(0.245, 0.25, 0.17, 9, M.robeCream, 0, 1.96, 0, person);
const headband = mesh(
new THREE.TorusGeometry(0.21, 0.065, 6, 12),
M.robeCream,
person
);
headband.position.y = 1.94;
headband.rotation.x = Math.PI / 2;
} else {
cylinder(0.29, 0.48, 0.82, 7, robe, 0, 0.72, 0, person);
sphere(0.22, skin, 0, 1.33, 0.01, person);
cylinder(0.235, 0.25, 0.16, 9, M.robeCream, 0, 1.51, 0, person);
const headband = mesh(
new THREE.TorusGeometry(0.205, 0.06, 6, 12),
M.robeCream,
person
);
headband.position.y = 1.49;
headband.rotation.x = Math.PI / 2;
sphere(0.15, robe, -0.18, 0.34, 0.22, person);
sphere(0.15, robe, 0.18, 0.34, 0.22, person);
}
// Face direction is local +Z.
sphere(0.022, M.ink, -0.075, 1.36, 0.205, person);
sphere(0.022, M.ink, 0.075, 1.36, 0.205, person);
sphere(0.05, skin, 0, 1.30, 0.225, person);
const shoulderY = standing ? 1.55 : 1.0;
const leftHand = gesturing
? [-0.67, 1.13, 0.37]
: [-0.34, 0.84, 0.62];
const rightHand = gesturing
? [0.68, 1.18, 0.31]
: [0.34, 0.84, 0.62];
rod(person, [-0.27, shoulderY, 0], [-0.48, shoulderY - 0.2, 0.18],
0.115, robe);
rod(person, [-0.48, shoulderY - 0.2, 0.18], leftHand,
0.09, robe);
sphere(0.085, skin, ...leftHand, person);
rod(person, [0.27, shoulderY, 0], [0.48, shoulderY - 0.2, 0.18],
0.115, robe);
rod(person, [0.48, shoulderY - 0.2, 0.18], rightHand,
0.09, robe);
sphere(0.085, skin, ...rightHand, person);
return person;
}
// Three copyists at low desks.
for (const x of [-5.7, 0, 5.7]) {
const station = new THREE.Group();
station.position.set(x, 0, -4.42);
scene.add(station);
writingDesk(station);
scholar({
x: 0,
z: -0.76,
robe: x === 0 ? M.robeBlue : (x < 0 ? M.robeBrown : M.robeGreen),
skin: x === 0 ? M.skin2 : M.skin,
parent: station
});
}
// A copyist in the shaded west bay.
const westStation = new THREE.Group();
westStation.position.set(-6.95, 0, 2.6);
westStation.rotation.y = Math.PI / 2;
scene.add(westStation);
writingDesk(westStation);
scholar({
x: 0,
z: -0.78,
robe: M.robeOchre,
skin: M.skin2,
parent: westStation
});
// Discussion circle on a woven carpet.
box(4.3, 0.045, 3.45, M.robeBlue, 3.35, 0.06, 1.55);
box(3.95, 0.015, 3.1, M.cobalt, 3.35, 0.091, 1.55);
for (const edge of [-2.1, 2.1]) {
box(0.07, 0.02, 3.35, M.parchment, 3.35 + edge, 0.106, 1.55);
}
box(1.23, 0.09, 0.83, M.woodLight, 3.35, 0.36, 1.55);
box(0.72, 0.018, 0.49, M.parchment, 3.35, 0.416, 1.55);
for (let i = 0; i < 4; i++) {
box(0.55, 0.009, 0.012, M.ink,
3.14, 0.43, 1.4 + i * 0.07);
}
scholar({
x: 2.0,
z: 1.48,
rotation: Math.PI / 2,
robe: M.robeCream,
gesturing: true
});
scholar({
x: 4.72,
z: 1.48,
rotation: -Math.PI / 2,
robe: M.robeBrown,
skin: M.skin2,
gesturing: true
});
scholar({
x: 3.35,
z: 3.28,
rotation: Math.PI,
robe: M.robeGreen,
gesturing: true
});
scholar({
x: 3.35,
z: -0.15,
rotation: 0,
robe: M.robeOchre,
skin: M.skin2,
gesturing: true
});
// Standing reader near the stores.
scholar({
x: 7.15,
z: -4.25,
rotation: -0.55,
robe: M.robeBlue,
standing: true,
gesturing: true
});
// Chests, stacked books, and a basket of scrolls.
function chest(x, z, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
scene.add(g);
box(1.1, 0.57, 0.66, M.wood, 0, 0.31, 0, g);
box(1.17, 0.1, 0.72, M.woodDark, 0, 0.61, 0, g);
for (const xPos of [-0.37, 0.37]) {
box(0.07, 0.56, 0.69, M.cobalt, xPos, 0.32, 0, g);
}
box(0.14, 0.16, 0.04, M.ink, 0, 0.39, 0.35, g);
}
chest(-7.25, -3.45, 0.12);
chest(7.2, -5.4, -0.08);
chest(-4.25, 4.85, 0.05);
for (let i = 0; i < 5; i++) {
box(
0.62 - i * 0.025,
0.075,
0.39,
bookColors[i % bookColors.length],
-3.8 + i * 0.02,
0.085 + i * 0.08,
4.8 + i * 0.015
);
}
const basket = new THREE.Group();
basket.position.set(-7.15, 0, 4.45);
scene.add(basket);
cylinder(0.36, 0.28, 0.45, 8, M.woodLight, 0, 0.23, 0, basket);
const rim = mesh(
new THREE.TorusGeometry(0.34, 0.045, 5, 12),
M.wood,
basket
);
rim.position.y = 0.46;
rim.rotation.x = Math.PI / 2;
for (let i = 0; i < 6; i++) {
const x = randomBetween(-0.15, 0.15);
const z = randomBetween(-0.12, 0.12);
rod(basket,
[x, 0.2, z],
[x + randomBetween(-0.18, 0.18), randomBetween(0.95, 1.22), z + 0.12],
0.035,
M.parchment,
7
);
}
// Shallow stone water basin.
const basin = new THREE.Group();
basin.position.set(-2.25, 0, 0.2);
scene.add(basin);
box(3.05, 0.18, 0.26, M.stone, 0, 0.23, -0.86, basin);
box(3.05, 0.18, 0.26, M.stone, 0, 0.23, 0.86, basin);
box(0.26, 0.18, 1.48, M.stone2, -1.39, 0.23, 0, basin);
box(0.26, 0.18, 1.48, M.stone2, 1.39, 0.23, 0, basin);
box(2.62, 0.08, 1.48, M.stone2, 0, 0.06, 0, basin);
const water = box(2.58, 0.025, 1.42, M.water, 0, 0.18, 0, basin);
water.castShadow = false;
// Low-poly date palm outside the main working court.
const palm = new THREE.Group();
palm.position.set(10.4, 0, -5.8);
scene.add(palm);
const palmSegments = [
[0, 0, 0, 0.15, 1.1, 0.12],
[0.15, 1.1, 0.12, 0.28, 2.2, 0.2],
[0.28, 2.2, 0.2, 0.4, 3.3, 0.28],
[0.4, 3.3, 0.28, 0.48, 4.35, 0.3]
];
for (const [x1, y1, z1, x2, y2, z2] of palmSegments) {
rod(palm, [x1, y1, z1], [x2, y2, z2], 0.16, M.palmTrunk, 7);
}
const fronds = [];
function palmLeafGeometry() {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute([
0, 0, 0,
-0.30, 0.04, 1.0,
0, 0.18, 2.35,
0.30, 0.04, 1.0,
0, -0.08, 0.28
], 3));
geometry.setIndex([
0, 1, 2,
0, 2, 3,
0, 3, 4,
1, 4, 2,
2, 4, 3
]);
geometry.computeVertexNormals();
return geometry;
}
for (let i = 0; i < 8; i++) {
const frond = new THREE.Group();
frond.position.set(0.48, 4.35, 0.3);
frond.rotation.y = i * Math.PI / 4;
frond.rotation.x = 0.18 + randomBetween(-0.05, 0.09);
palm.add(frond);
mesh(palmLeafGeometry(), i % 2 ? M.leaf : M.leaf2, frond);
fronds.push(frond);
}
// Potted citrus tree.
const citrus = new THREE.Group();
citrus.position.set(7.2, 0, 4.95);
scene.add(citrus);
cylinder(0.48, 0.34, 0.72, 8, M.pot, 0, 0.36, 0, citrus);
cylinder(0.51, 0.51, 0.1, 8, M.brick2, 0, 0.73, 0, citrus);
rod(citrus, [0, 0.65, 0], [0.05, 1.75, 0.03], 0.11, M.palmTrunk, 7);
const citrusCrowns = [
[0, 2.05, 0, 0.86],
[-0.48, 1.82, 0.04, 0.58],
[0.45, 1.9, 0.12, 0.61],
[0.02, 2.48, -0.05, 0.58]
];
for (const [x, y, z, s] of citrusCrowns) {
const crown = mesh(
new THREE.IcosahedronGeometry(s, 0),
M.leaf,
citrus
);
crown.position.set(x, y, z);
}
for (let i = 0; i < 7; i++) {
const a = i * Math.PI * 2 / 7;
const fruit = sphere(0.09, M.robeOchre,
Math.cos(a) * 0.55,
1.85 + randomBetween(0, 0.5),
Math.sin(a) * 0.55,
citrus
);
}
// Hanging lanterns.
function lantern(x, y, z) {
const g = new THREE.Group();
g.position.set(x, y, z);
scene.add(g);
rod(g, [0, 0, 0], [0, -0.42, 0], 0.018, M.ink, 5);
cylinder(0.18, 0.25, 0.08, 6, M.woodDark, 0, -0.5, 0, g);
box(0.31, 0.4, 0.31, M.lamp, 0, -0.72, 0, g);
for (const px of [-0.16, 0.16]) {
for (const pz of [-0.16, 0.16]) {
box(0.035, 0.42, 0.035, M.woodDark, px, -0.72, pz, g);
}
}
cylinder(0.25, 0.18, 0.08, 6, M.woodDark, 0, -0.97, 0, g);
const light = new THREE.PointLight(0xffb35c, 6.5, 4.5, 2);
light.position.set(0, -0.72, 0);
g.add(light);
}
lantern(-2.85, 3.24, -5.62);
lantern(8.2, 2.75, 0);
// Low, sparse dust motes.
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(150 * 3);
for (let i = 0; i < 150; i++) {
dustPositions[i * 3] = randomBetween(-10, 10);
dustPositions[i * 3 + 1] = randomBetween(0.5, 5.4);
dustPositions[i * 3 + 2] = randomBetween(-8, 8);
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xfff0c8,
size: 0.035,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
scene.add(dust);
// Manual orbit controls — no examples/addons are used.
const orbit = {
theta: 0.61,
phi: 0.96,
radius: 29.5,
target: new THREE.Vector3(0, 1.05, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetView() {
orbit.theta = 0.61;
orbit.phi = 0.96;
orbit.radius = 29.5;
orbit.target.set(0, 1.05, 0);
}
const pointers = new Map();
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.45, 1.34);
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (pinchDistance / Math.max(distance, 1)),
13,
43
);
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
13,
43
);
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", event => {
const step = 0.08;
if (event.key === "ArrowLeft") orbit.theta += step;
else if (event.key === "ArrowRight") orbit.theta -= step;
else if (event.key === "ArrowUp") orbit.phi = Math.max(0.45, orbit.phi - step);
else if (event.key === "ArrowDown") orbit.phi = Math.min(1.34, orbit.phi + step);
else if (event.key === "+" || event.key === "=") orbit.radius = Math.max(13, orbit.radius - 1);
else if (event.key === "-" || event.key === "_") orbit.radius = Math.min(43, orbit.radius + 1);
else return;
event.preventDefault();
});
document.querySelector("#reset-view").addEventListener("click", resetView);
let labelsVisible = true;
const labels = [
{ element: document.querySelector("#marker-storage"), point: new THREE.Vector3(-5.7, 4.75, -6.35) },
{ element: document.querySelector("#marker-copying"), point: new THREE.Vector3(0, 1.85, -4.25) },
{ element: document.querySelector("#marker-discussion"), point: new THREE.Vector3(3.35, 1.75, 1.55) }
];
document.querySelector("#toggle-labels").addEventListener("click", event => {
labelsVisible = !labelsVisible;
event.currentTarget.setAttribute("aria-pressed", String(labelsVisible));
for (const label of labels) {
label.element.style.display = labelsVisible ? "block" : "none";
}
});
function updateLabels() {
if (!labelsVisible) return;
for (const label of labels) {
const projected = label.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
M.water.opacity = 0.75 + Math.sin(elapsed * 1.2) * 0.035;
water.position.y = 0.18 + Math.sin(elapsed * 0.85) * 0.007;
water.rotation.y = Math.sin(elapsed * 0.18) * 0.012;
dust.rotation.y = elapsed * 0.009;
fronds.forEach((frond, index) => {
frond.rotation.z = Math.sin(elapsed * 0.75 + index) * 0.022;
});
updateCamera();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```