Prompt specification
Build or customize the Three.js 3D scene "Triangulation between visible landmarks" 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: Triangulation between visible landmarks
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/triangulation-between-visible-landmarks-x1327
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts landmark visibility across terrain. Arrange three towers around a valley and an observer with bearing rays. Show an approximate map position from intersecting bearings, with uncertainty represented as a small region. Voxel style.
Working Three.js Starter (triangulation-between-visible-landmarks-x1327):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Valley Bearing Triangulation</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(12, 22, 28, 0.82);
--line: rgba(255, 255, 255, 0.14);
--text: #f1f7f4;
--muted: #a9b9b5;
--mint: #52f0b3;
--cyan: #30d8c2;
--amber: #ffca58;
--coral: #ff7278;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfd1d5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(5, 16, 20, 0.22);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#overview {
position: absolute;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
border-radius: 16px;
overflow: hidden;
}
.header {
padding: 18px 19px 16px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 5px;
font-size: 23px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
}
.readout {
padding: 13px 18px;
border-right: 1px solid var(--line);
}
.readout:nth-child(2n) { border-right: 0; }
.readout:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
.readout .label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.readout strong {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13px;
font-weight: 650;
}
.legend {
display: grid;
gap: 9px;
padding: 15px 18px 17px;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #dce8e4;
font-size: 11px;
}
.swatch {
width: 18px;
height: 4px;
border-radius: 3px;
box-shadow: 0 0 10px currentColor;
}
.swatch.cyan { color: var(--cyan); background: var(--cyan); }
.swatch.amber { color: var(--amber); background: var(--amber); }
.swatch.coral { color: var(--coral); background: var(--coral); }
.swatch.mint { color: var(--mint); background: var(--mint); }
#status {
position: absolute;
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 12px var(--mint);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.45; transform: scale(0.75); }
}
#controls {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
gap: 7px;
padding: 8px;
border-radius: 13px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
padding: 9px 12px;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms, border-color 160ms, transform 160ms;
}
button:hover {
background: rgba(82, 240, 179, 0.12);
border-color: rgba(82, 240, 179, 0.45);
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
#hint {
position: absolute;
right: 22px;
bottom: 22px;
max-width: 320px;
padding: 11px 14px;
border-radius: 10px;
color: #d5e2de;
font-size: 10px;
line-height: 1.55;
text-align: right;
}
kbd {
display: inline-block;
min-width: 20px;
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 4px;
background: rgba(255, 255, 255, 0.07);
color: white;
font: inherit;
font-size: 9px;
text-align: center;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #bfd1d5;
color: #19332f;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 450ms ease, visibility 450ms;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
#overview {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
.header { padding: 13px 15px; }
h1 { font-size: 19px; }
.readouts, .legend { display: none; }
#status {
top: auto;
right: auto;
left: 12px;
bottom: 72px;
}
#controls {
left: 12px;
right: 12px;
bottom: 12px;
justify-content: center;
}
#hint { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section id="overview" class="panel">
<div class="header">
<div class="eyebrow">Survey Visualization / Valley 07</div>
<h1>Bearing Triangulation</h1>
<div class="subtitle">
Three landmark towers observe the same obscured region.
Their projected bearings produce an approximate ground fix.
</div>
</div>
<div class="readouts">
<div class="readout">
<span class="label">Estimated Position</span>
<strong id="positionReadout">CALCULATING</strong>
</div>
<div class="readout">
<span class="label">Uncertainty</span>
<strong>± 18 m</strong>
</div>
<div class="readout">
<span class="label">Observer Range</span>
<strong id="rangeReadout">—</strong>
</div>
<div class="readout">
<span class="label">Solution</span>
<strong>3-BEARING FIX</strong>
</div>
</div>
<div class="legend">
<div class="legend-row">
<span class="swatch cyan"></span>
<span>T1 — northwest ridge station</span>
</div>
<div class="legend-row">
<span class="swatch amber"></span>
<span>T2 — north valley station</span>
</div>
<div class="legend-row">
<span class="swatch coral"></span>
<span>T3 — east ridge station</span>
</div>
<div class="legend-row">
<span class="swatch mint"></span>
<span>Intersected position and uncertainty region</span>
</div>
</div>
</section>
<div id="status" class="panel">
<span class="status-dot"></span>
<span>Tracking active</span>
</div>
<nav id="controls" class="panel" aria-label="Camera controls">
<button id="resetView" type="button">Overview</button>
<button id="topView" type="button">Top Map</button>
<button id="fixView" type="button">Focus Fix</button>
<button id="observerView" type="button">Observer</button>
</nav>
<div id="hint" class="panel">
Drag to orbit · Scroll to zoom · Shift-drag to pan<br />
<kbd>R</kbd> overview
<kbd>T</kbd> top
<kbd>F</kbd> fix
</div>
</div>
<div id="loading">Building voxel terrain…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfd1d5);
scene.fog = new THREE.Fog(0xbfd1d5, 58, 125);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
220
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneRoot.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xeaf7ff, 0x56624d, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d2, 3.25);
sun.position.set(-28, 48, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 125;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaed8ff, 0.75);
fill.position.set(25, 18, -30);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, width, mat) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, mat);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(width, width, length);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
mesh.castShadow = false;
mesh.receiveShadow = false;
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(text, color = "#ffffff", width = 7.0) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
roundedRect(ctx, 12, 22, 488, 84, 18);
ctx.fillStyle = "rgba(10, 23, 28, 0.84)";
ctx.fill();
ctx.strokeStyle = color;
ctx.globalAlpha = 0.68;
ctx.lineWidth = 3;
ctx.stroke();
ctx.globalAlpha = 1;
ctx.fillStyle = color;
ctx.font = "700 39px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 30;
return sprite;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
// ---------------------------------------------------------------------
// Voxel terrain
// ---------------------------------------------------------------------
const CELL = 1.45;
const GRID = 51;
const HALF = (GRID - 1) / 2;
const BASE_Y = -1.3;
function riverX(z) {
return 2.6 * Math.sin(z * 0.115) + 0.9 * Math.sin(z * 0.29);
}
function terrainHeight(x, z) {
const distance = Math.abs(x - riverX(z));
if (distance < 1.35) return 0.08;
let h = 0.45;
h += Math.pow(Math.max(0, distance - 1.7) / 23, 1.45) * 9.2;
h += Math.max(0, (Math.abs(x) - 26) / 10) * 5;
h += 0.27 * Math.sin(x * 1.31 + z * 0.77);
h += 0.18 * Math.sin(x * 0.43 - z * 1.12);
return Math.max(0.08, h);
}
const terrain = new THREE.InstancedMesh(
new THREE.BoxGeometry(CELL * 0.94, 1, CELL * 0.94),
material(0xffffff, { vertexColors: true })
);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
const dummy = new THREE.Object3D();
const waterCells = [];
for (let iz = 0; iz < GRID; iz++) {
for (let ix = 0; ix < GRID; ix++) {
const x = (ix - HALF) * CELL;
const z = (iz - HALF) * CELL;
const y = terrainHeight(x, z);
const columnHeight = y - BASE_Y;
dummy.position.set(x, BASE_Y + columnHeight / 2, z);
dummy.scale.set(1, columnHeight, 1);
dummy.updateMatrix();
terrain.setMatrixAt(iz * GRID + ix, dummy.matrix);
const color = new THREE.Color();
if (Math.abs(x - riverX(z)) < 1.35) {
color.set(0x547b79);
waterCells.push([x, z]);
} else if (y > 11) {
color.set(0x79837d).lerp(new THREE.Color(0x9ca49d), (y - 11) / 18);
} else if (y > 5) {
color.set(0x71815b).lerp(new THREE.Color(0x7e8779), (y - 5) / 8);
} else {
color.set(0x849766).lerp(new THREE.Color(0x617c50), y / 7);
}
const variation = 0.9 +
0.08 * Math.sin(ix * 12.7 + iz * 7.3) +
0.04 * Math.cos(ix * 4.1 - iz * 9.6);
color.multiplyScalar(variation);
terrain.setColorAt(iz * GRID + ix, color);
}
}
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
const base = box(
scene,
[GRID * CELL + 2, 1.1, GRID * CELL + 2],
[0, BASE_Y - 0.55, 0],
material(0x3f504b),
false
);
base.receiveShadow = true;
const water = new THREE.InstancedMesh(
new THREE.BoxGeometry(CELL * 0.95, 0.08, CELL * 0.95),
new THREE.MeshStandardMaterial({
color: 0x4d9fa4,
roughness: 0.28,
metalness: 0.12,
transparent: true,
opacity: 0.84
})
);
waterCells.forEach(([x, z], i) => {
dummy.position.set(x, 0.15, z);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
water.setMatrixAt(i, dummy.matrix);
});
water.instanceMatrix.needsUpdate = true;
water.receiveShadow = true;
scene.add(water);
// ---------------------------------------------------------------------
// Voxel trees and shrubs
// ---------------------------------------------------------------------
const treePositions = [
[-15, -8], [3, -17], [17, 9], [-7, 18]
];
const random = seededRandom(7319);
const trunkMat = material(0x5a4936);
const leafMatA = material(0x3f7048);
const leafMatB = material(0x527f4d);
function clearOfFeatures(x, z, radius = 4) {
if (Math.hypot(x - 2.4, z - 1) < radius) return false;
return !treePositions.some(([tx, tz]) => Math.hypot(x - tx, z - tz) < radius);
}
let treesMade = 0;
for (let attempt = 0; attempt < 240 && treesMade < 48; attempt++) {
const x = (random() - 0.5) * 58;
const z = (random() - 0.5) * 58;
const y = terrainHeight(x, z);
if (y < 1.1 || y > 8.5) continue;
if (Math.abs(x - riverX(z)) < 3.4) continue;
if (!clearOfFeatures(x, z, 3.3)) continue;
const scale = 0.75 + random() * 0.65;
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
box(group, [0.28, 1.15, 0.28], [0, 0.575, 0], trunkMat);
box(group, [1.25, 0.85, 1.25], [0, 1.45, 0], random() > 0.5 ? leafMatA : leafMatB);
box(group, [0.85, 0.65, 0.85], [0, 2.05, 0], leafMatA);
scene.add(group);
treesMade++;
}
// ---------------------------------------------------------------------
// Triangulation calculation
// ---------------------------------------------------------------------
const nominalTarget = { x: 2.4, z: 1.0 };
const towerSpecs = [
{
id: "T1",
x: -15,
z: -8,
color: 0x30d8c2,
css: "#30d8c2",
noise: 0.013
},
{
id: "T2",
x: 3,
z: -17,
color: 0xffca58,
css: "#ffca58",
noise: -0.010
},
{
id: "T3",
x: 17,
z: 9,
color: 0xff7278,
css: "#ff7278",
noise: 0.009
}
];
function measuredDirection(tower) {
const dx = nominalTarget.x - tower.x;
const dz = nominalTarget.z - tower.z;
const angle = Math.atan2(dz, dx) + tower.noise;
return { x: Math.cos(angle), z: Math.sin(angle) };
}
function cross2(a, b) {
return a.x * b.z - a.z * b.x;
}
function subtract2(a, b) {
return { x: a.x - b.x, z: a.z - b.z };
}
function intersectLines(p1, d1, p2, d2) {
const denominator = cross2(d1, d2);
if (Math.abs(denominator) < 0.000001) {
return {
x: (p1.x + p2.x) / 2,
z: (p1.z + p2.z) / 2
};
}
const delta = subtract2(p2, p1);
const t = cross2(delta, d2) / denominator;
return {
x: p1.x + d1.x * t,
z: p1.z + d1.z * t
};
}
towerSpecs.forEach((tower) => {
tower.origin = { x: tower.x, z: tower.z };
tower.direction = measuredDirection(tower);
tower.bearing =
(THREE.MathUtils.radToDeg(
Math.atan2(tower.direction.x, -tower.direction.z)
) + 360) % 360;
});
const i12 = intersectLines(
towerSpecs[0].origin, towerSpecs[0].direction,
towerSpecs[1].origin, towerSpecs[1].direction
);
const i23 = intersectLines(
towerSpecs[1].origin, towerSpecs[1].direction,
towerSpecs[2].origin, towerSpecs[2].direction
);
const i31 = intersectLines(
towerSpecs[2].origin, towerSpecs[2].direction,
towerSpecs[0].origin, towerSpecs[0].direction
);
const estimatedFix = {
x: (i12.x + i23.x + i31.x) / 3,
z: (i12.z + i23.z + i31.z) / 3
};
const fixGroundY = terrainHeight(estimatedFix.x, estimatedFix.z);
const fixPoint = new THREE.Vector3(
estimatedFix.x,
fixGroundY + 0.38,
estimatedFix.z
);
document.querySelector("#positionReadout").textContent =
`E ${(estimatedFix.x + 500).toFixed(1)} / N ${(estimatedFix.z + 500).toFixed(1)}`;
// ---------------------------------------------------------------------
// Towers
// ---------------------------------------------------------------------
const towerObjects = [];
function addTower(spec, index) {
const group = new THREE.Group();
const groundY = terrainHeight(spec.x, spec.z);
group.position.set(spec.x, groundY, spec.z);
const towerMat = material(spec.color);
const darkMat = material(0x263b3c);
const paleMat = material(0xdce8df);
box(group, [3.5, 0.42, 3.5], [0, 0.21, 0], darkMat);
box(group, [2.75, 0.28, 2.75], [0, 0.56, 0], paleMat);
for (let level = 0; level < 8; level++) {
const y = 0.7 + level * 0.78;
const size = 1.55 - level * 0.035;
box(group, [size, 0.72, size], [0, y, 0], towerMat);
if (level % 3 === 1) {
box(group, [size + 0.08, 0.13, size + 0.08], [0, y + 0.25, 0], darkMat);
}
}
box(group, [2.35, 0.28, 2.35], [0, 7.12, 0], paleMat);
box(group, [0.18, 1.35, 0.18], [0, 7.92, 0], darkMat);
const beaconMat = material(spec.color, {
emissive: spec.color,
emissiveIntensity: 1.5,
roughness: 0.35
});
const beacon = box(
group,
[0.44, 0.44, 0.44],
[0, 8.65, 0],
beaconMat,
false
);
const label = makeLabel(
`${spec.id} / ${Math.round(spec.bearing).toString().padStart(3, "0")}°`,
spec.css,
5.7
);
label.position.set(0, 10.25, 0);
group.add(label);
scene.add(group);
const worldBeacon = new THREE.Vector3(
spec.x,
groundY + 8.65,
spec.z
);
towerObjects.push({ group, beacon, beaconMat, worldBeacon });
// Main elevated bearing ray, converging on the estimated position.
const rayMat = new THREE.MeshBasicMaterial({
color: spec.color,
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
});
const ray = beamBetween(worldBeacon, fixPoint, 0.075, rayMat);
ray.renderOrder = 12;
scene.add(ray);
// Faint planar projection of the measured bearing.
const overlayY = fixGroundY + 0.15;
const overlayStart = new THREE.Vector3(spec.x, overlayY, spec.z);
const overlayEnd = new THREE.Vector3(
spec.x + spec.direction.x * 62,
overlayY,
spec.z + spec.direction.z * 62
);
const projectedMat = new THREE.MeshBasicMaterial({
color: spec.color,
transparent: true,
opacity: 0.16,
depthTest: false,
depthWrite: false
});
const projectedRay = beamBetween(
overlayStart,
overlayEnd,
0.034,
projectedMat
);
projectedRay.renderOrder = 9;
scene.add(projectedRay);
const guideMat = new THREE.MeshBasicMaterial({
color: spec.color,
transparent: true,
opacity: 0.12,
depthTest: false,
depthWrite: false
});
const guide = beamBetween(
new THREE.Vector3(spec.x, groundY + 0.5, spec.z),
overlayStart,
0.035,
guideMat
);
guide.renderOrder = 8;
scene.add(guide);
}
towerSpecs.forEach(addTower);
// Small markers at the three pairwise line intersections.
[i12, i23, i31].forEach((intersection) => {
const markerMat = new THREE.MeshBasicMaterial({
color: 0xe8fff5,
transparent: true,
opacity: 0.75,
depthTest: false
});
const marker = box(
scene,
[0.28, 0.28, 0.28],
[intersection.x, fixGroundY + 0.16, intersection.z],
markerMat,
false
);
marker.renderOrder = 14;
});
// ---------------------------------------------------------------------
// Observer
// ---------------------------------------------------------------------
const observerX = -7;
const observerZ = 18;
const observerY = terrainHeight(observerX, observerZ);
const observer = new THREE.Group();
observer.position.set(observerX, observerY, observerZ);
const darkCloth = material(0x23383a);
const coat = material(0xe6eee8);
const skin = material(0xd79b75);
const hatMat = material(0xf2a24a);
box(observer, [0.38, 1.05, 0.42], [-0.24, 0.52, 0], darkCloth);
box(observer, [0.38, 1.05, 0.42], [0.24, 0.52, 0], darkCloth);
box(observer, [0.88, 1.15, 0.52], [0, 1.55, 0], coat);
box(observer, [0.92, 0.23, 0.58], [0, 1.82, 0], hatMat);
box(observer, [0.58, 0.58, 0.58], [0, 2.42, 0], skin);
box(observer, [0.64, 0.18, 0.64], [0, 2.72, 0], hatMat);
box(observer, [0.22, 0.8, 0.24], [-0.56, 1.48, 0], coat);
box(observer, [0.22, 0.8, 0.24], [0.56, 1.48, 0], coat);
const observerLabel = makeLabel("OBSERVER", "#f2a24a", 5.2);
observerLabel.position.set(0, 4.0, 0);
observer.add(observerLabel);
scene.add(observer);
const observerHead = new THREE.Vector3(
observerX,
observerY + 2.45,
observerZ
);
const observerRayGeometry = new THREE.BufferGeometry().setFromPoints([
observerHead,
fixPoint
]);
const observerRay = new THREE.Line(
observerRayGeometry,
new THREE.LineDashedMaterial({
color: 0xffe6a8,
transparent: true,
opacity: 0.68,
dashSize: 0.85,
gapSize: 0.55,
depthTest: false
})
);
observerRay.computeLineDistances();
observerRay.renderOrder = 11;
scene.add(observerRay);
const rangeMeters = Math.round(
observerHead.distanceTo(fixPoint) * 12
);
document.querySelector("#rangeReadout").textContent =
`${rangeMeters} m`;
// ---------------------------------------------------------------------
// Estimated position and voxel uncertainty region
// ---------------------------------------------------------------------
const uncertaintyMat = new THREE.MeshBasicMaterial({
color: 0x52f0b3,
transparent: true,
opacity: 0.19,
depthWrite: false
});
const uncertainty = new THREE.Group();
scene.add(uncertainty);
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -2; iz <= 2; iz++) {
if (Math.hypot(ix, iz) > 2.35) continue;
const x = estimatedFix.x + ix * 0.43;
const z = estimatedFix.z + iz * 0.43;
const y = terrainHeight(x, z) + 0.10;
box(
uncertainty,
[0.34, 0.08, 0.34],
[x, y, z],
uncertaintyMat,
false
);
}
}
const ringPoints = [];
const ringRadius = 1.48;
for (let i = 0; i <= 64; i++) {
const angle = (i / 64) * Math.PI * 2;
ringPoints.push(
new THREE.Vector3(
estimatedFix.x + Math.cos(angle) * ringRadius,
fixGroundY + 0.22,
estimatedFix.z + Math.sin(angle) * ringRadius
)
);
}
const uncertaintyRing = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(ringPoints),
new THREE.LineDashedMaterial({
color: 0x52f0b3,
transparent: true,
opacity: 0.95,
dashSize: 0.22,
gapSize: 0.13,
depthTest: false
})
);
uncertaintyRing.computeLineDistances();
uncertaintyRing.renderOrder = 15;
scene.add(uncertaintyRing);
const markerDark = material(0x193c35);
const markerMint = material(0x52f0b3, {
emissive: 0x52f0b3,
emissiveIntensity: 0.75
});
box(
scene,
[1.2, 0.18, 1.2],
[estimatedFix.x, fixGroundY + 0.18, estimatedFix.z],
markerDark,
false
);
box(
scene,
[0.18, 2.2, 0.18],
[estimatedFix.x, fixGroundY + 1.18, estimatedFix.z],
markerMint,
false
);
const fixCube = box(
scene,
[0.58, 0.58, 0.58],
[estimatedFix.x, fixGroundY + 2.5, estimatedFix.z],
markerMint,
false
);
box(
scene,
[2.0, 0.07, 0.07],
[estimatedFix.x, fixGroundY + 0.24, estimatedFix.z],
markerMint,
false
);
box(
scene,
[0.07, 0.07, 2.0],
[estimatedFix.x, fixGroundY + 0.25, estimatedFix.z],
markerMint,
false
);
const fixLabel = makeLabel("EST. POSITION / ±18m", "#52f0b3", 7.1);
fixLabel.position.set(
estimatedFix.x,
fixGroundY + 4.0,
estimatedFix.z
);
scene.add(fixLabel);
// ---------------------------------------------------------------------
// Block clouds and north marker
// ---------------------------------------------------------------------
const cloudMat = new THREE.MeshStandardMaterial({
color: 0xf4f7f1,
roughness: 1,
transparent: true,
opacity: 0.76,
depthWrite: false
});
const cloudData = [
[-20, 21, -18],
[15, 24, -27],
[25, 19, 4],
[-28, 25, 16],
[3, 27, -35]
];
cloudData.forEach(([x, y, z], cloudIndex) => {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(0.9 + (cloudIndex % 3) * 0.15);
box(group, [3.5, 1.2, 1.8], [0, 0, 0], cloudMat, false);
box(group, [2.3, 1.6, 1.7], [-1.0, 0.55, 0], cloudMat, false);
box(group, [2.5, 1.4, 1.6], [1.4, 0.38, 0.1], cloudMat, false);
scene.add(group);
});
const compass = new THREE.Group();
const compassX = 29;
const compassZ = 27;
compass.position.set(compassX, terrainHeight(compassX, compassZ) + 0.1, compassZ);
box(compass, [0.15, 0.12, 4.2], [0, 0, -0.6], material(0xf4f2e8), false);
box(compass, [0.15, 0.12, 2.2], [0, 0, 1.4], material(0x64746c), false);
box(compass, [1.3, 0.12, 0.16], [0, 0, -2.5], material(0xf4f2e8), false);
const northLabel = makeLabel("N", "#ffffff", 2.2);
northLabel.position.set(0, 1.3, -2.7);
compass.add(northLabel);
scene.add(compass);
// ---------------------------------------------------------------------
// Custom camera controls — no external controls addon
// ---------------------------------------------------------------------
const homeTarget = new THREE.Vector3(0, 4, 0);
const orbitTarget = homeTarget.clone();
const desiredTarget = homeTarget.clone();
const spherical = {
theta: 0.72,
phi: 0.82,
radius: 70
};
const desired = {
theta: spherical.theta,
phi: spherical.phi,
radius: spherical.radius
};
const pointerMap = new Map();
let shiftPressed = false;
let lastPinchDistance = 0;
function updateCamera() {
const sinPhi = Math.sin(spherical.phi);
camera.position.set(
orbitTarget.x + spherical.radius * sinPhi * Math.sin(spherical.theta),
orbitTarget.y + spherical.radius * Math.cos(spherical.phi),
orbitTarget.z + spherical.radius * sinPhi * Math.cos(spherical.theta)
);
camera.lookAt(orbitTarget);
}
function resetView() {
desiredTarget.copy(homeTarget);
desired.theta = 0.72;
desired.phi = 0.82;
desired.radius = 70;
}
function topView() {
desiredTarget.copy(homeTarget);
desired.theta = 0;
desired.phi = 0.075;
desired.radius = 76;
}
function focusFix() {
desiredTarget.set(estimatedFix.x, fixGroundY + 1, estimatedFix.z);
desired.theta = 0.55;
desired.phi = 0.86;
desired.radius = 24;
}
function observerView() {
desiredTarget.set(observerX, observerY + 1.5, observerZ);
desired.theta = -0.2;
desired.phi = 0.94;
desired.radius = 24;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerMap.has(event.pointerId)) return;
const previous = pointerMap.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size >= 2) {
const points = [...pointerMap.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (lastPinchDistance / Math.max(1, distance)),
12,
115
);
}
lastPinchDistance = distance;
return;
}
if (shiftPressed) {
const forward = camera.getWorldDirection(new THREE.Vector3());
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, new THREE.Vector3(0, 1, 0))
.normalize();
const cameraUp = new THREE.Vector3(0, 1, 0)
.applyQuaternion(camera.quaternion);
const scale = desired.radius * 0.0015;
desiredTarget.addScaledVector(right, -dx * scale);
desiredTarget.addScaledVector(cameraUp, dy * scale);
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.075,
1.38
);
}
});
function releasePointer(event) {
pointerMap.delete(event.pointerId);
if (pointerMap.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
12,
115
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
shiftPressed = event.shiftKey;
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "t") topView();
if (event.key.toLowerCase() === "f") focusFix();
});
window.addEventListener("keyup", () => {
shiftPressed = false;
});
document.querySelector("#resetView").addEventListener("click", resetView);
document.querySelector("#topView").addEventListener("click", topView);
document.querySelector("#fixView").addEventListener("click", focusFix);
document.querySelector("#observerView").addEventListener("click", observerView);
function resize() {
const width = sceneRoot.clientWidth;
const height = sceneRoot.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
const smoothing = 0.11;
spherical.theta += (desired.theta - spherical.theta) * smoothing;
spherical.phi += (desired.phi - spherical.phi) * smoothing;
spherical.radius += (desired.radius - spherical.radius) * smoothing;
orbitTarget.lerp(desiredTarget, smoothing);
updateCamera();
towerObjects.forEach((tower, index) => {
const pulse = 0.5 + 0.5 * Math.sin(time * 3.2 + index * 1.7);
const scale = 0.92 + pulse * 0.23;
tower.beacon.scale.set(scale, scale, scale);
tower.beaconMat.emissiveIntensity = 0.8 + pulse * 1.6;
});
const fixPulse = 0.92 + Math.sin(time * 2.5) * 0.08;
fixCube.scale.set(fixPulse, fixPulse, fixPulse);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```