ya2 · news · projects · code · about

fixed logging
[pmachines.git] / pmachines / pmachines.py
CommitLineData
8ee66edd 1import argparse
4894bb48
FC
2import simplepbr
3import gltf
8ee66edd
FC
4from sys import platform, argv
5from logging import info
6from os.path import exists
7from os import makedirs
1be87278
FC
8from panda3d.core import Filename, load_prc_file_data, AntialiasAttrib
9from panda3d.bullet import BulletWorld, BulletDebugNode
8ee66edd 10from direct.showbase.ShowBase import ShowBase
1be87278 11from pmachines.scene import Scene
54a1397e 12from pmachines.music import MusicMgr
8ee66edd
FC
13
14
15class Pmachines:
16
17 def __init__(self):
18 self._configure()
19 self.base = ShowBase()
20 info('platform: %s' % platform)
21 info('exists main.py: %s' % exists('main.py'))
1be87278 22 self._prepare_window()
8ee66edd
FC
23 args = self._parse_args()
24 self.updating = args.update
25 self.version = args.version
26 if args.update:
27 return
54a1397e 28 MusicMgr()
1be87278
FC
29 self._set_physics()
30 Scene(self.world)
8ee66edd
FC
31
32 def _configure(self):
33 load_prc_file_data('', 'window-title pmachines')
4894bb48
FC
34 load_prc_file_data('', 'framebuffer-multisample 1')
35 load_prc_file_data('', 'multisamples 4')
36 load_prc_file_data('', 'framebuffer-srgb true')
8ee66edd
FC
37
38 def _parse_args(self):
39 parser = argparse.ArgumentParser()
40 parser.add_argument('--update', action='store_true')
41 parser.add_argument('--version', action='store_true')
42 cmd_line = [arg for arg in iter(argv[1:]) if not arg.startswith('-psn_')]
43 args = parser.parse_args(cmd_line)
44 return args
45
1be87278 46 def _prepare_window(self):
8ee66edd
FC
47 data_path = ''
48 if (platform.startswith('win') or platform.startswith('linux')) and (
49 not exists('main.py') or __file__.startswith('/app/bin/')):
50 # it is the deployed version for windows
51 data_path = str(Filename.get_user_appdata_directory()) + '/pmachines'
52 home = '/home/flavio' # we must force this for wine
53 if data_path.startswith('/c/users/') and exists(home + '/.wine/'):
54 data_path = home + '/.wine/drive_' + data_path[1:]
55 info('creating dirs: %s' % data_path)
56 makedirs(data_path, exist_ok=True)
4894bb48
FC
57 gltf.patch_loader(base.loader)
58 pipeline = simplepbr.init(
59 use_normal_maps=True,
60 use_emission_maps=False,
61 use_occlusion_maps=True,
62 msaa_samples=4)
63 render.setAntialias(AntialiasAttrib.MAuto)
1be87278
FC
64 self.base.set_background_color(0, 0, 0, 1)
65 self.base.disable_mouse()
66
67 def _set_physics(self):
68 debug_node = BulletDebugNode('Debug')
69 debug_node.show_wireframe(True)
70 debug_node.show_constraints(True)
71 debug_node.show_bounding_boxes(True)
72 debug_node.show_normals(True)
73 debug_np = render.attach_new_node(debug_node)
74 debug_np.show()
75 self.world = BulletWorld()
76 self.world.set_gravity((0, 0, -9.81))
77 self.world.set_debug_node(debug_np.node())
78 def update(task):
79 dt = globalClock.get_dt()
80 self.world.do_physics(dt)
81 return task.cont
82 taskMgr.add(update, 'update')