Prompt specification
Build or customize the Three.js 3D scene "Curving stone passage and entrance" 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: Curving stone passage and entrance
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/curving-stone-passage-and-entrance-x2350
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the dry-stone enclosures of Great Zimbabwe. Create a compact curved stone passage with a narrow entrance and changing wall height. Preserve human-scale access and label its layout as a selective referenced stylization. Voxel style.
Working Three.js Starter (curving-stone-passage-and-entrance-x2350):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Great Zimbabwe — Voxel Stylization</title>
<style>
:root {
--ink: #292820;
--paper: rgba(239, 231, 210, 0.91);
--line: rgba(60, 54, 42, 0.24);
--accent: #9a5f32;
--accent-light: #d6ad72;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c7b99b;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(65, 58, 43, 0.28);
box-shadow: 0 12px 35px rgba(45, 38, 25, 0.12);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
#title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 19px 17px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #6c604e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3.2vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 0;
color: #5d5444;
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-style: italic;
}
.reference-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 7px 9px;
border: 1px solid rgba(97, 67, 37, 0.38);
background: rgba(190, 143, 83, 0.11);
color: #67462d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.095em;
text-transform: uppercase;
}
.reference-badge::before {
width: 7px;
height: 7px;
background: var(--accent);
content: "";
}
.disclaimer {
margin: 10px 0 0;
color: #6d6454;
font-size: 11px;
line-height: 1.45;
}
#legend {
top: 22px;
right: 22px;
width: 215px;
padding: 13px 14px;
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
color: #6b604e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
font-size: 11px;
color: #51493d;
}
.swatch {
width: 13px;
height: 13px;
border: 1px solid rgba(50, 45, 35, 0.15);
}
.swatch.stone { background: #888273; }
.swatch.path { background: #bca479; }
.swatch.land { background: #85865a; }
.swatch.wood { background: #514536; }
#controls {
bottom: 20px;
left: 22px;
padding: 10px 12px;
color: #5e5546;
font-size: 10px;
letter-spacing: 0.025em;
pointer-events: none;
}
#controls strong {
color: #332f27;
font-weight: 800;
}
#site-mark {
right: 22px;
bottom: 20px;
padding: 11px 14px;
text-align: right;
pointer-events: none;
}
#site-mark .place {
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
}
#site-mark .coord {
margin-top: 3px;
color: #716754;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#hotspots {
position: fixed;
inset: 0;
z-index: 8;
overflow: hidden;
pointer-events: none;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity 180ms ease;
white-space: nowrap;
}
.hotspot .num {
display: grid;
flex: 0 0 auto;
width: 23px;
height: 23px;
place-items: center;
border: 1px solid rgba(47, 42, 33, 0.45);
border-radius: 50%;
background: rgba(239, 231, 210, 0.94);
color: #4c3a28;
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
font-weight: 700;
box-shadow: 0 3px 10px rgba(37, 31, 20, 0.13);
}
.hotspot .copy {
padding: 6px 8px;
border: 1px solid rgba(57, 49, 37, 0.24);
background: rgba(238, 230, 209, 0.9);
box-shadow: 0 4px 14px rgba(37, 31, 20, 0.11);
}
.hotspot b {
display: block;
color: #393329;
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
font-weight: 600;
}
.hotspot small {
display: block;
margin-top: 2px;
color: #746954;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
#legend {
display: none;
}
#controls {
bottom: 12px;
left: 12px;
max-width: calc(100vw - 24px);
}
#site-mark {
display: none;
}
.hotspot .copy {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.hotspot {
transition: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel interpretation of the dry-stone enclosures of Great Zimbabwe"
></canvas>
<section id="title-card" class="panel">
<div class="eyebrow">Architectural landscape · Voxel study 01</div>
<h1>Great Zimbabwe</h1>
<p class="subtitle">Dry-stone enclosures of the ancient Zimbabwe plateau</p>
<div class="reference-badge">Selective referenced stylization</div>
<p class="disclaimer">
Interpretive layout inspired by the Great Enclosure’s curving masonry,
narrow passage, and conical tower. Not a survey reconstruction.
</p>
</section>
<aside id="legend" class="panel">
<div class="legend-title">Material key</div>
<div class="legend-row">
<span class="swatch stone"></span>
<span>Dry-laid granite masonry</span>
</div>
<div class="legend-row">
<span class="swatch path"></span>
<span>Human-scale passage</span>
</div>
<div class="legend-row">
<span class="swatch land"></span>
<span>Granite savanna</span>
</div>
<div class="legend-row">
<span class="swatch wood"></span>
<span>Acacia woodland</span>
</div>
</aside>
<div id="hotspots">
<div class="hotspot" id="label-entrance">
<span class="num">1</span>
<span class="copy">
<b>Narrow entrance</b>
<small>Human-scale throat</small>
</span>
</div>
<div class="hotspot" id="label-passage">
<span class="num">2</span>
<span class="copy">
<b>Curving passage</b>
<small>Between parallel walls</small>
</span>
</div>
<div class="hotspot" id="label-wall">
<span class="num">3</span>
<span class="copy">
<b>Variable wall height</b>
<small>Stepped granite courses</small>
</span>
</div>
<div class="hotspot" id="label-tower">
<span class="num">4</span>
<span class="copy">
<b>Conical tower</b>
<small>Interior landmark</small>
</span>
</div>
<div class="hotspot" id="label-secondary">
<span class="num">5</span>
<span class="copy">
<b>Secondary enclosure</b>
<small>Simplified spatial context</small>
</span>
</div>
</div>
<div id="controls" class="panel">
<strong>DRAG</strong> orbit ·
<strong>RIGHT-DRAG</strong> pan ·
<strong>SCROLL</strong> zoom ·
<strong>R</strong> reset
</div>
<div id="site-mark" class="panel">
<div class="place">Masvingo Province</div>
<div class="coord">Zimbabwe · Southern Africa</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.14;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9bea3);
scene.fog = new THREE.Fog(0xc9bea3, 39, 82);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight(
0xe8ddc3,
0x626047,
2.0
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2ad, 3.15);
sun.position.set(-19, 30, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 27;
sun.shadow.camera.bottom = -27;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7c4c4, 0.55);
fill.position.set(19, 11, -18);
scene.add(fill);
// Deterministic random values keep the stylization stable between reloads.
let seed = 72419;
function random() {
seed |= 0;
seed = (seed + 0x6D2B79F5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const rand = (a, b) => a + (b - a) * random();
const clamp = THREE.MathUtils.clamp;
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
metalness: 0
});
const pathMaterial = new THREE.MeshStandardMaterial({
color: 0xb9a176,
roughness: 1
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x514637,
roughness: 0.95
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x5f6543,
roughness: 1
});
const leafLightMaterial = new THREE.MeshStandardMaterial({
color: 0x74744b,
roughness: 1
});
const personMaterial = new THREE.MeshStandardMaterial({
color: 0x493d34,
roughness: 0.9
});
// -------------------------------------------------------------------------
// Terrain
// -------------------------------------------------------------------------
const terrain = new THREE.Mesh(
new THREE.BoxGeometry(46, 1.15, 38),
new THREE.MeshStandardMaterial({
color: 0x817d58,
roughness: 1
})
);
terrain.position.y = -0.58;
terrain.receiveShadow = true;
scene.add(terrain);
// Voxel ground plates.
const groundCountX = 23;
const groundCountZ = 19;
const groundTransforms = [];
for (let x = 0; x < groundCountX; x++) {
for (let z = 0; z < groundCountZ; z++) {
groundTransforms.push({
x: -22 + x * 2,
y: rand(-0.015, 0.025),
z: -18 + z * 2,
sx: rand(1.91, 2.02),
sz: rand(1.91, 2.02),
color: new THREE.Color().setHSL(
rand(0.115, 0.155),
rand(0.16, 0.28),
rand(0.37, 0.46)
)
});
}
}
const groundMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 0.09, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
}),
groundTransforms.length
);
const dummy = new THREE.Object3D();
groundTransforms.forEach((g, i) => {
dummy.position.set(g.x, g.y, g.z);
dummy.scale.set(g.sx, 1, g.sz);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
groundMesh.setMatrixAt(i, dummy.matrix);
groundMesh.setColorAt(i, g.color);
});
groundMesh.receiveShadow = true;
scene.add(groundMesh);
// -------------------------------------------------------------------------
// Dry-stone masonry system
// -------------------------------------------------------------------------
const stoneTransforms = [];
const stonePalette = [
0x898376,
0x958d7d,
0x7d786d,
0x9b927e,
0x827c70,
0x918775
];
function addStone(
position,
scale,
rotationY = 0,
color = stonePalette[0],
colorVariation = 0.10
) {
const c = new THREE.Color(color);
c.multiplyScalar(1 - colorVariation + random() * colorVariation * 2);
c.offsetHSL(rand(-0.008, 0.008), rand(-0.025, 0.025), 0);
stoneTransforms.push({
position: position.clone(),
scale: scale.clone(),
rotationY,
rotationX: rand(-0.012, 0.012),
rotationZ: rand(-0.012, 0.012),
color: c
});
}
function buildWall(curve, options = {}) {
const {
spacing = 0.58,
depth = 0.92,
baseHeight = 2.3,
heightVariation = 1.0,
heightFn = null,
courseHeight = 0.38
} = options;
const length = curve.getLength();
const samples = Math.max(8, Math.ceil(length / spacing));
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const p = curve.getPointAt(t);
const tangent = curve.getTangentAt(t).normalize();
const wave =
0.5 +
0.5 * Math.sin(t * Math.PI * 1.35 - 0.45);
const irregular =
0.18 * Math.sin(t * 16.0 + 0.8) +
0.10 * Math.sin(t * 31.0);
const desiredHeight = heightFn
? heightFn(t)
: baseHeight + wave * heightVariation + irregular;
const rows = Math.max(3, Math.floor(desiredHeight / courseHeight));
for (let row = 0; row < rows; row++) {
const stagger = row % 2 === 0 ? -spacing * 0.23 : spacing * 0.23;
const pos = p.clone().addScaledVector(tangent, stagger);
pos.y = 0.16 + row * courseHeight + rand(-0.018, 0.018);
const along = spacing * rand(1.10, 1.24);
const thickness = depth * rand(0.90, 1.08);
const height = courseHeight * rand(0.90, 1.04);
const angle = Math.atan2(-tangent.z, tangent.x);
addStone(
pos,
new THREE.Vector3(along, height, thickness),
angle + rand(-0.035, 0.035),
stonePalette[Math.floor(random() * stonePalette.length)],
0.085
);
}
}
}
function buildTower(x, z, radius, height) {
const courseHeight = 0.36;
const rows = Math.floor(height / courseHeight);
for (let row = 0; row < rows; row++) {
const t = row / rows;
const r = THREE.MathUtils.lerp(radius, 0.34, Math.pow(t, 0.9));
const count = Math.max(8, Math.round((Math.PI * 2 * r) / 0.59));
const arc = (Math.PI * 2) / count;
for (let i = 0; i < count; i++) {
const a = i * arc + (row % 2) * arc * 0.42;
const radial = new THREE.Vector3(Math.cos(a), 0, Math.sin(a));
const tangent = new THREE.Vector3(-Math.sin(a), 0, Math.cos(a));
const p = new THREE.Vector3(x, 0, z)
.addScaledVector(radial, r)
.addScaledVector(tangent, rand(-0.045, 0.045));
p.y = 0.16 + row * courseHeight + rand(-0.015, 0.015);
addStone(
p,
new THREE.Vector3(
arc * r * rand(1.04, 1.13),
courseHeight * rand(0.92, 1.04),
rand(0.48, 0.59)
),
Math.atan2(-tangent.z, tangent.x),
stonePalette[Math.floor(random() * stonePalette.length)],
0.10
);
}
}
}
// Great Enclosure: outer wall and parallel inner wall.
const outerPoints = [
new THREE.Vector3( 0.95, 0, -10.40),
new THREE.Vector3( 4.50, 0, -10.10),
new THREE.Vector3( 8.60, 0, -6.90),
new THREE.Vector3(10.40, 0, -1.50),
new THREE.Vector3( 9.80, 0, 4.10),
new THREE.Vector3( 6.90, 0, 8.60),
new THREE.Vector3( 1.80, 0, 10.10),
new THREE.Vector3(-4.30, 0, 9.30),
new THREE.Vector3(-8.40, 0, 5.10),
new THREE.Vector3(-9.40, 0, -0.30),
new THREE.Vector3(-8.00, 0, -5.80),
new THREE.Vector3(-4.90, 0, -9.00),
new THREE.Vector3(-0.95, 0, -10.40)
];
const innerPoints = [
new THREE.Vector3( 1.15, 0, -8.80),
new THREE.Vector3( 4.00, 0, -8.50),
new THREE.Vector3( 7.30, 0, -5.90),
new THREE.Vector3( 8.80, 0, -1.40),
new THREE.Vector3( 8.30, 0, 3.60),
new THREE.Vector3( 5.80, 0, 7.40),
new THREE.Vector3( 1.40, 0, 8.70),
new THREE.Vector3(-3.50, 0, 8.00),
new THREE.Vector3(-6.90, 0, 4.50),
new THREE.Vector3(-7.70, 0, -0.20),
new THREE.Vector3(-6.50, 0, -4.80),
new THREE.Vector3(-4.00, 0, -7.50),
new THREE.Vector3(-1.15, 0, -8.80)
];
const outerCurve = new THREE.CatmullRomCurve3(
outerPoints,
false,
"catmullrom",
0.36
);
const innerCurve = new THREE.CatmullRomCurve3(
innerPoints,
false,
"catmullrom",
0.36
);
buildWall(outerCurve, {
spacing: 0.58,
depth: 0.96,
heightFn: t => {
const crest =
0.5 + 0.5 * Math.sin(t * Math.PI * 1.45 - 0.45);
const westCrest =
0.28 * Math.exp(-Math.pow((t - 0.73) / 0.16, 2));
return 2.45 + crest * 1.12 + westCrest;
}
});
buildWall(innerCurve, {
spacing: 0.56,
depth: 0.72,
heightFn: t =>
1.95 +
0.48 * (0.5 + 0.5 * Math.sin(t * Math.PI * 1.7)) +
0.18 * Math.sin(t * 14.0)
});
// A narrow, human-scale throat between two masonry piers.
// Clear width is approximately 0.95 m.
for (const side of [-1, 1]) {
for (let row = 0; row < 7; row++) {
for (let zStep = 0; zStep < 3; zStep++) {
addStone(
new THREE.Vector3(
side * 0.82,
0.17 + row * 0.38,
-10.05 + zStep * 0.56
),
new THREE.Vector3(0.70, 0.35, 0.52),
rand(-0.025, 0.025),
stonePalette[Math.floor(random() * stonePalette.length)],
0.08
);
}
}
}
// Subtle chevron masonry on the exterior face.
for (let motif = 0; motif < 5; motif++) {
const centerT = 0.075 + motif * 0.043;
for (let s = -4; s <= 4; s++) {
const t = clamp(centerT + s * 0.009, 0, 1);
const p = outerCurve.getPointAt(t);
const tangent = outerCurve.getTangentAt(t).normalize();
const outward = p.clone().setY(0).normalize();
p.addScaledVector(outward, 0.51);
p.y = 1.26 + Math.abs(s) * 0.135;
addStone(
p,
new THREE.Vector3(0.31, 0.14, 0.13),
Math.atan2(-tangent.z, tangent.x),
0x625d54,
0.05
);
}
}
// Iconic conical masonry landmark inside the enclosure.
buildTower(-1.70, 2.30, 2.05, 5.35);
// Simplified secondary enclosure on the rear-left.
const secondaryPoints = [];
const secondaryCenter = new THREE.Vector3(-15.0, 0, 7.2);
const secondaryRx = 4.7;
const secondaryRz = 3.6;
for (let i = 0; i <= 22; i++) {
const a = -0.20 + (i / 22) * (Math.PI * 2 - 0.40);
secondaryPoints.push(
new THREE.Vector3(
secondaryCenter.x + Math.cos(a) * secondaryRx,
0,
secondaryCenter.z + Math.sin(a) * secondaryRz
)
);
}
const secondaryCurve = new THREE.CatmullRomCurve3(
secondaryPoints,
false,
"catmullrom",
0.4
);
buildWall(secondaryCurve, {
spacing: 0.61,
depth: 0.73,
heightFn: t =>
1.48 +
0.43 * (0.5 + 0.5 * Math.sin(t * Math.PI * 1.8 + 0.3))
});
// Rubble and fallen masonry.
for (let i = 0; i < 85; i++) {
const a = random() * Math.PI * 2;
const r = rand(10.7, 13.2);
addStone(
new THREE.Vector3(
Math.cos(a) * r,
rand(0.09, 0.19),
Math.sin(a) * r * 0.78
),
new THREE.Vector3(
rand(0.22, 0.62),
rand(0.16, 0.36),
rand(0.22, 0.56)
),
random() * Math.PI,
stonePalette[Math.floor(random() * stonePalette.length)],
0.11
);
}
// One instanced mesh holds all dry-stone blocks.
const stoneMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
stoneMaterial,
stoneTransforms.length
);
stoneTransforms.forEach((s, i) => {
dummy.position.copy(s.position);
dummy.scale.copy(s.scale);
dummy.rotation.set(s.rotationX, s.rotationY, s.rotationZ);
dummy.updateMatrix();
stoneMesh.setMatrixAt(i, dummy.matrix);
stoneMesh.setColorAt(i, s.color);
});
stoneMesh.castShadow = true;
stoneMesh.receiveShadow = true;
scene.add(stoneMesh);
// -------------------------------------------------------------------------
// Curved passage floor
// -------------------------------------------------------------------------
const passageTiles = [];
for (let i = 0; i < 74; i++) {
const t = i / 73;
const outer = outerCurve.getPointAt(t);
const inner = innerCurve.getPointAt(t);
const p = outer.clone().lerp(inner, 0.5);
const tangent = outerCurve.getTangentAt(t).normalize();
const lateral = new THREE.Vector3(-tangent.z, 0, tangent.x);
const lane = rand(-0.28, 0.28);
p.addScaledVector(lateral, lane);
p.y = 0.115 + rand(-0.008, 0.008);
passageTiles.push({
position: p,
angle: Math.atan2(-tangent.z, tangent.x),
sx: rand(0.63, 0.83),
sz: rand(0.46, 0.70),
shade: rand(-0.08, 0.08)
});
}
const passageMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 0.07, 1),
new THREE.MeshStandardMaterial({
color: 0xbba67d,
roughness: 1
}),
passageTiles.length
);
passageTiles.forEach((p, i) => {
dummy.position.copy(p.position);
dummy.rotation.set(0, p.angle, 0);
dummy.scale.set(p.sx, 1, p.sz);
dummy.updateMatrix();
passageMesh.setMatrixAt(i, dummy.matrix);
passageMesh.setColorAt(
i,
new THREE.Color().setHSL(
0.105,
0.29,
0.61 + p.shade
)
);
});
passageMesh.receiveShadow = true;
scene.add(passageMesh);
// -------------------------------------------------------------------------
// Small voxel human figure to communicate human scale
// -------------------------------------------------------------------------
const visitor = new THREE.Group();
function personBox(size, position) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
personMaterial
);
mesh.position.copy(position);
mesh.castShadow = true;
visitor.add(mesh);
}
personBox(new THREE.Vector3(0.17, 0.70, 0.20),
new THREE.Vector3(-0.12, 0.35, 0));
personBox(new THREE.Vector3(0.17, 0.70, 0.20),
new THREE.Vector3( 0.12, 0.35, 0));
personBox(new THREE.Vector3(0.50, 0.62, 0.29),
new THREE.Vector3(0, 1.00, 0));
personBox(new THREE.Vector3(0.28, 0.29, 0.28),
new THREE.Vector3(0, 1.46, 0));
personBox(new THREE.Vector3(0.16, 0.44, 0.18),
new THREE.Vector3(-0.33, 1.02, 0));
personBox(new THREE.Vector3(0.16, 0.44, 0.18),
new THREE.Vector3( 0.33, 1.02, 0));
visitor.position.set(0, 0.08, -9.38);
visitor.rotation.y = -0.22;
scene.add(visitor);
// -------------------------------------------------------------------------
// Granite outcrops and voxel acacia trees
// -------------------------------------------------------------------------
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x77736a,
roughness: 1
});
function addBoulder(x, z, sx, sy, sz) {
const rock = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
rockMaterial
);
rock.position.set(x, sy * 0.5 - 0.01, z);
rock.rotation.y = rand(-0.4, 0.4);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
[
[-18.8, -6.2, 2.8, 1.3, 2.0],
[-20.2, 8.7, 2.0, 0.9, 1.4],
[ 15.2, -8.0, 2.7, 1.1, 1.7],
[ 17.8, 6.5, 2.2, 1.5, 1.8],
[ 8.8, 14.0, 2.8, 1.2, 1.9],
[-10.4, 14.3, 2.4, 1.0, 1.8]
].forEach(b => addBoulder(...b));
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.BoxGeometry(0.42 * scale, 2.8 * scale, 0.42 * scale),
woodMaterial
);
trunk.position.y = 1.4 * scale;
trunk.castShadow = true;
tree.add(trunk);
const branch1 = new THREE.Mesh(
new THREE.BoxGeometry(1.65 * scale, 0.27 * scale, 0.30 * scale),
woodMaterial
);
branch1.position.set(-0.45 * scale, 2.35 * scale, 0);
branch1.rotation.z = 0.16;
branch1.castShadow = true;
tree.add(branch1);
const branch2 = new THREE.Mesh(
new THREE.BoxGeometry(1.45 * scale, 0.25 * scale, 0.28 * scale),
woodMaterial
);
branch2.position.set(0.48 * scale, 2.55 * scale, 0.1 * scale);
branch2.rotation.z = -0.18;
branch2.castShadow = true;
tree.add(branch2);
const canopyParts = [
[-1.15, 2.95, 0.0, 2.25, 0.90, 1.70, leafMaterial],
[ 0.55, 3.10, 0.0, 2.55, 0.95, 1.80, leafLightMaterial],
[ 1.45, 2.85, 0.2, 1.65, 0.80, 1.35, leafMaterial],
[-0.10, 3.42, 0.0, 2.15, 0.76, 1.45, leafLightMaterial]
];
canopyParts.forEach(p => {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
p[3] * scale,
p[4] * scale,
p[5] * scale
),
p[6]
);
mesh.position.set(
p[0] * scale,
p[1] * scale,
p[2] * scale
);
mesh.castShadow = true;
mesh.receiveShadow = true;
tree.add(mesh);
});
tree.position.set(x, 0, z);
scene.add(tree);
}
addTree(-17.5, -5.3, 1.15);
addTree(-18.0, 13.2, 1.0);
addTree( 4.2, 14.7, 1.2);
addTree( 16.0, 10.5, 1.05);
addTree( 18.0, -5.5, 1.25);
addTree( -5.8, 15.3, 0.82);
// Sparse voxel grass.
const grassGeometry = new THREE.BoxGeometry(0.075, 0.43, 0.075);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x8d8953,
roughness: 1
});
const grassCount = 180;
const grassMesh = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
grassCount
);
for (let i = 0; i < grassCount; i++) {
const x = rand(-21.5, 21.5);
const z = rand(-17.5, 17.5);
// Keep the immediate passage visually clear.
if (Math.abs(x) < 2.2 && z < -7.3) {
dummy.position.set(x, 0.2, z);
} else {
dummy.position.set(x, 0.22, z);
}
dummy.rotation.set(rand(-0.2, 0.2), random() * Math.PI, rand(-0.2, 0.2));
dummy.scale.set(rand(0.7, 1.2), rand(0.7, 1.4), rand(0.7, 1.2));
dummy.updateMatrix();
grassMesh.setMatrixAt(i, dummy.matrix);
}
grassMesh.castShadow = true;
scene.add(grassMesh);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard, and touch
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-2.1, 1.1, 0.4),
desiredTarget: new THREE.Vector3(-2.1, 1.1, 0.4),
theta: 0.66,
phi: 0.98,
radius: window.innerWidth < 760 ? 53 : 42,
desiredTheta: 0.66,
desiredPhi: 0.98,
desiredRadius: window.innerWidth < 760 ? 53 : 42,
dragging: false,
panning: false,
pointerX: 0,
pointerY: 0,
pointerId: null
};
function updateCamera() {
controls.theta = THREE.MathUtils.lerp(
controls.theta,
controls.desiredTheta,
0.11
);
controls.phi = THREE.MathUtils.lerp(
controls.phi,
controls.desiredPhi,
0.11
);
controls.radius = THREE.MathUtils.lerp(
controls.radius,
controls.desiredRadius,
0.11
);
controls.target.lerp(controls.desiredTarget, 0.10);
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);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
controls.dragging = true;
controls.panning = event.button === 2 || event.shiftKey;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.pointerId = event.pointerId;
canvas.focus();
});
canvas.addEventListener("pointermove", event => {
if (!controls.dragging || event.pointerId !== controls.pointerId) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
if (controls.panning) {
const scale = controls.radius * 0.00135;
const right = new THREE.Vector3(
Math.cos(controls.theta),
0,
-Math.sin(controls.theta)
);
const forward = new THREE.Vector3(
-Math.sin(controls.theta),
0,
-Math.cos(controls.theta)
);
controls.desiredTarget
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, -dy * scale);
controls.desiredTarget.x = clamp(controls.desiredTarget.x, -18, 16);
controls.desiredTarget.z = clamp(controls.desiredTarget.z, -14, 14);
} else {
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = clamp(
controls.desiredPhi - dy * 0.005,
0.28,
1.38
);
}
});
function endPointer(event) {
if (event.pointerId !== controls.pointerId) return;
controls.dragging = false;
controls.panning = false;
controls.pointerId = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.desiredRadius = clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
18,
68
);
},
{ passive: false }
);
function resetCamera() {
controls.desiredTarget.set(-2.1, 1.1, 0.4);
controls.desiredTheta = 0.66;
controls.desiredPhi = 0.98;
controls.desiredRadius = window.innerWidth < 760 ? 53 : 42;
}
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (key === "r") {
resetCamera();
} else if (key === "arrowleft") {
controls.desiredTheta -= 0.08;
} else if (key === "arrowright") {
controls.desiredTheta += 0.08;
} else if (key === "arrowup") {
controls.desiredPhi = clamp(controls.desiredPhi - 0.06, 0.28, 1.38);
} else if (key === "arrowdown") {
controls.desiredPhi = clamp(controls.desiredPhi + 0.06, 0.28, 1.38);
} else if (key === "+" || key === "=") {
controls.desiredRadius = clamp(controls.desiredRadius - 2, 18, 68);
} else if (key === "-" || key === "_") {
controls.desiredRadius = clamp(controls.desiredRadius + 2, 18, 68);
} else {
return;
}
event.preventDefault();
});
// -------------------------------------------------------------------------
// Projected labels
// -------------------------------------------------------------------------
const hotspotData = [
{
element: document.querySelector("#label-entrance"),
anchor: new THREE.Vector3(0, 1.9, -10.4),
offset: [38, 32]
},
{
element: document.querySelector("#label-passage"),
anchor: new THREE.Vector3(-4.1, 1.4, -6.2),
offset: [-65, -6]
},
{
element: document.querySelector("#label-wall"),
anchor: new THREE.Vector3(-8.4, 3.7, 4.5),
offset: [-24, -38]
},
{
element: document.querySelector("#label-tower"),
anchor: new THREE.Vector3(-1.7, 5.6, 2.3),
offset: [42, -22]
},
{
element: document.querySelector("#label-secondary"),
anchor: new THREE.Vector3(-15.0, 2.2, 7.2),
offset: [-34, -15]
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
hotspotData.forEach(item => {
const projected = item.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!visible) {
item.element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * width + item.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + item.offset[1];
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
item.element.style.opacity = "1";
});
}
// -------------------------------------------------------------------------
// Resize and render
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
updateCamera();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```