通过Blender python渲染和保存图像

use*_*506 28 python render save blender

我试图通过混合器中的python脚本渲染和保存多个图像.我知道如何通过Blender GUI渲染和保存图像,但我想通过我的脚本完成所有操作,因为我使用的是一组嵌套循环,需要保存多个图像.我能够渲染图像,我想在输出成功的情况下保存图像.但我不知道它保存到哪里,当我尝试编辑文件路径时,它给出了上下文错误的错误.

shy*_*cha 32

在这里我做了什么Blender 2.63:

bpy.data.scenes['Scene'].render.filepath = '/home/user/Documents/image.jpg'
bpy.ops.render.render( write_still=True ) 
Run Code Online (Sandbox Code Playgroud)

我正在做的是创建一个VR全景(围绕它的一系列物体镜头).我结束了这个算法:

  1. 创建或加载要拍摄的对象
  2. 缩放它并执行一些不错的照明; 通过渲染场景检查灯光(使用F12键)
  3. 创建一个Empty节点,并设置其位置和旋转,以标识(位置:0, 0, 0,旋转:0, 0, 0)
  4. 将相机视图设置为开始位置(再次使用渲染检查)
  5. 运行脚本!

您最终会step_count/home/user/VR目录中围绕对象进行拍摄.

cam = bpy.data.objects['Camera']
origin = bpy.data.objects['Empty']

step_count = 32

for step in range(0, step_count):
    origin.rotation_euler[2] = radians(step * (360.0 / step_count))

    bpy.data.scenes["Scene"].render.filepath = '/home/user/VR/vr_shot_%d.jpg' % step
    bpy.ops.render.render( write_still=True )
Run Code Online (Sandbox Code Playgroud)

  • @SibbsGambling 我认为这是因为 Blender 还可以选择渲染预览图像(就像按 F12 时一样)。所以实际上将渲染保存为静止图像在某种程度上是可选的。 (2认同)

Dir*_*irk 9

这样的事情:

import bpy

bpy.context.scene.render.filepath = 'pathToOutputImage'
bpy.context.scene.render.resolution_x = w #perhaps set resolution in code
bpy.context.scene.render.resolution_y = h
bpy.ops.render.render()
Run Code Online (Sandbox Code Playgroud)

  • 没有'write_still = True'作为'render()'函数的参数,在我的情况下,blender没有创建图像. (8认同)