[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3103] trunk/py/scripts/addons/ io_scene_fbx: option to export only deforming bones ( defaults to True for Unity3D)

Campbell Barton ideasman42 at gmail.com
Tue Mar 13 17:45:08 CET 2012


Revision: 3103
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3103
Author:   campbellbarton
Date:     2012-03-13 16:44:59 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
option to export only deforming bones (defaults to True for Unity3D)

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

Modified: trunk/py/scripts/addons/io_scene_fbx/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/__init__.py	2012-03-13 16:10:58 UTC (rev 3102)
+++ trunk/py/scripts/addons/io_scene_fbx/__init__.py	2012-03-13 16:44:59 UTC (rev 3103)
@@ -132,6 +132,11 @@
                          "pipeline errors with XNA"),
             default=False,
             )
+    use_armature_deform_only = BoolProperty(
+            name="Only Deform Bones",
+            description="Only write deforming bones",
+            default=False,
+            )
     use_anim = BoolProperty(
             name="Include Animation",
             description="Export keyframe animation",

Modified: trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/export_fbx.py	2012-03-13 16:10:58 UTC (rev 3102)
+++ trunk/py/scripts/addons/io_scene_fbx/export_fbx.py	2012-03-13 16:44:59 UTC (rev 3103)
@@ -216,6 +216,7 @@
         object_types={'EMPTY', 'CAMERA', 'LAMP', 'ARMATURE', 'MESH'},
         use_mesh_modifiers=True,
         mesh_smooth_type='FACE',
+        use_armature_deform_only=False,
         use_anim=True,
         use_anim_optimize=True,
         anim_optimize_precision=6,
@@ -2098,11 +2099,30 @@
         # fbxName, blenderObject, my_bones, blenderActions
         #ob_arms[i] = fbxArmObName, ob, arm_my_bones, (ob.action, [])
 
+        if use_armature_deform_only:
+            # tag non deforming bones that have no deforming children
+            deform_map = dict.fromkeys(my_arm.blenData.bones, False)
+            for bone in my_arm.blenData.bones:
+                if bone.use_deform:
+                    deform_map[bone] = True
+                    # tag all parents, even ones that are not deform since their child _is_
+                    for parent in bone.parent_recursive:
+                        deform_map[parent] = True
+
         for bone in my_arm.blenData.bones:
+
+            if use_armature_deform_only:
+                # if this bone doesnt deform, and none of its children deform, skip it!
+                if not deform_map[bone]:
+                    continue
+
             my_bone = my_bone_class(bone, my_arm)
             my_arm.fbxBones.append(my_bone)
             ob_bones.append(my_bone)
 
+        if use_armature_deform_only:
+            del deform_map
+
     # add the meshes to the bones and replace the meshes armature with own armature class
     #for obname, ob, mtx, me, mats, arm, armname in ob_meshes:
     for my_mesh in ob_meshes:
@@ -2932,6 +2952,7 @@
                 use_selection=False,
                 object_types={'ARMATURE', 'EMPTY', 'MESH'},
                 use_mesh_modifiers=True,
+                use_armature_deform_only=True,
                 use_anim=True,
                 use_anim_optimize=False,
                 use_anim_action_all=True,



More information about the Bf-extensions-cvs mailing list