Prompt specification
Build or customize the Three.js 3D scene "Target Rises Above a Schematic Horizon" 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: Target Rises Above a Schematic Horizon
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/target-rises-above-a-schematic-horizon-x3794
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: target rises above a schematic horizon. Animate a selected synthetic sky path relative to a horizon. Distinguish blocked, low, and clear sight lines under explicit geometric assumptions. Return one self-contained HTML file.
Working Three.js Starter (target-rises-above-a-schematic-horizon-x3794):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Skyline — Synthetic Sight-Line Lab</title>
<style>
:root {
--ink: #f5fbf8;
--muted: #a9bec2;
--panel: rgba(12, 28, 34, 0.82);
--panel-strong: rgba(9, 23, 29, 0.94);
--line: rgba(210, 242, 236, 0.16);
--clear: #62e6a5;
--low: #ffc857;
--blocked: #ff6464;
--accent: #ff8a4c;
--cyan: #8ee8f1;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 74% 18%, rgba(255, 225, 166, 0.5), transparent 21%),
linear-gradient(180deg, #8ab9ca 0%, #b8d2d4 48%, #d5d8bd 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
}
canvas.dragging { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.interactive {
pointer-events: auto;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(7, 22, 28, 0.22);
backdrop-filter: blur(16px) saturate(120%);
-webkit-backdrop-filter: blur(16px) saturate(120%);
}
.brand {
position: absolute;
top: 20px;
left: 20px;
width: min(420px, calc(100vw - 40px));
padding: 17px 19px 16px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(142, 232, 241, 0.8);
}
h1 {
margin: 8px 0 5px;
font-size: clamp(25px, 3vw, 37px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 800;
}
.brand p {
margin: 0;
max-width: 350px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status-panel {
position: absolute;
top: 20px;
right: 20px;
width: 310px;
padding: 15px;
border-radius: 16px;
}
.status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.status-name {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-badge {
min-width: 84px;
padding: 6px 9px;
border: 1px solid currentColor;
border-radius: 7px;
text-align: center;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
}
.status-badge.clear {
color: var(--clear);
background: rgba(98, 230, 165, 0.08);
}
.status-badge.low {
color: var(--low);
background: rgba(255, 200, 87, 0.08);
}
.status-badge.blocked {
color: var(--blocked);
background: rgba(255, 100, 100, 0.08);
}
.status-title {
margin: 13px 0 5px;
font-size: 19px;
letter-spacing: -0.025em;
}
.status-description {
min-height: 34px;
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1px;
overflow: hidden;
margin-top: 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--line);
}
.metric {
min-height: 54px;
padding: 9px 10px;
background: rgba(5, 20, 25, 0.56);
}
.metric-label {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
margin-top: 4px;
font-size: 14px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.status-path {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.status-path strong {
color: var(--ink);
font-weight: 700;
}
.deck {
position: absolute;
right: 20px;
bottom: 20px;
left: 20px;
display: grid;
grid-template-columns: 340px minmax(320px, 1fr) 350px;
gap: 12px;
align-items: end;
}
.control-panel,
.assumption-panel {
padding: 15px;
border-radius: 15px;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-heading .hint {
color: rgba(255, 255, 255, 0.38);
font-size: 9px;
letter-spacing: 0.04em;
text-transform: none;
}
.path-list {
display: grid;
gap: 7px;
}
.path-button {
width: 100%;
display: grid;
grid-template-columns: 29px 1fr auto;
gap: 9px;
align-items: center;
padding: 9px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
text-align: left;
transition: border-color 160ms, background 160ms, transform 160ms;
}
.path-button:hover {
transform: translateY(-1px);
border-color: rgba(142, 232, 241, 0.35);
background: rgba(255, 255, 255, 0.065);
}
.path-button.active {
border-color: rgba(255, 138, 76, 0.72);
background: rgba(255, 138, 76, 0.11);
box-shadow: inset 3px 0 0 var(--accent);
}
.path-number {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 7px;
color: var(--muted);
background: rgba(255, 255, 255, 0.06);
font-size: 10px;
font-weight: 850;
}
.path-button.active .path-number {
color: #1a2426;
background: var(--accent);
}
.path-name {
font-size: 12px;
font-weight: 750;
}
.path-meta {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.path-swatch {
width: 8px;
height: 8px;
border-radius: 2px;
background: #687b84;
}
.path-button.active .path-swatch {
background: var(--accent);
box-shadow: 0 0 9px rgba(255, 138, 76, 0.7);
}
.timeline-panel {
padding: 13px 15px 14px;
border-radius: 15px;
}
.timeline-row {
display: flex;
align-items: center;
gap: 12px;
}
.play-button {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 39px;
height: 39px;
border: 1px solid rgba(255, 138, 76, 0.55);
border-radius: 10px;
color: #182326;
background: var(--accent);
cursor: pointer;
font-size: 14px;
font-weight: 900;
box-shadow: 0 7px 20px rgba(255, 138, 76, 0.2);
}
.timeline-wrap {
flex: 1;
min-width: 0;
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#timeline {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
border-radius: 5px;
outline: none;
background: linear-gradient(
90deg,
var(--accent) 0%,
var(--accent) var(--progress, 0%),
rgba(255, 255, 255, 0.13) var(--progress, 0%),
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #183039;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
#timeline::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #183039;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 2px;
}
.legend-dot.clear { background: var(--clear); }
.legend-dot.low { background: var(--low); }
.legend-dot.blocked { background: var(--blocked); }
.legend-dot.horizon { background: var(--cyan); }
.assumption-panel {
max-height: 330px;
overflow: auto;
}
.formula {
margin: 0 0 11px;
padding: 9px 10px;
border: 1px solid rgba(142, 232, 241, 0.15);
border-radius: 8px;
color: #d7f6f7;
background: rgba(142, 232, 241, 0.06);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.55;
}
.assumption-list {
margin: 0;
padding: 0;
list-style: none;
counter-reset: assumptions;
}
.assumption-list li {
position: relative;
margin: 0 0 8px;
padding-left: 26px;
color: #c0d0d2;
font-size: 10px;
line-height: 1.48;
}
.assumption-list li::before {
position: absolute;
top: 0;
left: 0;
display: grid;
place-items: center;
width: 18px;
height: 18px;
border: 1px solid var(--line);
border-radius: 5px;
color: var(--cyan);
background: rgba(255, 255, 255, 0.035);
content: counter(assumptions);
counter-increment: assumptions;
font-size: 8px;
font-weight: 800;
}
.assumption-list strong { color: var(--ink); }
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 5px;
color: #f7ffff;
background: rgba(10, 27, 32, 0.76);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 120ms;
}
.world-label.target {
border-color: rgba(255, 138, 76, 0.55);
color: #ffd1bb;
}
.world-label.horizon {
border-color: rgba(142, 232, 241, 0.4);
color: #c5f7fb;
}
.world-label.ridge {
border-color: rgba(255, 200, 87, 0.4);
color: #ffe4a7;
}
.camera-tools {
position: absolute;
right: 20px;
top: 244px;
display: flex;
gap: 6px;
}
.tool-button {
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--ink);
background: var(--panel-strong);
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.tool-button:hover {
border-color: rgba(142, 232, 241, 0.45);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #173139;
background: #b6d0d1;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 300ms;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1050px) {
.deck {
grid-template-columns: 310px 1fr;
}
.assumption-panel { display: none; }
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 15px;
}
.brand p { display: none; }
.status-panel {
top: 104px;
right: 10px;
width: 245px;
padding: 12px;
}
.status-description { display: none; }
.metrics { margin-top: 9px; }
.metric { min-height: 47px; padding: 7px 8px; }
.deck {
right: 10px;
bottom: 10px;
left: 10px;
grid-template-columns: 1fr;
gap: 7px;
}
.path-list { grid-template-columns: repeat(3, 1fr); }
.path-button {
grid-template-columns: 1fr;
text-align: center;
}
.path-number, .path-swatch, .path-meta { display: none; }
.path-name { font-size: 10px; }
.camera-tools { top: 103px; right: 10px; }
.legend { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="ui">
<section class="brand panel interactive">
<div class="eyebrow">Synthetic sky-path laboratory</div>
<h1>Target Rise</h1>
<p>A voxel target climbs through a schematic horizon while the observer-to-target ray is tested against an opaque voxel ridge.</p>
</section>
<section class="status-panel panel interactive">
<div class="status-top">
<div class="status-name">Sight-line state</div>
<div id="statusBadge" class="status-badge low">LOW</div>
</div>
<h2 id="statusTitle" class="status-title">Low elevation</h2>
<p id="statusDescription" class="status-description">The target has not yet risen safely above the schematic horizon.</p>
<div class="metrics">
<div class="metric">
<div class="metric-label">Elevation</div>
<div id="elevationMetric" class="metric-value">−4.2°</div>
</div>
<div class="metric">
<div class="metric-label">Ridge clearance</div>
<div id="clearanceMetric" class="metric-value">—</div>
</div>
<div class="metric">
<div class="metric-label">Horizon offset</div>
<div id="offsetMetric" class="metric-value">−2.9 m</div>
</div>
<div class="metric">
<div class="metric-label">Slant range</div>
<div id="rangeMetric" class="metric-value">30.0 m</div>
</div>
</div>
<div class="status-path">
<span>Selected path</span>
<strong id="selectedPathMetric">Standard rise</strong>
</div>
</section>
<div class="camera-tools interactive">
<button id="resetCamera" class="tool-button" type="button">Reset view</button>
<button id="sideCamera" class="tool-button" type="button">Side view</button>
</div>
<div id="observerLabel" class="world-label">Observer O</div>
<div id="ridgeLabel" class="world-label ridge">Opaque voxel ridge</div>
<div id="targetLabel" class="world-label target">Target T</div>
<div id="horizonLabel" class="world-label horizon">Schematic horizon</div>
<div class="deck">
<section class="control-panel panel interactive">
<div class="section-heading">
<span>Synthetic path</span>
<span class="hint">Select trajectory</span>
</div>
<div id="pathList" class="path-list"></div>
</section>
<section class="timeline-panel panel interactive">
<div class="section-heading">
<span>Path playback</span>
<span id="timeMetric" class="hint">t = 0.000</span>
</div>
<div class="timeline-row">
<button id="playButton" class="play-button" type="button" aria-label="Pause animation">Ⅱ</button>
<div class="timeline-wrap">
<div class="timeline-labels">
<span>Start</span>
<span>Rising target</span>
<span>End</span>
</div>
<input id="timeline" type="range" min="0" max="1000" value="0" step="1" aria-label="Path position" />
</div>
</div>
<div class="legend">
<span class="legend-item"><i class="legend-dot clear"></i>Clear</span>
<span class="legend-item"><i class="legend-dot low"></i>Low</span>
<span class="legend-item"><i class="legend-dot blocked"></i>Blocked</span>
<span class="legend-item"><i class="legend-dot horizon"></i>Horizon reference</span>
</div>
</section>
<section class="assumption-panel panel interactive">
<div class="section-heading">
<span>Geometric assumptions</span>
<span class="hint">Units: metres</span>
</div>
<div id="formula" class="formula"></div>
<ol class="assumption-list">
<li><strong>Observer:</strong> O = (−14, 15.5, 38). The dashed horizontal plane is a schematic eye-level horizon.</li>
<li><strong>Ridge:</strong> opaque columns spanning x ∈ [−30, 30], z ∈ [4, 14], with voxel top h(x).</li>
<li><strong>Blocked:</strong> segment O→T intersects any ridge voxel.</li>
<li><strong>Low:</strong> unblocked, but elevation ≤ 6° or ridge clearance < 1.5 m.</li>
<li><strong>Clear:</strong> unblocked, elevation > 6°, and ridge clearance ≥ 1.5 m.</li>
<li>No atmospheric refraction, terrain beyond the ridge, target size, or sensor occlusion is modelled.</li>
</ol>
</section>
</div>
</div>
<div id="loading">Loading voxel laboratory…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xaacbd3, 105, 220);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel sight-line scene");
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
400
);
const cameraState = {
yaw: 0.70,
pitch: 0.48,
distance: 118,
target: new THREE.Vector3(-1, 13, -5)
};
const clock = new THREE.Clock();
const observer = new THREE.Vector3(-14, 15.5, 38);
const paths = [
{
id: "standard",
name: "Standard rise",
short: "Balanced climb",
formula: "T(t) = (−14 + 5 sin(2πt)sin(πt), 8 + 34t¹·⁸, 30 − 82t)",
point(t, out) {
return out.set(
-14 + 5 * Math.sin(2 * Math.PI * t) * Math.sin(Math.PI * t),
8 + 34 * Math.pow(t, 1.8),
30 - 82 * t
);
}
},
{
id: "late",
name: "Late climb",
short: "Delayed ascent",
formula: "T(t) = (−14 − 7 sin²(πt), 7 + 40t³·², 30 − 82t)",
point(t, out) {
return out.set(
-14 - 7 * Math.pow(Math.sin(Math.PI * t), 2),
7 + 40 * Math.pow(t, 3.2),
30 - 82 * t
);
}
},
{
id: "early",
name: "Early lift",
short: "High early arc",
formula: "T(t) = (−14 + 7 sin(πt), 8 + 38t⁰·⁷², 30 − 82t)",
point(t, out) {
return out.set(
-14 + 7 * Math.sin(Math.PI * t),
8 + 38 * Math.pow(t, 0.72),
30 - 82 * t
);
}
}
];
let selectedPathIndex = 0;
let pathTime = 0.045;
let playing = true;
const duration = 18;
const hemisphere = new THREE.HemisphereLight(0xdff6ff, 0x475044, 2.1);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe4bb, 3.2);
sunlight.position.set(-35, 70, 45);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -85;
sunlight.shadow.camera.right = 85;
sunlight.shadow.camera.top = 85;
sunlight.shadow.camera.bottom = -85;
sunlight.shadow.camera.near = 5;
sunlight.shadow.camera.far = 180;
sunlight.shadow.bias = -0.00035;
scene.add(sunlight);
const rimLight = new THREE.DirectionalLight(0x8ddff2, 1.1);
rimLight.position.set(45, 30, -65);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
});
}
function addBox(parent, size, position, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size.x, size.y, size.z);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// Low-relief voxel terrain.
const terrainMaterial = new THREE.MeshStandardMaterial({
roughness: 0.96,
metalness: 0,
vertexColors: true
});
const terrainColumns = 22;
const terrainRows = 31;
const terrainMesh = new THREE.InstancedMesh(unitBox, terrainMaterial, terrainColumns * terrainRows);
terrainMesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const terrainColor = new THREE.Color();
let terrainIndex = 0;
for (let ix = 0; ix < terrainColumns; ix++) {
for (let iz = 0; iz < terrainRows; iz++) {
const x = -42 + ix * 4;
const z = -62 + iz * 4;
const height =
-0.35 +
1.1 * Math.sin(x * 0.095 + z * 0.027) +
0.75 * Math.cos(z * 0.082 - x * 0.018) +
0.35 * Math.sin((x + z) * 0.17);
dummy.position.set(x, (height - 2) * 0.5, z);
dummy.scale.set(3.94, height + 2, 3.94);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
terrainMesh.setMatrixAt(terrainIndex, dummy.matrix);
const mix = THREE.MathUtils.clamp((height + 1.5) / 4.2, 0, 1);
terrainColor.set(0x466655).lerp(new THREE.Color(0x87946c), mix);
terrainColor.multiplyScalar(0.92 + 0.12 * Math.sin(ix * 3.7 + iz * 1.9));
terrainMesh.setColorAt(terrainIndex, terrainColor);
terrainIndex++;
}
}
terrainMesh.instanceMatrix.needsUpdate = true;
terrainMesh.instanceColor.needsUpdate = true;
scene.add(terrainMesh);
// Opaque ridge columns. Their exact top heights are used by the collision test.
const ridgeColumns = [];
const ridgeMaterial = new THREE.MeshStandardMaterial({
roughness: 0.9,
metalness: 0.03,
vertexColors: true
});
const ridgeCount = 31;
for (let i = 0; i < ridgeCount; i++) {
const minX = -30 + i * 2;
const x = minX + 1;
const height = Math.max(
7.2,
9.0 +
4.5 * Math.exp(-Math.pow((x + 12) / 13, 2)) +
1.2 * Math.sin(x * 0.26) +
0.6 * Math.cos(x * 0.11)
);
ridgeColumns.push({
minX,
maxX: minX + 2,
minZ: 4,
maxZ: 14,
minY: -2,
maxY: height
});
}
const ridgeMesh = new THREE.InstancedMesh(unitBox, ridgeMaterial, ridgeCount);
ridgeMesh.castShadow = true;
ridgeMesh.receiveShadow = true;
const ridgeColor = new THREE.Color();
ridgeColumns.forEach((column, i) => {
const height = column.maxY;
dummy.position.set(column.minX + 1, (height - 2) * 0.5, 9);
dummy.scale.set(2, height + 2, 10);
dummy.updateMatrix();
ridgeMesh.setMatrixAt(i, dummy.matrix);
ridgeColor.set(0x66757b).lerp(new THREE.Color(0x899295), 0.25 + 0.22 * Math.sin(i * 0.8));
ridgeMesh.setColorAt(i, ridgeColor);
});
ridgeMesh.instanceMatrix.needsUpdate = true;
ridgeMesh.instanceColor.needsUpdate = true;
scene.add(ridgeMesh);
// Observer tower and platform.
const towerGroup = new THREE.Group();
scene.add(towerGroup);
const towerMaterial = standardMaterial(0x41545c);
const towerAccentMaterial = standardMaterial(0x7e969a);
for (let level = 0; level < 12; level++) {
const y = 0.1 + level * 1.1;
for (const dx of [-1.5, 1.5]) {
for (const dz of [-1.5, 1.5]) {
addBox(
towerGroup,
new THREE.Vector3(1.15, 1.1, 1.15),
new THREE.Vector3(observer.x + dx, y, observer.z + dz),
towerMaterial
);
}
}
if (level % 3 === 0) {
addBox(
towerGroup,
new THREE.Vector3(4.4, 0.35, 0.65),
new THREE.Vector3(observer.x, y, observer.z - 1.5),
towerAccentMaterial
);
}
}
addBox(
towerGroup,
new THREE.Vector3(6, 0.7, 6),
new THREE.Vector3(observer.x, 13.35, observer.z),
standardMaterial(0x71878a)
);
addBox(
towerGroup,
new THREE.Vector3(2.1, 1.5, 1.6),
new THREE.Vector3(observer.x, 14.45, observer.z),
standardMaterial(0x21343c)
);
addBox(
towerGroup,
new THREE.Vector3(1.35, 1.15, 1.25),
new THREE.Vector3(observer.x, 15.75, observer.z),
standardMaterial(0xf0b46f)
);
addBox(
towerGroup,
new THREE.Vector3(0.75, 0.75, 0.12),
new THREE.Vector3(observer.x, 15.75, observer.z - 0.67),
standardMaterial(0x8ee8f1, { emissive: 0x173d47, emissiveIntensity: 0.8 })
);
// Schematic horizontal horizon plane and reference grid.
const horizonPlane = new THREE.Mesh(
new THREE.PlaneGeometry(110, 170),
new THREE.MeshBasicMaterial({
color: 0x9ce7ef,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
})
);
horizonPlane.rotation.x = -Math.PI / 2;
horizonPlane.position.set(-4, observer.y, -20);
scene.add(horizonPlane);
const horizonGridPoints = [];
for (let x = -55; x <= 55; x += 10) {
horizonGridPoints.push(new THREE.Vector3(x, observer.y, -95), new THREE.Vector3(x, observer.y, 55));
}
for (let z = -95; z <= 55; z += 10) {
horizonGridPoints.push(new THREE.Vector3(-55, observer.y, z), new THREE.Vector3(55, observer.y, z));
}
const horizonGridGeometry = new THREE.BufferGeometry().setFromPoints(horizonGridPoints);
const horizonGrid = new THREE.LineSegments(
horizonGridGeometry,
new THREE.LineBasicMaterial({
color: 0xc0f5f7,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
scene.add(horizonGrid);
const horizonRayGeometry = new THREE.BufferGeometry().setFromPoints([
observer.clone(),
new THREE.Vector3(-14, observer.y, -91)
]);
const horizonRay = new THREE.Line(
horizonRayGeometry,
new THREE.LineDashedMaterial({
color: 0xbff7fb,
dashSize: 2.2,
gapSize: 1.8,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
})
);
horizonRay.computeLineDistances();
horizonRay.renderOrder = 7;
scene.add(horizonRay);
// Voxel sun.
const sun = addBox(
scene,
new THREE.Vector3(8, 8, 1.5),
new THREE.Vector3(48, 52, -86),
new THREE.MeshBasicMaterial({ color: 0xffc674 }),
false,
false
);
sun.rotation.z = Math.PI / 4;
// Block clouds.
const cloudMaterial = new THREE.MeshLambertMaterial({
color: 0xe9f2ec,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const cloudBlocks = [
[-37, 45, -48, 8, 3, 5], [-31, 48, -48, 5, 4, 6], [-43, 47, -48, 5, 5, 4],
[30, 39, -22, 7, 3, 4], [37, 42, -22, 5, 4, 5], [24, 42, -22, 5, 5, 4],
[8, 52, -72, 8, 2.5, 4], [16, 54, -72, 5, 4, 4],
[-5, 34, 14, 5, 2.5, 3], [1, 36, 14, 4, 3, 4]
];
for (const [x, y, z, sx, sy, sz] of cloudBlocks) {
addBox(scene, new THREE.Vector3(sx, sy, sz), new THREE.Vector3(x, y, z), cloudMaterial, false, false);
}
// Synthetic paths rendered as voxel waypoints plus a thin guide line.
const pathMeshes = [];
const pathLines = [];
paths.forEach((path, pathIndex) => {
const count = 76;
const material = new THREE.MeshBasicMaterial({
color: 0xff8a4c,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(unitBox, material, count);
mesh.renderOrder = 6;
mesh.frustumCulled = false;
const points = [];
for (let i = 0; i < count; i++) {
const t = i / (count - 1);
const point = path.point(t, new THREE.Vector3());
points.push(point);
dummy.position.copy(point);
dummy.scale.setScalar(0.62);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
pathMeshes.push(mesh);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0xff9a61,
transparent: true,
opacity: 0.82,
depthTest: false,
depthWrite: false
})
);
line.renderOrder = 7;
scene.add(line);
pathLines.push(line);
});
// Voxel target.
const targetGroup = new THREE.Group();
scene.add(targetGroup);
const targetOrange = standardMaterial(0xff7043, {
emissive: 0x5e1608,
emissiveIntensity: 0.45
});
const targetCream = standardMaterial(0xffe4bd);
const targetDark = standardMaterial(0x263b43);
const targetCyan = standardMaterial(0x9bf5ff, {
emissive: 0x2a8793,
emissiveIntensity: 1.1
});
addBox(targetGroup, new THREE.Vector3(2.7, 1.8, 3.2), new THREE.Vector3(0, 0, 0), targetOrange);
addBox(targetGroup, new THREE.Vector3(7.2, 0.42, 1.5), new THREE.Vector3(0, 0.1, -0.1), targetCream);
addBox(targetGroup, new THREE.Vector3(1.45, 2.7, 1.6), new THREE.Vector3(0, 1.45, 0.8), targetOrange);
addBox(targetGroup, new THREE.Vector3(1.3, 0.7, 0.18), new THREE.Vector3(0, 0.05, -1.68), targetCyan);
addBox(targetGroup, new THREE.Vector3(0.55, 0.55, 0.55), new THREE.Vector3(0, 2.95, 0.8), targetCyan);
targetGroup.children.forEach(mesh => { mesh.castShadow = true; });
const beaconLight = new THREE.PointLight(0xff8a4c, 1.1, 12, 2);
beaconLight.position.set(0, 3.1, 0.8);
targetGroup.add(beaconLight);
// Segmented line-of-sight beam.
const beamSegments = 28;
const beamGeometry = new THREE.BoxGeometry(1, 1, 1);
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0x62e6a5,
transparent: true,
opacity: 0.88,
depthTest: false,
depthWrite: false
});
const beam = new THREE.InstancedMesh(beamGeometry, beamMaterial, beamSegments);
beam.renderOrder = 9;
beam.frustumCulled = false;
scene.add(beam);
// Collision marker.
const collisionMarker = new THREE.Group();
const collisionMaterial = new THREE.MeshBasicMaterial({
color: 0xff6464,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
addBox(collisionMarker, new THREE.Vector3(2.5, 0.38, 0.38), new THREE.Vector3(), collisionMaterial, false, false);
addBox(collisionMarker, new THREE.Vector3(0.38, 2.5, 0.38), new THREE.Vector3(), collisionMaterial, false, false);
collisionMarker.renderOrder = 10;
collisionMarker.visible = false;
scene.add(collisionMarker);
// Exact segment / AABB intersection.
function segmentBoxIntersection(a, b, box) {
let tMin = 0;
let tMax = 1;
const axes = ["x", "y", "z"];
for (const axis of axes) {
const minimum = box[`min${axis.toUpperCase()}`];
const maximum = box[`max${axis.toUpperCase()}`];
const origin = a[axis];
const direction = b[axis] - a[axis];
if (Math.abs(direction) < 1e-9) {
if (origin < minimum || origin > maximum) return null;
} else {
let t1 = (minimum - origin) / direction;
let t2 = (maximum - origin) / direction;
if (t1 > t2) [t1, t2] = [t2, t1];
tMin = Math.max(tMin, t1);
tMax = Math.min(tMax, t2);
if (tMin > tMax) return null;
}
}
return tMin;
}
function ridgeHeightAtX(x) {
if (x < -30 || x > 30) return null;
const index = THREE.MathUtils.clamp(Math.floor((x + 30) / 2), 0, ridgeColumns.length - 1);
return ridgeColumns[index].maxY;
}
function analyseSightLine(target) {
let hitT = null;
for (const column of ridgeColumns) {
const intersectionT = segmentBoxIntersection(observer, target, column);
if (intersectionT !== null && intersectionT >= 0 && intersectionT <= 1) {
if (hitT === null || intersectionT < hitT) hitT = intersectionT;
}
}
let clearance = null;
const samplePoint = new THREE.Vector3();
const samples = 420;
for (let i = 0; i <= samples; i++) {
samplePoint.lerpVectors(observer, target, i / samples);
if (samplePoint.z >= 4 && samplePoint.z <= 14 && samplePoint.x >= -30 && samplePoint.x <= 30) {
const height = ridgeHeightAtX(samplePoint.x);
if (height !== null) {
const margin = samplePoint.y - height;
clearance = clearance === null ? margin : Math.min(clearance, margin);
}
}
}
const dx = target.x - observer.x;
const dz = target.z - observer.z;
const horizontalDistance = Math.hypot(dx, dz);
const slantRange = Math.hypot(horizontalDistance, target.y - observer.y);
const elevation = THREE.MathUtils.radToDeg(Math.atan2(target.y - observer.y, horizontalDistance));
const offset = target.y - observer.y;
let state;
if (hitT !== null) {
state = "blocked";
} else if (elevation <= 6 || (clearance !== null && clearance < 1.5)) {
state = "low";
} else {
state = "clear";
}
const hitPoint = hitT === null ? null : observer.clone().lerp(target, hitT);
return { state, hitT, hitPoint, clearance, elevation, offset, horizontalDistance, slantRange };
}
const statusBadge = document.getElementById("statusBadge");
const statusTitle = document.getElementById("statusTitle");
const statusDescription = document.getElementById("statusDescription");
const elevationMetric = document.getElementById("elevationMetric");
const clearanceMetric = document.getElementById("clearanceMetric");
const offsetMetric = document.getElementById("offsetMetric");
const rangeMetric = document.getElementById("rangeMetric");
const selectedPathMetric = document.getElementById("selectedPathMetric");
const timeMetric = document.getElementById("timeMetric");
const timeline = document.getElementById("timeline");
const playButton = document.getElementById("playButton");
const formula = document.getElementById("formula");
const pathList = document.getElementById("pathList");
paths.forEach((path, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = `path-button${index === selectedPathIndex ? " active" : ""}`;
button.setAttribute("aria-pressed", index === selectedPathIndex ? "true" : "false");
button.innerHTML = `
<span class="path-number">0${index + 1}</span>
<span>
<span class="path-name">${path.name}</span>
<span class="path-meta" style="display:block">${path.short}</span>
</span>
<span class="path-swatch"></span>
`;
button.addEventListener("click", () => selectPath(index));
pathList.appendChild(button);
});
function selectPath(index) {
selectedPathIndex = index;
pathMeshes.forEach((mesh, i) => {
const active = i === index;
mesh.material.color.set(active ? 0xff8a4c : 0x78909a);
mesh.material.opacity = active ? 0.95 : 0.18;
mesh.material.depthTest = !active;
pathLines[i].material.color.set(active ? 0xffa166 : 0x78909a);
pathLines[i].material.opacity = active ? 0.86 : 0.16;
pathLines[i].material.depthTest = !active;
});
[...pathList.children].forEach((button, i) => {
const active = i === index;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", active ? "true" : "false");
});
formula.textContent = paths[index].formula;
selectedPathMetric.textContent = paths[index].name;
}
selectPath(0);
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause animation" : "Play animation");
});
timeline.addEventListener("input", () => {
pathTime = Number(timeline.value) / 1000;
});
function setCamera(yaw, pitch, distance, target = new THREE.Vector3(-1, 13, -5)) {
cameraState.yaw = yaw;
cameraState.pitch = pitch;
cameraState.distance = distance;
cameraState.target.copy(target);
updateCamera();
}
document.getElementById("resetCamera").addEventListener("click", () => {
setCamera(0.70, 0.48, 118);
});
document.getElementById("sideCamera").addEventListener("click", () => {
setCamera(0.02, 0.31, 112, new THREE.Vector3(-8, 14, -5));
});
// Direct camera controls: orbit, wheel zoom, and shift/right-drag pan.
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const scale = cameraState.distance * 0.0012;
const right = new THREE.Vector3(Math.cos(cameraState.yaw), 0, -Math.sin(cameraState.yaw));
const forward = new THREE.Vector3(-Math.sin(cameraState.yaw), 0, -Math.cos(cameraState.yaw));
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
} else {
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.004, 0.12, 1.28);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
48,
190
);
updateCamera();
}, { passive: false });
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * distance,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(target);
}
updateCamera();
const labelElements = {
observer: document.getElementById("observerLabel"),
ridge: document.getElementById("ridgeLabel"),
target: document.getElementById("targetLabel"),
horizon: document.getElementById("horizonLabel")
};
const projection = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projection.copy(worldPosition).project(camera);
const visible = projection.z > -1 && projection.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projection.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projection.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const targetPosition = new THREE.Vector3();
const beamDirection = new THREE.Vector3();
const beamQuaternion = new THREE.Quaternion();
const zAxis = new THREE.Vector3(0, 0, 1);
const beamScale = new THREE.Vector3();
const beamDummy = new THREE.Object3D();
const stateColors = {
clear: 0x62e6a5,
low: 0xffc857,
blocked: 0xff6464
};
function updateStatus(result) {
const badge = result.state.toUpperCase();
statusBadge.textContent = badge;
statusBadge.className = `status-badge ${result.state}`;
elevationMetric.textContent = `${result.elevation >= 0 ? "+" : "−"}${Math.abs(result.elevation).toFixed(1)}°`;
offsetMetric.textContent = `${result.offset >= 0 ? "+" : "−"}${Math.abs(result.offset).toFixed(1)} m`;
rangeMetric.textContent = `${result.slantRange.toFixed(1)} m`;
if (result.clearance === null) {
clearanceMetric.textContent = "not crossed";
} else {
clearanceMetric.textContent = `${result.clearance >= 0 ? "+" : "−"}${Math.abs(result.clearance).toFixed(1)} m`;
}
if (result.state === "blocked") {
statusTitle.textContent = "Sight line blocked";
statusDescription.textContent = "The observer-to-target segment intersects an opaque ridge voxel.";
} else if (result.state === "low") {
statusTitle.textContent = "Low sight line";
statusDescription.textContent =
result.elevation <= 6
? `The target is only ${Math.abs(result.elevation).toFixed(1)}° from the schematic horizon.`
: `The ray clears the ridge by less than the 1.5 m low-clearance threshold.`;
} else {
statusTitle.textContent = "Sight line clear";
const clearanceText = result.clearance === null
? "The target is ahead of the ridge"
: `The ray clears the ridge by ${result.clearance.toFixed(1)} m`;
statusDescription.textContent = `${clearanceText}; target elevation is ${result.elevation.toFixed(1)}°.`;
}
}
function updateScene() {
const selectedPath = paths[selectedPathIndex];
selectedPath.point(pathTime, targetPosition);
targetGroup.position.copy(targetPosition);
const result = analyseSightLine(targetPosition);
updateStatus(result);
beamMaterial.color.setHex(stateColors[result.state]);
beamDirection.subVectors(targetPosition, observer);
const totalLength = beamDirection.length();
beamDirection.normalize();
beamQuaternion.setFromUnitVectors(zAxis, beamDirection);
const segmentLength = totalLength / beamSegments;
for (let i = 0; i < beamSegments; i++) {
const fraction = (i + 0.5) / beamSegments;
beamDummy.position.lerpVectors(observer, targetPosition, fraction);
beamDummy.quaternion.copy(beamQuaternion);
beamScale.set(0.25, 0.25, segmentLength * 1.025);
beamDummy.scale.copy(beamScale);
beamDummy.updateMatrix();
beam.setMatrixAt(i, beamDummy.matrix);
}
beam.instanceMatrix.needsUpdate = true;
collisionMarker.visible = result.hitPoint !== null;
if (result.hitPoint) {
collisionMarker.position.copy(result.hitPoint);
collisionMarker.rotation.y += 0.012;
}
const pulse = 1 + Math.sin(performance.now() * 0.006) * 0.035;
targetGroup.scale.setScalar(pulse);
beaconLight.intensity = 1 + Math.sin(performance.now() * 0.008) * 0.3;
timeline.value = Math.round(pathTime * 1000);
timeline.style.setProperty("--progress", `${pathTime * 100}%`);
timeMetric.textContent = `t = ${pathTime.toFixed(3)}`;
positionLabel(labelElements.observer, observer.clone().add(new THREE.Vector3(0, 3.7, 0)));
positionLabel(labelElements.ridge, new THREE.Vector3(4, 15.2, 9));
positionLabel(labelElements.target, targetPosition.clone().add(new THREE.Vector3(0, 4.8, 0)));
positionLabel(labelElements.horizon, new THREE.Vector3(-14, observer.y + 1.2, -79));
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
pathTime = (pathTime + delta / duration) % 1;
}
updateScene();
renderer.render(scene, camera);
}
updateScene();
renderer.render(scene, camera);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
animate();
</script>
</body>
</html>
```