Prompt specification
Build or customize the Three.js 3D scene "Three meridians and local solar clocks" 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: Three meridians and local solar clocks
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-meridians-and-local-solar-clocks-x1350
Scene Description Prompt:
Place three solar clocks along equatorial meridians of a low-poly rotating globe beneath fixed sunlight. One HTML file using Three.js from cdnjs.
Working Three.js Starter (three-meridians-and-local-solar-clocks-x1350):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Solar Meridians</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 65% 35%, #142448 0%, #080e20 42%, #030610 100%);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 26px;
left: 28px;
max-width: 360px;
padding: 18px 20px;
border: 1px solid rgba(155, 203, 255, 0.16);
border-radius: 16px;
background: rgba(7, 14, 30, 0.58);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 8px;
color: #7edff2;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #f4f8ff;
font-size: clamp(24px, 3vw, 38px);
font-weight: 650;
letter-spacing: -0.035em;
line-height: 1.05;
}
.subtitle {
margin: 10px 0 0;
color: #9eacc7;
font-size: 13px;
line-height: 1.55;
}
.sun-status {
position: absolute;
top: 28px;
right: 28px;
display: flex;
align-items: center;
gap: 10px;
padding: 11px 14px;
border: 1px solid rgba(255, 205, 101, 0.2);
border-radius: 999px;
color: #ffe1a1;
background: rgba(22, 17, 10, 0.56);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.sun-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #ffc861;
box-shadow:
0 0 0 4px rgba(255, 200, 97, 0.1),
0 0 18px #ffc861;
}
.legend {
position: absolute;
left: 28px;
bottom: 26px;
display: flex;
flex-wrap: wrap;
gap: 9px 16px;
max-width: calc(100vw - 56px);
padding: 12px 15px;
border: 1px solid rgba(155, 203, 255, 0.13);
border-radius: 12px;
color: #aebbd1;
background: rgba(7, 14, 30, 0.54);
font-size: 11px;
backdrop-filter: blur(12px);
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 16px;
height: 3px;
border-radius: 999px;
background: currentColor;
}
.cyan {
color: #63e7dd;
}
.gold {
color: #ffd56c;
}
.orange {
color: #ff914d;
}
.hint {
position: absolute;
right: 28px;
bottom: 29px;
color: rgba(185, 200, 225, 0.62);
font-size: 11px;
letter-spacing: 0.04em;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
right: 14px;
max-width: none;
padding: 14px 16px;
}
.subtitle {
max-width: 270px;
}
.sun-status {
top: auto;
right: 14px;
bottom: 66px;
}
.legend {
left: 14px;
bottom: 14px;
right: 14px;
gap: 8px 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene"></main>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Equatorial light study</div>
<h1>Solar Meridians</h1>
<p class="subtitle">
Three solar clocks ride a faceted globe. The Earth turns beneath a
sunlight source locked to the world frame.
</p>
</section>
<div class="sun-status">
<span class="sun-dot"></span>
Sunlight locked
</div>
<div class="legend">
<span class="legend-item">
<span class="swatch cyan"></span>
Local solar hour
</span>
<span class="legend-item">
<span class="swatch gold"></span>
Solar minutes
</span>
<span class="legend-item">
<span class="swatch orange"></span>
Projected sun shadow
</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: 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.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly globe with three equatorial solar clocks"
);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x050914, 0.018);
const camera = new THREE.PerspectiveCamera(
56,
window.innerWidth / window.innerHeight,
0.1,
100
);
const GLOBE_RADIUS = 2.2;
const Y_AXIS = new THREE.Vector3(0, 1, 0);
// Direction from the Earth toward the fixed Sun.
const sunDirection = new THREE.Vector3(-0.78, 0.38, 0.50).normalize();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0x8fcaff, 0x071020, 1.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffedc4, 3.1);
sunlight.position.copy(sunDirection).multiplyScalar(12);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(1024, 1024);
sunlight.shadow.camera.left = -4.5;
sunlight.shadow.camera.right = 4.5;
sunlight.shadow.camera.top = 4.5;
sunlight.shadow.camera.bottom = -4.5;
sunlight.shadow.camera.near = 0.5;
sunlight.shadow.camera.far = 26;
sunlight.shadow.bias = -0.0002;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight);
scene.add(sunlight.target);
// -------------------------------------------------------------------------
// Background stars
// -------------------------------------------------------------------------
const starPositions = [];
for (let i = 0; i < 420; i++) {
const z = Math.random() * 2 - 1;
const angle = Math.random() * Math.PI * 2;
const radius = 32 + Math.random() * 12;
const planar = Math.sqrt(1 - z * z);
starPositions.push(
radius * planar * Math.cos(angle),
radius * z,
radius * planar * Math.sin(angle)
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xa8c8ff,
size: 0.055,
transparent: true,
opacity: 0.72,
depthWrite: false,
fog: false
})
);
scene.add(stars);
// -------------------------------------------------------------------------
// Procedural low-poly globe
// -------------------------------------------------------------------------
const continents = [
{ lon: -102, lat: 46, rx: 31, ry: 23 },
{ lon: -83, lat: 16, rx: 20, ry: 13 },
{ lon: -60, lat: -15, rx: 22, ry: 35 },
{ lon: 18, lat: 51, rx: 27, ry: 16 },
{ lon: 20, lat: 8, rx: 24, ry: 35 },
{ lon: 88, lat: 43, rx: 67, ry: 24 },
{ lon: 135, lat: -25, rx: 25, ry: 15 },
{ lon: -42, lat: 73, rx: 15, ry: 10 },
{ lon: 47, lat: -12, rx: 7, ry: 22 },
{ lon: -8, lat: 42, rx: 13, ry: 15 }
];
function isLand(lon, lat) {
for (const shape of continents) {
const longitudeDifference =
((lon - shape.lon + 540) % 360) - 180;
const x = longitudeDifference / shape.rx;
const y = (lat - shape.lat) / shape.ry;
if (x * x + y * y < 1) {
return true;
}
}
return false;
}
function faceColor(lon, lat) {
const land = isLand(lon, lat);
let color;
if (!land) {
color = new THREE.Color(0x15567b);
} else if (lat > 66) {
color = new THREE.Color(0xcbd8d8);
} else if (
(lat > 15 && lat < 34) &&
(lon > -18 && lon < 118)
) {
color = new THREE.Color(0xb99a60);
} else {
color = new THREE.Color(0x629d61);
}
const raw =
Math.sin(
(lon + 31.7) * 12.9898 +
(lat + 78.2) * 37.719
) * 43758.5453;
const variation = raw - Math.floor(raw);
color.offsetHSL(
(variation - 0.5) * 0.012,
(variation - 0.5) * 0.055,
(variation - 0.5) * 0.085
);
return color;
}
function createGlobeGeometry() {
const longitudeSegments = 24;
const latitudeSegments = 12;
const vertices = [];
for (let y = 0; y <= latitudeSegments; y++) {
const latitude =
-Math.PI / 2 + (y / latitudeSegments) * Math.PI;
for (let x = 0; x <= longitudeSegments; x++) {
const longitude =
-Math.PI + (x / longitudeSegments) * Math.PI * 2;
const cosLatitude = Math.cos(latitude);
vertices.push(
cosLatitude * Math.cos(longitude),
Math.sin(latitude),
cosLatitude * Math.sin(longitude)
);
}
}
const stride = longitudeSegments + 1;
const positions = [];
const colors = [];
function addTriangle(a, b, c) {
const ax = vertices[a * 3];
const ay = vertices[a * 3 + 1];
const az = vertices[a * 3 + 2];
const bx = vertices[b * 3];
const by = vertices[b * 3 + 1];
const bz = vertices[b * 3 + 2];
const cx = vertices[c * 3];
const cy = vertices[c * 3 + 1];
const cz = vertices[c * 3 + 2];
const centerLongitude =
Math.atan2(
az + bz + cz,
ax + bx + cx
) * 180 / Math.PI;
const centerLatitude =
Math.asin(
THREE.MathUtils.clamp(
(ay + by + cy) / 3,
-1,
1
)
) * 180 / Math.PI;
const color = faceColor(centerLongitude, centerLatitude);
positions.push(
ax, ay, az,
bx, by, bz,
cx, cy, cz
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
for (let y = 0; y < latitudeSegments; y++) {
for (let x = 0; x < longitudeSegments; x++) {
const a = y * stride + x;
const b = y * stride + x + 1;
const c = (y + 1) * stride + x;
const d = (y + 1) * stride + x + 1;
addTriangle(a, d, b);
addTriangle(a, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const globe = new THREE.Group();
globe.rotation.y = 0.2;
scene.add(globe);
const globeGeometry = createGlobeGeometry();
const globeMesh = new THREE.Mesh(
globeGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.82,
metalness: 0.02
})
);
globeMesh.castShadow = true;
globeMesh.receiveShadow = true;
globe.add(globeMesh);
const globeWire = new THREE.LineSegments(
new THREE.WireframeGeometry(globeGeometry),
new THREE.LineBasicMaterial({
color: 0x9adfff,
transparent: true,
opacity: 0.085,
depthWrite: false
})
);
globeWire.scale.setScalar(1.002);
globe.add(globeWire);
// -------------------------------------------------------------------------
// Meridian grid
// -------------------------------------------------------------------------
const clockData = [
{
id: "I",
longitude: THREE.MathUtils.degToRad(-60),
accent: 0xffc857,
accentCSS: "#ffc857"
},
{
id: "II",
longitude: THREE.MathUtils.degToRad(30),
accent: 0x5ee7d7,
accentCSS: "#5ee7d7"
},
{
id: "III",
longitude: THREE.MathUtils.degToRad(120),
accent: 0xff7f9e,
accentCSS: "#ff7f9e"
}
];
function meridianPoints(longitude, radius) {
const points = [];
const radial = new THREE.Vector3(
Math.cos(longitude),
0,
Math.sin(longitude)
);
for (let i = 0; i <= 80; i++) {
const latitude = -Math.PI / 2 + (i / 80) * Math.PI;
const point = radial
.clone()
.multiplyScalar(Math.cos(latitude) * radius)
.addScaledVector(Y_AXIS, Math.sin(latitude) * radius);
points.push(point);
}
return points;
}
for (let degrees = 0; degrees < 360; degrees += 30) {
const longitude = THREE.MathUtils.degToRad(degrees);
const selected = clockData.find(
item => Math.abs(item.longitude - longitude) < 0.001
);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
meridianPoints(longitude, GLOBE_RADIUS * 1.012)
),
new THREE.LineBasicMaterial({
color: selected ? selected.accent : 0x82b9df,
transparent: true,
opacity: selected ? 0.62 : 0.105,
depthWrite: false
})
);
globe.add(line);
}
const equatorPoints = [];
for (let i = 0; i < 160; i++) {
const longitude = (i / 160) * Math.PI * 2;
equatorPoints.push(
new THREE.Vector3(
Math.cos(longitude) * GLOBE_RADIUS * 1.015,
0,
Math.sin(longitude) * GLOBE_RADIUS * 1.015
)
);
}
const equator = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(equatorPoints),
new THREE.LineBasicMaterial({
color: 0xf5d47c,
transparent: true,
opacity: 0.46,
depthWrite: false
})
);
globe.add(equator);
const axis = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -GLOBE_RADIUS * 1.12, 0),
new THREE.Vector3(0, GLOBE_RADIUS * 1.12, 0)
]),
new THREE.LineBasicMaterial({
color: 0xaac9e7,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
globe.add(axis);
// -------------------------------------------------------------------------
// Canvas textures
// -------------------------------------------------------------------------
function roundedRectPath(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function createDialTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 512;
const context = canvas.getContext("2d");
const center = 256;
const gradient = context.createRadialGradient(
center - 40,
center - 55,
20,
center,
center,
256
);
gradient.addColorStop(0, "#142c43");
gradient.addColorStop(0.62, "#0a1728");
gradient.addColorStop(1, "#050b15");
context.fillStyle = gradient;
context.beginPath();
context.arc(center, center, 250, 0, Math.PI * 2);
context.fill();
context.strokeStyle = "rgba(171,220,255,.18)";
context.lineWidth = 3;
context.stroke();
for (let i = 0; i < 60; i++) {
const angle = -Math.PI / 2 + (i / 60) * Math.PI * 2;
const major = i % 5 === 0;
const outer = 224;
const inner = major ? 190 : 207;
context.beginPath();
context.moveTo(
center + Math.cos(angle) * inner,
center + Math.sin(angle) * inner
);
context.lineTo(
center + Math.cos(angle) * outer,
center + Math.sin(angle) * outer
);
context.strokeStyle = major
? "rgba(224,240,255,.88)"
: "rgba(171,210,242,.35)";
context.lineWidth = major ? 4 : 2;
context.stroke();
}
context.fillStyle = "#d8e8f7";
context.font = "600 37px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
const numbers = [
{ value: 12, angle: -Math.PI / 2 },
{ value: 3, angle: 0 },
{ value: 6, angle: Math.PI / 2 },
{ value: 9, angle: Math.PI }
];
for (const number of numbers) {
context.fillText(
String(number.value),
center + Math.cos(number.angle) * 163,
center + Math.sin(number.angle) * 163
);
}
context.fillStyle = "rgba(138,202,236,.62)";
context.font = "700 17px system-ui";
context.letterSpacing = "4px";
context.fillText("SOLAR", center, center + 81);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
const dialTexture = createDialTexture();
function createClockLabelTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return { canvas, context: canvas.getContext("2d"), texture };
}
function drawClockLabel(clock, longitudeText, hours, minutes) {
const { context, texture } = clock.label;
context.clearRect(0, 0, 512, 144);
roundedRectPath(context, 7, 7, 498, 130, 22);
context.fillStyle = "rgba(5,12,24,.88)";
context.fill();
context.strokeStyle = clock.accentCSS;
context.globalAlpha = 0.72;
context.lineWidth = 3;
context.stroke();
context.globalAlpha = 1;
context.textAlign = "left";
context.textBaseline = "middle";
context.fillStyle = clock.accentCSS;
context.font = "700 22px system-ui";
context.fillText(
`MERIDIAN ${clock.id} · ${longitudeText}`,
28,
43
);
context.fillStyle = "#eef6ff";
context.font = "650 39px system-ui";
context.fillText(
`SOLAR ${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`,
28,
94
);
texture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Solar clocks
// -------------------------------------------------------------------------
function createHand(length, width, material, z) {
const pivot = new THREE.Group();
pivot.position.z = z;
const hand = new THREE.Mesh(
new THREE.BoxGeometry(length, width, 0.018),
material
);
hand.position.x = length * 0.42;
pivot.add(hand);
const tail = new THREE.Mesh(
new THREE.BoxGeometry(0.085, width * 0.85, 0.016),
material
);
tail.position.x = -0.042;
pivot.add(tail);
return pivot;
}
function createSolarClock(data) {
const longitude = data.longitude;
const normal = new THREE.Vector3(
Math.cos(longitude),
0,
Math.sin(longitude)
);
const right = new THREE.Vector3(
Math.sin(longitude),
0,
-Math.cos(longitude)
);
const up = new THREE.Vector3(0, 1, 0);
const clock = {
...data,
longitude,
normal,
right,
up,
label: createClockLabelTexture(),
labelAccumulator: 0
};
const group = new THREE.Group();
group.position.copy(normal).multiplyScalar(GLOBE_RADIUS + 0.72);
const orientation = new THREE.Matrix4().makeBasis(
right,
up,
normal
);
group.quaternion.setFromRotationMatrix(orientation);
globe.add(group);
// Radial support between the globe and the clock.
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, 0.72, 8),
new THREE.MeshStandardMaterial({
color: data.accent,
emissive: data.accent,
emissiveIntensity: 0.18,
metalness: 0.65,
roughness: 0.35
})
);
stem.rotation.x = Math.PI / 2;
stem.position.z = -0.36;
stem.castShadow = true;
group.add(stem);
const face = new THREE.Mesh(
new THREE.CircleGeometry(0.58, 48),
new THREE.MeshStandardMaterial({
map: dialTexture,
emissive: 0x16364b,
emissiveMap: dialTexture,
emissiveIntensity: 0.48,
metalness: 0.08,
roughness: 0.64
})
);
face.castShadow = true;
face.receiveShadow = true;
group.add(face);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.605, 0.034, 8, 48),
new THREE.MeshStandardMaterial({
color: data.accent,
emissive: data.accent,
emissiveIntensity: 0.32,
metalness: 0.58,
roughness: 0.3
})
);
ring.position.z = 0.018;
ring.castShadow = true;
group.add(ring);
const hourPivot = createHand(
0.29,
0.047,
new THREE.MeshStandardMaterial({
color: 0x69eee3,
emissive: 0x1a6967,
emissiveIntensity: 0.65,
metalness: 0.18,
roughness: 0.42
}),
0.045
);
const minutePivot = createHand(
0.45,
0.026,
new THREE.MeshStandardMaterial({
color: 0xffd76e,
emissive: 0x805516,
emissiveIntensity: 0.68,
metalness: 0.2,
roughness: 0.4
}),
0.064
);
const shadowPivot = createHand(
0.49,
0.012,
new THREE.MeshBasicMaterial({
color: 0xff914d,
transparent: true,
opacity: 0.9
}),
0.083
);
group.add(hourPivot, minutePivot, shadowPivot);
clock.hourPivot = hourPivot;
clock.minutePivot = minutePivot;
clock.shadowPivot = shadowPivot;
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.07, 0.055, 16),
new THREE.MeshStandardMaterial({
color: data.accent,
emissive: data.accent,
emissiveIntensity: 0.4,
metalness: 0.7,
roughness: 0.25
})
);
hub.rotation.x = Math.PI / 2;
hub.position.z = 0.085;
group.add(hub);
const gnomon = new THREE.Mesh(
new THREE.ConeGeometry(0.035, 0.13, 8),
new THREE.MeshStandardMaterial({
color: 0xffd36c,
emissive: 0x9c6412,
emissiveIntensity: 0.6,
metalness: 0.6,
roughness: 0.28
})
);
gnomon.rotation.x = Math.PI / 2;
gnomon.position.z = 0.105;
group.add(gnomon);
const label = new THREE.Sprite(
new THREE.SpriteMaterial({
map: clock.label.texture,
transparent: true,
depthWrite: false,
depthTest: true
})
);
label.position.set(0, -0.86, 0.02);
label.scale.set(1.42, 0.4, 1);
group.add(label);
const equatorNode = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 12, 8),
new THREE.MeshStandardMaterial({
color: data.accent,
emissive: data.accent,
emissiveIntensity: 0.8
})
);
equatorNode.position.copy(normal).multiplyScalar(GLOBE_RADIUS * 1.025);
globe.add(equatorNode);
return clock;
}
const solarClocks = clockData.map(createSolarClock);
// -------------------------------------------------------------------------
// Fixed Sun marker and parallel rays
// -------------------------------------------------------------------------
function createGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
128,
0,
128,
128,
128
);
gradient.addColorStop(0, "rgba(255,245,190,1)");
gradient.addColorStop(0.12, "rgba(255,213,104,.95)");
gradient.addColorStop(0.4, "rgba(255,176,54,.28)");
gradient.addColorStop(1, "rgba(255,150,30,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const sunPosition = sunDirection.clone().multiplyScalar(5.2);
const sunGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0xffd36b,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false,
fog: false
})
);
sunGlow.position.copy(sunPosition);
sunGlow.scale.set(2.2, 2.2, 1);
scene.add(sunGlow);
const sunSphere = new THREE.Mesh(
new THREE.SphereGeometry(0.22, 20, 12),
new THREE.MeshBasicMaterial({
color: 0xffed9a,
fog: false
})
);
sunSphere.position.copy(sunPosition);
scene.add(sunSphere);
const rayBasisA = new THREE.Vector3(1, 0, 0)
.cross(sunDirection)
.normalize();
const rayBasisB = sunDirection
.clone()
.cross(rayBasisA)
.normalize();
const rayDirection = sunDirection.clone().negate();
for (let i = -3; i <= 3; i++) {
const offset = rayBasisA
.clone()
.multiplyScalar(i * 0.82)
.addScaledVector(
rayBasisB,
i % 2 === 0 ? 0.38 : -0.38
);
const origin = sunDirection
.clone()
.multiplyScalar(5.2)
.add(offset);
const arrow = new THREE.ArrowHelper(
rayDirection,
origin,
2.75,
0xffd06d,
0.18,
0.11
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.22;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.34;
arrow.cone.material.depthWrite = false;
scene.add(arrow);
}
// -------------------------------------------------------------------------
// Solar time calculation
// -------------------------------------------------------------------------
const worldSunLongitude = Math.atan2(
sunDirection.z,
sunDirection.x
);
function updateSolarClocks(delta, forceLabel = false) {
// The globe turns beneath the fixed world-space Sun.
const subsolarLocalLongitude =
worldSunLongitude + globe.rotation.y;
const sunLocal = sunDirection
.clone()
.applyAxisAngle(Y_AXIS, -globe.rotation.y);
for (const clock of solarClocks) {
const localHours = THREE.MathUtils.euclideanModulo(
12 +
(clock.longitude - subsolarLocalLongitude) *
(12 / Math.PI),
24
);
const hour = Math.floor(localHours);
const minute = Math.floor((localHours - hour) * 60);
const minuteFraction = (localHours % 1) * 60;
const hourFraction = localHours % 12;
clock.minutePivot.rotation.z =
Math.PI / 2 - (minuteFraction / 60) * Math.PI * 2;
clock.hourPivot.rotation.z =
Math.PI / 2 - (hourFraction / 12) * Math.PI * 2;
// Project the fixed parallel sunlight onto each clock face.
const projectedX = sunLocal.dot(clock.right);
const projectedY = sunLocal.dot(clock.up);
const projectedLength = Math.hypot(
projectedX,
projectedY
);
clock.shadowPivot.visible = projectedLength > 0.025;
if (clock.shadowPivot.visible) {
clock.shadowPivot.rotation.z = Math.atan2(
-projectedY,
-projectedX
);
}
clock.labelAccumulator += delta;
if (forceLabel || clock.labelAccumulator > 0.12) {
clock.labelAccumulator = 0;
let degrees = THREE.MathUtils.radToDeg(clock.longitude);
degrees = THREE.MathUtils.euclideanModulo(degrees + 180, 360) - 180;
const direction = degrees === 0
? "000°"
: `${String(Math.abs(Math.round(degrees))).padStart(3, "0")}° ${degrees < 0 ? "W" : "E"}`;
drawClockLabel(
clock,
direction,
hour,
minute
);
}
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0, 0);
const defaultCamera = {
yaw: 0.72,
pitch: 0.38,
distance: 9.4
};
let cameraYaw = defaultCamera.yaw;
let cameraPitch = defaultCamera.pitch;
let cameraDistance = defaultCamera.distance;
let activePointer = null;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const horizontalDistance =
Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontalDistance,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontalDistance
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraYaw = defaultCamera.yaw;
cameraPitch = defaultCamera.pitch;
cameraDistance = defaultCamera.distance;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", event => {
if (activePointer !== null) {
return;
}
activePointer = event.pointerId;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (event.pointerId !== activePointer) {
return;
}
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.006,
-1.35,
1.35
);
updateCamera();
});
function releasePointer(event) {
if (event.pointerId === activePointer) {
activePointer = null;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * Math.exp(event.deltaY * 0.001),
5.4,
17
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener(
"contextmenu",
event => event.preventDefault()
);
window.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraYaw -= 0.08;
break;
case "ArrowRight":
cameraYaw += 0.08;
break;
case "ArrowUp":
cameraPitch = Math.min(1.35, cameraPitch + 0.06);
break;
case "ArrowDown":
cameraPitch = Math.max(-1.35, cameraPitch - 0.06);
break;
case "+":
case "=":
cameraDistance = Math.max(5.4, cameraDistance - 0.35);
break;
case "-":
cameraDistance = Math.min(17, cameraDistance + 0.35);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const timer = new THREE.Clock();
const rotationSpeed = 0.075;
updateCamera();
updateSolarClocks(0, true);
function animate() {
const delta = Math.min(timer.getDelta(), 0.05);
globe.rotation.y =
(globe.rotation.y + delta * rotationSpeed) % (Math.PI * 2);
updateSolarClocks(delta);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```