[Bf-extensions-cvs] [b1eba81e] master: xoffsets: Cleanup on commas, updating comments
NBurn
noreply at git.blender.org
Tue May 30 01:17:38 CEST 2017
Commit: b1eba81e2bf4845ee668fc55d0a7255b6965ce10
Author: NBurn
Date: Mon May 29 19:15:18 2017 -0400
Branches: master
https://developer.blender.org/rBACb1eba81e2bf4845ee668fc55d0a7255b6965ce10
xoffsets: Cleanup on commas, updating comments
===================================================================
M mesh_xoffsets.py
===================================================================
diff --git a/mesh_xoffsets.py b/mesh_xoffsets.py
index 821a4cbf..2c7d98af 100644
--- a/mesh_xoffsets.py
+++ b/mesh_xoffsets.py
@@ -69,14 +69,15 @@ from bpy_extras.view3d_utils import location_3d_to_region_2d
print("Exact Offsets loaded")
-( SET_REF_PTS,
- GET_TRANSF_MODE,
- CHECK_POPUP_INFO,
- DO_TRANSFORM,
- GET_0_OR_180,
- MOVE,
- SCALE,
- ROTATE,
+(
+ SET_REF_PTS,
+ GET_TRANSF_MODE,
+ CHECK_POPUP_INFO,
+ DO_TRANSFORM,
+ GET_0_OR_180,
+ MOVE,
+ SCALE,
+ ROTATE,
) = range(8)
currMeasStor = 0.0
@@ -113,9 +114,9 @@ class VertObj:
self.co2D = co2D
self.dist2D = dist2D
self.refInd = refInd
- self.obj = bpy.context.scene.objects # short hand, for internal use
+ self.obj = bpy.context.scene.objects # short hand, for internal use
- def copy(self): # return independent copy of vertObj
+ 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):
@@ -128,7 +129,7 @@ class VertObj:
self.co3D = self.obj[self.objInd].matrix_world * tmpCoLocal
-# stores info for the reference points info
+# Stores the reference points and ref pt related info.
class ReferencePoints():
def __init__(self, count=0, rLs=[(),(),()], mLs=[(),(),()], axisLock='', col_ls=[]):
self.cnt = count
@@ -139,48 +140,49 @@ class ReferencePoints():
def update_col_ls(self):
if self.cnt < 3:
- self.col_ls = [Colr.red,Colr.green]
- else: # self.cnt > 2
- self.col_ls = [Colr.red,Colr.blue,Colr.green]
+ self.col_ls = [Colr.red, Colr.green]
+ else: # self.cnt > 2
+ self.col_ls = [Colr.red, Colr.blue, Colr.green]
- def removePt(self,remInd):
+ def removePt(self, remInd):
# hackery or smart, you decide...
if remInd != self.cnt - 1:
- ind = [0,1,2][:self.cnt]
+ ind = [0, 1, 2][:self.cnt]
ind.remove(remInd)
for i in range(len(ind)):
self.rLs[i] = self.rLs[ind[i]].copy()
self.rLs[i].refInd = i
self.cnt -= 1
- def tryAdd(self,found_pt):
+ def tryAdd(self, found_pt):
if self.cnt > 0:
for rp in range(self.cnt):
if self.rLs[rp].co3D == found_pt.co3D:
self.axLock = ''
self.removePt( self.rLs[rp].refInd )
self.mLs = self.rLs
- #print("ref pt removed:",rp,"cnt:",self.cnt) # debug
+ #print("ref pt removed:", rp, "cnt:", self.cnt) # debug
self.update_col_ls()
return
+ # if duplicate not found and cnt not max, add found_pt to rLs
if self.cnt < 3:
self.rLs[self.cnt] = found_pt
self.rLs[self.cnt].refInd = self.cnt
''' Begin Debug
ptFndStr = str(self.rLs[self.cnt].co3D)
- ptFndStr = ptFndStr.replace("<Vector ","Vector(")
- ptFndStr = ptFndStr.replace(">",")")
- print("Ref_pt_" + str(self.cnt) +' =',ptFndStr)
- #print("ref pt added:",self.cnt,"cnt:",self.cnt+1)
+ ptFndStr = ptFndStr.replace("<Vector ", "Vector(")
+ ptFndStr = ptFndStr.replace(">", ")")
+ print("Ref_pt_" + str(self.cnt) + ' =', ptFndStr)
+ #print("ref pt added:", self.cnt, "cnt:", self.cnt+1)
End Debug '''
self.cnt += 1
self.update_col_ls()
return
-# stores rotation info
-# for passing data from draw_callback_px to external functions
-# not as bad as hiding arguments in passed variables, but still seems hackish
+# Stores rotation info for passing data from draw_callback_px to
+# external functions. Not as bad as hiding arguments in passed
+# variables, but still seems hackish...
class RotationData:
def __init__(self):
self.newAngR = 0.0
@@ -188,46 +190,46 @@ class RotationData:
self.angDiffD = 0.0
self.angDiffR = 0.0
self.axisLk = ''
- self.pivNorm = [] # pivot normal
+ self.pivNorm = [] # pivot normal
#self.angleEq_0_180 = False
#self.obj = bpy.context.scene.objects[self.objInd] # short hand
-### linear equations ###
+# === Linear Equations ===
-#def getMidpoint2D(x1,y1,x2,y2):
+#def getMidpoint2D(x1, y1, x2, y2):
# return ( (x1+x2)/2 , (y1+y2)/2 )
def getMidpoint3D(ptA, ptB):
- x1,y1,z1 = ptA[0],ptA[1],ptA[2]
- x2,y2,z2 = ptB[0],ptB[1],ptB[2]
+ x1, y1, z1 = ptA[0], ptA[1], ptA[2]
+ x2, y2, z2 = ptB[0], ptB[1], ptB[2]
return Vector([ (x1+x2)/2 , (y1+y2)/2 , (z1+z2)/2 ])
def get_dist_2D(ptA, ptB):
- x1,y1 = ptA[0],ptA[1]
- x2,y2 = ptB[0],ptB[1]
+ x1, y1 = ptA[0], ptA[1]
+ x2, y2 = ptB[0], ptB[1]
return sqrt( abs( ((x2-x1)**2) + ((y2-y1)**2) ) )
def get_dist_3D(ptA, ptB):
- x1,y1,z1 = ptA[0],ptA[1],ptA[2]
- x2,y2,z2 = ptB[0],ptB[1],ptB[2]
+ x1, y1, z1 = ptA[0], ptA[1], ptA[2]
+ x2, y2, z2 = ptB[0], ptB[1], ptB[2]
res = sqrt( abs( ((x2-x1)**2) + ((y2-y1)**2) + ((z2-z1)**2) ) )
return res
-# for making sure rise over run doesn't get flipped
-def slope_check(pt1,pt2):
+# For making sure rise over run doesn't get flipped.
+def slope_check(pt1, pt2):
cmp = ( pt1[0] >= pt2[0], pt1[1] >= pt2[1], pt1[2] >= pt2[2] )
return cmp
def get_slope_3D(self, ptA, ptB):
dist3D = get_dist_3D( ptA, ptB )
- x1,y1,z1 = ptA[0],ptA[1],ptA[2]
- x2,y2,z2 = ptB[0],ptB[1],ptB[2]
+ x1, y1, z1 = ptA[0], ptA[1], ptA[2]
+ x2, y2, z2 = ptB[0], ptB[1], ptB[2]
if dist3D == 0:
self.report({'ERROR'}, 'Distance between points cannot be zero.')
return
@@ -237,20 +239,19 @@ def get_slope_3D(self, ptA, ptB):
return ( xSlope, ySlope, zSlope )
-def get_new_pt_3D(xyz,slope3D,dis3D):
+def get_new_pt_3D(xyz, slope3D, dis3D):
#newX = (x1 +- ( dis3D * slopeX ) )
- x1,y1,z1 = xyz[0], xyz[1], xyz[2]
- slopeX,slopeY,slopeZ = slope3D[0],slope3D[1],slope3D[2]
+ x1, y1, z1 = xyz[0], xyz[1], xyz[2]
+ slopeX, slopeY, slopeZ = slope3D[0], slope3D[1], slope3D[2]
newX = x1 + ( dis3D * slopeX )
newY = y1 + ( dis3D * slopeY )
newZ = z1 + ( dis3D * slopeZ )
- return Vector([newX,newY,newZ])
+ return Vector([newX, newY, newZ])
-# todo: split into 2 functions ?
-# finds 3D location that shares same slope of line connecting Anchor and
-# Free or is on axis line going through Anchor
-def get_new_3D_coor(self,lock, ptA, ptF, newDis):
+# Finds 3D location that shares same slope of line connecting Anchor and
+# Free or that is on axis line going through Anchor.
+def get_new_3D_coor(self, lock, ptA, ptF, newDis):
ptN_1, ptN_2 = (), ()
if lock == '':
if newDis == 0:
@@ -265,14 +266,14 @@ def get_new_3D_coor(self,lock, ptA, ptF, newDis):
if newDis > 0:
return ptN_1
else:
- # for negative distances
+ # for negative distances
return ptN_2
elif origSlope == ptN_2_slp:
if newDis > 0:
return ptN_2
else:
return ptN_1
- else: # neither slope matches
+ else: # neither slope matches
self.report({'ERROR'}, 'Slope mismatch. Cannot calculate new point.')
return []
elif lock == 'X':
@@ -284,12 +285,12 @@ def get_new_3D_coor(self,lock, ptA, ptF, newDis):
elif lock == 'Z':
if ptF[2] > ptA[2]: return Vector([ ptF[0], ptF[1], ptA[2] + newDis ])
else: return Vector([ ptF[0], ptF[1], ptA[2] - newDis ])
- else: # neither slope matches
+ else: # neither slope matches
self.report({'ERROR'}, "Slope mismatch. Can't calculate new point.")
return []
-# Floating point math fun! Since equality tests on floats are a crap shoot,
+# Floating point math fun! Since equality tests on floats are a crap shoot,
# instead check if floats are almost equal (is the first float within a
# certain tolerance amount of the second).
# Note, this function may fail in certain circumstances depending on the
@@ -297,7 +298,7 @@ def get_new_3D_coor(self,lock, ptA, ptF, newDis):
# try a different power of ten for the "tol" value (eg 0.01 or 0.00001)
# todo: replace this with Python 3.5's math.isclose() ?
# do recent versions of Blender support math.isclose()?
-def AreFloatsEq(flt_A,flt_B):
+def AreFloatsEq(flt_A, flt_B):
tol = 0.0001
return flt_A > (flt_B - tol) and flt_A < (flt_B + tol)
@@ -305,21 +306,22 @@ def AreFloatsEq(flt_A,flt_B):
# Aco, Bco, and Cco are Vector based 3D coordinates
# coordinates must share a common center "pivot" point (Bco)
def getLineAngle3D(Aco, Bco, Cco):
- # todo, more testing on Vector's built-in angle measure method
algnAco = Aco - Bco
algnCco = Cco - Bco
return algnAco.angle(algnCco)
-# checks if 3 coordinates create an angle that matches the expected angle
-def angleMatch3D(pt1,pt2,pt3,expAng):
- angMeas = getLineAngle3D(pt1,pt2,pt3)
- #print("pt1",pt1) # debug
- #print("pt2",pt2) # debug
- #print("pt3",pt3) # debug
- #print( "expAng ",expAng ) # debug
- #print( "angMeas ",angMeas ) # debug
- return AreFloatsEq(angMeas,expAng)
+# Checks if the 3 coordinates arguments (pt1, pt2, pt3) will create
+# an angle with a measurement matching the value in the argument
+# expAngMeas (expected angle measurement).
+def angleMatch3D(pt1, pt2, pt3, expAng):
+ angMeas = getLineAngle3D(pt1, pt2, pt3)
+ #print("pt1", pt1) # debug
+ #print("pt2", pt2) # debug
+ #print("pt3", pt3) # debug
+ #print( "expAng ", expAng ) # debug
+ #print( "angMeas ", angMeas ) # debug
+ return AreFloatsEq(angMeas, expAng)
# Calculates rotation around axis or face normal at Pivot's location.
@@ -328,23 +330,23 @@ def angleMatch3D(pt1,pt2,pt3,expAng):
# Aligns movCo to world origin (0, 0, 0) and rotates aligned
# movCo (movAligned) around axis stored in rotDat. After rotation,
# removes world-origin alignment
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list