【问题标题】:Python scripting in Blender: how can I save a sequence of rendered images?Blender 中的 Python 脚本:如何保存一系列渲染图像?
【发布时间】:2014-11-02 16:34:10
【问题描述】:

我是 Python 脚本的新手,所以我一直在尝试一些简单的东西——一堆立方体做 3D 随机游走的动画。

我已经设法让程序渲染进程的每一帧,但我不知道如何保存每一帧。有人可以帮忙吗?

这是代码。我所缺少的将出现在 def render_and_save 函数中。

干杯!

import bpy
import random

number_of_cubes = 10
animation_length = 10

def create_cubes(number_to_make):
    i = 0
    while i < number_to_make:
        bpy.ops.mesh.primitive_cube_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0))
        i += 1

def move_cube():
    bpy.ops.transform.translate(value=(random.randint(-1,1), random.randint(-1,1), random.randint(-1,1)), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)

def select_cube(cube_name):
    bpy.ops.object.select_all(action = "DESELECT")
    bpy.ops.object.select_pattern(pattern = cube_name)

def move_all():
    j = 0
    while j < number_of_cubes:
        if j == 0:
            name_of_cube = "Cube"
            print(name_of_cube)
        elif j < 10:
            name_of_cube = "Cube.00" + str(j)
            print(name_of_cube)
        elif j < 100:
            name_of_cube = "Cube.0" + str(j)
            print(name_of_cube)
        select_cube(name_of_cube)
        move_cube()
        j += 1

def render_and_save(moves):
    bpy.ops.render.render(use_viewport = True)
    filename = str(moves)+".png"
    #But what should go here to make it save each image?

create_cubes(number_of_cubes)

moves = 0
while moves < animation_length:
    move_all()
    render_and_save(moves)
    moves += 1

【问题讨论】:

    标签: python blender


    【解决方案1】:

    默认情况下bpy.ops.render.render() 不保存单个图像渲染。只需设置write_still=True 即可启用它。

    def render_and_save(moves):
        bpy.context.scene.render.filepath = "//renders/"+str(moves)+".png"
        bpy.ops.render.render(use_viewport = True, write_still=True)
    

    文件路径设置与渲染设置的输出面板中可用的值相同。通过将“//render/”放在它的开头,它将把图像放在一个名为 renders 的文件夹中,该文件夹与混合文件位于同一文件夹中 - “//”是当前混合文件父文件夹的缩写。

    【讨论】:

      猜你喜欢
      • 2013-02-05
      • 2018-12-14
      • 2020-08-19
      • 2023-01-17
      • 2012-05-12
      • 2016-05-05
      • 2018-07-07
      • 2019-08-30
      • 2011-07-21
      相关资源
      最近更新 更多