[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3393] trunk/py/scripts/addons/ io_scene_fbx/export_fbx.py: patch from Doug Perkowski

Campbell Barton ideasman42 at gmail.com
Thu May 24 09:26:09 CEST 2012


Revision: 3393
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3393
Author:   campbellbarton
Date:     2012-05-24 07:26:08 +0000 (Thu, 24 May 2012)
Log Message:
-----------
patch from Doug Perkowski

from Doug:

Most applications aren't very strict with the bind pose because they support different bind poses for different meshes.  Ogre requires a single bind pose for all meshes, which makes things a lot more difficult. 

The changes are where the BindPose is defined (which is pretty much ignored by most applications, but you seemed to have added it for XNA), and the skin deformer.  In both cases, global transforms for bones were not correctly being exported.  I set global transforms for the bones equal to (my_bone.fbxArm.matrixWorld * my_bone.restMatrix) * mtx4_z90.  That  appears to do the trick for me, though I can't say I fully understand how the terms are derived.

I've tested kngcalvn_fbx_test_new.fbx and our sample file in Maya & our FBX importer, and both work with the changes.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_scene_fbx/export_fbx.py

Modified: trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/export_fbx.py	2012-05-24 01:16:29 UTC (rev 3392)
+++ trunk/py/scripts/addons/io_scene_fbx/export_fbx.py	2012-05-24 07:26:08 UTC (rev 3393)
@@ -686,8 +686,12 @@
 
         #~ poseMatrix = write_object_props(my_bone.blenBone, None, None, my_bone.fbxArm.parRelMatrix())[3]
         poseMatrix = write_object_props(my_bone.blenBone, pose_bone=my_bone.getPoseBone())[3]  # dont apply bone matrices anymore
-        pose_items.append((my_bone.fbxName, poseMatrix))
 
+        # Use the same calculation as in write_sub_deformer_skin to compute the global
+        # transform of the bone for the bind pose.
+        global_matrix_bone = (my_bone.fbxArm.matrixWorld * my_bone.restMatrix) * mtx4_z90
+        pose_items.append((my_bone.fbxName, global_matrix_bone))
+
         # fw('\n\t\t\tProperty: "Size", "double", "",%.6f' % ((my_bone.blenData.head['ARMATURESPACE'] - my_bone.blenData.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length)
         fw('\n\t\t\tProperty: "Size", "double", "",1')
 
@@ -1331,19 +1335,19 @@
                 fw(',%.8f' % vg[1])
             i += 1
 
-        if my_mesh.fbxParent:
-            # TODO FIXME, this case is broken in some cases. skinned meshes just shouldnt have parents where possible!
-            m = (my_mesh.matrixWorld.inverted() * my_bone.fbxArm.matrixWorld.copy() * my_bone.restMatrix) * mtx4_z90
-        else:
-            # Yes! this is it...  - but dosnt work when the mesh is a.
-            m = (my_mesh.matrixWorld.inverted() * my_bone.fbxArm.matrixWorld.copy() * my_bone.restMatrix) * mtx4_z90
+        # Set TransformLink to the global transform of the bone and Transform
+        # equal to the mesh's transform in bone space.
+        # http://area.autodesk.com/forum/autodesk-fbx/fbx-sdk/why-the-values-return-by-fbxcluster-gettransformmatrix-x-not-same-with-the-value-in-ascii-fbx-file/
 
-        #m = mtx4_z90 * my_bone.restMatrix
-        matstr = mat4x4str(m)
-        matstr_i = mat4x4str(m.inverted())
+        global_bone_matrix = (my_bone.fbxArm.matrixWorld * my_bone.restMatrix) * mtx4_z90
+        global_mesh_matrix = my_mesh.matrixWorld
+        transform_matrix = (global_bone_matrix.inverted() * global_mesh_matrix)
 
-        fw('\n\t\tTransform: %s' % matstr_i)  # THIS IS __NOT__ THE GLOBAL MATRIX AS DOCUMENTED :/
-        fw('\n\t\tTransformLink: %s' % matstr)
+        global_bone_matrix_string = mat4x4str(global_bone_matrix )
+        transform_matrix_string = mat4x4str(transform_matrix )
+
+        fw('\n\t\tTransform: %s' % transform_matrix_string)
+        fw('\n\t\tTransformLink: %s' % global_bone_matrix_string)
         fw('\n\t}')
 
     def write_mesh(my_mesh):
@@ -1367,8 +1371,12 @@
         me_faces = me.tessfaces[:]
 
         poseMatrix = write_object_props(my_mesh.blenObject, None, my_mesh.parRelMatrix())[3]
-        pose_items.append((my_mesh.fbxName, poseMatrix))
 
+        # Calculate the global transform for the mesh in the bind pose the same way we do
+        # in write_sub_deformer_skin
+        globalMeshBindPose = my_mesh.matrixWorld * mtx4_z90
+        pose_items.append((my_mesh.fbxName, globalMeshBindPose))
+
         if do_shapekeys:
             for kb in my_mesh.blenObject.data.shape_keys.key_blocks[1:]:
                 fw('\n\t\t\tProperty: "%s", "Number", "AN",0' % kb.name)



More information about the Bf-extensions-cvs mailing list