Prompt specification
Build or customize the Three.js 3D scene "Longitude seam crossing and polar meridian convergence" 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: Longitude seam crossing and polar meridian convergence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/longitude-seam-crossing-and-polar-meridian-convergence-x1316
Scene Description Prompt:
Drag a marker around a voxel globe, showing longitude wrapping at 180 degrees and meridians converging at poles. Three.js from cdnjs, one HTML file.
Working Three.js Starter (longitude-seam-crossing-and-polar-meridian-convergence-x1316):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Globe — Longitude Wrap</title>
<style>
:root {
color-scheme: dark;
--bg: #020611;
--cyan: #65e6f2;
--gold: #ffd166;
--coral: #ff647c;
--muted: #8293a7;
--panel: rgba(7, 16, 29, 0.72);
--line: rgba(139, 224, 238, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
canvas.is-dragging-marker {
cursor: grabbing;
}
canvas.is-orbiting {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
color: #eaf8ff;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
header {
position: absolute;
top: 28px;
left: 30px;
max-width: 390px;
}
h1 {
margin: 7px 0 8px;
font-size: clamp(29px, 4vw, 52px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 850;
}
header p {
max-width: 330px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.status {
position: absolute;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
min-height: 38px;
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
backdrop-filter: blur(14px);
color: #a8bbca;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
letter-spacing: 0.08em;
transition: 180ms ease;
}
.status::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
.status.active {
color: #fff1d6;
border-color: rgba(255, 209, 102, 0.58);
background: rgba(54, 34, 10, 0.78);
}
.status.active::before {
background: var(--gold);
box-shadow: 0 0 16px var(--gold);
}
.coordinates {
position: absolute;
left: 30px;
bottom: 30px;
width: 238px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
}
.coordinate-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
margin-top: 14px;
}
.coordinate-value {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 19px;
font-weight: 750;
letter-spacing: -0.035em;
white-space: nowrap;
}
.coordinate-label {
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
}
.longitude-panel {
position: absolute;
left: 50%;
bottom: 30px;
width: min(550px, calc(100vw - 580px));
min-width: 340px;
transform: translateX(-50%);
padding: 15px 17px 13px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
}
.longitude-heading {
display: flex;
justify-content: space-between;
margin-bottom: 13px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.rail {
position: relative;
height: 8px;
border-radius: 999px;
background:
linear-gradient(
90deg,
rgba(255, 100, 124, 0.34) 0%,
rgba(101, 230, 242, 0.18) 24%,
rgba(101, 230, 242, 0.18) 76%,
rgba(255, 100, 124, 0.34) 100%
);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.rail::before,
.rail::after {
content: "";
position: absolute;
top: -4px;
bottom: -4px;
width: 1px;
background: var(--coral);
opacity: 0.8;
}
.rail::before {
left: 0;
}
.rail::after {
right: 0;
}
.rail-center {
position: absolute;
top: -4px;
bottom: -4px;
left: 50%;
width: 1px;
background: rgba(255, 255, 255, 0.35);
}
.longitude-indicator {
position: absolute;
top: 50%;
left: 94.4%;
width: 14px;
height: 14px;
transform: translate(-50%, -50%);
border: 2px solid #fff4c9;
border-radius: 50%;
background: var(--gold);
box-shadow:
0 0 0 4px rgba(255, 209, 102, 0.15),
0 0 18px rgba(255, 209, 102, 0.8);
transition: left 90ms linear;
}
.rail-labels {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: #62778b;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
}
.actions {
position: absolute;
right: 30px;
bottom: 30px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 10px;
}
button {
pointer-events: auto;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 16, 29, 0.78);
color: #c7d8e5;
font: 800 9px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.11em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: 150ms ease;
}
button:hover {
color: var(--gold);
border-color: rgba(255, 209, 102, 0.5);
transform: translateY(-1px);
}
.help {
max-width: 230px;
color: #718497;
font-size: 10px;
line-height: 1.65;
text-align: right;
}
.help strong {
color: #c5d6e3;
font-weight: 700;
}
#marker-hint {
position: absolute;
left: 50%;
top: 50%;
padding: 7px 10px;
transform: translate(-50%, -165%);
border: 1px solid rgba(255, 209, 102, 0.35);
border-radius: 8px;
background: rgba(12, 13, 12, 0.72);
color: var(--gold);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
white-space: nowrap;
transition: opacity 250ms ease;
}
#marker-hint.hidden {
opacity: 0;
}
@media (max-width: 900px) {
header {
top: 20px;
left: 20px;
}
header p {
display: none;
}
.status {
top: 20px;
right: 18px;
max-width: 44vw;
}
.coordinates {
left: 16px;
bottom: 100px;
width: 205px;
}
.longitude-panel {
left: 16px;
right: 16px;
bottom: 16px;
width: auto;
min-width: 0;
transform: none;
}
.actions {
display: none;
}
}
</style>
</head>
<body>
<div id="ui">
<header>
<div class="eyebrow">Spatial Navigation / 01</div>
<h1>VOXEL<br />WRAP</h1>
<p>
Drag the gold marker across the coral antimeridian. Longitude wraps
continuously from +180° to −180° while every meridian meets at the poles.
</p>
</header>
<div class="status" id="status">SURFACE LOCK · READY</div>
<section class="coordinates" aria-live="polite">
<div class="eyebrow">Surface Coordinates</div>
<div class="coordinate-row">
<div>
<div class="coordinate-label">LONGITUDE</div>
<div class="coordinate-value" id="longitude-value">160.0° E</div>
</div>
<div>
<div class="coordinate-label">LATITUDE</div>
<div class="coordinate-value" id="latitude-value">20.0° N</div>
</div>
</div>
</section>
<section class="longitude-panel">
<div class="longitude-heading">
<span>Signed Longitude Range</span>
<span>−180° / +180°</span>
</div>
<div class="rail">
<div class="rail-center"></div>
<div class="longitude-indicator" id="longitude-indicator"></div>
</div>
<div class="rail-labels">
<span>180° W</span>
<span>90° W</span>
<span>0°</span>
<span>90° E</span>
<span>180° E</span>
</div>
</section>
<div class="actions">
<button id="view-seam">View date line</button>
<button id="reset-marker">Reset marker</button>
<div class="help">
<strong>Drag gold marker</strong> to navigate<br />
<strong>Drag globe</strong> to rotate<br />
<strong>Scroll</strong> to zoom
</div>
</div>
<div id="marker-hint">DRAG MARKER</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x020611);
scene.fog = new THREE.FogExp2(0x020611, 0.022);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const canvas = renderer.domElement;
canvas.setAttribute("aria-label", "Interactive voxel globe");
canvas.tabIndex = 0;
const GLOBE_RADIUS = 3.05;
const LONGITUDE_COUNT = 96;
const LATITUDE_COUNT = 48;
const Z_AXIS = new THREE.Vector3(0, 0, 1);
const longitudeValue = document.getElementById("longitude-value");
const latitudeValue = document.getElementById("latitude-value");
const longitudeIndicator = document.getElementById("longitude-indicator");
const statusElement = document.getElementById("status");
const markerHint = document.getElementById("marker-hint");
let azimuth = Math.PI;
let elevation = 0.14;
let cameraDistance = 9.1;
let markerLongitude = 160;
let markerLatitude = 20;
let lastLongitude = markerLongitude;
let wrapCount = 0;
let seamPulse = 0;
let statusTimer;
let dragMode = null;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const horizontal = Math.cos(elevation) * cameraDistance;
camera.position.set(
Math.sin(azimuth) * horizontal,
Math.sin(elevation) * cameraDistance,
Math.cos(azimuth) * horizontal
);
camera.lookAt(0, 0, 0);
}
updateCamera();
// Lighting
scene.add(new THREE.AmbientLight(0x8abbd0, 0.95));
const keyLight = new THREE.DirectionalLight(0xd9f4ff, 2.5);
keyLight.position.set(-5, 7, 5);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x428cff, 2.2);
rimLight.position.set(6, 1, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb65c, 24, 15, 2);
warmLight.position.set(-4, -2, 4);
scene.add(warmLight);
// Background stars
{
const count = 1100;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const radius = 18 + Math.random() * 28;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i * 3] =
radius * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] =
radius * Math.cos(phi);
positions[i * 3 + 2] =
radius * Math.sin(phi) * Math.sin(theta);
const brightness = 0.45 + Math.random() * 0.55;
colors[i * 3] = brightness * 0.7;
colors[i * 3 + 1] = brightness * 0.88;
colors[i * 3 + 2] = brightness;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.BufferAttribute(colors, 3)
);
const stars = new THREE.Points(
geometry,
new THREE.PointsMaterial({
size: 0.035,
vertexColors: true,
transparent: true,
opacity: 0.82,
depthWrite: false
})
);
scene.add(stars);
}
function lonLatToVector(longitude, latitude, radius = GLOBE_RADIUS) {
const lon = THREE.MathUtils.degToRad(longitude);
const lat = THREE.MathUtils.degToRad(latitude);
return new THREE.Vector3(
radius * Math.cos(lat) * Math.sin(lon),
radius * Math.sin(lat),
radius * Math.cos(lat) * Math.cos(lon)
);
}
// Rough, embedded continent outlines used to color the voxel surface.
const landPolygons = [
// North America
[
[-168, 65], [-151, 72], [-130, 70], [-112, 61],
[-96, 51], [-82, 25], [-98, 15], [-114, 29],
[-124, 47], [-145, 54]
],
// Greenland
[
[-73, 59], [-48, 60], [-22, 75], [-42, 84],
[-63, 82], [-76, 70]
],
// South America
[
[-81, 12], [-67, 9], [-50, 2], [-35, -8],
[-42, -23], [-54, -36], [-68, -55], [-76, -35],
[-80, -10]
],
// Africa
[
[-17, 35], [5, 37], [25, 32], [35, 16],
[51, 11], [42, -12], [32, -30], [18, -35],
[8, -20], [-2, 5], [-16, 15]
],
// Europe and Asia
[
[-11, 36], [-10, 58], [10, 71], [35, 70],
[61, 76], [96, 78], [130, 70], [170, 62],
[180, 49], [160, 35], [137, 21], [121, 1],
[106, 7], [91, 23], [76, 8], [61, 26],
[45, 12], [35, 36], [20, 41], [8, 45], [0, 38]
],
// Australia
[
[113, -22], [121, -12], [137, -10], [153, -25],
[151, -39], [132, -43], [116, -34]
],
// Madagascar
[
[47, -13], [50, -17], [48, -26], [44, -23]
],
// Japan
[
[130, 31], [141, 45], [146, 43], [137, 32]
],
// Britain
[
[-8, 50], [1, 51], [-3, 59], [-7, 58]
]
];
function pointInPolygon(longitude, latitude, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const xi = polygon[i][0];
const yi = polygon[i][1];
const xj = polygon[j][0];
const yj = polygon[j][1];
const intersects =
yi > latitude !== yj > latitude &&
longitude <
((xj - xi) * (latitude - yi)) /
(yj - yi) +
xi;
if (intersects) inside = !inside;
}
return inside;
}
function isLand(longitude, latitude) {
if (latitude < -72) return true;
return landPolygons.some((polygon) =>
pointInPolygon(longitude, latitude, polygon)
);
}
function hash(longitude, latitude) {
const value = Math.sin(
longitude * 12.9898 + latitude * 78.233
) * 43758.5453;
return value - Math.floor(value);
}
// Voxel sphere
{
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.68,
metalness: 0.08
});
const voxelCount = LONGITUDE_COUNT * LATITUDE_COUNT;
const mesh = new THREE.InstancedMesh(
geometry,
material,
voxelCount
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let instance = 0;
for (let y = 0; y < LATITUDE_COUNT; y++) {
const latitude =
-90 + (y + 0.5) * (180 / LATITUDE_COUNT);
for (let x = 0; x < LONGITUDE_COUNT; x++) {
const longitude =
-180 + (x + 0.5) * (360 / LONGITUDE_COUNT);
const normal = lonLatToVector(
longitude,
latitude,
1
);
dummy.position.copy(normal).multiplyScalar(GLOBE_RADIUS);
dummy.quaternion.setFromUnitVectors(Z_AXIS, normal);
dummy.scale.set(0.178, 0.178, 0.2);
dummy.updateMatrix();
mesh.setMatrixAt(instance, dummy.matrix);
const land = isLand(longitude, latitude);
const greenland =
pointInPolygon(longitude, latitude, landPolygons[1]);
const ice =
Math.abs(latitude) > 78 ||
(greenland && latitude > 61);
const variation = hash(longitude, latitude);
if (ice) {
color.setHSL(
0.53 + variation * 0.025,
0.28,
0.76 + variation * 0.08
);
} else if (land) {
color.setHSL(
0.37 + variation * 0.055,
0.36 + variation * 0.12,
0.34 + variation * 0.13
);
} else {
color.setHSL(
0.535 + variation * 0.035,
0.53 + variation * 0.12,
0.22 + variation * 0.1
);
}
mesh.setColorAt(instance, color);
instance++;
}
}
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
scene.add(mesh);
}
// Atmospheric shell
{
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(GLOBE_RADIUS * 1.075, 64, 32),
new THREE.MeshBasicMaterial({
color: 0x55d9f2,
transparent: true,
opacity: 0.065,
side: THREE.BackSide,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
scene.add(atmosphere);
}
// Meridian and parallel grid. Every meridian reaches the exact poles.
function createMeridian(longitude, radius, material) {
const points = [];
for (let latitude = -90; latitude <= 90; latitude += 1.5) {
points.push(
lonLatToVector(longitude, latitude, radius)
);
}
return new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
material
);
}
const meridianMaterial = new THREE.LineBasicMaterial({
color: 0x72d7e8,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const parallelMaterial = new THREE.LineBasicMaterial({
color: 0x5ca6c1,
transparent: true,
opacity: 0.16,
depthWrite: false
});
for (let longitude = -165; longitude < 180; longitude += 15) {
scene.add(
createMeridian(
longitude,
GLOBE_RADIUS + 0.13,
meridianMaterial
)
);
}
for (const latitude of [-60, -30, 0, 30, 60]) {
const points = [];
for (let longitude = -180; longitude <= 180; longitude += 1.5) {
points.push(
lonLatToVector(
longitude,
latitude,
GLOBE_RADIUS + 0.13
)
);
}
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
parallelMaterial
)
);
}
// Antimeridian
const seamGlowMaterial = new THREE.LineBasicMaterial({
color: 0xff536d,
transparent: true,
opacity: 0.34,
depthWrite: false
});
const seamGlow = createMeridian(
180,
GLOBE_RADIUS + 0.185,
seamGlowMaterial
);
scene.add(seamGlow);
const seamMaterial = new THREE.LineDashedMaterial({
color: 0xff758a,
dashSize: 0.13,
gapSize: 0.075,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const seamLine = createMeridian(
180,
GLOBE_RADIUS + 0.195,
seamMaterial
);
seamLine.computeLineDistances();
scene.add(seamLine);
// Highlighted meridian follows the marker.
const selectedMaterial = new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const selectedMeridian = new THREE.Line(
new THREE.BufferGeometry(),
selectedMaterial
);
scene.add(selectedMeridian);
function updateSelectedMeridian(longitude) {
const points = [];
for (let latitude = -90; latitude <= 90; latitude += 1.5) {
points.push(
lonLatToVector(
longitude,
latitude,
GLOBE_RADIUS + 0.21
)
);
}
const oldGeometry = selectedMeridian.geometry;
selectedMeridian.geometry =
new THREE.BufferGeometry().setFromPoints(points);
oldGeometry.dispose();
}
// Marker
const markerGroup = new THREE.Group();
const markerCube = new THREE.Mesh(
new THREE.BoxGeometry(0.23, 0.23, 0.23),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xff9f1c,
emissiveIntensity: 1.4,
roughness: 0.3,
metalness: 0.18
})
);
markerGroup.add(markerCube);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.025, 10, 48),
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.96
})
);
markerGroup.add(markerRing);
const outerMarkerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.38, 0.009, 8, 48),
new THREE.MeshBasicMaterial({
color: 0xfff0b3,
transparent: true,
opacity: 0.62
})
);
markerGroup.add(outerMarkerRing);
// Invisible enlarged hit target.
const markerHitTarget = new THREE.Mesh(
new THREE.SphereGeometry(0.4, 16, 12),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
markerGroup.add(markerHitTarget);
const markerLight = new THREE.PointLight(0xffc45c, 2.2, 2.2);
markerGroup.add(markerLight);
scene.add(markerGroup);
// Drag trail
const MAX_TRAIL_POINTS = 180;
const trailPoints = [];
const trailGeometry = new THREE.BufferGeometry();
const trailPositionAttribute = new THREE.BufferAttribute(
new Float32Array(MAX_TRAIL_POINTS * 3),
3
);
trailPositionAttribute.setUsage(THREE.DynamicDrawUsage);
trailGeometry.setAttribute("position", trailPositionAttribute);
trailGeometry.setDrawRange(0, 0);
const trail = new THREE.Line(
trailGeometry,
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
trail.frustumCulled = false;
scene.add(trail);
function addTrailPoint() {
trailPoints.push(
lonLatToVector(
markerLongitude,
markerLatitude,
GLOBE_RADIUS + 0.16
)
);
if (trailPoints.length > MAX_TRAIL_POINTS) {
trailPoints.shift();
}
trailPoints.forEach((point, index) => {
trailPositionAttribute.setXYZ(
index,
point.x,
point.y,
point.z
);
});
trailPositionAttribute.needsUpdate = true;
trailGeometry.setDrawRange(0, trailPoints.length);
}
// Canvas labels
function makeLabel(text, color = "#9ceaf4") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(3, 10, 18, 0.78)";
context.fillRect(0, 0, 512, 128);
context.strokeStyle = "rgba(140, 225, 240, 0.3)";
context.lineWidth = 3;
context.strokeRect(2, 2, 508, 124);
context.fillStyle = color;
context.font = "700 34px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
return sprite;
}
const northLabel = makeLabel("NORTH POLE");
northLabel.position.set(0, GLOBE_RADIUS + 0.48, 0);
northLabel.scale.set(1.55, 0.39, 1);
scene.add(northLabel);
const southLabel = makeLabel("SOUTH POLE");
southLabel.position.set(0, -GLOBE_RADIUS - 0.48, 0);
southLabel.scale.set(1.55, 0.39, 1);
scene.add(southLabel);
const dateLineLabel = makeLabel("180° DATE LINE", "#ff8293");
dateLineLabel.position.copy(
lonLatToVector(180, -35, GLOBE_RADIUS + 0.42)
);
dateLineLabel.scale.set(1.9, 0.475, 1);
scene.add(dateLineLabel);
// Coordinate formatting
function normalizeLongitude(longitude) {
return (
((longitude + 180) % 360 + 360) % 360
) - 180;
}
function formatLongitude(longitude) {
const absolute = Math.abs(longitude);
const direction =
longitude === 0 ? "" : longitude > 0 ? "E" : "W";
return `${absolute.toFixed(1)}° ${direction}`.trim();
}
function formatLatitude(latitude) {
const absolute = Math.abs(latitude);
const direction =
latitude === 0 ? "" : latitude > 0 ? "N" : "S";
return `${absolute.toFixed(1)}° ${direction}`.trim();
}
function flashStatus(message) {
statusElement.textContent = message;
statusElement.classList.add("active");
clearTimeout(statusTimer);
statusTimer = setTimeout(() => {
statusElement.classList.remove("active");
statusElement.textContent = "SURFACE LOCK · READY";
}, 2200);
}
function updateReadout() {
longitudeValue.textContent =
formatLongitude(markerLongitude);
latitudeValue.textContent =
formatLatitude(markerLatitude);
const percentage =
((markerLongitude + 180) / 360) * 100;
longitudeIndicator.style.left =
`${THREE.MathUtils.clamp(percentage, 0, 100)}%`;
}
function setMarker(longitude, latitude, detectWrap = false) {
const normalizedLongitude =
normalizeLongitude(longitude);
markerLongitude = normalizedLongitude;
markerLatitude = THREE.MathUtils.clamp(latitude, -90, 90);
if (
detectWrap &&
lastLongitude !== null &&
Math.abs(markerLongitude - lastLongitude) > 180
) {
wrapCount++;
seamPulse = 1;
flashStatus(
`ANTIMERIDIAN WRAP ${wrapCount} · +180° ↔ −180°`
);
}
lastLongitude = markerLongitude;
const normal = lonLatToVector(
markerLongitude,
markerLatitude,
1
);
markerGroup.position
.copy(normal)
.multiplyScalar(GLOBE_RADIUS + 0.26);
markerGroup.quaternion.setFromUnitVectors(
Z_AXIS,
normal
);
updateSelectedMeridian(markerLongitude);
updateReadout();
}
setMarker(markerLongitude, markerLatitude);
// Pointer interaction
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const dragSphere = new THREE.Sphere(
new THREE.Vector3(),
GLOBE_RADIUS + 0.26
);
const intersection = new THREE.Vector3();
function updatePointer(event) {
const bounds = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
}
function updateRay() {
raycaster.setFromCamera(pointer, camera);
}
function markerIsFrontFacing() {
const normal = markerGroup.position.clone().normalize();
const toCamera = camera.position
.clone()
.sub(markerGroup.position);
return normal.dot(toCamera) > -0.05;
}
canvas.addEventListener("pointerdown", (event) => {
if (
event.pointerType === "mouse" &&
event.button !== 0
) {
return;
}
updatePointer(event);
updateRay();
const markerHits = raycaster.intersectObject(
markerGroup,
true
);
previousX = event.clientX;
previousY = event.clientY;
if (
markerHits.length > 0 &&
markerIsFrontFacing()
) {
dragMode = "marker";
markerHint.classList.add("hidden");
canvas.classList.add("is-dragging-marker");
} else {
dragMode = "orbit";
canvas.classList.add("is-orbiting");
}
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragMode) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragMode === "orbit") {
azimuth -= deltaX * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + deltaY * 0.005,
-1.35,
1.35
);
updateCamera();
return;
}
updatePointer(event);
updateRay();
if (
raycaster.ray.intersectSphere(
dragSphere,
intersection
)
) {
const normal = intersection.clone().normalize();
const latitude = Math.asin(
THREE.MathUtils.clamp(normal.y, -1, 1)
);
const longitude = Math.atan2(
normal.x,
normal.z
);
setMarker(
THREE.MathUtils.radToDeg(longitude),
THREE.MathUtils.radToDeg(latitude),
true
);
addTrailPoint();
}
});
function endDrag(event) {
dragMode = null;
canvas.classList.remove(
"is-dragging-marker",
"is-orbiting"
);
if (
event &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
window.addEventListener("pointerup", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * Math.exp(event.deltaY * 0.001),
6.4,
13.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document
.getElementById("view-seam")
.addEventListener("click", () => {
azimuth = Math.PI;
elevation = 0.14;
updateCamera();
});
document
.getElementById("reset-marker")
.addEventListener("click", () => {
trailPoints.length = 0;
trailGeometry.setDrawRange(0, 0);
wrapCount = 0;
seamPulse = 0;
setMarker(160, 20);
});
// Resize
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(
Math.min(devicePixelRatio, 2)
);
});
// Animation
const projectedMarker = new THREE.Vector3();
function animate(time) {
seamPulse *= 0.94;
seamGlowMaterial.opacity =
0.3 + seamPulse * 0.65;
const pulse = 1 + Math.sin(time * 0.004) * 0.055;
outerMarkerRing.scale.setScalar(pulse);
outerMarkerRing.rotation.z = time * 0.00025;
projectedMarker
.copy(markerGroup.position)
.project(camera);
const hintX =
((projectedMarker.x + 1) / 2) * innerWidth;
const hintY =
((1 - projectedMarker.y) / 2) * innerHeight;
markerHint.style.left = `${hintX}px`;
markerHint.style.top = `${hintY}px`;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```