[Bf-extensions-cvs] [ceb2fde] fbx_io_development: FBX import: Add a first, very basic AnimCurve 'baker'.
Bastien Montagne
noreply at git.blender.org
Fri May 23 17:49:38 CEST 2014
Commit: ceb2fde0778ca1588e5596aa69b23c0468d96eae
Author: Bastien Montagne
Date: Tue May 20 22:43:34 2014 +0200
https://developer.blender.org/rBAceb2fde0778ca1588e5596aa69b23c0468d96eae
FBX import: Add a first, very basic AnimCurve 'baker'.
===================================================================
M io_scene_fbx/import_fbx.py
===================================================================
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 20a085b..ea01567 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -517,17 +517,61 @@ def blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix):
# ---------
# Animation
+def blen_read_animations_curve_baker(fbx_acdata, blen_start_offset, fbx_start_offset, fps):
+ """
+ Get raw FBX AnimCurve data and output a baked array of "baked" float values (one per frame).
+ blen_start_offset is expected in frames, while fbx_start_offset is expected in FBX ktime.
+ """
+ # As a first step, assume linear interpolation between key frames, we'll (try to!) handle more
+ # of FBX curves later.
+ from .fbx_utils import FBX_KTIME
+ timefac = fps / FBX_KTIME
+
+ fbx_ktime = elem_prop_first(elem_find_first(fbx_acdata, b'KeyTime'))
+ fbx_kval = elem_prop_first(elem_find_first(fbx_acdata, b'KeyValueFloat'))
+ assert(len(fbx_ktime) == len(fbx_kval))
+
+ keyframes = []
+
+ curr_blenframe = 0.0
+ curr_fbxkey = 0
+ max_fbxkey = len(fbx_ktime) - 1
+ while 1:
+ curr_fbxktime = curr_blenframe / timefac
+ curr_fbxkey_ktime = fbx_ktime[curr_fbxkey] - fbx_start_offset
+ curr_fbxkey_val = fbx_kval[curr_fbxkey]
+ if curr_fbxktime >= curr_fbxkey_ktime:
+ # Add exact fbx key and increment current fbx key index.
+ keyframes.append((curr_fbxkey_ktime * timefac + blen_start_offset, curr_fbxkey_val))
+ curr_fbxkey += 1
+ if curr_fbxkey > max_fbxkey:
+ break # We are done!
+ elif curr_fbxkey != 0:
+ prev_fbxkey_ktime = fbx_ktime[curr_fbxkey - 1] - fbx_start_offset
+ prev_fbxkey_val = fbx_kval[curr_fbxkey - 1] # Not an issue in case curr_fbxkey = 0, we won't use it!
+ ifac = (curr_fbxktime - prev_fbxkey_ktime) / (curr_fbxkey_ktime - prev_fbxkey_ktime)
+ ival = (curr_fbxkey_val - prev_fbxkey_val) * ifac + prev_fbxkey_val
+ keyframes.append((curr_blenframe + blen_start_offset, ival))
+ # Only increment curr_blenframe if current fbx key is ahead of it in time.
+ if curr_fbxktime <= curr_fbxkey_ktime:
+ curr_blenframe += 1.0
+
+ return keyframes
+
+
def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene, global_matrix):
- for as_uuid, (fbx_asdata, alayers) in stacks.items():
+ for as_uuid, (fbx_asitem, alayers) in stacks.items():
print("Stack {}:".format(as_uuid))
- for al_uuid, (fbx_aldata, objects) in alayers.items():
+ for al_uuid, (fbx_alitem, 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))
+ for ac_uuid, (fbx_acitem, channel) in curves.items():
+ print(" " * 16 + "Channel {} (Curve {}): {}"
+ "".format(channel, ac_uuid,
+ blen_read_animations_curve_baker(fbx_acitem[0], 0.0, 0.0, scene.render.fps)))
# ----
More information about the Bf-extensions-cvs
mailing list