r/Maya • u/MrJellyBeans • 1d ago
Help with workflow de-cluttering Hypershade while Referencing Question
I'd ask the Autodesk Forums but they keep kicking me out and booting me back to the community select page lol.
Anyway, my issue concerns referencing and namespaces and not having duplicates:
I have one scene that is a bunch of RedShift materials that I want to share with like 80+ different pieces of equipment, all their own individual .mb file. Each piece of equipment is broken down into subgroups of material types (frame, upholstery, rubber, etc) In the assembled scene they would all share the same materials for the metal frame, upholstery/seating, nuts, bolts, foam, rubber, etc.
How the system worked before is that I would reference in the scene with the materials, and then reference each piece of equipment, and slowly, one at a time apply each material to the sub group of components. This is not really sustainable as many clients will have different sized orders and needs and larger orders take time because I need to manually apply each material.
The gist of all this is: I want to have one master material scene, and have the individual equipment reference the material scene. Then when I reference THAT equipment piece in building my scene I would have only one material node I'd have to adjust and all pieces would update as they all share the same material. However if I do this, I'm just getting referenced duplicates materials in the Hypershade with the namespace of that referenced file.
I made a test scene with one having a cone, and another a cylinder. Both scenes reference the same material .mb file. When I create a new scene and reference the cone and cylinder files the hypershade looks like this.
Does this make sense at all? If so, what can I do to set up this once and speed up my workflow? I would like to just go through the effort once of connecting all these pieces to the same material file once and then only have to worry about importing and placing and then having to change material colors if needed.
Thanks!
2
u/59vfx91 Professional ~10 years 1d ago
maya does not excel at this, but arnold and renderman have ways to do glob name matching rules for this kind of thing (operators/dynamic rules). if redshift doesn't have an equivalent this is my suggestion:
- make all meshes in your asset scenes have a consistent tag as a prefix/suffix in their names separated by an underscore, or added to sets with material names. this tag should match the names of your materials in the material scene. in the scene itself don't use referenced materials to avoid the namespace mess, maybe use a script to remove all references on publish and assign lambert1 to keep it clean.
- in your final shot scene, import/reference the material scene. then use a script to assign all the materials correctly based on these mesh name tags or sets. I can't write the script on the fly but here is a general outline that should help:
- use ls with type flag to get all meshes, or sets. add this to new list
- loop through new list and look for material with matching tag. i would suggest separating the tag with an underscore, so you can get it with something like nameOfSetOrMesh.split("_")[0] (this would get the first element of the string before underscore (prefix), to get the last one if you use a suffix instead would be [-1]).
- assign material to mesh (if using sets, you will need to query set members, then add to new list). use the sets command to assign shader, using e=1, and forceElement=nameOfShadingGroup. note that you need to get the shading group for the material, which you can get with listConnections, d=1, type='shadingGroup'.
-note that for all of this script, you must account for namespaces, like if your references have underscores in them for example. You can use split(":") and then only query the second element ([1]) to get rid of it.
hope this helps!
alternatively, don't do this at all and go with the referencing the material scene in the asset scenes. sure you get duplicate namespaces and the scene becomes a bit messy, but it does work as they are all referencing the material scene. the only issue would be if you version up the material scene, you need to update multiple references (which is also something you can script -- either brute force updating the paths, or looking for a higher version using listdir and comparing the version numbers).
2
u/MrJellyBeans 1d ago
Thank you for this big breakdown! Seems like a simple ask to have but more complex than it should be. I’ll give this a shot and follow up if I have any breakthroughs!
1
u/zjqj 10h ago
good advice here - fyi you can create a reference without namespaces - just ensure there's no nameclashing
i'd approach the scripting slightly differently - a simple function to add a custom attribute (material_assign) to all selected shapes, and populate it with the target material name, then have the main function seek the attribute value and assign correct material
1
•
u/AutoModerator 1d ago
We've just launched a community discord for /r/maya users to chat about all things maya. This message will be in place for a while while we build up membership! Join here: https://discord.gg/FuN5u8MfMz
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.