FBX IO: Speed up animation simplification using NumPy #104904
@ -2320,19 +2320,23 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
|
|||||||
split_at = np.cumsum(split_at[:-1])
|
split_at = np.cumsum(split_at[:-1])
|
||||||
all_ob_values, all_shape_key_values, all_camera_values = np.split(all_values, split_at)
|
all_ob_values, all_shape_key_values, all_camera_values = np.split(all_values, split_at)
|
||||||
|
|
||||||
|
all_anims = []
|
||||||
|
|
||||||
# Set location/rotation/scale curves.
|
# Set location/rotation/scale curves.
|
||||||
# Split into equal sized views of the arrays for each object.
|
# Split into equal sized views of the arrays for each object.
|
||||||
split_into = len(animdata_ob)
|
split_into = len(animdata_ob)
|
||||||
per_ob_values = np.split(all_ob_values, split_into) if split_into > 0 else ()
|
per_ob_values = np.split(all_ob_values, split_into) if split_into > 0 else ()
|
||||||
for (anim_loc, anim_rot, anim_scale), ob_values in zip(animdata_ob.values(), per_ob_values):
|
for anims, ob_values in zip(animdata_ob.values(), per_ob_values):
|
||||||
# Split again into equal sized views of the location, rotation and scaling arrays.
|
# Split again into equal sized views of the location, rotation and scaling arrays.
|
||||||
loc_xyz, rot_xyz, sca_xyz = np.split(ob_values, 3)
|
loc_xyz, rot_xyz, sca_xyz = np.split(ob_values, 3)
|
||||||
# In-place convert from Blender rotation to FBX rotation.
|
# In-place convert from Blender rotation to FBX rotation.
|
||||||
np.rad2deg(rot_xyz, out=rot_xyz)
|
np.rad2deg(rot_xyz, out=rot_xyz)
|
||||||
|
|
||||||
|
anim_loc, anim_rot, anim_scale = anims
|
||||||
anim_loc.set_keyframes(real_currframes, loc_xyz)
|
anim_loc.set_keyframes(real_currframes, loc_xyz)
|
||||||
anim_rot.set_keyframes(real_currframes, rot_xyz)
|
anim_rot.set_keyframes(real_currframes, rot_xyz)
|
||||||
anim_scale.set_keyframes(real_currframes, sca_xyz)
|
anim_scale.set_keyframes(real_currframes, sca_xyz)
|
||||||
|
all_anims.extend(anims)
|
||||||
|
|
||||||
# Set shape key curves.
|
# Set shape key curves.
|
||||||
# There's only one array per shape key, so there's no need to split `all_shape_key_values`.
|
# There's only one array per shape key, so there's no need to split `all_shape_key_values`.
|
||||||
@ -2340,6 +2344,7 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
|
|||||||
# In-place convert from Blender Shape Key Value to FBX Deform Percent.
|
# In-place convert from Blender Shape Key Value to FBX Deform Percent.
|
||||||
shape_key_values *= 100.0
|
shape_key_values *= 100.0
|
||||||
anim_shape.set_keyframes(real_currframes, shape_key_values)
|
anim_shape.set_keyframes(real_currframes, shape_key_values)
|
||||||
|
all_anims.append(anim_shape)
|
||||||
|
|
||||||
# Set camera curves.
|
# Set camera curves.
|
||||||
# Split into equal sized views of the arrays for each camera.
|
# Split into equal sized views of the arrays for each camera.
|
||||||
@ -2351,13 +2356,13 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
|
|||||||
focus_distance_values *= (1000 * gscale)
|
focus_distance_values *= (1000 * gscale)
|
||||||
anim_camera_lens.set_keyframes(real_currframes, lens_values)
|
anim_camera_lens.set_keyframes(real_currframes, lens_values)
|
||||||
anim_camera_focus_distance.set_keyframes(real_currframes, focus_distance_values)
|
anim_camera_focus_distance.set_keyframes(real_currframes, focus_distance_values)
|
||||||
|
all_anims.append(anim_camera_lens)
|
||||||
|
all_anims.append(anim_camera_focus_distance)
|
||||||
|
|
||||||
animations = {}
|
animations = {}
|
||||||
|
|
||||||
# And now, produce final data (usable by FBX export code)
|
# And now, produce final data (usable by FBX export code)
|
||||||
# Objects-like loc/rot/scale...
|
for anim in all_anims:
|
||||||
for ob_obj, anims in animdata_ob.items():
|
|
||||||
for anim in anims:
|
|
||||||
anim.simplify(simplify_fac, bake_step, force_keep)
|
anim.simplify(simplify_fac, bake_step, force_keep)
|
||||||
if not anim:
|
if not anim:
|
||||||
continue
|
continue
|
||||||
@ -2365,32 +2370,6 @@ def fbx_animations_do(scene_data, ref_id, f_start, f_end, start_zero, objects=No
|
|||||||
anim_data = animations.setdefault(obj_key, ("dummy_unused_key", {}))
|
anim_data = animations.setdefault(obj_key, ("dummy_unused_key", {}))
|
||||||
anim_data[1][fbx_group] = (group_key, group, fbx_gname)
|
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():
|
|
||||||
final_keys = {}
|
|
||||||
anim_shape.simplify(simplify_fac, bake_step, force_keep)
|
|
||||||
if not anim_shape:
|
|
||||||
continue
|
|
||||||
for elem_key, group_key, group, fbx_group, fbx_gname in anim_shape.get_final_data(scene, ref_id, force_keep):
|
|
||||||
anim_data = animations.setdefault(elem_key, ("dummy_unused_key", {}))
|
|
||||||
anim_data[1][fbx_group] = (group_key, group, fbx_gname)
|
|
||||||
|
|
||||||
# And cameras' lens and focus distance keys.
|
|
||||||
for cam_key, (anim_camera_lens, anim_camera_focus_distance, camera) in animdata_cameras.items():
|
|
||||||
final_keys = {}
|
|
||||||
anim_camera_lens.simplify(simplify_fac, bake_step, force_keep)
|
|
||||||
anim_camera_focus_distance.simplify(simplify_fac, bake_step, force_keep)
|
|
||||||
if anim_camera_lens:
|
|
||||||
for elem_key, group_key, group, fbx_group, fbx_gname in \
|
|
||||||
anim_camera_lens.get_final_data(scene, ref_id, force_keep):
|
|
||||||
anim_data = animations.setdefault(elem_key, ("dummy_unused_key", {}))
|
|
||||||
anim_data[1][fbx_group] = (group_key, group, fbx_gname)
|
|
||||||
if anim_camera_focus_distance:
|
|
||||||
for elem_key, group_key, group, fbx_group, fbx_gname in \
|
|
||||||
anim_camera_focus_distance.get_final_data(scene, ref_id, force_keep):
|
|
||||||
anim_data = animations.setdefault(elem_key, ("dummy_unused_key", {}))
|
|
||||||
anim_data[1][fbx_group] = (group_key, group, fbx_gname)
|
|
||||||
|
|
||||||
astack_key = get_blender_anim_stack_key(scene, ref_id)
|
astack_key = get_blender_anim_stack_key(scene, ref_id)
|
||||||
alayer_key = get_blender_anim_layer_key(scene, ref_id)
|
alayer_key = get_blender_anim_layer_key(scene, ref_id)
|
||||||
name = (get_blenderID_name(ref_id) if ref_id else scene.name).encode()
|
name = (get_blenderID_name(ref_id) if ref_id else scene.name).encode()
|
||||||
|
Loading…
Reference in New Issue
Block a user