Prompt specification
Build or customize the Three.js 3D scene "Tsingy limestone field and forest-edge scene" 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: Tsingy limestone field and forest-edge scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tsingy-limestone-field-and-forest-edge-scene-x3087
Scene Description Prompt:
Tsingy limestone field and forest-edge scene. Build a bounded referenced landscape with varied pinnacles, fracture corridors, and adjacent vegetation. Use a restricted footprint and readable paths rather than an overwhelming repeated spike grid. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (tsingy-limestone-field-and-forest-edge-scene-x3087):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tsingy — Voxel Limestone Pavilions</title>
<style>
:root {
--ink: #24302c;
--paper: rgba(247, 240, 220, 0.9);
--line: rgba(46, 57, 50, 0.22);
--limestone: #d8cfb5;
--fracture: #54554d;
--path: #b98950;
--forest: #426747;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9d2c8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
z-index: 0;
}
.panel {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-card {
top: 22px;
left: 22px;
width: min(330px, calc(100vw - 44px));
padding: 17px 18px 15px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 12px 40px rgba(39, 43, 34, 0.12);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 7px;
color: #66736a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3.2vw, 38px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 15px;
color: #59645d;
font-size: 12px;
line-height: 1.45;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #4b574f;
font-size: 10px;
letter-spacing: 0.04em;
}
.swatch {
width: 12px;
height: 12px;
flex: 0 0 auto;
border: 1px solid rgba(20, 30, 24, 0.2);
box-shadow: inset 2px 2px rgba(255, 255, 255, 0.22);
}
.swatch.limestone { background: var(--limestone); }
.swatch.fracture { background: var(--fracture); }
.swatch.path { background: var(--path); }
.swatch.forest { background: var(--forest); }
.footprint {
margin-top: 12px;
color: #778078;
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.controls-card {
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 10px 9px 13px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
color: #59635c;
font-size: 10px;
letter-spacing: 0.035em;
backdrop-filter: blur(10px);
pointer-events: auto;
}
#reset {
appearance: none;
border: 1px solid rgba(40, 52, 44, 0.25);
border-radius: 2px;
padding: 7px 9px;
background: rgba(255, 255, 255, 0.38);
color: #344039;
font: inherit;
font-size: 10px;
cursor: pointer;
}
#reset:hover {
background: rgba(255, 255, 255, 0.72);
}
.annotation {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
opacity: 0;
pointer-events: none;
transform: translate(10px, -50%);
transition: opacity 160ms ease;
white-space: nowrap;
}
.annotation::before {
content: "";
width: 19px;
height: 1px;
background: rgba(42, 54, 47, 0.62);
}
.annotation::after {
content: "";
position: absolute;
left: -2px;
width: 5px;
height: 5px;
border-radius: 50%;
background: #344039;
box-shadow: 0 0 0 3px rgba(248, 242, 223, 0.6);
}
.annotation span {
padding: 5px 7px;
border: 1px solid rgba(47, 58, 51, 0.18);
background: rgba(247, 240, 220, 0.79);
color: #39463e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(5px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #cbd3c9;
color: #47544c;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
.subtitle {
margin-bottom: 10px;
}
.legend {
gap: 6px 10px;
}
.controls-card {
right: 12px;
bottom: 12px;
}
.controls-card .desktop-hint {
display: none;
}
.annotation span {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="loading">Assembling limestone voxels</div>
<section class="panel title-card">
<div class="eyebrow">Bemaraha · Madagascar</div>
<h1>Tsingy<br>Stone Forest</h1>
<p class="subtitle">
A bounded voxel study of limestone pavilions, shadowed fracture corridors,
and the forest edge.
</p>
<div class="legend">
<div class="legend-item">
<i class="swatch limestone"></i>
Limestone
</div>
<div class="legend-item">
<i class="swatch fracture"></i>
Fracture
</div>
<div class="legend-item">
<i class="swatch path"></i>
Footpath
</div>
<div class="legend-item">
<i class="swatch forest"></i>
Forest edge
</div>
</div>
<div class="footprint">31 × 23 voxel footprint · not to scale</div>
</section>
<div class="annotation" id="label-pinnacles">
<span>Limestone pavilions</span>
</div>
<div class="annotation" id="label-fracture">
<span>Fracture corridor</span>
</div>
<div class="annotation" id="label-forest">
<span>Forest edge</span>
</div>
<div class="panel controls-card">
<span class="desktop-hint">Drag to orbit · shift-drag to pan · wheel to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.03;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel landscape of the Tsingy limestone stone forest"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xc8c7b6, 46, 96);
// Procedural gradient sky, generated without external assets.
const skyCanvas = document.createElement("canvas");
skyCanvas.width = 8;
skyCanvas.height = 512;
const skyContext = skyCanvas.getContext("2d");
const skyGradient = skyContext.createLinearGradient(0, 0, 0, 512);
skyGradient.addColorStop(0, "#76979c");
skyGradient.addColorStop(0.48, "#b8c7bf");
skyGradient.addColorStop(0.76, "#ded4ba");
skyGradient.addColorStop(1, "#c5b89b");
skyContext.fillStyle = skyGradient;
skyContext.fillRect(0, 0, 8, 512);
const skyTexture = new THREE.CanvasTexture(skyCanvas);
skyTexture.colorSpace = THREE.SRGBColorSpace;
scene.background = skyTexture;
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
140
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe6f0e8, 0x71634b, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.15);
sun.position.set(-16, 27, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -29;
sun.shadow.camera.right = 29;
sun.shadow.camera.top = 27;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd6da, 0.75);
fill.position.set(20, 12, -16);
scene.add(fill);
// A neutral ground catches the bounded model's shadow.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: 0xcfc3a8,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -3.52;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Deterministic helpers
// ------------------------------------------------------------
function mulberry32(seed) {
return function random() {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(73129);
function fract(value) {
return value - Math.floor(value);
}
function noise2(x, z, seed = 0) {
return fract(
Math.sin(x * 127.1 + z * 311.7 + seed * 74.73) * 43758.5453123
);
}
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function distanceToSegment(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
if (lengthSquared === 0) {
return Math.hypot(px - ax, pz - az);
}
const t = clamp(
((px - ax) * dx + (pz - az) * dz) / lengthSquared,
0,
1
);
const closestX = ax + t * dx;
const closestZ = az + t * dz;
return Math.hypot(px - closestX, pz - closestZ);
}
function distanceToLines(x, z, lines) {
let minimum = Infinity;
for (const line of lines) {
for (let i = 0; i < line.length - 1; i++) {
const a = line[i];
const b = line[i + 1];
minimum = Math.min(
minimum,
distanceToSegment(x, z, a[0], a[1], b[0], b[1])
);
}
}
return minimum;
}
// ------------------------------------------------------------
// Spatial layout: readable fracture network and footpaths
// ------------------------------------------------------------
const FRACTURE_LINES = [
[
[-13, 7],
[-9, 5],
[-7, 1],
[-3, 0],
[1, -1],
[4, -4],
[8, -5],
[11, -8]
],
[
[-12, -7],
[-8, -6],
[-6, -3],
[-8, 0],
[-10, 3]
],
[
[2, 8],
[3, 4],
[6, 1],
[8, -2]
]
];
const PATH_LINES = [
[
[-2, 10],
[-3, 7],
[-6, 5],
[-5, 2],
[-1, 0],
[1, -2],
[6, -4],
[10, -6]
],
[
[-6, 5],
[-10, 3],
[-11, 0],
[-9, -4],
[-8, -7]
],
[
[2, 8],
[3, 4],
[5, 1],
[8, -1]
]
];
function insideFootprint(x, z) {
if (Math.abs(x) > 15 || Math.abs(z) > 11) {
return false;
}
// Rounded/chamfered corners make the terrain read as a bounded model.
const cornerX = Math.max(0, Math.abs(x) - 12.5);
const cornerZ = Math.max(0, Math.abs(z) - 8.5);
return cornerX * cornerX + cornerZ * cornerZ <= 7;
}
function surfaceHeight(x, z) {
const fractureDistance = distanceToLines(x, z, FRACTURE_LINES);
const pathDistance = distanceToLines(x, z, PATH_LINES);
let height = 0;
const localNoise = noise2(x * 0.16, z * 0.16, 19);
if (localNoise > 0.91) height = 1;
if (localNoise < 0.075) height = -1;
// Both routes and fractures are one voxel lower.
if (fractureDistance < 0.78) height = -1;
if (pathDistance < 0.66) height = -1;
return height;
}
// ------------------------------------------------------------
// Voxel storage
// ------------------------------------------------------------
const rockBlocks = [];
const trunkBlocks = [];
const foliageBlocks = [];
function pushRock(x, y, z, color) {
rockBlocks.push({
position: new THREE.Vector3(x, y * 0.9, z),
color
});
}
const limestoneColors = [
new THREE.Color(0xd8ceb3),
new THREE.Color(0xc8bb9c),
new THREE.Color(0xe0d7bd),
new THREE.Color(0xb9aa8d)
];
const strataColor = new THREE.Color(0xb2a487);
// ------------------------------------------------------------
// Bounded limestone substrate
// ------------------------------------------------------------
const surfaceMap = new Map();
for (let x = -15; x <= 15; x++) {
for (let z = -11; z <= 11; z++) {
if (!insideFootprint(x, z)) continue;
const surface = surfaceHeight(x, z);
surfaceMap.set(`${x},${z}`, surface);
const fractureDistance = distanceToLines(x, z, FRACTURE_LINES);
const pathDistance = distanceToLines(x, z, PATH_LINES);
for (let y = -3; y <= surface; y++) {
const color = new THREE.Color();
if (y === surface) {
if (pathDistance < 0.53) {
color.set(pathDistance < 0.22 ? 0xc9a16a : 0xb98950);
} else if (fractureDistance < 0.78) {
color.set(0x56574f);
} else {
color.set(0xbeb294);
}
} else {
const band = (y + 4) % 3;
color.set(band === 0 ? 0x958a75 : band === 1 ? 0xa59a82 : 0x9b9079);
}
const variation = noise2(x * 0.83, z * 0.83 + y * 0.47, 29);
color.offsetHSL(
(variation - 0.5) * 0.018,
(variation - 0.5) * 0.065,
(variation - 0.5) * 0.105
);
pushRock(x, y, z, color);
}
}
}
// ------------------------------------------------------------
// Irregular limestone pavilion clusters
//
// Hand-placed, overlapping masses create a stone forest without
// relying on a regular repeated spike grid.
// ------------------------------------------------------------
const PAVILIONS = [
{ x: -10.8, z: -4.7, rx: 1.8, rz: 1.6, h: 6.5, seed: 11 },
{ x: -7.5, z: -5.5, rx: 1.4, rz: 2.0, h: 8.0, seed: 19 },
{ x: -4.7, z: -7.1, rx: 1.7, rz: 1.3, h: 5.6, seed: 31 },
{ x: -11.2, z: 1.2, rx: 1.4, rz: 1.7, h: 5.2, seed: 43 },
{ x: -8.4, z: 2.4, rx: 1.8, rz: 1.4, h: 7.0, seed: 57 },
{ x: -3.3, z: -2.5, rx: 1.4, rz: 1.6, h: 8.8, seed: 71 },
{ x: 1.4, z: -4.8, rx: 2.2, rz: 1.6, h: 6.6, seed: 89 },
{ x: 5.6, z: -6.8, rx: 1.5, rz: 2.0, h: 8.2, seed: 101 },
{ x: 8.1, z: -1.7, rx: 1.9, rz: 1.5, h: 6.1, seed: 113 },
{ x: 5.2, z: 2.4, rx: 1.7, rz: 1.8, h: 7.4, seed: 127 },
{ x: 1.0, z: 4.5, rx: 1.4, rz: 1.5, h: 5.4, seed: 139 },
{ x: 10.0, z: 3.0, rx: 1.2, rz: 1.4, h: 4.6, seed: 151 }
];
const formationHeights = new Map();
for (const pavilion of PAVILIONS) {
const extentX = Math.ceil(pavilion.rx * 1.4);
const extentZ = Math.ceil(pavilion.rz * 1.4);
for (let x = Math.floor(pavilion.x - extentX);
x <= Math.ceil(pavilion.x + extentX); x++) {
for (let z = Math.floor(pavilion.z - extentZ);
z <= Math.ceil(pavilion.z + extentZ); z++) {
if (!insideFootprint(x, z) || x > 10.4) continue;
const normalizedX = (x - pavilion.x) / pavilion.rx;
const normalizedZ = (z - pavilion.z) / pavilion.rz;
const radius = Math.hypot(normalizedX, normalizedZ);
const angle = Math.atan2(normalizedZ, normalizedX);
const edge =
0.88 +
0.14 * Math.sin(angle * 3 + pavilion.seed * 0.17) +
0.11 * noise2(x * 0.73, z * 0.73, pavilion.seed);
if (radius > edge) continue;
const fractureDistance = distanceToLines(x, z, FRACTURE_LINES);
const pathDistance = distanceToLines(x, z, PATH_LINES);
// Keep the corridors open and legible.
if (fractureDistance < 0.86 || pathDistance < 0.94) continue;
// Small missing columns introduce weathering and broken faces.
if (
radius > 0.42 &&
noise2(x * 1.7, z * 1.7, pavilion.seed + 5) < 0.055
) {
continue;
}
const core = 1 - radius / Math.max(edge, 0.01);
let height =
pavilion.h * (0.18 + 0.82 * Math.pow(Math.max(core, 0), 0.56));
height +=
(noise2(x * 0.91, z * 0.91, pavilion.seed + 9) - 0.5) * 2.3;
if (radius > 0.72) height -= 0.9;
height = Math.max(1, Math.round(height));
const key = `${x},${z}`;
formationHeights.set(
key,
Math.max(formationHeights.get(key) || 0, height)
);
}
}
}
for (const [key, height] of formationHeights) {
const [x, z] = key.split(",").map(Number);
const surface = surfaceMap.get(key) ?? 0;
const fractureDistance = distanceToLines(x, z, FRACTURE_LINES);
for (let relativeHeight = 1; relativeHeight <= height; relativeHeight++) {
const y = surface + relativeHeight;
const variation = noise2(
x * 0.67 + relativeHeight * 0.13,
z * 0.71,
211
);
const color = new THREE.Color(
relativeHeight >= height - 1 ? 0xe0d6ba : 0xc9bea1
);
if (relativeHeight % 4 === 0) {
color.lerp(strataColor, 0.2);
}
color.offsetHSL(
(variation - 0.5) * 0.018,
(variation - 0.5) * 0.07,
(variation - 0.5) * 0.115 + relativeHeight * 0.003
);
if (fractureDistance < 1.35) {
color.multiplyScalar(0.8);
}
pushRock(x, y, z, color);
}
}
// ------------------------------------------------------------
// Voxel forest edge
// ------------------------------------------------------------
const treeSpots = [];
for (let attempt = 0; attempt < 120 && treeSpots.length < 28; attempt++) {
const x = 11.25 + random() * 2.55;
const z = -9.6 + random() * 19.2;
if (distanceToLines(x, z, PATH_LINES) < 1.05) continue;
if (distanceToLines(x, z, FRACTURE_LINES) < 0.9) continue;
if (formationHeights.has(`${Math.round(x)},${Math.round(z)}`)) continue;
let tooClose = false;
for (const tree of treeSpots) {
if (Math.hypot(tree.x - x, tree.z - z) < 1.45) {
tooClose = true;
break;
}
}
if (tooClose) continue;
treeSpots.push({
x,
z,
levels: 3 + Math.floor(random() * 4),
tone: random()
});
}
const foliagePalette = [
new THREE.Color(0x315b3c),
new THREE.Color(0x426a46),
new THREE.Color(0x52784a),
new THREE.Color(0x658552),
new THREE.Color(0x718a55)
];
function addTree(tree) {
const roundedX = Math.round(tree.x);
const roundedZ = Math.round(tree.z);
const surface = surfaceMap.get(`${roundedX},${roundedZ}`) ?? 0;
const trunkBottom = surface * 0.9 + 0.45;
for (let level = 0; level < tree.levels; level++) {
const color = new THREE.Color(0x69513a);
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.07,
(random() - 0.5) * 0.09
);
trunkBlocks.push({
position: new THREE.Vector3(
tree.x,
trunkBottom + (level + 0.5) * 0.68,
tree.z
),
color
});
}
const canopyBase = trunkBottom + tree.levels * 0.68 - 0.1;
for (let dy = 0; dy < 2; dy++) {
for (let dx = -1; dx <= 1; dx++) {
for (let dz = -1; dz <= 1; dz++) {
const edgeCell = Math.abs(dx) + Math.abs(dz) === 2;
const keepProbability = dy === 0 && edgeCell ? 0.58 : 0.82;
if (random() > keepProbability) continue;
const color = foliagePalette[
Math.floor(random() * foliagePalette.length)
].clone();
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.07,
(random() - 0.5) * 0.075
);
foliageBlocks.push({
position: new THREE.Vector3(
tree.x + dx * 0.74,
canopyBase + dy * 0.72,
tree.z + dz * 0.74
),
color
});
}
}
}
}
treeSpots.forEach(addTree);
// Low scrub cubes soften the transition from bare rock to forest.
for (let attempt = 0; attempt < 80; attempt++) {
const x = 8.8 + random() * 4.8;
const z = -10 + random() * 20;
if (distanceToLines(x, z, PATH_LINES) < 0.85) continue;
if (distanceToLines(x, z, FRACTURE_LINES) < 0.85) continue;
const roundedX = Math.round(x);
const roundedZ = Math.round(z);
const surface = surfaceMap.get(`${roundedX},${roundedZ}`) ?? 0;
const count = 2 + Math.floor(random() * 3);
for (let i = 0; i < count; i++) {
const color = foliagePalette[
Math.floor(random() * foliagePalette.length)
].clone();
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.06,
(random() - 0.5) * 0.07
);
foliageBlocks.push({
position: new THREE.Vector3(
x + (random() - 0.5) * 0.55,
surface * 0.9 + 0.68 + random() * 0.22,
z + (random() - 0.5) * 0.55
),
scale: new THREE.Vector3(
0.42 + random() * 0.18,
0.36 + random() * 0.16,
0.42 + random() * 0.18
),
color
});
}
}
// ------------------------------------------------------------
// Instanced mesh construction
// ------------------------------------------------------------
function createInstancedMesh(blocks, geometry, material) {
const mesh = new THREE.InstancedMesh(
geometry,
material,
blocks.length
);
const helper = new THREE.Object3D();
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];
helper.position.copy(block.position);
helper.rotation.set(0, 0, 0);
helper.scale.copy(block.scale || new THREE.Vector3(1, 1, 1));
helper.updateMatrix();
mesh.setMatrixAt(i, helper.matrix);
mesh.setColorAt(i, block.color);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
return mesh;
}
createInstancedMesh(
rockBlocks,
new THREE.BoxGeometry(0.94, 0.88, 0.94),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0,
flatShading: true
})
);
createInstancedMesh(
trunkBlocks,
new THREE.BoxGeometry(0.39, 0.68, 0.39),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0,
flatShading: true
})
);
createInstancedMesh(
foliageBlocks,
new THREE.BoxGeometry(0.82, 0.72, 0.82),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.93,
metalness: 0,
flatShading: true
})
);
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, touch pinch
// ------------------------------------------------------------
const defaultView = {
theta: 0.76,
phi: 1.0,
radius: 38,
target: new THREE.Vector3(0, 2.0, 0)
};
const currentView = {
theta: defaultView.theta,
phi: defaultView.phi,
radius: defaultView.radius,
target: defaultView.target.clone()
};
const desiredView = {
theta: defaultView.theta,
phi: defaultView.phi,
radius: defaultView.radius,
target: defaultView.target.clone()
};
const pointers = new Map();
let dragMode = "orbit";
let previousPinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
if (pointers.size === 2) {
const positions = [...pointers.values()];
previousPinchDistance = Math.hypot(
positions[0].x - positions[1].x,
positions[0].y - positions[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const positions = [...pointers.values()];
const pinchDistance = Math.hypot(
positions[0].x - positions[1].x,
positions[0].y - positions[1].y
);
if (previousPinchDistance > 0 && pinchDistance > 0) {
desiredView.radius *=
previousPinchDistance / pinchDistance;
desiredView.radius = clamp(desiredView.radius, 24, 58);
}
previousPinchDistance = pinchDistance;
return;
}
if (dragMode === "orbit") {
desiredView.theta -= dx * 0.005;
desiredView.phi = clamp(
desiredView.phi - dy * 0.005,
0.32,
1.38
);
} else {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(
-Math.sin(desiredView.theta),
0,
-Math.cos(desiredView.theta)
);
const panScale = desiredView.radius * 0.00145;
desiredView.target.addScaledVector(right, -dx * panScale);
desiredView.target.addScaledVector(forward, dy * panScale);
desiredView.target.x = clamp(desiredView.target.x, -12, 12);
desiredView.target.z = clamp(desiredView.target.z, -10, 10);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const multiplier = Math.exp(event.deltaY * 0.001);
desiredView.radius = clamp(
desiredView.radius * multiplier,
24,
58
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
desiredView.theta = defaultView.theta;
desiredView.phi = defaultView.phi;
desiredView.radius = defaultView.radius;
desiredView.target.copy(defaultView.target);
});
function updateCamera() {
const damping = 0.085;
currentView.theta +=
(desiredView.theta - currentView.theta) * damping;
currentView.phi +=
(desiredView.phi - currentView.phi) * damping;
currentView.radius +=
(desiredView.radius - currentView.radius) * damping;
currentView.target.lerp(desiredView.target, damping);
const sinPhiRadius =
Math.sin(currentView.phi) * currentView.radius;
camera.position.set(
currentView.target.x +
sinPhiRadius * Math.sin(currentView.theta),
currentView.target.y +
Math.cos(currentView.phi) * currentView.radius,
currentView.target.z +
sinPhiRadius * Math.cos(currentView.theta)
);
camera.lookAt(currentView.target);
camera.updateMatrixWorld();
}
// ------------------------------------------------------------
// World-anchored field annotations
// ------------------------------------------------------------
const annotations = [
{
element: document.getElementById("label-pinnacles"),
position: new THREE.Vector3(-4.0, 8.0, -4.0)
},
{
element: document.getElementById("label-fracture"),
position: new THREE.Vector3(0.3, 0.5, -1.4)
},
{
element: document.getElementById("label-forest"),
position: new THREE.Vector3(13.0, 5.2, 1.8)
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
for (const annotation of annotations) {
projected.copy(annotation.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
annotation.element.style.opacity = visible ? "0.92" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
}
}
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = camera.aspect < 0.75 ? 52 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
});
camera.fov = camera.aspect < 0.75 ? 52 : 42;
camera.updateProjectionMatrix();
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => {
document.getElementById("loading").remove();
}, 400);
});
animate();
</script>
</body>
</html>
```