diff --git a/common/color_utils.py b/common/color_utils.py index 62e2c8b352a95163ca5739c646678fb7ade833aa..7c9cfe018b10935b4ab8831f1e2b413a998264b9 100644 --- a/common/color_utils.py +++ b/common/color_utils.py @@ -34,6 +34,15 @@ def conv_to_vec4_color(colour: tuple, alpha=1): # color = ursina_color.rgba(r, g, b, a) +def white_brightest(color, min_value=220): + # x = y/255*(255-min_value) + min_value + r, g, b = color + r = min(255, int(r / 255 * (255 - min_value) + min_value)) + g = min(255, int(g / 255 * (255 - min_value) + min_value)) + b = min(255, int(b / 255 * (255 - min_value) + min_value)) + return r, g, b + + def brightest(color): if isinstance(color, tuple): r, g, b = color @@ -51,6 +60,28 @@ def brightest(color): return [r, g, b] +def fixed_star_color_brightest(c, ursina_color=False): + if c is None: + bc = (255, 255, 255) + else: + bc = white_brightest(c) + + if ursina_color: + return conv_to_vec4_color(bc) + return bc + + +def brightest_color(c, ursina_color=False): + if c is None: + bc = (255, 255, 255) + else: + bc = brightest(c) + + if ursina_color: + return conv_to_vec4_color(bc) + return bc + + def trail_color_brightest(bodies): """ 天体尾巴最亮 diff --git a/sim_scenes/solar_system/solar_system_reality.py b/sim_scenes/solar_system/solar_system_reality.py index b351c5d3eb7f7483f65090db7408a79d748e3e2c..41f6545d2b0de525977b78ded46ee379b89ed641 100644 --- a/sim_scenes/solar_system/solar_system_reality.py +++ b/sim_scenes/solar_system/solar_system_reality.py @@ -192,7 +192,7 @@ class SolarSystemRealitySim: # 创建太阳系天体 self.create_bodies() # glows = (glow_num:10, glow_scale:1.03 glow_alpha:0.1~1) - self.sun.glows = (80, 1.005, 0.01) + self.sun.glows = (4, 1.005, 0.1) # 对地球进行初始化 self.init_earth() diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index c8d28bc708ff549de978a4cf8b3a6c519289e02a..9f99db90a596ce068cf76980458e1e5288a75085 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -11,10 +11,12 @@ from ursina import Ursina, window, Entity, Mesh, SmoothFollow, Texture, clamp, t camera, color, mouse, Vec2, Vec3, Vec4, Text, \ load_texture, held_keys, destroy, PointLight, DirectionalLight, distance +from common import color_utils +from common.image_utils import find_texture from simulators.ursina.entities.body_trail import BodyTrail, BodyTrailLine from simulators.ursina.ursina_config import UrsinaConfig from common.color_utils import adjust_brightness, conv_to_vec4_color, get_inverse_color -from simulators.ursina.ursina_mesh import create_torus +from simulators.ursina.ursina_mesh import create_torus, create_circle from common.func import find_file import math import numpy as np @@ -356,10 +358,24 @@ def create_fixed_star_lights(fixed_star): # _color = color.white _color = fixed_star.body_view.body.color + _color = color.rgba(_color[0] / 255, _color[1] / 255, _color[2] / 255, 1) for i in range(glow_num): glow_entity = Entity(parent=fixed_star, model='sphere', color=_color, scale=math.pow(glow_scale, i + 1), alpha=glow_alpha) + if glow_num < 5: + bright_color = color_utils.fixed_star_color_brightest(fixed_star.body_view.body.color, True) + glow_circle = create_circle(parent=None, pos=fixed_star.position, scale=fixed_star.scale * 1.8) + glow_circle.texture = find_texture("fixed_star_glow.png") + glow_circle.color = bright_color + glow_circle.set_light_off(True) + + def glow_circle_update(): + # from ursina import camera + glow_circle.look_at(camera) + + glow_circle.update = glow_circle_update + if hasattr(fixed_star.body_view.body, "light_on"): if fixed_star.body_view.body.light_on: for i in range(2): diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index 2fc403d2eb92e964f8f0ca544ad161d4d5e3dbc2..f94c63b3d0e2161e30b878d2d4155d2c02c21a0f 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -473,7 +473,7 @@ def create_line(from_pos, to_pos, parent=None, alpha=1.0, len_scale=1, set_light 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) + color=color, alpha=alpha, double_sided=True) return circle diff --git a/textures/fixed_star_glow.png b/textures/fixed_star_glow.png new file mode 100644 index 0000000000000000000000000000000000000000..fc8f051ffb16d7846806d4a530b8bc4fbdf4095c Binary files /dev/null and b/textures/fixed_star_glow.png differ