[Bf-extensions-cvs] [9c44ef76] master: Initial commit xoffsets by nburn T51286

meta-androcto noreply at git.blender.org
Sun Apr 23 07:43:18 CEST 2017


Commit: 9c44ef7636b4e2ea05b0a8ec1503946748d0df88
Author: meta-androcto
Date:   Sun Apr 23 15:42:57 2017 +1000
Branches: master
https://developer.blender.org/rBAC9c44ef7636b4e2ea05b0a8ec1503946748d0df88

Initial commit xoffsets by nburn T51286

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

A	mesh_xoffsets.py

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

diff --git a/mesh_xoffsets.py b/mesh_xoffsets.py
new file mode 100644
index 00000000..d1ae12a1
--- /dev/null
+++ b/mesh_xoffsets.py
@@ -0,0 +1,1456 @@
+'''
+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
+
+#############################################################################
+
+xoffsets.py (alpha version 005)
+
+Performance Note:
+The Add-On's vertex finding code is still mostly a proof-of-concept without 
+any performance optimizations. During trial runs the Add-On worked fine 
+with basic models, but once vertex counts reached the 10K to 30K range 
+performance took a major hit. Using the Add-On with anything more complex 
+than that might still be possible, but is not recommended.
+
+Install instructions (if downloaded separately from Blender):
+1) Save the xoffsets.py file to your computer.
+2) In Blender, go to File > User Preferences > Add-ons
+3) Press Install From File and select the xoffsets.py file you
+    just downloaded.
+4) Enable the Add-On by clicking on box to the left of Add-On's name
+
+Basic Usage: 
+Launch the Add-On from the Spacebar menu by typing in: Exact Offsets
+After launching the addon, it will be in "Point Select" mode where you can 
+select 2 or 3 "reference points" using the Left Mouse Button. Points are 
+selected by left clicking on/near the vertices of a mesh model in the 
+3D View. A point will be placed at the vertex closest to the location you 
+clicked (except when there are no vertices near the mouse cursor). The order 
+in which you selected the points determines their function and color:
+
+* 1st point set is the "Anchor" (red)
+* 2nd point set is the "Free" (green)
+* If a 3rd point is set, the 2nd point becomes the "Pivot" (blue) and the 
+   3rd point (last) becomes the "Free" point
+
+Unselecting points:
+If you click on an already "selected" reference point it will become 
+"unselected". For "unselecting" points, the Anchor > Pivot > Free 
+association works in reverse from when you selected points. 
+
+Examples:
+* If 2 points are selected and the Anchor is unselected, the Free point 
+   (being the only point selected) becomes the "new" Anchor.
+* If 3 points are selected and the Pivot is unselected, the Free and Anchor 
+   remain unchanged and the Pivot is removed.
+* If 3 points are selected and the Free is unselected, the Anchor remains
+   unchanged and the Pivot becomes the "new" Free.
+
+Entering a new measurement
+After you select 2 or 3 points, a "button" will appear in the 3D View 
+displaying the distance or rotation value between the selected points. If 
+you click on the button a "Measure Input" dialog box will appear displaying 
+the current measure between the points. If you change the measure in the 
+dialog box and click "OK", a translation (move), scale, or rotation will be
+performed depending on which mode was active.
+
+Available transform modes: 
+Translate, Scale (Object mode only), and Rotation.
+Translate mode is active when only 2 points are selected.
+Scale mode is active if 2 points are selected and attached to same object.
+Rotate mode active when 3 points are selected.
+
+Direction of Movement
+When a new measurement is input with the dialog box, the Free point will 
+move away from or towards the Anchor point to match the updated measurement. 
+If Blender was in Object Mode, the Object the "Free" point was attached to 
+will be moved. If Blender was in Edit Mode, the "Free" point's vertex will 
+be moved. If the Free point was part of a selection set, all other selected 
+vertices (if in Edit Mode) or Mesh Objects (if in Object Mode) will be moved 
+along with the Free point (except when in scale mode).
+
+Translate mode:
+Without an axis lock set, the Free point will move along the slope between 
+the Anchor and Free points. 
+With an axis lock set, Free is moved along set axis.
+
+Rotation mode:
+When an axis lock is set, the Free point will rotate around that axis where 
+it passes through the Pivot point's location. The displayed angle measurement
+(in degrees) represents the smallest angle created starting from the 
+Anchor-Pivot line (at 0 degrees) to the Pivot-Free line. Because the smallest
+angle is used to determine the direction to move the Free point, if the angle 
+measured 0 or 180 degrees before entering a new rotation value, the new 
+location for the Free point will have to be manually selected with the 
+Left Mouse Button. When no axis lock is set, the Free point will rotate 
+around the "face normal" of Anchor-Pivot-Free "face" coming off the Pivot's 
+location. You will not be able to do a rotation without an axis lock set if 
+the original rotation value was 0 or 180 degrees.
+
+Scale mode (Object Mode Only):
+If scale mode is active and no axis lock set, the whole object is scaled up 
+or down so the distance between the Anchor and Free points matches the 
+distance input with the dialog box. If an axis lock was set, the object will 
+scale only along the selected axis. Note that the object is scaled in the 
+direction of the Free point with the Anchor point maintaining its 
+original location.
+
+Notes: 
+* You cannot select more than 1 point in a given 3D location (Points can't 
+   share the same coordinates).
+* If Objects have an unapplied scale or rotation, transforms may not work as
+   intended (scale in particular).
+* Entering negative values will reverse the direction of the transformation.
+   For example, If a Z axis lock was applied, the Free vertex was 2 units 
+    above the Anchor, and -3 was entered, the Free vertex would be moved down
+    5 units to sit 3 units below the Anchor.
+
+Hotkeys:
+LMB = Left Mouse Button, RMB = Right Mouse Button
+
+ESC      exits the add-on
+LMB+RMB  exits the add-on
+LMB      selects points and activates button
+X        sets X-axis lock
+Y        sets Y-axis lock
+Z        sets Z-axis lock
+C        clears axis lock (sets "Spherical" lock in rotation mode)
+
+todo:
+  [?] rewrite/refactor code to optimize for modal operation
+  [?] make sure point removal state resets are correct (tryAdd)
+  [X] fix: when btn clicked, dialog will not appear until after mouse moved
+  [X] fix: when new meas input, transform not applied until after mouse moved
+  [ ] prevent selection of non-visible vertices
+  [ ] fix bug: obj is not subscriptable error if perspective is changed after 
+        launching addon, disabling perspective change for now
+  [ ] better measurement input panel
+  [ ] add hotkey reference info into 3D View ?
+
+#############################################################################
+'''
+
+bl_info = {
+    "name": "Exact Offsets",
+    "author": "nBurn",
+    "version": (0, 0, 5),
+    "blender": (2, 7, 7),
+    "location": "View3D",
+    "description": "Tool for precisely setting distance, scale, and rotation of mesh geometry",
+    "category": "Mesh"
+}
+
+import bpy
+import bgl
+import blf
+import bmesh
+from math import fmod, sqrt, degrees, radians
+from mathutils import Vector, geometry, Quaternion, Euler
+from mathutils.geometry import intersect_line_line_2d
+from bpy_extras.view3d_utils import location_3d_to_region_2d
+#import code
+#code.interact(local=locals())
+#__import__('code').interact(local=dict(globals(), **locals()))
+
+print("Exact Offsets loaded")
+
+(    SET_REF_PTS,
+    GET_TRANSF_MODE,
+    CHECK_POPUP_INFO,
+    DO_TRANSFORM,
+    GET_0_OR_180,
+    MOVE,
+    SCALE,
+    ROTATE,
+) = range(8)
+
+currMeasStor = 0.0
+newMeasStor = None
+popUpActive = False
+RegRv3d = ()
+
+
+def getRegRv3d():
+    global RegRv3d
+    region = bpy.context.region
+    rv3d = []
+    for area in bpy.context.screen.areas:
+        if area.type == "VIEW_3D":
+            rv3d = area.spaces[0].region_3d
+            break
+    RegRv3d = (region, rv3d)
+
+
+# vertex storage class, stores reference point info
+class vertObj:
+    def __init__(self, objInd=-1, vertInd=-1, co3D=[], co2D=[], dist2D=-1, refInd=-1):
+        self.objInd = objInd
+        self.vertInd = vertInd
+        self.co3D = co3D
+        self.co2D = co2D
+        self.dist2D = dist2D
+        self.refInd = refInd
+        self.obj = bpy.context.scene.objects # short hand, for internal use
+
+    def copy(self): # return independent copy of vertObj
+        return vertObj( self.objInd, self.vertInd, self.co3D.copy(), [*self.co2D], self.dist2D, self.refInd )
+
+    def set2D(self):
+        global RegRv3d
+        region, rv3d = RegRv3d[0], RegRv3d[1]
+        self.co2D = location_3d_to_region_2d(region, rv3d, self.co3D)
+
+    def update3D(self):
+        tmpCoLocal = self.obj[self.objInd].data.vertices[self.vertInd].co
+        self.co3D = self.obj[self.objInd].matrix_world * tmpCoLocal
+
+
+# stores info for the reference points info
+class referencePoints():
+    def __init__(self, count=0, rLs=[(),(),()], mLs=[(),(),()], axisLock='', col_ls=[]):
+        self.cnt = count
+        self.rLs = rLs
+        self.mLs = mLs
+        self.axLock = axisLock
+        self.col_ls = col_ls
+        self.colorRed   = [1.0, 0.0, 0.0, 0.5]
+        self.colorGreen = [0.0, 1.0, 0.0, 0.5]
+        self.colorBlue  = [0.0, 0.0, 1.0, 0.5]
+
+    def update_col_ls(self):
+        if self.cnt < 3:
+            self.col_ls = [self.colorRed,self.colorGreen]
+        else: # self.cnt > 2
+            self.col_ls = [self.colorRed,self.colorBlue,self.colorGreen]
+
+    def removePt(self,remInd):
+        # hackery or smart, you decide...
+        if remInd != self.cnt - 1:
+            ind = [0,1,2][:self.cnt]
+            ind.remove(remInd)
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list