[Bf-extensions-cvs] [a3080e0] fbx_io_development: Optimizations (avoid some dict lookups), and fix another bug from rootbones-as-armatures work.
Bastien Montagne
noreply at git.blender.org
Sun Jul 6 19:16:02 CEST 2014
Commit: a3080e09f9aee7a4648e72522de5b6b4ab3b070f
Author: Bastien Montagne
Date: Sun Jul 6 17:50:50 2014 +0200
https://developer.blender.org/rBAa3080e09f9aee7a4648e72522de5b6b4ab3b070f
Optimizations (avoid some dict lookups), and fix another bug from rootbones-as-armatures work.
===================================================================
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 c79e588..0f94273 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1069,9 +1069,8 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
del _uvtuples_gen
# Face's materials.
- me_fbxmats_idx = None
- if me in scene_data.mesh_mat_indices:
- me_fbxmats_idx = scene_data.mesh_mat_indices[me]
+ me_fbxmats_idx = scene_data.mesh_mat_indices.get(me)
+ if me_fbxmats_idx is not None:
me_blmats = me.materials
if me_fbxmats_idx and me_blmats:
lay_mat = elem_data_single_int32(geom, b"LayerElementMaterial", 0)
@@ -1762,9 +1761,10 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
anim.simplfy(simplify_fac, bake_step)
if anim:
for obj_key, group_key, group, fbx_group, fbx_gname in anim.get_final_data(scene, ref_id, force_keep):
- if obj_key not in animations:
- animations[obj_key] = ("dummy_unused_key", OrderedDict())
- animations[obj_key][1][fbx_group] = (group_key, group, fbx_gname)
+ anim_data = animations.get(obj_key)
+ if anim_data is None:
+ anim_data = animations[obj_key] = ("dummy_unused_key", OrderedDict())
+ anim_data[1][fbx_group] = (group_key, group, fbx_gname)
# And meshes' shape keys.
for channel_key, (anim_shape, me, shape) in animdata_shapes.items():
@@ -1772,9 +1772,10 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
anim_shape.simplfy(simplify_fac, bake_step)
if anim_shape:
for elem_key, group_key, group, fbx_group, fbx_gname in anim_shape.get_final_data(scene, ref_id, force_keep):
- if elem_key not in animations:
- animations[elem_key] = ("dummy_unused_key", OrderedDict())
- animations[elem_key][1][fbx_group] = (group_key, group, fbx_gname)
+ anim_data = animations.get(elem_key)
+ if anim_data is None:
+ anim_data = animations[elem_key] = ("dummy_unused_key", OrderedDict())
+ anim_data[1][fbx_group] = (group_key, group, fbx_gname)
astack_key = get_blender_anim_stack_key(scene, ref_id)
alayer_key = get_blender_anim_layer_key(scene, ref_id)
@@ -2030,8 +2031,9 @@ def fbx_data_from_scene(scene, settings):
# We support any kind of 'surface' shader though, better to have some kind of default Lambert than nothing.
# TODO: Support nodes (*BIG* todo!).
if mat.type in {'SURFACE'} and not mat.use_nodes:
- if mat in data_materials:
- data_materials[mat][1].append(ob_obj)
+ mat_data = data_materials.get(mat)
+ if mat_data is not None:
+ mat_data[1].append(ob_obj)
else:
data_materials[mat] = (get_blenderID_key(mat), [ob_obj])
@@ -2059,12 +2061,14 @@ def fbx_data_from_scene(scene, settings):
tex_fbx_props = fbx_mat_properties_from_texture(tex)
if not tex_fbx_props:
continue
- if tex in data_textures:
- data_textures[tex][1][mat] = tex_fbx_props
+ tex_data = data_textures.get(tex)
+ if tex_data is not None:
+ tex_data[1][mat] = tex_fbx_props
else:
data_textures[tex] = (get_blenderID_key(tex), OrderedDict(((mat, tex_fbx_props),)))
- if img in data_videos:
- data_videos[img][1].append(tex)
+ vid_data = data_videos.get(img)
+ if vid_data is not None:
+ vid_data[1].append(tex)
else:
data_videos[img] = (get_blenderID_key(img), [tex])
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py
index cf1349e..4a16fa5 100644
--- a/io_scene_fbx/fbx_utils.py
+++ b/io_scene_fbx/fbx_utils.py
@@ -520,13 +520,13 @@ def elem_props_template_init(templates, template_type):
"""
Init a writing template of given type, for *one* element's properties.
"""
- ret = None
- if template_type in templates:
- tmpl = templates[template_type]
+ ret = OrderedDict()
+ tmpl = templates.get(template_type)
+ if tmpl is not None:
written = tmpl.written[0]
props = tmpl.properties
ret = OrderedDict((name, [val, ptype, anim, written]) for name, (val, ptype, anim) in props.items())
- return ret or OrderedDict()
+ return ret
def elem_props_template_set(template, elem, ptype_name, name, value, animatable=False):
@@ -578,11 +578,12 @@ def fbx_templates_generate(root, fbx_templates):
templates = OrderedDict()
for type_name, prop_type_name, properties, nbr_users, _written in fbx_templates.values():
- if type_name not in templates:
+ tmpl = templates.get(type_name)
+ if tmpl is None:
templates[type_name] = [OrderedDict(((prop_type_name, (properties, nbr_users)),)), nbr_users]
else:
- templates[type_name][0][prop_type_name] = (properties, nbr_users)
- templates[type_name][1] += nbr_users
+ tmpl[0][prop_type_name] = (properties, nbr_users)
+ tmpl[1] += nbr_users
for type_name, (subprops, nbr_users) in templates.items():
template = elem_data_single_string(root, b"ObjectType", type_name)
@@ -773,8 +774,8 @@ class MetaObjectWrapper(type):
cache = getattr(cls, "_cache", None)
if cache is None:
cache = cls._cache = {}
- if key in cache:
- instance = cache[key]
+ instance = cache.get(key)
+ if instance is not None:
# Duplis hack: since duplis are not persistent in Blender (we have to re-create them to get updated
# info like matrix...), we *always* need to reset that matrix when calling ObjectWrapper() (all
# other data is supposed valid during whole cache live, so we can skip resetting it).
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 7d8a8bd..4e574ec 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -311,10 +311,9 @@ def add_vgroup_to_objects(vg_indices, vg_weights, vg_name, objects):
if vg_indices:
for obj in objects:
# We replace/override here...
- if vg_name not in obj.vertex_groups:
+ vg = obj.vertex_groups.get(vg_name)
+ if vg is None:
vg = obj.vertex_groups.new(vg_name)
- else:
- vg = obj.vertex_groups[vg_name]
for i, w in zip(vg_indices, vg_weights):
vg.add((i,), w, 'REPLACE')
@@ -388,11 +387,10 @@ def blen_read_object(fbx_tmpl, fbx_obj, object_data):
else:
rot_alt_mat = Matrix()
- if obj not in object_tdata_cache:
+ transform_data = object_tdata_cache.get(obj)
+ if transform_data is None:
transform_data = blen_read_object_transform_preprocess(fbx_props, fbx_obj, rot_alt_mat)
object_tdata_cache[obj] = transform_data
- else:
- transform_data = object_tdata_cache[obj]
obj.matrix_basis = blen_read_object_transform_do(transform_data)
return obj
@@ -556,11 +554,10 @@ def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, gl
assert(fbx_props[0] is not None)
pbo = b_item[1] = bl_adata.pose.bones[bl_bname]
- if pbo not in object_tdata_cache:
+ transform_data = object_tdata_cache.get(pbo)
+ if transform_data is None:
transform_data = blen_read_object_transform_preprocess(fbx_props, fbx_bdata, Matrix())
object_tdata_cache[pbo] = transform_data
- else:
- transform_data = object_tdata_cache[pbo]
mat = blen_read_object_transform_do(transform_data)
if pbo.parent:
# Bring back matrix in armature space.
@@ -706,9 +703,8 @@ def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global
# We want to create actions for objects, but for bones we 'reuse' armatures' actions!
id_data = ob.id_data
key = (as_uuid, al_uuid, id_data)
- if key in actions:
- action = actions[key]
- else:
+ action = actions.get(key)
+ if action is None:
action_name = "|".join((id_data.name, stack_name, layer_name))
actions[key] = action = bpy.data.actions.new(action_name)
action.use_fake_user = True
@@ -1787,9 +1783,10 @@ def load(operator, context, filepath="",
if fbx_obj.id != b'Model':
continue
# Handle rootbone-as-armature case :/
- if fbx_uuid in fbx_bones_to_fake_object:
- blen_data = fbx_bones_to_fake_object[fbx_uuid]
- if blen_data is None:
+ t_data = fbx_bones_to_fake_object.get(fbx_uuid)
+ if t_data is not None:
+ blen_data = t_data
+ elif blen_data is None:
continue # no object loaded.. ignore
for (fbx_lnk,
@@ -1810,13 +1807,14 @@ def load(operator, context, filepath="",
if fbx_obj.id != b'Model':
continue
# Handle rootbone-as-armature case :/
- if fbx_uuid in fbx_bones_to_fake_object:
- blen_data = fbx_bones_to_fake_object[fbx_uuid]
- if blen_data is None:
+ t_data = fbx_bones_to_fake_object.get(fbx_uuid)
+ if t_data is not None:
+ blen_data = t_data
+ elif blen_data is None:
continue # no object loaded.. ignore
- if fbx_item[1].parent is None:
- fbx_item[1].matrix_basis = global_matrix * fbx_item[1].matrix_basis
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list