[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3969] branches/broken_stuff/ add_mesh_column.py: Improved but not yet final.

Jim Bates jsbates at pacbell.net
Thu Nov 15 03:47:20 CET 2012


Revision: 3969
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3969
Author:   jambay
Date:     2012-11-15 02:47:15 +0000 (Thu, 15 Nov 2012)
Log Message:
-----------
Improved but not yet final. Can create wire mesh for base/capital with local utility functions but not complete (a.k.a. missing faces).

Modified Paths:
--------------
    branches/broken_stuff/add_mesh_column.py

Modified: branches/broken_stuff/add_mesh_column.py
===================================================================
--- branches/broken_stuff/add_mesh_column.py	2012-11-14 22:39:45 UTC (rev 3968)
+++ branches/broken_stuff/add_mesh_column.py	2012-11-15 02:47:15 UTC (rev 3969)
@@ -26,8 +26,8 @@
 bl_info = {
     "name": "Columns",
     "author": "Jim Bates, jambay",
-    "version": (0, 11),
-    "blender": (2, 5, 7),
+    "version": (0, 12),
+    "blender": (2, 6, 4),
     "location": "View3D > Add > Mesh > Columns",
     "description": "Add architectural column(s).",
     "warning": "WIP - Initial implementation; updates pending and API not final for Blender",
@@ -66,6 +66,7 @@
 
 
 # Version History
+# v0.12 2012/11/14	"Restored" local uitilites for base/capital generation due to bpy.ops.mesh.spin not working for this addon.
 # v0.11 2011/06/14	Added width parameter for base and capital.
 # v0.10 2011/06/13	Consolidated base and capital "add" functions. More styles. Fixed taper with negative radius.
 # v0.09 2011/06/06	Column fluting - 90%. Added "sides" parameter for flutes, not sure I want to fix "odd" behavior.
@@ -84,6 +85,81 @@
 from math import *
 from bpy.props import *
 
+
+##########################################################################################
+##########################################################################################
+##                    Miscellaneous Utilities - taken from Bolt Factory
+##
+
+#Create a matrix representing a rotation.
+#
+#Parameters:
+#
+#        * angle (float) - The angle of rotation desired.
+#        * matSize (int) - The size of the rotation matrix to construct. Can be 2d, 3d, or 4d.
+#        * axisFlag (string (optional)) - Possible values:
+#              o "x - x-axis rotation"
+#              o "y - y-axis rotation"
+#              o "z - z-axis rotation"
+#              o "r - arbitrary rotation around vector"
+#        * axis (Vector object. (optional)) - The arbitrary axis of rotation used with "R"
+#
+#Returns: Matrix object.
+#    A new rotation matrix.
+def Simple_RotationMatrix(angle, matSize, axisFlag):
+    if matSize != 4 :
+        print ("Simple_RotationMatrix can only do 4x4")
+
+    q = radians(angle)  #make the rotation go clockwise
+
+    if axisFlag == 'x':
+        matrix = mathutils.Matrix.Rotation(q, 4, 'X')
+    elif  axisFlag == 'y':
+        matrix = mathutils.Matrix.Rotation(q, 4, 'Y')
+    elif axisFlag == 'z':
+        matrix = mathutils.Matrix.Rotation(q, 4, 'Z')
+    else:
+        print   ("Simple_RotationMatrix can only do x y z axis")
+    return matrix
+
+
+# Returns a list of verts rotated by the given matrix. Used by SpinDup
+def Rot_Mesh(verts, matrix):
+    from mathutils import Vector
+    return [(matrix * Vector(v))[:] for v in verts]
+
+
+# Returns a list of faces that has their index incremented by offset
+def Copy_Faces(faces,offset):
+    return [[(i + offset) for i in f] for f in faces]
+
+
+# Much like Blenders built in SpinDup.
+def SpinDup(VERTS,FACES,DEGREE,DIVISIONS,AXIS):
+    verts=[]
+    faces=[]
+
+    if DIVISIONS == 0:
+        DIVISIONS = 1
+
+    step = DEGREE/DIVISIONS # set step so pieces * step = degrees in arc
+
+    for i in range(int(DIVISIONS)):
+        rotmat = Simple_RotationMatrix(step*i, 4, AXIS) # 4x4 rotation matrix, 30d about the x axis.
+        Rot = Rot_Mesh(VERTS,rotmat)
+        faces.extend(Copy_Faces(FACES,len(verts)))
+        verts.extend(Rot)
+    return verts,faces
+
+
+##
+## The previous utility functions were "restored" here due to failure of
+## bpy.ops.mesh.spin for base/cap generation in Blender 2.6x versions.
+##
+##########################################################################################
+##########################################################################################
+
+
 # A very simple "bridge" tool.
 # Connects two equally long vertex rows with faces.
 # Returns a list of the new faces (list of  lists)
@@ -219,7 +295,9 @@
 
     return newpoints
 
-
+##########################################################################################
+# Unused but possibly useful variations...
+# 
 # save a copy of add_col_flute, v 0.8, in case it gets "fixed"...
 # makes flower petal/notch effect...
 def add_notch(angle, target, zpos, radius, Ad, sides=6):
@@ -324,7 +402,10 @@
 
     return newpoints
 
+#
+##########################################################################################
 
+
 #####
 def add_col_face(angle, target, zpos, radius):
     """
@@ -1004,18 +1085,21 @@
         # Make a mesh from a list of verts/edges/faces.
 
         if self.col_base:
+            bVerts, bFaces = SpinDup(vertsBase, edgesBase, 360, (self.base_faces*4), 'z')
+            bVerts.extend(vertsBase)        #add the start verts to the Spin verts to complete the loop
+
+#
+# Need to make "solid" ... ditto capital.
+#
+
             meshBase = bpy.data.meshes.new("Base")
-            meshBase.from_pydata(vertsBase, edgesBase, [])
+            meshBase.from_pydata(bVerts, bFaces, [])
             meshBase.update()
 
             ob_new = bpy.data.objects.new("Base", meshBase)
             scene.objects.link(ob_new)
             scene.objects.active = ob_new
             ob_new.select = True
-            bpy.ops.object.editmode_toggle()
-            bpy.ops.mesh.spin(steps=(self.base_faces*4), dupli=False, degrees=360, center=(0,0,0), axis=(0,0,1))
-            bpy.ops.mesh.select_all(action='SELECT')
-            bpy.ops.object.editmode_toggle()
 
             # since base and cap use same logic to generate, rotate and reposition base for use with column...
             bpy.ops.transform.rotate(value=(3.14159,), axis=(1,0,0), constraint_axis=(True,False,False), constraint_orientation='GLOBAL',
@@ -1027,18 +1111,16 @@
                 snap_target='CLOSEST', snap_point=(0,0,0), snap_align=False, snap_normal=(0,0,0), texture_space=False, release_confirm=False)
 
         if self.col_cap:
+            cVerts, cFaces = SpinDup(vertsCap, edgesCap, 360, (self.cap_faces*4), 'z')
             meshCap = bpy.data.meshes.new("Capital")
-            meshCap.from_pydata(vertsCap, edgesCap, [])
+            meshCap.from_pydata(cVerts, cFaces, [])
             meshCap.update()
 
             ob_new = bpy.data.objects.new("Capital", meshCap)
             scene.objects.link(ob_new)
             scene.objects.active = ob_new
             ob_new.select = True
-            bpy.ops.object.editmode_toggle()
-            bpy.ops.mesh.spin(steps=(self.cap_faces*4), dupli=False, degrees=360, center=(0,0,0), axis=(0,0,1))
-            bpy.ops.object.editmode_toggle()
-        
+
         mesh = bpy.data.meshes.new("Column")
         mesh.from_pydata(verts, [], faces)
 
@@ -1057,8 +1139,6 @@
             bpy.ops.object.editmode_toggle()
 
         ob_new.location = tuple(context.scene.cursor_location)
-#        ob_new.rotation_quaternion = [1.0,0.0,0.0,0.0]
-#        ob_new.rotation_quaternion = [0.0,0.0,0.0,0.0]
 
         return {'FINISHED'}
 



More information about the Bf-extensions-cvs mailing list