diff --git a/objs/halley_comet.py b/objs/halley_comet.py index 1f59108d3feb18293b0b179ab058e203535de07d..abb58184909dc9ad30c06ee1653da9ad95302aa9 100644 --- a/objs/halley_comet.py +++ b/objs/halley_comet.py @@ -49,7 +49,8 @@ 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.18, 2.0, 100, 0.2) + self.comet_info = (0.03, 0.18, 1.5, 100) from ursina.prefabs.primitives import Shader diff --git a/objs/textures/comet_trail.png b/objs/textures/comet_trail.png index b4f5d46dff833a367f172bec9cf77fe6327f966f..7d4c7c42eec6cedb0c186b900c840de0afcfa6b6 100644 Binary files a/objs/textures/comet_trail.png and b/objs/textures/comet_trail.png differ diff --git a/simulators/ursina/entities/planet.py b/simulators/ursina/entities/planet.py index 7cf38e5a1f82314f998850c9287da11e9e86e0e4..5743279b0f0de17a402762640b513a83ba0f821a 100644 --- a/simulators/ursina/entities/planet.py +++ b/simulators/ursina/entities/planet.py @@ -18,7 +18,7 @@ from common.color_utils import adjust_brightness, conv_to_vec4_color, get_invers from common.func import find_file from simulators.views.body_view import BodyView from simulators.ursina.ursina_mesh import create_sphere, create_torus, create_arrow_line, create_line, create_label, \ - create_cone + create_cone, create_frustum import math @@ -182,10 +182,9 @@ class Planet(Entity): create_rings(self) def create_comet_trail(self, comet_info): - # cone = create_cone(0.25, 1.5, 100, 0.18) - cone = create_cone(*comet_info) + comet_mesh = create_frustum(*comet_info) texture = find_texture("comet_trail.png") - self.comet_trail = Entity(parent=self, model=cone, texture=texture, scale=20, + self.comet_trail = Entity(parent=self, model=comet_mesh, texture=texture, scale=20, position=(0, 0, 0), rotation=(0, 90, 90), double_sided=True, alpha=0.8) diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index 6acd1d66d66cf366a7074b61c316caec3366f883..bc88e1fefaeeee5f195862ff00c8259444bf7e4d 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -116,6 +116,62 @@ def create_cone(radius, height, subdivisions, r=0.1): return Mesh(vertices=verts, triangles=tris, normals=normals, uvs=uvs, mode='triangle') +import math + + +def create_frustum(bottom_radius, top_radius, height, subdivisions): + """ + 创建一个圆台 + @param bottom_radius: 圆台底部的半径 + @param top_radius: 圆台顶部的半径 + @param height: 圆台的高度 + @param subdivisions: 细分数,用于控制圆台的光滑度 + @return: Mesh对象,表示创建的圆台 + """ + verts = [] # 顶点列表 + tris = [] # 三角面索引列表 + normals = [] # 法线列表 + uvs = [] # UV坐标列表 + + # 生成圆台底部的顶点和UV坐标 + for i in range(subdivisions): + angle = 2 * math.pi * i / subdivisions + x = bottom_radius * math.cos(angle) + z = bottom_radius * math.sin(angle) + verts.append(Vec3(x, 0, z)) + uvs.append(Vec2(i / subdivisions, 0)) + + # 生成圆台顶部的顶点和UV坐标 + for i in range(subdivisions): + angle = 2 * math.pi * i / subdivisions + x = top_radius * math.cos(angle) + z = top_radius * math.sin(angle) + verts.append(Vec3(x, height, z)) + uvs.append(Vec2(i / subdivisions, 1)) + + # 生成圆台侧面的顶点、法线和三角面 + for i in range(subdivisions): + # 底部顶点索引 + bottom_index = i + # 顶部顶点索引 + top_index = i + subdivisions + # 下一个底部顶点索引 + next_bottom_index = (i + 1) % subdivisions + # 下一个顶部顶点索引 + next_top_index = (i + 1) % subdivisions + subdivisions + + # 侧面三角形 + tris.append((bottom_index, next_bottom_index, top_index)) + tris.append((next_bottom_index, next_top_index, top_index)) + + # 侧面法线 + normal = (verts[top_index] - verts[bottom_index]).cross( + verts[next_bottom_index] - verts[bottom_index]).normalized() + normals.append(normal) + normals.append(normal) + + return Mesh(vertices=verts, triangles=tris, normals=normals, uvs=uvs, mode='triangle') + def create_cylinder(radius, height, subdivisions): """ 创建一个圆柱体 diff --git a/textures/grid.png b/textures/grid.png new file mode 100644 index 0000000000000000000000000000000000000000..a38eca26f1c89c31cdfdec2b301d2250b3aa9f4b Binary files /dev/null and b/textures/grid.png differ diff --git a/textures/grid_r.png b/textures/grid_r.png new file mode 100644 index 0000000000000000000000000000000000000000..ecf679e5dd94b8bdf8489e2a584462cff156b041 Binary files /dev/null and b/textures/grid_r.png differ