Prompt specification
Build or customize the Three.js 3D scene "Baseline Changes Apparent Shift" 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: Baseline Changes Apparent Shift
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/baseline-changes-apparent-shift-x3834
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring stellar parallax and distance inference. Animate an observer moving between two positions while a nearby marker stays fixed. Measure the apparent angular difference and compare it with a farther marker. Voxel style.
Working Three.js Starter (baseline-changes-apparent-shift-x3834):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Stellar Parallax Observatory</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(8, 20, 34, 0.92);
--panel-border: #29445d;
--text: #e8f4ff;
--muted: #8ca5bb;
--near: #ff8066;
--far: #58dcff;
--yellow: #ffd166;
--green: #72efb1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.panel {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
}
.brand {
position: fixed;
top: 20px;
left: 20px;
z-index: 5;
width: 330px;
padding: 18px 20px;
border-left: 4px solid var(--yellow);
}
.eyebrow {
color: var(--yellow);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 7px;
font-size: clamp(26px, 3vw, 42px);
line-height: 0.92;
letter-spacing: -0.06em;
}
.brand p {
margin: 0;
max-width: 285px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.live {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
color: var(--green);
font-size: 10px;
letter-spacing: 0.1em;
}
.live::before {
content: "";
width: 7px;
height: 7px;
background: var(--green);
box-shadow: 0 0 12px var(--green);
}
.readout {
position: fixed;
top: 20px;
right: 20px;
z-index: 5;
width: 330px;
padding: 17px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 11px;
border-bottom: 1px solid #20374b;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.11em;
}
.status-chip {
padding: 3px 6px;
color: var(--green);
border: 1px solid #285945;
font-size: 9px;
}
.equation {
margin: 12px 0;
padding: 10px;
color: #bdd2e2;
background: #0a1928;
border: 1px solid #20374b;
text-align: center;
font-size: 12px;
}
.equation strong {
color: var(--yellow);
}
.marker-card {
margin-top: 9px;
padding: 11px 12px;
background: rgba(255, 255, 255, 0.025);
border-left: 3px solid var(--marker-color);
}
.marker-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 10px;
margin-bottom: 8px;
}
.marker-heading span:first-child {
color: var(--marker-color);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
}
.fixed {
color: var(--muted);
font-size: 8px;
letter-spacing: 0.12em;
}
.metric-row {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-top: 4px;
}
.metric-row span {
color: var(--muted);
font-size: 9px;
}
.metric-row strong {
font-size: 14px;
font-weight: 700;
}
.bar {
height: 5px;
margin-top: 9px;
overflow: hidden;
background: #14283a;
}
.bar > div {
width: 0;
height: 100%;
background: var(--marker-color);
box-shadow: 0 0 10px var(--marker-color);
transition: width 80ms linear;
}
.comparison {
display: flex;
justify-content: space-between;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid #20374b;
color: var(--muted);
font-size: 9px;
}
.comparison strong {
color: var(--yellow);
font-size: 12px;
}
.live-measurements {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid #20374b;
}
.live-row {
display: grid;
grid-template-columns: 70px 1fr 54px;
align-items: center;
gap: 8px;
margin-top: 8px;
font-size: 9px;
}
.live-row .bar {
margin: 0;
}
.live-row output {
color: var(--text);
text-align: right;
}
.controls {
position: fixed;
z-index: 6;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
width: min(780px, calc(100% - 40px));
padding: 14px 16px;
}
.control-row {
display: grid;
grid-template-columns: 110px 1fr 90px;
align-items: center;
gap: 14px;
}
.control-row + .control-row {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid #20374b;
}
.control-label {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
}
.control-label output {
display: block;
margin-top: 4px;
color: var(--text);
font-size: 11px;
}
button {
padding: 10px 12px;
color: #07111f;
background: var(--yellow);
border: 0;
border-radius: 0;
font: 700 10px "SFMono-Regular", Consolas, monospace;
letter-spacing: 0.08em;
cursor: pointer;
box-shadow: 3px 3px 0 #735b26;
}
button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
button:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 #735b26;
}
button.secondary {
color: var(--text);
background: #172c3e;
border: 1px solid #36536b;
box-shadow: 3px 3px 0 #08111c;
}
input[type="range"] {
width: 100%;
height: 5px;
appearance: none;
background: #183044;
border: 0;
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
background: var(--yellow);
border: 3px solid #08111f;
box-shadow: 0 0 0 1px var(--yellow);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
background: var(--yellow);
border: 3px solid #08111f;
border-radius: 0;
box-shadow: 0 0 0 1px var(--yellow);
}
.hint {
position: fixed;
left: 20px;
bottom: 22px;
z-index: 4;
max-width: 220px;
color: #7590a6;
font-size: 9px;
line-height: 1.7;
pointer-events: none;
}
.hint b {
color: var(--text);
}
@media (max-width: 900px) {
.brand {
width: 270px;
}
.readout {
width: 285px;
}
.hint {
display: none;
}
}
@media (max-width: 680px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 12px 14px;
}
.brand p {
display: none;
}
h1 {
font-size: 27px;
}
.readout {
top: 116px;
right: 10px;
width: 250px;
padding: 12px;
}
.equation,
.comparison {
display: none;
}
.controls {
bottom: 10px;
width: calc(100% - 20px);
padding: 12px;
}
.control-row {
grid-template-columns: 80px 1fr 66px;
gap: 9px;
}
.control-row + .control-row {
grid-template-columns: 80px 1fr 66px;
}
button {
padding: 9px 7px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="brand panel">
<div class="eyebrow">Voxel Observatory / Experiment 01</div>
<h1>STELLAR<br>PARALLAX</h1>
<p>
Move the observer between A and B. A nearby fixed target shifts more
than a distant target, revealing relative distance.
</p>
<div class="live">MEASUREMENT RUN ACTIVE</div>
</header>
<aside class="readout panel">
<div class="panel-title">
<span>ENDPOINT MEASUREMENT</span>
<span class="status-chip">A → B</span>
</div>
<div class="equation">
d = <strong>B</strong> / [ 2 tan(Δθ / 2) ]
</div>
<div class="marker-card" style="--marker-color: var(--near)">
<div class="marker-heading">
<span>NEAR BEACON</span>
<span class="fixed">FIXED IN SPACE</span>
</div>
<div class="metric-row">
<span>Angular difference</span>
<strong id="near-angle">—</strong>
</div>
<div class="metric-row">
<span>Inferred distance</span>
<strong id="near-distance">—</strong>
</div>
<div class="bar"><div id="near-bar"></div></div>
</div>
<div class="marker-card" style="--marker-color: var(--far)">
<div class="marker-heading">
<span>FAR BEACON</span>
<span class="fixed">FIXED IN SPACE</span>
</div>
<div class="metric-row">
<span>Angular difference</span>
<strong id="far-angle">—</strong>
</div>
<div class="metric-row">
<span>Inferred distance</span>
<strong id="far-distance">—</strong>
</div>
<div class="bar"><div id="far-bar"></div></div>
</div>
<div class="comparison">
<span>Near / far parallax ratio</span>
<strong id="parallax-ratio">—</strong>
</div>
<div class="live-measurements">
<div class="eyebrow">Live shift from position A</div>
<div class="live-row">
<span>NEAR</span>
<div class="bar"><div id="live-near-bar"></div></div>
<output id="live-near">0.00°</output>
</div>
<div class="live-row">
<span>FAR</span>
<div class="bar"><div id="live-far-bar"></div></div>
<output id="live-far">0.00°</output>
</div>
</div>
</aside>
<section class="controls panel">
<div class="control-row">
<button id="play-toggle" type="button">PAUSE</button>
<div>
<div class="control-label">OBSERVER POSITION</div>
<input
id="progress"
type="range"
min="0"
max="100"
step="0.1"
value="0"
aria-label="Observer position"
>
</div>
<div class="control-label">
A ↔ B
<output id="progress-value">0%</output>
</div>
</div>
<div class="control-row">
<button id="reset-view" class="secondary" type="button">RESET VIEW</button>
<div>
<div class="control-label">OBSERVATION BASELINE</div>
<input
id="baseline"
type="range"
min="12"
max="72"
step="1"
value="36"
aria-label="Observation baseline"
>
</div>
<div class="control-label">
BASELINE
<output id="baseline-value">36 u</output>
</div>
</div>
</section>
<div class="hint">
<b>DRAG</b> to orbit the camera<br>
<b>SCROLL</b> to zoom<br><br>
The beacons never move. Only the observer and its apparent sightlines change.
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
// ---------------------------------------------------------------------
// Scene setup
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 230, 760);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
1500
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
$("scene").appendChild(renderer.domElement);
const TARGET_Y = 4.9;
const NEAR_DISTANCE = 95;
const FAR_DISTANCE = 300;
let baseline = 36;
let progress = 0;
let phase = 0;
let playing = true;
let nearTheta = 0;
let farTheta = 0;
// ---------------------------------------------------------------------
// Camera controls, implemented directly without an addon
// ---------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(105, 2, 0),
radius: 350,
theta: 0.88,
phi: 0.93
};
function updateCamera() {
const spherical = new THREE.Spherical(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.setFromSpherical(spherical).add(orbit.target);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.30,
1.36
);
updateCamera();
});
function stopDragging() {
dragging = false;
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
180,
650
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0x9bcfff, 0x07101b, 1.55);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4b5, 2.5);
sun.position.set(80, 180, 120);
sun.target.position.set(110, 0, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -240;
sun.shadow.camera.right = 240;
sun.shadow.camera.top = 180;
sun.shadow.camera.bottom = -180;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 450;
scene.add(sun, sun.target);
const rimLight = new THREE.DirectionalLight(0x4e9dff, 1.1);
rimLight.position.set(350, 80, -170);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Helpers for the voxel construction
// ---------------------------------------------------------------------
function makeBox(
width,
height,
depth,
color,
x,
y,
z,
parent = scene,
emissive = 0
) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.08,
emissive,
emissiveIntensity: emissive ? 0.55 : 0
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color = "#d9edff", worldWidth = 42) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(5, 15, 26, 0.90)";
context.fillRect(8, 8, 752, 144);
context.strokeStyle = color;
context.lineWidth = 6;
context.strokeRect(8, 8, 752, 144);
context.fillStyle = color;
context.font = "bold 52px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 384, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * (160 / 768), 1);
sprite.renderOrder = 20;
return sprite;
}
function makeLine(color, opacity = 1, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 3.2,
gapSize: 2.2,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 4;
if (dashed) line.computeLineDistances();
scene.add(line);
return line;
}
function setTwoPointLine(line, a, b) {
const positions = line.geometry.getAttribute("position");
positions.setXYZ(0, a.x, a.y, a.z);
positions.setXYZ(1, b.x, b.y, b.z);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
if (line.material.isLineDashedMaterial) {
line.computeLineDistances();
}
}
// ---------------------------------------------------------------------
// Voxel terrain and star field
// ---------------------------------------------------------------------
makeBox(720, 2, 420, 0x08131f, 160, -1.2, 0);
const tileGeometry = new THREE.BoxGeometry(9.65, 0.18, 9.65);
const tileMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.95,
metalness: 0
});
const tileCountX = 46;
const tileCountZ = 21;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCountX * tileCountZ
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let ix = 0; ix < tileCountX; ix++) {
for (let iz = 0; iz < tileCountZ; iz++) {
const x = -50 + ix * 10;
const z = -100 + iz * 10;
dummy.position.set(x, -0.03, z);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
if (z === 0) {
tileColor.setHex(0x17364a);
} else {
tileColor.setHex(
(ix + iz) % 5 === 0 ? 0x102437 : 0x0b1b2a
);
}
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
const starCount = 240;
const starGeometry = new THREE.BoxGeometry(1, 1, 1);
const starMaterial = new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.82,
fog: false
});
const stars = new THREE.InstancedMesh(
starGeometry,
starMaterial,
starCount
);
const starPalette = [
new THREE.Color(0x9ec9ff),
new THREE.Color(0xffffff),
new THREE.Color(0xffd39d),
new THREE.Color(0x6fe6ff)
];
for (let i = 0; i < starCount; i++) {
const size = 0.45 + Math.random() * 1.8;
dummy.position.set(
-100 + Math.random() * 650,
42 + Math.random() * 185,
-280 + Math.random() * 560
);
dummy.scale.set(size, size, size);
dummy.updateMatrix();
stars.setMatrixAt(i, dummy.matrix);
stars.setColorAt(
i,
starPalette[Math.floor(Math.random() * starPalette.length)]
);
}
stars.instanceMatrix.needsUpdate = true;
stars.instanceColor.needsUpdate = true;
scene.add(stars);
// ---------------------------------------------------------------------
// Fixed distance markers
// ---------------------------------------------------------------------
function createMarker(x, color, labelText, labelColor) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
makeBox(14, 1, 14, 0x1b3040, 0, 0.5, 0, group);
makeBox(10, 1.5, 10, 0x27465b, 0, 1.75, 0, group);
makeBox(7, 3.2, 7, 0x36566b, 0, 3.1, 0, group);
const core = makeBox(
4.8,
4.8,
4.8,
color,
0,
TARGET_Y,
0,
group,
color
);
makeBox(3, 1.2, 3, color, 0, 7.8, 0, group, color);
makeBox(2, 3, 2, 0x294359, -5, 3.4, 0, group);
makeBox(2, 3, 2, 0x294359, 5, 3.4, 0, group);
const light = new THREE.PointLight(color, 26, 65, 2);
light.position.set(0, TARGET_Y, 0);
group.add(light);
const label = makeLabel(labelText, labelColor, 52);
label.position.set(0, 14, 0);
group.add(label);
return { group, core, label };
}
const nearMarker = createMarker(
NEAR_DISTANCE,
0xff8066,
"NEAR // 95 u",
"#ff8066"
);
const farMarker = createMarker(
FAR_DISTANCE,
0x58dcff,
"FAR // 300 u",
"#58dcff"
);
// Distance ticks along the observation corridor.
const distanceAxis = makeLine(0x3b6078, 0.6, true);
setTwoPointLine(
distanceAxis,
new THREE.Vector3(0, 0.18, 0),
new THREE.Vector3(FAR_DISTANCE, 0.18, 0)
);
for (let x = 50; x <= 300; x += 50) {
makeBox(0.65, 1.2, 0.65, 0x4b6e83, x, 0.6, 13);
const tickLabel = makeLabel(`${x} u`, "#7599af", 20);
tickLabel.position.set(x, 2.4, 17);
scene.add(tickLabel);
}
// ---------------------------------------------------------------------
// Observer, endpoint pads and sight lines
// ---------------------------------------------------------------------
const observer = new THREE.Group();
scene.add(observer);
makeBox(3.7, 1.1, 3.7, 0x24394c, 0, 0.55, 0, observer);
makeBox(2.7, 2.5, 2.7, 0xdde9f2, 0, 2.35, 0, observer);
makeBox(3.1, 2.3, 3.1, 0xe9f3fb, 0, 4.9, 0, observer);
makeBox(0.28, 0.8, 2.1, 0x142a3c, 1.58, 5, 0, observer);
makeBox(0.6, 1.3, 0.6, 0xffd166, -0.8, 6.55, 0, observer);
const observerLight = new THREE.PointLight(0xfff0c4, 16, 34, 2);
observerLight.position.set(0, 4.8, 0);
observer.add(observerLight);
const endpointPads = [
makeBox(7, 0.3, 7, 0x4d687c, 0, 0.15, 0),
makeBox(7, 0.3, 7, 0x4d687c, 0, 0.15, 0)
];
const endpointGhosts = [
makeBox(2.3, 2.3, 2.3, 0x89a9bd, 0, TARGET_Y, 0),
makeBox(2.3, 2.3, 2.3, 0x89a9bd, 0, TARGET_Y, 0)
];
for (const ghost of endpointGhosts) {
ghost.material.transparent = true;
ghost.material.opacity = 0.34;
ghost.material.depthWrite = false;
}
const endpointLabels = [
makeLabel("A", "#ffd166", 17),
makeLabel("B", "#ffd166", 17)
];
const baselineLine = makeLine(0xffd166, 0.95, false);
const nearEndpointRays = [
makeLine(0xff8066, 0.42, true),
makeLine(0xff8066, 0.42, true)
];
const farEndpointRays = [
makeLine(0x58dcff, 0.32, true),
makeLine(0x58dcff, 0.32, true)
];
const nearCurrentRay = makeLine(0xffb097, 0.96, false);
const farCurrentRay = makeLine(0x9beaff, 0.96, false);
const nearArc = makeLine(0xff8066, 0.95, false);
const farArc = makeLine(0x58dcff, 0.95, false);
nearArc.material.depthTest = false;
farArc.material.depthTest = false;
nearArc.renderOrder = 10;
farArc.renderOrder = 10;
// ---------------------------------------------------------------------
// Measurement helpers
// ---------------------------------------------------------------------
function endpointAngle(markerDistance) {
const fromA = new THREE.Vector3(
markerDistance,
0,
baseline / 2
);
const fromB = new THREE.Vector3(
markerDistance,
0,
-baseline / 2
);
return fromA.angleTo(fromB);
}
function liveAngle(markerDistance, observerZ) {
const fromA = new THREE.Vector3(
markerDistance,
0,
baseline / 2
);
const fromCurrent = new THREE.Vector3(
markerDistance,
0,
-observerZ
);
return fromA.angleTo(fromCurrent);
}
function inferredDistance(angle) {
return baseline / (2 * Math.tan(angle / 2));
}
function updateArc(line, markerDistance, radius) {
const a = new THREE.Vector2(-markerDistance, -baseline / 2);
const b = new THREE.Vector2(-markerDistance, baseline / 2);
const cross = a.x * b.y - a.y * b.x;
const dot = a.dot(b);
const signedAngle = Math.atan2(cross, dot);
const startAngle = Math.atan2(a.y, a.x);
const points = [];
for (let i = 0; i <= 40; i++) {
const t = i / 40;
const angle = startAngle + signedAngle * t;
points.push(
new THREE.Vector3(
markerDistance + Math.cos(angle) * radius,
TARGET_Y + 0.22,
Math.sin(angle) * radius
)
);
}
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
}
function updateObserverGeometry() {
const observerZ = -baseline / 2 + progress * baseline;
observer.position.set(0, 0, observerZ);
setTwoPointLine(
nearCurrentRay,
new THREE.Vector3(0, TARGET_Y, observerZ),
new THREE.Vector3(NEAR_DISTANCE, TARGET_Y, 0)
);
setTwoPointLine(
farCurrentRay,
new THREE.Vector3(0, TARGET_Y, observerZ),
new THREE.Vector3(FAR_DISTANCE, TARGET_Y, 0)
);
$("progress-value").textContent = `${Math.round(progress * 100)}%`;
$("progress").value = (progress * 100).toFixed(1);
updateLiveReadout(observerZ);
}
function updateLiveReadout(observerZ) {
const liveNear = liveAngle(NEAR_DISTANCE, observerZ);
const liveFar = liveAngle(FAR_DISTANCE, observerZ);
const nearDegrees = THREE.MathUtils.radToDeg(liveNear);
const farDegrees = THREE.MathUtils.radToDeg(liveFar);
$("live-near").textContent = `${nearDegrees.toFixed(2)}°`;
$("live-far").textContent = `${farDegrees.toFixed(2)}°`;
$("live-near-bar").style.width =
`${nearTheta > 0 ? (liveNear / nearTheta) * 100 : 0}%`;
$("live-far-bar").style.width =
`${farTheta > 0 ? (liveFar / farTheta) * 100 : 0}%`;
}
function updateFullReadout() {
nearTheta = endpointAngle(NEAR_DISTANCE);
farTheta = endpointAngle(FAR_DISTANCE);
const nearDistance = inferredDistance(nearTheta);
const farDistance = inferredDistance(farTheta);
const ratio = nearTheta / farTheta;
$("near-angle").textContent =
`${THREE.MathUtils.radToDeg(nearTheta).toFixed(2)}°`;
$("far-angle").textContent =
`${THREE.MathUtils.radToDeg(farTheta).toFixed(2)}°`;
$("near-distance").textContent = `${nearDistance.toFixed(1)} u`;
$("far-distance").textContent = `${farDistance.toFixed(1)} u`;
$("parallax-ratio").textContent = `${ratio.toFixed(2)}×`;
$("near-bar").style.width = "100%";
$("far-bar").style.width = `${(farTheta / nearTheta) * 100}%`;
$("baseline-value").textContent = `${baseline} u`;
}
function syncScene() {
const endpointZ = [-baseline / 2, baseline / 2];
endpointPads.forEach((pad, index) => {
pad.position.z = endpointZ[index];
});
endpointGhosts.forEach((ghost, index) => {
ghost.position.z = endpointZ[index];
});
endpointLabels.forEach((label, index) => {
label.position.set(-10, 2.5, endpointZ[index]);
});
setTwoPointLine(
baselineLine,
new THREE.Vector3(0, 0.35, endpointZ[0]),
new THREE.Vector3(0, 0.35, endpointZ[1])
);
for (let index = 0; index < 2; index++) {
const z = endpointZ[index];
setTwoPointLine(
nearEndpointRays[index],
new THREE.Vector3(0, TARGET_Y, z),
new THREE.Vector3(NEAR_DISTANCE, TARGET_Y, 0)
);
setTwoPointLine(
farEndpointRays[index],
new THREE.Vector3(0, TARGET_Y, z),
new THREE.Vector3(FAR_DISTANCE, TARGET_Y, 0)
);
}
updateArc(nearArc, NEAR_DISTANCE, 24);
updateArc(farArc, FAR_DISTANCE, 43);
updateFullReadout();
updateObserverGeometry();
}
// ---------------------------------------------------------------------
// Controls
// ---------------------------------------------------------------------
$("play-toggle").addEventListener("click", () => {
playing = !playing;
if (playing) {
// Resume toward position B.
phase = progress;
}
$("play-toggle").textContent = playing ? "PAUSE" : "PLAY";
});
$("progress").addEventListener("input", (event) => {
playing = false;
progress = Number(event.target.value) / 100;
phase = progress;
$("play-toggle").textContent = "PLAY";
updateObserverGeometry();
});
$("baseline").addEventListener("input", (event) => {
baseline = Number(event.target.value);
syncScene();
});
$("reset-view").addEventListener("click", () => {
orbit.target.set(105, 2, 0);
orbit.radius = 350;
orbit.theta = 0.88;
orbit.phi = 0.93;
updateCamera();
});
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
// Seven seconds from A to B, then seven seconds back.
phase = (phase + delta / 7) % 2;
progress = phase <= 1 ? phase : 2 - phase;
updateObserverGeometry();
}
nearMarker.core.material.emissiveIntensity =
0.52 + Math.sin(clock.elapsedTime * 2.2) * 0.12;
farMarker.core.material.emissiveIntensity =
0.48 + Math.sin(clock.elapsedTime * 1.8 + 1.7) * 0.11;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
syncScene();
animate();
</script>
</body>
</html>
```