Hey there Blender Community,
I'm trying to figure out the optimal way to use Blender's physics engine to perform simulations and access the information from each frame of the simulation for various other purposes. The idea, ultimately, is to be able to loop through the frames of the animation once the simulation is complete and get information about an object's location, for example, after a rigid body collision.
I was able to successfully accomplish something like this with the following method:
def analyze_scene():
scene = bpy.data.scenes['Scene'].frame_end
object = bpy.data.objects[object]
frameInfo = []
for frame in range(1, scene.frame_end):
scene.frame_current = frame
bpy.ops.ptcache.bake_all(bake=False)
frameInfo.append({"name": object.name, "frame": frame,
"translation": object.matrix_world.translation})
return frameInfo
(Note: There may be an error in this code, but it's just an outline of what I'm doing).
The issue with this is having to call "update all to frame" (bake_all) with every frame. Is there a better way of doing this that isn't so computationally expensive? I've experimented with Scene.update() to no avail.
My thanks in advance for any assistance.