Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
bf539743
宇宙模拟器
项目概览
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看板
提交
bf539743
编写于
11月 11, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
96156167
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
81 addition
and
52 deletion
+81
-52
sim_lab/earth_moon_reality_bak.py
sim_lab/earth_moon_reality_bak.py
+4
-1
sim_scenes/func.py
sim_scenes/func.py
+6
-3
sim_scenes/solar_system/earth_moon_reality.py
sim_scenes/solar_system/earth_moon_reality.py
+4
-2
sim_scenes/solar_system/halley_comet_lib.py
sim_scenes/solar_system/halley_comet_lib.py
+15
-3
sim_scenes/solar_system/halley_comet_sim.py
sim_scenes/solar_system/halley_comet_sim.py
+3
-3
sim_scenes/solar_system/solar_system_reality.py
sim_scenes/solar_system/solar_system_reality.py
+4
-1
simulators/ursina/entities/video_recorder.py
simulators/ursina/entities/video_recorder.py
+45
-39
未找到文件。
sim_lab/earth_moon_reality_bak.py
浏览文件 @
bf539743
...
@@ -95,8 +95,11 @@ class SolarSystemRealitySim:
...
@@ -95,8 +95,11 @@ class SolarSystemRealitySim:
if
self
.
clock_position_center
:
if
self
.
clock_position_center
:
position
,
origin
=
(
0
,
.
25
),
(
0
,
0
)
position
,
origin
=
(
0
,
.
25
),
(
0
,
0
)
else
:
else
:
from
ursina
import
window
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.3
,
-
0.465
),
(
-
0.5
,
0.5
),
# position, origin = (0.60, -0.465), (-0.5, 0.5)
# position, origin = (0.60, -0.465), (-0.5, 0.5)
position
,
origin
=
(
-
0.60
,
-
0.465
),
(
-
0.5
,
0.5
)
#
position, origin = (-0.60, -0.465), (-0.5, 0.5)
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
=
position
,
position
=
position
,
...
...
sim_scenes/func.py
浏览文件 @
bf539743
...
@@ -411,16 +411,19 @@ def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02):
...
@@ -411,16 +411,19 @@ def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02):
def
create_text_panel
(
width
=
0.35
,
height
=
.
5
):
def
create_text_panel
(
width
=
0.35
,
height
=
.
5
):
# 创建一个 Panel 组件
# 创建一个 Panel 组件
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
,
window
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
panel
=
Panel
(
aspect_ratio
=
window
.
aspect_ratio
# 1920, 1080 1.777777777 position=(-.88, 0.3, 0), # 1.77
# 2376, 1080 2.2 position=(-.99, 0.3, 0), # 1.77
panel
=
Panel
(
# 2
parent
=
None
,
parent
=
None
,
model
=
'quad'
,
model
=
'quad'
,
# texture='white_cube',
# texture='white_cube',
color
=
color
.
black
,
color
=
color
.
black
,
origin
=
(
-
.
48
,
.
48
,
-
.
48
),
origin
=
(
-
.
48
,
.
48
,
-
.
48
),
scale
=
(
width
,
height
),
scale
=
(
width
,
height
),
position
=
(
-
.
88
,
0.3
,
0
),
position
=
(
-
.
49
*
aspect_ratio
,
0.3
,
0
),
alpha
=
0.5
alpha
=
0.5
)
)
...
...
sim_scenes/solar_system/earth_moon_reality.py
浏览文件 @
bf539743
...
@@ -95,8 +95,10 @@ class SolarSystemRealitySim:
...
@@ -95,8 +95,10 @@ class SolarSystemRealitySim:
if
self
.
clock_position_center
:
if
self
.
clock_position_center
:
position
,
origin
=
(
0
,
.
25
),
(
0
,
0
)
position
,
origin
=
(
0
,
.
25
),
(
0
,
0
)
else
:
else
:
# position, origin = (0.60, -0.465), (-0.5, 0.5)
from
ursina
import
window
position
,
origin
=
(
-
0.60
,
-
0.465
),
(
-
0.5
,
0.5
)
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.3
,
-
0.465
),
(
-
0.5
,
0.5
),
# position, origin = (-0.60, -0.465), (-0.5, 0.5)
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
=
position
,
position
=
position
,
...
...
sim_scenes/solar_system/halley_comet_lib.py
浏览文件 @
bf539743
...
@@ -68,9 +68,20 @@ class HalleyCometSimBase:
...
@@ -68,9 +68,20 @@ class HalleyCometSimBase:
self
.
pluto
=
None
self
.
pluto
=
None
self
.
bodies
=
[]
self
.
bodies
=
[]
def
set_window_size
(
self
,
size
=
(
1536
,
684
)):
def
set_window_size
(
self
,
size
=
(
1536
,
684
)
,
fullscreen
=
False
):
from
ursina
import
window
from
ursina
import
window
if
fullscreen
:
# 设置窗口为全屏模式
window
.
fullscreen
=
True
# 设置窗口的宽度和高度
window
.
size
=
size
window
.
size
=
size
# self.set_window_size((3500, 1024))
# r = 1
# self.set_window_size((1920*2, 1080*2))
# self.set_window_size((int(1920 * r), int(1080 * r)))
# self.set_window_size((2376, 1080))
# self.set_window_size((520, 540), fullscreen=False)
def
build_solar_system
(
self
,
ignore_gravity
=
False
,
start_time
=
None
):
def
build_solar_system
(
self
,
ignore_gravity
=
False
,
start_time
=
None
):
# region 构建太阳系
# region 构建太阳系
...
@@ -126,8 +137,9 @@ class HalleyCometSimBase:
...
@@ -126,8 +137,9 @@ class HalleyCometSimBase:
# if self.clock_position_center:
# if self.clock_position_center:
# position, origin = (0, .25), (0, 0),
# position, origin = (0, .25), (0, 0),
# else:
# else:
position
,
origin
=
(
0.60
,
-
0.465
),
(
-
0.5
,
0.5
),
from
ursina
import
window
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.3
,
-
0.465
),
(
-
0.5
,
0.5
),
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
=
position
,
position
=
position
,
origin
=
origin
,
origin
=
origin
,
...
...
sim_scenes/solar_system/halley_comet_sim.py
浏览文件 @
bf539743
...
@@ -72,8 +72,8 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -72,8 +72,8 @@ class HalleyCometSim(HalleyCometSimBase):
# UrsinaConfig.trail_length = 180
# UrsinaConfig.trail_length = 180
UrsinaConfig
.
trail_factor
=
3
UrsinaConfig
.
trail_factor
=
3
# self.set_window_size((3500, 1024))
r
=
1
# self.set_window_size((1920, 1080)
)
self
.
set_window_size
((
int
(
1920
*
r
),
int
(
1080
*
r
)),
True
)
# camera.clip_plane_near = 0.1
# camera.clip_plane_near = 0.1
camera
.
clip_plane_far
=
1000000
camera
.
clip_plane_far
=
1000000
...
@@ -349,7 +349,7 @@ if __name__ == '__main__':
...
@@ -349,7 +349,7 @@ if __name__ == '__main__':
show_trail
=
True
,
show_trail
=
True
,
# bg_music='sounds/no_glory.mp3',
# bg_music='sounds/no_glory.mp3',
show_camera_info
=
False
,
show_camera_info
=
False
,
#
save_as_video=True,
save_as_video
=
True
,
show_control_info
=
False
,
show_control_info
=
False
,
timer_enabled
=
True
,
timer_enabled
=
True
,
show_grid
=
False
show_grid
=
False
...
...
sim_scenes/solar_system/solar_system_reality.py
浏览文件 @
bf539743
...
@@ -100,7 +100,10 @@ class SolarSystemRealitySim:
...
@@ -100,7 +100,10 @@ class SolarSystemRealitySim:
if
self
.
clock_position_center
:
if
self
.
clock_position_center
:
position
,
origin
=
(
0
,
.
25
),
(
0
,
0
),
position
,
origin
=
(
0
,
.
25
),
(
0
,
0
),
else
:
else
:
position
,
origin
=
(
0.60
,
-
0.465
),
(
-
0.5
,
0.5
),
from
ursina
import
window
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.3
,
-
0.465
),
(
-
0.5
,
0.5
),
# position, origin = (0.60, -0.465), (-0.5, 0.5),
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
=
position
,
position
=
position
,
...
...
simulators/ursina/entities/video_recorder.py
浏览文件 @
bf539743
...
@@ -64,10 +64,10 @@ class VideoRecorder(Entity):
...
@@ -64,10 +64,10 @@ class VideoRecorder(Entity):
for
key
,
value
in
kwargs
.
items
():
for
key
,
value
in
kwargs
.
items
():
setattr
(
self
,
key
,
value
)
setattr
(
self
,
key
,
value
)
self
.
max_frames
=
int
(
self
.
duration
*
self
.
fps
)
#
self.max_frames = int(self.duration * self.fps)
self
.
frames
=
[]
#
self.frames = []
self
.
save_name
=
"video_temp.mp4"
self
.
save_name
=
"video_temp.mp4"
self
.
video
=
self
.
create_video
(
864
,
1536
)
self
.
video
=
None
def
create_video
(
self
,
height
,
width
):
def
create_video
(
self
,
height
,
width
):
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
...
@@ -75,11 +75,11 @@ class VideoRecorder(Entity):
...
@@ -75,11 +75,11 @@ class VideoRecorder(Entity):
return
video
return
video
def
start_recording
(
self
):
def
start_recording
(
self
):
print
(
'start recording,'
,
self
.
duration
,
self
.
file_path
)
print
(
'start recording,'
,
self
.
file_path
)
window
.
fps_counter
.
enabled
=
False
window
.
fps_counter
.
enabled
=
False
window
.
exit_button
.
visible
=
False
window
.
exit_button
.
visible
=
False
self
.
frames
=
[]
#
self.frames = []
self
.
max_frames
=
self
.
duration
*
self
.
fps
#
self.max_frames = self.duration * self.fps
if
not
self
.
file_path
.
exists
():
if
not
self
.
file_path
.
exists
():
self
.
file_path
.
mkdir
()
self
.
file_path
.
mkdir
()
# base.movie(namePrefix=f'\\video_temp\\{self.video_name}', duration=2.0, fps=30, format='png', sd=4)
# base.movie(namePrefix=f'\\video_temp\\{self.video_name}', duration=2.0, fps=30, format='png', sd=4)
...
@@ -96,35 +96,35 @@ class VideoRecorder(Entity):
...
@@ -96,35 +96,35 @@ class VideoRecorder(Entity):
def
convert_to_mp4
(
self
):
def
convert_to_mp4
(
self
):
print
(
"视频保存中"
)
print
(
"视频保存中"
)
for
frame
in
self
.
frames
:
#
for frame in self.frames:
self
.
video
.
write
(
frame
)
#
self.video.write(frame)
self
.
video
.
release
()
self
.
video
.
release
()
cv2
.
destroyAllWindows
()
cv2
.
destroyAllWindows
()
# crop('video.mp4')
# crop('video.mp4')
print
(
"视频保存完成"
)
print
(
"视频保存完成"
)
print
(
self
.
save_name
)
print
(
self
.
save_name
)
def
screenshot_to_opencv_img
(
self
,
texture
):
#
def screenshot_to_opencv_img(self, texture):
# 将Texture对象转换为numpy数组
#
# 将Texture对象转换为numpy数组
array
=
texture
.
to_array
()
#
array = texture.to_array()
# 将数组reshape为4D,以便opencv可以正确读取
#
# 将数组reshape为4D,以便opencv可以正确读取
array
=
np
.
reshape
(
array
,
(
texture
.
height
,
texture
.
width
,
-
1
))
#
array = np.reshape(array, (texture.height, texture.width, -1))
# 转换为opencv读取的格式,注意需要先安装opencv库
#
# 转换为opencv读取的格式,注意需要先安装opencv库
img
=
cv2
.
cvtColor
(
array
,
#
img = cv2.cvtColor(array,
cv2
.
COLOR_RGB2BGR
)
# 这里的cv2.COLOR_RGB2BGR是将RGB格式转换为BGR格式,因为Ursina使用的是RGB格式,而opencv使用的是BGR格式
#
cv2.COLOR_RGB2BGR) # 这里的cv2.COLOR_RGB2BGR是将RGB格式转换为BGR格式,因为Ursina使用的是RGB格式,而opencv使用的是BGR格式
return
img
#
return img
def
update
(
self
):
def
update
(
self
):
if
not
self
.
recording
:
if
not
self
.
recording
:
return
return
self
.
t
+=
time
.
dt
#
self.t += time.dt
if
self
.
t
>=
1
/
30
:
#
if self.t >= 1 / 30:
# base.screenshot(
#
# base.screenshot(
# namePrefix='\\video_temp\\' + self.video_name + '_' + str(self.i).zfill(4) + '.png',
#
# namePrefix='\\video_temp\\' + self.video_name + '_' + str(self.i).zfill(4) + '.png',
# defaultFilename=0,
#
# defaultFilename=0,
# )
#
# )
self
.
t
=
0
#
self.t = 0
# image = deepcopy(camera.render_texture)
# image = deepcopy(camera.render_texture)
# self.frames.append(self.renderToPNM())
# self.frames.append(self.renderToPNM())
from
PIL
import
Image
from
PIL
import
Image
...
@@ -136,7 +136,12 @@ class VideoRecorder(Entity):
...
@@ -136,7 +136,12 @@ class VideoRecorder(Entity):
data
=
image
.
getRamImageAs
(
"BGR"
).
getData
()
data
=
image
.
getRamImageAs
(
"BGR"
).
getData
()
np_data
=
np
.
frombuffer
(
data
,
dtype
=
np
.
uint8
)
np_data
=
np
.
frombuffer
(
data
,
dtype
=
np
.
uint8
)
#
#
img_data
=
np
.
reshape
(
np_data
,
(
864
,
1536
,
3
))
if
self
.
video
is
None
:
self
.
video_height
=
image
.
y_size
# 864
self
.
video_width
=
image
.
x_size
# 1536
self
.
video
=
self
.
create_video
(
self
.
video_height
,
self
.
video_width
)
img_data
=
np
.
reshape
(
np_data
,
(
self
.
video_height
,
self
.
video_width
,
3
))
# img = Image.fromarray(img_data)
# img = Image.fromarray(img_data)
# img = self.screenshot_to_opencv_img(image)
# img = self.screenshot_to_opencv_img(image)
# img = np.array(data)
# img = np.array(data)
...
@@ -158,12 +163,13 @@ class VideoRecorder(Entity):
...
@@ -158,12 +163,13 @@ class VideoRecorder(Entity):
# # image = deepcopy(camera.render_texture)
# # image = deepcopy(camera.render_texture)
# self.frames.append(data)
# self.frames.append(data)
self
.
i
+=
1
#
self.i += 1
# img_bgr = cv2.cvtColor(img, cv2.COLOR_RGBA2BGR)
# img_bgr = cv2.cvtColor(img, cv2.COLOR_RGBA2BGR)
# if imageNum < self.fps * args.total_time:
# if imageNum < self.fps * args.total_time:
# show_image(frame)
# show_image(frame)
self
.
frames
.
append
(
normal_image
)
#
self.frames.append(normal_image)
self
.
video
.
write
(
normal_image
)
# store screenshot in memory
# store screenshot in memory
# def renderToPNM(self):
# def renderToPNM(self):
# base.graphicsEngine.renderFrame()
# base.graphicsEngine.renderFrame()
...
@@ -175,18 +181,18 @@ class VideoRecorder(Entity):
...
@@ -175,18 +181,18 @@ class VideoRecorder(Entity):
# # win.setupRenderTexture()
# # win.setupRenderTexture()
# return None
# return None
def
convert_to_gif
(
self
):
#
def convert_to_gif(self):
import
imageio
#
import imageio
images
=
[]
#
images = []
if
not
os
.
path
.
exists
(
self
.
file_path
):
#
if not os.path.exists(self.file_path):
return
#
return
#
for
filename
in
os
.
listdir
(
self
.
file_path
):
#
for filename in os.listdir(self.file_path):
images
.
append
(
imageio
.
imread
(
self
.
file_path
/
filename
))
#
images.append(imageio.imread(self.file_path / filename))
#
imageio
.
mimsave
(
Path
(
f
'
{
self
.
file_path
.
parent
}
/
{
self
.
video_name
}
.gif'
),
images
)
#
imageio.mimsave(Path(f'{self.file_path.parent}/{self.video_name}.gif'), images)
shutil
.
rmtree
(
self
.
file_path
)
# delete temp folder
#
shutil.rmtree(self.file_path) # delete temp folder
print
(
'saved gif to:'
,
Path
(
f
'
{
self
.
file_path
.
parent
}
/
{
self
.
video_name
}
.gif'
))
#
print('saved gif to:', Path(f'{self.file_path.parent}/{self.video_name}.gif'))
class
VideoRecorderUI
(
WindowPanel
):
class
VideoRecorderUI
(
WindowPanel
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录