diff --git a/fonts/DroidSansFallback.ttf b/fonts/DroidSansFallback.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2f23c9d9d5da4599c1be54884f42499dd7ff9eb7 Binary files /dev/null and b/fonts/DroidSansFallback.ttf differ diff --git a/sim_scenes/func.py b/sim_scenes/func.py index 7bd33df20bbb0b7bc7a15bacdcc28244b95ccd53..00ffc396c4505f27c927fcea76679ca77049f0e7 100644 --- a/sim_scenes/func.py +++ b/sim_scenes/func.py @@ -409,7 +409,7 @@ def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02): return panel -def create_text_panel(width=0.35, height=.5): +def create_text_panel(width=0.35, height=.5, font=None): # 创建一个 Panel 组件 from ursina import Text, Panel, color, camera, Vec3, window from simulators.ursina.ursina_config import UrsinaConfig @@ -426,14 +426,18 @@ def create_text_panel(width=0.35, height=.5): position=(-.49 * aspect_ratio, 0.3, 0), alpha=0.5 ) - + if font is None: + font = UrsinaConfig.CN_FONT + else: + from common.func import find_file + font = find_file(f"fonts/{font}", UrsinaConfig.CN_FONT) # 创建一个 Text 组件用于显示消息 text = Text( parent=panel, text='', origin=(-.5, .5, -.5), scale=(height * 5, width * 5), - font=UrsinaConfig.CN_FONT, + font=font, # background=True, # background_color=color.clear ) diff --git a/sim_scenes/solar_system/halley_comet_sim.py b/sim_scenes/solar_system/halley_comet_sim.py index b8f67d32219a322defece4ec01f10ab0443b16bc..9710a9f3a542abf4b8e1c706d9aae2bd803da77d 100644 --- a/sim_scenes/solar_system/halley_comet_sim.py +++ b/sim_scenes/solar_system/halley_comet_sim.py @@ -136,6 +136,7 @@ class HalleyCometSim(HalleyCometSimBase): label = create_label(trail, label=year, pos=_pos, label_color=label_color, + font="DroidSansFallback.ttf", scale=scale, alpha=1.0, background=background ) label.set_light_off() @@ -369,7 +370,7 @@ class HalleyCometSim(HalleyCometSimBase): # 创建太阳系天体的真实轨迹(太阳和哈雷彗星除外) self.create_orbit_lines() # 创建信息显示面板 - self.text_panel = create_text_panel() + self.text_panel = create_text_panel(font="DroidSansFallback.ttf") def on_timer_changed(self, time_data): """ diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index e4a2bdeb22d46c6ef7f37f5851e7ca0a68c4ba9d..9ba58510c72913236335f761016c9a9c4966173b 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -194,14 +194,19 @@ def create_arrow(height=0.5, width=0.1): return arrow_mesh -def create_label(parent, label, pos, label_color, scale=50, alpha=1.0, background=False): +def create_label(parent, label, pos, label_color, scale=50, alpha=1.0, background=False, font=None): if isinstance(label_color, tuple) or isinstance(label_color, list): label_color = conv_to_vec4_color(label_color) if alpha < 1: label_color[3] = alpha + if font is None: + font = UrsinaConfig.CN_FONT + else: + from common.func import find_file + font = find_file(f"fonts/{font}", UrsinaConfig.CN_FONT) text = Text(label, parent=parent, scale=scale, billboard=True, color=label_color, position=Vec3(pos) + Vec3(1, 1, 1), alpha=alpha, - font=UrsinaConfig.CN_FONT, background=background) + font=font, background=background) return text