[Bf-extensions-cvs] [4a07e80] master: Merged experimental code in 'stable' addon (mainly Jens Restemeier's summer work).

Bastien Montagne noreply at git.blender.org
Wed Oct 8 15:44:18 CEST 2014


Commit: 4a07e805addbe606d80223811d6d29c68579b603
Author: Bastien Montagne
Date:   Wed Oct 8 15:33:56 2014 +0200
Branches: master
https://developer.blender.org/rBA4a07e805addbe606d80223811d6d29c68579b603

Merged experimental code in 'stable' addon (mainly Jens Restemeier's summer work).

Will remove experimental one soon. Keeping old 6.1 exporter active for now, though.

Notes:
* Not 100% happy with how complex code is now... Rather sure though refactor would
  take a huge amount of time, not worth it for now.
* New code handles things like armature & animation import much much better than previous one,
  so definitively worth it.
* New code also fixes some real bugs (like Blender-side of T42135).
* Did a few cosmetic changes on the run, nothing serious.

This should make FBX work complete, aside from a few nice TODOs that I'll tackle in comming weeks,
in addition to ongoing bugbusting.

Many thanks to Jens for his work on armature mess! :D

===================================================================

M	io_scene_fbx/__init__.py
M	io_scene_fbx/export_fbx_bin.py
M	io_scene_fbx/fbx_utils.py
M	io_scene_fbx/import_fbx.py

===================================================================

diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index eff4e13..dde8d39 100644
--- a/io_scene_fbx/__init__.py
+++ b/io_scene_fbx/__init__.py
@@ -19,12 +19,12 @@
 # <pep8 compliant>
 
 bl_info = {
-    "name": "Autodesk FBX format",
-    "author": "Campbell Barton, Bastien Montagne",
-    "version": (3, 1, 0),
-    "blender": (2, 70, 0),
+    "name": "FBX format",
+    "author": "Campbell Barton, Bastien Montagne, Jens Restemeier",
+    "version": (3, 2, 0),
+    "blender": (2, 72, 0),
     "location": "File > Import-Export",
-    "description": "Export FBX meshes, UV's, vertex colors, materials, "
+    "description": "FBX IO meshes, UV's, vertex colors, materials, "
                    "textures, cameras, lamps and actions",
     "warning": "",
     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
@@ -59,7 +59,7 @@ from bpy_extras.io_utils import (ImportHelper,
 
 
 class ImportFBX(bpy.types.Operator, ImportHelper):
-    """Load a FBX geometry file"""
+    """Load a FBX file"""
     bl_idname = "import_scene.fbx"
     bl_label = "Import FBX"
     bl_options = {'UNDO', 'PRESET'}
@@ -101,6 +101,13 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
             min=0.001, max=1000.0,
             default=1.0,
             )
+    bake_space_transform = BoolProperty(
+            name="Apply Transform",
+            description=("Bake space transform into object data, avoids getting unwanted rotations to objects when "
+                         "target space is not aligned with Blender's space "
+                         "(WARNING! experimental option, might give odd/wrong results)"),
+            default=False,
+            )
 
     use_image_search = BoolProperty(
             name="Image Search",
@@ -135,6 +142,41 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
             options={'HIDDEN'},
             )
 
+    ignore_leaf_bones = BoolProperty(
+            name="Ignore leaf bones",
+            description="Ignore the last bone at the end of a chain that is used to mark the length of the previous bone",
+            default=False,
+            options={'HIDDEN'},
+            )
+    automatic_bone_orientation = BoolProperty(
+            name="Automatic Bone Orientation",
+            description="Try to align the major bone axis with the bone children",
+            default=False,
+            options={'HIDDEN'},
+            )
+    primary_bone_axis = EnumProperty(
+            name="Primary Bone Axis",
+            items=(('X', "X Axis", ""),
+                   ('Y', "Y Axis", ""),
+                   ('Z', "Z Axis", ""),
+                   ('-X', "-X Axis", ""),
+                   ('-Y', "-Y Axis", ""),
+                   ('-Z', "-Z Axis", ""),
+                   ),
+            default='Y',
+            )
+    secondary_bone_axis = EnumProperty(
+            name="Secondary Bone Axis",
+            items=(('X', "X Axis", ""),
+                   ('Y', "Y Axis", ""),
+                   ('Z', "Z Axis", ""),
+                   ('-X', "-X Axis", ""),
+                   ('-Y', "-Y Axis", ""),
+                   ('-Z', "-Z Axis", ""),
+                   ),
+            default='X',
+            )
+
     def draw(self, context):
         layout = self.layout
 
@@ -143,7 +185,8 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
         sub.enabled = self.use_manual_orientation
         sub.prop(self, "axis_forward")
         sub.prop(self, "axis_up")
-        sub.prop(self, "global_scale")
+        layout.prop(self, "global_scale")
+        layout.prop(self, "bake_space_transform")
 
         layout.prop(self, "use_image_search")
         # layout.prop(self, "use_alpha_decals")
@@ -154,6 +197,14 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
         sub.enabled = self.use_custom_props
         sub.prop(self, "use_custom_props_enum_as_string")
 
+        layout.prop(self, "ignore_leaf_bones")
+
+        layout.prop(self, "automatic_bone_orientation"),
+        sub = layout.column()
+        sub.enabled = not self.automatic_bone_orientation
+        sub.prop(self, "primary_bone_axis")
+        sub.prop(self, "secondary_bone_axis")
+
     def execute(self, context):
         keywords = self.as_keywords(ignore=("filter_glob", "directory"))
         keywords["use_cycles"] = (context.scene.render.engine == 'CYCLES')
@@ -163,7 +214,7 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
 
 
 class ExportFBX(bpy.types.Operator, ExportHelper):
-    """Selection to an ASCII Autodesk FBX"""
+    """Write a FBX file"""
     bl_idname = "export_scene.fbx"
     bl_label = "Export FBX"
     bl_options = {'UNDO', 'PRESET'}
@@ -273,6 +324,35 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
             description="Export custom properties",
             default=False,
             )
+    add_leaf_bones = BoolProperty(
+            name="Add leaf bones",
+            description=("Append a last bone to the end of each chain to specify bone length. It is useful to, "
+                         "enable this when exporting into another modelling application and to disable this when"
+                         "exporting into a game engine or real-time viewer."),
+            default=True # False for commit!
+            )
+    primary_bone_axis = EnumProperty(
+            name="Primary Bone Axis",
+            items=(('X', "X Axis", ""),
+                   ('Y', "Y Axis", ""),
+                   ('Z', "Z Axis", ""),
+                   ('-X', "-X Axis", ""),
+                   ('-Y', "-Y Axis", ""),
+                   ('-Z', "-Z Axis", ""),
+                   ),
+            default='Y',
+            )
+    secondary_bone_axis = EnumProperty(
+            name="Secondary Bone Axis",
+            items=(('X', "X Axis", ""),
+                   ('Y', "Y Axis", ""),
+                   ('Z', "Z Axis", ""),
+                   ('-X', "-X Axis", ""),
+                   ('-Y', "-Y Axis", ""),
+                   ('-Z', "-Z Axis", ""),
+                   ),
+            default='X',
+            )
     use_armature_deform_only = BoolProperty(
             name="Only Deform Bones",
             description="Only write deforming bones (and non-deforming ones when they have deforming children)",
@@ -387,6 +467,9 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
         layout.prop(self, "use_armature_deform_only")
         if is_74bin:
             layout.prop(self, "use_custom_props")
+            layout.prop(self, "add_leaf_bones")
+            layout.prop(self, "primary_bone_axis")
+            layout.prop(self, "secondary_bone_axis")
             layout.prop(self, "bake_anim")
             col = layout.column()
             col.enabled = self.bake_anim
@@ -442,11 +525,11 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
 
 
 def menu_func_import(self, context):
-    self.layout.operator(ImportFBX.bl_idname, text="Autodesk FBX (.fbx)")
+    self.layout.operator(ImportFBX.bl_idname, text="FBX (.fbx)")
 
 
 def menu_func_export(self, context):
-    self.layout.operator(ExportFBX.bl_idname, text="Autodesk FBX (.fbx)")
+    self.layout.operator(ExportFBX.bl_idname, text="FBX (.fbx)")
 
 
 def register():
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index ff223fa..a5cfdd2 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1371,6 +1371,8 @@ def fbx_data_armature_elements(root, arm_obj, scene_data):
     mat_world_arm = arm_obj.fbx_object_matrix(scene_data, global_space=True)
     bones = tuple(bo_obj for bo_obj in arm_obj.bones if bo_obj in scene_data.objects)
 
+    bone_radius_scale = scene_data.settings.global_scale * 33.0
+
     # Bones "data".
     for bo_obj in bones:
         bo = bo_obj.bdata
@@ -1382,13 +1384,18 @@ def fbx_data_armature_elements(root, arm_obj, scene_data):
 
         tmpl = elem_props_template_init(scene_data.templates, b"Bone")
         props = elem_properties(fbx_bo)
-        elem_props_template_set(tmpl, props, "p_double", b"Size", (bo.tail_local - bo.head_local).length)
+        elem_props_template_set(tmpl, props, "p_double", b"Size", bo.head_radius * bone_radius_scale)
         elem_props_template_finalize(tmpl, props)
 
         # Custom properties.
         if scene_data.settings.use_custom_props:
             fbx_data_element_custom_properties(props, bo)
 
+        # Store Blender bone length - XXX Not much useful actually :/
+        # (LimbLength can't be used because it is a scale factor 0-1 for the parent-child distance:
+        # http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/cpp_ref/class_fbx_skeleton.html#a9bbe2a70f4ed82cd162620259e649f0f )
+        # elem_props_set(props, "p_double", "BlenderBoneLength".encode(), (bo.tail_local - bo.head_local).length, custom=True)
+
     # Skin deformers and BindPoses.
     # Note: we might also use Deformers for our "parent to vertex" stuff???
     deformer = scene_data.data_deformers_skin.get(arm_obj, None)
@@ -1450,6 +1457,56 @@ def fbx_data_armature_elements(root, arm_obj, scene_data):
                 elem_data_single_float64_array(fbx_clstr, b"TransformAssociateModel", matrix4_to_array(mat_world_arm))
 
 
+def fbx_data_leaf_bone_elements(root, scene_data):
+    # Write a dummy leaf bone that is used by applications to show the length of the last bone in a chain
+    for (node_name, _par_uuid, node_uuid, attr_uuid, matrix, hide, size) in scene_data.data_leaf_bones:
+        # Bone 'data'...
+        fbx_bo = elem_data_single_int64(root, b"NodeAttribute", attr_uuid)
+        fbx_bo.add_string(fbx_name_class(node_name.encode(), b"NodeAttribute"))
+        fbx_bo.add_string(b"LimbNode")
+        elem_data_single_string(fbx_bo, b"TypeFlags", b"Skeleton")
+
+        tmpl = elem_props_template_init(scene_data.templates, b"Bone")
+        props = elem_properties(fbx_bo)
+        elem_props_template_set(tmpl, props, "p_double", b"Size", size)
+        elem_props_template_finalize(tmpl, props)
+
+        # And bone object.
+        model = elem_data_single_int64(root, b"Model", node_uuid)
+        model.add_string(fbx_name_class(node_name.encode(), b"Model"))
+        model.add_string(b"LimbNode")
+
+        elem_data_single_int32(model, b"Ve

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list