[Closed] Saving a Material Tree and Finding a Material Again
Sorry for the slightly abstract question but I want to store an indirect-reference to a sub-material but without using the material itself…
Example, a multi-level material.
MultiMaterialA
-Multi1:VrayMtlA
-Multi2:VrayBumpMtl
–BumpMtl: VrayBlendMtlA
—Base: VrayMtlB
—Coat1: VrayMtlC
—Coat2: VrayMtlD
-Multi3:VrayBlendMtlB
–Base: VrayMtlC
Lets say I wanted to have a pointer to VrayMtlC, but we cannot use the Name because it’s also in the VrayBlendMtlB. And even though they are the ‘same’ material name they aren’t instanced.
What I want to do is say.
themat = materialX.submats[2].submats[1].submats[2]
However there is no such thing in max at the moment, unless I’m missing a trick with the subanim tracks?
The purpose is that I need to isolate a material to put into a render element Vray Extra Tex, but the material is being constantly updated from a library so the reference keeps getting broken. I have a small UI for the user to pick which material from the subtree they want to use but how I keep a reference to it is the challenge.
Currently I think I need to store an array for each material in my UI of how to navigate to it using the getSubMtl function.
TargetMat = #("MultiMaterialA", "VrayMtlC", #(2,1,2))
Then I’ve got to run a loop to get the material back again…
fn recurseMat mat path level name =
(
if level == path.count then return mat
else
(
level += 1
recurseMat (getSubMtl mat path[level]) path level name
)
)
a = recurseMat scenematerials[TargetMat[1]] targetMat[3] 0 TargetMat[2]
Next I’ve got to path out all of the materials in the subtree…
matList = #()
fn indexMat theMat initialMat levels =
(
append matList #(initialMat.name,theMat.name,levels)
for i = 1 to getNumSubmtls theMat do
(
if (getSubMtl theMat i) != undefined do
(
local lel = deepcopy levels
append lel i
indexMat (getSubMtl theMat i) initialMat lel
)
)
)
indexMat $Sphere001.material $Sphere001.material #()
and then finally make a dropdownlist with all the indentations visibly displayed.
ddlList = #()
for i = 1 to matList.count do
(
local ind = ""
for indent = 1 to matList[i][3].count do
(
append ind "-"
)
append ddlList (ind + matList[i][2])
)
print ddlList
So I’ve pretty much solved my problem just by typing it out properly, but thought I’d still press Submit on this thread as might be interesting for others and maybe there’s a better way?