ya2 · news · projects · code · about

background
authorFlavio Calva <f.calva@gmail.com>
Thu, 30 Dec 2021 18:35:36 +0000 (19:35 +0100)
committerFlavio Calva <f.calva@gmail.com>
Thu, 30 Dec 2021 18:35:36 +0000 (19:35 +0100)
pmachines/__init__.py [new file with mode: 0644]
pmachines/items/__init__.py [new file with mode: 0644]
pmachines/items/background.py [new file with mode: 0644]
pmachines/pmachines.py
prj.org

diff --git a/pmachines/__init__.py b/pmachines/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pmachines/items/__init__.py b/pmachines/items/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pmachines/items/background.py b/pmachines/items/background.py
new file mode 100644 (file)
index 0000000..1161186
--- /dev/null
@@ -0,0 +1,21 @@
+from itertools import product
+from panda3d.core import NodePath
+
+
+class Background:
+
+    def __init__(self):
+        root = NodePath('background_root')
+        root.reparent_to(render)
+        ncols, nrows = 8, 5
+        start_size, end_size = 5, 2.5
+        offset = 5
+        for col, row in product(range(ncols), range(nrows)):
+            model = loader.load_model('assets/gltf/background/background.gltf')
+            model.set_scale(end_size / start_size)
+            model.reparent_to(root)
+            total_width, total_height = end_size * ncols, end_size * nrows
+            left, bottom = -total_width/2, -total_height/2
+            model.set_pos(left + end_size * col, -offset, bottom + end_size * row)
+        root.clear_model_nodes()
+        root.flatten_strong()
index 2a3fa46493322059bd95ae78aec333836b43f818..08669ee24c683c91a3c4441b0ced75f8bb827b2a 100755 (executable)
@@ -1,10 +1,14 @@
 import argparse
+import simplepbr
+import gltf
 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
+from panda3d.core import Filename, load_prc_file_data, AmbientLight, \
+    DirectionalLight, AntialiasAttrib
 from direct.showbase.ShowBase import ShowBase
+from pmachines.items.background import Background
 
 
 class Pmachines:
@@ -20,9 +24,44 @@ class Pmachines:
         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)
 
     def _configure(self):
         load_prc_file_data('', 'window-title pmachines')
+        load_prc_file_data('', 'framebuffer-multisample 1')
+        load_prc_file_data('', 'multisamples 4')
+        load_prc_file_data('', 'framebuffer-srgb true')
 
     def _parse_args(self):
         parser = argparse.ArgumentParser()
@@ -43,3 +82,11 @@ class Pmachines:
                 data_path = home + '/.wine/drive_' + data_path[1:]
             info('creating dirs: %s' % data_path)
             makedirs(data_path, exist_ok=True)
+        gltf.patch_loader(base.loader)
+        pipeline = simplepbr.init(
+            use_normal_maps=True,
+            use_emission_maps=False,
+            use_occlusion_maps=True,
+            msaa_samples=4)
+        render.setAntialias(AntialiasAttrib.MAuto)
+        base.set_background_color(0, 0, 0, 1)
diff --git a/prj.org b/prj.org
index e3e806c888b0148d4f0c5ea2d29d5a0793aa51a0..2b869cd40d270fd609e2581868f4a80629b6e330 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -1,8 +1,9 @@
 * issues
 * todo
-** images for buttons
-** background
-** shelf's logics
+** objects placement
+** shelf's logics (rotation, scale)
+** buttons
+** magnet
 *  waiting
 ** version 0.0.yymmdd
 ** do intro video with moviepy