ya2 · news · projects · support us · follow us · lists · code · about

side panel
authorFlavio Calva <f.calva@gmail.com>
Tue, 11 Jan 2022 18:24:15 +0000 (19:24 +0100)
committerFlavio Calva <f.calva@gmail.com>
Tue, 11 Jan 2022 18:24:15 +0000 (19:24 +0100)
pmachines/items/background.py
pmachines/items/box.py
pmachines/pmachines.py
pmachines/scene.py
pmachines/sidepanel.py [new file with mode: 0644]
prj.org

index cdbb1d8dfc775f5858d42ddfc308b4ce46643e5a..60c7c1588801d10052a43b7e948331ba7a0babee 100644 (file)
@@ -7,7 +7,7 @@ class Background:
     def __init__(self):
         root = NodePath('background_root')
         root.reparent_to(render)
-        ncols, nrows = 12, 8
+        ncols, nrows = 16, 8
         start_size, end_size = 5, 2.5
         offset = 5
         for col, row in product(range(ncols), range(nrows)):
index d37d8ab277c17bb4111272b44347735dbfc99119..929756db62e40afa07b62f7037bfcf47b16df958 100644 (file)
@@ -35,7 +35,7 @@ class Box:
                 pos = hit.get_hit_pos()
         bounds = self._np.get_tight_bounds()
         bounds = bounds[0] - self._np.get_pos(), bounds[1] - self._np.get_pos()
-        margin = .3, .2
+        margin = .3, .3
         dpos = bounds[1][0] + margin[0], 0, -bounds[1][2] - margin[1]
         self._np.set_pos(pos + dpos)
         new_node = NodePath('temp')
index 7e309e5adef96eb1fbd1bfb249403ad6e6c4706e..fdd1fa097b25c96f3ca5e00357fe811065c59b29 100755 (executable)
@@ -65,6 +65,7 @@ class Pmachines:
             'settings': {
                 'volume': 1},
             'development': {
+                'simplepbr': 1,
                 'verbose_log': 0,
                 'physics_debug': 0}}
         opt_path = LibP3d.fixpath(data_path + '/' + optfile) if data_path else optfile
@@ -75,11 +76,12 @@ class Pmachines:
         if not opt_exists:
             self._options.store()
         gltf.patch_loader(base.loader)
-        pipeline = simplepbr.init(
-            use_normal_maps=True,
-            use_emission_maps=False,
-            use_occlusion_maps=True,
-            msaa_samples=4)
+        if self._options['development']['simplepbr']:
+            pipeline = simplepbr.init(
+                use_normal_maps=True,
+                use_emission_maps=False,
+                use_occlusion_maps=True
+            )
         render.setAntialias(AntialiasAttrib.MAuto)
         self.base.set_background_color(0, 0, 0, 1)
         self.base.disable_mouse()
index 339a452b34e6098b02dc6c53e28cc194c9f07787..77e980aa58d44fb523989bdb50ffb1ed3e2e6213 100644 (file)
@@ -6,6 +6,7 @@ from direct.gui.DirectGuiGlobals import FLAT, DISABLED, NORMAL
 from direct.showbase.DirectObject import DirectObject
 from pmachines.items.background import Background
 from pmachines.items.box import Box
+from pmachines.sidepanel import SidePanel
 from lib.engine.gui.cursor import MouseCursor
 
 
@@ -24,6 +25,7 @@ class Scene(DirectObject):
         self._set_mouse_plane()
         Background()
         self.items = [Box(world, self._mouse_plane_node, 3, self.cb_inst)]
+        self._side_panel = SidePanel(world, self._mouse_plane_node, (-5, 4), (-3, 1), 1)
         taskMgr.add(self.on_frame, 'on_frame')
 
     def _set_camera(self):
@@ -139,6 +141,7 @@ class Scene(DirectObject):
 
     def on_aspect_ratio_changed(self):
         [item.on_aspect_ratio_changed() for item in self.items]
+        self._side_panel.update(self.items)
 
     def on_frame(self, task):
         hits = self._get_hits()
diff --git a/pmachines/sidepanel.py b/pmachines/sidepanel.py
new file mode 100644 (file)
index 0000000..b27f196
--- /dev/null
@@ -0,0 +1,107 @@
+from textwrap import dedent
+from panda3d.core import GeomVertexData, GeomVertexFormat, Geom, \
+    GeomVertexWriter, GeomTriangles, GeomNode, Shader, Point3
+
+
+class SidePanel:
+
+    def __init__(self, world, plane_node, top_l, bottom_r, y):
+        self._world = world
+        self._plane_node = plane_node
+        self._set(top_l, bottom_r, y)
+
+    def update(self, items):
+        p_from, p_to = Point3(), Point3()    # in camera coordinates
+        base.camLens.extrude((-1, 1), p_from, p_to)
+        p_from = render.get_relative_point(base.cam, p_from)  # global coords
+        p_to = render.get_relative_point(base.cam, p_to)  # global coords
+        for hit in self._world.ray_test_all(p_from, p_to).get_hits():
+            if hit.get_node() == self._plane_node:
+                pos = hit.get_hit_pos()
+        top_l = pos[0] - .8, pos[2] + .8
+        bottom_r = pos[0], pos[2]
+        y = 1
+        for item in items:
+            if not item._instantiated:
+                bounds = item._np.get_tight_bounds()
+                if bounds[1][0] > bottom_r[0]:
+                    bottom_r = bounds[1][0], bottom_r[1]
+                if bounds[0][2] < bottom_r[1]:
+                    bottom_r = bottom_r[0], bounds[0][2]
+                if bounds[1][1] > y:
+                    y = bounds[1][1]
+                bottom_r = bottom_r[0] + .3, bottom_r[1] - .3
+        self._set(top_l, bottom_r, y)
+
+    def _set(self, top_l, bottom_r, y):
+        if hasattr(self, '_np'):
+            self._np.remove_node()
+        vdata = GeomVertexData('quad', GeomVertexFormat.get_v3(), Geom.UHStatic)
+        vdata.setNumRows(2)
+        vertex = GeomVertexWriter(vdata, 'vertex')
+        vertex.add_data3(bottom_r[0], y, bottom_r[1])
+        vertex.add_data3(bottom_r[0], y, top_l[1])
+        vertex.add_data3(top_l[0], y, top_l[1])
+        vertex.add_data3(top_l[0], y, bottom_r[1])
+        prim = GeomTriangles(Geom.UHStatic)
+        prim.add_vertices(0, 1, 2)
+        prim.add_vertices(0, 2, 3)
+        prim.close_primitive()
+        geom = Geom(vdata)
+        geom.add_primitive(prim)
+        node = GeomNode('gnode')
+        node.add_geom(geom)
+        self._np = render.attach_new_node(node)
+        self._np.setTransparency(True)
+        vert = '''\
+            #version 150
+            uniform mat4 p3d_ModelViewProjectionMatrix;
+            in vec4 p3d_Vertex;
+            void main() {
+                gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex; }'''
+        frag = '''\
+            #version 150
+            out vec4 p3d_FragColor;
+            void main() {
+                p3d_FragColor = vec4(.04, .04, .04, .06); }'''
+        self._np.set_shader(Shader.make(Shader.SL_GLSL, dedent(vert), dedent(frag)))
+        # mat = Material()
+        # mat.set_base_color((1, 1, 1, 1))
+        # mat.set_emission((1, 1, 1, 1))
+        # mat.set_metallic(.5)
+        # mat.set_roughness(.5)
+        # np.set_material(mat)
+        # texture_sz = 64
+        # base_color_pnm = PNMImage(texture_sz, texture_sz)
+        # base_color_pnm.fill(.1, .1, .1)
+        # base_color_pnm.add_alpha()
+        # base_color_pnm.alpha_fill(.04)
+        # base_color_tex = Texture('base color')
+        # base_color_tex.load(base_color_pnm)
+        # ts = TextureStage('base color')
+        # ts.set_mode(TextureStage.M_modulate)
+        # np.set_texture(ts, base_color_tex)
+        # emission_pnm = PNMImage(texture_sz, texture_sz)
+        # emission_pnm.fill(0, 0, 0)
+        # emission_tex = Texture('emission')
+        # emission_tex.load(emission_pnm)
+        # ts = TextureStage('emission')
+        # ts.set_mode(TextureStage.M_emission)
+        # np.set_texture(ts, emission_tex)
+        # metal_rough_pnm = PNMImage(texture_sz, texture_sz)
+        # ambient_occlusion = 1
+        # roughness = .5
+        # metallicity = .5
+        # metal_rough_pnm.fill(ambient_occlusion, roughness, metallicity)
+        # metal_rough_tex = Texture('ao metal roughness')
+        # metal_rough_tex.load(metal_rough_pnm)
+        # ts = TextureStage('ao metal roughness')
+        # ts.set_mode(TextureStage.M_selector)
+        # np.set_texture(ts, metal_rough_tex)
+        # normal_pnm = PNMImage(texture_sz, texture_sz)
+        # normal_pnm.fill(.5, .5, .1)
+        # normal_tex = Texture('normals')
+        # normal_tex.load(normal_pnm)
+        # ts = TextureStage('normals')
+        # ts.set_mode(TextureStage.M_normal)
+        # np.set_texture(ts, normal_tex)
diff --git a/prj.org b/prj.org
index d09a51fe48a25e7003d1f966e235f513717f8c33..68d6d246dbfa28a82c965c9daba471f9a37c9d73 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -1,6 +1,6 @@
 * issues
 * todo
-** make a semi-transparent plane under the instantiable items
+** place the instantiable and the bg-panel considering 2d margins
 ** manage the physics of the to-be-instantiated with a ghost
 ** instructions
 ** main menu
@@ -8,9 +8,9 @@
 ** create one level per item, then levels with more items
 *** e.g. item1, item2, item1+2, item3, item1+2+3, ...
 ** build pipeline
-** magnet
-*  waiting
 ** version 0.0.yymmdd
 ** do intro video with moviepy
+** magnet
+*  waiting
 ** itch.io's client works with wine: functional tests for windows-itch.io
 * maybe/someday