Generate Material slots and assign from source figure Material (or Face group) for Copy Material

Issue #1077 closed
engetudouiti created an issue

Now we can keep material assignment of each material slot as “Face-map” when import daz figure/props. (https://bitbucket.org/Diffeomorphic/import_daz/commits/#:~:text=Thomas Larsson-,c5ec95b,-Fix for issue)

Then I feel, that means you can re-generate material-slots from source figure, when geometry structure is same as soruce.

Though I request to use Face map, (then I use it when I break default material slot),

Can you generate these steps by “Copy Material” of your add function for Recent versions?

  1. set Fake User for current Materials (as option)
  2. Remove all material slots (material assignment of the faces are removed)
  3. Generate new Material slots + assign each material slots for faces From Source Figure material slots (or Face maps)
  4. Copy Source Figure Material of each Material slots to the Target Material slots.

At current I think your offer “Copy Material” may try to keep Material slot name. (exchange shader nodes )But if you can do 1 to 4 steps, I suppose you can set new “Material slots name “(eg eyelash-wet) with keep same assignment.

Why I may often change Material-slots name, about blender,, Material-slots name = Material name, when we set… so we can not see clear, what type of material is currently used,, (eg Red skin , Wet skin, def white, etc)

To avoid this issue,, I requested to generate Face maps (and use the Face map as material slot name) but you know how assign Face-maps for each faces already so I suppose you can do same thing for material-slots.

So I suppose,, you can copy Material (generate material slots which have same name as Source material slots >> Copy material (shader nodes) from Source material one by one..

Of course user may need to re-name material slots if they hope to see what type of material is used.. but there is free rename tool, with use extension..

So I usually change material-slot name (= material name), when I edit materials hard.. eg,,

, if I edit Torso material with tatoo, I rename it,

as “Torso2.Tatoo” if I made wet version for Torso2, I rename it as “Torso2.Wet” then the material slot name represent current material type….. >>> you can keep many material set for each saved Object,, and can free copy material with keep the saved material names.

(You seems easy set Face maps from daz surface group,, so I expect,, you can assign material, without use Face map ,. but From source figure materials and their name ^^; if you can do it,,>>> you make material preset system which can auto-set material slot from source, even-though we tweak material slots assignments.. (eg you gather material slot as 7, for same shader group) but you can return materials from saved figure object (in another blend file),

Of course to “Copy material” work, we need to keep, same vertex order, and counts. so we need to save merged figure, and separated figure / graft figure individually,,, but it is not real problem..

Comments (24)

  1. engetudouiti reporter

    So this is real future request (not bug etc) then I hope you consider this request when-ever you hope it, 🙂

    I usually change materials save type as Object (not data) ,, I made simple tool to exchange all materials as Object without duplicate and re-assign material for faces…(blender do so ^^;) The good thing, is it can switch all materials of current Figure, as Object/data. without break appearance.

    So if you enhance Copy material,, I can save many material sets as different object but use same mesh data (only change material slots and material which saved in each object) i

    Then I save these object of same figure, in one blend file (aka Material set blend file).. >> anytime I can append the Object >> copy material

    (blender offer Copy material to selected tool or your offer Copy mateiral, they do almost same-thing but blender copy-material to selected change material-slot name, yours not.. and current problem is we need to keep same material slot structure. (so we can not copy material when we merge or change material assignment as we need , so if you solve this problem,, I think you offer perfect material preset system ^^;)

  2. Alessandro Padovani

    I’m not sure to understand what you’re after. Just pointing out that in blender you can select by material in edit mode so you don’t need face maps #1073 for that. Also we implemented material palettes to save/load back material sets.

    This is not to oppose your request but just to give information on the actual features in case you missed it. I have the feeling you’re trying to do things that are already implemented in a different way. But I may be wrong since I’m not understanding your comments very well.

    note. Please @Thomas when you add new features from user requests it is useful to also document how to use them. Otherwise they may remain “obscure“ features that only who requested them can understand and use. That’s not useful to many. As was the case with the “final slider values“ for example.

  3. engetudouiti reporter

    Alessandro, your described function are basic yes we use them often.

    .But it is not related with these request..

    You may check first, Blender “copy materials to selected”, And already offered “Copy materials” tool by this add on. (I do not request it, but Thomas already offer them)

    then limitation of current these tool.

    both copy matrials only work when user not modify material slot assginment.

    eg now you have default material slot, >> you gather those as 6 for same UDIM. after that Copy material failed. so I hope to remain default material slot in same data. to re-assign easy. (I use face-map to keep material slot assgin ment >> then I can select each poligons which saved as face map >> I can return default material slots when ever I need even though I modify them for each prupose. Of course auto re-generate matrial assignment is best, so I requested it if Thomas can make it work (If it work you can re-generate material slot + copy material from saved scene object)

  4. engetudouiti reporter

    And The usage to keep material group as face-map is,,, for user who modify material-slot assignment and break daz default surface group for each purposes.

    It is same you gather some material which may use same -shader group and texture.

    The problem is once you change it, then later you hope to use your savfed material for current scene,, you need to Copy materials from saved figure

    But , your saved figure keep default material assginment = DAZ surface group, so even though you Copy material to slected, or use Thomas offer “Copy material” it never work.

    So you need to re-assign material one by one with compare source figure . but I simply use Face-map (because Material slot have changed, but Face map keep as default), I can re-assign all material slot by use Face map (which generated when imported)

    just select Face-map and re-assign. without manually select each faces along with daz surface group. so it is useful.. Because material slot modified already. = Even though you select material with edit mode,, it just show your current modify assignment.. never show default one.

    Then This request is advance version… If Thomas can make it work,, now you can transfer all materials as you need, even though you hard change material slots. You just save and re-use whenever you hope so. You just append the figure >> Copy materials (to selected) . or everytime you need to check your current material slot assignment is same as Source. if it had been changed, you need to re-assign as same as source.

    I can confirm if it work well,, most of user thanks Thomas. (because we can save “material set” and re-use them by one click even though You change material assginment (and slot count) hardly.

    That means, you can transfer material about these 2 cubes (at current NO. so I request it)

  5. engetudouiti reporter

    OK I seems make it work,,, it was simple than I imagined ^^;

    Though I do not know how long to take re-assign material slot for high polygon like daz figures.

    import bpy
    tmode = bpy.context.active_object.mode
    objs = bpy.context.selected_objects
    so = bpy.context.active_object
    to = None
    
    if objs[0] == so:
        to = objs[1]
    else:
        to = objs[0]
    
    sms = so.material_slots
    
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.context.view_layer.objects.active = to
    
    while len(to.material_slots) != 0:
        bpy.ops.object.material_slot_remove()
    
    while len(to.material_slots) != len(so.material_slots):
        bpy.ops.object.material_slot_add()
    
    i = 0    
    while i < len(to.material_slots):
        to.material_slots[i].material = sms[i].material
        i += 1
    
    tplgs = to.data.polygons
    splgs = so.data.polygons
    
    j = 0
    while j < len(tplgs):
        tplgs[j].material_index = splgs[j].material_index
        j +=1
    

    About this case,, my script once remove all material slot from target object, then re-generate and re-assign as same as source.

    if polygon count and index are same,, it should assgin material-slot as same as source, after that simply copy material without rename.

    (Thomas Copy Material may duplicate, and change Material name right? though I do not know which is good.. I may hope to keep each material name which I edit, for skin type. )

    ===

    worked!! with my new PC it not take so long… 10 to 15 seconds ..

    Above pic, I just duplicate and keep my mat, then remove all materials and set one white mat for Target.

    after that , transfer the source duplicated def mat to current posing Target .. it seems generate all mat, and assgin again correctly!

    Can you add this for your current function “Copy material” as one option?

    Though it can not use palette. need real saved mesh with material as source. (need to append , then select both >> copy material to selected ( transfer Material from Active to Selected)

    I know you intend, not rename mat,, but about my scirpt,, it re-name material as source mat.

    (it will remove all current Target materials,, so if they are not Fake user,, it will be removed. as start point, I think it is enough to easy auto transfer materials from saved one.. though it need to keep poligon index, and poligon count as same as source. if you try to transfer non merged figure to merged figure, it not work.

  6. Alessandro Padovani

    This is just to point out that “copy materials” can work with material names instead of material slots. That’s also what daz studio does. So if the names are the same (apart the suffix number) it will work to copy a material palette from one figure to another, even with different slots.

    Again not sure this is what you’re after, just trying to help.

    note for @Thomas. The correct term in blender is “material slot“, not “material number“, so you may want to correct this in the relevant places. But this is a very minor note.

  7. engetudouiti reporter

    Alessandro, at least when I test with all option (Copy material with mix use those) it not work when you change material slots count. or merged some material slot as one. do you test it actually? I just get this error . and it is reasonable for me.

    because Thomas offer Copy material never re-generate material assginment as same as source.

    And it is because, Thomas not make it so. It is almost same how blender “Copy mateirals to selected work.What I requested is same as this. I found today some blender user seems asked same thing.

    https://blender.stackexchange.com/questions/251625/how-to-transfer-material-assignment-data-onto-another-mesh-with-same-uv-map-and

    Then my scirpt actually do it. so I hope if Thomas add the option for his material tool. but I do not complain,

    it is neat problem, and I already make my add on which can do it so. The difference is, my scirpt not just transfer material , but also re-assign all material as same as source. so I can make one material figure if I need. without use texture etc, then can swap those for any scene without problem. because it actually re-assgin all material from source, after clean up.

    Please do not take your time, if you do not actually test what I show you carefully. I really do not hope to say same thing again to another user, I have asked Thomas not you. If Thomas offer same function which I means, he never make it. (no meaning)

  8. engetudouiti reporter

    Then Alessandro means, if it is only naming matter (keep using current target material slot then just exchange shader node,

    or change material name at same time as source (I like it, because I can separate material by name)

    I notice there seems option, but it is not relate with this issue, so I not test all. From start point, it is matter transfer material slot assignment. Then if I edit material slot count, (merge some part) ,It can not keep material (slot) name as same as source. eg defualt 10 material slot and 10 name now, I merged as 5. so now it have only 5 material slot name. s

    so there is no meaning to remain default name about this case,, Of course Thomas script can transfer with name or change name I suppose though, aftter all, I need to re-assign material as same as source for polygons. or I can not see same render.

    Then if Thomas add this option (transfer and set all material assignment as same as source) I think, I may need not use FaceMap to keep default material assignment anymore.. (because now I can transfer all material slot and auto assign them for polygons anytime I need…Just save them when I modify and can re-use it anytime I need. so I do not need to keep material assignment as Face Map.. it is for manual assignment. (just record default assign then easy select again to return all slot)

  9. Alessandro Padovani

    @Thomas, we may want to make the copy material independent from the number of slots. At least for the name option it doesn’t matter if the source and target have the same number of slots, but only that they have some names in common.

    p.s. If I understand correctly what Enge says, this would also make #1073 unnecessary.

  10. engetudouiti reporter

    Yes. it is actually simple thing😐 . I suppose Alessandro not use many material options.. with change poligon assignment.

    eg when I export DAZ figure to other tools, , or bake, I often edit mateiral assginment and UVset too.

    Though basically, I like to keep all daz material slots to get most flexible materials (surface group) but sometimes I must reduce them for each purpose.

    or there is case I actually need only 5 or 6 mateiral set. separated with new UV tiles. then save the object in blend file.

    What I have requested was,, when you transfer or copy material FIgure A to Figure B,, eventhough Figure B lost all material slot or change mateiral slot assginment, with different name, or change UV, simply transfer all material from Fig A o FIgure B or FIgure B to FIgure A correctly and show same render, without any step. after that I remove appended source FIgure A

    I edit my script which remove all current UV, and transfer UVs from source and set active render UV as same as source.

    Then if Thomas will add same function, maybe It is better, it transfer UV set from source (and remove current one from target) too. and auto-set render UV as same name. (so even though shader node use specific UV set name, it basically work I suppose)

    Though I suppose Thomas already offer tool to transfer UV and activate it, as separate function. but actually if you can one click copy and paste all materials FIgure A to Figure B , it is really handy (for me), Though figA and figB can not change geometry. (it not bake , simply copy and paste, all UV and materials as same as source, with correctly assign all material-slot for polygons

  11. Alessandro Padovani

    Storing uv maps together with materials is not something that is usually done. They are separate functions because they deal with separate matters. So you first copy uvs and then copy materials.

  12. engetudouiti reporter

    Alessandro, There is no merit to devide UV transfer and Material transfer,

    when you need to transfer materials. the purpose is to get render as same as saved. It is same logic, you hope to use easy mode to import morphs.

    If it use different UV set, it never fit when you transfer materials.

    So logically , when you need to transfer full mat for target, you need to transfer UV, if different UV had been used.

  13. Thomas Larsson repo owner

    The Copy materials tool has been rewritten in the last commit. Match by name is now the default, and it copies materials with similar names irrespective of slot number. Actually simplified the code quite a bit.

    Adding materials to face maps makes little sense to me. However, I don’t want to undo #1073 completely, because it is the only way to import polygon groups from DS. Not that I think that anyone will use polygon groups in Blender, but it is nice to be able to import them for completeness.

  14. Thomas Larsson repo owner

    Engetu, there is a separate tool for loading UV sets, so I don’t see why doing it automatically here. If you copy materials between meshes with different UV sets, you are on thin ice anyway and really need to know what you are doing, and then you can load the new UVs manually.

  15. engetudouiti reporter

    Yes Face map is only way to keep daz surface group.(or any group which used as Faces) so I do not request, you remove the function. I suppose I can re-use it.

    Then Thomas, test this scene, and how you may transfer mat, uv-set, and get same render, from 3 source to 1 target. as you need.

    “Transfer matrials” means,, get same render as source for target when they have same polygon and index.

    (it is what I hope to) like this. so it need to get same UV , same material slots, same material as source. As for me, at least for such function,. at same time all polygons correctly assigned for new Materials.(slots)

    or Is there option, which you can do it already in blender/your add on ? As for me I do not think it is so important how you use slot-name / material name when copy each mats. it is option.

    I simply copy material as same name as source not keep current target slot name. (it is case by case, so you offer option is good )

    What I have requested is, simply transfer all for render at same time from source to current working figure mesh.

    but if your offered tool (recent version) already do same thing with mix use options, I happy close this issue as solved. then tell me, which option can do it please.

  16. engetudouiti reporter

    Test Scene. if you need my custom add on, I will attach it. (but I suppose you can easy add it as “Transfer all mats” option. which do all job as one click (select source . select target > click)

  17. engetudouiti reporter
      You may know how it is easy to transfer, any mesh materials to target ,  and should show same render as source .(because UV is same, slot is same, materials are same with slot name, and polygon assginment)
    

    The usage is,

    select source

    select target

    from material property> transfer materials it is all.

    Only miner problem is all target materials use same source materials, then if I happend to delete source or target material in the scene, both removed. So I usually after transfer materials, duplicate mat and rename. only about target.

    then edit and save, Then I can re-use it, as one click for other scene figures as I need.

    (Tjough need to append source again)

  18. Alessandro Padovani

    Ok now may be I understand what you’re looking for. That is not a “copy materials“, but rather a complete overwriting of the destination mesh. That is, this way the destination mesh will lose all its uv maps and materials and will acquire the uv maps and materials of the source mesh. This requires that the target is a morph of the source, that is, the geometry and vertex order has to be the same.

    @Thomas may write a new tool, something like:

    • tool name: “replace uvs and materials“
    • tooltip: “replace the target uvs and materials with the source, requires that the target is a morph of the source“

    edit. note. important. But in this case it would be simpler to just transfer the target shape as a morph to the source geometry, that can be easily done in blender with “join as shapes“. So instead of replacing uvs and materials you just transfer a shapekey. One click.

  19. engetudouiti reporter

    I really do not know how you say things so complex… OK,,,to transfer materials we need same geometry.

    but important thing is only transfer Material related things. though it not transfer smooth data or seam etc..

    Just transfer UV set, multi materials and assign it correctly.

    And why I need to say join as shapes etc? there is no reason.. because the Data keep shape keys as same as before with all driver, modifier. so it is not data transfer all meshes. only transfer / clean up material related things, never touch other data.

  20. engetudouiti reporter

    Then as I said, I do not looking for. . because now I have it as my tool. so just think if Thomas add it or not for others.

    so I set this request as miner. my tool already work, without any other tool.

  21. Thomas Larsson repo owner

    OK, now I understand what you are saying. But I think that this is a quite unusual way to do things, and I doubt that anyone but yourself would ever use such a tool. Since you have your own script, I don’t think that it is necessary to include it in this plugin. It is not that Daz specific either.

  22. engetudouiti reporter

    When you need to use any 3d paint tool just to make variation for daz complex figures, change material group is usuall process. If you only need to use daz offered items then apply it for import figures, you may need not. because your surface group may never change = always keep daz surface group. (just merged with graft etc)

    But if you will play with 3d paint tool / sculpt tool , they often say , change surface group (set it as minimum) to easy paint / sculpt for your purpose in another app, until export it. then texture sculpt >> return baked textures and re-apply it.

    if you only work with the changed material figure, it is no problem, but when you return daz default (which you and Alessandro main use ) materials, you need to change it again.

    After all every time, when you change material slot, you need to check your material-slots count. and manually re-assign it for polygons as same as source. (so your tool simply return “material count miss match”.

    if it is real special case, I do not think your copy tool need info. you just need to say it only work when source and target slot are same. when it not work = it not assign polygons for same slot. But as you said, it is your thinking how your tool work, so I stop this request. I already have it for my-self.

    (it is good thing because I had requested same thing really long time, with change topic name (like make material preset system etc)

  23. Log in to comment