In my scene I have many objects, some of which share materials. I'd like to create 1 UV map per material.
This is because I'm using Substance Painter, where 2 objects with the same material should not have overlapping UV maps (or their paint data overlaps). I'm effectively trying to create an "atlas" for each set of objects sharing a material.
I've written this script which joins all objects, separates them by material, then does a smart UV unwrap (thus creating 1 UV map per material), then joins them back:
# join & separate based on material bpy.ops.object.select_all(action='SELECT') bpy.ops.object.join() bpy.ops.mesh.separate(type='MATERIAL') # smart UV unwrap each object for obj in bpy.context.scene.objects: if obj.type == 'MESH': bpy.context.scene.objects.active = obj bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='SELECT') bpy.ops.uv.smart_project() bpy.ops.object.mode_set(mode='OBJECT') # join everything back again bpy.ops.object.select_all(action='SELECT') bpy.ops.object.join()
The problem is I end up with all my objects joined, and now I have to manually separate and rename them again to their original state. (PS. "separate by loose parts" is not good enough unfortunately).