Commit | Line | Data |
---|---|---|
8ee66edd | 1 | import argparse |
4894bb48 FC |
2 | import simplepbr |
3 | import gltf | |
8ee66edd FC |
4 | from sys import platform, argv |
5 | from logging import info | |
6 | from os.path import exists | |
7 | from os import makedirs | |
4894bb48 FC |
8 | from panda3d.core import Filename, load_prc_file_data, AmbientLight, \ |
9 | DirectionalLight, AntialiasAttrib | |
8ee66edd | 10 | from direct.showbase.ShowBase import ShowBase |
4894bb48 | 11 | from pmachines.items.background import Background |
8ee66edd FC |
12 | |
13 | ||
14 | class Pmachines: | |
15 | ||
16 | def __init__(self): | |
17 | self._configure() | |
18 | self.base = ShowBase() | |
19 | info('platform: %s' % platform) | |
20 | info('exists main.py: %s' % exists('main.py')) | |
21 | self._prepare_windows() | |
22 | args = self._parse_args() | |
23 | self.updating = args.update | |
24 | self.version = args.version | |
25 | if args.update: | |
26 | return | |
4894bb48 FC |
27 | self._set_camera() |
28 | self._set_lights() | |
29 | Background() | |
30 | ||
31 | def _set_camera(self): | |
32 | base.camera.set_pos(0, -20, 0) | |
33 | base.camera.look_at(0, 0, 0) | |
34 | self.base.disable_mouse() | |
35 | ||
36 | def _set_lights(self): | |
37 | alight = AmbientLight('alight') # for ao | |
38 | alight.setColor((.4, .4, .4, 1)) | |
39 | alnp = render.attachNewNode(alight) | |
40 | render.setLight(alnp) | |
41 | ||
42 | directionalLight = DirectionalLight('directionalLight') | |
43 | directionalLightNP = render.attachNewNode(directionalLight) | |
44 | directionalLightNP.setHpr(315, -60, 0) | |
45 | directionalLight.setColor((3.6, 3.6, 3.6, 1)) | |
46 | render.setLight(directionalLightNP) | |
47 | ||
48 | directionalLight = DirectionalLight('directionalLight') | |
49 | directionalLightNP = render.attachNewNode(directionalLight) | |
50 | directionalLightNP.setHpr(195, -30, 0) | |
51 | directionalLight.setColor((.4, .4, .4, 1)) | |
52 | render.setLight(directionalLightNP) | |
53 | ||
54 | directionalLight = DirectionalLight('directionalLight') | |
55 | directionalLightNP = render.attachNewNode(directionalLight) | |
56 | directionalLightNP.setHpr(75, -30, 0) | |
57 | directionalLight.setColor((.3, .3, .3, 1)) | |
58 | render.setLight(directionalLightNP) | |
8ee66edd FC |
59 | |
60 | def _configure(self): | |
61 | load_prc_file_data('', 'window-title pmachines') | |
4894bb48 FC |
62 | load_prc_file_data('', 'framebuffer-multisample 1') |
63 | load_prc_file_data('', 'multisamples 4') | |
64 | load_prc_file_data('', 'framebuffer-srgb true') | |
8ee66edd FC |
65 | |
66 | def _parse_args(self): | |
67 | parser = argparse.ArgumentParser() | |
68 | parser.add_argument('--update', action='store_true') | |
69 | parser.add_argument('--version', action='store_true') | |
70 | cmd_line = [arg for arg in iter(argv[1:]) if not arg.startswith('-psn_')] | |
71 | args = parser.parse_args(cmd_line) | |
72 | return args | |
73 | ||
74 | def _prepare_windows(self): | |
75 | data_path = '' | |
76 | if (platform.startswith('win') or platform.startswith('linux')) and ( | |
77 | not exists('main.py') or __file__.startswith('/app/bin/')): | |
78 | # it is the deployed version for windows | |
79 | data_path = str(Filename.get_user_appdata_directory()) + '/pmachines' | |
80 | home = '/home/flavio' # we must force this for wine | |
81 | if data_path.startswith('/c/users/') and exists(home + '/.wine/'): | |
82 | data_path = home + '/.wine/drive_' + data_path[1:] | |
83 | info('creating dirs: %s' % data_path) | |
84 | makedirs(data_path, exist_ok=True) | |
4894bb48 FC |
85 | gltf.patch_loader(base.loader) |
86 | pipeline = simplepbr.init( | |
87 | use_normal_maps=True, | |
88 | use_emission_maps=False, | |
89 | use_occlusion_maps=True, | |
90 | msaa_samples=4) | |
91 | render.setAntialias(AntialiasAttrib.MAuto) | |
92 | base.set_background_color(0, 0, 0, 1) |