From 19492412ecfaf964009114ac7d8c8e260797d7d1 Mon Sep 17 00:00:00 2001 From: march3 Date: Tue, 14 Nov 2023 13:12:03 +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 --- objs/halley_comet.py | 2 +- simulators/ursina/entities/planet.py | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/objs/halley_comet.py b/objs/halley_comet.py index 04478d3..c20c63d 100644 --- a/objs/halley_comet.py +++ b/objs/halley_comet.py @@ -50,7 +50,7 @@ class HalleComet(RockSnow): super().__init__(**params) # create_cone(radius, height, subdivisions, r=0.1) # self.comet_info = (0.18, 2.0, 100, 0.2) - self.comet_info = (0.07, 0.20, 2, 100) + self.comet_info = (0.07, 0.20, 2, 20) from ursina.prefabs.primitives import Shader diff --git a/simulators/ursina/entities/planet.py b/simulators/ursina/entities/planet.py index df3db86..7e31b69 100644 --- a/simulators/ursina/entities/planet.py +++ b/simulators/ursina/entities/planet.py @@ -8,7 +8,8 @@ # ============================================================================== # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina from ursina import application, Entity, camera, color, Vec3, Text, load_texture, destroy, PointLight - +import time +import random from common.image_utils import find_texture from simulators.ursina.entities.entity_utils import create_name_text, create_trails, clear_trails, create_rings, \ trail_init, create_fixed_star_lights @@ -191,7 +192,7 @@ class Planet(Entity): comet_num = 2 for i in range(1, comet_num): c = Entity(parent=self.comet_trail, model=create_comet_trail(*comet_info), - texture=texture, scale=1 + i * 0.01, + texture=texture, scale=1 + i * 0.02, position=(0, 0, 0), rotation=(0, 0, 0), double_sided=True, alpha=1) c.set_light_off() @@ -200,6 +201,11 @@ class Planet(Entity): # self.comet_sphere = Entity(parent=self, model="sphere", texture="", # color=color.white, scale=2.2, double_sided=True, alpha=0.6) def set_alpha(alpha): + """ + 设置尾巴的透明度 + @param alpha: + @return: + """ self.comet_trail.enabled = (alpha > 0.01) if self.comet_trail.enabled: self.comet_trail.alpha = alpha / 2 @@ -210,17 +216,27 @@ class Planet(Entity): # self.comet_sphere.alpha = alpha def comet_trail_update(): - import random + """ + 通过更新尾巴的旋转值,模拟尾巴的动画 + @return: + """ + if application.paused: + return + # 1秒钟更新一次,效果就可以了 + if time.time() - comet_trail_update.last_time >= 1: + comet_trail_update.last_time = time.time() + # self.comet_trail.rotation_x += 1 for c in self.comet_trail.children: c.rotation_y += (random.randint(-20, 20) / 10) self.comet_trail.set_alpha = set_alpha self.comet_trail.update = comet_trail_update - # set_alpha(0.8) + + comet_trail_update.last_time = time.time() # 设置行星环不受灯光影响,否则看不清行星环 self.comet_trail.set_light_off() - # self.comet_sphere.set_light_off() + def create_rotate_entity(self): """ -- GitLab