ya2 · news · projects · code · about

drag and drop
[pmachines.git] / pmachines / pmachines.py
index 08669ee24c683c91a3c4441b0ced75f8bb827b2a..2e9e73d9a90ea947b4d07255d632dfa9641912a1 100755 (executable)
@@ -5,10 +5,10 @@ from sys import platform, argv
 from logging import info
 from os.path import exists
 from os import makedirs
-from panda3d.core import Filename, load_prc_file_data, AmbientLight, \
-    DirectionalLight, AntialiasAttrib
+from panda3d.core import Filename, load_prc_file_data, AntialiasAttrib
+from panda3d.bullet import BulletWorld, BulletDebugNode
 from direct.showbase.ShowBase import ShowBase
-from pmachines.items.background import Background
+from pmachines.scene import Scene
 
 
 class Pmachines:
@@ -18,44 +18,14 @@ class Pmachines:
         self.base = ShowBase()
         info('platform: %s' % platform)
         info('exists main.py: %s' % exists('main.py'))
-        self._prepare_windows()
+        self._prepare_window()
         args = self._parse_args()
         self.updating = args.update
         self.version = args.version
         if args.update:
             return
-        self._set_camera()
-        self._set_lights()
-        Background()
-
-    def _set_camera(self):
-        base.camera.set_pos(0, -20, 0)
-        base.camera.look_at(0, 0, 0)
-        self.base.disable_mouse()
-
-    def _set_lights(self):
-        alight = AmbientLight('alight')  # for ao
-        alight.setColor((.4, .4, .4, 1))
-        alnp = render.attachNewNode(alight)
-        render.setLight(alnp)
-
-        directionalLight = DirectionalLight('directionalLight')
-        directionalLightNP = render.attachNewNode(directionalLight)
-        directionalLightNP.setHpr(315, -60, 0)
-        directionalLight.setColor((3.6, 3.6, 3.6, 1))
-        render.setLight(directionalLightNP)
-
-        directionalLight = DirectionalLight('directionalLight')
-        directionalLightNP = render.attachNewNode(directionalLight)
-        directionalLightNP.setHpr(195, -30, 0)
-        directionalLight.setColor((.4, .4, .4, 1))
-        render.setLight(directionalLightNP)
-
-        directionalLight = DirectionalLight('directionalLight')
-        directionalLightNP = render.attachNewNode(directionalLight)
-        directionalLightNP.setHpr(75, -30, 0)
-        directionalLight.setColor((.3, .3, .3, 1))
-        render.setLight(directionalLightNP)
+        self._set_physics()
+        Scene(self.world)
 
     def _configure(self):
         load_prc_file_data('', 'window-title pmachines')
@@ -71,7 +41,7 @@ class Pmachines:
         args = parser.parse_args(cmd_line)
         return args
 
-    def _prepare_windows(self):
+    def _prepare_window(self):
         data_path = ''
         if (platform.startswith('win') or platform.startswith('linux')) and (
                 not exists('main.py') or __file__.startswith('/app/bin/')):
@@ -89,4 +59,22 @@ class Pmachines:
             use_occlusion_maps=True,
             msaa_samples=4)
         render.setAntialias(AntialiasAttrib.MAuto)
-        base.set_background_color(0, 0, 0, 1)
+        self.base.set_background_color(0, 0, 0, 1)
+        self.base.disable_mouse()
+
+    def _set_physics(self):
+        debug_node = BulletDebugNode('Debug')
+        debug_node.show_wireframe(True)
+        debug_node.show_constraints(True)
+        debug_node.show_bounding_boxes(True)
+        debug_node.show_normals(True)
+        debug_np = render.attach_new_node(debug_node)
+        debug_np.show()
+        self.world = BulletWorld()
+        self.world.set_gravity((0, 0, -9.81))
+        self.world.set_debug_node(debug_np.node())
+        def update(task):
+            dt = globalClock.get_dt()
+            self.world.do_physics(dt)
+            return task.cont
+        taskMgr.add(update, 'update')