1
$\begingroup$

I want the screw object to rotate along the z-axis in 99 steps from 0 to 2*pi. For each step, the python can output an image and save in a folder.

The original position of the screw is like this: enter image description here

I had expected the rendered image's position could be like this. It can only rotate along z-axis without the changing of the origin's position.

enter image description here

But after I ran my code, the position of the screw changed to this:

enter image description here

My code is:

def animationImages(path, num):

    model = bpy.data.objects[0]
    print(model)
    model.rotation_mode = 'XYZ'
    images_path = path

    image_index = 1
    for radi in np.linspace(0, 2*math.pi, num, endpoint = False):
        model.rotation_euler = (0, 0, radi)
        image_save_path = "{}/{}.png".format(images_path, image_index)

        bpy.context.scene.render.filepath = image_save_path
        bpy.ops.render.render(write_still=True, use_viewport=True)

        image_index += 1
    return

images_path = r'M:\RenderedModels\images'
num_images = 99

animationImages(images_path, num_images)

How can I write the code to get the expected result?

$\endgroup$

1 Answer 1

1
$\begingroup$

sorry that I have worked it out. The code can be:

def animationImages(path, num):

    model = bpy.data.objects[0]
    print(model)
    model.rotation_mode = 'XYZ'
    images_path = path

    x_radi = bpy.context.object.rotation_euler[0]
    y_radi = bpy.context.object.rotation_euler[1]

    image_index = 1
    for radi in np.linspace(0, 2*math.pi, num, endpoint = False):
        model.rotation_euler = (x_radi, y_radi, radi)
        image_save_path = "{}/{}.png".format(images_path, image_index)

        bpy.context.scene.render.filepath = image_save_path
        bpy.ops.render.render(write_still=True, use_viewport=True)

        image_index += 1
    return

images_path = r'M:\RenderedModels\images'
num_images = 99

animationImages(images_path, num_images)
$\endgroup$

You must log in to answer this question.

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