[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33092] trunk/blender/release/scripts/op/ io_scene_fbx/export_fbx.py: FBX Export, small changes made while looking into reported bug.

Campbell Barton ideasman42 at gmail.com
Tue Nov 16 05:32:36 CET 2010


Revision: 33092
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33092
Author:   campbellbarton
Date:     2010-11-16 05:32:35 +0100 (Tue, 16 Nov 2010)

Log Message:
-----------
FBX Export, small changes made while looking into reported bug. (no functional changes)
- Warn for armature deformed meshes which are scaled, these don't work quite the same as in blender, reported as [#24663].
- Use matrix.decompose() to convert a matrix to loc/rot/scale.
- get vert/edge/face lists for each mesh only once.
- faster euler rad -> deg conversion function.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py

Modified: trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py	2010-11-16 03:11:22 UTC (rev 33091)
+++ trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py	2010-11-16 04:32:35 UTC (rev 33092)
@@ -63,16 +63,10 @@
 
 # I guess FBX uses degrees instead of radians (Arystan).
 # Call this function just before writing to FBX.
-def eulerRadToDeg(eul):
-    ret = Euler()
+# 180 / math.pi == 57.295779513
+def tuple_rad_to_deg(eul):
+    return eul[0] * 57.295779513, eul[1] * 57.295779513, eul[2] * 57.295779513
 
-    ret.x = 180 / math.pi * eul[0]
-    ret.y = 180 / math.pi * eul[1]
-    ret.z = 180 / math.pi * eul[2]
-
-    return ret
-
-
 # def strip_path(p):
 # 	return p.split('\\')[-1].split('/')[-1]
 
@@ -609,12 +603,12 @@
 # 				par_matrix = mtx4_z90 * parent.matrix['ARMATURESPACE'] # dont apply armature matrix anymore
                 matrix = par_matrix.copy().invert() * matrix
 
-            matrix_rot =	matrix.rotation_part()
-
-            loc =			tuple(matrix.translation_part())
-            scale =			tuple(matrix.scale_part())
-            rot =			tuple(matrix_rot.to_euler())
-
+            loc, rot, scale = matrix.decompose()
+            matrix_rot = rot.to_matrix()
+            
+            loc = tuple(loc)
+            rot = tuple(rot.to_euler()) # quat -> euler
+            scale = tuple(scale)
         else:
             # This is bad because we need the parent relative matrix from the fbx parent (if we have one), dont use anymore
             #if ob and not matrix: matrix = ob.matrix_world * GLOBAL_MATRIX
@@ -625,20 +619,20 @@
             #	matrix = matrix_scale * matrix
 
             if matrix:
-                loc = tuple(matrix.translation_part())
-                scale = tuple(matrix.scale_part())
+                loc, rot, scale = matrix.decompose()
+                matrix_rot = rot.to_matrix()
 
-                matrix_rot = matrix.rotation_part()
                 # Lamps need to be rotated
                 if ob and ob.type =='LAMP':
                     matrix_rot = matrix_rot * mtx_x90
-                    rot = tuple(matrix_rot.to_euler())
                 elif ob and ob.type =='CAMERA':
                     y = Vector((0.0, 1.0, 0.0)) * matrix_rot
                     matrix_rot = Matrix.Rotation(math.pi/2, 3, y) * matrix_rot
-                    rot = tuple(matrix_rot.to_euler())
-                else:
-                    rot = tuple(matrix_rot.to_euler())
+                # else do nothing.
+
+                loc = tuple(loc)
+                rot = tuple(matrix_rot.to_euler())
+                scale = tuple(scale)
             else:
                 if not loc:
                     loc = 0,0,0
@@ -656,7 +650,7 @@
         loc, rot, scale, matrix, matrix_rot = object_tx(ob, loc, matrix, matrix_mod)
 
         file.write('\n\t\t\tProperty: "Lcl Translation", "Lcl Translation", "A+",%.15f,%.15f,%.15f' % loc)
-        file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % tuple(eulerRadToDeg(rot)))
+        file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % tuple_rad_to_deg(rot))
 # 		file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % rot)
         file.write('\n\t\t\tProperty: "Lcl Scaling", "Lcl Scaling", "A+",%.15f,%.15f,%.15f' % scale)
         return loc, rot, scale, matrix, matrix_rot
@@ -1413,18 +1407,18 @@
         me = my_mesh.blenData
 
         # if there are non NULL materials on this mesh
-        if my_mesh.blenMaterials:	do_materials = True
-        else:						do_materials = False
-
-        if my_mesh.blenTextures:	do_textures = True
-        else:						do_textures = False
-
+        do_materials = bool(my_mesh.blenMaterials)
+        do_textures = bool(my_mesh.blenTextures)
         do_uvs = bool(me.uv_textures)
 
-
         file.write('\n\tModel: "Model::%s", "Mesh" {' % my_mesh.fbxName)
         file.write('\n\t\tVersion: 232') # newline is added in write_object_props
 
+        # convert into lists once.
+        me_vertices = me.vertices[:]
+        me_edges = me.edges[:]
+        me_faces = me.faces[:]
+
         poseMatrix = write_object_props(my_mesh.blenObject, None, my_mesh.parRelMatrix())[3]
         pose_items.append((my_mesh.fbxName, poseMatrix))
 
@@ -1439,7 +1433,7 @@
         file.write('\n\t\tVertices: ')
         i=-1
 
-        for v in me.vertices:
+        for v in me_vertices:
             if i==-1:
                 file.write('%.6f,%.6f,%.6f' % tuple(v.co));	i=0
             else:
@@ -1450,7 +1444,7 @@
 
         file.write('\n\t\tPolygonVertexIndex: ')
         i=-1
-        for f in me.faces:
+        for f in me_faces:
             fi = f.vertices[:]
 
             # last index XORd w. -1 indicates end of face
@@ -1470,7 +1464,7 @@
             i+=1
 
         # write loose edges as faces.
-        for ed in me.edges:
+        for ed in me_edges:
             if ed.is_loose:
                 ed_val = ed.vertices[:]
                 ed_val = ed_val[0], ed_val[-1] ^ -1
@@ -1488,7 +1482,7 @@
 
         file.write('\n\t\tEdges: ')
         i=-1
-        for ed in me.edges:
+        for ed in me_edges:
                 if i==-1:
                     file.write('%i,%i' % (ed.vertices[0], ed.vertices[1]))
                     i=0
@@ -1510,7 +1504,7 @@
             Normals: ''')
 
         i=-1
-        for v in me.vertices:
+        for v in me_vertices:
             if i==-1:
                 file.write('%.15f,%.15f,%.15f' % tuple(v.normal));	i=0
             else:
@@ -1530,7 +1524,7 @@
             Smoothing: ''')
 
         i=-1
-        for f in me.faces:
+        for f in me_faces:
             if i==-1:
                 file.write('%i' % f.use_smooth);	i=0
             else:
@@ -1551,7 +1545,7 @@
             Smoothing: ''')
 
         i=-1
-        for ed in me.edges:
+        for ed in me_edges:
             if i==-1:
                 file.write('%i' % (ed.use_edge_sharp));	i=0
             else:
@@ -1589,7 +1583,7 @@
                 i = -1
                 ii = 0 # Count how many Colors we write
 
-                for f, cf in zip(me.faces, collayer.data):
+                for f, cf in zip(me_faces, collayer.data):
                     colors = [cf.color1, cf.color2, cf.color3, cf.color4]
 
                     # determine number of verts
@@ -1756,11 +1750,11 @@
                 if me.uv_textures.active:
                     uv_faces = me.uv_textures.active.data
                 else:
-                    uv_faces = [None] * len(me.faces)
+                    uv_faces = [None] * len(me_faces)
 
                 i=-1
-                for f, uf in zip(me.faces, uv_faces):
-# 				for f in me.faces:
+                for f, uf in zip(me_faces, uv_faces):
+# 				for f in me_faces:
                     try:	mat = mats[f.material_index]
                     except:mat = None
 
@@ -2028,6 +2022,10 @@
 
                         if armob and armob not in ob_arms:
                             ob_arms.append(armob)
+                            
+                        # Warning for scaled, mesh objects with armatures
+                        if abs(ob.scale[0] - 1.0) > 0.05 or abs(ob.scale[1] - 1.0) > 0.05 or abs(ob.scale[1] - 1.0) > 0.05:
+                            operator.report('WARNING', "Object '%s' has a scale of (%.3f, %.3f, %.3f), Armature deformation will not work as expected!, Apply Scale to fix." % ((ob.name,) + tuple(ob.scale)))
 
                     else:
                         blenParentBoneName = armob = None
@@ -2708,7 +2706,7 @@
                                 for mtx in context_bone_anim_mats:
                                     if prev_eul:	prev_eul = mtx[1].to_euler('XYZ', prev_eul)
                                     else:			prev_eul = mtx[1].to_euler()
-                                    context_bone_anim_vecs.append(eulerRadToDeg(prev_eul))
+                                    context_bone_anim_vecs.append(tuple_rad_to_deg(prev_eul))
 
                             file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation
 





More information about the Bf-blender-cvs mailing list