[Bf-extensions-cvs] [551f78e] fbx_io_development: fixed problem when importing and deleting an FBX file several times in a row. Transform data was getting reused between imports, which resulted in strangely jumbled hierarchies and skeletons added support for "double" type user props fixed infinite loop in animation importer. This will need a cleanup when adding proper support for spline animation curves. fixed error when importing bone attributes without Properties70 child fixed error when creating alpha material (missing tex_map parameter)

Jens Ch. Restemeier noreply at git.blender.org
Thu Jul 31 13:36:56 CEST 2014


Commit: 551f78e6863ffb9a67bcfe5ac2aeaff99a2de0b6
Author: Jens Ch. Restemeier
Date:   Thu Jul 31 12:32:52 2014 +0100
Branches: fbx_io_development
https://developer.blender.org/rBA551f78e6863ffb9a67bcfe5ac2aeaff99a2de0b6

fixed problem when importing and deleting an FBX file several times in a row. Transform data was getting reused between imports, which resulted in strangely jumbled hierarchies and skeletons
added support for "double" type user props
fixed infinite loop in animation importer. This will need a cleanup when adding proper support for spline animation curves.
fixed error when importing bone attributes without Properties70 child
fixed error when creating alpha material (missing tex_map parameter)

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

M	io_scene_fbx/import_fbx.py

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

diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 51f9a0a..2663d97 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -274,9 +274,6 @@ FBXTransformData = namedtuple("FBXTransformData", (
     "sca", "sca_ofs", "sca_piv",
 ))
 
-
-object_tdata_cache = {}
-
 def blen_read_custom_properties(fbx_obj, blen_obj, settings):
     # There doesn't seem to be a way to put user properties into templates, so this only get the object properties:
     fbx_obj_props = elem_find_first(fbx_obj, b'Properties70')
@@ -312,7 +309,7 @@ def blen_read_custom_properties(fbx_obj, blen_obj, settings):
                     elif prop_type == b'KString':
                         assert(fbx_prop.props_type[4] == data_types.STRING)
                         blen_obj[prop_name] = fbx_prop.props[4].decode('utf-8')
-                    elif prop_type == b'Number':
+                    elif prop_type in {b'Number', b'double', b'Double'}:
                         assert(fbx_prop.props_type[4] == data_types.FLOAT64)
                         blen_obj[prop_name] = fbx_prop.props[4]
                     elif prop_type in {b'Float', b'float'}:
@@ -421,7 +418,7 @@ def blen_read_object_transform_preprocess(fbx_props, fbx_obj, rot_alt_mat):
                             sca, sca_ofs, sca_piv)
 
 
-def blen_read_object(fbx_tmpl, fbx_obj, object_data, settings):
+def blen_read_object(fbx_tmpl, fbx_obj, object_data, object_tdata_cache, settings):
     elem_name_utf8 = elem_name_ensure_class(fbx_obj)
 
     # Object data must be created already
@@ -561,7 +558,7 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices, fbx_tm
     return ebo
 
 
-def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, arm_parents, settings):
+def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, arm_parents, object_tdata_cache, settings):
     from mathutils import Matrix
 
     assert(settings.global_matrix is not None)
@@ -580,11 +577,11 @@ def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, ar
 
         if fbx_adata.props[2] in {b'LimbNode', b'Root'}:
             # rootbone-as-armature case...
-            fbx_bones_to_fake_object[fbx_adata.props[0]] = bl_adata = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, settings)
+            fbx_bones_to_fake_object[fbx_adata.props[0]] = bl_adata = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, object_tdata_cache, settings)
             # reset transform.
             bl_adata.matrix_basis = Matrix()
         else:
-            bl_adata = a_item[1] = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, settings)
+            bl_adata = a_item[1] = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, object_tdata_cache, settings)
 
         # Instantiate in scene.
         obj_base = scene.objects.link(bl_adata)
@@ -661,37 +658,32 @@ def blen_read_animations_curves_iter(fbx_curves, blen_start_offset, fbx_start_of
                     c]
                     for c in fbx_curves)
 
-    while True:
-        tmin = min(curves, key=lambda e: e[1][e[0]])
-        curr_fbxktime = tmin[1][tmin[0]]
+    allkeys = sorted({item for sublist in curves for item in sublist[1]})                    
+    for curr_fbxktime in allkeys:
         curr_values = []
-        do_break = True
         for item in curves:
             idx, times, values, fbx_curve = item
-            if idx != -1:
-                do_break = False
-            if times[idx] > curr_fbxktime:
-                if idx == 0:
-                    curr_values.append((values[idx], fbx_curve))
-                else:
-                    # Interpolate between this key and the previous one.
-                    ifac = (curr_fbxktime - times[idx - 1]) / (times[idx] - times[idx - 1])
-                    curr_values.append(((values[idx] - values[idx - 1]) * ifac + values[idx - 1], fbx_curve))
-            else:
-                curr_values.append((values[idx], fbx_curve))
+            
+            if times[idx] < curr_fbxktime:
                 if idx >= 0:
                     idx += 1
                     if idx >= len(times):
                         # We have reached our last element for this curve, stay on it from now on...
                         idx = -1
                     item[0] = idx
+            
+            if times[idx] >= curr_fbxktime:
+                if idx == 0:
+                    curr_values.append((values[idx], fbx_curve))
+                else:
+                    # Interpolate between this key and the previous one.
+                    ifac = (curr_fbxktime - times[idx - 1]) / (times[idx] - times[idx - 1])
+                    curr_values.append(((values[idx] - values[idx - 1]) * ifac + values[idx - 1], fbx_curve))
         curr_blenkframe = (curr_fbxktime - fbx_start_offset) * timefac + blen_start_offset
         yield (curr_blenkframe, curr_values)
-        if do_break:
-            break
 
 
-def blen_read_animations_action_item(action, item, cnodes, global_matrix, force_global, fps):
+def blen_read_animations_action_item(action, item, cnodes, global_matrix, force_global, fps, object_tdata_cache):
     """
     'Bake' loc/rot/scale into the action, taking into account global_matrix if no parent is present.
     """
@@ -707,7 +699,7 @@ def blen_read_animations_action_item(action, item, cnodes, global_matrix, force_
         props = [(item.path_from_id("value"), 1, "Key")]
     else:  # Object or PoseBone:
         if item not in object_tdata_cache:
-            print("ERROR! object '%s' has no transform data, while being animated!" % ob.name)
+            print("ERROR! object '%s' has no transform data, while being animated!" % item.name)
             return
 
         # We want to create actions for objects, but for bones we 'reuse' armatures' actions!
@@ -795,7 +787,7 @@ def blen_read_animations_action_item(action, item, cnodes, global_matrix, force_
         fc.update()
 
 
-def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global_matrix, force_global_objects):
+def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global_matrix, force_global_objects, object_tdata_cache):
     """
     Recreate an action per stack/layer/object combinations.
     Note actions are not linked to objects, this is up to the user!
@@ -814,7 +806,7 @@ def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global
                     actions[key] = action = bpy.data.actions.new(action_name)
                     action.use_fake_user = True
                 blen_read_animations_action_item(action, item, cnodes, global_matrix,
-                                                 item in force_global_objects, scene.render.fps)
+                                                 item in force_global_objects, scene.render.fps, object_tdata_cache)
 
 
 # ----
@@ -1472,6 +1464,7 @@ def load(operator, context, filepath="",
     basedir = os.path.dirname(filepath)
 
     cycles_material_wrap_map = {}
+    object_tdata_cache = {}
     image_cache = {}
     if not use_cycles:
         texture_cache = {}
@@ -1744,7 +1737,8 @@ def load(operator, context, filepath="",
                         if fbx_tdata is None or fbx_tdata.id != b'NodeAttribute' or fbx_tdata.props[2] != b'LimbNode':
                             continue
                         fbx_props = (elem_find_first(fbx_tdata, b'Properties70'),)
-                        size = elem_props_get_number(fbx_props, b'Size', default=size)
+                        if fbx_props != (None,):
+                            size = elem_props_get_number(fbx_props, b'Size', default=size)
                         break  # Only one bone data per bone!
 
                     clusters = []
@@ -1834,7 +1828,7 @@ def load(operator, context, filepath="",
                     break
             if ok:
                 # create when linking since we need object data
-                obj = blen_read_object(fbx_tmpl, fbx_obj, fbx_lnk_item, settings)
+                obj = blen_read_object(fbx_tmpl, fbx_obj, fbx_lnk_item, object_tdata_cache, settings)
                 assert(fbx_item[1] is None)
                 fbx_item[1] = obj
 
@@ -1902,7 +1896,7 @@ def load(operator, context, filepath="",
     def _():
         fbx_tmpl = fbx_template_get((b'Model', b'KFbxNode'))
 
-        blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, arm_parents, settings)
+        blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, arm_parents, object_tdata_cache, settings)
     _(); del _
 
     def _():
@@ -2049,7 +2043,7 @@ def load(operator, context, filepath="",
                 curvenodes[acn_uuid][ac_uuid] = (fbx_acitem, channel)
 
         # And now that we have sorted all this, apply animations!
-        blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global_matrix, force_global_objects)
+        blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global_matrix, force_global_objects, object_tdata_cache)
 
     _(); del _
 
@@ -2209,7 +2203,7 @@ def load(operator, context, filepath="",
                         else:
                             print("WARNING: material link %r ignored" % lnk_type)
 
-                        material_images.setdefault(material, {})[lnk_type] = image
+                        material_images.setdefault(material, {})[lnk_type] = (image, tex_map)
                 else:
                     if fbx_lnk_type.props[0] == b'OP':
                         lnk_type = fbx_lnk_type.props[3]
@@ -2251,7 +2245,7 @@ def load(operator, context, filepath="",
                         else:
                             print("WARNING: material link %r ignored" % lnk_type)
 
-                        material_images.setdefault(material, {})[lnk_type] = image
+                        material_images.setdefault(material, {})[lnk_type] = (image, tex_map)
 
         # Check if the diffuse image has an alpha channel,
         # if so, use the alpha channel.
@@ -2262,7 +2256,7 @@ def load(operator, context, filepath="",
             if fbx_obj.id != b'Material':
                 continue
             material = fbx_table_nodes[fbx_uuid][1]
-   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list