0
$\begingroup$

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).

$\endgroup$
  • $\begingroup$ It sounds like you want to use the texture atlas addon, it is included with blender, just enable it. $\endgroup$ – sambler Jun 25 '18 at 7:02
  • $\begingroup$ Used it, doesn't address my problem. It'll create an atlas for all selected objects which may or may not share a material. $\endgroup$ – Biarity Jun 25 '18 at 8:23
  • $\begingroup$ it allows you to place multiple objects onto one uv layout without them overlapping, and without having to join and separate them. Most people do this to use one image texture for all objects but you can use this new uv layout with one material or ten materials. $\endgroup$ – sambler Jun 25 '18 at 8:45
  • $\begingroup$ I guess this would work our if there is a "select all objects with same material" feature (select all with same material then generate an atlas for them). Do you know if this achievable, even with scripting? $\endgroup$ – Biarity Jun 25 '18 at 8:49
  • $\begingroup$ Select objects with same material (one of a zillion) Can you add a say 3 cube 5 material example of result you want? Possible unanswered duplicate $\endgroup$ – batFINGER Jun 25 '18 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.