Collect all Materials in scenematerials subnum node

Hey,

I was wondering if there's a less hard coded way of collecting all the materials that are wired into the scenematerials array such as multisubmaterial, blend, CoronaRaySwitchMtl, VRayBlendMtl and so on..

Each of these have different properties to check against for materials but I was hoping to see if it can be done to collect the materials in those slots by checking whether or not it's a material only node or material Array.

Has anyone done this successfully before.

HARDCODED METHOD EXAMPLE #1

crsmMat = meditMaterials[1] = CoronaRaySwitchMtl name:"CoronaRaySwitchMtl"
giMat = crsmMat.giMtl

Returns:

CoronaRaySwitchMtl:CoronaRaySwitchMtl
Material #33:CoronaMtl

HARDCODED METHOD EXAMPLE #2

Mat = multimaterial numsubs:2
if Mat != undefined do objMatSubs = Mat.materialList

Returns:

#Multi/Sub-Object:Multimaterial(Standard:Material #34, Standard:Material #35)
#(Material #34:Standard, Material #35:Standard)

It would be nice if scenematerial array would have a way to get those materials too.

PS.
I thought I could get those materials through the rootScene method but no luck.

w=rootscene[#Scene_Materials] 
for i in w.object do print i

Only returns same as the scenematerials array method. :(

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

Try to play with getClassInstances fn
http://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_41314BE...

barigazy

pixamoon's picture

`

Hey,

This should work:

AllMaterials = #()
 
fn FindMaterials m = if m != undefined and Superclassof m == Material do (
	appendifunique AllMaterials m
	for i = 1 to getNumSubMtls m do FindMaterials (getSubMtl m i)
)
 
for m in scenematerials do FindMaterials m
 
print AllMaterials
barigazy's picture

...

Again maybe is smarter way to collect first all unique mats by class from scene materials and then search specific mat. Something like this (just concept)

-- let try with multimaterial
mats = getclassinstances multimaterial target:scenematerials
mtl = --some material ei. multimaterial
uniqueMats = #()
-- appendifunique fn is very slow so we try something like this
if (n = getNumSubMtls mtl) > 0 do
    for i = 1 to n where findItem uniqueMats (m = getSubMtl mtl i) do 
        append uniqueMats m

I did'nt test this but as concept is ok

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.