Reorganized app class

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/models/doortype1.glb Normal file

Binary file not shown.

BIN
assets/models/room1.glb Normal file

Binary file not shown.

BIN
assets/textures/floor1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
assets/textures/wall1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -1,24 +0,0 @@
from .packages import PackageManager
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
from panda3d.core import WindowProperties, TextureStage, AmbientLight, PointLight
import simplepbr
import gltf
class Game(ShowBase):
def __init__(self, packages):
ShowBase.__init__(self)
simplepbr.init()
gltf.patch_loader(self.loader)
self.camLens.setFov(90)
self.camera.setPos(0, -4, 1)
winprops = WindowProperties()
winprops.setSize(1600, 900)
self.win.requestProperties(winprops)

View File

@ -1,33 +0,0 @@
from .packages import PackageManager
from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties, TextureStage
class Game(ShowBase):
def __init__(self, packages):
ShowBase.__init__(self)
#self.disableMouse()
self.fs = PackageManager()
for package in packages:
self.fs.include(package)
mdl2 = self.fs.find_model('$/arrangements/arrange3.glb')
mdl2.reparentTo(render)
mdl2.find('origin/wall').setTexture(self.fs.find_texture('$/generic_noise.png'))
mdl_missing = self.fs.find_model('main-assetsz/sword1/sword1.glb')
print(mdl_missing)
mdl_missing.reparentTo(render)
winprops = WindowProperties()
winprops.setSize(1600, 900)
self.win.requestProperties(winprops)
def start_game(packages):
if not packages:
packages = []
game = Game(packages)
game.run()

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)

View File

@ -3,12 +3,17 @@ import tkinter as tk
from source.packages import PackageManager
from source.packages.gui import *
from direct.showbase.ShowBase import ShowBase
from panda3d.core import VirtualFileSystem, Material
from panda3d.core import VirtualFileSystem, Material, Vec3, CullFaceAttrib, WindowProperties
from direct.actor.Actor import Actor
class PackageExplorer:
def __init__(self, args):
self.gui = tk.Tk()
self.gui.title("Blackjack and Hookers: Package Explorer")
self.panda = ShowBase()
props = WindowProperties()
props.setTitle('Blackjack and Hookers: 3D Viewport')
self.panda.win.requestProperties(props)
self.package_manager = PackageManager(VirtualFileSystem.getGlobalPtr())
self.package_manager.set_main_package(args.main)
self.icons = get_icons()
@ -19,9 +24,14 @@ class PackageExplorer:
self.tree_packages = None
self.tree_scene = None
self.running = True
self.env_root = None
self.camera_root = None
self.camera_accel = 100
self.panda_keymap = {
'mouse1': False
}
self.mouse_previous = Vec3()
self.mouse_direction = Vec3()
init_gui(self, args)
init_packages_tree(self.tree_packages, self.package_manager, self.icons)
init_panda(self, args)
@ -37,14 +47,24 @@ class PackageExplorer:
mat = Material()
mat.setAmbient((1, 0, 0, 1))
node = self.panda.loader.loadModel(item)
path = node.find('**/+Character')
if not path.isEmpty():
node = Actor(node)
node.reparentTo(self.scene_root)
node.setMaterial(mat)
node.setTwoSided(False)
node.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullClockwise))
self.display_scenegraph(node, item)
self.prev = node
def display_scenegraph(self, node, item):
self.tree_scene.delete(*self.tree_scene.get_children())
self.tree_scene.insert('', 'end', '/', text=f' {item}', open=True, image=self.icons.shape_square)
joints = node.getJoints() if getattr(node, 'getJoints', None) else []
if len(joints) > 0:
self.tree_scene.insert('/', 'end', 'joints', text=f' Joints ({len(joints)})', image=self.icons.chart_line_link)
for joint in joints:
self.tree_scene.insert('joints', 'end', f'joint_{joint.getName()}', text=f' {joint.getName()}', image=self.icons.anchor)
self.add_scene_nodes(node, '/')
def add_scene_nodes(self, node, parent):
@ -76,10 +96,28 @@ class PackageExplorer:
def mouse1_up(self):
self.panda_keymap['mouse1'] = False
def wheel_up(self):
quat = self.panda.camera.getQuat(self.camera_root)
forward = quat.getForward()
self.panda.camera.setPos(self.panda.camera.getPos() + forward)
def wheel_down(self):
quat = self.panda.camera.getQuat(self.camera_root)
forward = quat.getForward()
self.panda.camera.setPos(self.panda.camera.getPos() - forward)
def update_input(self, task):
dt = self.panda.clock.getDt()
if self.panda.mouseWatcherNode.hasMouse():
mouse = self.panda.mouseWatcherNode.getMouse()
dt = self.panda.clock.getDt()
self.mouse_direction = Vec3(self.mouse_previous.getX() - mouse.getX(),
self.mouse_previous.getY() - mouse.getY(),
0)
self.mouse_previous = Vec3(mouse.getX(), mouse.getY(), 0)
if self.panda_keymap['mouse1']:
print('Mouse1 down')
self.camera_root.setH(self.panda.render, self.camera_root.getH() + self.mouse_direction.getX() * self.camera_accel)
self.camera_root.setP(self.panda.render, self.camera_root.getP() + -self.mouse_direction.getY() * self.camera_accel)
return task.cont

BIN
ui/axis.glb Normal file

Binary file not shown.

BIN
ui/header.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

View File

Before

Width:  |  Height:  |  Size: 523 B

After

Width:  |  Height:  |  Size: 523 B

View File

Before

Width:  |  Height:  |  Size: 464 B

After

Width:  |  Height:  |  Size: 464 B

View File

Before

Width:  |  Height:  |  Size: 399 B

After

Width:  |  Height:  |  Size: 399 B

View File

Before

Width:  |  Height:  |  Size: 825 B

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

View File

Before

Width:  |  Height:  |  Size: 434 B

After

Width:  |  Height:  |  Size: 434 B

View File

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 152 B

View File

Before

Width:  |  Height:  |  Size: 892 B

After

Width:  |  Height:  |  Size: 892 B

View File

Before

Width:  |  Height:  |  Size: 667 B

After

Width:  |  Height:  |  Size: 667 B

View File

Before

Width:  |  Height:  |  Size: 653 B

After

Width:  |  Height:  |  Size: 653 B

View File

Before

Width:  |  Height:  |  Size: 537 B

After

Width:  |  Height:  |  Size: 537 B

View File

Before

Width:  |  Height:  |  Size: 343 B

After

Width:  |  Height:  |  Size: 343 B

BIN
ui/icons/music.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

View File

Before

Width:  |  Height:  |  Size: 641 B

After

Width:  |  Height:  |  Size: 641 B

View File

Before

Width:  |  Height:  |  Size: 606 B

After

Width:  |  Height:  |  Size: 606 B

View File

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 704 B

View File

Before

Width:  |  Height:  |  Size: 403 B

After

Width:  |  Height:  |  Size: 403 B

View File

Before

Width:  |  Height:  |  Size: 553 B

After

Width:  |  Height:  |  Size: 553 B

View File

Before

Width:  |  Height:  |  Size: 353 B

After

Width:  |  Height:  |  Size: 353 B

View File

Before

Width:  |  Height:  |  Size: 610 B

After

Width:  |  Height:  |  Size: 610 B

View File

Before

Width:  |  Height:  |  Size: 741 B

After

Width:  |  Height:  |  Size: 741 B

BIN
ui/plane.glb Normal file

Binary file not shown.

BIN
ui/rotation.glb Normal file

Binary file not shown.