Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- # Make sure you model has been UV unwrapped
- # Set the render engine to Cycles
- bpy.context.scene.render.engine = 'CYCLES'
- # Create a new image to bake to
- image_name = "BakedTexture"
- image = bpy.data.images.new(image_name, width=1024, height=1024)
- # Iterate through all materials and assign the new image
- for mat in bpy.data.materials:
- if mat.use_nodes:
- for node in mat.node_tree.nodes:
- if node.type == 'BSDF_PRINCIPLED':
- # Create an Image Texture node and assign the new image
- image_node = mat.node_tree.nodes.new('ShaderNodeTexImage')
- image_node.image = image
- mat.node_tree.nodes.active = image_node
- # Bake the base colors
- bpy.ops.object.bake(type='DIFFUSE', pass_filter={'COLOR'})
- # Save the baked image
- image.filepath_raw = "//baked_texture.png"
- image.file_format = 'PNG'
- image.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement