-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
675 lines (587 loc) · 22.8 KB
/
index.html
File metadata and controls
675 lines (587 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>3D Earth Visualizer | Premium Edition</title>
<style>
:root {
--primary: #00d2ff;
--bg-glass: rgba(10, 15, 30, 0.45);
--border-glass: rgba(255, 255, 255, 0.08);
}
body {
margin: 0;
overflow: hidden;
font-family: 'Inter', 'Segoe UI', sans-serif;
background-color: #000;
color: #fff;
}
/* Loading Screen */
#loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #020205;
z-index: 100;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transition: opacity 1s ease-in-out;
}
.spinner {
width: 60px;
height: 60px;
border: 3px solid rgba(0, 210, 255, 0.15);
border-top: 3px solid var(--primary);
border-radius: 50%;
animation: spin 1s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
margin-bottom: 25px;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.loading-text {
font-size: 13px;
letter-spacing: 5px;
color: var(--primary);
text-transform: uppercase;
font-weight: 500;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%,
100% {
opacity: 0.5;
}
50% {
opacity: 1;
}
}
/* Glassmorphic Top Info */
#info {
position: absolute;
top: 24px;
left: 24px;
background: var(--bg-glass);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
padding: 18px 26px;
border-radius: 16px;
border: 1px solid var(--border-glass);
pointer-events: none;
z-index: 10;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
transform: translateY(-20px);
opacity: 0;
animation: slideDown 0.8s ease forwards 0.5s;
}
@keyframes slideDown {
to {
transform: translateY(0);
opacity: 1;
}
}
#info h1 {
margin: 0;
font-size: 1.5rem;
letter-spacing: 2px;
background: linear-gradient(90deg, #fff, #88ccff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-weight: 700;
}
#info p {
margin: 8px 0 0;
font-size: 0.85rem;
color: rgba(255, 255, 255, 0.7);
letter-spacing: 1px;
font-weight: 300;
}
/* Control Panel */
#ui-panel {
position: absolute;
top: 24px;
right: 24px;
width: 260px;
background: var(--bg-glass);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid var(--border-glass);
border-radius: 16px;
padding: 24px;
z-index: 10;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
transform: translateX(50px);
opacity: 0;
transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}
.panel-visible {
transform: translateX(0) !important;
opacity: 1 !important;
}
#ui-panel h3 {
margin: 0 0 24px 0;
font-size: 0.9rem;
letter-spacing: 2px;
color: rgba(255, 255, 255, 0.9);
text-transform: uppercase;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
padding-bottom: 12px;
font-weight: 600;
}
.control-group {
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.control-group:last-child {
margin-bottom: 0;
}
.control-group label {
font-size: 0.85rem;
color: rgba(255, 255, 255, 0.85);
font-weight: 400;
}
/* Custom Range Slider */
input[type=range] {
-webkit-appearance: none;
width: 110px;
background: transparent;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 4px;
cursor: pointer;
background: rgba(255, 255, 255, 0.15);
border-radius: 2px;
}
input[type=range]::-webkit-slider-thumb {
height: 14px;
width: 14px;
border-radius: 50%;
background: var(--primary);
cursor: pointer;
-webkit-appearance: none;
margin-top: -5px;
box-shadow: 0 0 12px rgba(0, 210, 255, 0.6);
transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
input[type=range]::-webkit-slider-thumb:hover {
transform: scale(1.3);
}
/* Custom Checkbox as Toggle Switch */
.switch {
position: relative;
display: inline-block;
width: 44px;
height: 22px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(255, 255, 255, 0.15);
transition: .4s;
border-radius: 22px;
}
.slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .4s;
border-radius: 50%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
input:checked+.slider {
background-color: var(--primary);
}
input:checked+.slider:before {
transform: translateX(22px);
}
/* Controls Note Overlay */
#controls-note {
position: absolute;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
color: rgba(255, 255, 255, 0.7);
background: var(--bg-glass);
padding: 12px 24px;
border-radius: 30px;
border: 1px solid var(--border-glass);
font-size: 0.8rem;
pointer-events: none;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
letter-spacing: 1px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
white-space: nowrap;
}
/* Mobile Responsiveness */
@media (max-width: 768px) {
#info {
top: 16px;
left: 16px;
padding: 14px 20px;
}
#info h1 {
font-size: 1.2rem;
}
#ui-panel {
top: auto;
bottom: 85px;
left: 16px;
right: 16px;
width: auto;
transform: translateY(50px);
}
.panel-visible {
transform: translateY(0) !important;
}
#controls-note {
bottom: 16px;
font-size: 0.7rem;
padding: 10px 16px;
width: max-content;
}
}
</style>
</head>
<body>
<!-- Initial Loading Screen -->
<div id="loader">
<div class="spinner"></div>
<div class="loading-text">Establishing Connection</div>
</div>
<!-- UI Overlay Info -->
<div id="info">
<h1>EARTH VISUALIZER</h1>
<p>Dynamic Premium Render</p>
</div>
<!-- Control Panel -->
<div id="ui-panel">
<h3>System Controls</h3>
<div class="control-group">
<label>Time Speed</label>
<input type="range" id="speed-slider" min="0" max="3" step="0.1" value="0.8">
</div>
<div class="control-group">
<label>Atmospheric Halo</label>
<label class="switch">
<input type="checkbox" id="toggle-atmos" checked>
<span class="slider"></span>
</label>
</div>
<div class="control-group">
<label>Cloud Layer</label>
<label class="switch">
<input type="checkbox" id="toggle-clouds" checked>
<span class="slider"></span>
</label>
</div>
<div class="control-group">
<label>City Lights</label>
<label class="switch">
<input type="checkbox" id="toggle-night" checked>
<span class="slider"></span>
</label>
</div>
</div>
<div id="controls-note">
🖱️ Drag: Rotate • Scroll: Zoom • Right-Click: Pan
</div>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.128.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.128.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
// --- 1. Loading Manager Setup ---
const manager = new THREE.LoadingManager();
manager.onLoad = () => {
const loader = document.getElementById('loader');
loader.style.opacity = '0';
setTimeout(() => {
loader.style.display = 'none';
document.getElementById('ui-panel').classList.add('panel-visible');
}, 1000);
};
// --- 2. Scene, Camera, & Renderer ---
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x020205);
scene.fog = new THREE.FogExp2(0x020205, 0.0001);
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 3.8);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, powerPreference: "high-performance" });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); // Limit pixel ratio for performance scaling
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.0;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
// --- 3. Post-Processing (Bloom) ---
const renderScene = new RenderPass(scene, camera);
const bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 0.8, 0.5, 0.6);
bloomPass.threshold = 0.6; // Only bloom bright spots (sun, city lights)
bloomPass.strength = 0.8;
bloomPass.radius = 0.5;
const composer = new EffectComposer(renderer);
composer.addPass(renderScene);
composer.addPass(bloomPass);
// --- 4. Orbit Controls ---
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.minDistance = 1.2; // Prevent going inside Earth
controls.maxDistance = 12;
controls.enablePan = true;
// --- 5. Lighting ---
// Boosted ambient to guarantee no deep unlit black areas
const ambientLight = new THREE.AmbientLight(0x333355, 0.8);
scene.add(ambientLight);
// Directional Sun Light
const sunLight = new THREE.DirectionalLight(0xfff5e6, 1.5);
sunLight.position.set(5, 3, 5); // Positioned in front and to the right
sunLight.castShadow = true;
sunLight.shadow.mapSize.width = 2048;
sunLight.shadow.mapSize.height = 2048;
sunLight.shadow.bias = -0.0001;
scene.add(sunLight);
// Add a visual sun sphere representation
const sunGeo = new THREE.SphereGeometry(0.2, 32, 32);
const sunMat = new THREE.MeshBasicMaterial({ color: 0xffffee });
const sunMesh = new THREE.Mesh(sunGeo, sunMat);
sunMesh.position.copy(sunLight.position);
scene.add(sunMesh);
// Subtle fill light mimicking starlight/distant scatter
// Bright fill light mimicking distant starlight so the opposite side is clearly visible
const fillLight = new THREE.DirectionalLight(0x6688cc, 0.8);
fillLight.position.set(0, 0, -5); // Directly behind the earth
scene.add(fillLight);
// --- 6. Earth, Clouds, and Atmosphere Setup ---
const systemGroup = new THREE.Group();
scene.add(systemGroup);
const textureLoader = new THREE.TextureLoader(manager);
textureLoader.setCrossOrigin('anonymous'); // Ensure no CORS issues with WebGL
const earthRadius = 1;
const earthGeometry = new THREE.SphereGeometry(earthRadius, 128, 128);
// Ultra High-res 8k textures for deep zooming
const earthMap = textureLoader.load('https://unpkg.com/three-globe/example/img/earth-blue-marble.jpg');
const bumpMap = textureLoader.load('https://unpkg.com/three-globe/example/img/earth-topology.png');
const specularMap = textureLoader.load('https://unpkg.com/three-globe/example/img/earth-water.png');
const nightMap = textureLoader.load('https://unpkg.com/three-globe/example/img/earth-night.jpg');
const cloudsMap = textureLoader.load('https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/planets/earth_clouds_1024.png'); // Clouds usually look fine scaled
// Apply Anisotropy to prevent extreme angle blurriness
const maxAniso = renderer.capabilities.getMaxAnisotropy();
earthMap.anisotropy = maxAniso;
bumpMap.anisotropy = maxAniso;
specularMap.anisotropy = maxAniso;
nightMap.anisotropy = maxAniso;
const earthMaterial = new THREE.MeshPhongMaterial({
map: earthMap,
bumpMap: bumpMap,
bumpScale: 0.015,
specularMap: specularMap,
specular: new THREE.Color(0x333333),
shininess: 25
});
const earth = new THREE.Mesh(earthGeometry, earthMaterial);
earth.castShadow = true;
earth.receiveShadow = true;
systemGroup.add(earth);
// --- 100% Robust Dedicated Night Lights Mesh ---
const nightLightsMaterial = new THREE.ShaderMaterial({
uniforms: {
nightTexture: { value: nightMap },
sunPosition: { value: sunLight.position }
},
vertexShader: `
varying vec2 vUv;
varying vec3 vWorldNormal;
varying vec3 vWorldPosition;
void main() {
vUv = uv;
vWorldNormal = normalize((modelMatrix * vec4(normal, 0.0)).xyz);
vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform sampler2D nightTexture;
uniform vec3 sunPosition;
varying vec2 vUv;
varying vec3 vWorldNormal;
varying vec3 vWorldPosition;
void main() {
vec3 earthCenter = vec3(0.0, 0.0, 0.0);
vec3 worldNormal = normalize(vWorldPosition - earthCenter);
vec3 sunDir = normalize(sunPosition - earthCenter);
float sunDot = dot(worldNormal, sunDir);
// FIXED: edge0 must strictly be less than edge1 in GLSL smoothstep!
// This mathematically guarantees nightMix is 1.0 on the dark side, 0.0 on bright side.
float nightMix = 1.0 - smoothstep(-0.3, 0.1, sunDot);
vec4 nightColor = texture2D(nightTexture, vUv);
// Pure additive blend with 1.0 alpha
gl_FragColor = vec4(nightColor.rgb * nightMix * 2.5, 1.0);
}
`,
blending: THREE.AdditiveBlending,
transparent: true,
depthWrite: false
});
const nightLightsMesh = new THREE.Mesh(earthGeometry, nightLightsMaterial);
nightLightsMesh.scale.setScalar(1.002); // Slightly larger to prevent z-fighting
earth.add(nightLightsMesh); // Inherits Earth's rotation automatically!
// Cloud Layer
const cloudGeometry = new THREE.SphereGeometry(earthRadius * 1.006, 128, 128);
const cloudMaterial = new THREE.MeshPhongMaterial({
map: cloudsMap,
transparent: true,
opacity: 0.8,
blending: THREE.AdditiveBlending,
side: THREE.DoubleSide,
depthWrite: false
});
const clouds = new THREE.Mesh(cloudGeometry, cloudMaterial);
systemGroup.add(clouds);
// True Atmospheric Halo using a Custom Shader
const atmosGeometry = new THREE.SphereGeometry(earthRadius * 1.15, 64, 64);
const atmosMaterial = new THREE.ShaderMaterial({
vertexShader: `
varying vec3 vNormal;
void main() {
vNormal = normalize(normalMatrix * normal);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
varying vec3 vNormal;
void main() {
// Fresnel calculation for edge glow
float intensity = pow(0.65 - dot(vNormal, vec3(0, 0, 1.0)), 4.0);
gl_FragColor = vec4(0.3, 0.6, 1.0, 1.0) * intensity * 1.2;
}
`,
blending: THREE.AdditiveBlending,
side: THREE.BackSide,
transparent: true,
depthWrite: false
});
const atmosphere = new THREE.Mesh(atmosGeometry, atmosMaterial);
systemGroup.add(atmosphere);
// --- 7. The Moon ---
const moonRadius = 0.27;
const moonGeometry = new THREE.SphereGeometry(moonRadius, 64, 64);
const moonMap = textureLoader.load('https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/planets/moon_1024.jpg');
const moonMaterial = new THREE.MeshStandardMaterial({
map: moonMap,
roughness: 0.8,
metalness: 0.1
});
const moon = new THREE.Mesh(moonGeometry, moonMaterial);
moon.castShadow = true;
moon.receiveShadow = true;
const moonPivot = new THREE.Group();
systemGroup.add(moonPivot);
moonPivot.add(moon);
moon.position.set(4, 0.5, 0); // Approx scaled distance for visual presentation
// --- 8. Starfield ---
const createStars = (count, size, color, radiusStart, radiusEnd) => {
const geo = new THREE.BufferGeometry();
const pos = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const r = radiusStart + Math.random() * (radiusEnd - radiusStart);
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
pos[i * 3] = r * Math.sin(phi) * Math.cos(theta);
pos[i * 3 + 1] = r * Math.sin(phi) * Math.sin(theta);
pos[i * 3 + 2] = r * Math.cos(phi);
}
geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
const mat = new THREE.PointsMaterial({ color, size, transparent: true, opacity: 0.8 });
return new THREE.Points(geo, mat);
};
const stars1 = createStars(3000, 0.015, 0xffffff, 50, 100);
const stars2 = createStars(2000, 0.025, 0x88bbff, 100, 200);
scene.add(stars1);
scene.add(stars2);
// --- 9. UI Logic Integration ---
let baseSpeed = 0.8;
document.getElementById('speed-slider').addEventListener('input', (e) => {
baseSpeed = parseFloat(e.target.value);
});
document.getElementById('toggle-atmos').addEventListener('change', (e) => {
atmosphere.visible = e.target.checked;
});
document.getElementById('toggle-clouds').addEventListener('change', (e) => {
clouds.visible = e.target.checked;
});
document.getElementById('toggle-night').addEventListener('change', (e) => {
nightLightsMesh.visible = e.target.checked;
});
// --- 10. Animation Loop ---
let lastTime = performance.now();
function animate() {
const now = performance.now();
let delta = Math.min(0.05, (now - lastTime) / 1000);
lastTime = now;
const timeStep = delta * baseSpeed;
// Orbital rotation physics
earth.rotation.y += timeStep * 0.05;
clouds.rotation.y += timeStep * 0.06; // Clouds spin slightly faster
// Moon mechanics
moonPivot.rotation.y += timeStep * 0.015;
moon.rotation.y += timeStep * 0.02;
// Slowly rotate background stars for dynamic feel
stars1.rotation.y += timeStep * 0.003;
stars2.rotation.y -= timeStep * 0.002;
stars2.rotation.x += timeStep * 0.001;
controls.update();
composer.render();
requestAnimationFrame(animate);
}
// Handle Responsive Resizing
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
composer.setSize(window.innerWidth, window.innerHeight);
});
animate();
</script>
</body>
</html>