2
$\begingroup$

I'm making a small script just to speed up the baking process of the various textures maps needed in game engines. I've got my normals, diffuse, and roughness maps mostly figured out but there is no metallic bake type in blender as of now. I know I can plug whatever is plugged in my Principled BSDF Metallic input into a Diffuse node and bake it without lighting information to get my metallic map but what if I make multiple Principled BSDFs and Mix Shader nodes in my material? Not so great as you can see. What would be a more robust way to get my metallic map through codes in the minimum amount of lines and working 100% of times?

Current code (still have to add all the baking process and saving the images but the jist of it is there)

import bpy
Scene = bpy.context.scene
obj = bpy.context.object.name
mat = bpy.context.object.active_material

loc = [0, -500]
size = 1024*2

map = "Diffuse"
node = mat.node_tree.nodes.new(type="ShaderNodeTexImage")
node.name = obj + "_" + map
node.label = obj + "_" + map
node.location = loc
loc[0] = loc [0] + 300
img = bpy.data.images.new(obj + "_" + map + "Tex", size, size, alpha = False)
img.colorspace_settings.name = 'sRGB'
node.image = img

Scene.cycles.bake_type = map.upper()

map = "Roughness"
node = mat.node_tree.nodes.new(type="ShaderNodeTexImage")
node.name = obj + "_" + map
node.label = obj + "_" + map
node.location = loc
loc[0] = loc [0] + 300
img = bpy.data.images.new(obj + "_" + map + "Tex", size, size, alpha = False)
node.image = img
img.colorspace_settings.name = 'Non-Color'

map = "Normal"
node = mat.node_tree.nodes.new(type="ShaderNodeTexImage")
node.name = obj + "_" + map
node.label = obj + "_" + map
node.location = loc
loc[0] = loc [0] + 300
img = bpy.data.images.new(obj + "_" + map + "Tex", size, size, alpha = False)
node.image = img
img.colorspace_settings.name = 'Non-Color'

enter image description here

$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .