I’m a blender n00b, and I’m trying to generate a bunch of pictures from a scene to use in a machine learning project. To do that I have made a python script. The python script runs, but all the pictures it produce are identical. It seems that my code (that I stole from https://stackoverflow.com/questions/14982836/rendering-and-saving-images-through-blender-python) isn’t working (full code at the bottom of this message).
To be specific, there is one particular line that is intended to rotate the entire scene a bit, that doesn’t seem to do anything at all:
origin.rotation_euler[2] = math.radians(angle)
So, does any of you know how to programmatically rotate the entire scene some angle between frames, either by tweaking the script below, or by some other mechanism that actually works, I’d be thrilled to know I’m using blender 2.90.1
Best wishes
Bjørn
def rotate_and_render(output_dir, output_file_format, rotation_steps = 4, rotation_angle = 360):
# Setting rendering parameters
bpy.context.scene.render.image_settings.file_format='JPEG'
bpy.ops.object.add(type = 'EMPTY')
origin = bpy.context.object
origin.rotation_mode = 'XYZ'
# Setting resolution
for scene in bpy.data.scenes:
scene.render.resolution_x = 48
scene.render.resolution_y = 27
for step in range(0, rotation_steps):
print("in da loop")
angle = step * (rotation_angle / rotation_steps)
origin.rotation_euler[2] = math.radians(angle)
print("Post rotation: ", angle)
print("Euler angle ", origin.rotation_euler[2])
filename = output_file_format.format(step, angle)
bpy.context.scene.render.filepath = output_dir + filename
print("Pre rendering")
bpy.ops.render.render(write_still = True)
bpy.ops.object.delete(confirm = False)