FBX IO: Speed up animation simplification using NumPy #104904
@ -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.
|
||||
int_currframes = currframes.astype(int)
|
||||
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):
|
||||
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 instance with the current frame's matrix and then returns the existing instance.
|
||||
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!).
|
||||
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)
|
||||
p_rots[ob_obj] = rot
|
||||
next_p_rots.append(rot)
|
||||
yield from loc
|
||||
yield from rot
|
||||
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
|
||||
for anim_camera_lens, anim_camera_focus_distance, camera in animdata_cameras.values():
|
||||
for camera in animdata_cameras_only:
|
||||
yield camera.lens
|
||||
yield camera.dof.focus_distance
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user