0
$\begingroup$

I am trying to create a 3D scene using blender. I have made a model and camera path using blender interface. However, I want camera matrix to be exported frame by frame as well.

I know using Python script interface might do the job. Thus, I am wondering if I can animate frame by frame and in processing each frame, I can output camera matrix as well.

I know bpy.ops.render.render(animation=True) can render all the frames at once. Is there a way that I can do frame-basis?

Any comments are appreciated.

$\endgroup$
0

1 Answer 1

1
$\begingroup$
import bpy
import os

scn = bpy.context.scene

for f in range(scn.frame_start, scn.frame_end + 1, scn.frame_step):

    # go to frame f
    scn.frame_set(f)

    # output the camera matrix on the current frame
    mat = scn.camera.matrix_world
    print(mat)

    # set the filepath
    scn.render.filepath = os.path.join("C:/my/path/to/file/basename", str(f).zfill(4)

    # render the current frame
    bpy.ops.render.render(write_still=True)
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .