Prompt specification
Build or customize the Three.js 3D scene "Church construction bay with staged materials" 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: Church construction bay with staged materials
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/church-construction-bay-with-staged-materials-x2347
Scene Description Prompt:
A low-poly medieval church construction bay with scaffolding, stone storage, workers, and visibly unfinished masonry. Three.js from cdnjs, one HTML file.
Working Three.js Starter (church-construction-bay-with-staged-materials-x2347):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stone & Timber — Medieval Construction Bay</title>
<style>
:root {
color-scheme: dark;
font-family: Georgia, "Times New Roman", serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9c7c8;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(350px, calc(100vw - 48px));
padding: 18px 20px 17px;
color: #f2ead8;
background:
linear-gradient(135deg, rgba(31, 36, 34, 0.91), rgba(54, 47, 39, 0.82));
border: 1px solid rgba(224, 205, 161, 0.4);
border-left: 4px solid #b88a43;
box-shadow: 0 14px 35px rgba(32, 29, 24, 0.22);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #d0aa66;
font: 600 10px/1.2 Arial, sans-serif;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 37px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: #c8c0ae;
font: 12px/1.45 Arial, sans-serif;
letter-spacing: 0.06em;
}
.date-badge {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
padding: 10px 13px;
color: #efe5cd;
background: rgba(35, 39, 36, 0.8);
border: 1px solid rgba(229, 208, 160, 0.3);
box-shadow: 0 10px 25px rgba(24, 28, 26, 0.15);
font: 600 10px/1 Arial, sans-serif;
letter-spacing: 0.18em;
text-transform: uppercase;
pointer-events: none;
}
.date-badge span {
display: block;
margin-top: 6px;
color: #c9a15c;
font-size: 12px;
letter-spacing: 0.11em;
}
.help {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 5;
padding: 10px 13px;
color: rgba(246, 240, 224, 0.9);
background: rgba(32, 36, 34, 0.72);
border: 1px solid rgba(238, 222, 187, 0.2);
font: 11px/1.4 Arial, sans-serif;
letter-spacing: 0.04em;
pointer-events: none;
}
.help b {
color: #d6ae67;
font-weight: 600;
}
#reset {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 6;
padding: 10px 14px;
color: #f0e8d8;
background: rgba(38, 42, 39, 0.84);
border: 1px solid rgba(225, 202, 153, 0.38);
font: 11px/1 Arial, sans-serif;
letter-spacing: 0.11em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
#reset:hover {
background: rgba(69, 62, 49, 0.95);
transform: translateY(-1px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #eee4cf;
background: #26302f;
font: 13px/1 Arial, sans-serif;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 16px;
}
.date-badge {
top: auto;
right: auto;
left: 14px;
bottom: 62px;
}
.help {
right: 14px;
bottom: 14px;
max-width: 190px;
}
#reset {
left: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive low-poly medieval church construction scene"></main>
<section class="title-card">
<div class="eyebrow">Construction study · Bay IV</div>
<h1>Stone & Timber</h1>
<p class="subtitle">A medieval nave in the midst of its making.</p>
</section>
<div class="date-badge">
Active Worksite
<span>Year 1387</span>
</div>
<button id="reset" type="button">Reset View</button>
<div class="help"><b>Drag</b> to orbit · <b>Scroll</b> to zoom</div>
<div id="loading">Raising the stonework…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9c8c8);
scene.fog = new THREE.Fog(0xb9c8c8, 24, 58);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.08;
document.querySelector("#scene").appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xd9ecf0, 0x69533b, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0ae, 3.2);
sun.position.set(-9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaac8d2, 0.65);
fill.position.set(10, 7, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Deterministic random helpers
// -------------------------------------------------------------------------
let seed = 731947;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function pick(items) {
return items[Math.floor(random() * items.length)];
}
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.92,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
side: options.side ?? THREE.FrontSide,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
const stoneColors = [
0xa9a18f,
0x999486,
0xb8ad98,
0x8f8d82,
0xc0b59e,
0x9da091,
0xaaa38f
];
const floorColors = [
0x77796e,
0x818176,
0x6d7169,
0x8b897b,
0x74776f
];
const stoneMat = material(0xffffff);
const darkStone = material(0x74766f);
const foundationMat = material(0x77776d);
const floorMat = material(0xffffff);
const woodMat = material(0x69462f);
const darkWoodMat = material(0x493326);
const scaffoldMat = material(0x8b5d35);
const ropeMat = material(0xa08a60);
const ironMat = material(0x3e4545, { metalness: 0.45, roughness: 0.66 });
const skinMat = material(0xb98158);
const bootMat = material(0x3e3028);
const hairMat = material(0x3b2b23);
const tunicColors = [
material(0x8b4936),
material(0x526d73),
material(0x7c743c),
material(0x66516f),
material(0x946b37)
];
const trouserMat = material(0x5b5146);
const mortarMat = material(0x9b9789);
const darkOpeningMat = material(0x263131);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addMesh(geometry, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
return addMesh(new THREE.BoxGeometry(w, h, d), mat, x, y, z, parent);
}
function beamBetween(a, b, width, mat, parent = scene, depth = width) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = addMesh(
new THREE.BoxGeometry(width, depth, length),
mat,
(start.x + end.x) / 2,
(start.y + end.y) / 2,
(start.z + end.z) / 2,
parent
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
return mesh;
}
function rodBetween(a, b, radius, mat, parent = scene, segments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
mat,
(start.x + end.x) / 2,
(start.y + end.y) / 2,
(start.z + end.z) / 2,
parent
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function lowPolySphere(radius, mat, x, y, z, parent = scene, detail = 0) {
return addMesh(
new THREE.IcosahedronGeometry(radius, detail),
mat,
x,
y,
z,
parent
);
}
// -------------------------------------------------------------------------
// Ground and foundations
// -------------------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(80, 80),
material(0x81765e),
0,
-0.38,
0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
const dirtPatch = addMesh(
new THREE.CircleGeometry(13, 18),
material(0x75654d),
0,
-0.355,
-0.5
);
dirtPatch.rotation.x = -Math.PI / 2;
dirtPatch.castShadow = false;
box(10.8, 0.48, 14.5, foundationMat, 0, -0.19, -0.55);
// Old interior paving
{
const tileGeo = new THREE.BoxGeometry(1, 1, 1);
const tiles = [];
const tileMat = material(0xffffff);
for (let row = 0; row < 15; row++) {
for (let col = 0; col < 9; col++) {
const x = -4.15 + col * 1.03 + (row % 2 ? 0.18 : 0);
const z = -6.75 + row * 0.86;
if (x > 4.55) continue;
const width = range(0.84, 0.98);
const depth = range(0.68, 0.82);
tiles.push({
x,
y: range(0.055, 0.075),
z,
width,
depth,
color: pick(floorColors)
});
}
}
const instance = new THREE.InstancedMesh(tileGeo, tileMat, tiles.length);
const dummy = new THREE.Object3D();
tiles.forEach((tile, index) => {
dummy.position.set(tile.x, tile.y, tile.z);
dummy.scale.set(tile.width, 0.09, tile.depth);
dummy.rotation.set(0, range(-0.012, 0.012), 0);
dummy.updateMatrix();
instance.setMatrixAt(index, dummy.matrix);
instance.setColorAt(index, new THREE.Color(tile.color));
});
instance.castShadow = true;
instance.receiveShadow = true;
scene.add(instance);
}
// -------------------------------------------------------------------------
// Instanced masonry walls
// -------------------------------------------------------------------------
function buildMasonry({
orientation = "x",
fixed = 0,
start = 0,
length = 10,
height = 7,
depth = 0.56,
courses = 14,
blockLength = 0.94,
profile = null,
openingTest = null,
roughTop = true
}) {
const blocks = [];
const courseHeight = height / courses;
for (let row = 0; row < courses; row++) {
const y = (row + 0.5) * courseHeight;
const offset = row % 2 ? blockLength * 0.5 : 0;
const first = start - length / 2 - offset;
for (let u = first; u < start + length / 2; u += blockLength) {
const left = u - blockLength / 2;
const right = u + blockLength / 2;
if (left < start - length / 2 - 0.01) continue;
if (right > start + length / 2 + 0.01) continue;
if (profile && y > profile(u)) continue;
if (openingTest && openingTest(u, y)) continue;
if (roughTop && row === courses - 1 && random() < 0.18) continue;
if (roughTop && row === courses - 2 && random() < 0.055) continue;
blocks.push({
u,
y,
w: blockLength - 0.035,
h: courseHeight - 0.035
});
}
}
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
stoneMat,
blocks.length
);
const dummy = new THREE.Object3D();
blocks.forEach((block, index) => {
if (orientation === "x") {
dummy.position.set(block.u, block.y, fixed);
dummy.scale.set(block.w, block.h, depth);
} else {
dummy.position.set(fixed, block.y, block.u);
dummy.scale.set(depth, block.h, block.w);
}
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(pick(stoneColors)));
});
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const backOpening = (x, y) => {
if (y < 1.82 || y > 6.52) return false;
const halfWidth = y <= 4.96
? 1.25
: 1.25 * (6.52 - y) / 1.56;
return Math.abs(x) < halfWidth;
};
buildMasonry({
orientation: "x",
fixed: -7.35,
start: 0,
length: 10.3,
height: 7.2,
depth: 0.62,
courses: 15,
openingTest: backOpening
});
const sideOpeningCenters = [-4.25, 0.05];
const leftOpening = (z, y) => {
for (const center of sideOpeningCenters) {
if (y < 2.25 || y > 5.42) continue;
const halfWidth = y <= 4.48
? 0.69
: 0.69 * (5.42 - y) / 0.94;
if (Math.abs(z - center) < halfWidth) return true;
}
return false;
};
buildMasonry({
orientation: "z",
fixed: -5.02,
start: -2.15,
length: 10.7,
height: 6.55,
depth: 0.58,
courses: 14,
openingTest: leftOpening
});
const rightProfile = (z) => {
if (z < -3.8) return 4.45;
if (z < -0.8) return 4.45 - (z + 3.8) * 0.17;
return 3.83 - (z + 0.8) * 0.28;
};
buildMasonry({
orientation: "z",
fixed: 5.02,
start: -2.85,
length: 9.0,
height: 4.5,
depth: 0.58,
courses: 10,
profile: rightProfile,
roughTop: true
});
// Rear gable
{
const shape = new THREE.Shape();
shape.moveTo(-5.15, 0);
shape.lineTo(5.15, 0);
shape.lineTo(0, 2.45);
shape.closePath();
const gable = addMesh(
new THREE.ExtrudeGeometry(shape, {
depth: 0.62,
bevelEnabled: false
}),
material(0xa39c8c),
0,
7.18,
-7.67
);
gable.receiveShadow = true;
}
// -------------------------------------------------------------------------
// Gothic window tracery
// -------------------------------------------------------------------------
function buildBackWindow() {
const z = -7.015;
box(0.16, 3.25, 0.17, stoneMat, -1.31, 3.45, z);
box(0.16, 3.25, 0.17, stoneMat, 1.31, 3.45, z);
box(0.18, 4.02, 0.18, stoneMat, 0, 3.78, z);
const leftPoints = [];
const rightPoints = [];
for (let i = 0; i <= 5; i++) {
const t = i / 5;
leftPoints.push([
THREE.MathUtils.lerp(-1.36, 0, t),
THREE.MathUtils.lerp(4.98, 6.58, t),
z
]);
rightPoints.push([
THREE.MathUtils.lerp(0, 1.36, t),
THREE.MathUtils.lerp(6.58, 4.98, t),
z
]);
}
for (let i = 0; i < leftPoints.length - 1; i++) {
beamBetween(leftPoints[i], leftPoints[i + 1], 0.17, stoneMat);
beamBetween(rightPoints[i], rightPoints[i + 1], 0.17, stoneMat);
}
box(2.76, 0.13, 0.16, stoneMat, 0, 4.08, z);
box(0.12, 2.15, 0.14, stoneMat, -0.62, 3.12, z);
box(0.12, 2.15, 0.14, stoneMat, 0.62, 3.12, z);
beamBetween([-0.62, 4.12, z], [0, 5.57, z], 0.11, stoneMat);
beamBetween([0.62, 4.12, z], [0, 5.57, z], 0.11, stoneMat);
const ring = addMesh(
new THREE.TorusGeometry(0.39, 0.075, 4, 12),
stoneMat,
0,
5.48,
z
);
ring.castShadow = true;
}
function buildSideWindow(center) {
const x = -4.71;
beamBetween([x, 2.24, center - 0.72], [x, 4.48, center - 0.72], 0.14, stoneMat);
beamBetween([x, 2.24, center + 0.72], [x, 4.48, center + 0.72], 0.14, stoneMat);
beamBetween([x, 2.24, center], [x, 4.83, center], 0.12, stoneMat);
const left = [];
const right = [];
for (let i = 0; i <= 4; i++) {
const t = i / 4;
left.push([
x,
THREE.MathUtils.lerp(4.48, 5.43, t),
THREE.MathUtils.lerp(center - 0.72, center, t)
]);
right.push([
x,
THREE.MathUtils.lerp(5.43, 4.48, t),
THREE.MathUtils.lerp(center, center + 0.72, t)
]);
}
for (let i = 0; i < 4; i++) {
beamBetween(left[i], left[i + 1], 0.14, stoneMat);
beamBetween(right[i], right[i + 1], 0.14, stoneMat);
}
}
buildBackWindow();
buildSideWindow(-4.25);
buildSideWindow(0.05);
// -------------------------------------------------------------------------
// Buttresses
// -------------------------------------------------------------------------
function buttress(x, z, outward) {
const direction = Math.sign(outward);
box(0.92, 3.25, 1.08, stoneMat, x, 1.63, z);
box(0.64, 4.4, 0.78, stoneMat, x + direction * 0.08, 4.13, z);
box(0.75, 0.55, 0.9, stoneMat, x + direction * 0.12, 6.42, z);
const cap = addMesh(
new THREE.ConeGeometry(0.58, 0.72, 4),
stoneMat,
x + direction * 0.12,
6.96,
z
);
cap.rotation.y = Math.PI / 4;
}
buttress(-5.55, -6.25, -1);
buttress(-5.55, -2.35, -1);
buttress(-5.55, 1.55, -1);
buttress(5.55, -5.7, 1);
buttress(5.55, -1.9, 1);
// -------------------------------------------------------------------------
// Exposed timber roof trusses
// -------------------------------------------------------------------------
function roofTruss(z, complete = true) {
const y = 6.28;
beamBetween([-4.82, y, z], [4.82, y, z], 0.27, darkWoodMat);
beamBetween([-4.82, y, z], [0, 8.46, z], 0.25, darkWoodMat);
if (complete) {
beamBetween([0, 8.46, z], [4.82, y, z], 0.25, darkWoodMat);
beamBetween([0, 6.28, z], [0, 8.46, z], 0.2, darkWoodMat);
beamBetween([-2.35, 7.31, z], [2.35, 7.31, z], 0.18, darkWoodMat);
} else {
beamBetween([0, 6.28, z], [0, 8.46, z], 0.19, darkWoodMat);
beamBetween([-4.82, y, z], [0, 8.46, z], 0.24, darkWoodMat);
}
}
roofTruss(-6.18, true);
roofTruss(-2.35, true);
roofTruss(1.0, false);
beamBetween([-2.35, 7.31, -6.18], [-2.35, 7.31, 1], 0.19, darkWoodMat);
beamBetween([2.35, 7.31, -6.18], [2.35, 7.31, 1], 0.19, darkWoodMat);
// -------------------------------------------------------------------------
// Scaffolding
// -------------------------------------------------------------------------
const scaffoldZ = [-6.2, -4.1, -2.0, 0.1];
const scaffoldX = [-4.48, -3.18];
for (const x of scaffoldX) {
for (const z of scaffoldZ) {
rodBetween([x, 0.1, z], [x, 6.72, z], 0.105, scaffoldMat, scene, 7);
}
}
for (const y of [0.78, 2.77, 4.76, 6.48]) {
beamBetween([-4.48, y, -6.2], [-4.48, y, 0.1], 0.13, scaffoldMat);
beamBetween([-3.18, y, -6.2], [-3.18, y, 0.1], 0.13, scaffoldMat);
}
// Wall ties
for (const z of scaffoldZ) {
for (const y of [1.0, 3.0, 5.0, 6.35]) {
rodBetween([-4.48, y, z], [-4.98, y, z], 0.055, ironMat, scene, 5);
}
}
// Outer diagonal braces
for (let i = 0; i < scaffoldZ.length - 1; i++) {
const z1 = scaffoldZ[i];
const z2 = scaffoldZ[i + 1];
const y1 = i % 2 === 0 ? 0.78 : 2.77;
const y2 = i % 2 === 0 ? 2.77 : 4.76;
beamBetween([-3.15, y1, z1], [-3.15, y2, z2], 0.11, scaffoldMat);
beamBetween([-3.15, y1, z2], [-3.15, y2, z1], 0.11, scaffoldMat);
}
// Working decks
for (const y of [1.0, 3.0, 5.0]) {
for (let i = 0; i < 4; i++) {
const x = -4.31 + i * 0.34;
box(0.29, 0.12, 6.42, scaffoldMat, x, y, -3.05);
}
box(1.48, 0.1, 0.18, darkWoodMat, -3.81, y + 0.07, 0.1);
}
// Ladder
{
const ladder = new THREE.Group();
ladder.position.set(-3.3, 0.05, 0.62);
ladder.rotation.x = -0.13;
scene.add(ladder);
beamBetween([-0.38, 0, 0], [-0.38, 5.15, 0], 0.09, scaffoldMat, ladder);
beamBetween([0.38, 0, 0], [0.38, 5.15, 0], 0.09, scaffoldMat, ladder);
for (let y = 0.35; y < 5; y += 0.46) {
beamBetween([-0.38, y, 0], [0.38, y, 0], 0.07, scaffoldMat, ladder);
}
}
// Hoist beam, pulley, rope, and suspended stone
beamBetween([-4.68, 6.85, 0.1], [-2.9, 6.85, 0.1], 0.16, darkWoodMat);
const pulley = addMesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.16, 10),
darkWoodMat,
-3.03,
6.62,
0.1
);
pulley.rotation.z = Math.PI / 2;
rodBetween([-3.03, 6.55, 0.1], [-3.03, 3.8, 0.1], 0.025, ropeMat, scene, 5);
const hangingStone = box(0.72, 0.42, 0.55, stoneMat, -3.03, 3.55, 0.1);
hangingStone.rotation.y = 0.08;
// -------------------------------------------------------------------------
// Scaffold sign
// -------------------------------------------------------------------------
function makeSignTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#4b3425";
ctx.fillRect(0, 0, 512, 256);
ctx.strokeStyle = "#c29a55";
ctx.lineWidth = 10;
ctx.strokeRect(18, 18, 476, 220);
ctx.strokeStyle = "#7d5b35";
ctx.lineWidth = 3;
ctx.strokeRect(31, 31, 450, 194);
ctx.fillStyle = "#e1c386";
ctx.textAlign = "center";
ctx.font = "bold 78px Georgia";
ctx.fillText("BAY IV", 256, 125);
ctx.fillStyle = "#b79561";
ctx.font = "24px Georgia";
ctx.fillText("STONEWORK", 256, 174);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const sign = addMesh(
new THREE.PlaneGeometry(1.35, 0.68),
new THREE.MeshStandardMaterial({
map: makeSignTexture(),
roughness: 0.9,
side: THREE.DoubleSide
}),
-3.68,
4.45,
0.22
);
sign.castShadow = true;
// -------------------------------------------------------------------------
// Cloth banner
// -------------------------------------------------------------------------
function makeBannerTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 384;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#a34f35";
ctx.fillRect(0, 0, 256, 384);
ctx.fillStyle = "#d2ad62";
ctx.beginPath();
ctx.moveTo(0, 60);
ctx.lineTo(128, 188);
ctx.lineTo(256, 60);
ctx.lineTo(256, 120);
ctx.lineTo(128, 246);
ctx.lineTo(0, 120);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = "#51392d";
ctx.lineWidth = 9;
ctx.strokeRect(10, 10, 236, 364);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const bannerGeometry = new THREE.PlaneGeometry(1.15, 1.7, 5, 8);
const bannerBasePositions = bannerGeometry.attributes.position.array.slice();
const banner = addMesh(
bannerGeometry,
new THREE.MeshStandardMaterial({
map: makeBannerTexture(),
side: THREE.DoubleSide,
roughness: 1
}),
-3.02,
5.55,
-5.45
);
banner.rotation.y = Math.PI / 2;
rodBetween([-3.04, 6.5, -5.45], [-3.04, 4.52, -5.45], 0.035, woodMat);
// -------------------------------------------------------------------------
// Workers
// -------------------------------------------------------------------------
function createWorker({
x,
y = 0,
z,
rotation = 0,
tunic = tunicColors[0],
pose = "carry"
}) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
scene.add(group);
// Legs and boots
box(0.19, 0.68, 0.22, trouserMat, -0.16, 0.43, 0, group);
box(0.19, 0.68, 0.22, trouserMat, 0.16, 0.43, 0, group);
box(0.24, 0.18, 0.38, bootMat, -0.16, 0.09, 0.06, group);
box(0.24, 0.18, 0.38, bootMat, 0.16, 0.09, 0.06, group);
// Tunic and belt
const torso = addMesh(
new THREE.CylinderGeometry(0.27, 0.39, 0.73, 7),
tunic,
0,
1.1,
0,
group
);
torso.scale.z = 0.82;
box(0.61, 0.09, 0.52, bootMat, 0, 0.83, 0, group);
box(0.13, 0.16, 0.1, material(0xb89b55), 0, 0.84, 0.28, group);
// Neck, head, cap
rodBetween([0, 1.47, 0], [0, 1.61, 0], 0.12, skinMat, group, 6);
lowPolySphere(0.225, skinMat, 0, 1.77, 0, group);
lowPolySphere(0.19, hairMat, 0, 1.83, -0.035, group);
const cap = addMesh(
new THREE.CylinderGeometry(0.24, 0.26, 0.12, 7),
tunic,
0,
1.96,
0,
group
);
cap.scale.z = 0.88;
// Eyes
lowPolySphere(0.026, darkOpeningMat, -0.075, 1.79, 0.202, group);
lowPolySphere(0.026, darkOpeningMat, 0.075, 1.79, 0.202, group);
const leftShoulder = [-0.29, 1.37, 0];
const rightShoulder = [0.29, 1.37, 0];
let leftHand = [-0.31, 0.93, 0.35];
let rightHand = [0.31, 0.93, 0.35];
if (pose === "carry") {
leftHand = [-0.27, 0.91, 0.47];
rightHand = [0.27, 0.91, 0.47];
} else if (pose === "lay") {
leftHand = [-0.38, 1.02, 0.68];
rightHand = [0.22, 1.08, 0.77];
} else if (pose === "trowel") {
leftHand = [-0.34, 0.87, 0.16];
rightHand = [0.27, 1.06, 0.68];
} else if (pose === "point") {
leftHand = [-0.3, 0.84, 0.08];
rightHand = [0.34, 1.24, 0.58];
}
const leftElbow = [
(leftShoulder[0] + leftHand[0]) / 2,
(leftShoulder[1] + leftHand[1]) / 2 - 0.08,
(leftShoulder[2] + leftHand[2]) / 2
];
const rightElbow = [
(rightShoulder[0] + rightHand[0]) / 2,
(rightShoulder[1] + rightHand[1]) / 2 - 0.08,
(rightShoulder[2] + rightHand[2]) / 2
];
rodBetween(leftShoulder, leftElbow, 0.105, tunic, group, 6);
rodBetween(leftElbow, leftHand, 0.09, skinMat, group, 6);
rodBetween(rightShoulder, rightElbow, 0.105, tunic, group, 6);
rodBetween(rightElbow, rightHand, 0.09, skinMat, group, 6);
lowPolySphere(0.105, skinMat, ...leftHand, group);
lowPolySphere(0.105, skinMat, ...rightHand, group);
if (pose === "carry") {
const carried = box(0.56, 0.33, 0.46, stoneMat, 0, 0.86, 0.61, group);
carried.rotation.y = 0.08;
}
if (pose === "trowel") {
rodBetween(
[rightHand[0], rightHand[1], rightHand[2]],
[rightHand[0] + 0.04, rightHand[1] - 0.18, rightHand[2] + 0.25],
0.025,
woodMat,
group,
5
);
const blade = box(
0.19,
0.025,
0.27,
ironMat,
rightHand[0] + 0.04,
rightHand[1] - 0.18,
rightHand[2] + 0.36,
group
);
blade.rotation.y = 0.15;
}
if (pose === "lay") {
box(0.32, 0.18, 0.35, stoneMat, 0.22, 1.03, 0.96, group);
}
return group;
}
createWorker({
x: -3.68,
y: 5.08,
z: -2.1,
rotation: -Math.PI / 2,
tunic: tunicColors[0],
pose: "lay"
});
createWorker({
x: -3.75,
y: 3.08,
z: -5.25,
rotation: -Math.PI / 2,
tunic: tunicColors[2],
pose: "point"
});
createWorker({
x: 1.58,
y: 0.12,
z: 2.2,
rotation: 0.2,
tunic: tunicColors[1],
pose: "carry"
});
createWorker({
x: -1.2,
y: 0.12,
z: 1.35,
rotation: -0.55,
tunic: tunicColors[3],
pose: "trowel"
});
createWorker({
x: 2.4,
y: 0.12,
z: -5.55,
rotation: Math.PI,
tunic: tunicColors[4],
pose: "lay"
});
// -------------------------------------------------------------------------
// Stone storage
// -------------------------------------------------------------------------
function addStoneBlock(x, y, z, sx = 0.92, sy = 0.38, sz = 0.55, parent = scene) {
const block = box(sx, sy, sz, stoneMat, x, y, z, parent);
block.rotation.y = range(-0.035, 0.035);
block.rotation.z = range(-0.012, 0.012);
return block;
}
// A partially stacked wall of dressed blocks
for (let row = 0; row < 5; row++) {
const count = row === 4 ? 3 : 5;
for (let col = 0; col < count; col++) {
if (row === 3 && col === 2) continue;
if (row === 4 && col === 1) continue;
const x = 2.3 + col * 0.92 + (row % 2 ? 0.22 : 0);
const y = 0.25 + row * 0.39;
const z = 3.2 + (row % 2 ? 0.03 : -0.03);
addStoneBlock(x, y, z, 0.86, 0.36, 0.58);
}
}
// Loose rubble pile
for (let i = 0; i < 28; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 1.4;
const x = 3.0 + Math.cos(angle) * radius;
const z = 1.65 + Math.sin(angle) * radius;
const stone = addMesh(
new THREE.DodecahedronGeometry(range(0.12, 0.28), 0),
stoneMat,
x,
range(0.08, 0.34),
z
);
stone.scale.set(range(0.7, 1.4), range(0.55, 1.0), range(0.7, 1.4));
stone.rotation.set(random(), random(), random());
}
// Scattered rubble along unfinished wall
for (let i = 0; i < 34; i++) {
const stone = addMesh(
new THREE.DodecahedronGeometry(range(0.08, 0.19), 0),
stoneMat,
range(3.4, 5.5),
range(0.04, 0.2),
range(-6.8, 1.9)
);
stone.scale.y = range(0.45, 0.85);
stone.rotation.set(random(), random(), random());
}
// -------------------------------------------------------------------------
// Wooden crate with stone
// -------------------------------------------------------------------------
{
const crate = new THREE.Group();
crate.position.set(4.0, 0.1, 4.2);
crate.rotation.y = -0.18;
scene.add(crate);
box(1.35, 0.12, 1.05, scaffoldMat, 0, 0.08, 0, crate);
box(1.35, 0.12, 1.05, scaffoldMat, 0, 0.78, 0, crate);
for (const x of [-0.63, 0.63]) {
for (const z of [-0.48, 0.48]) {
box(0.12, 0.83, 0.12, darkWoodMat, x, 0.42, z, crate);
}
}
for (const z of [-0.49, 0.49]) {
box(1.32, 0.15, 0.08, woodMat, 0, 0.38, z, crate);
}
addStoneBlock(-0.3, 0.48, 0.05, 0.5, 0.28, 0.48, crate);
addStoneBlock(0.25, 0.43, -0.08, 0.55, 0.26, 0.45, crate);
addStoneBlock(0.02, 0.69, 0.08, 0.46, 0.22, 0.42, crate);
}
// -------------------------------------------------------------------------
// Hand cart
// -------------------------------------------------------------------------
{
const cart = new THREE.Group();
cart.position.set(0.0, 0.05, 4.8);
cart.rotation.y = 0.24;
scene.add(cart);
box(1.45, 0.16, 1.7, woodMat, 0, 0.68, 0, cart);
box(1.45, 0.38, 0.11, scaffoldMat, 0, 0.89, -0.78, cart);
box(1.45, 0.38, 0.11, scaffoldMat, 0, 0.89, 0.78, cart);
box(0.11, 0.38, 1.6, scaffoldMat, -0.67, 0.89, 0, cart);
box(0.11, 0.38, 1.6, scaffoldMat, 0.67, 0.89, 0, cart);
for (const x of [-0.79, 0.79]) {
const wheel = addMesh(
new THREE.CylinderGeometry(0.47, 0.47, 0.16, 12),
darkWoodMat,
x,
0.48,
0.12,
cart
);
wheel.rotation.z = Math.PI / 2;
rodBetween([x, 0.48, 0.12], [x, 0.88, 0.12], 0.045, woodMat, cart, 5);
rodBetween([x, 0.48, 0.12], [x, 0.08, 0.12], 0.045, woodMat, cart, 5);
rodBetween([x, 0.48, 0.12], [x, 0.48, 0.55], 0.04, woodMat, cart, 5);
rodBetween([x, 0.48, 0.12], [x, 0.48, -0.31], 0.04, woodMat, cart, 5);
}
beamBetween([-0.56, 0.7, 0.78], [-0.48, 0.67, 2.1], 0.1, woodMat, cart);
beamBetween([0.56, 0.7, 0.78], [0.48, 0.67, 2.1], 0.1, woodMat, cart);
addStoneBlock(-0.35, 0.95, -0.25, 0.6, 0.3, 0.52, cart);
addStoneBlock(0.22, 0.92, 0.1, 0.58, 0.28, 0.5, cart);
addStoneBlock(0.03, 1.18, -0.03, 0.52, 0.26, 0.45, cart);
}
// -------------------------------------------------------------------------
// Mortar tub, buckets, and hand tools
// -------------------------------------------------------------------------
{
const tub = addMesh(
new THREE.CylinderGeometry(0.42, 0.34, 0.55, 10),
scaffoldMat,
-2.0,
0.29,
2.75
);
const mortar = addMesh(
new THREE.CylinderGeometry(0.36, 0.36, 0.025, 12),
mortarMat,
-2.0,
0.57,
2.75
);
mortar.castShadow = false;
const bucket = addMesh(
new THREE.CylinderGeometry(0.23, 0.18, 0.37, 9),
woodMat,
-0.25,
0.22,
2.88
);
bucket.rotation.z = 0.04;
rodBetween([-0.4, 0.42, 2.88], [-0.1, 0.42, 2.88], 0.018, ironMat, scene, 5);
}
// Chisel and mallet on a plank
box(0.8, 0.08, 0.42, woodMat, -3.2, 1.14, -0.8);
rodBetween([-3.48, 1.22, -0.84], [-3.0, 1.22, -0.74], 0.025, ironMat);
box(0.2, 0.12, 0.12, woodMat, -2.87, 1.24, -0.73);
// -------------------------------------------------------------------------
// Grass, weeds, and foreground details
// -------------------------------------------------------------------------
const grassMat = material(0x647044);
const grassDarkMat = material(0x4f5939);
const dirtDarkMat = material(0x5e503e);
function grassClump(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.33, z);
group.scale.setScalar(scale);
scene.add(group);
for (let i = 0; i < 4; i++) {
const blade = addMesh(
new THREE.ConeGeometry(range(0.035, 0.07), range(0.22, 0.52), 3),
i % 2 ? grassMat : grassDarkMat,
range(-0.16, 0.16),
range(0.12, 0.25),
range(-0.16, 0.16),
group
);
blade.rotation.z = range(-0.32, 0.32);
blade.rotation.x = range(-0.25, 0.25);
}
}
for (let i = 0; i < 70; i++) {
let x = range(-17, 17);
let z = range(-15, 17);
if (Math.abs(x) < 6.3 && z > -8.2 && z < 6.7) {
x += x < 0 ? -3 : 3;
}
grassClump(x, z, range(0.7, 1.7));
}
// Small dark soil patches
for (let i = 0; i < 16; i++) {
const patch = addMesh(
new THREE.CircleGeometry(range(0.25, 0.9), 7),
dirtDarkMat,
range(-12, 12),
-0.345,
range(-12, 14)
);
patch.rotation.x = -Math.PI / 2;
patch.castShadow = false;
}
// -------------------------------------------------------------------------
// Floating dust motes
// -------------------------------------------------------------------------
const dustCount = 150;
const dustPositions = new Float32Array(dustCount * 3);
const dustSpeeds = new Float32Array(dustCount);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = range(-9, 9);
dustPositions[i * 3 + 1] = range(0.2, 10);
dustPositions[i * 3 + 2] = range(-10, 8);
dustSpeeds[i] = range(0.035, 0.12);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffe2ad,
size: 0.045,
transparent: true,
opacity: 0.42,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Custom orbit controls — no external controls module
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 3.1, -1.45),
radius: 22.5,
theta: 0.34,
phi: 1.03,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.47, 1.39);
controls.radius = THREE.MathUtils.clamp(controls.radius, 12, 35);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.theta -= dx * 0.005;
controls.phi -= dy * 0.004;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
updateCamera();
});
function stopDragging(event) {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset").addEventListener("click", () => {
controls.target.set(0, 3.1, -1.45);
controls.radius = 22.5;
controls.theta = 0.34;
controls.phi = 1.03;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.theta += 0.08;
if (event.key === "ArrowRight") controls.theta -= 0.08;
if (event.key === "ArrowUp") controls.phi -= 0.05;
if (event.key === "ArrowDown") controls.phi += 0.05;
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Gentle cloth motion
const positionAttribute = bannerGeometry.attributes.position;
for (let i = 0; i < positionAttribute.count; i++) {
const baseX = bannerBasePositions[i * 3];
const baseY = bannerBasePositions[i * 3 + 1];
const weight = THREE.MathUtils.clamp((0.85 - baseY) / 1.7, 0, 1);
positionAttribute.setZ(
i,
Math.sin(baseX * 6 + elapsed * 2.2) * 0.075 * weight
);
}
positionAttribute.needsUpdate = true;
bannerGeometry.computeVertexNormals();
// Rising dust
for (let i = 0; i < dustCount; i++) {
const index = i * 3;
dustPositions[index + 1] += dustSpeeds[i] * 0.016;
dustPositions[index] += Math.sin(elapsed * 0.3 + i) * 0.0008;
if (dustPositions[index + 1] > 10.5) {
dustPositions[index + 1] = 0.1;
}
}
dustGeometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
animate();
setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 350);
</script>
</body>
</html>
```