[Bf-extensions-cvs] [541840f9] master: Curve Tools: Fixed bugs. Added spline sequence change

Spivak Vladimir cwolf3d noreply at git.blender.org
Mon Sep 16 00:35:04 CEST 2019


Commit: 541840f949d279e4c9ef7ec06d3aeed7ed29530c
Author: Spivak Vladimir (cwolf3d)
Date:   Mon Sep 16 01:34:28 2019 +0300
Branches: master
https://developer.blender.org/rBA541840f949d279e4c9ef7ec06d3aeed7ed29530c

Curve Tools: Fixed bugs. Added spline sequence change

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

M	curve_tools/PathFinder.py
M	curve_tools/ShowCurveResolution.py
A	curve_tools/SplinesSequence.py
M	curve_tools/__init__.py

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

diff --git a/curve_tools/PathFinder.py b/curve_tools/PathFinder.py
index 2f661382..4df49c41 100644
--- a/curve_tools/PathFinder.py
+++ b/curve_tools/PathFinder.py
@@ -18,7 +18,7 @@
 
 bl_info = {
     'name': 'PathFinder',
-    'author': 'Spivak Vladimir (http://cwolf3d.korostyshev.net)',
+    'author': 'Spivak Vladimir (cwolf3d)',
     'version': (0, 5, 0),
     'blender': (2, 80, 0),
     'location': 'Curve Tools addon. (N) Panel',
@@ -225,7 +225,16 @@ def click(self, context, event):
                     self.handlers.append(bpy.types.SpaceView3D.draw_handler_add(draw_points, args, 'WINDOW', 'POST_VIEW'))
                         
                     for point in spline.points:
-                        point.select = True    
+                        point.select = True
+
+def remove_handler(handlers):
+    for handler in handlers:
+        try:
+            bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
+        except:
+            pass
+    for handler in handlers:
+        handlers.remove(handler)                        
 
 class PathFinder(bpy.types.Operator):
     bl_idname = "curvetools.pathfinder"
@@ -254,41 +263,32 @@ class PathFinder(bpy.types.Operator):
         context.area.tag_redraw()
         
         if event.type in {'ESC', 'TAB'}:  # Cancel
-            for handler in self.handlers:
-                try:
-                    bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
-                except:
-                    pass
-            for handler in self.handlers:
-                self.handlers.remove(handler)
-            self.report({'INFO'}, "PathFinder deactivated")
+            remove_handler(self.handlers)
             return {'CANCELLED'}
             
         if event.type in {'X', 'DEL'}:  # Cancel
-            for handler in self.handlers:
-                try:
-                    bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
-                except:
-                    pass
-            for handler in self.handlers:
-                self.handlers.remove(handler)
+            remove_handler(self.handlers)
             bpy.ops.curve.delete(type='VERT') 
             return {'RUNNING_MODAL'}         
         
-        elif event.alt and event.type == 'LEFTMOUSE':
+        elif event.alt and not event.shift and event.type == 'LEFTMOUSE':
+            remove_handler(self.handlers)
+            bpy.ops.curve.select_all(action='DESELECT')
+            click(self, context, event)
+            
+        elif event.alt and event.shift and event.type == 'LEFTMOUSE':
             click(self, context, event)
                                     
         elif event.alt and event.type == 'RIGHTMOUSE':
+           remove_handler(self.handlers)
+           bpy.ops.curve.select_all(action='DESELECT')
            click(self, context, event)
+
+        elif event.alt and not event.shift and event.shift and event.type == 'RIGHTMOUSE':
+            click(self, context, event)
             
         elif event.type == 'A':
-            for handler in self.handlers:
-                try:
-                    bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
-                except:
-                    pass
-            for handler in self.handlers:
-                self.handlers.remove(handler)
+            remove_handler(self.handlers)
             bpy.ops.curve.select_all(action='DESELECT')
             
         elif event.type == 'MOUSEMOVE':  # 
diff --git a/curve_tools/ShowCurveResolution.py b/curve_tools/ShowCurveResolution.py
index 97cf310e..69271704 100644
--- a/curve_tools/ShowCurveResolution.py
+++ b/curve_tools/ShowCurveResolution.py
@@ -22,7 +22,6 @@
 import bpy
 from bpy import *
 from bpy.props import *
-from bpy.types import AddonPreferences, PropertyGroup
 
 import bgl
 import blf
@@ -34,11 +33,7 @@ import mathutils
 from mathutils import Vector
 from mathutils.geometry import interpolate_bezier
 
-import bpy_extras
-from bpy_extras.view3d_utils import location_3d_to_region_2d as loc3d2d
 
- 
- 
 def get_points(spline, matrix_world):
 
     bezier_points = spline.bezier_points
@@ -47,6 +42,8 @@ def get_points(spline, matrix_world):
         return []
 
     r = spline.resolution_u + 1
+    if r < 2:
+       return []
     segments = len(bezier_points)
     
     if not spline.use_cyclic_u:
@@ -67,16 +64,18 @@ def get_points(spline, matrix_world):
  
     return point_list
  
-def draw(self, context, spline, curve_vertcolor, matrix_world):
-    
-    points = get_points(spline, matrix_world)
+def draw(self, context, splines, curve_vertcolor, matrix_world):
     
-    shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
-    batch = batch_for_shader(shader, 'POINTS', {"pos": points})
+    for spline in splines:
+        points = get_points(spline, matrix_world)
+        
+        shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
+
+        batch = batch_for_shader(shader, 'POINTS', {"pos": points})
     
-    shader.bind()
-    shader.uniform_float("color", curve_vertcolor)
-    batch.draw(shader)
+        shader.bind()
+        shader.uniform_float("color", curve_vertcolor)
+        batch.draw(shader)
 
 
 class ShowCurveResolution(bpy.types.Operator):
@@ -109,17 +108,15 @@ class ShowCurveResolution(bpy.types.Operator):
             # color change in the panel
             curve_vertcolor = bpy.context.scene.curvetools.curve_vertcolor
             
-            # the arguments we pass the the callback
-            
-            
             splines = context.active_object.data.splines
             matrix_world = context.active_object.matrix_world
-            for spline in splines:
-                args = (self, context, spline, curve_vertcolor, matrix_world)
             
-                # Add the region OpenGL drawing callback
-                # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
-                self.handlers.append(bpy.types.SpaceView3D.draw_handler_add(draw, args, 'WINDOW', 'POST_VIEW'))
+            # the arguments we pass the the callback
+            args = (self, context, splines, curve_vertcolor, matrix_world)
+            
+            # Add the region OpenGL drawing callback
+            # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
+            self.handlers.append(bpy.types.SpaceView3D.draw_handler_add(draw, args, 'WINDOW', 'POST_VIEW'))
 
             context.window_manager.modal_handler_add(self)
             return {'RUNNING_MODAL'}
@@ -127,3 +124,8 @@ class ShowCurveResolution(bpy.types.Operator):
             self.report({'WARNING'}, 
             "View3D not found, cannot run operator")
             return {'CANCELLED'}
+            
+    @classmethod
+    def poll(cls, context):
+        return (context.object is not None and
+                context.object.type == 'CURVE')
diff --git a/curve_tools/SplinesSequence.py b/curve_tools/SplinesSequence.py
new file mode 100644
index 00000000..c64ceec1
--- /dev/null
+++ b/curve_tools/SplinesSequence.py
@@ -0,0 +1,275 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and / or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+#
+
+
+import bpy
+
+import bgl
+import blf
+import gpu
+from gpu_extras.batch import batch_for_shader
+
+import math
+import mathutils
+from mathutils import Vector
+
+from bpy.props import (
+        EnumProperty,
+        )
+
+# ------------------------------------------------------------
+# ShowSplinesSequence
+
+def draw_number(n, co, font_height):
+
+    point_list = []
+    
+    numeral = [
+              [Vector((0, 0, 0)), Vector((0, 2, 0)), Vector((0, 2, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((1, 0, 0)), Vector((1, 0, 0)), Vector((0, 0, 0))],
+              [Vector((0, 1, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((1, 0, 0))],
+              [Vector((0, 2, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((1, 1, 0)), Vector((1, 1, 0)), Vector((0, 0, 0)), Vector((0, 0, 0)), Vector((1, 0, 0))],
+              [Vector((0, 2, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((1, 1, 0)), Vector((1, 1, 0)), Vector((0, 0, 0))],
+              [Vector((0, 2, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((1, 1, 0)), Vector((1, 1, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((1, 0, 0))],
+              [Vector((1, 2, 0)), Vector((0, 2, 0)), Vector((0, 2, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((1, 1, 0)), Vector((1, 1, 0)), Vector((1, 0, 0)), Vector((1, 0, 0)), Vector((0, 0, 0))],
+              [Vector((1, 2, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((0, 0, 0)), Vector((0, 0, 0)), Vector((1, 0, 0)), Vector((1, 0, 0)), Vector((1, 1, 0)), Vector((1, 1, 0)), Vector((0, 1, 0))],
+              [Vector((0, 2, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((0, 0, 0))],
+              [Vector((0, 1, 0)), Vector((0, 2, 0)), Vector((0, 2, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((1, 0, 0)), Vector((1, 0, 0)), Vector((0, 0, 0)), Vector((0, 0, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((1, 1, 0))],
+              [Vector((0, 0, 0)), Vector((1, 1, 0)), Vector((1, 1, 0)), Vector((1, 2, 0)), Vector((1, 2, 0)), Vector((0, 2, 0)), Vector((0, 2, 0)), Vector((0, 1, 0)), Vector((0, 1, 0)), Vector((1, 1, 0))],
+              ]
+    
+    for num in numeral[n]:
+        point_list.extend([num * font_height + co])
+    
+    return point_list
+
+ 
+def draw(self, context, splines, sequence_color, font_thickness, font_size, matrix_world):

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list