From 646157eef0a92f9dd9b974ff9de8fda089f26ac2 Mon Sep 17 00:00:00 2001 From: march3 Date: Sat, 11 Mar 2023 17:45:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E7=B3=BB=E4=B8=89=E4=BD=93?= =?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 --- scenes/func.py | 9 +++++++-- simulators/ursina_simulator.py | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scenes/func.py b/scenes/func.py index 9034a02..6553a72 100644 --- a/scenes/func.py +++ b/scenes/func.py @@ -52,7 +52,12 @@ def mayavi_run(bodies, dt=SECONDS_PER_WEEK, mlab.show() -def ursina_run(bodies, dt=SECONDS_PER_HALF_DAY, position=(4000000, 800000000, 4000000), light=True, cosmic_bg=None): +def ursina_run(bodies, + dt=SECONDS_PER_HALF_DAY, + position=(4000000, 800000000, 4000000), + light=True, + cosmic_bg=None, + show_grid=True): """ :param bodies: @@ -75,7 +80,7 @@ def ursina_run(bodies, dt=SECONDS_PER_HALF_DAY, position=(4000000, 800000000, 40 import sys sys.modules["__main__"].update = callback_update - simulator.run(dt, light=light, cosmic_bg=cosmic_bg) + simulator.run(dt, light=light, cosmic_bg=cosmic_bg, show_grid=show_grid) def mpl_run(bodies, dt=SECONDS_PER_WEEK, gif_file_name=None, gif_max_frame=200): diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index b692374..f9cd3d3 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -7,7 +7,7 @@ # python_version :3.8 # ============================================================================== # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina -from ursina import Ursina, window, Entity, camera, color, mouse, Vec2, Vec3, load_texture, held_keys +from ursina import Ursina, window, Entity, Grid, Mesh, camera, color, mouse, Vec2, Vec3, load_texture, held_keys from ursina.prefabs.first_person_controller import FirstPersonController from simulators.views.ursina_view import UrsinaView, UrsinaPlayer @@ -20,6 +20,19 @@ from ursina import EditorCamera, PointLight, SpotLight, AmbientLight from scenes.func import ursina_run +class WorldGrid(Entity): # Entity # 定义构造方法 + def __init__(self): + super().__init__() + s = 100 + grid = Entity(model=Grid(s, s), scale=s * 20, color=color.color(0, 0, .1, 1), rotation_x=90, + position=(0, -80, 0)) + vertsx = ((0, 0, 0), (10, 0, 0)) + Entity(model=Mesh(vertices=vertsx, mode='line', thickness=3), color=color.cyan).set_light_off() + vertsyz = [(0, 0, 0), (0, 10, 0), (0, 0, 0), (0, 0, 10)] + Entity(model=Mesh(vertices=vertsyz, mode='line', thickness=3), color=color.yellow).set_light_off() + grid.set_light_off() + + class UrsinaSimulator(Simulator): def __init__(self, bodies_sys: System): self.app = Ursina() @@ -83,6 +96,10 @@ class UrsinaSimulator(Simulator): # DirectionalLight # SpotLight + if "show_grid" in kwargs: + if kwargs["show_grid"]: + WorldGrid() + if "cosmic_bg" in kwargs: cosmic_bg = kwargs["cosmic_bg"] if cosmic_bg is None: @@ -140,4 +157,4 @@ if __name__ == '__main__': Pluto(size_scale=10e3, distance_scale=0.23), # 冥王星放大 10000 倍,距离缩小到真实距离的 0.23(从太阳系的行星中排除) ] - ursina_run(bodies, SECONDS_PER_DAY, position=(AU * 2, AU * 2, AU * 3)) + ursina_run(bodies, SECONDS_PER_DAY, position=(AU * 2, AU * 2, AU * 3), show_grid=True) -- GitLab