[Bf-extensions-cvs] [529d056] fbx_io_development: FBX import: Support armature pose.

Bastien Montagne noreply at git.blender.org
Tue May 6 10:01:48 CEST 2014


Commit: 529d056e9dae882dd560f70e70207df5cb207bfb
Author: Bastien Montagne
Date:   Tue May 6 09:55:32 2014 +0200
https://developer.blender.org/rBA529d056e9dae882dd560f70e70207df5cb207bfb

FBX import: Support armature pose.

Note Squirel test fails dramatically here, not sure why (other rigged chars are OK). :/

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

M	io_scene_fbx/import_fbx.py

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

diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 33978ee..68db37a 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -354,19 +354,18 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices):
     from mathutils import Matrix, Vector
 
     b_item, bsize, p_uuid, clusters = bones[b_uuid]
-    fbx_bdata, bl_bdata = b_item
-    if bl_bdata is not None:
-        return  # Might have already been created...
+    fbx_bdata, bl_bname = b_item
+    if bl_bname is not None:
+        return bl_arm.edit_bones[bl_bname]  # Have already been created...
 
     p_ebo = None
     if p_uuid is not None:
         # Recurse over parents!
-        blen_read_armatures_add_bone(bl_obj, bl_arm, bones, p_uuid, matrices)
-        p_ebo = bones[p_uuid][0][1]
+        p_ebo = blen_read_armatures_add_bone(bl_obj, bl_arm, bones, p_uuid, matrices)
 
     # Remember we assume (for now) that one bone only has one cluster, this will have to be checked ultimately.
     if not clusters:
-        return None, None
+        return None
     fbx_cdata, meshes, objects = clusters[0]
     objects = {o[1] for o in objects}
 
@@ -384,14 +383,16 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices):
     # ----
     # Now, create the (edit)bone.
     bmat_arm = amat_glob.inverted() * bmat_glob
-    bone_name_utf8 = elem_name_ensure_class(fbx_bdata, b'Model')
+    bone_name = elem_name_ensure_class(fbx_bdata, b'Model')
 
-    b_item[1] = ebo = bl_arm.edit_bones.new(name=bone_name_utf8)
+    ebo = bl_arm.edit_bones.new(name=bone_name)
+    bone_name = ebo.name  # Might differ from FBX bone name!
+    b_item[1] = bone_name  # since ebo is only valid in Edit mode... :/
 
     # So that our bone gets its final length, but still Y-aligned in armature space.
     ebo.tail = Vector((0.0, 1.0, 0.0)) * bsize
     # And rotate/move it to its final "rest pose".
-    ebo.transform(bmat_arm)
+    ebo.matrix = bmat_arm.normalized()
 
     # Connection to parent.
     if p_ebo is not None:
@@ -409,10 +410,10 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices):
     if indices and len(indices) == len(weights):
         for obj in objects:
             # We replace/override here...
-            if bone_name_utf8 not in obj.vertex_groups:
-                vg = obj.vertex_groups.new(bone_name_utf8)
+            if bone_name not in obj.vertex_groups:
+                vg = obj.vertex_groups.new(bone_name)
             else:
-                vg = obj.vertex_groups[bone_name_utf8]
+                vg = obj.vertex_groups[bone_name]
             for i, w in zip(indices, weights):
                 vg.add((i,), w, 'REPLACE')
 
@@ -428,6 +429,8 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices):
                 continue
             matrices[obj] = (amat_glob, mmat_glob)
 
+    return ebo
+
 
 def blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix):
     from mathutils import Matrix
@@ -479,6 +482,20 @@ def blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix):
             ob_me.matrix_basis = me_mat_back
         bl_adata.matrix_basis = arm_mat_back
 
+        # Set Pose transformations...
+        for b_item, _b_size, _p_uuid, _clusters in bones.values():
+            fbx_bdata, bl_bname = b_item
+            fbx_props = (elem_find_first(fbx_bdata, b'Properties70'),
+                         elem_find_first(fbx_tmpl, b'Properties70', fbx_elem_nil))
+            assert(fbx_props[0] is not None)
+
+            pbo = b_item[1] = bl_adata.pose.bones[bl_bname]
+            mat = blen_read_object_transform(fbx_props, fbx_bdata, Matrix())
+            if pbo.parent:
+                # Bring back matrix in armature space.
+                mat = pbo.parent.matrix * mat
+            pbo.matrix = mat
+
 
 # ----
 # Mesh
@@ -924,7 +941,7 @@ def blen_read_texture(fbx_tmpl, fbx_obj, basedir, image_cache,
     import os
     from bpy_extras import image_utils
 
-    elem_name_utf8 = elem_name_ensure_class(fbx_obj, b'NodeAttribute')
+    elem_name_utf8 = elem_name_ensure_class(fbx_obj, b'Texture')
 
     filepath = elem_find_first_string(fbx_obj, b'FileName')
     if os.sep == '/':
@@ -1310,8 +1327,6 @@ def load(operator, context, filepath="",
                                     objects.append(o_item)
                                 meshes.add(bl_mdata)
                             # Skin deformers are only here to connect clusters to meshes, for us, nothing else to do.
-                        print(objects)
-                        print(meshes)
                         clusters.append((fbx_cdata, meshes, objects))
                     # For now, we assume there is only one cluster & skin per bone (at least for a given armature)!
                     assert(len(clusters) <= 1)



More information about the Bf-extensions-cvs mailing list