-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2387 lines (2044 loc) · 118 KB
/
Copy pathindex.html
File metadata and controls
2387 lines (2044 loc) · 118 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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Realistic Solar System Model</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://unpkg.com/mp4-muxer/build/mp4-muxer.js"></script>
<script src="https://unpkg.com/webm-muxer/build/webm-muxer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/exporters/GLTFExporter.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000000; /* Set default to black */
color: white;
font-family: sans-serif;
user-select: none;
}
/* Custom scrollbar for settings */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 4px; }
</style>
</head>
<body class="w-screen h-screen flex items-center justify-center relative overflow-hidden">
<!-- The Canvas Container (Centers and resizes) -->
<div id="canvas-container" class="relative flex-none shadow-2xl">
<!-- Capture Area Guide Overlay -->
<div id="capture-guide-overlay" class="absolute inset-0 border-2 border-dashed border-red-500 hidden z-10 pointer-events-none shadow-[0_0_0_9999px_rgba(0,0,0,0.85)] transition-opacity"></div>
<!-- ThreeJS Injects Canvas Here -->
</div>
<!-- UI Overlay -->
<div id="ui-layer" class="absolute inset-0 p-4 flex flex-col justify-between pointer-events-none z-20">
<div class="flex justify-between items-start w-full">
<!-- Info Panel -->
<div class="pointer-events-auto bg-black/60 backdrop-blur-md border border-gray-700 rounded-xl shadow-lg overflow-hidden transition-all duration-300 max-w-[280px]">
<button id="btn-toggle-info" class="w-full flex justify-between items-center p-3 hover:bg-gray-800/50 transition-colors gap-4">
<h1 class="text-sm font-bold text-gray-100 tracking-wider flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
INFO
</h1>
<svg id="info-chevron" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="transform transition-transform"><polyline points="6 9 12 15 18 9"></polyline></svg>
</button>
<div id="info-content" class="hidden p-4 pt-2 border-t border-gray-700/50">
<div class="mb-4">
<h3 class="font-bold text-gray-400 mb-1 uppercase tracking-wider text-xs">Current Date (UTC)</h3>
<p id="date-display" class="text-xl font-mono text-blue-400">2000-01-01</p>
</div>
<div>
<h3 class="font-bold text-gray-400 mb-2 uppercase tracking-wider text-xs">Legend</h3>
<div id="legend-container" class="grid grid-cols-2 gap-x-4 gap-y-2 text-xs text-gray-300">
<!-- Injected via JS -->
</div>
<p class="text-gray-500 mt-3 italic text-[10px]">1 Unit = 1 Astronomical Unit (AU)</p>
</div>
<!-- Planet Details Section (Hidden by default) -->
<div id="planet-details" class="hidden mt-4 pt-4 border-t border-gray-700/50">
<div class="flex justify-between items-center mb-3">
<h3 id="detail-name" class="font-bold text-blue-400 text-lg uppercase tracking-wider">Earth</h3>
<button id="btn-reset-focus" class="text-xs bg-gray-800 hover:bg-gray-700 px-2 py-1 rounded text-gray-300 border border-gray-600 transition-colors">Unfocus</button>
</div>
<div class="grid grid-cols-2 gap-3 text-xs text-gray-300">
<div><span class="text-gray-500 font-bold">Size:</span> <br><span id="detail-size" class="font-mono">1x Earth</span></div>
<div><span class="text-gray-500 font-bold">Orbit Size:</span> <br><span id="detail-orbit" class="font-mono">1.00 AU</span></div>
<div class="col-span-2"><span class="text-gray-500 font-bold">Orbit Time:</span> <br><span id="detail-time" class="font-mono">365.25 days</span></div>
</div>
</div>
</div>
</div>
<!-- Settings Toggle Button -->
<button id="btn-open-settings" class="bg-gray-800/80 hover:bg-gray-700 text-white p-3 rounded-full shadow-lg border border-gray-600 transition-all pointer-events-auto" title="Open Settings">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"></path><circle cx="12" cy="12" r="3"></circle></svg>
</button>
</div>
</div>
<!-- Settings Panel (Modal) -->
<div id="settings-panel" class="absolute top-4 right-4 w-80 max-h-[90vh] bg-gray-900/95 backdrop-blur-xl border border-gray-700 rounded-2xl shadow-2xl z-30 hidden transform transition-all flex flex-col pointer-events-auto">
<!-- Header -->
<div class="flex justify-between items-center p-4 border-b border-gray-700 shrink-0">
<h2 class="text-lg font-bold text-white flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
Time Controls
</h2>
<button id="btn-close-settings" class="text-gray-400 hover:text-white bg-gray-800 hover:bg-gray-700 rounded-full p-1 transition-colors">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
</div>
<!-- Body -->
<div class="p-5 space-y-6 overflow-y-auto">
<!-- Time Speed Control -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Time Flow (Days per Second)</label>
<input type="range" id="time-speed" min="-1000" max="1000" value="1" class="w-full h-2 bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-500">
<div class="flex justify-between text-xs text-gray-500 mt-2 font-mono">
<span>Reverse (-1000)</span>
<span id="speed-label" class="text-blue-400 font-bold">1 days/s</span>
<span>Forward (1000)</span>
</div>
<div class="flex justify-center mt-3 gap-2 flex-wrap">
<button id="btn-pause" class="bg-gray-800 hover:bg-gray-700 px-3 py-1.5 rounded text-xs border border-gray-600 transition-colors">Pause</button>
<button id="btn-realtime" class="bg-gray-800 hover:bg-gray-700 px-3 py-1.5 rounded text-xs border border-gray-600 transition-colors">Real-time</button>
<button id="btn-normal" class="bg-gray-800 hover:bg-gray-700 px-3 py-1.5 rounded text-xs border border-gray-600 transition-colors">Normal (1d/s)</button>
</div>
</div>
<hr class="border-gray-700">
<!-- Jump to Date -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Jump to Date</label>
<div class="flex gap-2">
<input type="date" id="date-picker" class="flex-1 bg-gray-800 border border-gray-600 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2 custom-date-input">
<button id="btn-go-date" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded-lg text-sm transition-colors">Go</button>
</div>
<button id="btn-present" class="w-full mt-3 bg-gray-800 hover:bg-gray-700 text-white border border-gray-600 py-2 rounded-lg text-sm transition-colors flex items-center justify-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>
Return to Present
</button>
</div>
<hr class="border-gray-700">
<!-- Motion & Trails -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">System Motion</label>
<div class="flex gap-4 text-sm text-gray-300 mb-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="motion-mode" value="static" checked class="accent-blue-500"> Static
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="motion-mode" value="vortex" class="accent-blue-500"> Moving Sun
</label>
</div>
<div id="vortex-settings-container" class="hidden mt-2 mb-4 pt-3 border-t border-gray-700/50">
<label class="block text-sm font-medium text-gray-300 mb-2">Solar Motion Approximation</label>
<div class="flex flex-col gap-2 text-sm text-gray-300 mb-3">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="vortex-preset" value="90" checked class="accent-blue-500"> Diagram (Vertical)
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="vortex-preset" value="53" class="accent-blue-500"> Local Apex (~53°, 4.2 AU/yr)
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="vortex-preset" value="60" class="accent-blue-500"> Galactic Tangent (~60°, 48.5 AU/yr)
</label>
</div>
<label class="block text-sm font-medium text-gray-300 mb-2">Translation Speed (AU / Year)</label>
<input type="number" id="vortex-speed-input" value="4.2" step="0.1" class="bg-gray-800 border border-gray-600 rounded p-2 w-full text-sm">
</div>
<label class="block text-sm font-medium text-gray-300 mb-2">Trail Mode</label>
<div class="flex flex-col gap-2 text-sm text-gray-300">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="trail-mode" value="none" class="accent-blue-500"> None
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="trail-mode" value="streak" checked class="accent-blue-500"> Frame Streak
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="trail-mode" value="continuous" class="accent-blue-500"> Continuous Path
</label>
</div>
</div>
<hr class="border-gray-700">
<!-- Orbit Spacing Toggle -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Orbit Spacing</label>
<div class="flex flex-col gap-2 text-sm text-gray-300 sm:flex-row sm:gap-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="spacing-mode" value="realistic" checked class="accent-blue-500"> Realistic
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="spacing-mode" value="uniform" class="accent-blue-500"> Uniform Steps
</label>
</div>
</div>
<hr class="border-gray-700">
<!-- Planet Size Toggle -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Planet Sizes</label>
<div class="flex flex-col gap-2 text-sm text-gray-300">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="size-mode" value="uniform" checked class="accent-blue-500"> Uniform
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="size-mode" value="relative" class="accent-blue-500"> Relative (Exaggerated)
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="size-mode" value="true" class="accent-blue-500"> True to Orbit Scale (Realistic)
</label>
</div>
</div>
<hr class="border-gray-700">
<!-- Lighting Mode Toggle -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Lighting</label>
<div class="flex gap-4 text-sm text-gray-300">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="lighting-mode" value="realistic" checked class="accent-blue-500"> Realistic
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="lighting-mode" value="flat" class="accent-blue-500"> Flat (Circles)
</label>
</div>
</div>
<hr class="border-gray-700">
<!-- Background Settings -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Background</label>
<div class="flex flex-col gap-3 text-sm text-gray-300">
<div class="flex items-center gap-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="bg-mode" value="color" checked class="accent-blue-500"> Solid Color
</label>
<input type="color" id="bg-color-picker" value="#000000" class="w-8 h-8 rounded cursor-pointer bg-gray-800 border border-gray-600 p-0 border-0">
</div>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="bg-mode" value="transparent" class="accent-blue-500"> Transparent (PNG)
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="bg-mode" value="starmap" class="accent-blue-500"> Realistic Sky (360° Milky Way)
</label>
</div>
</div>
<hr class="border-gray-700">
<!-- Camera Modes -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Camera Projection</label>
<div class="flex gap-4 text-sm text-gray-300 mb-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="camera-mode" value="perspective" checked class="accent-blue-500"> Perspective
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="camera-mode" value="orthographic" class="accent-blue-500"> Orthographic
</label>
</div>
<label class="block text-sm font-medium text-gray-300 mb-2">Reference Frame</label>
<div class="flex flex-col gap-2 text-sm text-gray-300 mb-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="reference-frame" value="sun" checked class="accent-blue-500"> Sun-Centered
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="reference-frame" value="fixed" class="accent-blue-500"> Fixed Origin
</label>
</div>
<label class="block text-sm font-medium text-gray-300 mb-2">Guides & Alignment</label>
<div class="flex flex-col gap-2 text-sm text-gray-300 mb-3">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="toggle-grid-axes" class="accent-blue-500"> Show Grid & Axes (X, Y, Z)
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="toggle-motion-vectors" class="accent-blue-500"> Motion Vectors
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="toggle-galactic-center" class="accent-blue-500"> Indicator: Galactic Center & Equator
</label>
</div>
<label class="block text-xs text-gray-500 mb-2">Snap Camera To:</label>
<div class="grid grid-cols-2 gap-2">
<button id="btn-cam-top" class="bg-gray-800 hover:bg-gray-700 text-white px-2 py-1.5 rounded-lg text-xs transition-colors border border-gray-600">Top (+Y)</button>
<button id="btn-cam-x" class="bg-gray-800 hover:bg-gray-700 text-white px-2 py-1.5 rounded-lg text-xs transition-colors border border-gray-600">Equinox (+X)</button>
<button id="btn-cam-z" class="bg-gray-800 hover:bg-gray-700 text-white px-2 py-1.5 rounded-lg text-xs transition-colors border border-gray-600">Side (+Z)</button>
<button id="btn-cam-gc" class="bg-gray-800 hover:bg-gray-700 text-white px-2 py-1.5 rounded-lg text-xs transition-colors border border-gray-600">View Gal. Center</button>
</div>
</div>
<hr class="border-gray-700">
<!-- Render & Export -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">Render Video or Sequence</label>
<div class="space-y-3 text-sm text-gray-300">
<div class="flex justify-between items-center">
<span>Format</span>
<select id="render-format" class="bg-gray-800 border border-gray-600 rounded p-1 text-xs">
<option value="mp4">Video (MP4)</option>
<option value="webm">Video (WebM)</option>
<option value="zip">Frames (ZIP PNGs)</option>
</select>
</div>
<div class="flex justify-between items-center">
<span>Resolution</span>
<select id="render-res" class="bg-gray-800 border border-gray-600 rounded p-1 text-xs">
<option value="1920x1080">1080p (16:9)</option>
<option value="1280x720">720p (16:9)</option>
<option value="800x600">SVGA (4:3)</option>
<option value="1080x1920">Vertical (9:16)</option>
<option value="1080x1080">Square (1:1)</option>
<option value="custom">Custom...</option>
</select>
</div>
<div id="custom-res-inputs" class="hidden flex justify-between items-center gap-2">
<input type="number" id="custom-res-w" value="1920" class="bg-gray-800 border border-gray-600 rounded p-1 w-full text-center text-xs" placeholder="Width">
<span class="text-gray-500">x</span>
<input type="number" id="custom-res-h" value="1080" class="bg-gray-800 border border-gray-600 rounded p-1 w-full text-center text-xs" placeholder="Height">
</div>
<div class="flex justify-between items-center">
<span>Framerate</span>
<select id="render-fps" class="bg-gray-800 border border-gray-600 rounded p-1 text-xs">
<option value="30">30 fps</option>
<option value="60">60 fps</option>
</select>
</div>
<div class="flex justify-between items-center">
<span>Start Date</span>
<input type="date" id="render-start-date" class="bg-gray-800 border border-gray-600 rounded p-1 w-32 text-center text-xs">
</div>
<div class="flex justify-between items-center">
<span>End Date</span>
<input type="date" id="render-end-date" class="bg-gray-800 border border-gray-600 rounded p-1 w-32 text-center text-xs">
</div>
<div class="flex justify-between items-center">
<span>Duration (sec)</span>
<input type="number" id="render-duration" value="5" min="1" max="60" class="bg-gray-800 border border-gray-600 rounded p-1 w-16 text-center text-xs">
</div>
<div class="mt-2 pt-3 border-t border-gray-700/50">
<div class="flex items-center gap-2">
<input type="checkbox" id="toggle-capture-guide" class="accent-blue-500 cursor-pointer">
<label for="toggle-capture-guide" class="cursor-pointer">Show Capture Area Guide</label>
</div>
<div id="preview-scale-container" class="hidden justify-between items-center mt-3">
<span class="text-xs text-gray-400">Preview Scale</span>
<input type="range" id="preview-scale" min="10" max="100" value="80" class="w-1/2 h-2 bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-500">
</div>
</div>
<button id="btn-start-render" class="w-full bg-green-600 hover:bg-green-700 text-white px-3 py-2 rounded-lg text-sm transition-colors font-bold mt-2 shadow-lg">Start Render</button>
<div id="render-status" class="text-center text-xs text-blue-400 font-bold hidden">Rendering...</div>
<div id="render-progress-bar" class="w-full bg-gray-700 rounded-full h-1.5 hidden">
<div id="render-progress-fill" class="bg-blue-500 h-1.5 rounded-full transition-all duration-100" style="width: 0%"></div>
</div>
</div>
</div>
<hr class="border-gray-700">
<!-- 3D Model Export -->
<div>
<label class="block text-sm font-medium text-gray-300 mb-2">3D Path Generation & Export</label>
<div class="space-y-3 text-sm text-gray-300">
<div class="flex justify-between items-center">
<span>Start Date</span>
<input type="date" id="export-3d-start-date" class="bg-gray-800 border border-gray-600 rounded p-1 w-32 text-center text-xs">
</div>
<div class="flex justify-between items-center">
<span>End Date</span>
<input type="date" id="export-3d-end-date" class="bg-gray-800 border border-gray-600 rounded p-1 w-32 text-center text-xs">
</div>
<div class="flex gap-2">
<button id="btn-preview-3d" class="flex-1 bg-blue-600 hover:bg-blue-700 text-white px-2 py-2 rounded-lg text-xs transition-colors font-bold shadow-lg">Preview Path</button>
<button id="btn-export-3d" class="flex-1 bg-purple-600 hover:bg-purple-700 text-white px-2 py-2 rounded-lg text-xs transition-colors font-bold shadow-lg">Export Path</button>
</div>
<button id="btn-export-current" class="w-full bg-gray-700 hover:bg-gray-600 text-white px-3 py-2 rounded-lg text-xs transition-colors shadow-lg border border-gray-500">Export Current Scene (GLB)</button>
</div>
</div>
<hr class="border-gray-700">
<!-- Visibility Controls -->
<div>
<label class="flex items-center gap-2 cursor-pointer text-sm font-medium text-gray-300 mb-2">
<input type="checkbox" id="toggle-orbits" checked class="accent-blue-500"> Show Orbits
</label>
</div>
<hr class="border-gray-700">
<!-- Instructions -->
<div class="text-xs text-gray-400">
<p><strong>Mouse Controls:</strong></p>
<ul class="list-disc list-inside mt-1 space-y-1">
<li><strong>Drag:</strong> Rotate camera</li>
<li><strong>Scroll:</strong> Zoom in / out</li>
<li><strong>Click:</strong> Select planet to focus</li>
</ul>
</div>
</div>
</div>
<script>
/**
* PLANETARY DATA
* JPL-style approximate Keplerian elements and rates, valid for broad
* visualization ranges. a = semi-major axis in AU, e = eccentricity,
* I = inclination, L = mean longitude, longPeri = longitude of perihelion,
* node = longitude of ascending node. Rates are per Julian century.
* Note: Sizes are exaggerated relative to distances so they remain visible as dots.
*/
const planetsData = [
{ name: "Mercury", a: 0.38709843, aRate: 0.00000000, e: 0.20563661, eRate: 0.00002123, I: 7.00559432, IRate: -0.00590158, L: 252.25166724, LRate: 149472.67486623, longPeri: 77.45771895, longPeriRate: 0.15940013, node: 48.33961819, nodeRate: -0.12214182, color: 0xaaaaaa, relativeRadius: 0.38, trueRadius: 0.0000163 },
{ name: "Venus", a: 0.72332102, aRate: -0.00000026, e: 0.00676399, eRate: -0.00005107, I: 3.39777545, IRate: 0.00043494, L: 181.97970850, LRate: 58517.81560260, longPeri: 131.76755713, longPeriRate: 0.05679648, node: 76.67261496, nodeRate: -0.27274174, color: 0xe3bb76, relativeRadius: 0.95, trueRadius: 0.0000404 },
{ name: "Earth", a: 1.00000018, aRate: -0.00000003, e: 0.01673163, eRate: -0.00003661, I: -0.00054346, IRate: -0.01337178, L: 100.46691572, LRate: 35999.37306329, longPeri: 102.93005885, longPeriRate: 0.31795260, node: -5.11260389, nodeRate: -0.24123856, color: 0x2b82c9, relativeRadius: 1.00, trueRadius: 0.0000426 },
{ name: "Mars", a: 1.52371243, aRate: 0.00000097, e: 0.09336511, eRate: 0.00009149, I: 1.85181869, IRate: -0.00724757, L: -4.56813164, LRate: 19140.29934243, longPeri: -23.91744784, longPeriRate: 0.45223625, node: 49.71320984, nodeRate: -0.26852431, color: 0xc1440e, relativeRadius: 0.53, trueRadius: 0.0000226 },
{ name: "Jupiter", a: 5.20248019, aRate: -0.00002864, e: 0.04853590, eRate: 0.00018026, I: 1.29861416, IRate: -0.00322699, L: 34.33479152, LRate: 3034.90371757, longPeri: 14.27495244, longPeriRate: 0.18199196, node: 100.29282654, nodeRate: 0.13024619, b: -0.00012452, c: 0.06064060, s: -0.35635438, f: 38.35125000, color: 0xd39c7e, relativeRadius: 11.20, trueRadius: 0.0004673 },
{ name: "Saturn", a: 9.54149883, aRate: -0.00003065, e: 0.05550825, eRate: -0.00032044, I: 2.49424102, IRate: 0.00451969, L: 50.07571329, LRate: 1222.11494724, longPeri: 92.86136063, longPeriRate: 0.54179478, node: 113.63998702, nodeRate: -0.25015002, b: 0.00025899, c: -0.13434469, s: 0.87320147, f: 38.35125000, color: 0xc5ab6e, relativeRadius: 9.45, trueRadius: 0.0003892 },
{ name: "Uranus", a: 19.18797948, aRate: -0.00020455, e: 0.04685740, eRate: -0.00001550, I: 0.77298127, IRate: -0.00180155, L: 314.20276625, LRate: 428.49512595, longPeri: 172.43404441, longPeriRate: 0.09266985, node: 73.96250215, nodeRate: 0.05739699, b: 0.00058331, c: -0.97731848, s: 0.17689245, f: 7.67025000, color: 0x65868b, relativeRadius: 4.00, trueRadius: 0.0001695 },
{ name: "Neptune", a: 30.06952752, aRate: 0.00006447, e: 0.00895439, eRate: 0.00000818, I: 1.77005520, IRate: 0.00022400, L: 304.22289287, LRate: 218.46515314, longPeri: 46.68158724, longPeriRate: 0.01009938, node: 131.78635853, nodeRate: -0.00606302, b: -0.00041348, c: 0.68346318, s: -0.10162547, f: 7.67025000, color: 0x2249ab, relativeRadius: 3.88, trueRadius: 0.0001646 }
];
// Core App Variables
let scene, camera, renderer;
let perspCamera, orthoCamera;
let isOrthographic = false;
let planetMeshes = [];
let orbitLines = [];
let sunMesh;
let sunLight;
let sunStreakLine;
let sunTrailCapMesh;
let timeSpeed = 1; // Simulated days per real second
let simulatedDate = new Date(); // Start at real present
const J2000_EPOCH = new Date(Date.UTC(2000, 0, 1, 12, 0, 0)).getTime();
const J2000_JD = 2451545.0;
const UNIX_EPOCH_JD = 2440587.5;
const DEG_TO_RAD = Math.PI / 180;
let lastFrameTime = performance.now();
let sizeMode = 'uniform';
let isUniformOrbits = false;
let showOrbits = true;
let gridHelper, axesHelper, galacticCenterArrow, galacticEquator, gcDir, gnpDir;
let solarMotionArrow, eclipticNorthArrow, eclipticPlane;
let solarMotionLabel, eclipticNorthLabel, galacticCenterLabel;
let skydome;
// Trail & Motion Variables
let trailMode = 'streak'; // 'none', 'streak', 'continuous'
let continuousTrailStartDate = null;
let isVortexMode = false;
let vortexStartDate = null;
let vortexSpeedAUPerYear = 4.2;
let vortexDirection = new THREE.Vector3(0, 1, 0); // Default: ecliptic north in scene coordinates
let skipStreakNextFrame = false;
const MAX_TRAIL_SEGMENTS = 8192; // Increased from 1024 for 8x more curve detail
const EARTH_BASE_RADIUS = 0.02; // Base scale for relative sizes
const UNIFORM_RADIUS = 0.1; // Fixed size for all planets
// Camera Interaction Variables
let cameraRadius = 15;
let cameraTheta = Math.PI / 4;
let cameraPhi = Math.PI / 3;
let followMovingSun = true;
let showMotionVectors = false;
let isDragging = false;
let hasMoved = false; // To distinguish between drag and click
let previousMousePosition = { x: 0, y: 0 };
// Raycaster / Focus Variables
const raycaster = new THREE.Raycaster();
let focusedPlanet = null;
// DOM Elements
const canvasContainer = document.getElementById('canvas-container');
const dateDisplay = document.getElementById('date-display');
const settingsPanel = document.getElementById('settings-panel');
const btnOpenSettings = document.getElementById('btn-open-settings');
const btnCloseSettings = document.getElementById('btn-close-settings');
const btnToggleInfo = document.getElementById('btn-toggle-info');
const infoContent = document.getElementById('info-content');
const infoChevron = document.getElementById('info-chevron');
const planetDetailsPanel = document.getElementById('planet-details');
const detailName = document.getElementById('detail-name');
const detailSize = document.getElementById('detail-size');
const detailOrbit = document.getElementById('detail-orbit');
const detailTime = document.getElementById('detail-time');
const btnResetFocus = document.getElementById('btn-reset-focus');
const timeSpeedSlider = document.getElementById('time-speed');
const speedLabel = document.getElementById('speed-label');
const btnPresent = document.getElementById('btn-present');
const btnPause = document.getElementById('btn-pause');
const btnRealtime = document.getElementById('btn-realtime');
const btnNormal = document.getElementById('btn-normal');
const datePicker = document.getElementById('date-picker');
const btnGoDate = document.getElementById('btn-go-date');
const legendContainer = document.getElementById('legend-container');
const motionModeRadios = document.querySelectorAll('input[name="motion-mode"]');
const trailModeRadios = document.querySelectorAll('input[name="trail-mode"]');
const sizeModeRadios = document.querySelectorAll('input[name="size-mode"]');
const spacingModeRadios = document.querySelectorAll('input[name="spacing-mode"]');
const lightingModeRadios = document.querySelectorAll('input[name="lighting-mode"]');
const cameraModeRadios = document.querySelectorAll('input[name="camera-mode"]');
const referenceFrameRadios = document.querySelectorAll('input[name="reference-frame"]');
const btnCamTop = document.getElementById('btn-cam-top');
const btnCamX = document.getElementById('btn-cam-x');
const btnCamZ = document.getElementById('btn-cam-z');
const btnCamGC = document.getElementById('btn-cam-gc');
const toggleOrbits = document.getElementById('toggle-orbits');
const toggleGridAxes = document.getElementById('toggle-grid-axes');
const toggleMotionVectors = document.getElementById('toggle-motion-vectors');
const toggleGalacticCenter = document.getElementById('toggle-galactic-center');
const bgModeRadios = document.querySelectorAll('input[name="bg-mode"]');
const bgColorPicker = document.getElementById('bg-color-picker');
// Vortex Elements
const vortexSettingsContainer = document.getElementById('vortex-settings-container');
const vortexSpeedInput = document.getElementById('vortex-speed-input');
const vortexPresetRadios = document.querySelectorAll('input[name="vortex-preset"]');
// Render & Export Elements
const renderFormat = document.getElementById('render-format');
const renderRes = document.getElementById('render-res');
const customResInputs = document.getElementById('custom-res-inputs');
const customResW = document.getElementById('custom-res-w');
const customResH = document.getElementById('custom-res-h');
const renderStartDate = document.getElementById('render-start-date');
const renderEndDate = document.getElementById('render-end-date');
const toggleCaptureGuide = document.getElementById('toggle-capture-guide');
const captureGuideOverlay = document.getElementById('capture-guide-overlay');
const previewScaleContainer = document.getElementById('preview-scale-container');
const previewScaleSlider = document.getElementById('preview-scale');
const btnStartRender = document.getElementById('btn-start-render');
const renderStatus = document.getElementById('render-status');
const renderProgressBar = document.getElementById('render-progress-bar');
const renderProgressFill = document.getElementById('render-progress-fill');
let isRendering = false;
// 3D Export Elements
const export3DStartDate = document.getElementById('export-3d-start-date');
const export3DEndDate = document.getElementById('export-3d-end-date');
const btnPreview3D = document.getElementById('btn-preview-3d');
const btnExport3D = document.getElementById('btn-export-3d');
const btnExportCurrent = document.getElementById('btn-export-current');
init();
animate();
function init() {
// 1. Setup Three.js Scene
scene = new THREE.Scene();
// Add a subtle starfield background
scene.background = new THREE.Color(0x000000);
// 2. Setup Camera
perspCamera = new THREE.PerspectiveCamera(60, 1, 0.000001, 1000);
orthoCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.000001, 1000);
camera = perspCamera;
updateCameraPosition();
// 3. Setup Renderer (alpha: true allows transparency)
renderer = new THREE.WebGLRenderer({ antialias: true, logarithmicDepthBuffer: true, alpha: true });
renderer.setClearColor(0x000000, 1);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); // optimize performance
// Attach to the container
canvasContainer.appendChild(renderer.domElement);
// Apply initial sizing based on Guide logic
applyCaptureGuide();
// 4. Create Sun
const sunGeometry = new THREE.SphereGeometry(1, 32, 32);
const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffdd00 }); // Basic material so it glows regardless of light
sunMesh = new THREE.Mesh(sunGeometry, sunMaterial);
scene.add(sunMesh);
// Sun Trail Setup
const sunStreakGeo = new THREE.BufferGeometry();
const sunSides = 16;
const sunIndices = [];
for (let k = 0; k < sunSides; k++) {
const i0 = k;
const i1 = (k + 1) % sunSides;
const n0 = sunSides + k;
const n1 = sunSides + ((k + 1) % sunSides);
// CCW winding
sunIndices.push(i0, i1, n0);
sunIndices.push(i1, n1, n0);
}
sunStreakGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(2 * sunSides * 3), 3));
sunStreakGeo.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(2 * sunSides * 3), 3));
// Upgraded to Uint32Array to support higher polygon counts
sunStreakGeo.setIndex(new THREE.BufferAttribute(new Uint32Array(sunIndices), 1));
const sunStreakMat = new THREE.MeshBasicMaterial({ color: 0xffdd00 });
sunStreakLine = new THREE.Mesh(sunStreakGeo, sunStreakMat);
sunStreakLine.visible = false;
sunStreakLine.frustumCulled = false;
scene.add(sunStreakLine);
const sunCapGeo = new THREE.SphereGeometry(1, 16, 16);
sunTrailCapMesh = new THREE.Mesh(sunCapGeo, sunStreakMat);
sunTrailCapMesh.visible = false;
scene.add(sunTrailCapMesh);
// Add Sun Light
sunLight = new THREE.PointLight(0xffffff, 1.5, 100);
scene.add(sunLight);
scene.add(new THREE.AmbientLight(0x222222)); // Ambient light to see dark sides slightly
// Guides & Indicators
gridHelper = new THREE.GridHelper(100, 100, 0x444444, 0x222222);
gridHelper.visible = false;
scene.add(gridHelper);
axesHelper = new THREE.AxesHelper(20);
axesHelper.visible = false;
scene.add(axesHelper);
// Galactic directions are defined in J2000 ecliptic lon/lat, then converted once into scene space.
gcDir = eclipticLonLatToSceneVector(266.84, -5.53);
// Magenta arrow pointing to the galactic center.
galacticCenterArrow = new THREE.ArrowHelper(gcDir, new THREE.Vector3(0,0,0), 35, 0xff00ff, 2, 1);
galacticCenterArrow.visible = false;
scene.add(galacticCenterArrow);
// Galactic North Pole Direction (J2000 ecliptic coordinates: lat 29.81°, lon 180.03°)
gnpDir = eclipticLonLatToSceneVector(180.03, 29.81);
const equatorGeo = new THREE.TorusGeometry(890, 0.5, 4, 128);
const equatorMat = new THREE.MeshBasicMaterial({ color: 0xff00ff, transparent: true, opacity: 0.5 });
galacticEquator = new THREE.Mesh(equatorGeo, equatorMat);
// Orient the ring so its normal faces the Galactic North Pole
galacticEquator.lookAt(gnpDir);
galacticEquator.visible = false;
scene.add(galacticEquator);
solarMotionArrow = new THREE.ArrowHelper(vortexDirection.clone().normalize(), new THREE.Vector3(0,0,0), 14, 0x00d4ff, 1.3, 0.75);
solarMotionArrow.visible = false;
scene.add(solarMotionArrow);
eclipticNorthArrow = new THREE.ArrowHelper(eclipticLonLatToSceneVector(0, 90), new THREE.Vector3(0,0,0), 9, 0x22c55e, 0.9, 0.5);
eclipticNorthArrow.visible = false;
scene.add(eclipticNorthArrow);
const eclipticPlaneGeo = new THREE.CircleGeometry(35, 128);
const eclipticPlaneMat = new THREE.MeshBasicMaterial({
color: 0x2b82c9,
transparent: true,
opacity: 0.08,
side: THREE.DoubleSide,
depthWrite: false
});
eclipticPlane = new THREE.Mesh(eclipticPlaneGeo, eclipticPlaneMat);
eclipticPlane.rotation.x = -Math.PI / 2;
eclipticPlane.visible = false;
scene.add(eclipticPlane);
solarMotionLabel = createLabelSprite('Solar motion', '#00d4ff');
eclipticNorthLabel = createLabelSprite('Ecliptic north', '#22c55e');
galacticCenterLabel = createLabelSprite('Galactic center', '#ff00ff');
[solarMotionLabel, eclipticNorthLabel, galacticCenterLabel].forEach(label => {
label.visible = false;
scene.add(label);
});
// 360 Sky Sphere (True Equirectangular NASA Milky Way Panorama)
const textureLoader = new THREE.TextureLoader();
textureLoader.setCrossOrigin('anonymous'); // Ensure CORS gets requested explicitly
textureLoader.load(
'https://cdn.eso.org/images/large/eso0932a.jpg',
(texture) => {
// 1. Prevent Three.js from mapping the image upside down
texture.flipY = false;
const domeGeo = new THREE.SphereGeometry(900, 64, 64);
const domeMat = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.BackSide,
color: 0xdddddd, // Very slight dimming so the planets pop out
depthWrite: false
});
skydome = new THREE.Mesh(domeGeo, domeMat);
// 2. Flip the sphere horizontally (-X) to fix the inside-out mirror effect.
// Flip vertically (-Y) to swap North/South so Magellanic Clouds sit in the South!
skydome.scale.set(-1, -1, 1);
// 3. Absolute Mathematical Alignment Matrix
// We map the physical top of the image (+Y) to the Galactic North Pole.
// We map the physical center of the image (-X due to the scale flip) to the Galactic Center.
const localY = gnpDir.clone().normalize();
const localX = gcDir.clone().negate().normalize();
const localZ = new THREE.Vector3().crossVectors(localX, localY).normalize();
const alignMatrix = new THREE.Matrix4().makeBasis(localX, localY, localZ);
skydome.quaternion.setFromRotationMatrix(alignMatrix);
skydome.visible = false; // default off
scene.add(skydome);
updateBackground(); // Sync in case it loaded after a UI toggle
},
undefined,
(error) => {
console.error("Failed to load the sky texture. Check your internet connection.", error);
}
);
// 5. Build reusable indexed ribbon geometry for solid 3D segments
const sides = 16;
const indices = [];
for (let j = 0; j < MAX_TRAIL_SEGMENTS; j++) {
for (let k = 0; k < sides; k++) {
const i0 = j * sides + k;
const i1 = j * sides + ((k + 1) % sides);
const n0 = (j + 1) * sides + k;
const n1 = (j + 1) * sides + ((k + 1) % sides);
// CCW winding looking from the outside for correct normal generation:
indices.push(i0, i1, n0);
indices.push(i1, n1, n0);
}
}
// Upgraded to Uint32Array because 8192 segments * 16 sides exceeds the 65,535 limit of 16-bit indices
const indicesArray = new Uint32Array(indices);
// 6. Create Planets, Orbit Guides, and solid 3D Ribbon Streaks with Rounded Caps
planetsData.forEach(pData => {
// Planet Mesh (Unit size, scaled later)
const geometry = new THREE.SphereGeometry(1, 16, 16);
const standardMaterial = new THREE.MeshStandardMaterial({
color: pData.color,
roughness: 0.7,
metalness: 0.1
});
const basicMaterial = new THREE.MeshBasicMaterial({ color: pData.color });
const mesh = new THREE.Mesh(geometry, standardMaterial);
scene.add(mesh);
// solid 3D Ribbon Streak Mesh (cylindrical tube profile)
const streakGeo = new THREE.BufferGeometry();
const streakPositions = new Float32Array((MAX_TRAIL_SEGMENTS + 1) * sides * 3);
const streakNormals = new Float32Array((MAX_TRAIL_SEGMENTS + 1) * sides * 3);
streakGeo.setAttribute('position', new THREE.BufferAttribute(streakPositions, 3));
streakGeo.setAttribute('normal', new THREE.BufferAttribute(streakNormals, 3));
streakGeo.setIndex(new THREE.BufferAttribute(indicesArray, 1));
// Create independent solid materials for the streaks
const streakStandardMat = new THREE.MeshStandardMaterial({
color: pData.color,
roughness: 0.7,
metalness: 0.1
});
const streakBasicMat = new THREE.MeshBasicMaterial({
color: pData.color
});
const streakLine = new THREE.Mesh(streakGeo, streakStandardMat);
streakLine.visible = false;
streakLine.frustumCulled = false;
scene.add(streakLine);
// Create independent solid Tail Cap Mesh (to seal the past end of the trail seamlessly)
const capGeometry = new THREE.SphereGeometry(1, 16, 16);
const capStandardMat = new THREE.MeshStandardMaterial({
color: pData.color,
roughness: 0.7,
metalness: 0.1
});
const capBasicMat = new THREE.MeshBasicMaterial({ color: pData.color });
const trailCapMesh = new THREE.Mesh(capGeometry, capStandardMat);
trailCapMesh.visible = false;
scene.add(trailCapMesh);
planetMeshes.push({
mesh: mesh,
data: pData,
standardMaterial: standardMaterial,
basicMaterial: basicMaterial,
streakStandardMaterial: streakStandardMat,
streakBasicMaterial: streakBasicMat,
streakLine: streakLine,
trailCapMesh: trailCapMesh,
capStandardMaterial: capStandardMat,
capBasicMaterial: capBasicMat
});
// Orbit Line
const orbitLine = createOrbitLine(pData.color);
scene.add(orbitLine);
orbitLines.push(orbitLine);
// Add to Legend UI (Make it clickable)
const pIndex = planetMeshes.length - 1;
const legendItem = document.createElement('button');
legendItem.className = 'flex items-center gap-2 hover:bg-gray-700/50 p-1.5 rounded transition-colors w-full text-left';
legendItem.innerHTML = `
<div class="w-3 h-3 rounded-full shadow shrink-0" style="background-color: #${pData.color.toString(16).padStart(6, '0')}"></div>
<span class="truncate">${pData.name}</span>
`;
legendItem.onclick = () => focusPlanet(planetMeshes[pIndex]);
legendContainer.appendChild(legendItem);
});
updatePlanetSizes();
updateOrbitsDisplay();
// 7. Event Listeners
window.addEventListener('resize', applyCaptureGuide);
setupMouseControls();
setupUIListeners();
}
function createLabelSprite(text, color) {
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'rgba(0, 0, 0, 0.62)';
ctx.fillRect(0, 22, canvas.width, 84);
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.strokeRect(2, 24, canvas.width - 4, 80);
ctx.fillStyle = color;
ctx.font = 'bold 42px sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(5.2, 1.3, 1);
return sprite;
}
function setMotionVectorVisibility(visible) {
showMotionVectors = visible;
if (solarMotionArrow) solarMotionArrow.visible = visible;
if (eclipticNorthArrow) eclipticNorthArrow.visible = visible;
if (eclipticPlane) eclipticPlane.visible = visible;
if (solarMotionLabel) solarMotionLabel.visible = visible;
if (eclipticNorthLabel) eclipticNorthLabel.visible = visible;
updateReferenceGuidesPosition();
}
function setGalacticGuideVisibility(visible) {
if (galacticCenterArrow) galacticCenterArrow.visible = visible;
if (galacticEquator) galacticEquator.visible = visible;
if (galacticCenterLabel) galacticCenterLabel.visible = visible;
updateReferenceGuidesPosition();
}
function getReferenceFrameOffset(offset = null) {
const currentOffset = offset || getVortexOffset(simulatedDate.getTime());
if (isVortexMode && !followMovingSun) return { x: 0, y: 0, z: 0 };
return currentOffset;
}
function updateReferenceFrameAnchors(offset = null) {
const frameOffset = getReferenceFrameOffset(offset);
if (gridHelper) gridHelper.position.set(frameOffset.x, frameOffset.y, frameOffset.z);
if (axesHelper) axesHelper.position.set(frameOffset.x, frameOffset.y, frameOffset.z);
}
function updateReferenceGuidesPosition(offset = null) {
const currentOffset = offset || getVortexOffset(simulatedDate.getTime());
const origin = new THREE.Vector3(currentOffset.x, currentOffset.y, currentOffset.z);
const motionDir = vortexDirection.clone().normalize();
const eclipticNorth = eclipticLonLatToSceneVector(0, 90);
if (solarMotionArrow) {
solarMotionArrow.position.copy(origin);
solarMotionArrow.setDirection(motionDir);
}
if (eclipticNorthArrow) {
eclipticNorthArrow.position.copy(origin);
eclipticNorthArrow.setDirection(eclipticNorth);
}
if (eclipticPlane) {
eclipticPlane.position.copy(origin);
}
if (galacticCenterArrow) {
galacticCenterArrow.position.copy(origin);
galacticCenterArrow.setDirection(gcDir);
}
if (solarMotionLabel) {
solarMotionLabel.position.copy(origin).add(motionDir.clone().multiplyScalar(16));
}
if (eclipticNorthLabel) {
eclipticNorthLabel.position.copy(origin).add(eclipticNorth.multiplyScalar(10.5));
}
if (galacticCenterLabel) {
galacticCenterLabel.position.copy(origin).add(gcDir.clone().multiplyScalar(37));
}
}
function createCircularOrbitGeometry(radius) {
const points = [];
const segments = 128;
for (let i = 0; i <= segments; i++) {
const theta = (i / segments) * Math.PI * 2;
points.push(eclipticToSceneVector({
x: radius * Math.cos(theta),
y: radius * Math.sin(theta),
z: 0
}));
}
return new THREE.BufferGeometry().setFromPoints(points);
}
function createKeplerOrbitGeometry(pData, date) {
const points = [];
const segments = 256;
const T = getCenturiesSinceJ2000(date);
for (let i = 0; i <= segments; i++) {
const E = (i / segments) * Math.PI * 2;
const pos = calculateKeplerPositionFromEccentricAnomaly(pData, T, E);
points.push(new THREE.Vector3(pos.x, pos.y, pos.z));
}
return new THREE.BufferGeometry().setFromPoints(points);
}
function createOrbitLine(colorHex) {
const material = new THREE.LineBasicMaterial({
color: colorHex,
transparent: true,
opacity: 0.25
});
return new THREE.Line(createCircularOrbitGeometry(1), material);
}
// Sets visibility of orbits and applies uniform step metrics if configured
function updateOrbitsDisplay() {
planetMeshes.forEach((p, i) => {
const distance = isUniformOrbits ? (i + 1) * 1.5 : p.data.a;
if (orbitLines[i]) {
const nextGeometry = isUniformOrbits
? createCircularOrbitGeometry(distance)
: createKeplerOrbitGeometry(p.data, simulatedDate);
orbitLines[i].geometry.dispose();
orbitLines[i].geometry = nextGeometry;
orbitLines[i].scale.set(1, 1, 1);
orbitLines[i].visible = showOrbits;
}
});
}
function updatePlanetSizes() {
planetMeshes.forEach(p => {
let scale = UNIFORM_RADIUS;
if (sizeMode === 'relative') scale = p.data.relativeRadius * EARTH_BASE_RADIUS;
else if (sizeMode === 'true') scale = p.data.trueRadius;
p.mesh.scale.set(scale, scale, scale);
p.trailCapMesh.scale.set(scale, scale, scale);
});
if (sunMesh) {
let sunScale = 0.15;
if (sizeMode === 'true') {
sunScale = 0.004654;
} else if (sizeMode === 'uniform') {
sunScale = UNIFORM_RADIUS;
}
sunMesh.scale.set(sunScale, sunScale, sunScale);
if (typeof sunTrailCapMesh !== 'undefined') {
sunTrailCapMesh.scale.set(sunScale, sunScale, sunScale);
}
}
}
function updateLightingMode() {
const isFlat = document.querySelector('input[name="lighting-mode"]:checked').value === 'flat';
planetMeshes.forEach(p => {
p.mesh.material = isFlat ? p.basicMaterial : p.standardMaterial;
p.streakLine.material = isFlat ? p.streakBasicMaterial : p.streakStandardMaterial;
p.trailCapMesh.material = isFlat ? p.capBasicMaterial : p.capStandardMaterial;
});
}