KirilStrezikozin/BakeMaster-Blender-Addon

REQUEST: Material groups - divide materials into separate image sets to bake

KirilStrezikozin opened this issue · 17 comments

This feature request is:

  • not a duplicate
  • implemented

Is your feature request related to a problem? Please describe.
Snoopybob from BlenderMarket:
I can tell you that I have compared most of the addons of this type, and I haven't found any that offers this obvious feature. I am sure that many people would be interested in such a feature, especially in the field of video games. Merging maps is convenient, but when you are constrained to low resolutions, it is better to have one map per material.

Describe the solution you'd like to be implemented
a sub-table in which, when you select an object, the list of materials appears with the possibility of selecting those which will be baker individually, of those which one could merge.

Not easy to project but I think this is the kind of functionality that should be allowed to "unfold" once an option is checked. This allows the user to glimpse new and more refined possibilities.

  1. We activate the display of the bake options by material
  2. Choose the objects concerned, then the materials concerned by objects
  3. Specify which ones will be merged and which ones will be individually baked "by default".

Just an idea, I hope it inspires you

Additional context
my option:
A section called "Material Groups" where you could specify unique material groups and add one or multiple objects' materials to them. With this kind of customization, you could be able to not bake all materials merged or all separately, but instead, for ex, choose mat1, mat2, mat4 to bake merged and mat3 separately from them.

  • implement UI:
  1. on bm_props.global_active_index Update, refill CollectionProperty for object's materials, add that CollectionProperty to the UI.
  • UI: add buttons to quickly set different indexes for all materials and another button to quickly set the same
  • Sideway todo: for bm_table_of_objects updates, write reassign for ..table_active_index because, for ex, highpoly table active index I haven't reseted and it causes UI draw errors
  • minor fixes around all code
  • add $matgroup tag to batchname
  • call bpy.ops.bakemaster.item_matgroups_table_refresh in bake_prepare_all_objects() after settings bm_props.global_active_index and before resolving batchname
  • add method: def ...matgroups_batch_collector(batchname: str, object) to collect batchname and matgroups and form a shell of images for self.bake_images[...][...] = (output from new method)

Example:

input:
batchname
[ mat1 - 1 ]
[ mat2 - 2 ]
[ mat3 - 1 ]
[ mat4 - 1 ]
[ mat5 - 3 ]

output:
[ batchname1, 1, mat1, mat3, mat4 ]
[ batchname2, 2, mat2 ]
[ batchname3, 3, mat5 ]

  • adapt texsets init to image_groups put into self.bake_images[...][...]
  • edit adaptation: combine only image_groups that have the same group_index

example:

========================================
[['Cube_1_NORMAL', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
[['Cube_1_ALBEDO', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
[['Cube_1_METAL', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
[['Cube_1_ROUGH', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
========================================
[['Cube_1_NORMAL', 1, ['Material', 'Material.002', 'Material.003']], ['Cube_1_NORMAL', 2, ['Material.001']], ['Cube_1_NORMAL', 3, ['Material.004']]]
[['Cube_1_ALBEDO', 1, ['Material', 'Material.002', 'Material.003']], ['Cube_1_ALBEDO', 2, ['Material.001']], ['Cube_1_ALBEDO', 3, ['Material.004']]]
[['Cube_1_METAL', 1, ['Material', 'Material.002', 'Material.003']], ['Cube_1_METAL', 2, ['Material.001']], ['Cube_1_METAL', 3, ['Material.004']]]
[['Cube_1_ROUGH', 1, ['Material', 'Material.002', 'Material.003']], ['Cube_1_ROUGH', 2, ['Material.001']], ['Cube_1_ROUGH', 3, ['Material.004']]]

should be:

========================================
[['Cube_1_NORMAL', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
[['Cube_1_ALBEDO', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
[['Cube_1_METAL', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
[['Cube_1_ROUGH', 1, ['Material', 'Material.001', 'Material.002', 'Material.003', 'Material.004']]]
========================================
[['Cube_1_NORMAL', 1, ['Material', 'Material.002', 'Material.003']], ['Ball_2_NORMAL', 2, ['Material.001']], ['Ball_3_NORMAL', 3, ['Material.004']]]
[['Cube_1_ALBEDO', 1, ['Material', 'Material.002', 'Material.003']], ['Ball_2_ALBEDO', 2, ['Material.001']], ['Ball_3_ALBEDO', 3, ['Material.004']]]
[['Cube_1_METAL', 1, ['Material', 'Material.002', 'Material.003']], ['Ball_2_METAL', 2, ['Material.001']], ['Ball_3_METAL', 3, ['Material.004']]]
[['Cube_1_ROUGH', 1, ['Material', 'Material.002', 'Material.003']], ['Ball_2_ROUGH', 2, ['Material.001']], ['Ball_3_ROUGH', 3, ['Material.004']]]
  • Full operator_bake.py code adaptation to matgroups

need to test definitely

but it wasn't as hard as I expected. Just added another headache on top of existing multidimensional arrays holding bake data

@@ -3151,6 +3129,8 @@ def grab_image_name(item):
                data += dir_data

            # append already initialized images
+           # whoa look at da 4-dimensional array,
+           # that's what makes stuff blazingly fast ^_^
            for obj_shell in self.bake_images:
                for maps_shells in obj_shell:
                    for map_shell in maps_shells:
                        for image_group in map_shell:
                            data.append(image_group[0])
  • in handle_object(...), where I get image_groups, call handle_matgroups(...) to mute materials that aren't in the current matgroup. On map_index, matgroup_index change, restore muted materials.

hell i'm done with this +.+

bakemaster_matgroups_ui-2023-02-22_16.47.42.mp4
  • make matgroup_naming prop look better in the ui