[Bf-extensions-cvs] [68a2d28b] master: xoffsets: xedit 0.2.0 update
NBurn
noreply at git.blender.org
Tue Dec 4 17:07:28 CET 2018
Commit: 68a2d28b24430133946f21d7deede1312d181aaf
Author: NBurn
Date: Tue Dec 4 11:07:00 2018 -0500
Branches: master
https://developer.blender.org/rBAC68a2d28b24430133946f21d7deede1312d181aaf
xoffsets: xedit 0.2.0 update
Add-on renamed from Exact Offsets to Exact Edit.
Vertex based ref points replaced with location based ref points.
===================================================================
A exact_edit/__init__.py
A exact_edit/xedit_free_rotate.py
A exact_edit/xedit_set_meas.py
D mesh_xoffsets.py
===================================================================
diff --git a/exact_edit/__init__.py b/exact_edit/__init__.py
new file mode 100644
index 00000000..1ab4e1e6
--- /dev/null
+++ b/exact_edit/__init__.py
@@ -0,0 +1,75 @@
+'''
+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
+'''
+
+bl_info = {
+ "name": "Exact Edit",
+ "author": "nBurn",
+ "version": (0, 2, 0),
+ "blender": (2, 7, 7),
+ "location": "View3D",
+ "description": "Tool for precisely setting distance, scale, and rotation",
+ "wiki_url": "https://github.com/n-Burn/Exact_Edit/wiki",
+ "category": "Object"
+}
+
+if "bpy" in locals():
+ import importlib
+ importlib.reload(xedit_set_meas)
+ importlib.reload(xedit_free_rotate)
+else:
+ from . import xedit_set_meas
+ from . import xedit_free_rotate
+
+import bpy
+
+
+class XEditPanel(bpy.types.Panel):
+ # Creates a panel in the 3d view Toolshelf window
+ bl_label = 'Exact Edit'
+ bl_idname = 'xedit_base_panel'
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'TOOLS'
+ #bl_context = 'objectmode'
+ bl_category = 'Tools'
+
+ def draw(self, context):
+ #layout = self.layout
+ row = self.layout.row(True)
+ col = row.column()
+ col.operator("view3d.xedit_set_meas_op", text="Set Measure", icon="EDIT")
+ col.operator("view3d.xedit_free_rotate_op", text="Free Rotate", icon="FORCE_MAGNETIC")
+
+
+def register():
+ bpy.utils.register_class(xedit_set_meas.XEditStoreMeasBtn)
+ bpy.utils.register_class(xedit_set_meas.XEditMeasureInputPanel)
+ bpy.utils.register_class(xedit_set_meas.XEditSetMeas)
+ bpy.utils.register_class(xedit_free_rotate.XEditFreeRotate)
+ bpy.utils.register_class(XEditPanel)
+
+def unregister():
+ bpy.utils.unregister_class(xedit_set_meas.XEditStoreMeasBtn)
+ bpy.utils.unregister_class(xedit_set_meas.XEditMeasureInputPanel)
+ bpy.utils.unregister_class(xedit_set_meas.XEditSetMeas)
+ bpy.utils.unregister_class(xedit_free_rotate.XEditFreeRotate)
+ bpy.utils.unregister_class(XEditPanel)
+
+if __name__ == "__main__":
+ register()
diff --git a/exact_edit/xedit_free_rotate.py b/exact_edit/xedit_free_rotate.py
new file mode 100644
index 00000000..6cd461c0
--- /dev/null
+++ b/exact_edit/xedit_free_rotate.py
@@ -0,0 +1,1421 @@
+'''
+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]
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list