Prompt specification
Build or customize the Three.js 3D scene "Mason and carpenter sharing a work bay" 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: Mason and carpenter sharing a work bay
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mason-and-carpenter-sharing-a-work-bay-x2346
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a Gothic church construction workshop. Create a historically informed building-yard vignette with stone shaping and timber centering preparation. Show separate work zones whose parts fit the same small arch opening. Low-poly.
Working Three.js Starter (mason-and-carpenter-sharing-a-work-bay-x2346):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Gothic Building Yard</title>
<style>
:root {
--ink: #252823;
--paper: rgba(244, 239, 224, 0.92);
--line: rgba(45, 48, 40, 0.22);
--gold: #b57932;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bac4c1;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 48%, rgba(35, 40, 34, 0.23) 120%),
linear-gradient(to bottom, rgba(255, 241, 204, 0.08), transparent 25%);
z-index: 2;
}
#panel {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(370px, calc(100vw - 44px));
padding: 18px 19px 16px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.48);
box-shadow: 0 12px 38px rgba(30, 35, 29, 0.2);
backdrop-filter: blur(8px);
}
#panel .eyebrow {
margin-bottom: 6px;
color: #80602f;
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.2em;
text-transform: uppercase;
}
#panel h1 {
margin: 0;
font-size: clamp(23px, 3vw, 32px);
font-weight: 500;
line-height: 1.02;
}
#panel p {
margin: 10px 0 14px;
max-width: 32em;
font: 12px/1.5 Arial, sans-serif;
color: rgba(37, 40, 35, 0.76);
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
button {
appearance: none;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.36);
color: var(--ink);
padding: 7px 9px;
cursor: pointer;
font: 700 10px/1 Arial, sans-serif;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: background 150ms, color 150ms, transform 150ms;
}
button:hover {
background: rgba(255, 255, 255, 0.85);
transform: translateY(-1px);
}
button.active {
color: #f9f1df;
background: #45483f;
border-color: #45483f;
}
#hint {
position: fixed;
right: 18px;
bottom: 16px;
z-index: 10;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.3);
background: rgba(35, 40, 35, 0.64);
color: #f2ecdc;
font: 10px/1.45 Arial, sans-serif;
letter-spacing: 0.035em;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 5;
pointer-events: none;
transform: translate(-50%, -100%);
padding: 6px 8px;
background: rgba(242, 235, 216, 0.9);
border-left: 3px solid var(--gold);
box-shadow: 0 5px 15px rgba(24, 30, 25, 0.16);
white-space: nowrap;
transition: opacity 150ms;
}
.world-label strong {
display: block;
font: 700 10px/1.1 Arial, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label span {
display: block;
margin-top: 3px;
color: rgba(35, 40, 35, 0.68);
font: 10px/1.2 Arial, sans-serif;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 19px;
background: rgba(72, 60, 38, 0.65);
}
#labels.hidden { opacity: 0; }
@media (max-width: 650px) {
#panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
#panel p { display: none; }
#panel h1 { font-size: 22px; }
#hint { display: none; }
.world-label span { display: none; }
}
</style>
</head>
<body>
<div id="vignette"></div>
<section id="panel">
<div class="eyebrow">Building-yard study · c. 1350</div>
<h1>The Gothic Building Yard</h1>
<p>
One limestone arch module is being prepared in three coordinated trades:
stone shaping, timber centering, and final assembly at the church wall.
</p>
<div class="buttons">
<button class="active" data-view="overview">Overview</button>
<button data-view="stone">Stone</button>
<button data-view="timber">Centering</button>
<button data-view="assembly">Arch</button>
<button id="toggle-labels">Labels</button>
</div>
</section>
<div id="labels">
<div class="world-label" id="label-stone">
<strong>I · Stone shaping</strong>
<span>Drafted ashlar, mallet and point chisel</span>
</div>
<div class="world-label" id="label-timber">
<strong>II · Centering</strong>
<span>Full-size rib and crown assembly</span>
</div>
<div class="world-label" id="label-assembly">
<strong>III · Assembly</strong>
<span>Voussoirs and laths share the same opening</span>
</div>
</div>
<div id="hint">
Drag: orbit · Right-drag: pan · Wheel/pinch: zoom<br>
Keys 1–4: viewpoints · H: hide labels
</div>
<script type="module">
import * as THREE from
'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
// -------------------------------------------------------------------------
// Renderer and atmosphere
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbec9c5);
scene.fog = new THREE.Fog(0xc4ccc6, 30, 67);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: 'high-performance'
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f0ec, 0x685c49, 1.75);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffd39b, 3.1);
sun.position.set(-10, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb6d0d7, 0.65);
fill.position.set(12, 8, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
let seed = 73421;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...extra
});
}
const materials = {
ground: standard(0x8d826c),
mortar: standard(0x817d70),
limestone: [
standard(0xc9bda0),
standard(0xd1c5a8),
standard(0xbeb195),
standard(0xd8cbaa),
standard(0xb9ad94)
],
timber: standard(0x755033),
timberLight: standard(0x987047),
timberDark: standard(0x4f3827),
rope: standard(0x66543b),
iron: standard(0x3e4240, { roughness: 0.72, metalness: 0.45 }),
linen: standard(0xb7aa8d),
soil: standard(0x756652),
chalk: new THREE.LineBasicMaterial({ color: 0xf3e6c4 }),
stoneDust: standard(0xd7c8a8)
};
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 = 0, y = 0, z = 0, parent = scene) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
material,
x, y, z, parent
);
}
function cylinder(rt, rb, h, segments, material, x = 0, y = 0, z = 0, parent = scene) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material,
x, y, z, parent
);
}
function beamBetween(a, b, width, depth, material, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const middle = start.clone().add(end).multiplyScalar(0.5);
const mesh = box(width, direction.length(), depth, material, 0, 0, 0, parent);
mesh.position.copy(middle);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = scene, segments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const middle = start.clone().add(end).multiplyScalar(0.5);
const mesh = cylinder(
radius, radius, direction.length(), segments, material,
0, 0, 0, parent
);
mesh.position.copy(middle);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function roughStone(w, h, d, material, x, y, z, parent = scene) {
const stone = addMesh(
new THREE.DodecahedronGeometry(0.5, 0),
material,
x, y, z, parent
);
stone.scale.set(w * 1.55, h * 1.35, d * 1.55);
stone.rotation.set(random() * 0.5, random() * Math.PI, random() * 0.35);
return stone;
}
function makeBarrel(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.42, 0.32, 0.92, 10, materials.timber, 0, 0.46, 0, group);
for (const h of [0.17, 0.72]) {
const band = cylinder(0.43, 0.43, 0.055, 10, materials.iron, 0, h, 0, group);
band.scale.z = 1;
}
cylinder(0.32, 0.32, 0.04, 10, materials.timberDark, 0, 0.93, 0, group);
return group;
}
// -------------------------------------------------------------------------
// Yard paving
// -------------------------------------------------------------------------
box(60, 0.14, 60, materials.ground, 0, -0.12, 0);
const pavingGeometry = new THREE.BoxGeometry(1, 0.065, 0.8);
const pavingMaterial = standard(0xffffff);
const paving = new THREE.InstancedMesh(pavingGeometry, pavingMaterial, 238);
const dummy = new THREE.Object3D();
const pavingColors = [
0x8c826e, 0x958a74, 0x807765, 0x9d9077, 0x736d60
];
let pavingIndex = 0;
for (let row = 0; row < 14; row++) {
for (let col = 0; col < 17; col++) {
if (pavingIndex >= 238) break;
dummy.position.set(
-14.8 + col * 1.77 + (row % 2) * 0.35,
-0.025,
-8.6 + row * 1.23
);
dummy.rotation.y = (random() - 0.5) * 0.08;
dummy.scale.set(
0.92 + random() * 0.12,
1,
0.89 + random() * 0.15
);
dummy.updateMatrix();
paving.setMatrixAt(pavingIndex, dummy.matrix);
paving.setColorAt(
pavingIndex,
new THREE.Color(pavingColors[Math.floor(random() * pavingColors.length)])
);
pavingIndex++;
}
}
paving.receiveShadow = true;
scene.add(paving);
// Low boundary wall and scattered spoil.
for (let i = 0; i < 25; i++) {
box(
0.95, 0.68 + (i % 3) * 0.08, 0.65,
materials.limestone[i % materials.limestone.length],
-12 + i, 0.34, -10.6
);
}
for (let i = 0; i < 36; i++) {
const x = -11 + random() * 22;
const z = -1 + random() * 9;
if (Math.abs(x) < 4 && z < 0) continue;
roughStone(
0.14 + random() * 0.22,
0.09 + random() * 0.13,
0.13 + random() * 0.2,
materials.limestone[Math.floor(random() * materials.limestone.length)],
x, 0.07, z
);
}
// -------------------------------------------------------------------------
// Gothic wall and pointed opening
// -------------------------------------------------------------------------
const arch = {
halfWidth: 1.2,
spring: 2.8,
radius: 2.4,
rise: Math.sqrt(3) * 1.2,
get apex() { return this.spring + this.rise; }
};
const openingPolygon = [
new THREE.Vector2(-arch.halfWidth, 0),
new THREE.Vector2(-arch.halfWidth, arch.spring),
new THREE.Vector2(0, arch.apex),
new THREE.Vector2(arch.halfWidth, arch.spring),
new THREE.Vector2(arch.halfWidth, 0)
];
const wallShape = new THREE.Shape();
wallShape.moveTo(-5, 0);
wallShape.lineTo(5, 0);
wallShape.lineTo(5, 6.4);
wallShape.lineTo(-5, 6.4);
wallShape.closePath();
const openingPath = new THREE.Path();
openingPath.moveTo(-arch.halfWidth, 0);
openingPath.lineTo(-arch.halfWidth, arch.spring);
openingPath.lineTo(0, arch.apex);
openingPath.lineTo(arch.halfWidth, arch.spring);
openingPath.lineTo(arch.halfWidth, 0);
openingPath.closePath();
wallShape.holes.push(openingPath);
const wallGeometry = new THREE.ExtrudeGeometry(wallShape, {
depth: 0.65,
bevelEnabled: false,
curveSegments: 1
});
addMesh(wallGeometry, materials.mortar, 0, 0, -4.1);
function convexPolygonIntersectsRect(polygon, x, y, w, h) {
const rect = [
new THREE.Vector2(x - w / 2, y - h / 2),
new THREE.Vector2(x + w / 2, y - h / 2),
new THREE.Vector2(x + w / 2, y + h / 2),
new THREE.Vector2(x - w / 2, y + h / 2)
];
const polygons = [polygon, rect];
for (let p = 0; p < polygons.length; p++) {
const source = polygons[p];
for (let i = 0; i < source.length; i++) {
const a = source[i];
const b = source[(i + 1) % source.length];
const axis = new THREE.Vector2(-(b.y - a.y), b.x - a.x).normalize();
let minA = Infinity, maxA = -Infinity;
let minB = Infinity, maxB = -Infinity;
for (const point of polygon) {
const projection = point.dot(axis);
minA = Math.min(minA, projection);
maxA = Math.max(maxA, projection);
}
for (const point of rect) {
const projection = point.dot(axis);
minB = Math.min(minB, projection);
maxB = Math.max(maxB, projection);
}
if (maxA < minB || maxB < minA) return false;
}
}
return true;
}
for (let row = 0; row < 16; row++) {
const y = 0.2 + row * 0.4;
const offset = row % 2 ? 0.41 : 0;
for (let col = 0; col < 12; col++) {
const x = -4.65 + col * 0.84 + offset;
if (x > 5.2) continue;
const width = 0.79;
if (convexPolygonIntersectsRect(openingPolygon, x, y, width, 0.365)) {
continue;
}
const material = materials.limestone[
Math.floor(random() * materials.limestone.length)
];
box(width, 0.365, 0.16, material, x, y, -3.37);
}
}
// Side returns of the unfinished church.
box(0.65, 5.65, 4.2, materials.mortar, -5, 2.825, -6.05);
box(0.65, 5.65, 4.2, materials.mortar, 5, 2.825, -6.05);
for (const side of [-1, 1]) {
for (let row = 0; row < 14; row++) {
for (let depth = 0; depth < 5; depth++) {
box(
0.72, 0.36, 0.77,
materials.limestone[(row + depth) % materials.limestone.length],
side * 4.68, 0.2 + row * 0.4, -4.3 - depth * 0.82
);
}
}
}
// Front buttresses.
function makeButtress(x) {
const group = new THREE.Group();
group.position.set(x, 0, -3.18);
scene.add(group);
box(1.18, 1.35, 1.02, materials.limestone[1], 0, 0.675, 0, group);
box(0.96, 1.8, 0.8, materials.limestone[2], 0, 2.25, -0.05, group);
box(0.76, 1.25, 0.62, materials.limestone[0], 0, 3.75, -0.08, group);
const cap = box(1.03, 0.23, 0.86, materials.limestone[3], 0, 4.47, -0.08, group);
cap.rotation.x = -0.16;
}
makeButtress(-4.55);
makeButtress(4.55);
// Exposed roof trusses behind the front wall.
for (const z of [-4.85, -7.15]) {
beamBetween([-4.8, 6.3, z], [0, 9.05, z], 0.25, 0.28, materials.timber);
beamBetween([0, 9.05, z], [4.8, 6.3, z], 0.25, 0.28, materials.timber);
beamBetween([-4.8, 6.3, z], [4.8, 6.3, z], 0.28, 0.3, materials.timber);
beamBetween([0, 6.3, z], [0, 9.0, z], 0.22, 0.25, materials.timber);
beamBetween([-3.2, 7.1, z], [0, 6.45, z], 0.16, 0.2, materials.timber);
beamBetween([3.2, 7.1, z], [0, 6.45, z], 0.16, 0.2, materials.timber);
}
// -------------------------------------------------------------------------
// Voussoirs and the active timber centering
// -------------------------------------------------------------------------
function archCurveData() {
const leftInner = [];
const leftOuter = [];
const rightInner = [];
const rightOuter = [];
const count = 7;
const t = 0.43;
for (let i = 0; i <= count; i++) {
const theta = Math.PI - (Math.PI / 3) * (i / count);
leftInner.push(new THREE.Vector2(
arch.halfWidth + arch.radius * Math.cos(theta),
arch.radius * Math.sin(theta)
));
leftOuter.push(new THREE.Vector2(
arch.halfWidth + (arch.radius + t) * Math.cos(theta),
(arch.radius + t) * Math.sin(theta)
));
}
for (let i = 0; i <= count; i++) {
const theta = (Math.PI / 3) * (i / count);
rightInner.push(new THREE.Vector2(
-arch.halfWidth + arch.radius * Math.cos(theta),
arch.radius * Math.sin(theta)
));
rightOuter.push(new THREE.Vector2(
-arch.halfWidth + (arch.radius + t) * Math.cos(theta),
(arch.radius + t) * Math.sin(theta)
));
}
return { leftInner, leftOuter, rightInner, rightOuter };
}
const curveData = archCurveData();
function voussoir(innerA, innerB, outerA, outerB, index) {
const shape = new THREE.Shape();
shape.moveTo(innerA.x, innerA.y);
shape.lineTo(innerB.x, innerB.y);
shape.lineTo(outerB.x, outerB.y);
shape.lineTo(outerA.x, outerA.y);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.27,
bevelEnabled: false
});
const material = index === 6 || index === 7
? materials.limestone[3]
: materials.limestone[index % materials.limestone.length];
return addMesh(geometry, material, 0, arch.spring, -3.45);
}
for (let i = 0; i < curveData.leftInner.length - 1; i++) {
voussoir(
curveData.leftInner[i],
curveData.leftInner[i + 1],
curveData.leftOuter[i],
curveData.leftOuter[i + 1],
i
);
}
for (let i = 0; i < curveData.rightInner.length - 1; i++) {
voussoir(
curveData.rightInner[i],
curveData.rightInner[i + 1],
curveData.rightOuter[i],
curveData.rightOuter[i + 1],
i + 8
);
}
function archPath() {
const path = [];
path.push(...curveData.leftInner);
for (let i = curveData.rightInner.length - 2; i >= 0; i--) {
path.push(curveData.rightInner[i]);
}
return path;
}
function offsetTowardOpening(path, distance) {
const center = new THREE.Vector2(0, 0);
return path.map(point => {
const direction = center.clone().sub(point).normalize();
return point.clone().addScaledVector(direction, distance);
});
}
function centeringRibGeometry(depth = 0.16) {
const path = archPath();
const inner = offsetTowardOpening(path, 0.19);
const shape = new THREE.Shape();
shape.moveTo(path[0].x, path[0].y);
for (let i = 1; i < path.length; i++) shape.lineTo(path[i].x, path[i].y);
for (let i = inner.length - 1; i >= 0; i--) shape.lineTo(inner[i].x, inner[i].y);
shape.closePath();
return new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false
});
}
const activeCentering = new THREE.Group();
activeCentering.position.y = arch.spring;
scene.add(activeCentering);
const activeRibGeometry = centeringRibGeometry(0.15);
addMesh(activeRibGeometry, materials.timber, 0, 0, -4.03, activeCentering);
addMesh(activeRibGeometry, materials.timberLight, 0, 0, -3.37, activeCentering);
for (const z of [-4.03, -3.37]) {
box(0.19, arch.spring, 0.18, materials.timber, -arch.halfWidth, -arch.spring / 2, z, activeCentering);
box(0.19, arch.spring, 0.18, materials.timber, arch.halfWidth, -arch.spring / 2, z, activeCentering);
}
box(0.27, 0.23, 0.92, materials.timberDark, 0, arch.rise - 0.1, -3.7, activeCentering);
const activePath = archPath();
for (let i = 3; i < activePath.length - 3; i += 2) {
const p = activePath[i];
const p2 = activePath[Math.min(i + 1, activePath.length - 1)];
const angle = Math.atan2(p2.y - p.y, p2.x - p.x);
const slat = box(0.31, 0.075, 0.74, materials.timberLight, p.x, p.y, -3.7, activeCentering);
slat.rotation.z = angle;
}
// Mason's layout cords over the wall face.
cylinderBetween(
[0, arch.apex, -3.16],
[-arch.halfWidth, arch.spring, -3.16],
0.012,
materials.rope
);
cylinderBetween(
[0, arch.apex, -3.16],
[arch.halfWidth, arch.spring, -3.16],
0.012,
materials.rope
);
cylinderBetween(
[0, arch.spring, -3.16],
[0, arch.apex, -3.16],
0.009,
materials.rope
);
// Scaffolding beside the opening.
const scaffold = new THREE.Group();
scene.add(scaffold);
for (const x of [-2.15, 2.15]) {
cylinder(0.075, 0.085, 5.55, 7, materials.timber, x, 2.78, -2.93, scaffold);
cylinder(0.055, 0.055, 5.1, 6, materials.timber, x + (x < 0 ? 0.72 : -0.72), 2.55, -3.15, scaffold);
}
for (const y of [1.2, 2.6, 4.2, 5.35]) {
beamBetween([-2.15, y, -2.93], [2.15, y, -2.93], 0.13, 0.15, materials.timber, scaffold);
}
beamBetween([-2.1, 1.25, -2.93], [1.5, 4.15, -2.93], 0.1, 0.12, materials.timber, scaffold);
beamBetween([2.1, 2.65, -2.93], [-1.5, 5.3, -2.93], 0.1, 0.12, materials.timber, scaffold);
// A dressed keystone waiting on the scaffold.
box(0.46, 0.64, 0.55, materials.limestone[3], 2.15, 4.6, -2.78, scaffold);
for (let i = 0; i < 4; i++) {
box(0.58, 0.24, 0.54, materials.limestone[i], -2.72, 0.35 + i * 0.25, -2.65);
}
// -------------------------------------------------------------------------
// Zone I: stone shaping
// -------------------------------------------------------------------------
const stoneZone = new THREE.Group();
scene.add(stoneZone);
// Workbench.
box(2.8, 0.18, 1.16, materials.timberLight, -7.2, 1.02, 1.65, stoneZone);
for (const x of [-8.28, -6.12]) {
for (const z of [1.25, 2.05]) {
box(0.17, 1.0, 0.17, materials.timber, x, 0.5, z, stoneZone);
}
}
beamBetween([-8.3, 0.28, 1.8], [-6.1, 0.28, 1.8], 0.12, 0.14, materials.timber, stoneZone);
// Dressed block with chalked drafted margins.
const dressedBlock = box(1.12, 0.47, 0.72, materials.limestone[1], -7.05, 1.34, 1.65, stoneZone);
const blockEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(dressedBlock.geometry),
materials.chalk
);
dressedBlock.add(blockEdges);
const chalkPoints = [
[-7.48, 1.581, 1.35], [-6.62, 1.581, 1.35],
[-7.48, 1.581, 1.95], [-6.62, 1.581, 1.95]
];
const chalkGeometry = new THREE.BufferGeometry().setFromPoints(
chalkPoints.map(p => new THREE.Vector3(...p))
);
stoneZone.add(new THREE.Line(chalkGeometry, materials.chalk));
// Point chisel lying on the block.
const chisel = new THREE.Group();
chisel.position.set(-7.35, 1.61, 1.7);
chisel.rotation.y = -0.35;
stoneZone.add(chisel);
cylinder(0.035, 0.045, 0.42, 7, materials.timberLight, 0, 0, 0, chisel);
box(0.055, 0.13, 0.045, materials.iron, 0, -0.25, 0, chisel);
// Loose mallet on the bench.
const mallet = new THREE.Group();
mallet.position.set(-6.35, 1.18, 1.55);
mallet.rotation.z = 0.24;
stoneZone.add(mallet);
cylinder(0.045, 0.055, 0.68, 7, materials.timberLight, 0, 0, 0, mallet);
const malletHead = cylinder(0.13, 0.13, 0.3, 8, materials.timber, 0, -0.26, 0, mallet);
malletHead.rotation.z = Math.PI / 2;
// Stone dressing area.
roughStone(0.55, 0.32, 0.48, materials.limestone[2], -8.45, 0.24, 2.62, stoneZone);
roughStone(0.43, 0.28, 0.38, materials.limestone[0], -8.02, 0.19, 2.92, stoneZone);
roughStone(0.66, 0.3, 0.5, materials.limestone[4], -5.88, 0.22, 2.48, stoneZone);
for (let i = 0; i < 28; i++) {
roughStone(
0.05 + random() * 0.09,
0.035 + random() * 0.05,
0.05 + random() * 0.08,
materials.stoneDust,
-8.4 + random() * 2.4,
0.025,
1.0 + random() * 2.1,
stoneZone
);
}
// -------------------------------------------------------------------------
// Zone II: full-size centering preparation
// -------------------------------------------------------------------------
const timberZone = new THREE.Group();
scene.add(timberZone);
const preparedCentering = new THREE.Group();
preparedCentering.position.set(7.15, 1.22, 0.75);
timberZone.add(preparedCentering);
const preparedRib = centeringRibGeometry(0.19);
addMesh(preparedRib, materials.timber, 0, 0, -0.48, preparedCentering);
addMesh(preparedRib, materials.timberLight, 0, 0, 0.48, preparedCentering);
for (const z of [-0.48, 0.48]) {
box(0.22, 1.22, 0.22, materials.timber, -arch.halfWidth, -0.61, z, preparedCentering);
box(0.22, 1.22, 0.22, materials.timber, arch.halfWidth, -0.61, z, preparedCentering);
}
box(0.34, 0.25, 1.28, materials.timberDark, 0, arch.rise - 0.12, 0, preparedCentering);
// Longitudinal laths, showing how the curved rib is clad.
const prepPath = archPath();
for (let i = 0; i < prepPath.length - 1; i++) {
const p = prepPath[i];
const p2 = prepPath[i + 1];
const angle = Math.atan2(p2.y - p.y, p2.x - p.x);
const length = p.distanceTo(p2) * 0.82;
const slat = box(length, 0.065, 1.02, materials.timberLight, p.x, p.y, 0, preparedCentering);
slat.rotation.z = angle;
}
// Radial struts inside the prepared rib.
for (const index of [3, 6, 9, 12]) {
const p = prepPath[index];
const inner = p.clone().multiplyScalar(0.55);
beamBetween(
[inner.x, inner.y, 0],
[p.x, p.y, 0],
0.1, 0.12,
materials.timber,
preparedCentering
);
}
// Trestles supporting the frame.
function makeTrestle(x, z, width = 1.05) {
const group = new THREE.Group();
group.position.set(x, 0, z);
timberZone.add(group);
beamBetween([-width, 0.05, 0], [0, 1.18, 0], 0.16, 0.19, materials.timber, group);
beamBetween([width, 0.05, 0], [0, 1.18, 0], 0.16, 0.19, materials.timber, group);
beamBetween([-width * 0.65, 0.47, 0], [width * 0.65, 0.47, 0], 0.11, 0.14, materials.timberLight, group);
box(0.58, 0.12, 0.65, materials.timberDark, 0, 1.18, 0, group);
}
makeTrestle(5.78, 0.72);
makeTrestle(8.52, 0.72);
// Lumber, wedges and carpenter's tools.
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 3; col++) {
box(
2.0, 0.16, 0.23,
row % 2 ? materials.timber : materials.timberLight,
8.8, 0.12 + row * 0.19, 3.0 + col * 0.28
);
}
}
for (let i = 0; i < 8; i++) {
const wedge = box(0.4, 0.1, 0.14, materials.timberLight, 5.55 + random() * 0.6, 0.07 + i * 0.035, 2.25 + random() * 0.8);
wedge.rotation.y = random() * Math.PI;
}
// A frame saw.
const sawGroup = new THREE.Group();
sawGroup.position.set(8.15, 0.65, 2.55);
sawGroup.rotation.set(-Math.PI / 2, 0, 0.22);
timberZone.add(sawGroup);
beamBetween([-0.72, 0, 0], [0.72, 0, 0], 0.035, 0.24, materials.iron, sawGroup);
beamBetween([-0.8, 0, 0], [-0.72, 0, 0], 0.08, 0.1, materials.timber, sawGroup);
beamBetween([0.72, 0, 0], [0.82, 0, 0], 0.08, 0.1, materials.timber, sawGroup);
// Adze and auger.
beamBetween([5.55, 0.08, 3.0], [6.45, 0.08, 2.6], 0.07, 0.08, materials.timberLight);
box(0.38, 0.08, 0.16, materials.iron, 5.5, 0.09, 3.0);
// Measuring rod with alternating divisions.
const rod = box(0.065, 3.7, 0.065, materials.timberLight, 9.55, 1.85, 0.25);
rod.rotation.z = -0.12;
for (let i = 0; i < 12; i++) {
const mark = box(0.13, 0.035, 0.075, materials.rope, 9.65 - i * 0.029, 0.35 + i * 0.3, 0.25);
mark.rotation.z = -0.12;
}
// -------------------------------------------------------------------------
// Workers
// -------------------------------------------------------------------------
const workers = [];
function createWorker({
x, z, rotation = 0, tunic = 0x59616a,
apron = null, skin = 0xa87555, cap = 0x65503a,
pose = 'work', tool = 'mallet'
}) {
const root = new THREE.Group();
root.position.set(x, 0, z);
root.rotation.y = rotation;
scene.add(root);
const cloth = standard(tunic);
const skinMaterial = standard(skin);
const capMaterial = standard(cap);
const torso = cylinder(0.29, 0.41, 0.72, 7, cloth, 0, 1.12, 0, root);
torso.rotation.z = 0.015;
cylinder(0.13, 0.15, 0.64, 6, standard(0x51483d), -0.16, 0.38, 0, root);
cylinder(0.13, 0.15, 0.64, 6, standard(0x51483d), 0.16, 0.38, 0, root);
box(0.25, 0.14, 0.38, materials.timberDark, -0.16, 0.08, 0.07, root);
box(0.25, 0.14, 0.38, materials.timberDark, 0.16, 0.08, 0.07, root);
const head = addMesh(
new THREE.DodecahedronGeometry(0.25, 0),
skinMaterial,
0, 1.75, 0, root
);
head.scale.set(0.9, 1.05, 0.92);
box(0.075, 0.09, 0.11, skinMaterial, 0, 1.73, 0.235, root);
cylinder(0.26, 0.27, 0.095, 8, capMaterial, 0, 1.94, 0, root);
cylinder(0.19, 0.23, 0.12, 8, capMaterial, 0, 2.01, -0.015, root);
if (apron !== null) {
box(0.55, 0.73, 0.055, standard(apron), 0, 1.06, 0.335, root);
}
function makeArm(side) {
const arm = new THREE.Group();
arm.position.set(side * 0.36, 1.4, 0);
root.add(arm);
cylinder(0.105, 0.09, 0.57, 6, cloth, 0, -0.285, 0, arm);
addMesh(
new THREE.DodecahedronGeometry(0.105, 0),
skinMaterial,
0, -0.59, 0, arm
);
return arm;
}
const leftArm = makeArm(-1);
const rightArm = makeArm(1);
if (tool) {
const hand = new THREE.Group();
hand.position.set(0, -0.6, 0.03);
rightArm.add(hand);
if (tool === 'mallet') {
cylinder(0.035, 0.045, 0.48, 6, materials.timberLight, 0, -0.13, 0, hand);
const head = cylinder(0.12, 0.12, 0.27, 7, materials.timber, 0, -0.39, 0, hand);
head.rotation.z = Math.PI / 2;
} else if (tool === 'adze') {
cylinder(0.035, 0.045, 0.58, 6, materials.timberLight, 0, -0.18, 0, hand);
const blade = box(0.31, 0.11, 0.07, materials.iron, 0.08, -0.46, 0, hand);
blade.rotation.z = 0.35;
}
}
const worker = { root, leftArm, rightArm, pose };
workers.push(worker);
return worker;
}
const mason = createWorker({
x: -7.2, z: 2.75, rotation: Math.PI,
tunic: 0x6d5948, apron: 0x9b8058,
pose: 'mason'
});
const hauler = createWorker({
x: -9.25, z: 3.45, rotation: -0.55,
tunic: 0x56636a, pose: 'carry', tool: null
});
hauler.leftArm.rotation.x = -1.05;
hauler.rightArm.rotation.x = -1.05;
roughStone(0.62, 0.43, 0.5, materials.limestone[2], 0, 1.12, 0.47, hauler.root);
const carpenter = createWorker({
x: 8.75, z: 2.35, rotation: Math.PI - 0.2,
tunic: 0x7c6844, apron: 0x5d4b35,
pose: 'carpenter', tool: 'adze'
});
const laborer = createWorker({
x: 3.35, z: -0.75, rotation: -0.7,
tunic: 0x756a54, pose: 'work', tool: null
});
// -------------------------------------------------------------------------
// Treadwheel crane, hoisting gear, and stone stacks
// -------------------------------------------------------------------------
const crane = new THREE.Group();
crane.position.set(4.25, 0, -1.1);
scene.add(crane);
beamBetween([-0.72, 0.05, 0], [0, 4.1, 0], 0.19, 0.22, materials.timber, crane);
beamBetween([0.72, 0.05, 0], [0, 4.1, 0], 0.19, 0.22, materials.timber, crane);
beamBetween([-0.52, 2.1, 0], [0.52, 2.1, 0], 0.15, 0.18, materials.timber, crane);
beamBetween([0, 0.15, 0], [0, 4.15, 0], 0.18, 0.22, materials.timberDark, crane);
const wheel = new THREE.Group();
wheel.position.set(0, 3.62, 0.31);
crane.add(wheel);
addMesh(
new THREE.TorusGeometry(0.68, 0.095, 6, 18),
materials.timberDark,
0, 0, 0, wheel
);
for (let i = 0; i < 8; i++) {
const spoke = box(1.32, 0.085, 0.09, materials.timber, 0, 0, 0, wheel);
spoke.rotation.z = i * Math.PI / 8;
}
const wheelHub = cylinder(0.15, 0.15, 0.24, 8, materials.timberDark, 0, 0, 0, wheel);
wheelHub.rotation.x = Math.PI / 2;
cylinderBetween([0, 3.0, 0.3], [-3.85, 1.3, 0.3], 0.025, materials.rope, crane);
beamBetween([-3.85, 1.35, 0.3], [-3.85, 0.9, 0.3], 0.06, 0.06, materials.iron, crane);
// Suspended limestone block.
roughStone(0.7, 0.48, 0.62, materials.limestone[1], -3.85, 0.66, 0.3, crane);
// Stacked dressed stones near the crane.
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 3 - Math.floor(row / 2); col++) {
box(
0.74, 0.3, 0.58,
materials.limestone[(row + col) % materials.limestone.length],
5.15 + col * 0.78,
0.17 + row * 0.31,
-2.55
);
}
}
makeBarrel(-4.8, 0, 3.7, 0.85);
makeBarrel(5.25, 0, 4.0, 0.78);
// A simple handcart with a stone load.
const cart = new THREE.Group();
cart.position.set(-5.1, 0, -0.15);
cart.rotation.y = -0.35;
scene.add(cart);
box(1.9, 0.16, 0.9, materials.timber, 0, 0.7, 0, cart);
box(1.9, 0.48, 0.08, materials.timberLight, 0, 0.96, -0.42, cart);
box(1.9, 0.48, 0.08, materials.timberLight, 0, 0.96, 0.42, cart);
beamBetween([0.8, 0.62, -0.36], [2.0, 0.45, -0.36], 0.09, 0.1, materials.timber, cart);
beamBetween([0.8, 0.62, 0.36], [2.0, 0.45, 0.36], 0.09, 0.1, materials.timber, cart);
for (const z of [-0.55, 0.55]) {
const cartWheel = addMesh(
new THREE.TorusGeometry(0.45, 0.08, 6, 14),
materials.timberDark,
-0.35, 0.48, z, cart
);
for (let i = 0; i < 6; i++) {
const spoke = box(0.82, 0.065, 0.06, materials.timber, -0.35, 0.48, z, cart);
spoke.rotation.z = i * Math.PI / 6;
}
}
for (let i = 0; i < 4; i++) {
roughStone(0.54, 0.3, 0.46, materials.limestone[i], -0.3 + (i % 2) * 0.6, 1.0 + Math.floor(i / 2) * 0.35, 0, cart);
}
// -------------------------------------------------------------------------
// Direct camera controls
// -------------------------------------------------------------------------
const control = {
target: new THREE.Vector3(0, 2.15, -1.0),
radius: 24,
theta: 0.68,
phi: 1.03
};
const views = {
overview: {
target: new THREE.Vector3(0, 2.15, -1.0),
radius: 24, theta: 0.68, phi: 1.03
},
stone: {
target: new THREE.Vector3(-7.0, 1.3, 1.8),
radius: 8.2, theta: 0.42, phi: 1.12
},
timber: {
target: new THREE.Vector3(7.1, 2.0, 0.75),
radius: 9.2, theta: 0.76, phi: 1.08
},
assembly: {
target: new THREE.Vector3(0, 3.0, -3.2),
radius: 11.5, theta: 0.28, phi: 1.1
}
};
let transition = null;
function updateCamera() {
const sinPhi = Math.sin(control.phi);
camera.position.set(
control.target.x + control.radius * sinPhi * Math.sin(control.theta),
control.target.y + control.radius * Math.cos(control.phi),
control.target.z + control.radius * sinPhi * Math.cos(control.theta)
);
camera.lookAt(control.target);
camera.updateMatrixWorld();
}
function focusView(name) {
const view = views[name];
if (!view) return;
transition = {
start: performance.now(),
fromTarget: control.target.clone(),
fromRadius: control.radius,
fromTheta: control.theta,
fromPhi: control.phi,
toTarget: view.target.clone(),
toRadius: view.radius,
toTheta: view.theta,
toPhi: 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', () => focusView(button.dataset.view));
});
const pointerState = new Map();
let lastPinchDistance = null;
renderer.domElement.addEventListener('contextmenu', event => event.preventDefault());
renderer.domElement.addEventListener('pointerdown', event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerState.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
transition = null;
lastPinchDistance = null;
});
renderer.domElement.addEventListener('pointermove', event => {
if (!pointerState.has(event.pointerId)) return;
const previous = pointerState.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointerState.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: previous.button
});
if (pointerState.size === 2) {
const points = [...pointerState.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (lastPinchDistance) {
control.radius = clamp(
control.radius * (lastPinchDistance / distance),
5,
42
);
}
lastPinchDistance = distance;
updateCamera();
return;
}
if (previous.button === 2 || event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = control.radius * 0.0015;
control.target.addScaledVector(right, -dx * panScale);
control.target.addScaledVector(up, dy * panScale);
control.target.y = clamp(control.target.y, 0.2, 8.5);
} else {
control.theta -= dx * 0.005;
control.phi = clamp(control.phi - dy * 0.0045, 0.25, 1.48);
}
updateCamera();
});
function endPointer(event) {
pointerState.delete(event.pointerId);
if (pointerState.size < 2) lastPinchDistance = null;
}
renderer.domElement.addEventListener('pointerup', endPointer);
renderer.domElement.addEventListener('pointercancel', endPointer);
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
transition = null;
control.radius = clamp(
control.radius * Math.exp(event.deltaY * 0.001),
5,
42
);
updateCamera();
}, { passive: false });
window.addEventListener('keydown', event => {
if (event.key === '1') focusView('overview');
if (event.key === '2') focusView('stone');
if (event.key === '3') focusView('timber');
if (event.key === '4') focusView('assembly');
if (event.key.toLowerCase() === 'h') toggleLabels();
});
// -------------------------------------------------------------------------
// World labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById('label-stone'),
position: new THREE.Vector3(-7.1, 2.9, 2.2)
},
{
element: document.getElementById('label-timber'),
position: new THREE.Vector3(7.1, 4.15, 0.8)
},
{
element: document.getElementById('label-assembly'),
position: new THREE.Vector3(0, 5.65, -3.15)
}
];
function toggleLabels() {
const container = document.getElementById('labels');
container.classList.toggle('hidden');
const button = document.getElementById('toggle-labels');
button.classList.toggle('active', !container.classList.contains('hidden'));
}
document.getElementById('toggle-labels').addEventListener('click', toggleLabels);
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? '1' : '0';
label.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (transition) {
const t = clamp((performance.now() - transition.start) / 850, 0, 1);
const eased = t * t * (3 - 2 * t);
control.target.lerpVectors(
transition.fromTarget,
transition.toTarget,
eased
);
control.radius = lerp(transition.fromRadius, transition.toRadius, eased);
control.theta = lerp(transition.fromTheta, transition.toTheta, eased);
control.phi = lerp(transition.fromPhi, transition.toPhi, eased);
if (t >= 1) transition = null;
}
updateCamera();
mason.rightArm.rotation.x = -0.83 + Math.sin(elapsed * 4.2) * 0.25;
mason.rightArm.rotation.z = -0.18;
mason.leftArm.rotation.x = -0.72;
mason.root.rotation.z = Math.sin(elapsed * 2.1) * 0.012;
carpenter.rightArm.rotation.x = -0.65 + Math.sin(elapsed * 2.8 + 1.3) * 0.2;
carpenter.rightArm.rotation.z = 0.16;
carpenter.leftArm.rotation.x = -0.9;
laborer.leftArm.rotation.x = -0.9;
laborer.rightArm.rotation.x = -0.75;
wheel.rotation.z = Math.sin(elapsed * 0.23) * 0.025;
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
animate();
</script>
</body>
</html>
```