Files
test2/tests/files/render/util/render_bake.py
Sergey Sharybin 628f53a28c Refactor: Consolidate baking settings into BakeData
Almost all settings were duplicated between BakeData and RenderData.
The only missing field was the bake type, which is stored as a custom
property in Cycles.

This change:
- Removes unused bake_samples and bake_biasdist.
- Migrates settings like bake_margin to BakeData.
- Switches multires baker to use bake_margin.
- Introduces bake type in the BakeData, the same way how it was
  defined in RenderData::bake_mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/144984
2025-08-22 19:18:03 +02:00

38 lines
1.3 KiB
Python

# SPDX-FileCopyrightText: 2024 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
def bake(context):
scene = context.scene
cscene = scene.cycles
image = bpy.data.images["bake_result"]
if scene.render.bake.target == 'VERTEX_COLORS':
# Bake to the vertex group first, then bake to a image
#
# TODO: The code currently works under the assumption that
# a color attribute node with the baked attribute is connected
# to the material output node. This limits the type of passes
# that can be baked to a vertex group to specific data passes.
# Look at https://projects.blender.org/blender/blender-test-data/pulls/73
# for ideas on how to improve this.
bpy.ops.object.bake(type=cscene.bake_type)
scene.render.bake.target = 'IMAGE_TEXTURES'
cscene.bake_type = 'COMBINED'
if scene.render.bake.use_multires:
# Multires baking calls a different function to bake images.
bpy.ops.object.bake_image()
else:
bpy.ops.object.bake(type=cscene.bake_type)
# TODO(sergey): This is currently corresponding to how
# regular rendering pipeline saves images.
image.save_render(scene.render.filepath + '0001.png', scene=scene)
if __name__ == "__main__":
bake(bpy.context)