[Bf-extensions-cvs] [2f1fe59d] blender2.8: Snap Utilities Line: Adapt to the use of Gizmos in order to start drawing the Tool without waiting for input

mano-wii noreply at git.blender.org
Thu Nov 1 04:34:08 CET 2018


Commit: 2f1fe59d88db13d2a51d2d23617f9e19f54cf9f1
Author: mano-wii
Date:   Thu Nov 1 00:33:29 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBA2f1fe59d88db13d2a51d2d23617f9e19f54cf9f1

Snap Utilities Line: Adapt to the use of Gizmos in order to start drawing the Tool without waiting for input

===================================================================

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/common_classes.py
M	mesh_snap_utilities_line/ops_line.py

===================================================================

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index 9811bfb9..0aedab1f 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -33,6 +33,7 @@ if "bpy" in locals():
     import importlib
     importlib.reload(preferences)
     importlib.reload(ops_line)
+    importlib.reload(common_classes)
 else:
     from . import preferences
     from . import ops_line
@@ -64,11 +65,11 @@ def tool_make_line():
             "Connect them to split faces"
         ),
         icon=os.path.join(icons_dir, "ops.mesh.make_line"),
-        widget=None,
+        widget="MESH_GGT_mouse_point",
         operator="mesh.make_line",
-        keymap=(
-            ("mesh.make_line", None, dict(type='ACTIONMOUSE', value='PRESS')),
-        ),
+#        keymap=(
+#            ("mesh.make_line", dict(wait_for_input=False), dict(type='ACTIONMOUSE', value='PRESS')),
+#        ),
         draw_settings=draw_settings,
     )
 
@@ -81,6 +82,8 @@ def register():
 
     bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences)
     bpy.utils.register_class(ops_line.SnapUtilitiesLine)
+    bpy.utils.register_class(common_classes.MousePointWidget)
+    bpy.utils.register_class(common_classes.MousePointWidgetGroup)
 
     bpy.utils.register_tool('VIEW_3D', 'EDIT_MESH', tool_make_line)
 
@@ -94,6 +97,8 @@ def register():
 def unregister():
     bpy.utils.unregister_tool('VIEW_3D', 'EDIT_MESH', tool_make_line)
 
+    bpy.utils.unregister_class(common_classes.MousePointWidgetGroup)
+    bpy.utils.unregister_class(common_classes.MousePointWidget)
     bpy.utils.unregister_class(ops_line.SnapUtilitiesLine)
     bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences)
 
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index 09fc3a02..9a968862 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -20,6 +20,8 @@ import bgl
 import gpu
 import numpy as np
 
+from .common_utilities import snap_utilities
+
 
 class SnapDrawn():
     def __init__(self, out_color, face_color,
@@ -161,19 +163,20 @@ class SnapDrawn():
         gpu.matrix.multiply_matrix(snap_obj.mat)
 
         if isinstance(elem, BMVert):
-            color = self.vert_color
-            edges = np.empty((len(elem.link_edges), 2), [("pos", "f4", 3), ("color", "f4", 4)])
-            edges["pos"][:, 0] = elem.co
-            edges["pos"][:, 1] = [e.other_vert(elem).co for e in elem.link_edges]
-            edges["color"][:, 0] = color
-            edges["color"][:, 1] = (color[0], color[1], color[2], 0.0)
-            edges.shape = -1
-
-            self._program_smooth_col.bind()
-            bgl.glLineWidth(3.0)
-            batch = self.batch_lines_smooth_color_create(edges["pos"], edges["color"])
-            batch.draw(self._program_smooth_col)
-            bgl.glLineWidth(1.0)
+            if elem.link_edges:
+                color = self.vert_color
+                edges = np.empty((len(elem.link_edges), 2), [("pos", "f4", 3), ("color", "f4", 4)])
+                edges["pos"][:, 0] = elem.co
+                edges["pos"][:, 1] = [e.other_vert(elem).co for e in elem.link_edges]
+                edges["color"][:, 0] = color
+                edges["color"][:, 1] = (color[0], color[1], color[2], 0.0)
+                edges.shape = -1
+
+                self._program_smooth_col.bind()
+                bgl.glLineWidth(3.0)
+                batch = self.batch_lines_smooth_color_create(edges["pos"], edges["color"])
+                batch.draw(self._program_smooth_col)
+                bgl.glLineWidth(1.0)
         else:
             self._program_unif_col.bind()
 
@@ -332,3 +335,104 @@ class CharMap:
             elif event.type == 'RIGHT_ARROW':
                 self.line_pos = (self.line_pos + 1) % (len(self.length_entered) + 1)
 
+
+class MousePointWidget(bpy.types.Gizmo):
+    bl_idname = "VIEW3D_GT_mouse_point"
+
+    __slots__ = (
+        "sctx",
+        "bm",
+        "draw_cache",
+        "geom",
+        "incremental",
+        "preferences",
+        "loc",
+        "snap_obj",
+        "snap_to_grid",
+        "type",
+    )
+
+    def test_select(self, context, mval):
+        #print('test_select', mval)
+        self.snap_obj, prev_loc, self.loc, self.type, self.bm, self.geom, len = snap_utilities(
+                self.sctx,
+                None,
+                mval,
+                increment=self.incremental
+        )
+        context.area.tag_redraw()
+        return False
+
+    def draw(self, context):
+        if self.bm:
+            self.draw_cache.draw_elem(self.snap_obj, self.bm, self.geom)
+        self.draw_cache.draw(self.type, self.loc, None, None, None)
+
+    def setup(self):
+        if not hasattr(self, "sctx"):
+            context = bpy.context
+
+            self.preferences = preferences = context.user_preferences.addons[__package__].preferences
+
+            #Configure the unit of measure
+            self.snap_to_grid = preferences.increments_grid
+            self.incremental = bpy.utils.units.to_value(
+                    context.scene.unit_settings.system, 'LENGTH', str(preferences.incremental))
+
+            self.draw_cache = SnapDrawn(
+                preferences.out_color,
+                preferences.face_color,
+                preferences.edge_color,
+                preferences.vert_color,
+                preferences.center_color,
+                preferences.perpendicular_color,
+                preferences.constrain_shift_color,
+                (*context.user_preferences.themes[0].user_interface.axis_x, 1.0),
+                (*context.user_preferences.themes[0].user_interface.axis_y, 1.0),
+                (*context.user_preferences.themes[0].user_interface.axis_z, 1.0)
+            )
+
+            #Init Snap Context
+            from .snap_context_l import SnapContext
+            from mathutils import Vector
+
+            self.sctx = SnapContext(context.region, context.space_data)
+            self.sctx.set_pixel_dist(12)
+            self.sctx.use_clip_planes(True)
+
+            if preferences.outer_verts:
+                for base in context.visible_bases:
+                    self.sctx.add_obj(base.object, base.object.matrix_world)
+
+            self.sctx.set_snap_mode(True, True, True)
+            self.bm = None
+            self.type = 'OUT'
+            self.loc = Vector()
+
+    def __del__(self):
+        self.sctx.free()
+        del self.draw_cache
+
+
+class MousePointWidgetGroup(bpy.types.GizmoGroup):
+    bl_idname = "MESH_GGT_mouse_point"
+    bl_label = "Draw Mouse Point"
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'WINDOW'
+    bl_options = {'3D'}
+
+    __slots__ = (
+        "snap_widget",
+    )
+
+    def setup(self, context):
+        if not hasattr(self, "snap_widget"):
+            self.snap_widget = self.gizmos.new(MousePointWidget.bl_idname)
+            props = self.snap_widget.target_set_operator("mesh.make_line")
+            props.wait_for_input = False
+
+            b_sctx_ptr = id(self.snap_widget).to_bytes(8, 'big')
+            props.snap_widget_ptr[0] = int.from_bytes(b_sctx_ptr[0:2], 'big')
+            props.snap_widget_ptr[1] = int.from_bytes(b_sctx_ptr[2:4], 'big')
+            props.snap_widget_ptr[2] = int.from_bytes(b_sctx_ptr[4:6], 'big')
+            props.snap_widget_ptr[3] = int.from_bytes(b_sctx_ptr[6:8], 'big')
diff --git a/mesh_snap_utilities_line/ops_line.py b/mesh_snap_utilities_line/ops_line.py
index 2fe01ef9..ecef5a86 100644
--- a/mesh_snap_utilities_line/ops_line.py
+++ b/mesh_snap_utilities_line/ops_line.py
@@ -83,12 +83,12 @@ def draw_line(self, bm_geom, location):
     bm = self.main_bm
     split_faces = set()
 
-    drawing_is_dirt = False
     update_edit_mesh = False
 
     if bm_geom is None:
         vert = bm.verts.new(location)
         self.list_verts.append(vert)
+        update_edit_mesh = True
 
     elif isinstance(bm_geom, bmesh.types.BMVert):
         if (bm_geom.co - location).length_squared < .001:
@@ -97,7 +97,7 @@ def draw_line(self, bm_geom, location):
         else:
             vert = bm.verts.new(location)
             self.list_verts.append(vert)
-            drawing_is_dirt = True
+            update_edit_mesh = True
 
     elif isinstance(bm_geom, bmesh.types.BMEdge):
         self.list_edges.append(bm_geom)
@@ -110,7 +110,8 @@ def draw_line(self, bm_geom, location):
                 vert = bm_geom.verts[1]
             else:
                 edge, vert = bmesh.utils.edge_split(bm_geom, bm_geom.verts[0], ret[1])
-                drawing_is_dirt = True
+                update_edit_mesh = True
+
             self.list_verts.append(vert)
             self.geom = vert # hack to highlight in the drawing
             # self.list_edges.append(edge)
@@ -118,27 +119,25 @@ def draw_line(self, bm_geom, location):
         else:  # constrain point is near
             vert = bm.verts.new(location)
             self.list_verts.append(vert)
-            drawing_is_dirt = True
+            update_edit_mesh = True
 
     elif isinstance(bm_geom, bmesh.types.BMFace):
         split_faces.add(bm_geom)
         vert = bm.verts.new(location)
         self.list_verts.append(vert)
-        drawing_is_dirt = True
+        update_edit_mesh = True
 
     # draw, split and create face
     if len(self.list_verts) >= 2:
         v1, v2 = self.list_verts[-2:]
-        # v2_link_verts = [x for y in [a.verts for a in v2.link_edges] for x in y if x != v2]
         edge = bm.edges.get([v1, v2])
         if edge:
                 self.list_edges.append(edge)
 
-        else:  # if v1 not in v2_link_verts:
+        else:
             if not v2.link_edges:
                 edge = bm.edges.new([v1, v2])
                 self.list_edges.append(edge)
-                drawing_is_dirt = True
             else:  # split face
                 v1_link_faces = v1.link_faces
                 v2_link_faces = v2.link_faces
@@ -166,7 +165,6 @@ def draw_line(self, bm_geom, location):
                     for face in split_faces:
                         facesp = bmesh.utils.face_split_edgenet(face, ed_list)
        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list