Is it possible to bake textures to active UV layer from Python? I’m working on a script that will bake the textures of each object in a group called “Scene” to a UV layer called “Bake”. Here is what I have so far:
import bpy
import uvcalc_lightmap as uvpack
def export():
# Get the scene group (contains all objects to be exported)
sceneGroup = bpy.data.groups["Scene"]
# Loop through each object in the scene group
for obj in sceneGroup.objects:
# Get the mesh data for the current object
mesh = obj.getData(mesh=1)
# Get a list of the uv layers for the current mesh
uvLayers = mesh.getUVLayerNames()
# if the mesh doesn't have a uvlayer for baking textures
if "Bake" not in uvLayers:
# Add new uv layer for baking
mesh.addUVLayer("Bake")
# Set the new uv layer as active layer
mesh.activeUVLayer = "Bake"
# unwrap the mesh
uvpack.lightmap_uvpack([mesh])
# Now i need to bake the textures here
# ???
export()
At the moment, I loop through each object in the “Scene” group, get the mesh data for the object, check if the mesh has a UV layer named “Bake”, if it doesn’t, I add the “Bake” UV layer and set it as the active UV layer. I then unwrap the UV’s to the active layer, now I need to actually bake the textures. What modules/functions do I need to be looking at in order to do this?
Thank You.
EDIT: Typical, after posting this I found what object I was looking for, http://www.zoo-logique.org/3D.Blender/scripts_python/API/