[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28417] trunk/blender: py api

Campbell Barton ideasman42 at gmail.com
Sun Apr 25 21:28:46 CEST 2010


Revision: 28417
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28417
Author:   campbellbarton
Date:     2010-04-25 21:27:59 +0200 (Sun, 25 Apr 2010)

Log Message:
-----------
py api
- mathutils.Color.hsv attribute. eg. material.diffuse_color.hsv = 0.2, 0.8, 0.4
- Vector/Euler/Quaternion/Color now only take a single seq arg.
- internal function for parsing arrays. (cleanup messy internal list/vector/tuple/seq parsing)
- didnt update rigify yet.

Modified Paths:
--------------
    trunk/blender/release/scripts/io/export_fbx.py
    trunk/blender/release/scripts/io/import_anim_bvh.py
    trunk/blender/release/scripts/modules/bpy_types.py
    trunk/blender/release/scripts/op/add_mesh_torus.py
    trunk/blender/release/scripts/op/object.py
    trunk/blender/release/scripts/op/uvcalc_smart_project.py
    trunk/blender/release/scripts/op/vertexpaint_dirt.py
    trunk/blender/source/blender/python/generic/mathutils.c
    trunk/blender/source/blender/python/generic/mathutils.h
    trunk/blender/source/blender/python/generic/mathutils_color.c
    trunk/blender/source/blender/python/generic/mathutils_euler.c
    trunk/blender/source/blender/python/generic/mathutils_quat.c
    trunk/blender/source/blender/python/generic/mathutils_vector.c

Modified: trunk/blender/release/scripts/io/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/io/export_fbx.py	2010-04-25 15:39:04 UTC (rev 28416)
+++ trunk/blender/release/scripts/io/export_fbx.py	2010-04-25 19:27:59 UTC (rev 28417)
@@ -54,50 +54,11 @@
 import math # math.pi
 import shutil # for file copying
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-# import Blender
 import bpy
-import mathutils
+from mathutils import Vector, Euler, Matrix, RotationMatrix
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 def copy_file(source, dest):
+    # XXX - remove, can use shutil
     file = open(source, 'rb')
     data = file.read()
     file.close()
@@ -135,7 +96,7 @@
 # I guess FBX uses degrees instead of radians (Arystan).
 # Call this function just before writing to FBX.
 def eulerRadToDeg(eul):
-    ret = mathutils.Euler()
+    ret = Euler()
 
     ret.x = 180 / math.pi * eul[0]
     ret.y = 180 / math.pi * eul[1]
@@ -143,10 +104,10 @@
 
     return ret
 
-mtx4_identity = mathutils.Matrix()
+mtx4_identity = Matrix()
 
 # testing
-mtx_x90		= mathutils.RotationMatrix( math.pi/2, 3, 'X') # used
+mtx_x90		= RotationMatrix( math.pi/2, 3, 'X') # used
 #mtx_x90n	= RotationMatrix(-90, 3, 'x')
 #mtx_y90	= RotationMatrix( 90, 3, 'y')
 #mtx_y90n	= RotationMatrix(-90, 3, 'y')
@@ -154,11 +115,11 @@
 #mtx_z90n	= RotationMatrix(-90, 3, 'z')
 
 #mtx4_x90	= RotationMatrix( 90, 4, 'x')
-mtx4_x90n	= mathutils.RotationMatrix(-math.pi/2, 4, 'X') # used
+mtx4_x90n	= RotationMatrix(-math.pi/2, 4, 'X') # used
 #mtx4_y90	= RotationMatrix( 90, 4, 'y')
-mtx4_y90n	= mathutils.RotationMatrix(-math.pi/2, 4, 'Y') # used
-mtx4_z90	= mathutils.RotationMatrix( math.pi/2, 4, 'Z') # used
-mtx4_z90n	= mathutils.RotationMatrix(-math.pi/2, 4, 'Z') # used
+mtx4_y90n	= RotationMatrix(-math.pi/2, 4, 'Y') # used
+mtx4_z90	= RotationMatrix( math.pi/2, 4, 'Z') # used
+mtx4_z90n	= RotationMatrix(-math.pi/2, 4, 'Z') # used
 
 # def strip_path(p):
 # 	return p.split('\\')[-1].split('/')[-1]
@@ -333,7 +294,7 @@
         EXP_CAMERA =				True,
         EXP_EMPTY =					True,
         EXP_IMAGE_COPY =			False,
-        GLOBAL_MATRIX =				mathutils.Matrix(),
+        GLOBAL_MATRIX =				Matrix(),
         ANIM_ENABLE =				True,
         ANIM_OPTIMIZE =				True,
         ANIM_OPTIMIZE_PRECISSION =	6,
@@ -600,8 +561,8 @@
                 matrix_rot = matrix_rot * mtx_x90
             elif type =='CAMERA':
 # 			elif ob and type =='Camera':
-                y = matrix_rot * mathutils.Vector(0,1,0)
-                matrix_rot = mathutils.RotationMatrix(math.pi/2, 3, y) * matrix_rot
+                y = matrix_rot * Vector((0.0, 1.0, 0.0))
+                matrix_rot = RotationMatrix(math.pi/2, 3, y) * matrix_rot
 
             return matrix_rot
 
@@ -702,8 +663,8 @@
                     matrix_rot = matrix_rot * mtx_x90
                     rot = tuple(matrix_rot.to_euler())
                 elif ob and ob.type =='Camera':
-                    y = matrix_rot * mathutils.Vector(0,1,0)
-                    matrix_rot = mathutils.RotationMatrix(math.pi/2, 3, y) * matrix_rot
+                    y = matrix_rot * Vector((0.0, 1.0, 0.0))
+                    matrix_rot = RotationMatrix(math.pi/2, 3, y) * matrix_rot
                     rot = tuple(matrix_rot.to_euler())
                 else:
                     rot = tuple(matrix_rot.to_euler())
@@ -1088,8 +1049,8 @@
         file.write('\n\t\tTypeFlags: "Camera"')
         file.write('\n\t\tGeometryVersion: 124')
         file.write('\n\t\tPosition: %.6f,%.6f,%.6f' % loc)
-        file.write('\n\t\tUp: %.6f,%.6f,%.6f' % tuple(matrix_rot * mathutils.Vector(0,1,0)) )
-        file.write('\n\t\tLookAt: %.6f,%.6f,%.6f' % tuple(matrix_rot * mathutils.Vector(0,0,-1)) )
+        file.write('\n\t\tUp: %.6f,%.6f,%.6f' % tuple(matrix_rot * Vector((0.0, 1.0, 0.0))))
+        file.write('\n\t\tLookAt: %.6f,%.6f,%.6f' % tuple(matrix_rot * Vector((0.0, 0.0, -1.0))))
 
         #file.write('\n\t\tUp: 0,0,0' )
         #file.write('\n\t\tLookAt: 0,0,0' )

Modified: trunk/blender/release/scripts/io/import_anim_bvh.py
===================================================================
--- trunk/blender/release/scripts/io/import_anim_bvh.py	2010-04-25 15:39:04 UTC (rev 28416)
+++ trunk/blender/release/scripts/io/import_anim_bvh.py	2010-04-25 19:27:59 UTC (rev 28417)
@@ -83,7 +83,7 @@
 
     # Should work but doesnt!
     '''
-    eul = Euler(x,y,z)
+    eul = Euler((x, y, z))
     eul.order = "XYZ"[rot_order[0]] + "XYZ"[rot_order[1]] + "XYZ"[rot_order[2]]
     return tuple(eul.to_matrix().to_euler())
     '''
@@ -136,7 +136,7 @@
             #print '%snode: %s, parent: %s' % (len(bvh_nodes_serial) * '  ', name,  bvh_nodes_serial[-1])
 
             lineIdx += 2 # Incriment to the next line (Offset)
-            rest_head_local = Vector(float(file_lines[lineIdx][1]), float(file_lines[lineIdx][2]), float(file_lines[lineIdx][3])) * GLOBAL_SCALE
+            rest_head_local = Vector((float(file_lines[lineIdx][1]), float(file_lines[lineIdx][2]), float(file_lines[lineIdx][3]))) * GLOBAL_SCALE
             lineIdx += 1 # Incriment to the next line (Channels)
 
             # newChannel[Xposition, Yposition, Zposition, Xrotation, Yrotation, Zrotation]
@@ -188,7 +188,7 @@
         # Account for an end node
         if file_lines[lineIdx][0].lower() == 'end' and file_lines[lineIdx][1].lower() == 'site': # There is somtimes a name after 'End Site' but we will ignore it.
             lineIdx += 2 # Incriment to the next line (Offset)
-            rest_tail = Vector(float(file_lines[lineIdx][1]), float(file_lines[lineIdx][2]), float(file_lines[lineIdx][3])) * GLOBAL_SCALE
+            rest_tail = Vector((float(file_lines[lineIdx][1]), float(file_lines[lineIdx][2]), float(file_lines[lineIdx][3]))) * GLOBAL_SCALE
 
             bvh_nodes_serial[-1].rest_tail_world = bvh_nodes_serial[-1].rest_head_world + rest_tail
             bvh_nodes_serial[-1].rest_tail_local = bvh_nodes_serial[-1].rest_head_local + rest_tail
@@ -267,8 +267,8 @@
                 #	raise 'error, bvh node has no end and no children. bad file'
 
                 # Removed temp for now
-                rest_tail_world = Vector(0.0, 0.0, 0.0)
-                rest_tail_local = Vector(0.0, 0.0, 0.0)
+                rest_tail_world = Vector((0.0, 0.0, 0.0))
+                rest_tail_local = Vector((0.0, 0.0, 0.0))
                 for bvh_node_child in bvh_node.children:
                     rest_tail_world += bvh_node_child.rest_head_world
                     rest_tail_local += bvh_node_child.rest_head_local
@@ -328,7 +328,7 @@
             lx, ly, lz, rx, ry, rz = bvh_node.anim_data[frame_current]
 
             rest_head_local = bvh_node.rest_head_local
-            bvh_node.temp.loc = rest_head_local + Vector(lx, ly, lz)
+            bvh_node.temp.loc = rest_head_local + Vector((lx, ly, lz))
 
             bvh_node.temp.rot = rx, ry, rz
 
@@ -531,7 +531,7 @@
                     prev_euler[i] = euler
 
             if bvh_node.has_loc:
-                pose_bone.location = (bone_rest_matrix_inv * TranslationMatrix(Vector(lx, ly, lz) - bvh_node.rest_head_local)).translation_part()
+                pose_bone.location = (bone_rest_matrix_inv * TranslationMatrix(Vector((lx, ly, lz)) - bvh_node.rest_head_local)).translation_part()
 
             if bvh_node.has_loc:
                 pose_bone.keyframe_insert("location")

Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py	2010-04-25 15:39:04 UTC (rev 28416)
+++ trunk/blender/release/scripts/modules/bpy_types.py	2010-04-25 19:27:59 UTC (rev 28417)
@@ -95,19 +95,19 @@
     def x_axis(self):
         """ Vector pointing down the x-axis of the bone.
         """
-        return self.matrix.rotation_part() * Vector(1.0, 0.0, 0.0)
+        return self.matrix.rotation_part() * Vector((1.0, 0.0, 0.0))
 
     @property
     def y_axis(self):
         """ Vector pointing down the x-axis of the bone.
         """
-        return self.matrix.rotation_part() * Vector(0.0, 1.0, 0.0)
+        return self.matrix.rotation_part() * Vector((0.0, 1.0, 0.0))
 
     @property
     def z_axis(self):
         """ Vector pointing down the x-axis of the bone.
         """
-        return self.matrix.rotation_part() * Vector(0.0, 0.0, 1.0)
+        return self.matrix.rotation_part() * Vector((0.0, 0.0, 1.0))
 
     @property
     def basename(self):
@@ -237,7 +237,7 @@
         Expects a 4x4 or 3x3 matrix.
         """
         from mathutils import Vector
-        z_vec = self.matrix.rotation_part() * Vector(0.0, 0.0, 1.0)
+        z_vec = self.matrix.rotation_part() * Vector((0.0, 0.0, 1.0))
         self.tail = matrix * self.tail
         self.head = matrix * self.head
         scalar = matrix.median_scale

Modified: trunk/blender/release/scripts/op/add_mesh_torus.py
===================================================================
--- trunk/blender/release/scripts/op/add_mesh_torus.py	2010-04-25 15:39:04 UTC (rev 28416)
+++ trunk/blender/release/scripts/op/add_mesh_torus.py	2010-04-25 19:27:59 UTC (rev 28417)
@@ -39,8 +39,8 @@
         for minor_index in range(minor_seg):
             angle = 2 * pi * minor_index / minor_seg
 
-            vec = Vector(major_rad + (cos(angle) * minor_rad), 0.0,
-                        (sin(angle) * minor_rad)) * quat
+            vec = Vector((major_rad + (cos(angle) * minor_rad), 0.0,
+                        (sin(angle) * minor_rad))) * quat
 
             verts.extend([vec.x, vec.y, vec.z])
 

Modified: trunk/blender/release/scripts/op/object.py
===================================================================
--- trunk/blender/release/scripts/op/object.py	2010-04-25 15:39:04 UTC (rev 28416)
+++ trunk/blender/release/scripts/op/object.py	2010-04-25 19:27:59 UTC (rev 28417)
@@ -457,7 +457,7 @@
 
         SCALE_FAC = 0.01
         offset = 0.5 * SCALE_FAC
-        base_tri = Vector(-offset, -offset, 0.0), Vector(offset, -offset, 0.0), Vector(offset, offset, 0.0), Vector(-offset, offset, 0.0)
+        base_tri = Vector((-offset, -offset, 0.0)), Vector((offset, -offset, 0.0)), Vector((offset, offset, 0.0)), Vector((-offset, offset, 0.0))
 
         def matrix_to_quat(matrix):
             # scale = matrix.median_scale

Modified: trunk/blender/release/scripts/op/uvcalc_smart_project.py

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list