Prompt specification
Build or customize the Three.js 3D scene "Ottoman caravanserai unloading corner" 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: Ottoman caravanserai unloading corner
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ottoman-caravanserai-unloading-corner-x2382
Scene Description Prompt:
Create a cutaway Ottoman caravanserai unloading corner, separating pack-animal routes from the pedestrian gallery. One HTML file using Three.js from cdnjs.
Working Three.js Starter (ottoman-caravanserai-unloading-corner-x2382):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ottoman Caravanserai — Unloading Corner</title>
<style>
:root {
--ink: #182326;
--paper: #f4efe3;
--animal: #d9793f;
--pedestrian: #2d8580;
--line: rgba(24, 35, 38, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfc7b7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-card {
position: fixed;
top: 26px;
left: 28px;
z-index: 10;
width: min(390px, calc(100vw - 56px));
padding: 18px 20px 16px;
background: rgba(247, 243, 233, 0.91);
border: 1px solid rgba(255, 255, 255, 0.72);
border-left: 4px solid #8d4c35;
box-shadow: 0 12px 40px rgba(34, 31, 24, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: #8d4c35;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(23px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
.subtitle {
margin-top: 9px;
color: #536063;
font-size: 12px;
line-height: 1.45;
}
.views {
position: fixed;
top: 26px;
right: 28px;
z-index: 12;
display: flex;
gap: 6px;
padding: 6px;
background: rgba(247, 243, 233, 0.9);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: 0 10px 35px rgba(34, 31, 24, 0.12);
backdrop-filter: blur(12px);
}
.views button {
appearance: none;
border: 0;
padding: 9px 12px;
background: transparent;
color: #435054;
font: 700 10px/1 inherit;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, color 160ms ease;
}
.views button:hover,
.views button.active {
background: var(--ink);
color: #fffaf0;
}
.legend {
position: fixed;
left: 28px;
bottom: 27px;
z-index: 10;
display: grid;
gap: 9px;
min-width: 235px;
padding: 14px 16px;
background: rgba(247, 243, 233, 0.9);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: 0 10px 35px rgba(34, 31, 24, 0.11);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 2px;
color: #6c7473;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 28px;
height: 4px;
flex: none;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.animal { background: var(--animal); }
.swatch.pedestrian { background: var(--pedestrian); }
.swatch.section {
height: 10px;
background:
repeating-linear-gradient(
135deg,
#a6947b 0 2px,
#d5c9b4 2px 5px
);
}
.help {
position: fixed;
right: 28px;
bottom: 28px;
z-index: 10;
padding: 9px 12px;
color: rgba(29, 40, 42, 0.7);
background: rgba(247, 243, 233, 0.72);
border: 1px solid rgba(255, 255, 255, 0.55);
font-size: 10px;
letter-spacing: 0.025em;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 8;
transform: translate(-50%, -100%);
padding: 6px 9px;
background: rgba(250, 247, 239, 0.93);
border: 1px solid rgba(30, 40, 42, 0.16);
border-top: 3px solid #8d4c35;
box-shadow: 0 5px 18px rgba(35, 30, 22, 0.13);
color: #263337;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
opacity: 0;
transition: opacity 120ms ease;
}
.world-label.ped {
border-top-color: var(--pedestrian);
}
.world-label.animal {
border-top-color: var(--animal);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: rgba(30, 40, 42, 0.38);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d8d0c1;
color: #39474a;
font: 700 11px/1.4 inherit;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 13px 15px;
}
.subtitle { display: none; }
.views {
top: auto;
right: 14px;
bottom: 74px;
}
.views button {
padding: 9px 8px;
font-size: 9px;
}
.legend {
left: 14px;
bottom: 14px;
min-width: 205px;
}
.help { display: none; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="title-card">
<div class="eyebrow">Architectural Cutaway · Sequence Study</div>
<h1>Ottoman Caravanserai</h1>
<div class="subtitle">
Unloading corner with the pack-animal court physically separated from the elevated pedestrian gallery.
</div>
</header>
<nav class="views" aria-label="Camera views">
<button class="active" data-view="overview">Overview</button>
<button data-view="animals">Animal court</button>
<button data-view="gallery">Gallery</button>
</nav>
<section class="legend" aria-label="Drawing legend">
<div class="legend-title">Movement & section</div>
<div class="legend-row">
<span class="swatch animal"></span>
Pack-animal unloading route
</div>
<div class="legend-row">
<span class="swatch pedestrian"></span>
Pedestrian gallery route
</div>
<div class="legend-row">
<span class="swatch section"></span>
Exposed cut face
</div>
</section>
<div class="help">Drag to orbit · Wheel to zoom · Shift/right-drag to pan</div>
<div id="label-animal" class="world-label animal">Pack-animal route</div>
<div id="label-gallery" class="world-label ped">Pedestrian gallery</div>
<div id="label-unload" class="world-label">Unloading bay</div>
<div id="label-gate" class="world-label">Caravanserai gate</div>
<div id="loading">Constructing the caravanserai…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd5cdbd);
scene.fog = new THREE.Fog(0xd5cdbd, 45, 88);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemisphere = new THREE.HemisphereLight(0xf9efd7, 0x66706b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d5, 3.6);
sun.position.set(-14, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00018;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9c7d1, 0.75);
fill.position.set(14, 9, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Procedural textures — no external image assets
// -------------------------------------------------------------------------
function makeTexture(draw, size = 512, repeatX = 1, repeatY = 1) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = size;
const ctx = canvas.getContext("2d");
draw(ctx, size);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeatX, repeatY);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const pavingTexture = makeTexture((ctx, s) => {
ctx.fillStyle = "#a99e89";
ctx.fillRect(0, 0, s, s);
const rows = 8;
const rowH = s / rows;
for (let row = 0; row < rows; row++) {
const offset = row % 2 ? -s / 12 : 0;
const cols = 6;
for (let col = -1; col <= cols; col++) {
const x = col * (s / cols) + offset + 3;
const y = row * rowH + 3;
const w = s / cols - 6;
const h = rowH - 6;
const shade = 164 + Math.floor(Math.random() * 22);
ctx.fillStyle = `rgb(${shade + 12}, ${shade + 5}, ${shade - 9})`;
ctx.fillRect(x, y, w, h);
ctx.strokeStyle = "rgba(78,70,58,.25)";
ctx.strokeRect(x + 0.5, y + 0.5, w - 1, h - 1);
}
}
for (let i = 0; i < 1400; i++) {
ctx.fillStyle = Math.random() > 0.5
? "rgba(255,255,255,.035)"
: "rgba(45,38,30,.035)";
ctx.fillRect(
Math.random() * s,
Math.random() * s,
1 + Math.random() * 2,
1 + Math.random() * 2
);
}
}, 512, 5, 3.4);
const stoneTexture = makeTexture((ctx, s) => {
ctx.fillStyle = "#c8b896";
ctx.fillRect(0, 0, s, s);
for (let i = 0; i < 3400; i++) {
const a = 0.018 + Math.random() * 0.06;
ctx.fillStyle = Math.random() > 0.5
? `rgba(255,248,225,${a})`
: `rgba(74,59,42,${a})`;
const size = 1 + Math.random() * 4;
ctx.fillRect(Math.random() * s, Math.random() * s, size, size);
}
}, 256, 2.2, 1.4);
const roofTexture = makeTexture((ctx, s) => {
ctx.fillStyle = "#9e4931";
ctx.fillRect(0, 0, s, s);
const cols = 8;
const rows = 12;
const cw = s / cols;
const rh = s / rows;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const x = col * cw;
const y = row * rh;
const g = ctx.createLinearGradient(x, 0, x + cw, 0);
g.addColorStop(0, "#713326");
g.addColorStop(0.22, "#bd6241");
g.addColorStop(0.55, "#a64f35");
g.addColorStop(1, "#713326");
ctx.fillStyle = g;
ctx.fillRect(x + 1, y + 1, cw - 2, rh - 2);
}
}
ctx.strokeStyle = "rgba(65,29,20,.55)";
ctx.lineWidth = 3;
for (let row = 0; row <= rows; row++) {
ctx.beginPath();
ctx.moveTo(0, row * rh);
ctx.lineTo(s, row * rh);
ctx.stroke();
}
}, 512, 2.3, 4.8);
const stripeTexture = makeTexture((ctx, s) => {
const bands = 10;
const bw = s / bands;
for (let i = 0; i < bands; i++) {
ctx.fillStyle = i % 2 ? "#e9dcc0" : "#b65e3d";
ctx.fillRect(i * bw, 0, bw, s);
}
ctx.fillStyle = "rgba(75,46,31,.09)";
for (let y = 0; y < s; y += 5) {
ctx.fillRect(0, y, s, 1);
}
}, 256, 2, 1);
const hatchTexture = makeTexture((ctx, s) => {
ctx.fillStyle = "#d8cbb2";
ctx.fillRect(0, 0, s, s);
ctx.strokeStyle = "rgba(78,64,47,.52)";
ctx.lineWidth = 3;
for (let x = -s; x < s * 2; x += 18) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x + s, s);
ctx.stroke();
}
}, 128, 2, 4);
const materials = {
paving: new THREE.MeshStandardMaterial({
map: pavingTexture,
roughness: 0.94
}),
stone: new THREE.MeshStandardMaterial({
map: stoneTexture,
color: 0xf2dfb8,
roughness: 0.92
}),
paleStone: new THREE.MeshStandardMaterial({
color: 0xd8c7a3,
roughness: 0.9
}),
trim: new THREE.MeshStandardMaterial({
color: 0x947253,
roughness: 0.86
}),
darkStone: new THREE.MeshStandardMaterial({
color: 0x74634d,
roughness: 0.94
}),
wood: new THREE.MeshStandardMaterial({
color: 0x765039,
roughness: 0.88
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x39291f,
roughness: 0.92
}),
roof: new THREE.MeshStandardMaterial({
map: roofTexture,
color: 0xf0b08b,
roughness: 0.86,
side: THREE.DoubleSide
}),
cut: new THREE.MeshStandardMaterial({
map: hatchTexture,
roughness: 0.95
}),
dark: new THREE.MeshStandardMaterial({
color: 0x25241f,
roughness: 1
}),
animalRoute: new THREE.MeshStandardMaterial({
color: 0xd9793f,
emissive: 0x4a1d08,
emissiveIntensity: 0.18,
roughness: 0.8
}),
pedestrianRoute: new THREE.MeshStandardMaterial({
color: 0x2d8580,
emissive: 0x092e2d,
emissiveIntensity: 0.2,
roughness: 0.8
}),
teal: new THREE.MeshStandardMaterial({
color: 0x327c78,
roughness: 0.72
}),
red: new THREE.MeshStandardMaterial({
color: 0x9c4635,
roughness: 0.83
}),
cream: new THREE.MeshStandardMaterial({
color: 0xead9b9,
roughness: 0.93
}),
straw: new THREE.MeshStandardMaterial({
color: 0xb79a61,
roughness: 1
}),
water: new THREE.MeshStandardMaterial({
color: 0x4d9d9a,
roughness: 0.22,
metalness: 0.1,
transparent: true,
opacity: 0.84
}),
canvas: new THREE.MeshStandardMaterial({
map: stripeTexture,
roughness: 0.95,
side: THREE.DoubleSide
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const unitSphere = new THREE.SphereGeometry(1, 16, 12);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = addMesh(unitBox, material, parent);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
return mesh;
}
function ellipsoid(rx, ry, rz, material, x, y, z, parent = scene) {
const mesh = addMesh(unitSphere, material, parent);
mesh.scale.set(rx, ry, rz);
mesh.position.set(x, y, z);
return mesh;
}
function cylinderBetween(
start,
end,
radius,
material,
parent = scene,
radialSegments = 9
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius * 1.04, length, radialSegments),
material,
parent
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function addPointedHole(shape, cx, width, spring, top, bottom = 0) {
const hole = new THREE.Path();
const half = width / 2;
hole.moveTo(cx - half, bottom);
hole.lineTo(cx - half, spring);
hole.quadraticCurveTo(cx - half, spring, cx, top);
hole.quadraticCurveTo(cx + half, top, cx + half, spring);
hole.lineTo(cx + half, bottom);
hole.closePath();
shape.holes.push(hole);
}
function pointedArchBand(
innerWidth,
spring,
innerTop,
band,
depth,
material
) {
const shape = new THREE.Shape();
const innerHalf = innerWidth / 2;
const outerHalf = innerHalf + band;
const outerTop = innerTop + band * 0.85;
shape.moveTo(-outerHalf, spring);
shape.quadraticCurveTo(-outerHalf, spring, 0, outerTop);
shape.quadraticCurveTo(outerHalf, outerTop, outerHalf, spring);
shape.lineTo(innerHalf, spring);
shape.quadraticCurveTo(innerHalf, innerTop, 0, innerTop);
shape.quadraticCurveTo(-innerHalf, spring, -innerHalf, spring);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: 18
});
geometry.translate(0, 0, -depth / 2);
return addMesh(geometry, material);
}
function solidPointedArch(width, spring, top, depth, material) {
const shape = new THREE.Shape();
const half = width / 2;
shape.moveTo(-half, 0);
shape.lineTo(-half, spring);
shape.quadraticCurveTo(-half, spring, 0, top);
shape.quadraticCurveTo(half, top, half, spring);
shape.lineTo(half, 0);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: 18
});
geometry.translate(0, 0, -depth / 2);
return addMesh(geometry, material);
}
function arrowMesh(material) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.25, 0, -0.28,
0.25, 0, -0.28,
0, 0, 0.38
], 3)
);
geometry.computeVertexNormals();
const mesh = addMesh(geometry, material);
mesh.castShadow = false;
mesh.receiveShadow = false;
return mesh;
}
// -------------------------------------------------------------------------
// Presentation base and pavement
// -------------------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({ color: 0xcac2b2, roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.76;
ground.castShadow = false;
box(25.4, 0.72, 21.5, materials.darkStone, 0, -0.38, 0);
const courtyardFloor = addMesh(
new THREE.PlaneGeometry(24, 16.2),
materials.paving
);
courtyardFloor.rotation.x = -Math.PI / 2;
courtyardFloor.position.set(0, 0.015, 0);
courtyardFloor.castShadow = false;
const outsideLane = addMesh(
new THREE.PlaneGeometry(3.8, 4.1),
materials.paving
);
outsideLane.rotation.x = -Math.PI / 2;
outsideLane.position.set(-5.4, 0.02, -9.45);
outsideLane.castShadow = false;
// Thin bronze edging indicates the removed portion of the enclosure.
box(24.1, 0.045, 0.055, materials.trim, 0, 0.04, 8.12);
box(0.055, 0.045, 16.2, materials.trim, -11.72, 0.04, 0);
// -------------------------------------------------------------------------
// Back wall with pointed gate and high window
// -------------------------------------------------------------------------
const backShape = new THREE.Shape();
backShape.moveTo(-11.8, 0);
backShape.lineTo(11.8, 0);
backShape.lineTo(11.8, 5.75);
backShape.lineTo(-11.8, 5.75);
backShape.closePath();
addPointedHole(backShape, -5.4, 3.2, 2.62, 5.02, -0.04);
addPointedHole(backShape, 6.55, 1.15, 3.0, 4.18, 1.55);
const backGeometry = new THREE.ExtrudeGeometry(backShape, {
depth: 0.7,
bevelEnabled: false,
curveSegments: 20
});
backGeometry.translate(0, 0, -0.35);
const backWall = addMesh(backGeometry, materials.stone);
backWall.position.z = -8.1;
box(24.1, 0.22, 0.88, materials.trim, 0, 5.86, -8.1);
// Dark recess behind the gateway.
box(3.18, 5.0, 0.08, materials.dark, -5.4, 2.5, -8.5);
box(1.14, 2.6, 0.08, materials.dark, 6.55, 2.86, -8.5);
// Portal arch and jambs.
const gateArch = pointedArchBand(
3.2, 2.62, 5.02, 0.34, 0.24, materials.trim
);
gateArch.position.set(-5.4, 0, -7.68);
box(0.34, 2.62, 0.24, materials.trim, -7.17, 1.31, -7.68);
box(0.34, 2.62, 0.24, materials.trim, -3.63, 1.31, -7.68);
box(0.46, 0.66, 0.3, materials.paleStone, -5.4, 5.08, -7.68);
// Colored wall panels around the entrance.
box(1.15, 1.7, 0.08, materials.teal, -8.45, 2.15, -7.70);
box(1.15, 1.7, 0.08, materials.red, -2.35, 2.15, -7.70);
box(1.3, 0.12, 0.12, materials.paleStone, -8.45, 3.05, -7.64);
box(1.3, 0.12, 0.12, materials.paleStone, -2.35, 3.05, -7.64);
// -------------------------------------------------------------------------
// Right-hand outer wall and exposed cut face
// -------------------------------------------------------------------------
box(0.68, 5.65, 16.55, materials.stone, 11.0, 2.825, -0.05);
box(0.88, 0.22, 16.75, materials.trim, 11.0, 5.74, -0.05);
box(0.69, 5.65, 0.055, materials.cut, 11.0, 2.825, 8.26);
// Short remnants of the removed front and left enclosure.
box(0.65, 1.8, 1.55, materials.stone, -11.7, 0.9, -7.1);
box(0.66, 1.8, 0.055, materials.cut, -11.7, 0.9, -6.31);
box(4.6, 0.48, 0.6, materials.stone, -9.2, 0.24, 8.15);
// -------------------------------------------------------------------------
// Roof fragments: outer gallery roof and narrow rear eave
// -------------------------------------------------------------------------
function roofPatch(vertices, indices, uvs) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return addMesh(geometry, materials.roof);
}
roofPatch(
[
7.72, 5.58, -8.30,
11.25, 6.18, -8.30,
11.25, 6.18, 8.20,
7.72, 5.58, 8.20
],
[0, 2, 1, 0, 3, 2],
[0, 0, 1, 0, 1, 4, 0, 4]
);
roofPatch(
[
-11.8, 5.84, -8.38,
11.8, 5.84, -8.38,
11.8, 6.20, -6.52,
-11.8, 6.20, -6.52
],
[0, 2, 1, 0, 3, 2],
[0, 0, 1, 0, 1, 2.4, 0, 2.4]
);
box(0.18, 0.26, 16.6, materials.darkWood, 7.72, 5.52, -0.05);
box(23.7, 0.16, 0.18, materials.darkWood, 0, 5.79, -6.54);
// -------------------------------------------------------------------------
// Raised pedestrian gallery and its pointed arcade
// -------------------------------------------------------------------------
box(4.45, 0.35, 16.1, materials.paleStone, 8.74, 0.175, -0.02);
// Continuous low screen: the architectural separation from the animal court.
box(0.24, 0.58, 14.75, materials.trim, 6.42, 0.29, -0.05);
const arcadeZ = [-7, -3.5, 0, 3.5, 7];
const bayCenters = [-5.25, -1.75, 1.75, 5.25];
for (const z of arcadeZ) {
const column = new THREE.Group();
column.position.set(6.66, 0.35, z);
scene.add(column);
box(0.72, 0.22, 0.72, materials.trim, 0, 0.11, 0, column);
box(0.56, 0.15, 0.56, materials.paleStone, 0, 0.29, 0, column);
const shaft = addMesh(
new THREE.CylinderGeometry(0.23, 0.25, 2.34, 12),
materials.paleStone,
column
);
shaft.position.y = 1.53;
const capital = addMesh(
new THREE.CylinderGeometry(0.37, 0.28, 0.28, 12),
materials.trim,
column
);
capital.position.y = 2.82;
box(0.63, 0.16, 0.63, materials.paleStone, 0, 3.0, 0, column);
}
for (const z of bayCenters) {
const arch = pointedArchBand(
3.5, 2.78, 4.28, 0.25, 0.28, materials.trim
);
arch.position.set(6.66, 0.35, z);
arch.rotation.y = -Math.PI / 2;
const keystone = box(
0.39, 0.48, 0.32,
materials.paleStone,
0, 4.39, 0.15,
arch
);
}
// Door and recessed windows in the outer gallery wall.
box(0.09, 2.45, 1.42, materials.darkWood, 10.62, 1.58, 5.28);
box(0.13, 0.12, 1.62, materials.trim, 10.58, 2.84, 5.28);
box(0.13, 0.12, 1.62, materials.trim, 10.58, 0.38, 5.28);
for (const z of [-4.0, 1.35]) {
const windowPanel = solidPointedArch(
1.2, 1.8, 2.75, 0.05, materials.dark
);
windowPanel.rotation.y = -Math.PI / 2;
windowPanel.position.set(10.61, 1.25, z);
}
// Gallery access stairs at the cutaway edge.
box(2.25, 0.15, 0.58, materials.paleStone, 8.2, 0.075, 8.87);
box(2.25, 0.30, 0.58, materials.paleStone, 8.2, 0.15, 8.38);
box(2.25, 0.45, 0.58, materials.paleStone, 8.2, 0.225, 7.89);
// -------------------------------------------------------------------------
// Movement routes
// -------------------------------------------------------------------------
// Pack-animal lane: gate → unloading bay → side stall.
box(0.13, 0.022, 10.8, materials.animalRoute, -5.4, 0.035, -1.8);
box(4.6, 0.022, 0.13, materials.animalRoute, -7.55, 0.036, 3.45);
// Pedestrian route stays on the raised gallery.
box(0.12, 0.022, 13.9, materials.pedestrianRoute, 8.25, 0.37, -0.25);
box(0.12, 0.022, 1.0, materials.pedestrianRoute, 8.25, 0.18, 8.37);
const routeArrows = [];
for (const z of [-6.3, -3.6, -0.8, 1.8]) {
const arrow = arrowMesh(materials.animalRoute.clone());
arrow.position.set(-5.4, 0.064, z);
routeArrows.push(arrow);
}
for (const x of [-6.5, -8.2]) {
const arrow = arrowMesh(materials.animalRoute.clone());
arrow.position.set(x, 0.065, 3.45);
arrow.rotation.y = -Math.PI / 2;
routeArrows.push(arrow);
}
for (const z of [-5.6, -2.0, 1.6, 5.2]) {
const arrow = arrowMesh(materials.pedestrianRoute.clone());
arrow.position.set(8.25, 0.398, z);
routeArrows.push(arrow);
}
// -------------------------------------------------------------------------
// Unloading bay: timber deck, posts, partial striped awning, and freight
// -------------------------------------------------------------------------
box(4.6, 0.16, 3.45, materials.wood, -7.25, 0.08, 3.75);
for (let i = 0; i < 12; i++) {
const x = -9.46 + i * 0.405;
box(0.035, 0.025, 3.4, materials.darkWood, x, 0.172, 3.75);
}
for (const x of [-9.45, -5.05]) {
for (const z of [2.12, 5.38]) {
box(0.17, 3.1, 0.17, materials.darkWood, x, 1.55, z);
}
}
box(4.7, 0.2, 0.2, materials.darkWood, -7.25, 3.08, 2.12);
box(4.7, 0.2, 0.2, materials.darkWood, -7.25, 3.08, 5.38);
box(0.2, 0.2, 3.45, materials.darkWood, -9.45, 3.08, 3.75);
box(0.2, 0.2, 3.45, materials.darkWood, -5.05, 3.08, 3.75);
// Only the rear half of the awning remains, preserving the cutaway reading.
const awning = addMesh(new THREE.PlaneGeometry(4.85, 1.42), materials.canvas);
awning.rotation.x = -Math.PI / 2;
awning.position.set(-7.25, 3.22, 2.78);
const rolledCanvas = addMesh(
new THREE.CylinderGeometry(0.17, 0.17, 4.75, 12),
materials.cream
);
rolledCanvas.rotation.z = Math.PI / 2;
rolledCanvas.position.set(-7.25, 3.23, 3.48);
function makeCrate(parent, x, y, z, size = 0.72) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
box(size, size, size, materials.wood, 0, size / 2, 0, group);
for (const side of [-1, 1]) {
box(size + 0.025, 0.075, 0.065, materials.darkWood, 0, size * 0.25, side * size / 2, group);
box(size + 0.025, 0.075, 0.065, materials.darkWood, 0, size * 0.75, side * size / 2, group);
box(0.065, size + 0.025, 0.075, materials.darkWood, side * size / 2, size / 2, size / 2, group);
box(0.065, size + 0.025, 0.075, materials.darkWood, side * size / 2, size / 2, -size / 2, group);
}
return group;
}
function makeSack(parent, x, y, z, scale = 1, material = materials.cream) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
ellipsoid(0.34, 0.43, 0.31, material, 0, 0.4, 0, group);
ellipsoid(0.14, 0.12, 0.13, material, 0, 0.77, 0, group);
const tie = addMesh(
new THREE.CylinderGeometry(0.105, 0.12, 0.08, 10),
materials.red,
group
);
tie.position.y = 0.79;
return group;
}
function makeBarrel(parent, x, y, z, material = materials.wood) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const barrel = addMesh(
new THREE.CylinderGeometry(0.35, 0.31, 0.82, 14),
material,
group
);
barrel.position.y = 0.41;
for (const height of [0.18, 0.63]) {
const ring = addMesh(
new THREE.TorusGeometry(0.345, 0.025, 6, 18),
materials.darkWood,
group
);
ring.rotation.x = Math.PI / 2;
ring.position.y = height;
}
return group;
}
makeCrate(scene, -8.95, 0.17, 4.45, 0.82);
makeCrate(scene, -8.95, 0.99, 4.45, 0.66);
makeCrate(scene, -7.95, 0.17, 4.72, 0.7);
makeCrate(scene, -6.85, 0.17, 4.72, 0.62);
makeSack(scene, -8.45, 0.17, 3.25, 1.05);
makeSack(scene, -7.8, 0.17, 3.05, 0.92, materials.straw);
makeBarrel(scene, -6.15, 0.17, 4.75);
// Rolled carpets beside the loading area.
for (let i = 0; i < 3; i++) {
const carpet = addMesh(
new THREE.CylinderGeometry(0.17, 0.17, 1.75, 14),
i === 1 ? materials.teal : materials.red
);
carpet.rotation.z = Math.PI / 2;
carpet.position.set(-8.75 + i * 0.22, 0.38 + i * 0.29, 5.55);
}
// -------------------------------------------------------------------------
// Central courtyard fountain
// -------------------------------------------------------------------------
const fountain = new THREE.Group();
fountain.position.set(0.65, 0, -1.25);
scene.add(fountain);
const basin = addMesh(
new THREE.CylinderGeometry(1.28, 1.36, 0.46, 8),
materials.paleStone,
fountain
);
basin.position.y = 0.23;
const water = addMesh(
new THREE.CylinderGeometry(1.05, 1.05, 0.035, 32),
materials.water,
fountain
);
water.position.y = 0.47;
water.castShadow = false;
cylinderBetween([0, 0.45, 0], [0, 1.78, 0], 0.18, materials.trim, fountain);
const bowl = addMesh(
new THREE.CylinderGeometry(0.64, 0.28, 0.22, 12),
materials.paleStone,
fountain
);
bowl.position.y = 1.72;
cylinderBetween([0, 1.78, 0], [0, 2.3, 0], 0.11, materials.trim, fountain);
const upperBowl = addMesh(
new THREE.CylinderGeometry(0.4, 0.18, 0.18, 12),
materials.paleStone,
fountain
);
upperBowl.position.y = 2.25;
// -------------------------------------------------------------------------
// Cypress and a small pot
// -------------------------------------------------------------------------
const pot = addMesh(
new THREE.CylinderGeometry(0.42, 0.32, 0.55, 12),
materials.red
);
pot.position.set(4.7, 0.28, 5.35);
const cypress = addMesh(
new THREE.ConeGeometry(0.68, 3.55, 12),
new THREE.MeshStandardMaterial({ color: 0x3c5a43, roughness: 1 })
);
cypress.position.set(4.7, 2.08, 5.35);
// -------------------------------------------------------------------------
// Gate lantern
// -------------------------------------------------------------------------
cylinderBetween(
[-3.02, 3.65, -7.68],
[-3.02, 2.98, -7.68],
0.025,
materials.darkWood
);
const lantern = addMesh(
new THREE.CylinderGeometry(0.16, 0.21, 0.37, 8),
new THREE.MeshStandardMaterial({
color: 0xe6a952,
emissive: 0xd67b20,
emissiveIntensity: 1.6,
roughness: 0.55
})
);
lantern.position.set(-3.02, 2.73, -7.68);
const lampLight = new THREE.PointLight(0xffb65e, 15, 7, 2);
lampLight.position.set(-3.02, 2.65, -7.15);
scene.add(lampLight);
// -------------------------------------------------------------------------
// Pack animals
// -------------------------------------------------------------------------
const hideMaterials = [
new THREE.MeshStandardMaterial({ color: 0x6f5140, roughness: 0.94 }),
new THREE.MeshStandardMaterial({ color: 0x8b8172, roughness: 0.96 }),
new THREE.MeshStandardMaterial({ color: 0x4e433d, roughness: 0.97 })
];
const muzzleMaterial = new THREE.MeshStandardMaterial({
color: 0x342c29,
roughness: 0.95
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x11110f,
roughness: 0.35
});
function createMule(position, rotationY, hideMaterial, blanketMaterial) {
const animal = new THREE.Group();
animal.position.set(...position);
animal.rotation.y = rotationY;
scene.add(animal);
// Body and chest.
ellipsoid(0.56, 0.62, 1.08, hideMaterial, 0, 1.08, 0, animal);
ellipsoid(0.51, 0.57, 0.42, hideMaterial, 0, 1.13, 0.72, animal);
ellipsoid(0.52, 0.55, 0.38, hideMaterial, 0, 1.08, -0.73, animal);
// Neck and head.
cylinderBetween(
[0, 1.24, 0.67],
[0, 1.88, 1.03],
0.28,
hideMaterial,
animal,
12
);
ellipsoid(0.33, 0.34, 0.48, hideMaterial, 0, 1.93, 1.23, animal);
ellipsoid(0.29, 0.24, 0.28, muzzleMaterial, 0, 1.77, 1.56, animal);
// Long ears.
for (const side of [-1, 1]) {
const ear = addMesh(
new THREE.ConeGeometry(0.12, 0.48, 8),
hideMaterial,
animal
);
ear.position.set(side * 0.17, 2.28, 1.12);
ear.rotation.z = side * -0.15;
ear.rotation.x = -0.18;
}
// Eyes.
for (const side of [-1, 1]) {
ellipsoid(
0.042, 0.048, 0.035,
eyeMaterial,
side * 0.25, 2.0, 1.53,
animal
);
}
// Four legs with angled joints.
for (const side of [-1, 1]) {
for (const z of [-0.67, 0.63]) {
const x = side * 0.35;
cylinderBetween(
[x, 0.94, z],
[x + side * 0.055, 0.45, z + (z > 0 ? 0.06 : -0.04)],
0.095,
hideMaterial,
animal,
8
);
cylinderBetween(
[x + side * 0.055, 0.45, z + (z > 0 ? 0.06 : -0.04)],
[x + side * 0.065, 0.09, z + (z > 0 ? 0.08 : -0.05)],
0.072,
hideMaterial,
animal,
8
);
box(
0.19, 0.13, 0.25,
muzzleMaterial,
x + side * 0.065,
0.065,
z + (z > 0 ? 0.08 : -0.05),
animal
);
}
}
// Tail.
cylinderBetween(
[0, 1.17, -1.02],
[0.05, 0.62, -1.14],
0.045,
hideMaterial,
animal,
7
);
ellipsoid(0.085, 0.22, 0.08, muzzleMaterial, 0.05, 0.53, -1.15, animal);
// Saddle blanket, side packs, and straps.
box(0.92, 0.08, 1.08, blanketMaterial, 0, 1.68, -0.03, animal);
box(0.38, 0.58, 0.74, materials.wood, -0.68, 1.22, -0.05, animal);
box(0.38, 0.58, 0.74, materials.wood, 0.68, 1.22, -0.05, animal);
for (const z of [-0.53, 0.47]) {
const strap = addMesh(
new THREE.TorusGeometry(0.61, 0.027, 6, 24),
materials.darkWood,
animal
);
strap.scale.y = 0.94;
strap.position.set(0, 1.14, z);
}
// Pack ropes and small tassels.
const ropeMaterial = new THREE.MeshStandardMaterial({
color: 0xb59b65,
roughness: 1
});
for (const side of [-1, 1]) {
cylinderBetween(
[side * 0.58, 1.55, -0.55],
[side * 0.68, 0.92, -0.62],
0.018,
ropeMaterial,
animal,
6
);
}
return animal;
}
createMule([-5.4, 0, -5.55], 0, hideMaterials[0], materials.red);
createMule([-5.45, 0, -1.15], 0.04, hideMaterials[1], materials.teal);
createMule([-6.35, 0, 4.15], 0.24, hideMaterials[2], materials.red);
// A handler leads the animal at the unloading bay.
const leadRope = cylinderBetween(
[-4.78, 1.95, 3.52],
[-5.9, 1.8, 3.63],
0.018,
new THREE.MeshStandardMaterial({ color: 0xb69a62, roughness: 1 }),
scene,
6
);
// -------------------------------------------------------------------------
// Human figures
// -------------------------------------------------------------------------
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xb9825c,
roughness: 0.95
});
const turbanMaterial = new THREE.MeshStandardMaterial({
color: 0xe8ddc8,
roughness: 1
});
function createPerson(position, robeMaterial, scale = 1, rotationY = 0) {
const person = new THREE.Group();
person.position.set(...position);
person.rotation.y = rotationY;
person.scale.setScalar(scale);
scene.add(person);
const robe = addMesh(
new THREE.CylinderGeometry(0.22, 0.36, 0.9, 9),
robeMaterial,
person
);
robe.position.y = 0.46;
ellipsoid(0.19, 0.23, 0.17, skinMaterial, 0, 1.09, 0, person);
const turban = ellipsoid(
0.225, 0.15, 0.205,
turbanMaterial,
0, 1.25, 0,
person
);
cylinderBetween(
[-0.19, 0.83, 0],
[-0.3, 0.44, 0.08],
0.065,
robeMaterial,
person,
7
);
cylinderBetween(
[0.19, 0.83, 0],
[0.3, 0.48, 0.05],
0.065,
robeMaterial,
person,
7
);
return person;
}
// Animal handlers remain in the working court.
createPerson([-4.25, 0, 3.55], materials.teal, 1.03, -0.35);
createPerson([-8.7, 0, 5.82], materials.red, 0.98, 0.2);
// Pedestrians remain on the elevated gallery.
createPerson([8.45, 0.35, -4.25], materials.red, 0.95, Math.PI);
createPerson([8.75, 0.35, 1.55], materials.teal, 0.9, Math.PI);
createPerson([8.42, 0.35, 5.95], materials.cream, 0.82, Math.PI);
// Gallery parcels and a woven chest.
makeCrate(scene, 9.25, 0.35, -2.75, 0.58);
makeSack(scene, 9.25, 0.35, -3.75, 0.8, materials.straw);
makeBarrel(scene, 9.3, 0.35, 3.95, materials.darkWood);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch pinch
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.35, 0),
radius: 39,
theta: -0.72,
phi: 1.02
};
const cameraGoal = {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
};
function setCameraView(view) {
const views = {
overview: {
target: [0, 1.35, 0],
radius: 39,
theta: -0.72,
phi: 1.02
},
animals: {
target: [-5.1, 1.05, -0.2],
radius: 26,
theta: -0.62,
phi: 1.13
},
gallery: {
target: [7.9, 1.65, 0.15],
radius: 21.5,
theta: -0.48,
phi: 1.16
}
};
const selected = views[view];
if (!selected) return;
cameraGoal.target.set(...selected.target);
cameraGoal.radius = selected.radius;
cameraGoal.theta = selected.theta;
cameraGoal.phi = selected.phi;
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === view);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setCameraView(button.dataset.view));
});
const pointers = new Map();
let panMode = false;
let lastPinchDistance = 0;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button,
shift: event.shiftKey
});
panMode = event.button === 2 || event.shiftKey;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius * lastPinchDistance / distance,
11,
62
);
}
lastPinchDistance = distance;
return;
}
if (panMode || previous.shift) {
const right = new THREE.Vector3(
Math.cos(cameraGoal.theta),
0,
-Math.sin(cameraGoal.theta)
);
const forward = new THREE.Vector3(
-Math.sin(cameraGoal.theta),
0,
-Math.cos(cameraGoal.theta)
);
const scale = cameraGoal.radius * 0.00115;
const shift = right.multiplyScalar(-dx * scale)
.add(forward.multiplyScalar(-dy * scale));
cameraGoal.target.add(shift);
cameraState.target.add(shift);
} else {
cameraGoal.theta -= dx * 0.006;
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi - dy * 0.005,
0.28,
1.42
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
panMode = false;
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius * Math.exp(event.deltaY * 0.001),
11,
62
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-animal"),
position: new THREE.Vector3(-5.4, 0.7, -2.65)
},
{
element: document.getElementById("label-gallery"),
position: new THREE.Vector3(8.25, 1.15, -1.65)
},
{
element: document.getElementById("label-unload"),
position: new THREE.Vector3(-7.1, 3.72, 4.75)
},
{
element: document.getElementById("label-gate"),
position: new THREE.Vector3(-5.4, 5.35, -7.58)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "1";
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const damping = 1 - Math.exp(-7 * Math.min(clock.getDelta(), 0.05));
cameraState.target.lerp(cameraGoal.target, damping);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraGoal.radius,
damping
);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraGoal.theta,
damping
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraGoal.phi,
damping
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
// Gentle route-arrow pulse helps distinguish the circulation paths.
routeArrows.forEach((arrow, index) => {
arrow.material.opacity = 0.72 + Math.sin(elapsed * 2.1 + index * 0.65) * 0.2;
arrow.material.transparent = true;
});
updateLabels();
renderer.render(scene, camera);
}
setCameraView("overview");
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```