Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
c616a5bf
宇宙模拟器
项目概览
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看板
提交
c616a5bf
编写于
4月 22, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
faa5674c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
139 addition
and
8 deletion
+139
-8
sim_lab/__init__.py
sim_lab/__init__.py
+0
-0
sim_lab/earth_moon.py
sim_lab/earth_moon.py
+78
-0
sim_lab/light_shader.py
sim_lab/light_shader.py
+43
-0
sim_scenes/solar_system/earth_moon.py
sim_scenes/solar_system/earth_moon.py
+0
-4
sim_scenes/wonders/sun_earth_moon.py
sim_scenes/wonders/sun_earth_moon.py
+1
-1
simulators/ursina/entities/entity_utils.py
simulators/ursina/entities/entity_utils.py
+10
-0
simulators/ursina/entities/world_grid.py
simulators/ursina/entities/world_grid.py
+4
-1
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+3
-2
未找到文件。
sim_lab/__init__.py
0 → 100644
浏览文件 @
c616a5bf
sim_lab/earth_moon.py
0 → 100644
浏览文件 @
c616a5bf
# -*- coding:utf-8 -*-
# title :地月场景模拟
# description :地月场景模拟
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
Body
,
Sun
,
Earth
,
Moon
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
sim_scenes.func
import
ursina_run
,
camera_look_at
from
bodies.body
import
AU
from
simulators.ursina.entities.entity_utils
import
create_directional_light
from
simulators.ursina.ursina_event
import
UrsinaEvent
if
__name__
==
'__main__'
:
"""
地球、月球
"""
OFFSETTING
=
0
# TODO: 可以抵消月球带动地球的力,保持地球在原地
# OFFSETTING = 0.01265
bodies
=
[
Earth
(
init_position
=
[
0
,
0
,
0
],
texture
=
"earth_hd.jpg"
,
init_velocity
=
[
OFFSETTING
,
0
,
0
],
size_scale
=
0.5e1
),
# 地球放大 5 倍,距离保持不变
Moon
(
init_position
=
[
0
,
0
,
363104
],
# 距地距离约: 363104 至 405696 km
init_velocity
=
[
-
1.03
,
0
,
0
],
size_scale
=
1e1
)
# 月球放大 10 倍,距离保持不变
]
from
ursina.shaders
import
lit_with_shadows_shader
from
ursina
import
Vec2
,
Vec4
,
Entity
shader
=
lit_with_shadows_shader
shader
.
default_input
=
{
'texture_scale'
:
Vec2
(
1
,
1
),
'texture_offset'
:
Vec2
(
0
,
0
),
'shadow_color'
:
Vec4
(
0.1
,
0.1
,
0.1
,
.
5
),
}
Entity
.
default_shader
=
shader
def
on_ready
():
Entity
.
body
=
Entity
(
model
=
"sphere"
,
texture
=
'../textures/transparent.png'
,
y
=
0
,
x
=
0
,
z
=
0
,
scale
=
10
)
# 运行前触发
# 运行开始前,将摄像机指向地球
earth
=
bodies
[
0
]
moon
=
bodies
[
1
]
# 摄像机看向地球
camera_look_at
(
earth
)
e_pos
=
earth
.
planet
.
position
from
ursina.lights
import
DirectionalLight
sun
=
DirectionalLight
(
shadow_map_resolution
=
(
1024
,
1024
),
position
=
earth
.
planet
.
position
)
sun
.
look_at
(
moon
.
planet
.
position
)
sun
.
rotation_x
=
0
Entity
.
sun
=
sun
sun
.
_light
.
show_frustum
()
# 创建太阳光
shadows_shader
=
create_directional_light
(
position
=
(
200
,
0
,
-
300
),
target
=
earth
,
shadows
=
True
)
earth
.
planet
.
shadows
=
shadows_shader
moon
.
planet
.
shadows
=
shadows_shader
def
on_timer_changed
(
time_data
):
Entity
.
sun
.
update_bounds
()
# Entity.sun.update_bounds(bodies[1].planet)
pass
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_DAY
,
position
=
(
-
300000
,
1500000
,
-
1000
),
show_timer
=
True
,
show_trail
=
True
)
sim_lab/light_shader.py
0 → 100644
浏览文件 @
c616a5bf
from
ursina
import
*
from
ursina.shaders
import
lit_with_shadows_shader
from
ursina.lights
import
DirectionalLight
from
simulators.ursina.ursina_mesh
import
create_sphere
shader
=
lit_with_shadows_shader
shader
.
default_input
=
{
'texture_scale'
:
Vec2
(
1
,
1
),
'texture_offset'
:
Vec2
(
0
,
0
),
'shadow_color'
:
Vec4
(
0.1
,
0.1
,
0.1
,
.
5
),
}
Entity
.
default_shader
=
shader
app
=
Ursina
()
moon
=
Entity
(
model
=
create_sphere
(
0.5
,
32
),
texture
=
"../textures/moon.png"
,
y
=
1
,
color
=
color
.
light_gray
)
earth
=
Entity
(
model
=
create_sphere
(
0.5
,
32
),
texture
=
'../textures/earth.png'
,
y
=
1
,
x
=
1
,
z
=
3
)
e_pos
=
earth
.
position
sun
=
DirectionalLight
(
shadow_map_resolution
=
(
1024
,
1024
),
position
=
[
e_pos
[
0
],
e_pos
[
1
]
+
1
,
e_pos
[
2
]
+
1
])
sun
.
look_at
(
moon
)
sun
.
_light
.
show_frustum
()
# light = PointLight(parent=earth, intensity=10, range=10, color=color.white)
def
update
():
moon
.
x
+=
(
held_keys
[
'd'
]
-
held_keys
[
'a'
])
*
time
.
dt
moon
.
y
+=
(
held_keys
[
'e'
]
-
held_keys
[
'q'
])
*
time
.
dt
moon
.
z
+=
(
held_keys
[
'w'
]
-
held_keys
[
's'
])
*
time
.
dt
sun
.
update_bounds
()
# scene.fog_density = (100, 500)
# scene.fog_color = color.orange
# scene.fog_density = (10, 50)
Sky
(
color
=
color
.
light_gray
,
texture
=
"../textures/cosmic1.png"
)
EditorCamera
()
app
.
run
()
sim_scenes/solar_system/earth_moon.py
浏览文件 @
c616a5bf
...
...
@@ -35,10 +35,6 @@ if __name__ == '__main__':
moon
=
bodies
[
1
]
# 摄像机看向地球
camera_look_at
(
earth
)
# 创建太阳光
shadows_shader
=
create_directional_light
(
position
=
(
200
,
0
,
-
300
),
target
=
earth
,
shadows
=
True
)
earth
.
planet
.
shadows
=
shadows_shader
moon
.
planet
.
shadows
=
shadows_shader
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
...
...
sim_scenes/wonders/sun_earth_moon.py
浏览文件 @
c616a5bf
...
...
@@ -14,7 +14,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
if
__name__
==
'__main__'
:
"""
地
球、月球
地
月场景模拟
"""
# 地球的Y方向初始速度
EARTH_INIT_VELOCITY
=
0
# 0km/s
...
...
simulators/ursina/entities/entity_utils.py
浏览文件 @
c616a5bf
...
...
@@ -169,6 +169,16 @@ def create_directional_light(position, target=None, shadows=False, light_color=N
@return:
"""
from
ursina.shaders
import
lit_with_shadows_shader
from
ursina
import
Vec2
,
Vec4
,
Entity
shader
=
lit_with_shadows_shader
shader
.
default_input
=
{
'texture_scale'
:
Vec2
(
1
,
1
),
'texture_offset'
:
Vec2
(
0
,
0
),
'shadow_color'
:
Vec4
(
0.1
,
0.1
,
0.1
,
.
5
),
}
Entity
.
default_shader
=
shader
if
shadows
:
Entity
.
default_shader
=
lit_with_shadows_shader
if
light_color
is
None
:
...
...
simulators/ursina/entities/world_grid.py
浏览文件 @
c616a5bf
...
...
@@ -8,9 +8,10 @@
# ==============================================================================
from
ursina
import
Entity
,
Grid
,
color
from
simulators.ursina.ursina_mesh
import
create_arrow_line
from
common.singleton
import
Singleton
class
WorldGrid
(
Entity
):
class
WorldGrid
(
Singleton
,
Entity
):
"""
创建一个宇宙网格对象
"""
...
...
@@ -33,3 +34,5 @@ class WorldGrid(Entity):
grid
.
set_light_off
()
# self.draw_axises()
if
not
hasattr
(
self
,
"instance"
):
self
.
instance
=
self
simulators/ursina_simulator.py
浏览文件 @
c616a5bf
...
...
@@ -234,7 +234,7 @@ class UrsinaSimulator(Simulator):
from
ursina
import
Sky
sky
=
Sky
(
texture
=
texture
,
scale
=
sky_scale
)
Sky
.
instance
=
sky
# sky = SphereSky(texture=texture, scale=sky_scale)
sky
.
scale
=
sky_scale
camera
.
sky
=
sky
...
...
@@ -320,7 +320,6 @@ class UrsinaSimulator(Simulator):
if
self
.
show_timer
:
self
.
create_timer
()
EditorCamera
(
ignore_paused
=
True
)
# 防止打开中文输入法
# self.switch_to_english_input_method()
# file: 指定音乐文件的路径
...
...
@@ -347,6 +346,8 @@ class UrsinaSimulator(Simulator):
audio
=
Audio
(
bg_music
,
pitch
=
1
,
loop
=
True
,
autoplay
=
True
)
audio
.
volume
=
0.3
EditorCamera
(
ignore_paused
=
True
)
if
self
.
show_timer
:
UrsinaEvent
.
on_reset
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录