FBX IO: Speed up animation export using NumPy #104884

Merged
Thomas Barlow merged 12 commits from Mysteryem/blender-addons:fbx_anim_export_numpy_intermediate into main 2023-09-19 01:13:25 +02:00
Showing only changes of commit 7c7ab21973 - Show all commits

View File

@ -2265,6 +2265,13 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
# Iterate through each frame and yield the values for that frame. # Iterate through each frame and yield the values for that frame.
int_currframes = currframes.astype(int) int_currframes = currframes.astype(int)
subframes = currframes - int_currframes subframes = currframes - int_currframes
# Create simpler iterables that return only the values we care about.
animdata_shapes_only = [shape for _anim_shape, _me, shape in animdata_shapes.values()]
animdata_cameras_only = [camera for _anim_camera_lens, _anim_camera_focus_distance, camera
in animdata_cameras.values()]
# Previous frame's rotation for each object in animdata_ob, this will be updated each frame.
animdata_ob_p_rots = p_rots.values()
# Iterating .data, the memoryview of an array, is faster than iterating the array directly.
for real_currframe, int_currframe, subframe in zip(real_currframes.data, int_currframes.data, subframes.data): for real_currframe, int_currframe, subframe in zip(real_currframes.data, int_currframes.data, subframes.data):
scene.frame_set(int_currframe, subframe=subframe) scene.frame_set(int_currframe, subframe=subframe)
@ -2276,17 +2283,18 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
# ObjectWrapper caches its instances. Attempting to create a new instance updates the existing # ObjectWrapper caches its instances. Attempting to create a new instance updates the existing
# ObjectWrapper instance with the current frame's matrix and then returns the existing instance. # ObjectWrapper instance with the current frame's matrix and then returns the existing instance.
ObjectWrapper(dup) ObjectWrapper(dup)
for ob_obj in animdata_ob: next_p_rots = []
for ob_obj, p_rot in zip(animdata_ob, animdata_ob_p_rots):
# We compute baked loc/rot/scale for all objects (rot being euler-compat with previous value!). # We compute baked loc/rot/scale for all objects (rot being euler-compat with previous value!).
p_rot = p_rots.get(ob_obj, None)
loc, rot, scale, _m, _mr = ob_obj.fbx_object_tx(scene_data, rot_euler_compat=p_rot) loc, rot, scale, _m, _mr = ob_obj.fbx_object_tx(scene_data, rot_euler_compat=p_rot)
p_rots[ob_obj] = rot next_p_rots.append(rot)
yield from loc yield from loc
yield from rot yield from rot
yield from scale yield from scale
for anim_shape, me, shape in animdata_shapes.values(): animdata_ob_p_rots = next_p_rots
for shape in animdata_shapes_only:
yield shape.value yield shape.value
for anim_camera_lens, anim_camera_focus_distance, camera in animdata_cameras.values(): for camera in animdata_cameras_only:
yield camera.lens yield camera.lens
yield camera.dof.focus_distance yield camera.dof.focus_distance