[Bf-extensions-cvs] [b8fbe7f] fbx_io_development: More cleanup, a few minor changes here and there...

Bastien Montagne noreply at git.blender.org
Thu Jul 31 21:27:32 CEST 2014


Commit: b8fbe7f6a5af48ddbb6e8b1ce0578c5f451ca49d
Author: Bastien Montagne
Date:   Thu Jul 31 20:53:26 2014 +0200
Branches: fbx_io_development
https://developer.blender.org/rBAb8fbe7f6a5af48ddbb6e8b1ce0578c5f451ca49d

More cleanup, a few minor changes here and there...

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

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/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index 303b0af..8d606dd 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -530,11 +530,8 @@ def fbx_data_element_custom_properties(props, bid):
     Store custom properties of blender ID bid (any mapping-like object, in fact) into FBX properties props.
     """
     for k, v in bid.items():
-        to_list = getattr(v, "to_list", None)
-        list_val = None
-        if to_list:
-            list_val = to_list()
-    
+        list_val = getattr(v, "to_list", lambda: None)()
+
         if isinstance(v, str):
             elem_props_set(props, "p_string", k.encode(), v, custom=True)
         elif isinstance(v, int):
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py
index a889796..fd740ca 100644
--- a/io_scene_fbx/fbx_utils.py
+++ b/io_scene_fbx/fbx_utils.py
@@ -1094,5 +1094,6 @@ FBXImportSettings = namedtuple("FBXImportSettings", (
     "report", "to_axes", "global_matrix", "global_scale",
     "use_cycles", "use_image_search", 
     "use_alpha_decals", "decal_offset", 
-    "use_custom_props", "use_custom_props_enum_as_string"
+    "use_custom_props", "use_custom_props_enum_as_string",
+    "object_tdata_cache", "cycles_material_wrap_map", "image_cache",
 ))
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 2663d97..d6d8232 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -418,11 +418,12 @@ 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, object_tdata_cache, settings):
+def blen_read_object(fbx_tmpl, fbx_obj, object_data, settings):
     elem_name_utf8 = elem_name_ensure_class(fbx_obj)
 
     # Object data must be created already
     obj = bpy.data.objects.new(name=elem_name_utf8, object_data=object_data)
+    object_tdata_cache = settings.object_tdata_cache
 
     fbx_props = (elem_find_first(fbx_obj, b'Properties70'),
                  elem_find_first(fbx_tmpl, b'Properties70', fbx_elem_nil))
@@ -558,10 +559,12 @@ 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, object_tdata_cache, settings):
+def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, arm_parents, settings):
     from mathutils import Matrix
 
-    assert(settings.global_matrix is not None)
+    global_matrix = settings.global_matrix
+    assert(global_matrix is not None)
+    object_tdata_cache = settings.object_tdata_cache
 
     for a_item, bones in armatures:
         fbx_adata, bl_adata = a_item
@@ -577,11 +580,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, object_tdata_cache, settings)
+            fbx_bones_to_fake_object[fbx_adata.props[0]] = bl_adata = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, settings)
             # reset transform.
             bl_adata.matrix_basis = Matrix()
         else:
-            bl_adata = a_item[1] = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, object_tdata_cache, settings)
+            bl_adata = a_item[1] = blen_read_object(fbx_tmpl, fbx_adata, bl_arm, settings)
 
         # Instantiate in scene.
         obj_base = scene.objects.link(bl_adata)
@@ -603,8 +606,8 @@ def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, ar
         arm_mat_back = bl_adata.matrix_basis.copy()
         for ob_me, (amat, mmat) in matrices.items():
             # bring global armature & mesh matrices into *Blender* global space.
-            amat = settings.global_matrix * amat
-            mmat = settings.global_matrix * mmat
+            amat = global_matrix * amat
+            mmat = global_matrix * mmat
 
             bl_adata.matrix_basis = amat
             me_mat_back = ob_me.matrix_basis.copy()
@@ -658,7 +661,7 @@ def blen_read_animations_curves_iter(fbx_curves, blen_start_offset, fbx_start_of
                     c]
                     for c in fbx_curves)
 
-    allkeys = sorted({item for sublist in curves for item in sublist[1]})                    
+    allkeys = sorted({item for sublist in curves for item in sublist[1]})
     for curr_fbxktime in allkeys:
         curr_values = []
         for item in curves:
@@ -683,7 +686,7 @@ def blen_read_animations_curves_iter(fbx_curves, blen_start_offset, fbx_start_of
         yield (curr_blenkframe, curr_values)
 
 
-def blen_read_animations_action_item(action, item, cnodes, global_matrix, force_global, fps, object_tdata_cache):
+def blen_read_animations_action_item(action, item, cnodes, force_global, fps, settings):
     """
     'Bake' loc/rot/scale into the action, taking into account global_matrix if no parent is present.
     """
@@ -691,6 +694,8 @@ def blen_read_animations_action_item(action, item, cnodes, global_matrix, force_
     from mathutils import Euler, Matrix
     from itertools import chain
 
+    global_matrix = settings.global_matrix
+    object_tdata_cache = settings.object_tdata_cache
     blen_curves = []
     fbx_curves = []
     props = []
@@ -787,7 +792,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, object_tdata_cache):
+def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, force_global_objects, settings):
     """
     Recreate an action per stack/layer/object combinations.
     Note actions are not linked to objects, this is up to the user!
@@ -805,8 +810,8 @@ def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global
                     action_name = "|".join((id_data.name, stack_name, layer_name))
                     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, object_tdata_cache)
+                blen_read_animations_action_item(action, item, cnodes,
+                                                 item in force_global_objects, scene.render.fps, settings)
 
 
 # ----
@@ -1196,7 +1201,7 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
     return mesh
 
 
-def blen_read_shape(fbx_tmpl, fbx_sdata, fbx_bcdata, meshes, scene, global_matrix):
+def blen_read_shape(fbx_tmpl, fbx_sdata, fbx_bcdata, meshes, scene, settings):
     from mathutils import Vector
 
     elem_name_utf8 = elem_name_ensure_class(fbx_sdata, b'Geometry')
@@ -1244,9 +1249,10 @@ def blen_read_shape(fbx_tmpl, fbx_sdata, fbx_bcdata, meshes, scene, global_matri
 # --------
 # Material
 
-def blen_read_material(fbx_tmpl, fbx_obj, cycles_material_wrap_map, settings):
+def blen_read_material(fbx_tmpl, fbx_obj, settings):
     elem_name_utf8 = elem_name_ensure_class(fbx_obj, b'Material')
 
+    cycles_material_wrap_map = settings.cycles_material_wrap_map
     ma = bpy.data.materials.new(name=elem_name_utf8)
 
     const_color_white = 1.0, 1.0, 1.0
@@ -1299,13 +1305,14 @@ def blen_read_material(fbx_tmpl, fbx_obj, cycles_material_wrap_map, settings):
 # -------
 # Texture
 
-def blen_read_texture(fbx_tmpl, fbx_obj, basedir, image_cache,
-                      settings):
+def blen_read_texture(fbx_tmpl, fbx_obj, basedir, settings):
     import os
     from bpy_extras import image_utils
 
     elem_name_utf8 = elem_name_ensure_class(fbx_obj, b'Texture')
 
+    image_cache = settings.image_cache
+
     filepath = elem_find_first_string(fbx_obj, b'FileName')
     if os.sep == '/':
         filepath = filepath.replace('\\', '/')
@@ -1463,8 +1470,8 @@ def load(operator, context, filepath="",
 
     basedir = os.path.dirname(filepath)
 
-    cycles_material_wrap_map = {}
     object_tdata_cache = {}
+    cycles_material_wrap_map = {}
     image_cache = {}
     if not use_cycles:
         texture_cache = {}
@@ -1518,7 +1525,8 @@ def load(operator, context, filepath="",
         use_cycles, use_image_search, 
         use_alpha_decals, decal_offset,
         use_custom_props, use_custom_props_enum_as_string,
-        )
+        object_tdata_cache, cycles_material_wrap_map, image_cache,
+    )
 
     #### And now, the "real" data.
 
@@ -1614,8 +1622,7 @@ def load(operator, context, filepath="",
             if fbx_obj.id != b'Material':
                 continue
             assert(blen_data is None)
-            fbx_item[1] = blen_read_material(fbx_tmpl, fbx_obj,
-                                             cycles_material_wrap_map, settings)
+            fbx_item[1] = blen_read_material(fbx_tmpl, fbx_obj, settings)
     _(); del _
 
     # ----
@@ -1627,8 +1634,7 @@ def load(operator, context, filepath="",
             fbx_obj, blen_data = fbx_item
             if fbx_obj.id != b'Texture':
                 continue
-            fbx_item[1] = blen_read_texture(fbx_tmpl, fbx_obj, basedir, image_cache,
-                                            settings)
+            fbx_item[1] = blen_read_texture(fbx_tmpl, fbx_obj, basedir, settings)
     _(); del _
 
     # ----
@@ -1737,7 +1743,7 @@ 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'),)
-                        if fbx_props != (None,):
+                        if fbx_props[0] is not None:  # Some bones have no Properties70 at all...
                             size = elem_props_get_number(fbx_props, b'Size', default=size)
                         break  # Only one bone data per bone!
 
@@ -1828,7 +1834,7 @@ def load(operator, conte

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list