- Multiple bake maps at same time with one click:
There is the addon “MeltDown”. Amazing tool except a bit clunky and buggy.
- Export automatically all textures to a external folder at same time that I bake:
def save_image(data, obj, scene):
path = Pref.blendPath()
size = Pref.bake_size()
a = 0
f_name = '_'.join([obj.name, data.img_type])
f_path = os.path.join(path, f_name + '.png')
while os.path.exists(f_path):
a += 1
f_name = '_'.join([obj.name, data.img_type, deci(a)])
f_path = os.path.join(path, f_name +'.png')
image = bpy.data.images[_img + _active]
image.filepath_raw = (f_path)
image.file_format = 'PNG'
image.scale(size, size)
image.save()
Most importantly, find the path to your relative Blender file.
Secondly, create a path including the “…\baked_image.png” part.
Check if such file already exist, therefore it grants the option to overwrite or version control.
Get the image you wanted to save as a ‘image’ variable/pointer, then image.save(), in my code, I used the image’s name to find the correct one.
Run this function after each “bpy.ops.object.bake_image()” code and make sure the correct image is passed in. There it is, automatic exporting.
If you fancy a specific image format and the image color depth, use image.save_render(context.scene, ???) with proper output settings.
Btw, automatically creating the materials for the user would be a big plus. At least that’s what I’m doing with my own script, but I haven’t figured out how to do it with Cycles. Though, with Blender Render, here is the example code:
# the parameter "data" is a specific class type I use to store settings for each type of bakes.
def set_material(data, objects):
if hasattr(data, 'mat_name'):
mat = bpy.data.materials.get(data.mat_name)
if mat is None:
mat = bpy.data.materials.new(name = data.mat_name)
if hasattr(data, 'mat_emit'):
mat.emit = data.mat_emit
if hasattr(data, 'mat_albedo'):
mat.diffuse_color = data.mat_albedo
if hasattr(data, 'mat_specular'):
mat.specular_color = data.mat_specular
for obj in objects:
obj.data.materials.clear()
obj.active_material = mat
return True
# these returns doesn't mean anything. It's for error handling and laziness.
else:
return False
def clear_material(objects):
for obj in objects:
obj.data.materials.clear()
Cycles use nodes, which adds a layer of complexity and I haven’t figured out yet.
When 2.79 actually releases, It’s possible to save material linking data before setting the material and when the bake is done, re-link the original materials back onto the objects. IDproperties, wink wink.
Keep up the good work mate, Yours could save me a lot of time.