-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
687 lines (585 loc) · 27.2 KB
/
Copy pathindex.html
File metadata and controls
687 lines (585 loc) · 27.2 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
676
677
678
679
680
681
682
683
684
685
686
687
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:image" content="img/img1.jpg" />
<title>Solar System</title>
<style>
/* --- 1. CORE VISUALS & FONTS --- */
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;700&family=Share+Tech+Mono&display=swap');
body {
margin: 0;
overflow: hidden;
background-color: #000;
font-family: 'Rajdhani', sans-serif;
user-select: none;
}
/* --- 2. UI LAYOUT --- */
#ui-layer {
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
pointer-events: none; /* Let clicks pass through to 3D */
z-index: 10;
display: flex; flex-direction: column; justify-content: space-between;
}
/* Header / HUD Top */
.hud-header {
padding: 20px;
background: linear-gradient(180deg, rgba(0, 10, 20, 0.9) 0%, transparent 100%);
border-bottom: 1px solid rgba(0, 242, 255, 0.2);
pointer-events: auto;
display: flex; justify-content: space-between; align-items: center;
}
.title-block h1 {
color: #00f2ff; margin: 0; font-size: 36px; text-transform: uppercase;
text-shadow: 0 0 15px rgba(0, 242, 255, 0.8); letter-spacing: 4px;
}
.title-block .subtitle {
font-family: 'Share Tech Mono', monospace; color: #ffd700; font-size: 14px; margin-top: 5px;
opacity: 0.8;
}
/* Dashboard Stats */
.stats-container {
display: flex; gap: 30px;
}
.stat-box { text-align: right; }
.stat-label { color: #888; font-size: 12px; font-weight: bold; letter-spacing: 1px; }
.stat-value { color: #fff; font-size: 20px; font-family: 'Share Tech Mono'; text-shadow: 0 0 5px white; }
/* --- 3. SIDE PANEL (DATA) --- */
#info-panel {
position: absolute; right: -400px; top: 100px; bottom: 100px;
width: 320px;
background: rgba(5, 15, 25, 0.9);
border-left: 2px solid #00f2ff;
backdrop-filter: blur(10px);
transition: right 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
padding: 30px; box-sizing: border-box;
pointer-events: auto;
overflow-y: auto;
box-shadow: -10px 0 30px rgba(0,0,0,0.8);
}
#info-panel.active { right: 0; }
.p-name {
font-size: 40px; color: #fff; font-weight: 800; text-transform: uppercase;
border-bottom: 2px solid #ffd700; padding-bottom: 10px; margin-bottom: 20px;
}
.p-data-row {
display: flex; justify-content: space-between; padding: 10px 0;
border-bottom: 1px solid rgba(255,255,255,0.1); color: #ccc;
}
.p-val { color: #00f2ff; font-weight: bold; font-family: 'Share Tech Mono'; }
.moon-grid { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 15px; }
.moon-badge {
background: rgba(0, 242, 255, 0.15); border: 1px solid #00f2ff;
color: #fff; padding: 4px 8px; font-size: 11px; border-radius: 4px;
}
/* --- 4. BOTTOM CONTROLS --- */
.hud-footer {
padding: 20px;
background: linear-gradient(0deg, rgba(0, 10, 20, 0.9) 0%, transparent 100%);
display: flex; gap: 10px; pointer-events: auto; align-items: flex-end;
}
.btn {
background: rgba(0, 0, 0, 0.5); border: 1px solid #00f2ff; color: #00f2ff;
padding: 10px 20px; font-family: 'Rajdhani'; font-weight: bold; font-size: 16px;
cursor: pointer; transition: all 0.2s; text-transform: uppercase;
}
.btn:hover { background: #00f2ff; color: #000; box-shadow: 0 0 15px #00f2ff; }
.btn.active-mode { background: #ffd700; color: #000; border-color: #ffd700; }
/* Speed Slider */
.slider-group { background: rgba(0,0,0,0.6); padding: 10px 20px; border-radius: 5px; border: 1px solid #555; }
input[type=range] { accent-color: #ffd700; width: 200px; cursor: pointer; }
/* --- 5. TOOLTIP (HOVER) --- */
#tooltip {
position: absolute; pointer-events: none; opacity: 0;
background: rgba(0,0,0,0.8); border: 1px solid #ffd700;
color: #ffd700; padding: 5px 10px; border-radius: 4px;
transform: translate(-50%, -150%); transition: opacity 0.2s;
font-family: 'Share Tech Mono'; font-size: 12px; z-index: 20;
}
/* Loading Screen */
#loader {
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: #000; z-index: 100;
display: flex; flex-direction: column; justify-content: center; align-items: center;
transition: opacity 1s;
}
.loader-text { color: #00f2ff; font-size: 24px; letter-spacing: 5px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.5; } }
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
</head>
<body>
<div id="loader">
<div class="loader-text">INITIALIZING SYSTEMS...</div>
<div style="color: #555; margin-top: 10px;">LOADING ASSETS | GENERATING TEXTURES | CALCULATING ORBITS</div>
</div>
<div id="tooltip">Earth</div>
<div id="ui-layer">
<div class="hud-header">
<div class="title-block">
<h1>Solar Engine <span style="color:#ffd700">PRO</span></h1>
<div class="subtitle">STATUS: ONLINE</div>
</div>
<div class="stats-container">
<div class="stat-box">
<div class="stat-label">DATE</div>
<div class="stat-value" id="ui-date">Year 1</div>
</div>
<div class="stat-box">
<div class="stat-label">OBJECTS</div>
<div class="stat-value">5,000+</div>
</div>
</div>
</div>
<div id="info-panel">
<button onclick="closePanel()" style="float:right; background:none; border:none; color:red; font-size:20px; cursor:pointer;">✖</button>
<div class="p-name" id="p-name">PLANET</div>
<div style="color: #ffd700; margin-bottom: 20px; letter-spacing: 2px;" id="p-type">TYPE</div>
<div class="p-data-row"><span>Surface Temp</span> <span class="p-val" id="p-temp">0°C</span></div>
<div class="p-data-row"><span>Diameter</span> <span class="p-val" id="p-dia">0 km</span></div>
<div class="p-data-row"><span>Orbit Speed</span> <span class="p-val" id="p-speed">0 km/s</span></div>
<div class="p-data-row"><span>Distance from Sun</span> <span class="p-val" id="p-dist">0 AU</span></div>
<p style="color:#aaa; line-height: 1.6; margin-top:20px; font-size:14px;" id="p-desc">Description...</p>
<div style="margin-top:20px; font-weight:bold; color:#fff;">SATELLITES SYSTEM</div>
<div class="moon-grid" id="p-moons"></div>
</div>
<div class="hud-footer">
<div class="slider-group">
<label style="color:#ffd700; font-size:12px; display:block; margin-bottom:5px;">TIME WARP</label>
<input type="range" id="speedSlider" min="0" max="4" step="0.1" value="1">
</div>
<button class="btn" onclick="resetCam()">Top View</button>
<button class="btn" id="tourBtn" onclick="toggleTour()">Cinematic Tour</button>
</div>
</div>
<!-- <audio src="music.mp3" autoplay>
</audio> -->
<script>
/**
* ==========================================
* SOLAR SYSTEM ENGINE - CORE JAVASCRIPT
* Developed by: Anaf Ibn Shahibul
* Features: Raycasting, Procedural Textures,
* Particle Systems, Cinematic Camera
* ==========================================
*/
// --- 1. SCENE SETUP ---
const scene = new THREE.Scene();
// Background Fog for depth (Very dark blue-ish black)
scene.fog = new THREE.FogExp2(0x000005, 0.00015);
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 20000);
camera.position.set(0, 400, 600); // High angle start
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.maxDistance = 5000;
// --- 2. LIGHTING (THE SUN) ---
// User requested "Bright Old Style" Sun
// Core Point Light (The physics light)
const sunLight = new THREE.PointLight(0xffffff, 2.5, 5000);
sunLight.position.set(0, 0, 0);
sunLight.castShadow = true;
sunLight.shadow.mapSize.width = 2048; // High res shadows
sunLight.shadow.mapSize.height = 2048;
scene.add(sunLight);
// Ambient Light (So shadows aren't pitch black)
const ambientLight = new THREE.AmbientLight(0x404040, 0.6);
scene.add(ambientLight);
// --- 3. TEXTURE GENERATORS (Procedural Canvas) ---
// Generating high-quality textures in code to keep it single-file
const textureLoader = new THREE.TextureLoader();
function getProceduralTexture(type, color1, color2) {
const canvas = document.createElement('canvas');
canvas.width = 512; canvas.height = 512;
const ctx = canvas.getContext('2d');
const w = 512, h = 512;
// Base
ctx.fillStyle = color1;
ctx.fillRect(0,0,w,h);
if(type === 'sun') {
// Bright solid core
ctx.fillStyle = '#ffcc00';
ctx.fillRect(0,0,w,h);
// Heat waves
for(let i=0; i<100; i++) {
ctx.beginPath();
ctx.arc(Math.random()*w, Math.random()*h, Math.random()*50, 0, Math.PI*2);
ctx.fillStyle = 'rgba(255, 100, 0, 0.2)';
ctx.fill();
}
}
else if (type === 'earth') {
// Vibrant Blue Water
ctx.fillStyle = '#0044ff';
ctx.fillRect(0,0,w,h);
// Green Continents
ctx.fillStyle = '#00aa33';
for(let i=0; i<80; i++) {
const x = Math.random()*w; const y = Math.random()*h;
const r = Math.random()*60 + 20;
ctx.beginPath(); ctx.arc(x,y,r,0,Math.PI*2); ctx.fill();
}
// Clouds
ctx.fillStyle = 'rgba(255,255,255,0.3)';
for(let i=0; i<100; i++) {
ctx.beginPath(); ctx.arc(Math.random()*w, Math.random()*h, Math.random()*30, 0, Math.PI*2); ctx.fill();
}
}
else if (type === 'gas') {
// Banded texture
const grad = ctx.createLinearGradient(0,0,0,h);
grad.addColorStop(0, color1);
grad.addColorStop(0.5, color2);
grad.addColorStop(1, color1);
ctx.fillStyle = grad;
ctx.fillRect(0,0,w,h);
// Stripes
for(let i=0; i<20; i++) {
ctx.fillStyle = 'rgba(0,0,0,0.1)';
ctx.fillRect(0, Math.random()*h, w, Math.random()*20);
}
}
else {
// Rocky noise
for(let i=0; i<5000; i++) {
ctx.fillStyle = Math.random() > 0.5 ? color2 : '#000000';
ctx.globalAlpha = 0.1;
ctx.fillRect(Math.random()*w, Math.random()*h, 2, 2);
}
}
return new THREE.CanvasTexture(canvas);
}
// --- 4. OBJECT BUILDERS ---
const interactables = []; // Objects we can click
const updatables = []; // Things that move
// A. SUN MESH
const sunGeo = new THREE.SphereGeometry(35, 64, 64);
const sunMat = new THREE.MeshBasicMaterial({ map: getProceduralTexture('sun', '#ffd700', '#ff8800') });
const sun = new THREE.Mesh(sunGeo, sunMat);
scene.add(sun);
// B. SUN GLOW (SPRITE) - The "Bright" effect
const spriteCanvas = document.createElement('canvas');
spriteCanvas.width = 128; spriteCanvas.height = 128;
const sCtx = spriteCanvas.getContext('2d');
const grad = sCtx.createRadialGradient(64,64,0,64,64,64);
grad.addColorStop(0, 'rgba(255, 220, 100, 1)'); // Center bright
grad.addColorStop(0.3, 'rgba(255, 150, 0, 0.4)'); // Mid Orange
grad.addColorStop(1, 'rgba(0, 0, 0, 0)'); // Edge transparent
sCtx.fillStyle = grad;
sCtx.fillRect(0,0,128,128);
const glowMat = new THREE.SpriteMaterial({
map: new THREE.CanvasTexture(spriteCanvas),
color: 0xffdd44,
blending: THREE.AdditiveBlending
});
const sunGlow = new THREE.Sprite(glowMat);
sunGlow.scale.set(220, 220, 1); // Big glow radius
sun.add(sunGlow);
// C. PLANET CONFIG DATA
const planets = [
{ name: "MERCURY", r: 3, d: 70, s: 0.04, c1: '#aaaaaa', c2: '#555555', type: 'rocky', desc: "Fastest planet, sun-scorched surface.", moons: [] },
{ name: "VENUS", r: 5.5, d: 100, s: 0.015, c1: '#eecfa1', c2: '#dbb47e', type: 'rocky', desc: "Hottest planet due to greenhouse gases.", moons: [] },
{ name: "EARTH", r: 6, d: 140, s: 0.01, c1: '#0000ff', c2: '#00ff00', type: 'earth', desc: "Our home. The only known life.", moons: [{name:"Moon", r:1.5, d:12}] },
{ name: "MARS", r: 4.5, d: 180, s: 0.008, c1: '#c1440e', c2: '#8a2be2', type: 'rocky', desc: "The Red Planet. Possible ancient water.", moons: [{name:"Phobos", r:0.5, d:6}, {name:"Deimos", r:0.3, d:8}] },
{ name: "JUPITER", r: 18, d: 300, s: 0.004, c1: '#d9cdb1', c2: '#a97c50', type: 'gas', desc: "King of planets. Massive gas giant.", moons: [{name:"Io", r:1.8, d:25}, {name:"Europa", r:1.6, d:28}, {name:"Ganymede", r:2.2, d:34}, {name:"Callisto", r:2, d:40}] },
{ name: "SATURN", r: 15, d: 420, s: 0.003, c1: '#f4d03f', c2: '#c9a128', type: 'gas', desc: "Known for its majestic ring system.", ring: true, moons: [{name:"Titan", r:2, d:30}] },
{ name: "URANUS", r: 10, d: 520, s: 0.002, c1: '#73acac', c2: '#ffffff', type: 'gas', desc: "Ice giant that spins on its side.", moons: [{name:"Titania", r:1, d:18}] },
{ name: "NEPTUNE", r: 9.5, d: 600, s: 0.0018, c1: '#3333ff', c2: '#111199', type: 'gas', desc: "Windiest planet. Dark blue world.", moons: [{name:"Triton", r:1.2, d:20}] },
// Dwarf Planets
{ name: "CERES", r: 1.5, d: 240, s: 0.007, c1: '#888888', c2: '#444444', type: 'rocky', desc: "Queen of the asteroid belt.", moons: [] },
{ name: "PLUTO", r: 2.5, d: 700, s: 0.001, c1: '#dcb', c2: '#987', type: 'rocky', desc: "Dwarf planet with a heart-shaped glacier.", moons: [{name:"Charon", r:1.2, d:8}] },
{ name: "ERIS", r: 2.6, d: 800, s: 0.0008, c1: '#fff', c2: '#eee', type: 'rocky', desc: "More massive than Pluto.", moons: [] },
{ name: "MAKEMAKE", r: 2.4, d: 900, s: 0.0007, c1: '#aa5555', c2: '#552222', type: 'rocky', desc: "Reddish dwarf planet.", moons: [] }
];
// D. BUILD PLANETS LOOP
planets.forEach(p => {
// Orbit Pivot (Center)
const pivot = new THREE.Object3D();
scene.add(pivot);
// Random Start Position
pivot.rotation.y = Math.random() * Math.PI * 2;
// Planet Group
const pGroup = new THREE.Group();
pGroup.position.x = p.d;
pivot.add(pGroup);
// Planet Mesh
const mat = new THREE.MeshStandardMaterial({
map: getProceduralTexture(p.type, p.c1, p.c2),
roughness: 0.6, metalness: 0.2
});
// Make Earth brighter
if(p.type === 'earth') { mat.emissive = new THREE.Color(0x001133); mat.emissiveIntensity = 0.3; }
const mesh = new THREE.Mesh(new THREE.SphereGeometry(p.r, 32, 32), mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
// Add data to mesh for Raycasting
mesh.userData = { isPlanet: true, name: p.name, data: p };
pGroup.add(mesh);
interactables.push(mesh);
p.meshRef = mesh; // Save for camera
// Orbit Trail (Line)
const trackGeo = new THREE.RingGeometry(p.d - 0.5, p.d + 0.5, 128);
const trackMat = new THREE.MeshBasicMaterial({ color: 0xffffff, opacity: 0.1, transparent: true, side: THREE.DoubleSide });
const track = new THREE.Mesh(trackGeo, trackMat);
track.rotation.x = Math.PI/2;
scene.add(track);
// Rings (Saturn)
if(p.ring) {
const ringGeo = new THREE.RingGeometry(p.r * 1.4, p.r * 2.5, 64);
const ringMat = new THREE.MeshStandardMaterial({ color: 0xccbbaa, opacity: 0.7, transparent: true, side: THREE.DoubleSide });
const rings = new THREE.Mesh(ringGeo, ringMat);
rings.rotation.x = Math.PI/2;
mesh.add(rings);
}
// Moons
if(p.moons.length > 0) {
p.moons.forEach(m => {
const mPivot = new THREE.Object3D();
mesh.add(mPivot); // Moon orbits planet
const mGeo = new THREE.SphereGeometry(m.r, 16, 16);
const mMat = new THREE.MeshStandardMaterial({ color: 0xdddddd });
const mMesh = new THREE.Mesh(mGeo, mMat);
mMesh.position.x = m.d;
mMesh.castShadow = true; mMesh.receiveShadow = true;
mPivot.add(mMesh);
// Moon animation
updatables.push((speed) => {
mPivot.rotation.y += (0.05 / m.d * 10) * speed;
});
});
}
// Planet Animation
updatables.push((speed) => {
pivot.rotation.y += p.s * speed; // Orbit
mesh.rotation.y += 0.02; // Spin
});
});
// --- 5. ASTEROID BELT (InstancedMesh) ---
function createAsteroids() {
const count = 5000;
const geo = new THREE.TetrahedronGeometry(0.8, 1);
const mat = new THREE.MeshStandardMaterial({ color: 0x777777, roughness: 0.9 });
const mesh = new THREE.InstancedMesh(geo, mat, count);
const dummy = new THREE.Object3D();
for(let i=0; i<count; i++) {
// Between Mars (180) and Jupiter (300), concentrated around 240
const dist = 220 + Math.random() * 60;
const angle = Math.random() * Math.PI * 2;
const h = (Math.random() - 0.5) * 20; // Spread height
dummy.position.set(
Math.cos(angle) * dist,
h,
Math.sin(angle) * dist
);
dummy.rotation.set(Math.random()*3, Math.random()*3, Math.random()*3);
dummy.scale.setScalar(Math.random() * 2 + 0.5);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
scene.add(mesh);
// Rotate belt
updatables.push((speed) => {
mesh.rotation.y += 0.0005 * speed;
});
}
createAsteroids();
// --- 6. COMET SYSTEM (Special Feature) ---
function createComet() {
const cometHead = new THREE.Mesh(
new THREE.SphereGeometry(1, 16, 16),
new THREE.MeshBasicMaterial({ color: 0x00ffff })
);
scene.add(cometHead);
// Trail (Particles)
const trailGeo = new THREE.BufferGeometry();
const trailCount = 50;
const positions = new Float32Array(trailCount * 3);
trailGeo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
const trailMat = new THREE.PointsMaterial({ color: 0x00ffff, size: 2, transparent: true, opacity: 0.6 });
const trail = new THREE.Points(trailGeo, trailMat);
scene.add(trail);
let t = 0;
const trailPositions = [];
updatables.push((speed) => {
t += 0.008 * speed;
// Elliptical Orbit
const x = Math.cos(t) * 150 + 50; // Offset center
const z = Math.sin(t) * 400;
cometHead.position.set(x, z * 0.1, z); // Tilt orbit
// Update Trail
trailPositions.unshift(cometHead.position.clone());
if(trailPositions.length > trailCount) trailPositions.pop();
const arr = trail.geometry.attributes.position.array;
for(let i=0; i<trailPositions.length; i++) {
arr[i*3] = trailPositions[i].x;
arr[i*3+1] = trailPositions[i].y;
arr[i*3+2] = trailPositions[i].z;
}
trail.geometry.attributes.position.needsUpdate = true;
});
}
createComet();
// --- 7. STARFIELD (Background) ---
function createStars() {
const geo = new THREE.BufferGeometry();
const pos = [];
const cols = [];
for(let i=0; i<10000; i++) {
pos.push((Math.random()-0.5)*10000, (Math.random()-0.5)*10000, (Math.random()-0.5)*10000);
const c = new THREE.Color();
c.setHSL(Math.random(), 0.8, 0.8);
cols.push(c.r, c.g, c.b);
}
geo.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
geo.setAttribute('color', new THREE.Float32BufferAttribute(cols, 3));
const mat = new THREE.PointsMaterial({ size: 2, vertexColors: true });
const stars = new THREE.Points(geo, mat);
scene.add(stars);
}
createStars();
// --- 8. INTERACTION & LOGIC ---
// Raycaster
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
const tooltip = document.getElementById('tooltip');
window.addEventListener('mousemove', (e) => {
// UI Handling
mouse.x = (e.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(e.clientY / window.innerHeight) * 2 + 1;
// Tooltip pos
tooltip.style.left = e.clientX + 'px';
tooltip.style.top = e.clientY + 'px';
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(interactables);
if(intersects.length > 0) {
const data = intersects[0].object.userData;
document.body.style.cursor = 'pointer';
tooltip.style.opacity = 1;
tooltip.innerText = data.name;
} else {
document.body.style.cursor = 'default';
tooltip.style.opacity = 0;
}
});
window.addEventListener('click', (e) => {
if(e.target.closest('#ui-layer button') || e.target.closest('#info-panel')) return;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(interactables);
if(intersects.length > 0) {
openPanel(intersects[0].object.userData);
}
});
function openPanel(data) {
if(!data.data) return; // Ignore if no data
const d = data.data;
document.getElementById('p-name').innerText = d.name;
document.getElementById('p-type').innerText = d.type.toUpperCase() + " PLANET";
document.getElementById('p-temp').innerText = "CALCULATING..."; // Placeholder
document.getElementById('p-dia').innerText = (d.r * 2 * 1000).toLocaleString() + " km";
document.getElementById('p-dist').innerText = d.d + " Million Km";
document.getElementById('p-desc').innerText = d.desc;
document.getElementById('p-speed').innerText = (d.s * 1000).toFixed(1) + " km/s";
const mContainer = document.getElementById('p-moons');
mContainer.innerHTML = '';
if(d.moons.length > 0) {
d.moons.forEach(m => {
const badge = document.createElement('div');
badge.className = 'moon-badge';
badge.innerText = m.name;
mContainer.appendChild(badge);
});
} else {
mContainer.innerHTML = '<span style="color:#666; font-size:12px;">No Moons Detected</span>';
}
document.getElementById('info-panel').classList.add('active');
// Auto focus camera?
// controls.target.copy(data.meshRef.position);
}
window.closePanel = () => document.getElementById('info-panel').classList.remove('active');
// --- 9. CAMERA & CINEMATICS ---
let tourMode = false;
let tourIndex = 0;
let tourTimer = 0;
window.toggleTour = () => {
tourMode = !tourMode;
const btn = document.getElementById('tourBtn');
if(tourMode) {
btn.classList.add('active-mode');
btn.innerText = "STOP TOUR";
closePanel();
} else {
btn.classList.remove('active-mode');
btn.innerText = "CINEMATIC TOUR";
controls.autoRotate = false;
}
};
window.resetCam = () => {
tourMode = false;
camera.position.set(0, 500, 0);
controls.target.set(0,0,0);
};
// --- 10. MAIN LOOP ---
const dateEl = document.getElementById('ui-date');
const speedInput = document.getElementById('speedSlider');
let timeSpeed = 1;
let days = 0;
speedInput.addEventListener('input', (e) => timeSpeed = parseFloat(e.target.value));
function animate() {
requestAnimationFrame(animate);
// Run Physics
updatables.forEach(fn => fn(timeSpeed));
// Update Date
if(timeSpeed > 0) {
days += timeSpeed * 0.5;
dateEl.innerText = "Year " + Math.floor(days/365 + 1) + " | Day " + Math.floor(days%365);
}
// Tour Mode Logic
if(tourMode) {
tourTimer += 0.01;
if(tourTimer > 5) { // Switch every 5 seconds (simulated time unit)
tourIndex = (tourIndex + 1) % planets.length;
tourTimer = 0;
}
const targetP = planets[tourIndex];
if(targetP.meshRef) {
// Smooth follow
const targetPos = new THREE.Vector3();
targetP.meshRef.getWorldPosition(targetPos);
// Camera lerp
const camOffset = targetPos.clone().add(new THREE.Vector3(targetP.r*4, targetP.r*2, targetP.r*4));
camera.position.lerp(camOffset, 0.05);
controls.target.lerp(targetPos, 0.05);
}
}
controls.update();
renderer.render(scene, camera);
}
// Hide loader
setTimeout(() => {
document.getElementById('loader').style.opacity = 0;
setTimeout(() => document.getElementById('loader').remove(), 1000);
}, 1500);
animate();
// Resize Handler
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
const bgMusic = new Audio('music.mp3');
bgMusic.loop = true;
bgMusic.volume = 0.5;
window.addEventListener('mousedown', () => {
bgMusic.play().catch(e => console.log("Audio play blocked"));
}, { once: true });
</script>
</body>
</html>