From 9809fe3dc67ab3223c595f0858ae6f4f53c43693 Mon Sep 17 00:00:00 2001 From: march3 Date: Fri, 23 Jun 2023 21:06:29 +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 --- simulators/ursina/entities/entity_utils.py | 28 +++++++++++----------- simulators/ursina/ursina_mesh.py | 12 ++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index 2982354..31a6953 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -33,7 +33,7 @@ def create_name_text(parent): origin=(0, 0)) name_text.background.color = color.rgba(b_color[0], b_color[1], b_color[2], 0.3) name_text.resolution = 24 - # self.name_text.scale = self.scale + # parent.name_text.scale = parent.scale if text_color is None: text_color = get_inverse_color(b_color) else: @@ -239,7 +239,7 @@ def create_trail_line(parent, pos): return trail -def create_rings(self): +def create_rings(parent): """ 创建行星环(使用土星贴图) @return: @@ -248,34 +248,34 @@ def create_rings(self): rings_texture = find_file(rings_texture) # 行星环偏移角度 - # self.ring_rotation_x = 80 + # parent.ring_rotation_x = 80 # 创建行星环 - # self.ring = Entity(parent=self.planet, model='circle', texture=rings_texture, scale=3.5, - # rotation=(self.ring_rotation_x, 0, 0), double_sided=True) + # parent.ring = Entity(parent=parent.planet, model='circle', texture=rings_texture, scale=3.5, + # rotation=(parent.ring_rotation_x, 0, 0), double_sided=True) # 行星环偏移角度 - self.ring_rotation_x = 80 + parent.ring_rotation_x = 80 # 创建行星环 torus = create_torus(0.7, 1.2, 64) - self.ring = Entity(parent=self, model=torus, texture=rings_texture, scale=1, - rotation=(self.ring_rotation_x, 0, 0), double_sided=True) + parent.ring = Entity(parent=parent, model=torus, texture=rings_texture, scale=1, + rotation=(parent.ring_rotation_x, 0, 0), double_sided=True) # 设置行星环不受灯光影响,否则看不清行星环 - self.ring.set_light_off() + parent.ring.set_light_off() -def clear_trails(self): +def clear_trails(parent): """ - @param self: + @param parent: @return: """ - if not hasattr(self, "trails"): + if not hasattr(parent, "trails"): return # 删除拖尾 - for entity, pos in self.trails.items(): + for entity, pos in parent.trails.items(): destroy(entity) - self.trails.clear() + parent.trails.clear() def create_fixed_star_lights(fixed_star): diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index 644512d..825bee8 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -109,6 +109,18 @@ def create_line(from_pos, to_pos, parent=None, alpha=1.0, len_scale=1, set_light return line +def create_circle(parent=None, pos=Vec3(0, 0, 0), thickness=1, scale=1, color=color.white, alpha=1): + circle = Entity(parent=parent, model="circle", thickness=thickness, scale=scale, position=pos, + color=color, alpha=alpha) + return circle + + +def create_circle_line(parent=None, pos=Vec3(0, 0, 0), thickness=1, scale=1, color=color.white, alpha=1): + circle = Entity(parent=parent, model="circle", thickness=thickness, scale=scale, position=pos, + color=color, alpha=alpha) + return circle + + def create_arrow_line(from_pos, to_pos, parent=None, label=None, set_light_off=True, alpha=1.0, len_scale=0.5, color=color.white, thickness=2, -- GitLab