[Closed] Accessing Material from its Map Node
Hello,
I have almost the same Problem as it is explained in this thread:
http://forums.cgsociety.org/showthread.php?f=98&t=602855&highlight=texture+map
My Problem is, that I have to access the parent node of the e.g. diffuseMap.
Just like the buttons on the Material Editor “go to parent” or go forward to sibling”
I`am developing an scripted texuremap plugin and when the map is assigned to the diffuse channel of the material I want to create an customized bumpmap in the bump slot of the material.
But I have to know how deeply nested the Material is in which my texturemap is created.
I`m not sure if I explained the problem clearly because my english is not so good but I hope somebody can help me.
Thanks
so given…
myMat = meditmaterials[1]
01 - Default:Standard
myMap = Noise()
Noise:Noise
myMat.diffuseMap = myMap
Noise:Noise
You want to know how, if you have ‘myMap’, to get to ‘myMat’?
dependentRefs = refs.dependents myMap
#(ReferenceTarget:ReferenceTarget, 01 - Default:Standard, ReferenceTarget:Material_Editor, ReferenceTarget:Scene)
mats = for ref in dependentRefs where (superClassOf ref == material) collect ( ref )
#(01 - Default:Standard)
mats[1]
01 - Default:Standard
Even if you nest the map inside other maps, that should still work:
myMat.diffuseMap = Mix()
Mix:Mix
myMat.diffuseMap.map1 = myMap
Noise:Noise
dependentRefs = refs.dependents myMap
#(Mix:Mix, ReferenceTarget:ReferenceTarget, 01 - Default:Standard, ReferenceTarget:Material_Editor, ReferenceTarget:Scene)
mats = for ref in dependentRefs where (superClassOf ref == material) collect ( ref )
#(01 - Default:Standard)
mats[1]
01 - Default:Standard
If it’s inside a nested material, you basically hit the same problem as the thread you referenced; although I would check into a more robus method of trying to find your map (unless you can make the same assumptions as in that thread).
You may or may not hit a problem if a user instances the map, however – as I don’t think there is a way to get the ‘parent’ of the map as it will have more than one:
anotherMat = meditmaterials[2]
02 - Default:Standard
anotherMat.diffuseMap = newMap
Noise:Noise
dependentRefs = refs.dependents myMap
#(Mix:Mix, ReferenceTarget:ReferenceTarget, 01 - Default:Standard, ReferenceTarget:ReferenceTarget, 02 - Default:Standard, ReferenceTarget:Material_Editor, ReferenceTarget:Scene)
mats = for ref in dependentRefs where (superClassOf ref == material) collect ( ref )
#(01 - Default:Standard, 02 - Default:Standard)
Which would be especially problematic if you have a multi/sub material and, say, the map is instanced to the second material – already being present in the first material. If you simply loop over things, the fist submat is what would be returned as having your map in it; thus ignoring the second material.
How to handle that situation (which may not actually occur where you use it) will depend on what the map does, etc. You might set a flag on any material you have already processed, for example, so that any loop you may use will ignore materials that are flagged until it finds the one it hasn’t processed yet (indicating that the map would be new to that material).
It’s entirely possible I missed something glaringly obvious the documentation, however
Hi ZeBoxx2,
thank you very much for the quick and detailed answer. I will check it out tomorrow an hope I can fix my problem with this information.
Thank you
Hi ZeBoxx2
I just try it and it works. Great. Thank you very much again.
Greets Stephan