[Bf-extensions-cvs] [ceb054a0] blender2.8: Merge branch 'master' into blender2.8

Brecht Van Lommel noreply at git.blender.org
Fri Dec 21 12:11:01 CET 2018


Commit: ceb054a0f923fa49cd9e8ef20322261a26160151
Author: Brecht Van Lommel
Date:   Fri Dec 21 12:10:47 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBACceb054a0f923fa49cd9e8ef20322261a26160151

Merge branch 'master' into blender2.8

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



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

diff --cc exact_edit/xedit_free_rotate.py
index 00000000,6cd461c0..013ada6c
mode 000000,100644..100644
--- a/exact_edit/xedit_free_rotate.py
+++ b/exact_edit/xedit_free_rotate.py
@@@ -1,0 -1,1421 +1,1419 @@@
+ '''
+ 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
+ '''
+ 
+ from copy import deepcopy
+ from math import degrees, radians, pi
+ 
+ import bpy
+ import bmesh
+ import bgl
+ import blf
+ from mathutils import geometry, Euler, 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
+ 
+ # "Constant" values
+ (
+     X,
+     Y,
+     Z,
+ 
+     CLICK_CHECK,
+     WAIT_FOR_POPUP,
+     GET_0_OR_180,
+     DO_TRANSFORM,
+ 
+     MOVE,
+     SCALE,
+     ROTATE,
+ ) = range(10)
+ 
+ # globals
+ curr_meas_stor = 0.0
+ new_meas_stor = None
+ popup_active = False
+ 
+ 
+ #print("Loaded add-on.\n")  # debug
+ 
+ 
+ class Colr:
+     red    = 1.0, 0.0, 0.0, 0.6
+     green  = 0.0, 1.0, 0.0, 0.6
+     blue   = 0.0, 0.0, 1.0, 0.6
+     white  = 1.0, 1.0, 1.0, 1.0
+     grey   = 1.0, 1.0, 1.0, 0.4
+     black  = 0.0, 0.0, 0.0, 1.0
+     yellow = 1.0, 1.0, 0.0, 0.6
+     brown  = 0.15, 0.15, 0.15, 0.20
+ 
+ 
+ class RotDat:
+     placeholder = True
+ 
+ 
+ # Refreshes mesh drawing in 3D view and updates mesh coordinate
+ # data so ref_pts are drawn at correct locations.
+ # Using editmode_toggle to do this seems hackish, but editmode_toggle seems
+ # to be the only thing that updates both drawing and coordinate info.
+ def editmode_refresh():
+     if bpy.context.mode == "EDIT_MESH":
+         bpy.ops.object.editmode_toggle()
+         bpy.ops.object.editmode_toggle()
+ 
+ 
+ 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_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.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_target = 'CLOSEST'
+     bpy.context.space_data.pivot_point = 'ACTIVE_ELEMENT'
+     bpy.context.space_data.transform_orientation = 'GLOBAL'
+     bpy.context.space_data.show_manipulator = 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_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.scene.cursor_location = deepcopy(backup[6])
+     return
+ 
+ 
+ def flts_alm_eq(flt_a, flt_b):
+     tol = 0.0001
+     return flt_a > (flt_b - tol) and flt_a < (flt_b + tol)
+ 
+ 
+ # todo : replace with flt_lists_alm_eq?
+ def vec3s_alm_eq(vec_a, vec_b):
+     X, Y, Z = 0, 1, 2
+     if flts_alm_eq(vec_a[X], vec_b[X]):
+         if flts_alm_eq(vec_a[Y], vec_b[Y]):
+             if flts_alm_eq(vec_a[Z], vec_b[Z]):
+                 return True
+     return False
+ 
+ 
+ # assume both float lists are same size?
+ def flt_lists_alm_eq(ls_a, ls_b):
+     for i in range(len(ls_a)):
+         if not flts_alm_eq(ls_a[i], ls_b[i]):
+             return False
+     return True
+ 
+ 
+ class MenuStore:
+     def __init__(self):
+         self.cnt = 0
+         self.active = 0  # unused ?
+         # todo : replace above with self.current ?
+         self.txtcolrs = []
+         self.tcoords = []
+         self.texts = []
+         self.arrows = []  # arrow coordinates
+ 
+ 
+ class MenuHandler:
+     def __init__(self, title, tsize, act_colr, dis_colr, toolwid, reg):
+         self.dpi = bpy.context.user_preferences.system.dpi
+         self.title = title
+         # todo : better solution than None "magic numbers"
+         self.menus = [None]  # no menu for 0
+         self.menu_cnt = len(self.menus)
+         self.current = 0  # current active menu
+         self.tsize = tsize  # text size
+         self.act_colr = act_colr
+         self.dis_colr = dis_colr  # disabled color
+         self.reg = reg  # region
+ 
+         view_offset = 36, 45  # box left top start
+         self.box_y_pad = 8  # vertical space between boxes
+ 
+         fontid = 0
+         blf.size(fontid, tsize, self.dpi)
+         lcase_wid, lcase_hgt = blf.dimensions(fontid, "n")
+         ucase_wid, ucase_hgt = blf.dimensions(fontid, "N")
+         bot_space = blf.dimensions(fontid, "gp")[1] - lcase_hgt
+         self.full_hgt = blf.dimensions(fontid, "NTgp")[1]
+ 
+         arr_wid, arr_hgt = 12, 16
+         arrow_base = (0, 0), (0, arr_hgt), (arr_wid, arr_hgt/2)
+         aw_adj, ah_adj = arr_wid * 1.5, (arr_hgt - ucase_hgt) / 2
+         self.arrow_pts = []
+         for a in arrow_base:
+             self.arrow_pts.append((a[0] - aw_adj, a[1] - ah_adj))
+ 
+         self.blef = view_offset[0] + toolwid  # box left start
+         self.titlco = self.blef // 2, self.reg.height - view_offset[1]
+         self.btop = self.titlco[1] - (self.full_hgt // 1.5)
+         self.txt_y_pad = bot_space * 2
+ 
+     def add_menu(self, strings):
+         self.menus.append(MenuStore())
+         new = self.menus[-1]
+         btop = self.btop
+         tlef = self.blef  # text left
+         new.cnt = len(strings)
+         for i in range(new.cnt):
+             new.txtcolrs.append(self.dis_colr)
+             new.texts.append(strings[i])
+             bbot = btop - self.full_hgt
+             new.tcoords.append((tlef, bbot))
+             btop = bbot - self.box_y_pad
+             new.arrows.append((
+                 (self.arrow_pts[0][0] + tlef, self.arrow_pts[0][1] + bbot),
+                 (self.arrow_pts[1][0] + tlef, self.arrow_pts[1][1] + bbot),
+                 (self.arrow_pts[2][0] + tlef, self.arrow_pts[2][1] + bbot)))
+         new.txtcolrs[new.active] = self.act_colr
+         self.menu_cnt += 1
+ 
+     def update_active(self, change):
+         menu = self.menus[self.current]
+         if menu is None:
+             return
+         menu.txtcolrs[menu.active] = self.dis_colr
+         menu.active = (menu.active + change) % menu.cnt
+         menu.txtcolrs[menu.active] = self.act_colr
+ 
+     def change_menu(self, new):
+         self.current = new
+ 
+     def get_mode(self):
+         menu = self.menus[self.current]
+         return menu.texts[menu.active]
+ 
+     #def rebuild_menus(self)  # add in case blender window size changes?
+     #    return
+ 
+     def draw(self, menu_visible):
+         menu = self.menus[self.current]
+         # prepare to draw text
+         font_id = 0
+         blf.size(font_id, self.tsize, self.dpi)
+         # draw title
+         bgl.glColor4f(*self.dis_colr)
+         blf.position(font_id, self.titlco[0], self.titlco[1], 0)
+         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])
+                 blf.position(font_id, menu.tcoords[i][0], menu.tcoords[i][1], 0)
+                 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()
+ 
+ 
+ # === 3D View mouse location and button code ===
+ class ViewButton():
+     def __init__(self, colr_on, colr_off, txt_sz, txt_colr, offs=(0, 0)):
+         self.dpi = bpy.context.user_preferences.system.dpi
+         self.is_drawn = False
+         self.ms_over = False  # mouse over button
+         self.wid = 0
+         self.coords = None
+         #self.co_outside_btn = None
+         self.co2d = None
+         self.colr_off = colr_off  # colr when mouse not over button
+         self.colr_on = colr_on  # colr when mouse over button
+         self.txt = ""
+         self.txt_sz = txt_sz
+         self.txt_colr = txt_colr
+         self.txt_co = None
+         self.offset = Vector(offs)
+ 
+         # Set button height and text offsets (to determine where text would
+         # be placed within button). Done in __init__ as this will not change
+         # during program execution and prevents having to recalculate these
+         # values every time text is changed.
+         font_id = 0
+         blf.size(font_id, self.txt_sz, self.dpi)
+         samp_txt_max = "Tgp"  # text with highest and lowest pixel values
+         x, max_y =  blf.dimensions(font_id, samp_txt_max)
+         y = blf.dimensions(font_id, "T")[1]  # T = sample text
+         y_diff = (max_y - y)
+ 
+         self.hgt = int(max_y + (y_diff * 2))
+         self.txt_x_offs = int(x / (len(samp_txt_max) * 2) )
+         self.txt_y_offs = int(( self.hgt -

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list