[Bf-extensions-cvs] [921a936] fbx_io_development: FBX import: cleanup of Anim Step I (still nothing visible on userlevel).
Bastien Montagne
noreply at git.blender.org
Fri May 23 17:49:38 CEST 2014
Commit: 921a9360bb40438abb359d32a04a018a964228b2
Author: Bastien Montagne
Date: Tue May 20 21:21:12 2014 +0200
https://developer.blender.org/rBA921a9360bb40438abb359d32a04a018a964228b2
FBX import: cleanup of Anim Step I (still nothing visible on userlevel).
===================================================================
M io_scene_fbx/import_fbx.py
===================================================================
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 850b224..20a085b 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -257,21 +257,6 @@ def elem_props_get_enum(elem, elem_prop_id, default=None):
return default
-"""
-def elem_props_get_compound(elem, elem_prop_id, default=None, getter=elem_props_find_first):
- elem_prop = getter(elem, elem_prop_id)
- if elem_prop is not None:
- assert(elem_prop.props[0] == elem_prop_id)
- assert(elem_prop.props[1] == b'Compound')
- assert(elem_prop.props[2] == b'')
- assert(elem_prop.props[3] == b'')
-
- root = elem_prop_id + b'|'
- def getter(elem, elem_prop_id):
- return elem_props_find_first(elem, root + elem_prop_id)
- return getter
- return default
-"""
# ----------------------------------------------------------------------------
# Blender
@@ -530,6 +515,21 @@ def blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix):
pbo.matrix = mat
+# ---------
+# Animation
+def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global_matrix):
+ for as_uuid, (fbx_asdata, alayers) in stacks.items():
+ print("Stack {}:".format(as_uuid))
+ for al_uuid, (fbx_aldata, objects) in alayers.items():
+ print(" " * 4 + "Layer {} ({} objects):".format(al_uuid, len(objects)))
+ for ob, cnodes in objects.items():
+ print(" " * 8 + "Action for object {}: {} animated properties:".format(ob.name, len(cnodes)))
+ for acn_uuid, (curves, obprop) in cnodes.items():
+ print(" " * 12 + "Prop {} (CurveNode {}) has {} curves:".format(obprop, acn_uuid, len(curves)))
+ for ac_uuid, (fbx_acdata, channel) in curves.items():
+ print(" " * 16 + "Channel {} (Curve {}): {}".format(channel, ac_uuid, fbx_acdata))
+
+
# ----
# Mesh
@@ -1468,48 +1468,82 @@ def load(operator, context, filepath="",
blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix)
_(); del _
+ def _():
+ # Parent objects, after we created them...
+ for fbx_uuid, fbx_item in fbx_table_nodes.items():
+ if fbx_uuid in fbx_objects_parent_ignore:
+ # Ignore bones, but not armatures here!
+ continue
+ fbx_obj, blen_data = fbx_item
+ if fbx_obj.id != b'Model':
+ continue
+ if fbx_item[1] is None:
+ continue # no object loaded.. ignore
+
+ for (fbx_lnk,
+ fbx_lnk_item,
+ fbx_lnk_type) in connection_filter_forward(fbx_uuid, b'Model'):
+
+ fbx_item[1].parent = fbx_lnk_item
+ _(); del _
+
+ def _():
+ if global_matrix is not None:
+ # Apply global matrix last (after parenting)
+ for fbx_uuid, fbx_item in fbx_table_nodes.items():
+ if fbx_uuid in fbx_objects_parent_ignore:
+ # Ignore bones, but not armatures here!
+ continue
+ fbx_obj, blen_data = fbx_item
+ if fbx_obj.id != b'Model':
+ continue
+ if fbx_item[1] 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
+ _(); del _
+
# Animation!
def _():
+ fbx_tmpl_astack = fbx_template_get((b'AnimationStack', b'FbxAnimStack'))
+ fbx_tmpl_alayer = fbx_template_get((b'AnimationLayer', b'FbxAnimLayer'))
stacks = {}
- animlayers_ignored = set()
# AnimationStacks.
- for fbx_uuid, fbx_item in fbx_table_nodes.items():
- fbx_asdata, blen_data = fbx_item
+ for as_uuid, fbx_asitem in fbx_table_nodes.items():
+ fbx_asdata, _blen_data = fbx_asitem
if fbx_asdata.id != b'AnimationStack' or fbx_asdata.props[2] != b'':
continue
- stacks[fbx_uuid] = (fbx_asdata, set(), {})
+ stacks[as_uuid] = (fbx_asitem, {})
- # AnimationLayers (only one per stack currently).
+ # AnimationLayers (mixing is completely ignored for now, each layer results in an independent set of actions).
def get_astacks_from_alayer(al_uuid):
for as_uuid, as_ctype in fbx_connection_map.get(al_uuid, ()):
if as_ctype.props[0] != b'OO':
continue
fbx_asdata, _bl_asdata = fbx_table_nodes.get(as_uuid, (None, None))
- if (fbx_asdata is None or fbx_asdata.id != b'AnimationStack' or fbx_asdata.props[2] != b'' or
- as_uuid not in stacks or (as_uuid, al_uuid) in animlayers_ignored):
+ if (fbx_asdata is None or fbx_asdata.id != b'AnimationStack' or
+ fbx_asdata.props[2] != b'' or as_uuid not in stacks):
continue
yield as_uuid
- for fbx_uuid, fbx_item in fbx_table_nodes.items():
- fbx_aldata, _blen_data = fbx_item
+ for al_uuid, fbx_alitem in fbx_table_nodes.items():
+ fbx_aldata, _blen_data = fbx_alitem
if fbx_aldata.id != b'AnimationLayer' or fbx_aldata.props[2] != b'':
continue
- for as_uuid in get_astacks_from_alayer(fbx_uuid):
- _fbx_asdata, alayers, _acnodes = stacks[as_uuid]
- alayers.add(fbx_uuid)
- if len(alayers) > 1:
- # For now, we only support one animlayer per animstack!
- animlayers_ignored.add((as_uuid, fbx_uuid))
+ for as_uuid in get_astacks_from_alayer(al_uuid):
+ _fbx_asitem, alayers = stacks[as_uuid]
+ alayers[al_uuid] = (fbx_alitem, {})
# AnimationCurveNodes (also the ones linked to actual animated data!).
curvenodes = {}
- for fbx_uuid, fbx_item in fbx_table_nodes.items():
- fbx_acndata, _blen_data = fbx_item
+ for acn_uuid, fbx_acnitem in fbx_table_nodes.items():
+ fbx_acndata, _blen_data = fbx_acnitem
if fbx_acndata.id != b'AnimationCurveNode' or fbx_acndata.props[2] != b'':
continue
- cnode = curvenodes[fbx_uuid] = {}
+ cnode = curvenodes[acn_uuid] = {}
objs = []
- for ob_uuid, ob_ctype in fbx_connection_map.get(fbx_uuid, ()):
+ for ob_uuid, ob_ctype in fbx_connection_map.get(acn_uuid, ()):
if ob_ctype.props[0] != b'OP':
continue
lnk_prop = {
@@ -1519,21 +1553,26 @@ def load(operator, context, filepath="",
}.get(ob_ctype.props[3], None)
if lnk_prop is None:
continue
- objs.append((ob_uuid, lnk_prop))
+ ob = fbx_table_nodes[ob_uuid][1]
+ if ob is None:
+ continue
+ objs.append((ob, lnk_prop))
for al_uuid, al_ctype in fbx_connection_map.get(acn_uuid, ()):
if al_ctype.props[0] != b'OO':
continue
- fbx_aldata, _bl_aldata = fbx_table_nodes.get(al_uuid, (None, None))
+ fbx_aldata, _blen_aldata = fbx_alitem = fbx_table_nodes.get(al_uuid, (None, None))
if fbx_aldata is None or fbx_aldata.id != b'AnimationLayer' or fbx_aldata.props[2] != b'':
continue
for as_uuid in get_astacks_from_alayer(al_uuid):
- _fbx_asdata, _alayers, objects = stacks[as_uuid]
- for ob_uuid, ob_prop in objs:
- objects.setdefault(ob_uuid, {})[fbx_uuid] = (cnode, ob_prop)
+ _fbx_alitem, objects = stacks[as_uuid][1][al_uuid]
+ assert(_fbx_alitem == fbx_alitem)
+ for ob, ob_prop in objs:
+ # No need to keep curvenode FBX data here, contains nothing useful for us.
+ objects.setdefault(ob, {})[acn_uuid] = (cnode, ob_prop)
# AnimationCurves (real animation data).
- for fbx_uuid, fbx_item in fbx_table_nodes.items():
- fbx_acdata, _blen_data = fbx_item
+ for ac_uuid, fbx_acitem in fbx_table_nodes.items():
+ fbx_acdata, _blen_data = fbx_acitem
if fbx_acdata.id != b'AnimationCurve' or fbx_acdata.props[2] != b'':
continue
for acn_uuid, acn_ctype in fbx_connection_map.get(ac_uuid, ()):
@@ -1546,46 +1585,13 @@ def load(operator, context, filepath="",
# Note this is an infamous simplification of the compound props stuff,
# seems to be standard naming but we'll probably have to be smarter to handle more exotic files?
channel = {b'd|X': 'x', b'd|Y': 'y', b'd|Z': 'z'}.get(acn_ctype.props[3], None)
- curvenodes[acn_uuid][channel] = fbx_acdata
-
- print(stacks)
-
- _(); del _
-
- def _():
- # Parent objects, after we created them...
- for fbx_uuid, fbx_item in fbx_table_nodes.items():
- if fbx_uuid in fbx_objects_parent_ignore:
- # Ignore bones, but not armatures here!
- continue
- fbx_obj, blen_data = fbx_item
- if fbx_obj.id != b'Model':
- continue
- if fbx_item[1] is None:
- continue # no object loaded.. ignore
-
- for (fbx_lnk,
- fbx_lnk_item,
- fbx_lnk_type) in connection_filter_forward(fbx_uuid, b'Model'):
-
- fbx_item[1].parent = fbx_lnk_item
- _(); del _
-
- def _():
- if global_matrix is not None:
- # Apply global matrix last (after parenting)
- for fbx_uuid, fbx_item in fbx_table_nodes.items():
- if fbx_uuid in fbx_objects_parent_ignore:
- # Ignore bones, but not armatures here!
- continue
- fbx_obj, blen_data = fbx_item
- i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list