[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2842] trunk/py/scripts/addons/ mesh_looptools.py: Fix for column major matrix API change.

Bart Crouch bartius.crouch at gmail.com
Sat Dec 31 12:45:55 CET 2011


Revision: 2842
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2842
Author:   crouch
Date:     2011-12-31 11:45:52 +0000 (Sat, 31 Dec 2011)
Log Message:
-----------
Fix for column major matrix API change.
+ reversal of previous commit, which broke circle tool

Modified Paths:
--------------
    trunk/py/scripts/addons/mesh_looptools.py

Modified: trunk/py/scripts/addons/mesh_looptools.py
===================================================================
--- trunk/py/scripts/addons/mesh_looptools.py	2011-12-31 10:57:35 UTC (rev 2841)
+++ trunk/py/scripts/addons/mesh_looptools.py	2011-12-31 11:45:52 UTC (rev 2842)
@@ -19,9 +19,9 @@
 bl_info = {
     'name': "LoopTools",
     'author': "Bart Crouch",
-    'version': (3, 2, 2),
-    'blender': (2, 6, 0),
-    'api': 42162,
+    'version': (3, 2, 3),
+    'blender': (2, 6, 1),
+    'api': 42905,
     'location': "View3D > Toolbar and View3D > Specials (W-key)",
     'warning': "",
     'description': "Mesh modelling toolkit. Several tools to aid modelling",
@@ -223,13 +223,13 @@
                                 ))
         for loc in locs:
             mat[0][0] += (loc[0]-x)**2
-            mat[0][1] += (loc[0]-x)*(loc[1]-y)
-            mat[0][2] += (loc[0]-x)*(loc[2]-z)
-            mat[1][0] += (loc[1]-y)*(loc[0]-x)
+            mat[1][0] += (loc[0]-x)*(loc[1]-y)
+            mat[2][0] += (loc[0]-x)*(loc[2]-z)
+            mat[0][1] += (loc[1]-y)*(loc[0]-x)
             mat[1][1] += (loc[1]-y)**2
-            mat[1][2] += (loc[1]-y)*(loc[2]-z)
-            mat[2][0] += (loc[2]-z)*(loc[0]-x)
-            mat[2][1] += (loc[2]-z)*(loc[1]-y)
+            mat[2][1] += (loc[1]-y)*(loc[2]-z)
+            mat[0][2] += (loc[2]-z)*(loc[0]-x)
+            mat[1][2] += (loc[2]-z)*(loc[1]-y)
             mat[2][2] += (loc[2]-z)**2
         
         # calculating the normal to the plane
@@ -244,12 +244,20 @@
             elif sum(mat[2]) == 0.0:
                 normal = mathutils.Vector((0.0, 0.0, 1.0))
         if not normal:
+            # warning! this is different from .normalize()
+            itermax = 500
+            iter = 0
             vec = mathutils.Vector((1.0, 1.0, 1.0))
-            normal = (mat * vec)/(mat * vec).length
-            if normal.length == 0:
-                normal = vec
-            else:
-                normal.normalize()
+            vec2 = (mat * vec)/(mat * vec).length
+            while vec != vec2 and iter<itermax:
+                iter+=1
+                vec = vec2
+                vec2 = mat * vec
+                if vec2.length != 0:
+                    vec2 /= vec2.length
+            if vec2.length == 0:
+                vec2 = mathutils.Vector((1.0, 1.0, 1.0))
+            normal = vec2
     
     elif method == 'normal':
         # averaging the vertex normals
@@ -904,13 +912,13 @@
         x, y, z = centers[i]
         for loc in [mesh.vertices[vertex].co for vertex in loop]:
             mat[0][0] += (loc[0]-x)**2
-            mat[0][1] += (loc[0]-x)*(loc[1]-y)
-            mat[0][2] += (loc[0]-x)*(loc[2]-z)
-            mat[1][0] += (loc[1]-y)*(loc[0]-x)
+            mat[1][0] += (loc[0]-x)*(loc[1]-y)
+            mat[2][0] += (loc[0]-x)*(loc[2]-z)
+            mat[0][1] += (loc[1]-y)*(loc[0]-x)
             mat[1][1] += (loc[1]-y)**2
-            mat[1][2] += (loc[1]-y)*(loc[2]-z)
-            mat[2][0] += (loc[2]-z)*(loc[0]-x)
-            mat[2][1] += (loc[2]-z)*(loc[1]-y)
+            mat[2][1] += (loc[1]-y)*(loc[2]-z)
+            mat[0][2] += (loc[2]-z)*(loc[0]-x)
+            mat[1][2] += (loc[2]-z)*(loc[1]-y)
             mat[2][2] += (loc[2]-z)**2
         # plane normal
         normal = False
@@ -926,12 +934,20 @@
             elif sum(mat[2]) == 0:
                 normal = mathutils.Vector((0.0, 0.0, 1.0))
         if not normal:
+            # warning! this is different from .normalize()
+            itermax = 500
+            iter = 0
             vec = mathutils.Vector((1.0, 1.0, 1.0))
-            normal = (mat * vec)/(mat * vec).length
-            if normal.length == 0:
-                normal = vec
-            else:
-                normal.normalize()
+            vec2 = (mat * vec)/(mat * vec).length
+            while vec != vec2 and iter<itermax:
+                iter+=1
+                vec = vec2
+                vec2 = mat * vec
+                if vec2.length != 0:
+                    vec2 /= vec2.length
+            if vec2.length == 0:
+                vec2 = mathutils.Vector((1.0, 1.0, 1.0))
+            normal = vec2
         normals.append(normal)
     # have plane normals face in the same direction (maximum angle: 90 degrees)
     if ((center1 + normals[0]) - center2).length < \
@@ -1643,14 +1659,14 @@
         for i in range(len(jmat)):
             k2 += mathutils.Vector(jmat[i])*k[i]
             jmat2[0][0] += jmat[i][0]**2
-            jmat2[0][1] += jmat[i][0]*jmat[i][1]
-            jmat2[0][2] += jmat[i][0]*jmat[i][2]
+            jmat2[1][0] += jmat[i][0]*jmat[i][1]
+            jmat2[2][0] += jmat[i][0]*jmat[i][2]
             jmat2[1][1] += jmat[i][1]**2
-            jmat2[1][2] += jmat[i][1]*jmat[i][2]
+            jmat2[2][1] += jmat[i][1]*jmat[i][2]
             jmat2[2][2] += jmat[i][2]**2
-        jmat2[1][0] = jmat2[0][1]
-        jmat2[2][0] = jmat2[0][2]
-        jmat2[2][1] = jmat2[1][2]
+        jmat2[0][1] = jmat2[1][0]
+        jmat2[0][2] = jmat2[2][0]
+        jmat2[1][2] = jmat2[2][1]
         try:
             jmat2.invert()
         except:



More information about the Bf-extensions-cvs mailing list