I'm trying to get all the meshes in a scene to their identity transform to export them so I can use their matrix_world to position them properly for animations/instancing/etc. I set them all back to their identity transform by clearing location/rotation/scale with bpy.ops.object.(location|rotation|scale)_clear()
. However in the case of animated objects with keyframes their position doesn't get cleared, so they're exported incorrectly.
What's odd is that just doing ALT-(G|R|S) to clear them manually does clear the position properly. Is there something extra I need to do to properly clear the positions from Python?
My script is essentially just:
# Select all the objects we want to export and save
# their matrix_world so we can restore it after exporting
# Clear positions for exporting everything at its identity transform
bpy.ops.object.location_clear()
bpy.ops.object.rotation_clear()
bpy.ops.object.scale_clear()
# Export meshes to OBJ
bpy.ops.export_scene.obj(...)
# Restore transformations by setting matrix_world back to what we saved earlier