From f13243c52e2f0ba7f68581095b3f077dbbc6fc01 Mon Sep 17 00:00:00 2001 From: march3 Date: Thu, 9 Nov 2023 22:09:23 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sim_scenes/solar_system/halley_comet_sim.py | 48 +++++++++++++++++---- simulators/ursina/ursina_mesh.py | 4 +- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/sim_scenes/solar_system/halley_comet_sim.py b/sim_scenes/solar_system/halley_comet_sim.py index 9858b26..0736a57 100644 --- a/sim_scenes/solar_system/halley_comet_sim.py +++ b/sim_scenes/solar_system/halley_comet_sim.py @@ -14,7 +14,7 @@ from common.celestial_data_service import init_bodies_reality_pos_vels, conv_to_ from common.consts import SECONDS_PER_YEAR, AU from common.func import calculate_distance from objs import HalleComet -from sim_scenes.func import create_text_panel +from sim_scenes.func import create_text_panel, camera_look_at from sim_scenes.func import ursina_run, create_sphere_sky from sim_scenes.solar_system.halley_comet_lib import HalleyCometSimBase, HalleyCometParams, \ create_halley_comet, create_orbit_line @@ -63,10 +63,11 @@ class HalleyCometSim(HalleyCometSimBase): # 创建天空 create_sphere_sky(scale=200000) # UrsinaConfig.trail_type = "curve_line" - # UrsinaConfig.trail_thickness_factor = 3 + # UrsinaConfig.trail_length = 300 UrsinaConfig.trail_type = "line" - UrsinaConfig.trail_thickness_factor = 3 UrsinaConfig.trail_length = 152 + UrsinaConfig.trail_thickness_factor = 5 + # UrsinaConfig.trail_length = 180 UrsinaConfig.trail_factor = 3 # camera.clip_plane_near = 0.1 @@ -111,7 +112,7 @@ class HalleyCometSim(HalleyCometSimBase): t = self.start_time + time_data.total_days set_solar_system_celestial_position(self.bodies, t, False) - def create_year_label(self, trail, year, halley_comet_pos): + def create_year_label(self, trail, year, halley_comet_pos=None, pos=None, scale=40, background=False): """ 在界面上创建年份的标签 @param trail: @@ -119,11 +120,18 @@ class HalleyCometSim(HalleyCometSimBase): @param halley_comet_pos: @return: """ + # 为了不影响 2023年12月9日的显示,附近的 Label 就不显示 + if year in ["1986", "2061", "2023", "2024", "2025"]: + return + if trail is None: - pos = halley_comet_pos + _pos = halley_comet_pos else: - pos = (0, 0, 0) - label = create_label(trail, label=year, pos=pos, color=(255, 255, 255), scale=40, alpha=1.0) + _pos = pos + if _pos is None: + _pos = (0, 0, 0) + label = create_label(trail, label=year, pos=_pos, color=(255, 255, 255), scale=scale, alpha=1.0, + background=background) label.set_light_off() def set_comet_trail_alpha(self, distance_sun): @@ -150,6 +158,23 @@ class HalleyCometSim(HalleyCometSimBase): c = self.halley_comet.planet.children[0] c.alpha = alpha + def show_milestone_lable(self, last_trail, dt): + """ + 远日点: 35.1 AU(2023年12月9日) + 近日点: 0.586 AU 上次通过近日点:1986年2月9日 下次通过近日点:2061年7月28日 + @param last_trail: + @param dt: + @return: + """ + milestones = ["1986-02-09", "2023-12-09", "2061-07-28"] + for milestone in milestones: + prop_name = f"milestone_{milestone}" + if not hasattr(self, prop_name) and dt.strftime("%Y-%m-%d") >= milestone: + setattr(self, prop_name, milestone) + self.create_year_label(last_trail, milestone, pos=(0, 2, 0), scale=100, background=True) + application.paused = True + UrsinaEvent.on_pause() + def on_timer_changed(self, time_data): """ @@ -159,6 +184,8 @@ class HalleyCometSim(HalleyCometSimBase): dt = time_data.get_datetime(str(self.start_time)) year = dt.strftime("%Y") + camera_look_at(self.halley_comet) + if hasattr(self, "halley_comet"): if self.halley_comet.planet.enabled: self.halley_comet.planet.look_at(self.sun.planet) @@ -177,7 +204,9 @@ class HalleyCometSim(HalleyCometSimBase): import copy - if not hasattr(self, "last_year"): + if self.show_milestone_lable(last_trail, dt): + pass + elif not hasattr(self, "last_year"): self.create_year_label(last_trail, year, pos) elif self.last_year != year: if not hasattr(self, "last_label_pos"): @@ -272,7 +301,8 @@ if __name__ == '__main__': ursina_run(sim.bodies, SECONDS_PER_YEAR, # position=(0, 2 * AU, -11 * AU), - position=(0, 0.5 * AU, -5 * AU), + # position=(0, 0.5 * AU, -5 * AU), + position=(0, AU, -20 * AU), cosmic_bg='', show_trail=True, # bg_music='sounds/no_glory.mp3', diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index 1d12f95..975d645 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -194,14 +194,14 @@ def create_arrow(height=0.5, width=0.1): return arrow_mesh -def create_label(parent, label, pos, color, scale=50, alpha=1.0): +def create_label(parent, label, pos, color, scale=50, alpha=1.0, background=False): if isinstance(color, tuple) or isinstance(color, list): color = conv_to_vec4_color(color) if alpha < 1: color[3] = alpha text = Text(label, parent=parent, scale=scale, billboard=True, color=color, position=Vec3(pos) + Vec3(1, 1, 1), alpha=alpha, - font=UrsinaConfig.CN_FONT, background=False) + font=UrsinaConfig.CN_FONT, background=background) return text -- GitLab