I am trying to get the updated rotation of an object during simulation in Blender 2.92. However, I am not able to get what I want. I appreciate if someone can help me with this.
As you may know, you will always get the original object's location and rotation if you do
bpy.context.object.location for each frame. However, you can get the object location if you make a vertex group from the original object vertices and add an empty object to it. This has allowed me to track the object and get its updated location. However, this trick does not seem to work for getting the updated rotation of the object for each frame. Even the empty's rotation does not match with the original object rotation before I start the simulation. For each frame of the simulation also I get more or less completely random rotation vectors from the empty if I print its rotation.
Does anyone have a solution for this?
vertices_to_add =  for vertex in bpy.data.objects['Cube'].vertices: vertices_to_add.append(vertex.index) # add vertices to vertex group group = self.obj.vertex_groups.new(name='Group') group.add(vertices_to_add, 1.0, "ADD") # create an empty bpy.ops.object.empty_add(type='PLAIN_AXES') bpy.context.object.rotation_euler = bpy.data.objects['Cube'].rotation_euler bpy.ops.object.constraint_add(type='COPY_LOCATION') bpy.context.object.constraints["Copy Location"].target = self.obj bpy.context.object.constraints["Copy Location"].subtarget = "Group" bpy.ops.object.constraint_add(type='COPY_ROTATION') bpy.context.object.constraints["Copy Rotation"].target = self.obj bpy.context.object.constraints["Copy Rotation"].subtarget = "Group" # Later on I do the followings to print the current rotation of the Empty for frame in range(1, num_frames+1): bpy.context.scene.frame_set(frame) print(bpy.data.objects['Empty'].rotation_euler) # this always prints the original object rotation print(bpy.data.objects["Empty"].matrix_world.to_euler('XYZ')) # This gives me completely random rotation vectors