Prompt specification
Build or customize the Three.js 3D scene "Santo Domingo stone doorway massing study" 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: Santo Domingo stone doorway massing study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/santo-domingo-stone-doorway-massing-study-x2773
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: Santo Domingo stone doorway massing study. Build a simplified referenced doorway and wall fragment from Oaxaca's Santo Domingo setting. Preserve broad proportions and layered depth without attempting every carved decorative detail. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (santo-domingo-stone-doorway-massing-study-x2773):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#cdbfa7" />
<title>Santo Domingo — Voxel Massing Study</title>
<style>
:root {
--ink: #29251f;
--muted: #71685a;
--paper: rgba(239, 229, 209, 0.91);
--line: rgba(57, 49, 39, 0.2);
--accent: #86583d;
--stone: #a3947c;
--shadow: #4b4338;
--earth: #9b7659;
--green: #66715a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cdbfa7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overscroll-behavior: none;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
body.is-dragging canvas {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(57, 47, 35, 0.11), transparent 22%),
radial-gradient(
circle at 50% 46%,
transparent 45%,
rgba(61, 47, 31, 0.13) 115%
);
z-index: 2;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 14px 38px rgba(54, 40, 25, 0.11);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
header {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 44px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0;
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.metric {
min-width: 0;
padding-right: 12px;
}
.metric + .metric {
padding-left: 12px;
border-left: 1px solid var(--line);
}
.metric strong {
display: block;
font-size: 15px;
font-weight: 750;
}
.metric span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.toolbar {
top: 24px;
right: 24px;
display: flex;
gap: 8px;
padding: 7px;
}
button {
min-height: 34px;
padding: 0 13px;
border: 1px solid transparent;
border-radius: 0;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease;
}
button:hover {
border-color: var(--line);
background: rgba(255, 255, 255, 0.34);
}
button[aria-pressed="true"] {
border-color: var(--accent);
background: var(--accent);
color: #fff8eb;
}
.legend {
bottom: 24px;
left: 24px;
display: flex;
align-items: center;
gap: 17px;
padding: 12px 16px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border: 1px solid rgba(30, 25, 19, 0.18);
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}
.swatch.stone {
background: var(--stone);
}
.swatch.shadow {
background: var(--shadow);
}
.swatch.earth {
background: var(--earth);
}
.swatch.green {
background: var(--green);
}
.hint {
right: 24px;
bottom: 24px;
padding: 11px 15px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint span {
color: var(--ink);
}
.disclaimer {
position: fixed;
left: 50%;
bottom: 28px;
z-index: 4;
transform: translateX(-50%);
color: rgba(50, 43, 34, 0.64);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-align: center;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #cdbfa7;
color: var(--ink);
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.loader::before {
width: 14px;
height: 14px;
content: "";
border: 2px solid rgba(41, 37, 31, 0.18);
border-top-color: var(--accent);
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 760px) {
header {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px;
}
h1 {
font-size: 32px;
}
.metrics {
margin-top: 14px;
padding-top: 12px;
}
.toolbar {
top: auto;
right: 14px;
bottom: 66px;
}
.legend {
bottom: 14px;
left: 14px;
gap: 10px;
padding: 10px 12px;
}
.legend-item {
font-size: 8px;
}
.legend-item:nth-child(3),
.legend-item:nth-child(4),
.hint,
.disclaimer {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="panel">
<div class="eyebrow">Oaxaca · Voxel Study</div>
<h1>Santo Domingo</h1>
<p class="subtitle">
A simplified stone doorway and wall-fragment massing study,
emphasizing proportion, recessed depth, and layered masonry.
</p>
<div class="metrics">
<div class="metric">
<strong>13.2 m</strong>
<span>Wall fragment</span>
</div>
<div class="metric">
<strong>2.8 m</strong>
<span>Clear opening</span>
</div>
<div class="metric">
<strong>5.5 m</strong>
<span>Portal crown</span>
</div>
</div>
</header>
<nav class="toolbar panel" aria-label="Scene controls">
<button id="rotateButton" type="button" aria-pressed="false">
Auto orbit
</button>
<button id="resetButton" type="button">Reset view</button>
</nav>
<aside class="legend panel" aria-label="Material legend">
<div class="legend-item">
<i class="swatch stone"></i>
Limestone
</div>
<div class="legend-item">
<i class="swatch shadow"></i>
Reveal
</div>
<div class="legend-item">
<i class="swatch earth"></i>
Earth
</div>
<div class="legend-item">
<i class="swatch green"></i>
Agave
</div>
</aside>
<div class="hint panel">
<span>Drag</span> orbit · <span>Scroll</span> zoom ·
<span>R</span> reset
</div>
<div class="disclaimer">
Interpretive reconstruction · conceptual geometry, not a measured survey
</div>
<div id="loading">
<div class="loader">Building voxel study</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
// ------------------------------------------------------------
// Renderer, camera, and lighting
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcdbfa7);
scene.fog = new THREE.Fog(0xcdbfa7, 25, 48);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute("aria-label", "Interactive voxel model");
renderer.domElement.tabIndex = 0;
const hemisphere = new THREE.HemisphereLight(0xffe8c6, 0x67513b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0ae, 3.5);
sun.position.set(-8, 13, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc6d1d3, 0.72);
fill.position.set(9, 6, -7);
scene.add(fill);
// ------------------------------------------------------------
// Deterministic random utilities
// ------------------------------------------------------------
let seed = 73421;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function stoneTone(base, lightness = 0, saturation = 0) {
const color = new THREE.Color(base);
color.offsetHSL(
(random() - 0.5) * 0.012,
(random() - 0.5) * 0.055 + saturation,
lightness + (random() - 0.5) * 0.075
);
return color;
}
// ------------------------------------------------------------
// Instanced voxel batches
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const up = new THREE.Vector3(0, 1, 0);
class VoxelBatch {
constructor(material) {
this.material = material;
this.matrices = [];
this.colors = [];
this.dummy = new THREE.Object3D();
}
add(
x,
y,
z,
sx,
sy,
sz,
color,
rx = 0,
ry = 0,
rz = 0
) {
this.dummy.position.set(x, y, z);
this.dummy.rotation.set(rx, ry, rz);
this.dummy.scale.set(sx, sy, sz);
this.dummy.updateMatrix();
this.matrices.push(this.dummy.matrix.clone());
this.colors.push(
color?.isColor ? color.clone() : new THREE.Color(color)
);
}
addSegment(a, b, width, color) {
const direction = b.clone().sub(a);
const length = direction.length();
const midpoint = a.clone().add(b).multiplyScalar(0.5);
this.dummy.position.copy(midpoint);
this.dummy.quaternion.setFromUnitVectors(
up,
direction.clone().normalize()
);
this.dummy.scale.set(width, length, width);
this.dummy.updateMatrix();
this.matrices.push(this.dummy.matrix.clone());
this.colors.push(
color?.isColor ? color.clone() : new THREE.Color(color)
);
}
commit(parent) {
if (!this.matrices.length) return null;
const mesh = new THREE.InstancedMesh(
unitBox,
this.material,
this.matrices.length
);
for (let i = 0; i < this.matrices.length; i++) {
mesh.setMatrixAt(i, this.matrices[i]);
mesh.setColorAt(i, this.colors[i]);
}
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
parent.add(mesh);
return mesh;
}
}
function makeMaterial(color, roughness = 0.93) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
});
}
const masonryBatch = new VoxelBatch(makeMaterial(0xffffff, 0.96));
const portalBatch = new VoxelBatch(makeMaterial(0xffffff, 0.91));
const revealBatch = new VoxelBatch(makeMaterial(0xffffff, 1));
const paverBatch = new VoxelBatch(makeMaterial(0xffffff, 1));
const plasterBatch = new VoxelBatch(makeMaterial(0xffffff, 1));
const vegetationBatch = new VoxelBatch(makeMaterial(0xffffff, 0.96));
const rubbleBatch = new VoxelBatch(makeMaterial(0xffffff, 1));
function addBox(parent, material, x, y, z, sx, sy, sz) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground and paving
// ------------------------------------------------------------
const earthMaterial = makeMaterial(0x927158, 1);
addBox(scene, earthMaterial, 0, -0.23, 0, 42, 0.3, 42);
const groundTileSize = 0.56;
for (let gx = -13; gx <= 13; gx++) {
for (let gz = -7; gz <= 12; gz++) {
const x = gx * groundTileSize + (random() - 0.5) * 0.05;
const z = gz * groundTileSize + (random() - 0.5) * 0.05;
// Keep the threshold area visually legible.
if (Math.abs(x) < 2.5 && z > 0.1 && z < 2.5) {
continue;
}
const width = range(0.45, 0.53);
const depth = range(0.44, 0.53);
const height = range(0.065, 0.11);
const color = stoneTone(
random() > 0.76 ? 0x9b7658 : 0x87745f,
range(-0.035, 0.035)
);
paverBatch.add(
x,
-0.035 + height * 0.5,
z,
width,
height,
depth,
color,
0,
range(-0.035, 0.035),
0
);
}
}
// ------------------------------------------------------------
// Main wall fragment
// ------------------------------------------------------------
const rowHeight = 0.5;
const wallRows = 13;
const wallHalfWidth = 6.6;
for (let row = 0; row < wallRows; row++) {
const y = rowHeight * 0.5 + row * rowHeight;
let x = -wallHalfWidth + (row % 2) * 0.43;
while (x < wallHalfWidth) {
const nominalWidth = 0.88 + (random() - 0.5) * 0.08;
const width = Math.min(nominalWidth, wallHalfWidth - x);
const centerX = x + width * 0.5;
const overlapsOpening =
centerX + width * 0.5 > -1.36 &&
centerX - width * 0.5 < 1.36;
// The lower eight courses contain the rectangular opening.
if (!(row < 8 && overlapsOpening)) {
const depth = range(1.12, 1.28);
const z = -0.26 + range(-0.035, 0.035);
const color = stoneTone(
random() > 0.87 ? 0xa08d70 : 0x978a74,
range(-0.035, 0.035)
);
masonryBatch.add(
centerX,
y + range(-0.012, 0.012),
z,
width - 0.025,
rowHeight - 0.03,
depth,
color
);
}
x += width;
}
}
// Slightly projecting edge quoins clarify the wall's thickness.
for (let row = 0; row < wallRows; row++) {
const y = rowHeight * 0.5 + row * rowHeight;
for (const side of [-1, 1]) {
masonryBatch.add(
side * 6.32,
y,
-0.16,
0.49,
0.465,
1.43,
stoneTone(0xa3947b, range(-0.025, 0.035))
);
}
}
// Heavy top coping.
let capX = -wallHalfWidth;
while (capX < wallHalfWidth) {
const width = Math.min(0.93, wallHalfWidth - capX);
const centerX = capX + width * 0.5;
masonryBatch.add(
centerX,
6.57,
-0.17,
width - 0.025,
0.29,
1.53,
stoneTone(0xa7987e, range(-0.025, 0.025))
);
capX += width;
}
// ------------------------------------------------------------
// Deep doorway reveal
// ------------------------------------------------------------
// Dark interior plane makes the opening read as a deep recess.
const interiorMaterial = makeMaterial(0x211d18, 1);
addBox(scene, interiorMaterial, 0, 2.0, -1.28, 2.82, 4.22, 0.14);
const revealFloorMaterial = makeMaterial(0x5b4d3d, 1);
addBox(scene, revealFloorMaterial, 0, 0.12, -0.58, 2.78, 0.22, 1.2);
// Inner jamb blocks: visibly deeper than the outer frame.
for (let y = 0.26; y < 4.15; y += 0.5) {
for (const side of [-1, 1]) {
revealBatch.add(
side * 1.53,
y,
-0.25,
0.28,
0.455,
1.55,
stoneTone(0x706451, range(-0.025, 0.025))
);
}
}
// Outer jamb blocks.
for (let y = 0.26; y < 4.15; y += 0.5) {
for (const side of [-1, 1]) {
portalBatch.add(
side * 2.02,
y,
0.34,
0.72,
0.455,
0.8,
stoneTone(0xb0a084, range(-0.025, 0.035))
);
// Narrow secondary edge course.
portalBatch.add(
side * 1.67,
y,
0.62,
0.13,
0.42,
0.16,
stoneTone(0xc0b092, range(-0.015, 0.02))
);
}
}
function segmentedRow({
batch,
y,
totalWidth,
unitWidth,
height,
depth,
z,
baseColor,
inset = 0.025,
}) {
let x = -totalWidth * 0.5;
while (x < totalWidth * 0.5 - 0.01) {
const width = Math.min(unitWidth, totalWidth * 0.5 - x);
const centerX = x + width * 0.5;
batch.add(
centerX,
y,
z,
width - inset,
height,
depth,
stoneTone(baseColor, range(-0.03, 0.035))
);
x += width;
}
}
// Layered lintel: three stepped masonry courses.
segmentedRow({
batch: revealBatch,
y: 4.16,
totalWidth: 3.48,
unitWidth: 0.48,
height: 0.39,
depth: 1.45,
z: -0.13,
baseColor: 0x756754,
});
segmentedRow({
batch: portalBatch,
y: 4.48,
totalWidth: 4.45,
unitWidth: 0.58,
height: 0.39,
depth: 1.07,
z: 0.12,
baseColor: 0xaa9a7e,
});
segmentedRow({
batch: portalBatch,
y: 4.81,
totalWidth: 5.48,
unitWidth: 0.68,
height: 0.39,
depth: 0.83,
z: 0.34,
baseColor: 0xb7a589,
});
// Abstract frieze course; carved detail is intentionally omitted.
segmentedRow({
batch: portalBatch,
y: 5.18,
totalWidth: 5.1,
unitWidth: 0.46,
height: 0.35,
depth: 0.58,
z: 0.51,
baseColor: 0x9f8e73,
inset: 0.035,
});
// Central plaque as a simple projecting block.
portalBatch.add(
0,
5.18,
0.86,
1.32,
0.48,
0.18,
stoneTone(0xc0ad8c, 0.015)
);
// Small upper cap stones.
for (const x of [-1.92, -0.96, 0, 0.96, 1.92]) {
portalBatch.add(
x,
5.49,
0.54,
0.72,
0.22,
0.62,
stoneTone(0xb4a183, range(-0.018, 0.025))
);
}
// ------------------------------------------------------------
// Threshold and broad approach steps
// ------------------------------------------------------------
const thresholdMaterial = makeMaterial(0xffffff, 0.95);
addBox(
scene,
thresholdMaterial,
0,
0.11,
1.66,
4.85,
0.22,
1.2
).material.color.set(0x9b8d76);
addBox(
scene,
thresholdMaterial,
0,
0.32,
1.08,
3.95,
0.22,
0.78
).material.color.set(0xa3957d);
addBox(
scene,
thresholdMaterial,
0,
0.53,
0.52,
3.12,
0.22,
0.68
).material.color.set(0xac9e84);
// Break up the steps with a few voxel edge stones.
for (const z of [1.25, 1.7, 2.02]) {
for (const x of [-1.95, -0.65, 0.7, 1.95]) {
masonryBatch.add(
x + range(-0.08, 0.08),
range(0.19, 0.27),
z,
range(0.35, 0.6),
range(0.1, 0.17),
range(0.25, 0.43),
stoneTone(0x95866f, range(-0.025, 0.025))
);
}
}
// ------------------------------------------------------------
// Weathered plaster remnants
// ------------------------------------------------------------
const plasterPatches = [
[-4.7, 2.1, 0.64, 0.5],
[-4.2, 3.0, 0.42, 0.7],
[-3.5, 4.75, 0.7, 0.34],
[3.7, 1.6, 0.58, 0.38],
[4.4, 2.5, 0.5, 0.75],
[3.4, 4.55, 0.75, 0.42],
[-5.5, 5.15, 0.42, 0.58],
[5.35, 4.8, 0.52, 0.43],
];
for (const [x, y, sx, sy] of plasterPatches) {
plasterBatch.add(
x,
y,
0.43,
sx,
sy,
0.07,
stoneTone(0xc2aa82, range(-0.025, 0.025))
);
}
// ------------------------------------------------------------
// Rubble at the wall base
// ------------------------------------------------------------
for (let i = 0; i < 30; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * range(2.5, 6.1);
const z = range(0.42, 1.35);
rubbleBatch.add(
x,
range(0.07, 0.17),
z,
range(0.18, 0.48),
range(0.1, 0.28),
range(0.18, 0.46),
stoneTone(0x8f7f67, range(-0.035, 0.035)),
range(-0.12, 0.12),
range(0, Math.PI),
range(-0.1, 0.1)
);
}
// ------------------------------------------------------------
// Sparse voxel agave
// ------------------------------------------------------------
function addAgave(x, z, scale = 1) {
const leafCount = 13;
const baseY = 0.08;
for (let leaf = 0; leaf < leafCount; leaf++) {
const angle = (leaf / leafCount) * Math.PI * 2 + range(-0.18, 0.18);
const radial = new THREE.Vector3(
Math.sin(angle),
0,
Math.cos(angle)
);
const reach = range(0.9, 1.55) * scale;
const height = range(0.85, 1.55) * scale;
const p0 = new THREE.Vector3(x, baseY, z);
const p1 = p0
.clone()
.addScaledVector(radial, reach * 0.28)
.add(new THREE.Vector3(0, height * 0.55, 0));
const p2 = p0
.clone()
.addScaledVector(radial, reach * 0.65)
.add(new THREE.Vector3(0, height * 0.82, 0));
const p3 = p0
.clone()
.addScaledVector(radial, reach)
.add(new THREE.Vector3(0, height * 0.47, 0));
const color = stoneTone(
random() > 0.72 ? 0x758067 : 0x5c6e53,
range(-0.025, 0.03)
);
vegetationBatch.addSegment(p0, p1, 0.18 * scale, color);
vegetationBatch.addSegment(p1, p2, 0.145 * scale, color);
vegetationBatch.addSegment(p2, p3, 0.1 * scale, color);
}
vegetationBatch.add(
x,
baseY + 0.06,
z,
0.28 * scale,
0.18 * scale,
0.28 * scale,
stoneTone(0x59664d, -0.02)
);
}
addAgave(-4.45, 2.4, 1.05);
addAgave(4.85, 1.75, 0.9);
addAgave(-5.45, -1.25, 0.72);
addAgave(5.55, -2.05, 0.62);
// Distant blocky vegetation to give the courtyard depth.
const distantGreen = new VoxelBatch(makeMaterial(0xffffff, 1));
for (const [x, z, height] of [
[-8.4, -6.4, 3.4],
[8.0, -7.2, 4.1],
[10.4, -9.1, 2.8],
]) {
for (let level = 0; level < height; level += 0.42) {
const width = 1.35 - level * 0.12;
distantGreen.add(
x + range(-0.12, 0.12),
level + 0.2,
z + range(-0.12, 0.12),
width,
0.42,
width,
stoneTone(0x6e745c, range(-0.03, 0.025))
);
}
}
distantGreen.commit(scene);
// Commit all voxel batches.
masonryBatch.commit(scene);
portalBatch.commit(scene);
revealBatch.commit(scene);
paverBatch.commit(scene);
plasterBatch.commit(scene);
vegetationBatch.commit(scene);
rubbleBatch.commit(scene);
// ------------------------------------------------------------
// Custom orthographic orbit controls
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 2.7, -0.15);
const view = {
theta: 0.57,
phi: 1.08,
zoom: 1,
targetTheta: 0.57,
targetPhi: 1.08,
targetZoom: 1,
autoRotate: false,
};
const pointerPositions = new Map();
let dragging = false;
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function pointerDistance() {
const points = [...pointerPositions.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerPositions.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
});
renderer.domElement.setPointerCapture(event.pointerId);
if (pointerPositions.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
document.body.classList.add("is-dragging");
} else if (pointerPositions.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerPositions.has(event.pointerId)) return;
pointerPositions.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
});
if (pointerPositions.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
view.targetZoom = clamp(
view.targetZoom * (distance / previousPinchDistance),
0.62,
1.85
);
}
previousPinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
view.targetTheta -= dx * 0.0055;
view.targetPhi = clamp(view.targetPhi + dy * 0.0042, 0.48, 1.43);
previousX = event.clientX;
previousY = event.clientY;
});
function releasePointer(event) {
pointerPositions.delete(event.pointerId);
if (pointerPositions.size === 0) {
dragging = false;
document.body.classList.remove("is-dragging");
}
if (pointerPositions.size < 2) {
previousPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.targetZoom = clamp(
view.targetZoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.85
);
},
{ passive: false }
);
function resetView() {
view.targetTheta = 0.57;
view.targetPhi = 1.08;
view.targetZoom = 1;
}
document.getElementById("resetButton").addEventListener("click", resetView);
const rotateButton = document.getElementById("rotateButton");
rotateButton.addEventListener("click", () => {
view.autoRotate = !view.autoRotate;
rotateButton.setAttribute("aria-pressed", String(view.autoRotate));
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
});
// ------------------------------------------------------------
// Responsive camera and render loop
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const viewHeight = aspect < 0.95 ? 12.2 / aspect : 12.2;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (view.autoRotate) {
view.targetTheta += dt * 0.075;
}
const smoothing = 1 - Math.exp(-8 * dt);
view.theta += (view.targetTheta - view.theta) * smoothing;
view.phi += (view.targetPhi - view.phi) * smoothing;
view.zoom += (view.targetZoom - view.zoom) * smoothing;
const radius = 24;
const horizontalRadius = Math.sin(view.phi) * radius;
camera.position.set(
target.x + horizontalRadius * Math.sin(view.theta),
target.y + Math.cos(view.phi) * radius,
target.z + horizontalRadius * Math.cos(view.theta)
);
camera.lookAt(target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// Give the first frame a moment to compile before hiding the loader.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
});
</script>
</body>
</html>
```