From 0ad66e87045bc6c400f239a53533490ea6587bc6 Mon Sep 17 00:00:00 2001 From: march3 Date: Tue, 2 May 2023 15:31:24 +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/wonders/comets_jupiter.py | 2 +- simulators/ursina/entities/entity_utils.py | 23 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/sim_scenes/wonders/comets_jupiter.py b/sim_scenes/wonders/comets_jupiter.py index 8f475dd..504d9be 100644 --- a/sim_scenes/wonders/comets_jupiter.py +++ b/sim_scenes/wonders/comets_jupiter.py @@ -88,7 +88,7 @@ if __name__ == '__main__': def on_ready(): # 运行前触发 # 为了较好的立体效果,可以增加太阳光线,光线指向木星(target=jupiter) - create_directional_light(position=(200, 0, -300), target=jupiter) + create_directional_light(position=(200, 0, -300), light_num=3, target=jupiter) # 摄像机看向木星 camera_look_at(jupiter, rotation_z=0) diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index ccd6f41..2982354 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -167,7 +167,7 @@ def create_trail_sphere(parent, pos): # return value, direction -def create_directional_light(position, target=None, shadows=False, light_color=None): +def create_directional_light(position, target=None, shadows=False, light_num=1, light_color=None): """ 创建平行光(DirectionalLight) @param position: 光源位置 @@ -194,19 +194,24 @@ def create_directional_light(position, target=None, shadows=False, light_color=N else: light_color = color.rgba(light_color[0] / 255, light_color[1] / 255, light_color[2] / 255, 1) - light = DirectionalLight(position=position, intensity=10, range=10, color=light_color) + lights = [] + for i in range(light_num): + light = DirectionalLight(position=position, intensity=10, range=10, color=light_color) + lights.append(light) if shadows: - light.shadows = lit_with_shadows_shader + for light in lights: + light.shadows = lit_with_shadows_shader if target is not None: - if hasattr(target, "planet"): - if hasattr(target.planet, "main_entity"): - light.look_at(target.planet.main_entity) + for light in lights: + if hasattr(target, "planet"): + if hasattr(target.planet, "main_entity"): + light.look_at(target.planet.main_entity) + else: + light.look_at(target.planet) else: - light.look_at(target.planet) - else: - light.look_at(target) + light.look_at(target) if shadows: return lit_with_shadows_shader -- GitLab