Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
bd596248
宇宙模拟器
项目概览
Python_超人
/
宇宙模拟器
通知
19
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
宇宙模拟器
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
bd596248
编写于
10月 29, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
124a3b58
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
123 addition
and
8 deletion
+123
-8
objs/halley_comet.py
objs/halley_comet.py
+4
-1
objs/textures/comet.jpg
objs/textures/comet.jpg
+0
-0
objs/textures/comet_trail.png
objs/textures/comet_trail.png
+0
-0
sim_scenes/solar_system/halley_comet_sim.py
sim_scenes/solar_system/halley_comet_sim.py
+3
-2
sim_scenes/solar_system/halley_comet_sim_02.py
sim_scenes/solar_system/halley_comet_sim_02.py
+4
-2
sim_scenes/solar_system/halley_comet_sim_03.py
sim_scenes/solar_system/halley_comet_sim_03.py
+4
-2
simulators/ursina/entities/planet.py
simulators/ursina/entities/planet.py
+17
-1
simulators/ursina/ursina_mesh.py
simulators/ursina/ursina_mesh.py
+91
-0
未找到文件。
objs/halley_comet.py
浏览文件 @
bd596248
...
@@ -25,7 +25,7 @@ class HalleComet(RockSnow):
...
@@ -25,7 +25,7 @@ class HalleComet(RockSnow):
init_position
=
[
0
,
0
,
0
],
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
1.0
,
distance_scale
=
1.0
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
255
,
255
,
255
),
trail_color
=
None
,
show_name
=
False
,
trail_color
=
None
,
show_name
=
False
,
rotation
=
(
0
,
0
,
0
),
rotation
=
(
0
,
0
,
0
),
parent
=
None
,
gravity_only_for
=
[]):
parent
=
None
,
gravity_only_for
=
[]):
...
@@ -37,6 +37,7 @@ class HalleComet(RockSnow):
...
@@ -37,6 +37,7 @@ class HalleComet(RockSnow):
"density"
:
density
,
"density"
:
density
,
"color"
:
color
,
"color"
:
color
,
"size_scale"
:
size_scale
,
"size_scale"
:
size_scale
,
"texture"
:
"comet.jpg"
,
"distance_scale"
:
distance_scale
,
"distance_scale"
:
distance_scale
,
"ignore_mass"
:
ignore_mass
,
"ignore_mass"
:
ignore_mass
,
"trail_color"
:
trail_color
,
"trail_color"
:
trail_color
,
...
@@ -46,6 +47,8 @@ class HalleComet(RockSnow):
...
@@ -46,6 +47,8 @@ class HalleComet(RockSnow):
"gravity_only_for"
:
gravity_only_for
,
"gravity_only_for"
:
gravity_only_for
,
}
}
super
().
__init__
(
**
params
)
super
().
__init__
(
**
params
)
# create_cone(radius, height, subdivisions, r=0.1)
self
.
comet_info
=
(
0.18
,
1.5
,
100
,
0.2
)
from
ursina.prefabs.primitives
import
Shader
from
ursina.prefabs.primitives
import
Shader
...
...
objs/textures/comet.jpg
0 → 100644
浏览文件 @
bd596248
315.8 KB
objs/textures/comet_trail.png
0 → 100644
浏览文件 @
bd596248
432.3 KB
sim_scenes/solar_system/halley_comet_sim.py
浏览文件 @
bd596248
...
@@ -116,8 +116,9 @@ class HalleyCometSim:
...
@@ -116,8 +116,9 @@ class HalleyCometSim:
"""
"""
# 哈雷彗星飞行的翻转效果
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
# self.halley_comet.planet.rotation_x += 0.1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
# self.halley_comet.planet.rotation_y += 1
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
# 摄像机始终看向哈雷彗星
# 摄像机始终看向哈雷彗星
# camera_look_at(self.halley_comet)
# camera_look_at(self.halley_comet)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
...
...
sim_scenes/solar_system/halley_comet_sim_02.py
浏览文件 @
bd596248
...
@@ -145,8 +145,10 @@ class HalleyCometSim:
...
@@ -145,8 +145,10 @@ class HalleyCometSim:
if
hasattr
(
self
,
"halley_comet"
):
if
hasattr
(
self
,
"halley_comet"
):
# 哈雷彗星飞行的翻转效果
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
# self.halley_comet.planet.rotation_x += 0.1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
# self.halley_comet.planet.rotation_y += 1
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
self
.
text_panel
.
text
=
"哈雷彗星距离太阳:%.3f AU"
%
(
d
/
AU
)
self
.
text_panel
.
text
=
"哈雷彗星距离太阳:%.3f AU"
%
(
d
/
AU
)
...
...
sim_scenes/solar_system/halley_comet_sim_03.py
浏览文件 @
bd596248
...
@@ -191,8 +191,10 @@ class HalleyCometSim:
...
@@ -191,8 +191,10 @@ class HalleyCometSim:
if
hasattr
(
self
,
"halley_comet"
):
if
hasattr
(
self
,
"halley_comet"
):
# 哈雷彗星飞行的翻转效果
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
# self.halley_comet.planet.rotation_x += 0.1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
# self.halley_comet.planet.rotation_y += 1
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
...
...
simulators/ursina/entities/planet.py
浏览文件 @
bd596248
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
# 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
from
ursina
import
application
,
Entity
,
camera
,
color
,
Vec3
,
Text
,
load_texture
,
destroy
,
PointLight
from
common.image_utils
import
find_texture
from
simulators.ursina.entities.entity_utils
import
create_name_text
,
create_trails
,
clear_trails
,
create_rings
,
\
from
simulators.ursina.entities.entity_utils
import
create_name_text
,
create_trails
,
clear_trails
,
create_rings
,
\
trail_init
,
create_fixed_star_lights
trail_init
,
create_fixed_star_lights
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
...
@@ -16,7 +17,8 @@ from simulators.ursina.ursina_event import UrsinaEvent
...
@@ -16,7 +17,8 @@ from simulators.ursina.ursina_event import UrsinaEvent
from
common.color_utils
import
adjust_brightness
,
conv_to_vec4_color
,
get_inverse_color
from
common.color_utils
import
adjust_brightness
,
conv_to_vec4_color
,
get_inverse_color
from
common.func
import
find_file
from
common.func
import
find_file
from
simulators.views.body_view
import
BodyView
from
simulators.views.body_view
import
BodyView
from
simulators.ursina.ursina_mesh
import
create_sphere
,
create_torus
,
create_arrow_line
,
create_line
,
create_label
from
simulators.ursina.ursina_mesh
import
create_sphere
,
create_torus
,
create_arrow_line
,
create_line
,
create_label
,
\
create_cone
import
math
import
math
...
@@ -168,6 +170,9 @@ class Planet(Entity):
...
@@ -168,6 +170,9 @@ class Planet(Entity):
# 如果是非恒星,并且禁用灯光
# 如果是非恒星,并且禁用灯光
self
.
set_light_off
()
self
.
set_light_off
()
if
hasattr
(
self
.
body
,
"comet_info"
):
self
.
create_comet_trail
(
self
.
body
.
comet_info
)
if
self
.
body
.
show_name
:
if
self
.
body
.
show_name
:
create_name_text
(
self
)
create_name_text
(
self
)
...
@@ -176,6 +181,17 @@ class Planet(Entity):
...
@@ -176,6 +181,17 @@ class Planet(Entity):
# 创建行星环(目前只有土星环)
# 创建行星环(目前只有土星环)
create_rings
(
self
)
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
)
texture
=
find_texture
(
"comet_trail.png"
)
self
.
comet_trail
=
Entity
(
parent
=
self
,
model
=
cone
,
texture
=
texture
,
scale
=
20
,
position
=
(
0
,
0
,
0
),
rotation
=
(
0
,
90
,
90
),
double_sided
=
True
,
alpha
=
0.8
)
# 设置行星环不受灯光影响,否则看不清行星环
self
.
comet_trail
.
set_light_off
()
def
create_rotate_entity
(
self
):
def
create_rotate_entity
(
self
):
"""
"""
...
...
simulators/ursina/ursina_mesh.py
浏览文件 @
bd596248
...
@@ -69,6 +69,97 @@ def create_sphere(radius, subdivisions):
...
@@ -69,6 +69,97 @@ def create_sphere(radius, subdivisions):
return
Mesh
(
vertices
=
verts
,
triangles
=
tris
,
normals
=
normals
,
uvs
=
uvs
,
mode
=
'triangle'
)
return
Mesh
(
vertices
=
verts
,
triangles
=
tris
,
normals
=
normals
,
uvs
=
uvs
,
mode
=
'triangle'
)
def
create_cone
(
radius
,
height
,
subdivisions
,
r
=
0.1
):
"""
创建一个圆锥
@param radius: 圆锥底部的半径
@param height: 圆锥的高度
@param subdivisions: 细分数,用于控制圆锥的光滑度
@return: Mesh对象,表示创建的圆锥
"""
verts
=
[]
# 顶点列表
tris
=
[]
# 三角面索引列表
normals
=
[]
# 法线列表
uvs
=
[]
# UV坐标列表
p_h
=
r
*
height
d_h
=
(
1
-
r
)
*
height
# 生成圆锥底部的顶点和UV坐标
for
i
in
range
(
subdivisions
):
angle
=
2
*
math
.
pi
*
i
/
subdivisions
x
=
radius
*
math
.
cos
(
angle
)
z
=
radius
*
math
.
sin
(
angle
)
verts
.
append
(
Vec3
(
x
,
d_h
,
z
))
uvs
.
append
(
Vec2
(
i
/
subdivisions
,
0
))
# 圆锥尖端的顶点
verts
.
append
(
Vec3
(
0
,
-
p_h
,
0
))
uvs
.
append
(
Vec2
(
0.5
,
1
))
# 生成圆锥侧面的顶点、法线和三角面
for
i
in
range
(
subdivisions
):
p1
=
verts
[
i
]
p2
=
verts
[(
i
+
1
)
%
subdivisions
]
# 侧面三角形
tris
.
append
((
i
,
(
i
+
1
)
%
subdivisions
,
subdivisions
))
# 侧面法线
normal
=
Vec3
(
0
,
1
,
0
).
cross
(
p2
-
p1
).
normalized
()
normals
.
append
(
normal
)
return
Mesh
(
vertices
=
verts
,
triangles
=
tris
,
normals
=
normals
,
uvs
=
uvs
,
mode
=
'triangle'
)
def
create_cylinder
(
radius
,
height
,
subdivisions
):
"""
创建一个圆柱体
@param radius: 圆柱体的底部半径
@param height:圆柱体的高度
@param subdivisions: 细分数,用于控制圆柱体的光滑度
@return: Mesh对象,表示创建的圆柱体
"""
# 生成圆锥的顶点、UV坐标uvs、法线normals和三角面tris
verts
=
[]
tris
=
[]
normals
=
[]
uvs
=
[]
# 生成底面顶点和法线
verts
.
append
(
Vec3
(
0
,
0
,
0
))
normals
.
append
(
Vec3
(
0
,
-
1
,
0
))
for
x
in
range
(
subdivisions
+
1
):
angle
=
x
/
subdivisions
*
2
*
pi
x_pos
=
cos
(
angle
)
*
radius
z_pos
=
sin
(
angle
)
*
radius
verts
.
append
(
Vec3
(
x_pos
,
0
,
z_pos
))
normals
.
append
(
Vec3
(
0
,
-
1
,
0
))
# 生成侧面顶点、法线和纹理坐标
for
y
in
range
(
subdivisions
+
1
):
for
x
in
range
(
subdivisions
+
1
):
angle
=
x
/
subdivisions
*
2
*
pi
x_pos
=
cos
(
angle
)
*
radius
*
(
1
-
y
/
subdivisions
)
y_pos
=
-
height
+
(
y
/
subdivisions
)
*
height
z_pos
=
sin
(
angle
)
*
radius
*
(
1
-
y
/
subdivisions
)
verts
.
append
(
Vec3
(
x_pos
,
y_pos
,
z_pos
))
normals
.
append
(
Vec3
(
cos
(
angle
),
radius
/
height
,
sin
(
angle
)))
uvs
.
append
(
Vec2
(
x
/
subdivisions
,
y
/
subdivisions
))
# 生成底面三角面
for
x
in
range
(
subdivisions
):
tris
.
append
((
0
,
x
+
2
,
x
+
1
))
# 生成侧面三角面
for
y
in
range
(
subdivisions
):
for
x
in
range
(
subdivisions
):
first
=
(
y
*
(
subdivisions
+
1
))
+
x
+
1
second
=
first
+
subdivisions
+
1
tris
.
append
((
first
,
second
,
first
+
1
))
tris
.
append
((
second
,
second
+
1
,
first
+
1
))
return
Mesh
(
vertices
=
verts
,
triangles
=
tris
,
normals
=
normals
,
uvs
=
uvs
,
mode
=
'triangle'
)
def
create_arrow
(
height
=
0.5
,
width
=
0.1
):
def
create_arrow
(
height
=
0.5
,
width
=
0.1
):
# 创建金字塔的顶点
# 创建金字塔的顶点
r
=
width
/
2
r
=
width
/
2
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录