Reorganized app class

This commit is contained in:
2023-02-21 20:31:29 +01:00
parent 17c009c1ac
commit 8e995bd94c
37 changed files with 91 additions and 93 deletions

View File

@ -8,25 +8,27 @@ from panda3d.core import NodePath, DirectionalLight, TransparencyAttrib
def get_icons():
return type('', (object,), {
'app': tk.PhotoImage(file="icons/application.png"),
'brick': tk.PhotoImage(file="icons/brick.png"),
'bricks': tk.PhotoImage(file="icons/bricks.png"),
'computer': tk.PhotoImage(file="icons/computer.png"),
'folder': tk.PhotoImage(file="icons/folder.png"),
'shape_group': tk.PhotoImage(file="icons/shape_group.png"),
'pictures': tk.PhotoImage(file="icons/pictures.png"),
'picture': tk.PhotoImage(file='icons/picture.png'),
"page_red": tk.PhotoImage(file='icons/page_red.png'),
'shape_square': tk.PhotoImage(file='icons/shape_square.png'),
'color_wheel': tk.PhotoImage(file='icons/color_wheel.png'),
'color_swatch': tk.PhotoImage(file='icons/color_swatch.png'),
'link': tk.PhotoImage(file='icons/link.png'),
'sound': tk.PhotoImage(file='icons/sound.png'),
'chart_organisation': tk.PhotoImage(file='icons/chart_organisation.png'),
'anchor': tk.PhotoImage(file='icons/anchor.png'),
'shape_flip_horizontal': tk.PhotoImage(file='icons/shape_flip_horizontal.png'),
'film': tk.PhotoImage(file='icons/film.png'),
'user': tk.PhotoImage(file='icons/user.png')
'app': tk.PhotoImage(file="ui/icons/application.png"),
'brick': tk.PhotoImage(file="ui/icons/brick.png"),
'bricks': tk.PhotoImage(file="ui/icons/bricks.png"),
'computer': tk.PhotoImage(file="ui/icons/computer.png"),
'folder': tk.PhotoImage(file="ui/icons/folder.png"),
'shape_group': tk.PhotoImage(file="ui/icons/shape_group.png"),
'pictures': tk.PhotoImage(file="ui/icons/pictures.png"),
'picture': tk.PhotoImage(file='ui/icons/picture.png'),
"page_red": tk.PhotoImage(file='ui/icons/page_red.png'),
'shape_square': tk.PhotoImage(file='ui/icons/shape_square.png'),
'color_wheel': tk.PhotoImage(file='ui/icons/color_wheel.png'),
'color_swatch': tk.PhotoImage(file='ui/icons/color_swatch.png'),
'link': tk.PhotoImage(file='ui/icons/link.png'),
'sound': tk.PhotoImage(file='ui/icons/sound.png'),
'chart_organisation': tk.PhotoImage(file='ui/icons/chart_organisation.png'),
'anchor': tk.PhotoImage(file='ui/icons/anchor.png'),
'shape_flip_horizontal': tk.PhotoImage(file='ui/icons/shape_flip_horizontal.png'),
'film': tk.PhotoImage(file='ui/icons/film.png'),
'user': tk.PhotoImage(file='ui/icons/user.png'),
'chart_line_link': tk.PhotoImage(file='ui/icons/chart_line_link.png'),
'music': tk.PhotoImage(file='ui/icons/music.png')
})()
def add_package_contents_to_tree(tree, package, type, name, extensions, icon_folder, icon_group, icon_item):
@ -54,11 +56,15 @@ def add_package_materials_to_tree(tree, package, icons):
def add_package_sounds_to_tree(tree, package, icons):
add_package_contents_to_tree(tree, package, 'sounds/', 'Sounds', ('.ogg', '.wav'), icons.folder, icons.sound, icons.sound)
def add_package_music_to_tree(tree, package, icons):
add_package_contents_to_tree(tree, package, 'music/', 'Music', ('.ogg', '.mp3'), icons.folder, icons.music, icons.music)
def add_package_to_tree(tree, package, icons):
add_package_models_to_tree(tree, package, icons)
add_package_textures_to_tree(tree, package, icons)
add_package_materials_to_tree(tree, package, icons)
add_package_sounds_to_tree(tree, package, icons)
add_package_music_to_tree(tree, package, icons)
def init_packages_tree(tree, packages, icons):
tree.insert('', 'end', '/', text=' /', open=True, image=icons.app)
@ -112,34 +118,40 @@ def init_gui(app, args):
def init_panda(app, args):
gltf.patch_loader(app.panda.loader)
app.panda.setBackgroundColor(0, 0, 0)
app.panda.setBackgroundColor(.02, .02, .02)
app.panda.disableMouse()
app.panda.camera.setPos(-5, -5, 2.5)
app.panda.camera.setHpr(-45, -20, 0)
app.panda.camera.setPos(0, -5, 2.5)
app.panda.camera.setHpr(0, -20, 0)
simplepbr.init()
env_root = NodePath('env_root')
env_root.reparentTo(app.panda.render)
app.env_root = NodePath('env_root')
app.env_root.reparentTo(app.panda.render)
axis = app.panda.loader.loadModel(app.package_manager.get_model_path('axis.glb'))
axis.setTransparency(TransparencyAttrib.MAlpha)
axis.setAlphaScale(0.2)
axis.reparentTo(env_root)
axis.reparentTo(app.env_root)
plane = app.panda.loader.loadModel(app.package_manager.get_model_path('debugplane.glb'))
plane.setTransparency(TransparencyAttrib.MAlpha)
plane.setAlphaScale(0.4)
plane.reparentTo(env_root)
plane.setAlphaScale(0.2)
plane.reparentTo(app.env_root)
root = app.panda.loader.loadModel(app.package_manager.get_model_path('debugrot.glb'))
root.setTransparency(TransparencyAttrib.MAlpha)
root.setAlphaScale(0.4)
root.reparentTo(env_root)
root.setAlphaScale(0.2)
root.reparentTo(app.env_root)
dlight = DirectionalLight('light')
dlight.setColor((4, 4, 4, 1))
dlight.setShadowCaster(True, 512, 512)
nplight = env_root.attachNewNode(dlight)
nplight.setPos(0, 0, -1)
nplight.setHpr(0, -60, -45)
nplight = app.env_root.attachNewNode(dlight)
nplight.setPos(0, 1, 1)
nplight.setHpr(180+15, -45, 15)
app.camera_root = NodePath('camera_root')
app.camera_root.reparentTo(app.panda.render)
app.panda.camera.wrtReparentTo(app.camera_root)
app.panda.render.setLight(nplight)
app.scene_root = NodePath('scene_root')
app.scene_root.reparentTo(app.panda.render)
app.panda.taskMgr.add(app.update_input, "update_input")
app.panda.accept('mouse1', app.mouse1_down, [])
app.panda.accept('mouse1-up', app.mouse1_up, [])
app.panda.accept('mouse1-up', app.mouse1_up, [])
app.panda.accept('wheel_up', app.wheel_up, [])
app.panda.accept('wheel_down', app.wheel_down, [])

View File

@ -11,6 +11,11 @@ class PackageManager:
self.package_list = []
self.main_package = None
def unmount_all(self):
self.vfs.unmount(self.main_package.mount_dir)
for package in self.package_list:
self.vfs.unmount(package.mount_dir)
def get_package_meta(self, filepath):
if not os.path.exists(filepath):
raise FilepathNotFound(filepath)