ynput / ayon-substance-painter

SubstancePainter integration for AYON
Apache License 2.0
5 stars 1 forks source link

AY-7195_Allow project with multiple texture sets to export as one texture output #20

Open ynbot opened 3 days ago

ynbot commented 3 days ago

Please describe the enhancement you have in mind and explain what the current shortcomings are?

How would you imagine the implementation of the enhancemenent?

No response

Describe alternatives you've considered:

No response

Additional context:

link to discussion on Discord (might be a private channel)

This issue was automatically created from Clickup ticket AY-7195

moonyuet commented 8 hours ago

For the current Substance Painter API, there is no way to export multiple texture sets as one texture output. There are some related plugins which bridges the photoshop to send the texture sets and users can combine this. See comphonia/substance-painter-merger in github. There is an executable to help on merging the texture. So, there should be the way that we can merge the images in a hacky way for merging the texture sets and output as one texture. https://app.gumroad.com/d/62b7fabfccada3c32a547729f24edd83 We can probably test with the pillow library to combine the texture sets into one before the publish. But we need to make sure the data is correct (I mean the RGBA). Take this code below as an example

from PIL import Image, ImageChops

def load_normal_map(file_path):
    return Image.open(file_path).convert('RGB')

def save_normal_map(image, file_path):
    image.save(file_path)

def combine_normal_maps(normal_map1, normal_map2):
    combined = ImageChops.add(normal_map1, normal_map2, scale=2.0, offset=0)
    return combined

normal_map1 = load_normal_map('normal_map1.png')
normal_map2 = load_normal_map('normal_map2.png')

combined_normal_map = combine_normal_maps(normal_map1, normal_map2)

save_normal_map(combined_normal_map, 'combined_normal_map.png')

Meanwhile, we need to ask the Substance support if they have any suggestion/updates for this particular issue. EDIT: The support from Adobe has answered the question, they told me there is no automated way in substance painter to do this. He told that "it is best to not use multiple texture sets unless you have a very good reason to do so ie. different shader. If the intent is to just combine them in the end you're adding extra work for yourself. If the sets all would work being combined and not overlap you can just merge them as well post export with transparency." See https://discord.com/channels/179919948569640960/179930558439096321/1310607608998133832 for more info.

So the best solution to do so is to figure out how to merge the maps with transparency after exporting these maps from SP and uses pillow to combine all these maps. And this needs some refactoring on the collector and a new extractor for exporting the maps and combine them.