[Bf-extensions-cvs] [7077ff07] master: xedit: set meas fixes, update free rotate for 2.80

NBurn noreply at git.blender.org
Tue May 28 11:30:03 CEST 2019


Commit: 7077ff07384491d1f7630484995557f1c7302dae
Author: NBurn
Date:   Tue May 28 05:28:51 2019 -0400
Branches: master
https://developer.blender.org/rBAC7077ff07384491d1f7630484995557f1c7302dae

xedit: set meas fixes, update free rotate for 2.80

Set Measure and Free Rotate should now have most to all of their
original functionality back and Set Measure should now work better
with mulit-object-editing (thanks to Jacques Lucke, Stephen Leger,
and Campbell Barton). The custom Free Rotate menu drawn in the
3D View still needs updating.

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

M	exact_edit/__init__.py
M	exact_edit/xedit_free_rotate.py
M	exact_edit/xedit_set_meas.py

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

diff --git a/exact_edit/__init__.py b/exact_edit/__init__.py
index d99f1256..c9df3096 100644
--- a/exact_edit/__init__.py
+++ b/exact_edit/__init__.py
@@ -21,7 +21,7 @@ END GPL LICENSE BLOCK
 bl_info = {
     "name": "Exact Edit",
     "author": "nBurn",
-    "version": (0, 3, 0),
+    "version": (0, 3, 1),
     "blender": (2, 80, 0),
     "location": "View3D",
     "description": "Tool for precisely setting distance, scale, and rotation",
@@ -32,10 +32,10 @@ bl_info = {
 if "bpy" in locals():
     import importlib
     importlib.reload(xedit_set_meas)
-    #importlib.reload(xedit_free_rotate)  # not working yet
+    importlib.reload(xedit_free_rotate)  # beta testing...
 else:
     from . import xedit_set_meas
-    #from . import xedit_free_rotate  # not working yet
+    from . import xedit_free_rotate  # beta testing...
 
 import bpy
 
@@ -52,15 +52,16 @@ class XEDIT_PT_ui_pan(bpy.types.Panel):
     def draw(self, context):
         row = self.layout.row(align=True)
         col = row.column()
+        #col.operator("view3d.xedit_set_meas_op", text="Set Measure", icon="EDIT")
         col.operator("view3d.xedit_set_meas_op", text="Set Measure")
-        #col.operator("view3d.xedit_free_rotate_op", text="Free Rotate")  # not working yet
+        col.operator("view3d.xedit_free_rotate_op", text="Free Rotate", icon="FORCE_MAGNETIC")  # not working yet
 
 
 classes = (
     xedit_set_meas.XEDIT_OT_store_meas_btn,
     xedit_set_meas.XEDIT_OT_meas_inp_dlg,
     xedit_set_meas.XEDIT_OT_set_meas,
-    #xedit_free_rotate.XEDIT_OT_free_rotate,  # not working yet
+    xedit_free_rotate.XEDIT_OT_free_rotate,  # beta testing...
     XEDIT_PT_ui_pan
 )
 
diff --git a/exact_edit/xedit_free_rotate.py b/exact_edit/xedit_free_rotate.py
index 10b4b15e..97dbde39 100644
--- a/exact_edit/xedit_free_rotate.py
+++ b/exact_edit/xedit_free_rotate.py
@@ -25,12 +25,14 @@ import bpy
 import bmesh
 import bgl
 import blf
-from mathutils import geometry, Euler, Quaternion, Vector
+import gpu
+from mathutils import geometry, Euler, Matrix, Quaternion, Vector
 from bpy_extras import view3d_utils
 from bpy_extras.view3d_utils import location_3d_to_region_2d as loc3d_to_reg2d
 from bpy_extras.view3d_utils import region_2d_to_vector_3d as reg2d_to_vec3d
 from bpy_extras.view3d_utils import region_2d_to_location_3d as reg2d_to_loc3d
 from bpy_extras.view3d_utils import region_2d_to_origin_3d as reg2d_to_org3d
+from gpu_extras.batch import batch_for_shader
 
 # "Constant" values
 (
@@ -85,32 +87,32 @@ def editmode_refresh():
 def backup_blender_settings():
     backup = [
         deepcopy(bpy.context.tool_settings.use_snap),
-        deepcopy(bpy.context.tool_settings.snap_element),
+        deepcopy(bpy.context.tool_settings.snap_elements),
         deepcopy(bpy.context.tool_settings.snap_target),
-        deepcopy(bpy.context.space_data.pivot_point),
-        deepcopy(bpy.context.space_data.transform_orientation),
-        deepcopy(bpy.context.space_data.show_manipulator),
+        deepcopy(bpy.context.tool_settings.transform_pivot_point),
+        deepcopy(bpy.context.scene.transform_orientation_slots[0].type),
+        deepcopy(bpy.context.space_data.show_gizmo),
         deepcopy(bpy.context.scene.cursor.location)]
     return backup
 
 
 def init_blender_settings():
     bpy.context.tool_settings.use_snap = False
-    bpy.context.tool_settings.snap_element = 'VERTEX'
+    bpy.context.tool_settings.snap_elements = {'VERTEX'}
     bpy.context.tool_settings.snap_target = 'CLOSEST'
-    bpy.context.space_data.pivot_point = 'ACTIVE_ELEMENT'
-    bpy.context.space_data.transform_orientation = 'GLOBAL'
-    bpy.context.space_data.show_manipulator = False
+    bpy.context.tool_settings.transform_pivot_point = 'ACTIVE_ELEMENT'
+    bpy.context.scene.transform_orientation_slots[0].type = 'GLOBAL'
+    bpy.context.space_data.show_gizmo = False
     return
 
 
 def restore_blender_settings(backup):
     bpy.context.tool_settings.use_snap = deepcopy(backup[0])
-    bpy.context.tool_settings.snap_element = deepcopy(backup[1])
+    bpy.context.tool_settings.snap_elements = deepcopy(backup[1])
     bpy.context.tool_settings.snap_target = deepcopy(backup[2])
-    bpy.context.space_data.pivot_point = deepcopy(backup[3])
-    bpy.context.space_data.transform_orientation = deepcopy(backup[4])
-    bpy.context.space_data.show_manipulator = deepcopy(backup[5])
+    bpy.context.tool_settings.transform_pivot_point = deepcopy(backup[3])
+    bpy.context.scene.transform_orientation_slots[0].type = deepcopy(backup[4])
+    bpy.context.space_data.show_gizmo = deepcopy(backup[5])
     bpy.context.scene.cursor.location = deepcopy(backup[6])
     return
 
@@ -131,9 +133,9 @@ def vec3s_alm_eq(vec_a, vec_b):
 
 
 # assume both float lists are same size?
-def flt_lists_alm_eq(ls_a, ls_b):
+def flt_lists_alm_eq(ls_a, ls_b, tol=0.001):
     for i in range(len(ls_a)):
-        if not flts_alm_eq(ls_a[i], ls_b[i]):
+        if not (ls_a[i] > (ls_b[i] - tol) and ls_a[i] < (ls_b[i] + tol)):
             return False
     return True
 
@@ -227,23 +229,33 @@ class MenuHandler:
         font_id = 0
         blf.size(font_id, self.tsize, self.dpi)
         # draw title
-        bgl.glColor4f(*self.dis_colr)
+        #bgl.glColor4f(*self.dis_colr)
         blf.position(font_id, self.titlco[0], self.titlco[1], 0)
+        blf.color(font_id, *self.dis_colr)
         blf.draw(font_id, self.title)
         # draw menu
         if menu_visible and menu is not None:
             for i in range(menu.cnt):
-                bgl.glColor4f(*menu.txtcolrs[i])
+                #bgl.glColor4f(*menu.txtcolrs[i])
                 blf.position(font_id, menu.tcoords[i][0], menu.tcoords[i][1], 0)
+                blf.color(font_id, *menu.txtcolrs[i])
                 blf.draw(font_id, menu.texts[i])
 
             # draw arrow
+            '''
             bgl.glEnable(bgl.GL_BLEND)
             bgl.glColor4f(*self.act_colr)
             bgl.glBegin(bgl.GL_LINE_LOOP)
             for p in menu.arrows[menu.active]:
                 bgl.glVertex2f(*p)
             bgl.glEnd()
+            '''
+            indices = ((0, 1), (1, 2), (2, 0))
+            shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
+            batch = batch_for_shader(shader, 'LINES', {"pos": menu.arrows[menu.active]}, indices=indices)
+            shader.bind()
+            shader.uniform_float("color", self.act_colr)
+            batch.draw(shader)
 
 
 # === 3D View mouse location and button code ===
@@ -310,7 +322,7 @@ class ViewButton():
         if my < self.ms_chk[2] or my > self.ms_chk[3]:
             return False
         return True
-    
+
     def draw_btn(self, btn_loc, mouse_co, highlight_mouse=False):
         if btn_loc is not None:
             offs_loc = btn_loc + self.offset
@@ -323,27 +335,46 @@ class ViewButton():
             else:
                 self.ms_over = False
             # draw button box
+            '''
             bgl.glColor4f(*colr)
             bgl.glBegin(bgl.GL_LINE_STRIP)
             for coord in self.coords:
                 bgl.glVertex2f(coord[0], coord[1])
             bgl.glVertex2f(self.coords[0][0], self.coords[0][1])
             bgl.glEnd()
+            '''
+            indc = ((0, 1), (1, 2), (2, 3), (3, 0))
+            shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
+            batch = batch_for_shader(shader, 'LINES', {"pos": self.coords}, indices=indc)
+            shader.bind()
+            shader.uniform_float("color", colr)
+            batch.draw(shader)
+
             # draw outline around button box
             if highlight_mouse and self.ms_over:
-                bgl.glColor4f(*self.colr_off)
+                #bgl.glColor4f(*self.colr_off)
                 HO = 4  # highlight_mouse offset
                 offs = (-HO, -HO), (-HO, HO), (HO, HO), (HO, -HO)
-                bgl.glBegin(bgl.GL_LINE_STRIP)
+                #bgl.glBegin(bgl.GL_LINE_STRIP)
+                off_co = []
                 for i, coord in enumerate(self.coords):
-                    bgl.glVertex2f(coord[0] + offs[i][0], coord[1] + offs[i][1])
-                bgl.glVertex2f(self.coords[0][0] + offs[0][0], self.coords[0][1] + offs[0][1])
-                bgl.glEnd()
+                    off_co.append((coord[0] + offs[i][0], coord[1] + offs[i][1]))
+                off_co.append((self.coords[0][0] + offs[0][0], self.coords[0][1] + offs[0][1]))
+
+                shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
+                batch = batch_for_shader(shader, 'LINES', {"pos": off_co})
+                shader.bind()
+                shader.uniform_float("color", self.colr_off)
+                batch.draw(shader)
+
             # draw button text
-            bgl.glColor4f(*self.txt_colr)
-            blf.size(font_id, self.txt_sz, self.dpi)
             blf.position(font_id, self.txt_co[0], self.txt_co[1], 0)
+            #bgl.glColor4f(*self.txt_colr)
+            blf.size(font_id, self.txt_sz, self.dpi)
+            blf.color(font_id, *self.txt_colr)
+            #blf.position(font_id, self.txt_co[0], self.txt_co[1], 0)
             blf.draw(font_id, self.txt)
+
         else:
             self.ms_over = False
 
@@ -535,7 +566,7 @@ def add_select(self):
                     elif type(sel) is bmesh.types.BMFace:
                         sel_verts = sel.verts
                     for v in sel_verts:
-                        v_co3d = m_w * v.co
+                        v_co3d = m_w @ v.co
                         add_pt(self, v_co3d)
                         if self.pt_cnt > 2:
                             exit_loop = True
@@ -567,7 +598,7 @@ def add_select_multi(self):
                     elif type(sel) is bmesh.types.BMFace:
                         sel_verts = sel.verts
                     for v in sel_verts:
-                        v_co3d = m_w * v.co
+                        v_co3d = m_w @ v.co
                         self.multi_tmp.try_add(v_co3d)
                         if self.multi_tmp.cnt == self.multi_tmp.max_cnt:
                             exit_loop = True
@@ -625,7 +656,7 @@ def new_select_multi(self):
                 elif type(sel) is bmesh.types.BMFace:
                     sel_verts = sel.verts
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list