[Bf-extensions-cvs] [93cd3f9a] master: mesh_snap_utilities_line: Cleanup

mano-wii noreply at git.blender.org
Sun Feb 10 15:21:09 CET 2019


Commit: 93cd3f9a9be7f97b150d7d9b58a9506bd9a0fbe3
Author: mano-wii
Date:   Sun Feb 10 11:19:32 2019 -0200
Branches: master
https://developer.blender.org/rBA93cd3f9a9be7f97b150d7d9b58a9506bd9a0fbe3

mesh_snap_utilities_line: Cleanup

Rename files, and split the `common_classes.py` file into `drawing_utilities.py`, `navigation_ops.py` and `widgets.py`

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

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/common_classes.py
M	mesh_snap_utilities_line/common_utilities.py
A	mesh_snap_utilities_line/drawing_utilities.py
A	mesh_snap_utilities_line/navigation_ops.py
R098	mesh_snap_utilities_line/ops_line.py	mesh_snap_utilities_line/op_line.py
M	mesh_snap_utilities_line/preferences.py
M	mesh_snap_utilities_line/snap_context_l/__init__.py
A	mesh_snap_utilities_line/widgets.py

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

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index dc086540..be37d8a0 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -22,22 +22,24 @@
 bl_info = {
     "name": "Snap_Utilities_Line",
     "author": "Germano Cavalcante",
-    "version": (5, 9, 00),
+    "version": (5, 9, 1),
     "blender": (2, 80, 0),
     "location": "View3D > TOOLS > Line Tool",
     "description": "Extends Blender Snap controls",
-    #"wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities",
+    "wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities",
     "category": "Mesh"}
 
 if "bpy" in locals():
     import importlib
-    importlib.reload(common_classes)
+    importlib.reload(navigation_ops)
+    importlib.reload(widgets)
     importlib.reload(preferences)
-    importlib.reload(ops_line)
+    importlib.reload(op_line)
 else:
-    from . import common_classes
+    from . import navigation_ops
+    from . import widgets
     from . import preferences
-    from . import ops_line
+    from . import op_line
 
 import bpy
 from bpy.utils.toolsystem import ToolDef
@@ -105,7 +107,7 @@ def register_snap_tools():
 
     tools[:index] += None, tool_line
 
-    del tool, tools, index
+    del tools, index
 
     keyconfigs = bpy.context.window_manager.keyconfigs
     kc_defaultconf = keyconfigs.get("blender")
@@ -144,11 +146,11 @@ def unregister_snap_tools():
 
 classes = (
     preferences.SnapUtilitiesPreferences,
-    ops_line.SnapUtilitiesLine,
-    common_classes.VIEW3D_OT_rotate_custom_pivot,
-    common_classes.VIEW3D_OT_zoom_custom_target,
-    common_classes.SnapPointWidget,
-    common_classes.SnapPointWidgetGroup,
+    op_line.SnapUtilitiesLine,
+    navigation_ops.VIEW3D_OT_rotate_custom_pivot,
+    navigation_ops.VIEW3D_OT_zoom_custom_target,
+    widgets.SnapPointWidget,
+    widgets.SnapPointWidgetGroup,
 )
 
 def register():
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index a096415d..6ad150c4 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -16,222 +16,15 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import bgl
 
 from mathutils import Vector
-
+from .drawing_utilities import SnapDrawn
 from .common_utilities import (
     convert_distance,
     get_units_info,
-    snap_utilities,
     )
 
 
-class SnapDrawn():
-    def __init__(self, out_color, face_color,
-                 edge_color, vert_color, center_color,
-                 perpendicular_color, constrain_shift_color,
-                 axis_x_color, axis_y_color, axis_z_color):
-
-        import gpu
-
-        self.out_color = out_color
-        self.face_color = face_color
-        self.edge_color = edge_color
-        self.vert_color = vert_color
-        self.center_color = center_color
-        self.perpendicular_color = perpendicular_color
-        self.constrain_shift_color = constrain_shift_color
-
-        self.axis_x_color = axis_x_color
-        self.axis_y_color = axis_y_color
-        self.axis_z_color = axis_z_color
-
-        self._format_pos = gpu.types.GPUVertFormat()
-        self._format_pos.attr_add(id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
-
-        self._format_pos_and_color = gpu.types.GPUVertFormat()
-        self._format_pos_and_color.attr_add(id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
-        self._format_pos_and_color.attr_add(id="color", comp_type='F32', len=4, fetch_mode='FLOAT')
-
-        self._program_unif_col = gpu.shader.from_builtin("3D_UNIFORM_COLOR")
-        self._program_smooth_col = gpu.shader.from_builtin("3D_SMOOTH_COLOR")
-
-        self._batch_point = None
-
-
-    def batch_line_strip_create(self, coords):
-        from gpu.types import (
-            GPUVertBuf,
-            GPUBatch,
-        )
-
-        vbo = GPUVertBuf(self._format_pos, len = len(coords))
-        vbo.attr_fill(0, data = coords)
-        batch_lines = GPUBatch(type = "LINE_STRIP", buf = vbo)
-        return batch_lines
-
-    def batch_lines_smooth_color_create(self, coords, colors):
-        from gpu.types import (
-            GPUVertBuf,
-            GPUBatch,
-        )
-
-        vbo = GPUVertBuf(self._format_pos_and_color, len = len(coords))
-        vbo.attr_fill(0, data = coords)
-        vbo.attr_fill(1, data = colors)
-        batch_lines = GPUBatch(type = "LINES", buf = vbo)
-        return batch_lines
-
-    def batch_triangles_create(self, coords):
-        from gpu.types import (
-            GPUVertBuf,
-            GPUBatch,
-        )
-
-        vbo = GPUVertBuf(self._format_pos, len = len(coords))
-        vbo.attr_fill(0, data = coords)
-        batch_tris = GPUBatch(type = "TRIS", buf = vbo)
-        return batch_tris
-
-    def batch_point_get(self):
-        if self._batch_point is None:
-            from gpu.types import (
-                GPUVertBuf,
-                GPUBatch,
-            )
-            vbo = GPUVertBuf(self._format_pos, len = 1)
-            vbo.attr_fill(0, ((0.0, 0.0, 0.0),))
-            self._batch_point = GPUBatch(type = "POINTS", buf = vbo)
-        return self._batch_point
-
-    def draw(self, type, location, list_verts_co, vector_constrain, prevloc):
-        import gpu
-
-        # draw 3d point OpenGL in the 3D View
-        bgl.glEnable(bgl.GL_BLEND)
-        gpu.matrix.push()
-        self._program_unif_col.bind()
-
-        if list_verts_co:
-            # draw 3d line OpenGL in the 3D View
-            bgl.glDepthRange(0, 0.9999)
-            bgl.glLineWidth(3.0)
-
-            batch = self.batch_line_strip_create([v.to_tuple() for v in list_verts_co] + [location.to_tuple()])
-
-            self._program_unif_col.uniform_float("color", (1.0, 0.8, 0.0, 0.5))
-            batch.draw(self._program_unif_col)
-            del batch
-
-        bgl.glDisable(bgl.GL_DEPTH_TEST)
-
-        point_batch = self.batch_point_get()
-        if vector_constrain:
-            if prevloc:
-                bgl.glPointSize(5)
-                gpu.matrix.translate(prevloc)
-                self._program_unif_col.uniform_float("color", (1.0, 1.0, 1.0, 0.5))
-                point_batch.draw(self._program_unif_col)
-                gpu.matrix.translate(-prevloc)
-
-            if vector_constrain[2] == 'X':
-                Color4f = self.axis_x_color
-            elif vector_constrain[2] == 'Y':
-                Color4f = self.axis_y_color
-            elif vector_constrain[2] == 'Z':
-                Color4f = self.axis_z_color
-            else:
-                Color4f = self.constrain_shift_color
-        else:
-            if type == 'OUT':
-                Color4f = self.out_color
-            elif type == 'FACE':
-                Color4f = self.face_color
-            elif type == 'EDGE':
-                Color4f = self.edge_color
-            elif type == 'VERT':
-                Color4f = self.vert_color
-            elif type == 'CENTER':
-                Color4f = self.center_color
-            elif type == 'PERPENDICULAR':
-                Color4f = self.perpendicular_color
-            else: # type == None
-                Color4f = self.out_color
-
-        bgl.glPointSize(10)
-
-        gpu.matrix.translate(location)
-        self._program_unif_col.uniform_float("color", Color4f)
-        point_batch.draw(self._program_unif_col)
-
-        # restore opengl defaults
-        bgl.glDepthRange(0.0, 1.0)
-        bgl.glPointSize(1.0)
-        bgl.glLineWidth(1.0)
-        bgl.glEnable(bgl.GL_DEPTH_TEST)
-        bgl.glDisable(bgl.GL_BLEND)
-
-        gpu.matrix.pop()
-
-    def draw_elem(self, snap_obj, bm, elem):
-        #TODO: Cache coords (because antialiasing)
-        import gpu
-        from bmesh.types import(
-            BMVert,
-            BMEdge,
-            BMFace,
-        )
-        # draw 3d point OpenGL in the 3D View
-        bgl.glEnable(bgl.GL_BLEND)
-        bgl.glDisable(bgl.GL_DEPTH_TEST)
-
-        with gpu.matrix.push_pop():
-            gpu.matrix.multiply_matrix(snap_obj.mat)
-
-            if isinstance(elem, BMVert):
-                if elem.link_edges:
-                    import numpy as np
-
-                    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()
-
-                if isinstance(elem, BMEdge):
-                    self._program_unif_col.uniform_float("color", self.edge_color)
-
-                    bgl.glLineWidth(3.0)
-                    batch = self.batch_line_strip_create([v.co for v in elem.verts])
-                    batch.draw(self._program_unif_col)
-                    bgl.glLineWidth(1.0)
-
-                elif isinstance(elem, BMFace):
-                    if len(snap_obj.data) == 2:
-                        face_color = self.face_color[0], self.face_color[1], self.face_color[2], self.face_color[3] * 0.2
-                        self._program_unif_col.uniform_float("color", face_color)
-
-                        tris = snap_obj.data[1].get_loop_tri_co_by_bmface(bm, elem)
-                        tris.shape = (-1, 3)
-                        batch = self.batch_triangles_create(tris)
-                        batch.draw(self._program_unif_col)
-
-            # restore opengl defaults
-            bgl.glEnable(bgl.GL_DEPTH_TEST)
-            bgl.glDisable(bgl.GL_BLEND)
-
-
 class SnapNavigation():
     @staticmethod
     def debug_key(key):
@@ -4

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list