Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
58a6255b
宇宙模拟器
项目概览
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看板
提交
58a6255b
编写于
8月 04, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
91524f90
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
75 addition
and
15 deletion
+75
-15
objs/water_drop.py
objs/water_drop.py
+49
-0
sim_scenes/solar_system/solar_system_reality.py
sim_scenes/solar_system/solar_system_reality.py
+3
-0
sim_scenes/tri_bodies/water_drop_01.py
sim_scenes/tri_bodies/water_drop_01.py
+21
-13
simulators/ursina/ui/ui_panel.py
simulators/ursina/ui/ui_panel.py
+2
-2
未找到文件。
objs/water_drop.py
浏览文件 @
58a6255b
...
@@ -43,8 +43,56 @@ class WaterDrop(Obj):
...
@@ -43,8 +43,56 @@ class WaterDrop(Obj):
}
}
super
().
__init__
(
**
params
)
super
().
__init__
(
**
params
)
from
ursina.prefabs.primitives
import
Shader
matcap_shader
=
Shader
(
name
=
'matcap_shader'
,
language
=
Shader
.
GLSL
,
vertex
=
'''#version 140
uniform mat4 p3d_ModelViewProjectionMatrix;
uniform mat4 p3d_ModelMatrix;
uniform mat4 p3d_ModelViewMatrix;
uniform mat3 p3d_NormalMatrix;
in vec4 p3d_Vertex;
in vec3 p3d_Normal;
out vec3 eye;
out vec3 view_normal;
// reflect alternative:
// r = e - 2. * dot( n, e ) * n;
void main() {
gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
eye = normalize(vec3(p3d_ModelViewMatrix * vec4(p3d_Vertex.xyz, 1.0)));
view_normal = normalize( p3d_NormalMatrix * p3d_Normal );
}
'''
,
fragment
=
'''
#version 130
uniform sampler2D p3d_Texture0;
uniform vec4 p3d_ColorScale;
in vec3 eye;
in vec3 view_normal;
out vec4 fragColor;
void main() {
vec3 r = reflect( eye, view_normal );
float m = 2. * sqrt( pow( r.x, 2. ) + pow( r.y, 2. ) + pow( r.z + 1., 2. ) );
vec2 vN = r.xy / m + .5;
vec3 base = texture2D( p3d_Texture0, vN ).rgb;
// vec3 base = texture2D( p3d_Texture0, uv ).rgb;
fragColor = vec4( base, 1. ) * p3d_ColorScale;
}
'''
,
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
shader
=
matcap_shader
water_drop
=
WaterDrop
(
water_drop
=
WaterDrop
(
# texture="drops_normal.png"
# texture="drops_normal.png"
# texture="drops_uvw.png"
# texture="drops_uvw.png"
...
@@ -56,6 +104,7 @@ if __name__ == '__main__':
...
@@ -56,6 +104,7 @@ if __name__ == '__main__':
def
on_ready
():
def
on_ready
():
water_drop
.
planet
.
rotation_x
=
90
water_drop
.
planet
.
rotation_x
=
90
water_drop
.
planet
.
shader
=
shader
,
water_drop
.
show_demo
(
size_scale
=
1000000
,
on_ready_fun
=
on_ready
)
water_drop
.
show_demo
(
size_scale
=
1000000
,
on_ready_fun
=
on_ready
)
sim_scenes/solar_system/solar_system_reality.py
浏览文件 @
58a6255b
...
@@ -250,6 +250,8 @@ if __name__ == '__main__':
...
@@ -250,6 +250,8 @@ if __name__ == '__main__':
# print(time_data.get_datetime(str(current_time)))
# print(time_data.get_datetime(str(current_time)))
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
position
=
(
0.60
,
-
0.465
),
origin
=
(
-
0.5
,
0.5
),
font
=
"verdana.ttf"
,
font
=
"verdana.ttf"
,
close_time
=-
1
)
close_time
=-
1
)
...
@@ -267,4 +269,5 @@ if __name__ == '__main__':
...
@@ -267,4 +269,5 @@ if __name__ == '__main__':
position
=
(
0
,
0.2
*
AU
,
-
3
*
AU
),
position
=
(
0
,
0.2
*
AU
,
-
3
*
AU
),
gravity_works
=
False
,
# 关闭万有引力的计算
gravity_works
=
False
,
# 关闭万有引力的计算
show_grid
=
False
,
show_grid
=
False
,
show_camera_info
=
False
,
timer_enabled
=
True
)
timer_enabled
=
True
)
sim_scenes/tri_bodies/water_drop_01.py
浏览文件 @
58a6255b
...
@@ -16,6 +16,7 @@ from simulators.ursina.entities.body_timer import TimeData
...
@@ -16,6 +16,7 @@ from simulators.ursina.entities.body_timer import TimeData
from
simulators.ursina.entities.entity_utils
import
create_directional_light
from
simulators.ursina.entities.entity_utils
import
create_directional_light
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
camera
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
"""
"""
...
@@ -45,7 +46,9 @@ if __name__ == '__main__':
...
@@ -45,7 +46,9 @@ if __name__ == '__main__':
texture
=
"drops_bright.png"
,
texture
=
"drops_bright.png"
,
# trail_color=[200, 200, 255],
# trail_color=[200, 200, 255],
init_velocity
=
[
-
WATER_SPEED
,
0
,
0
],
init_velocity
=
[
-
WATER_SPEED
,
0
,
0
],
size_scale
=
4e4
).
set_ignore_gravity
(
True
).
set_light_disable
(
True
)
# size_scale=4e4,
size_scale
=
1e3
).
set_ignore_gravity
(
True
).
set_light_disable
(
True
)
# moon = Moon(init_position=[0, 0, 363104], # 距地距离约: 363104 至 405696 km
# moon = Moon(init_position=[0, 0, 363104], # 距地距离约: 363104 至 405696 km
# init_velocity=[-1.03, 0, 0], size_scale=2e1) # 月球放大 10 倍,距离保持不变
# init_velocity=[-1.03, 0, 0], size_scale=2e1) # 月球放大 10 倍,距离保持不变
# moon.set_light_disable(True)
# moon.set_light_disable(True)
...
@@ -88,15 +91,18 @@ if __name__ == '__main__':
...
@@ -88,15 +91,18 @@ if __name__ == '__main__':
def
on_timer_changed
(
time_data
:
TimeData
):
def
on_timer_changed
(
time_data
:
TimeData
):
if
time_data
.
total_days
>
27.5
:
if
time_data
.
total_days
>
0.2
:
exit
(
0
)
if
water_drop
.
position
[
0
]
<
-
WATER_RANGE
:
if
water_drop
.
position
[
0
]
<
-
WATER_RANGE
:
water_drop
.
planet
.
rotation_z
=
-
90
water_drop
.
planet
.
rotation_z
=
-
90
water_drop
.
velocity
=
[
WATER_SPEED
,
0
,
0
]
water_drop
.
velocity
=
[
WATER_SPEED
,
0
,
0
]
elif
water_drop
.
position
[
0
]
>
WATER_RANGE
:
elif
water_drop
.
position
[
0
]
>
WATER_RANGE
:
water_drop
.
planet
.
rotation_z
=
90
water_drop
.
planet
.
rotation_z
=
90
water_drop
.
velocity
=
[
-
WATER_SPEED
,
0
,
0
]
water_drop
.
velocity
=
[
-
WATER_SPEED
,
0
,
0
]
else
:
# camera_look_at(water_drop, rotation_z=0)
water_drop
.
acceleration
=
[
-
9.8e-4
,
0
,
0
]
camera_look_at
(
water_drop
,
rotation_z
=
0
)
# camera.y += UrsinaConfig.SCALE_FACTOR * 100
def
on_ready
():
def
on_ready
():
...
@@ -110,8 +116,8 @@ if __name__ == '__main__':
...
@@ -110,8 +116,8 @@ if __name__ == '__main__':
water_drop
.
planet
.
rotation_z
=
90
water_drop
.
planet
.
rotation_z
=
90
#
water_drop.init_position = (0, 0, 0)
water_drop
.
init_position
=
(
0
,
0
,
0
)
#
water_drop.init_velocity = [0, 0, 0]
water_drop
.
init_velocity
=
[
0
,
0
,
0
]
# 订阅事件后,上面2个函数功能才会起作用
# 订阅事件后,上面2个函数功能才会起作用
...
@@ -127,11 +133,13 @@ if __name__ == '__main__':
...
@@ -127,11 +133,13 @@ if __name__ == '__main__':
SECONDS_PER_DAY
/
24
,
SECONDS_PER_DAY
/
24
,
# SECONDS_PER_WEEK * 4,
# SECONDS_PER_WEEK * 4,
# position=(0, 0, -220000),
# position=(0, 0, -220000),
position
=
(
0
,
0
,
0
),
position
=
(
0
,
0
,
-
20000
),
# position=(0, 0, 0),
show_grid
=
False
,
show_grid
=
False
,
# cosmic_bg="",
# cosmic_bg="",
# gravity_works=False,
# gravity_works=False,
# save_cube_map=True,
# save_cube_map=True,
show_timer
=
True
,
timer_enabled
=
True
,
timer_enabled
=
True
,
show_camera_info
=
False
,
show_camera_info
=
False
,
show_control_info
=
False
,
show_control_info
=
False
,
...
...
simulators/ursina/ui/ui_panel.py
浏览文件 @
58a6255b
...
@@ -63,7 +63,7 @@ class UiPanel(WindowPanel):
...
@@ -63,7 +63,7 @@ class UiPanel(WindowPanel):
"""
"""
pass
pass
def
show_message
(
self
,
message
,
font
=
None
,
close_time
=
3
):
def
show_message
(
self
,
message
,
font
=
None
,
origin
=
(
0
,
0
),
position
=
(
0
,
.
25
),
close_time
=
3
):
"""
"""
显示消息框
显示消息框
@param message: 消息内容
@param message: 消息内容
...
@@ -78,7 +78,7 @@ class UiPanel(WindowPanel):
...
@@ -78,7 +78,7 @@ class UiPanel(WindowPanel):
# else:
# else:
# font = None
# font = None
# 创建消息框
# 创建消息框
message_box
=
Text
(
text
=
message
,
font
=
font
,
background
=
True
,
origin
=
(
0
,
0
),
y
=
.
25
)
message_box
=
Text
(
text
=
message
,
font
=
font
,
background
=
True
,
origin
=
origin
,
position
=
position
)
self
.
last_message_box
=
message_box
self
.
last_message_box
=
message_box
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录