-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
3131 lines (2581 loc) · 141 KB
/
main.py
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
# import OpenGL
# from OpenGL.GL import *
# from OpenGL.GLU import *
import os
import keyboard
import glfw
# import time
import re
# import shutil
import sys
import random
import glob
import ast
from graphics import *
from vessel_class import *
from body_class import *
from camera_class import *
from surface_point_class import *
from barycenter_class import *
# from math_utils import *
from maneuver import *
from orbit import *
from plot import *
from command_panel import *
from config_utils import *
from radiation_pressure import *
from atmospheric_drag import *
# from vector3 import *
from solver import *
from proximity import *
from resource import *
from general_relativity import *
from test_propagator import *
from observation import *
from surface_coverage import *
from wavefront import Wavefront3D
def clear_cmd_terminal():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
initial_run = True
vessels = []
bodies = []
barycenters = []
surface_points = []
objs = []
projections = []
plots = []
cameras = []
maneuvers = []
radiation_pressures = []
atmospheric_drags = []
schwarzschilds = []
lensethirrings = []
proximity_zones = []
resources = []
observations = []
surface_coverages = []
starfield = []
batch_commands = []
command_history = []
preset_orientations = ["prograde", "prograde_dynamic", "retrograde", "retrograde_dynamic",
"normal", "normal_dynamic", "antinormal", "antinormal_dynamic",
"radial_in", "radial_in_dynamic", "radial_out", "radial_out_dynamic",
"prograde_tangential", "prograde_tangential_dynamic",
"retrograde_tangential", "retrograde_tangential_dynamic"]
sim_time = 0
# these three below are default values, should be changed by main() once the program reads config data
gvar_fov = 70
gvar_near_clip = 0.01
gvar_far_clip = 10E5
def window_resize(window, width, height):
global gvar_fov, gvar_near_clip, gvar_far_clip, cameras
try:
# glfw.get_framebuffer_size(window)
glViewport(0, 0, width, height)
glLoadIdentity()
main_cam = cameras[0]
gluPerspective(gvar_fov, width/height, gvar_near_clip, gvar_far_clip)
glTranslate(main_cam.pos.x, main_cam.pos.y, main_cam.pos.z)
main_cam.orient = matrix3x3()
except ZeroDivisionError:
# if the window is minimized it makes height = 0, but we don't need to update projection in that case anyway
pass
def read_batch(batch_path):
try:
batch_file = open(batch_path, "r")
except FileNotFoundError:
try:
batch_file = open("scenarios/" + batch_path, "r")
except FileNotFoundError:
try:
batch_file = open(batch_path + ".obf", "r")
except FileNotFoundError:
try:
batch_file = open("scenarios/" + batch_path + ".obf", "r")
except FileNotFoundError:
print("\nError reading batch file.\n")
time.sleep(2)
return [[""]]
batch_lines = batch_file.readlines()
commands = []
for line in batch_lines:
if not line[0] == ";":
commands.append(line[0:-1].split(" "))
return commands
def clear_scene():
global objs, vessels, bodies, projections, maneuvers, surface_points, barycenters, resources,\
plots, radiation_pressures, atmospheric_drags, proximity_zones, schwarzschilds, lensethirrings,\
observations, surface_coverages, sim_time
objs = []
vessels = []
bodies = []
maneuvers = []
projections = []
surface_points = []
barycenters = []
resources = []
plots = []
radiation_pressures = []
atmospheric_drags = []
proximity_zones = []
schwarzschilds = []
lensethirrings = []
observations = []
surface_coverages = []
sim_time = 0
def import_scenario(scn_filename):
global objs, vessels, bodies, surface_points, maneuvers, barycenters, atmospheric_drags,\
schwarzschilds, lensethirrings, observations, surface_coverages, proximity_zones,\
resources, sim_time
def construct_point_mass_cloud(pmc_str):
# this is a bit of an operation unfortunately, but should be more readable to the user
data_list = ast.literal_eval(pmc_str)
point_mass_cloud = []
for pos_lst, scalar in data_list:
pos = vec3(lst=pos_lst)
point_mass_cloud.append([pos, scalar])
return point_mass_cloud
clear_scene()
try:
scn_file = open(scn_filename, "r")
except FileNotFoundError:
try:
scn_file = open("scenarios/" + scn_filename, "r")
except FileNotFoundError:
try:
scn_file = open(scn_filename + ".osf", "r")
except FileNotFoundError:
try:
scn_file = open("scenarios/" + scn_filename + ".osf", "r")
except FileNotFoundError:
print("Scenario file not found.")
time.sleep(2)
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
init_sim()
start_time = 0
print("\nImporting scenario:", scn_filename, "\n")
import_lines = scn_file.readlines()
for line in import_lines:
line = line[0:-1].split("|")
# get sim start time
if line[0] == "T":
try:
start_time = float(line[1])
except:
pass
# import bodies
if line[0] == "B":
line[6] = eval(line[6])
line[7] = eval(line[7])
line[8] = eval(line[8])
orient_nums = re.findall(r"[-+]?\d*\.\d+|\d+", line[9])
if line[3] == "None":
smp = None
else:
smp = line[3]
new_body = body(line[1], Wavefront3D(line[2]), line[2],
smp, # surface map path
float(line[4]), float(line[5]),
line[6], vec3(lst=line[7]), vec3(lst=line[8]),
matrix3x3([[float(orient_nums[0]), float(orient_nums[1]), float(orient_nums[2])],
[float(orient_nums[3]), float(orient_nums[4]), float(orient_nums[5])],
[float(orient_nums[6]), float(orient_nums[7]), float(orient_nums[8])]]),
float(line[10]), # day length
vec3(lst=eval(line[11])), # rot axis
float(line[12]), # J2
float(line[13]), # luminosity
float(line[14]), float(line[15]), # atmosphere
construct_point_mass_cloud(line[16])) # point-mass-cloud
bodies.append(new_body)
objs.append(new_body)
print("Loading body:", new_body.get_name())
# import vessels
elif line[0] == "V":
line[3] = eval(line[3])
line[4] = eval(line[4])
line[5] = eval(line[5])
new_vessel = vessel(line[1], Wavefront3D(line[2]), line[2],
line[3], vec3(lst=line[4]), vec3(lst=line[5]))
vessels.append(new_vessel)
objs.append(new_vessel)
print("Loading vessel:", new_vessel.get_name())
# import maneuvers
elif line[0] == "M":
if line[2] == "const_accel":
if line[5] in preset_orientations:
new_maneuver = maneuver_const_accel(line[1], find_obj_by_name(line[3]), find_obj_by_name(line[4]),
line[5], float(line[6]), float(line[7]), float(line[8]))
else:
line[5] = eval(line[5])
new_maneuver = maneuver_const_accel(line[1], find_obj_by_name(line[3]), find_obj_by_name(line[4]),
vec3(lst=line[5]),
float(line[6]), float(line[7]), float(line[8]))
elif line[2] == "const_thrust":
if line[5] in preset_orientations:
new_maneuver = maneuver_const_thrust(line[1], find_obj_by_name(line[3]), find_obj_by_name(line[4]),
line[5], float(line[6]), float(line[7]), float(line[8]),
float(line[9]), float(line[10]))
else:
line[5] = eval(line[5])
new_maneuver = maneuver_const_thrust(line[1], find_obj_by_name(line[3]), find_obj_by_name(line[4]),
vec3(lst=line[5]),
float(line[6]), float(line[7]), float(line[8]),
float(line[9]), float(line[10]))
elif line[2] == "impulsive":
if line[5] in preset_orientations:
new_maneuver = maneuver_impulsive(line[1], find_obj_by_name(line[3]), find_obj_by_name(line[4]),
line[5], float(line[6]), float(line[7]))
else:
line[5] = eval(line[5])
new_maneuver = maneuver_impulsive(line[1], find_obj_by_name(line[3]), find_obj_by_name(line[4]),
vec3(lst=line[5]), float(line[6]), float(line[7]))
maneuvers.append(new_maneuver)
print("Loading maneuver:", new_maneuver.get_name())
# import surface points
elif line[0] == "S":
line[3] = eval(line[3]) # color
line[4] = eval(line[4]) # gpos
new_sp = surface_point(line[1], find_obj_by_name(line[2]), line[3], line[4])
surface_points.append(new_sp)
objs.append(new_sp)
print("Loading surface point:", new_sp.get_name())
# import barycenters
elif line[0] == "C":
line[2] = line[2].split(",")
bodies_included = []
for body_name in line[2]:
bodies_included.append(find_obj_by_name(body_name))
new_bc = barycenter(line[1], bodies_included)
barycenters.append(new_bc)
objs.append(new_bc)
print("Loading barycenter:", new_bc.get_name())
# import radiation pressure data
elif line[0] == "R":
if line[6] in preset_orientations:
new_rp = radiation_pressure(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]),
float(line[4]), find_obj_by_name(line[5]), line[6], float(line[7]), int(line[8]))
else:
line[6] = eval(line[6])
new_rp = radiation_pressure(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]),
float(line[4]), find_obj_by_name(line[5]), vec3(lst=line[6]),
float(line[7]), int(line[8]))
radiation_pressures.append(new_rp)
print("Loading radiation pressure:", new_rp.get_name())
# import atmospheric drag data
elif line[0] == "A":
new_ad = atmospheric_drag(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]),
float(line[4]), float(line[5]), float(line[6]), int(line[7]))
atmospheric_drags.append(new_ad)
print("Loading atmospheric drag:", new_ad.get_name())
# import proximity zone data
elif line[0] == "P":
new_pz = proximity_zone(line[1], find_obj_by_name(line[2]), float(line[3]), float(line[4]))
proximity_zones.append(new_pz)
print("Loading proximity zone:", new_pz.name)
# import surface coverage data
elif line[0] == "SC":
new_sc = surface_coverage(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]))
surface_coverages.append(new_sc)
print("Loading surface coverage:", new_sc.name)
# import resource data
elif line[0] == "U":
new_res = resource(line[1], float(line[2]), line[3], line[4], find_obj_by_name(line[5]), find_obj_by_name(line[6]), eval(line[7]), eval(line[8]))
resources.append(new_res)
print("Loading resource:", new_res.name)
# import Schwarzschild effect data
elif line[0] == "GR0":
new_sch = GR_Schwarzschild(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]))
schwarzschilds.append(new_sch)
print("Loading Schwarzschild effect:", new_sch.name)
# import Lense-Thirring effect data
elif line[0] == "GR1":
new_lt = GR_LenseThirring(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]), eval(line[4]))
lensethirrings.append(new_lt)
print("Loading Lense-Thirring effect:", new_lt.name)
elif line[0] == "OBS":
new_obs = observation(line[1], find_obj_by_name(line[2]), find_obj_by_name(line[3]))
observations.append(new_obs)
print("Loading observation:", new_obs.name)
main(scn_filename, start_time)
def export_scenario(scn_filename, verbose=True):
global objs, vessels, bodies, surface_points, maneuvers, barycenters, resources, radiation_pressures, atmospheric_drags,\
schwarzschilds, lensethirrings, observations, surface_coverages, proximity_zones, sim_time, command_history
os.makedirs("scenarios/", exist_ok=True)
scn_filename = "scenarios/" + scn_filename
if not scn_filename.endswith(".osf"):
scn_filename += ".osf"
if verbose:
clear_cmd_terminal()
print("Saving scenario into " + scn_filename)
with open(scn_filename, "w") as scn_file:
print("Writing header...")
header_string = """
;.osf -- orbitSim3D scenario format
; This scenario was exported by orbitSim3D.
;= = = = = = = = = =\n
"""
scn_file.write(header_string)
if verbose:
print("Writing simulation time...")
time_save_string = "T|" + str(sim_time) + "\n"
scn_file.write(time_save_string)
scn_file.write("\n")
if verbose:
print("Writing bodies...")
for b in bodies:
body_save_string = "B|" + b.get_name() + "|" + b.get_model_path() + "|" + b.get_surface_map_path() + "|" + str(b.get_mass()) + "|" +\
str(b.get_radius()) + "|" + str(b.get_color()) + "|" + str(b.get_pos().tolist()) + "|" +\
str(b.get_vel().tolist()) + "|" + str(b.get_orient().tolist()) + "|" + str(b.get_day_length()) + "|" + str(b.get_rot_axis().tolist()) + "|" +\
str(b.get_J2()) + "|" + str(b.luminosity) + "|" + str(b.atmos_sea_level_density) + "|" +\
str(b.atmos_scale_height) + "|" + b.pmc_to_str() + "\n"
scn_file.write(body_save_string)
scn_file.write("\n")
if verbose:
print("Writing vessels...")
for v in vessels:
vessel_save_string = "V|" + v.get_name() + "|" + v.get_model_path() + "|" + str(v.get_color()) + "|" +\
str(v.get_pos().tolist()) + "|" + str(v.get_vel().tolist()) + "\n"
scn_file.write(vessel_save_string)
scn_file.write("\n")
if verbose:
print("Writing maneuvers...")
for m in maneuvers:
maneuver_save_string = "M|" + m.get_name() + "|"
if m.get_type() == "const_accel":
maneuver_save_string += "const_accel|" + m.get_vessel().get_name() + "|" + m.frame_body.get_name() + "|" +\
str(m.orientation_input) + "|" + str(m.accel) + "|" + str(m.t_start) + "|" + str(m.duration) + "\n"
elif m.get_type() == "const_thrust":
maneuver_save_string += "const_thrust|" + m.get_vessel().get_name() + "|" + m.frame_body.get_name() + "|" +\
str(m.orientation_input) + "|" + str(m.thrust) + "|" + str(m.mass_init) + "|" + str(m.mass_flow) + "|" +\
str(m.t_start) + "|" + str(m.duration) + "\n"
elif m.get_type() == "impulsive":
maneuver_save_string += "impulsive|" + m.get_vessel().get_name() + "|" + m.frame_body.get_name() + "|" +\
str(m.orientation_input) + "|" + str(m.delta_v) + "|" + str(m.t_perform) + "\n"
scn_file.write(maneuver_save_string)
scn_file.write("\n")
if verbose:
print("Writing surface points...")
for s in surface_points:
sp_save_string = "S|" + s.get_name() + "|" + s.get_body().get_name() + "|" + str(s.get_color()) + "|" + str(s.get_gpos()) + "\n"
scn_file.write(sp_save_string)
scn_file.write("\n")
if verbose:
print("Writing barycenters...")
for bc in barycenters:
bc_save_string = "C|" + bc.get_name() + "|"
for b in bc.get_bodies():
bc_save_string += b.get_name() + ","
bc_save_string = bc_save_string[:-1]+"\n"
scn_file.write(bc_save_string)
scn_file.write("\n")
if verbose:
print("Writing surface coverages...")
for sc in surface_coverages:
sc_save_string = "SC|" + sc.name + "|" + sc.get_vessel().get_name() + "|" + sc.get_body().get_name() + "\n"
scn_file.write(sc_save_string)
scn_file.write("\n")
if verbose:
print("Writing resources...")
for res in resources:
res_save_string = "U|" + res.get_name() + "|" + str(res.value) + "|" + res.equation + "|" + res.variable + "|" + res.obj1.name + "|" + res.obj2.name + "|" + str(res.coeffs) + "|" + str(res.limits) + "\n"
scn_file.write(res_save_string)
scn_file.write("\n")
if verbose:
print("Writing radiation pressures...")
for rp in radiation_pressures:
rp_save_string = "R|" + rp.get_name() + "|" + rp.vessel.get_name() + "|" + rp.body.get_name() + "|" + str(rp.get_area()) +\
"|" + rp.orientation_frame.get_name() + "|" + str(rp.direction_input) + "|" + str(rp.mass) + "|" + str(rp.mass_auto_update) + "\n"
scn_file.write(rp_save_string)
scn_file.write("\n")
if verbose:
print("Writing atmospheric drags...")
for ad in atmospheric_drags:
ad_save_string = "A|" + ad.get_name() + "|" + ad.vessel.get_name() + "|" + ad.body.get_name() + "|" + str(ad.get_area()) +\
"|" + str(ad.get_drag_coeff()) + "|" + str(ad.get_mass()) + "|" + str(ad.mass_auto_update) + "\n"
scn_file.write(ad_save_string)
scn_file.write("\n")
if verbose:
print("Writing proximity zones...")
for pz in proximity_zones:
pz_save_string = "P|" + pz.name + "|" + pz.vessel.get_name() + "|" + str(pz.vessel_size) + "|" + str(pz.zone_size) + "\n"
scn_file.write(pz_save_string)
scn_file.write("\n")
if verbose:
print("Writing Schwarzschild effects...")
for sch in schwarzschilds:
sch_save_string = "GR0|" + sch.name + "|" + sch.body.get_name() + "|" + sch.vessel.get_name() + "\n"
scn_file.write(sch_save_string)
scn_file.write("\n")
if verbose:
print("Writing Lense-Thirring effects...")
for lt in lensethirrings:
lt_save_string = "GR1|" + lt.name + "|" + lt.body.get_name() + "|" + lt.vessel.get_name() + "|" + str(lt.J) + "\n"
scn_file.write(lt_save_string)
scn_file.write("\n")
if verbose:
print("Writing observation setups...")
for obs in observations:
obs_save_string = "OBS|" + obs.name + "|" + obs.observer.get_name() + "|" + obs.obj.get_name() + "|" + str(obs.axes[0].tolist()).replace(" ", "") + "|" + str(obs.axes[1].tolist()).replace(" ", "") + "|" + str(obs.axes[2].tolist()).replace(" ", "") + "\n"
scn_file.write(obs_save_string)
scn_file.write("\n")
if verbose:
print("Scenario export complete!")
time.sleep(2)
# Export commands
if command_history:
if verbose:
print("Saving command history into " + scn_filename[:-4] + "_cmdhist.obf")
with open(scn_filename[:-4] + "_cmdhist.obf", "w") as cmd_file:
for cmd in command_history:
cmd_file.write(' '.join(cmd) + "\n")
if verbose:
print("Command history export complete!")
time.sleep(2)
def create_maneuver_const_accel(mnv_name, mnv_vessel, mnv_frame, mnv_orientation, mnv_accel, mnv_start,
mnv_duration):
global maneuvers
if find_maneuver_by_name(mnv_name):
print("A maneuver with this name already exists. Please pick another name for the new maneuver.\n")
input("Press Enter to continue...")
return
new_maneuver = maneuver_const_accel(mnv_name, mnv_vessel, mnv_frame, mnv_orientation, mnv_accel,
mnv_start, mnv_duration)
maneuvers.append(new_maneuver)
def create_maneuver_const_thrust(mnv_name, mnv_vessel, mnv_frame, mnv_orientation, mnv_thrust, mnv_mass_init,
mnv_mass_flow, mnv_start, mnv_duration):
global maneuvers
if find_maneuver_by_name(mnv_name):
print("A maneuver with this name already exists. Please pick another name for the new maneuver.\n")
input("Press Enter to continue...")
return
new_maneuver = maneuver_const_thrust(mnv_name, mnv_vessel, mnv_frame, mnv_orientation, mnv_thrust,
mnv_mass_init, mnv_mass_flow, mnv_start, mnv_duration)
maneuvers.append(new_maneuver)
def create_maneuver_impulsive(mnv_name, mnv_vessel, mnv_frame, mnv_orientation, mnv_deltav, mnv_t_perform):
global maneuvers
if find_maneuver_by_name(mnv_name):
print("A maneuver with this name already exists. Please pick another name for the new maneuver.\n")
input("Press Enter to continue...")
return
new_maneuver = maneuver_impulsive(mnv_name, mnv_vessel, mnv_frame, mnv_orientation, mnv_deltav, mnv_t_perform)
maneuvers.append(new_maneuver)
def delete_maneuver(mnv_name):
global maneuvers
mnv = find_maneuver_by_name(mnv_name)
if not mnv:
print("Maneuver not found!")
time.sleep(2)
return
maneuvers.remove(mnv)
del mnv
def find_maneuver_by_name(mnv_name):
global maneuvers
result = None
for m in maneuvers:
if m.name == mnv_name:
result = m
break
return result
def apply_radiation_pressure(rp_name, rp_vessel, rp_body, rp_area, rp_orient_frame, rp_direction, rp_mass, rp_mass_auto_update):
global radiation_pressures
if find_radiation_pressure_by_name(rp_name):
print("A radiation pressure effect with this name already exists. Please pick another name for the new effect.\n")
input("Press Enter to continue...")
return
new_rp = radiation_pressure(rp_name, rp_vessel, rp_body, rp_area, rp_orient_frame, rp_direction, rp_mass, rp_mass_auto_update)
radiation_pressures.append(new_rp)
def remove_radiation_pressure(rp_name):
global radiation_pressures
rp = find_radiation_pressure_by_name(rp_name)
if not rp:
print("Radiation pressure effect not found!")
time.sleep(2)
return
radiation_pressures.remove(rp)
del rp
def find_radiation_pressure_by_name(rp_name):
global radiation_pressures
result = None
for rp in radiation_pressures:
if rp.name == rp_name:
result = rp
break
return result
def apply_atmospheric_drag(ad_name, ad_vessel, ad_body, ad_area, ad_drag_coeff, ad_mass, ad_mass_auto_update):
global atmospheric_drags
if find_atmospheric_drag_by_name(ad_name):
print("An atmospheric drag effect with this name already exists. Please pick another name for the new effect.\n")
input("Press Enter to continue...")
return
new_ad = atmospheric_drag(ad_name, ad_vessel, ad_body, ad_area, ad_drag_coeff, ad_mass, ad_mass_auto_update)
atmospheric_drags.append(new_ad)
def remove_atmospheric_drag(ad_name):
global atmospheric_drags
ad = find_atmospheric_drag_by_name(ad_name)
if not ad:
print("Atmospheric drag effect not found!")
time.sleep(2)
return
atmospheric_drags.remove(ad)
del ad
def find_atmospheric_drag_by_name(ad_name):
global atmospheric_drags
result = None
for ad in atmospheric_drags:
if ad.name == ad_name:
result = ad
break
return result
def create_vessel(name, model_name, color, pos, vel):
global vessels, objs
if find_obj_by_name(name):
print("An object with this name already exists. Please pick another name for the new vessel.\n")
input("Press Enter to continue...")
return
try:
model_path = "data/models/" + model_name + ".obj"
model = Wavefront3D(model_path)
except:
print("Could not load model:", model_path)
time.sleep(3)
return
if type(pos) == list:
pos = vec3(lst=pos)
if type(vel) == list:
vel = vec3(lst=vel)
try:
new_vessel = vessel(name, model, model_path, color, pos, vel)
except:
print("Could not create vessel:", name)
time.sleep(3)
return
vessels.append(new_vessel)
objs.append(new_vessel)
def fragment(vessel_name, num_of_frags, vel_of_frags):
if num_of_frags < 1:
print("Cannot fragment vessel into less than 1 parts! (Duh.)")
input("Press Enter to continue...")
return
if find_obj_by_name(vessel_name):
vessel = find_obj_by_name(vessel_name)
else:
print("A vessel with name \'" + vessel_name + "\' does not exist! Cannot create fragments!")
input("Press Enter to continue...")
return
for i in range(num_of_frags):
fragment_vel = vec3(lst=[vessel.get_vel().x + random.uniform(-vel_of_frags, vel_of_frags),
vessel.get_vel().y + random.uniform(-vel_of_frags, vel_of_frags),
vessel.get_vel().z + random.uniform(-vel_of_frags, vel_of_frags)])
fragment_pos = vessel.get_pos()
create_vessel(vessel_name + "_frag_" + str(i), "fragment", vessel.get_color(), fragment_pos, fragment_vel)
def delete_vessel(name):
global vessels, objs, proximity_zones
vessel_tbd = find_obj_by_name(name)
if not vessel_tbd:
print("Object not found!")
time.sleep(2)
return
for pz in proximity_zones:
if vessel_tbd == pz.vessel:
delete_proximity_zone(pz.name)
vessels.remove(vessel_tbd)
objs.remove(vessel_tbd)
del vessel_tbd
def find_obj_by_name(name):
global objs
result = None
for obj in objs:
if obj.get_name() == name:
result = obj
break
return result
# 'point' here can either be an object with property 'pos' or an
# arbitrary point in the 3D scene
def get_closest_object_to(point):
global objs
current_pos = vec3(0, 0, 0)
result_obj = None
if point.get_pos:
current_pos = point.get_pos()
else:
current_pos = point
min_dist = None
for obj in objs:
current_dist = ((obj.get_pos().x - current_pos.x)**2 + (obj.get_pos().y - current_pos.y)**2 + (obj.get_pos().z - current_pos.z)**2)**0.5
if not min_dist or current_dist < min_dist:
min_dist = current_dist
result_obj = obj
return obj
def find_proj_by_name(name):
global projections
result = None
for proj in projections:
if proj.get_name() == name:
result = proj
break
return result
def create_keplerian_proj(name, vessel, body, proj_time):
global projections
if find_proj_by_name(name):
print("A projection with this name already exists. Please pick another name for the new projection.\n")
input("Press Enter to continue...")
return
new_proj = kepler_projection(name, vessel, body, proj_time)
projections.append(new_proj)
def delete_keplerian_proj(name):
global projections
proj_tbd = find_proj_by_name(name)
if not proj_tbd:
print("Projection not found!")
time.sleep(2)
return
projections.remove(proj_tbd)
del proj_tbd
def update_keplerian_proj(name, update_time):
global projections
proj_tbu = find_proj_by_name(name)
if not proj_tbu:
print("Projection not found!")
time.sleep(2)
return
proj_vessel = proj_tbu.get_vessel()
proj_body = proj_tbu.get_body()
try:
delete_keplerian_proj(name)
create_keplerian_proj(name, proj_vessel, proj_body, update_time)
except:
print("Can not update projection!")
time.sleep(2)
return
def find_plot_by_name(name):
global plots
result = None
for plot in plots:
if plot.get_name() == name:
result = plot
break
return result
def create_plot(name, variable, obj1_name, obj2_name, start_time=-1, end_time=-1):
global plots, sim_time
if find_plot_by_name(name):
print("A plot with this name already exists. Please pick another name for the new plot.\n")
input("Press Enter to continue...")
return
if start_time == -1:
start_time = sim_time
if end_time == -1:
end_time = start_time + 100
# plot title, x name, x list, y name, y list, obj1, obj2, variable, start_time, end_time
if variable == "alt":
obj1 = find_obj_by_name(obj1_name)
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Altitude of " + obj1_name + " above " + obj2_name, [],
obj1, obj2, "alt", start_time, end_time)
elif variable == "dist":
obj1 = find_obj_by_name(obj1_name)
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Distance between " + obj1_name + " and " + obj2_name, [],
obj1, obj2, "dist", start_time, end_time)
elif variable == "vel_mag":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Velocity of " + obj1_name + " rel to " + obj2_name, [],
obj1, obj2, "vel_mag", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "Velocity of " + obj1_name, [],
obj1, None, "vel_mag", start_time, end_time)
elif variable == "groundtrack":
obj1 = find_obj_by_name(obj1_name)
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Longitude", [], "Latitude", [], obj1, obj2, "groundtrack",
start_time, end_time)
elif variable == "surface_coverage":
obj1 = find_surface_coverage_by_name(obj1_name)
obj2 = obj1.body
new_plot = plot(name, "Longitude", [], "Latitude", [], obj1, obj2, "surface_coverage",
start_time, end_time)
elif variable == "pos_x":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "X Position of " + obj1_name + " rel. to " + obj2_name, [],
obj1, obj2, "pos_x", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "X Position of " + obj1_name, [],
obj1, None, "pos_x", start_time, end_time)
elif variable == "pos_y":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Y Position of " + obj1_name + " rel. to " + obj2_name, [],
obj1, obj2, "pos_y", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "Y Position of " + obj1_name, [],
obj1, None, "pos_y", start_time, end_time)
elif variable == "pos_z":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Z Position of " + obj1_name + " rel. to " + obj2_name, [],
obj1, obj2, "pos_z", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "Z Position of " + obj1_name, [],
obj1, None, "pos_z", start_time, end_time)
elif variable == "vel_x":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "X Velocity of " + obj1_name + " rel. to " + obj2_name, [],
obj1, obj2, "vel_x", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "X Velocity of " + obj1_name, [],
obj1, None, "vel_x", start_time, end_time)
elif variable == "vel_y":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Y Velocity of " + obj1_name + " rel. to " + obj2_name, [],
obj1, obj2, "vel_y", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "Y Velocity of " + obj1_name, [],
obj1, None, "vel_y", start_time, end_time)
elif variable == "vel_z":
obj1 = find_obj_by_name(obj1_name)
if not obj2_name == "None":
obj2 = find_obj_by_name(obj2_name)
new_plot = plot(name, "Time", [], "Z Velocity of " + obj1_name + " rel. to " + obj2_name, [],
obj1, obj2, "vel_z", start_time, end_time)
else:
new_plot = plot(name, "Time", [], "Z Velocity of " + obj1_name, [],
obj1, None, "vel_z", start_time, end_time)
plots.append(new_plot)
def delete_plot(name):
global plots
plot_tbd = find_plot_by_name(name)
if not plot_tbd:
print("Plot not found!")
time.sleep(2)
return
plots.remove(plot_tbd)
del plot_tbd
def find_surface_coverage_by_name(name):
global surface_coverages
result = None
for sc in surface_coverages:
if sc.get_name() == name:
result = sc
break
return result
def create_surface_coverage(name, vessel, body):
global surface_coverages
if find_surface_coverage_by_name(name):
print("A surface coverage computation with this name already exists. Please pick another name for the new surface coverage computation.\n")
input("Press Enter to continue...")
return
try:
new_sc = surface_coverage(name, vessel, body)