【问题标题】:How to use python to export the bake image form blender如何使用 python 从搅拌机中导出烘焙图像
【发布时间】:2017-07-17 03:03:32
【问题描述】:

我想做一些自动化操作。但是我在烘焙后导出图像时遇到了一些麻烦。起初我尝试使用“bpy.ops.object.bake_image()”来烘焙图像。但是结果图像无法在 uv 编辑器中激活。 The bake was success,but the result image didn't appear in the uv editor.It need selected so that I could export the file.

于是我搜索了文档,发现另一个命令“bpy.ops.object.bake()”。它有一个参数“save_mode”,但是我在使用这个命令时还是遇到了一些障碍。它总是指出我即“ RuntimeError: error: No active image found in material "material" (0) for object "1.001" "。 这是关于这两个命令的官方文档:
https://docs.blender.org/api/blender_python_api_2_78a_release/bpy.ops.object.html?highlight=bake#bpy.ops.object.bake

任何人都可以尝试给我一些解决方案或一些建议,我该如何解决这个问题。

【问题讨论】:

标签: python blender blender-2.76


【解决方案1】:

许多搅拌机操作员需要一定的上下文才能正常工作,因为 bpy.ops.image.save() 包括具有活动图像的 UV/图像编辑器。虽然 there are waysoverride the current context 可以使它们起作用,但使用其他方法通常会更容易。

Image 对象可以save() 自身。如果是新图像,您首先需要将其设置为filepath,您可能还需要将其设置为file_format

img = bpy.data.images['imagename']
img.filepath = '/path/to/save/imagename.png'
img.file_format = 'PNG'
img.save()

【讨论】:

    猜你喜欢
    • 2017-06-28
    • 1970-01-01
    • 2012-02-07
    • 2015-08-26
    • 2010-11-19
    • 2012-02-02
    • 1970-01-01
    • 2017-09-03
    • 2020-01-06
    相关资源
    最近更新 更多