I'm moving my camera on a Bezier circle drawn around an object. To achieve this, I added an Empty, parented the Empty to the camera, added a Follow Path constraint to the Empty (set the target as my object), and finally added a Track To constraint to my camera. With this setup, I can move the camera on an arbitrary path by arranging the control points of the Bezier circle.
While doing this, I also want to get the camera location and orientation for each frame using this script:
import bpy
scene = bpy.context.scene
def handler(scene):
print("Frame Change", scene.frame_current)
print("Camera location", scene.camera.location)
print("Camera rotation", scene.camera.rotation_quaternion)
bpy.app.handlers.frame_change_pre.append(handler)
bpy.ops.screen.animation_play()
However, I always get the same camera transform regardless of the camera position along the path:
Frame Change 1
Camera location <Vector (0.0000, 0.0000, 0.0000)>
Camera rotation <Quaternion (w=1.0000, x=0.0000, y=0.0000, z=0.0000)>
Frame Change 2
Camera location <Vector (0.0000, 0.0000, 0.0000)>
Camera rotation <Quaternion (w=1.0000, x=0.0000, y=0.0000, z=0.0000)>
...
How can I get the world coordinates of the camera at each frame?