loop through all slots in material

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2011   #1
loop through all slots in material

Hi.

I've got a loop that goes through all materials in the scene.
It then checks the diffuse slot if there's a bitmap:

I then set the diffuse map to "undefined" if I find a missing texture.
The current code works great, but this is now hard coded like this:
'o' is my current material in my loop.
Code:
o.diffuseMap = undefined


I'd like to scan each and every slot in the materials in a loop, instead of defining each slot type through script (Diffuse, bump, specular etc), but I'm stuck on how to go about doing that.
__________________
http://stigatle.no
 
Old 03 March 2011   #2
Have a look at using getNumSubMtls and getNumSubTexmaps
with
getSubMtl and getSubTexmap
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 03 March 2011   #3
Perhaps something like:

Code:
fn YourValidateFunction bmap = ( format "Validating %\n" bmap true ) fn ValidateMaterial mat = ( if (classof mat == multimaterial) then ( for submat in mat.materiallist where submat != undefined do ( ValidateMaterial submat ) ) else if (classof mat == standardmaterial) then ( for i = 1 to mat.maps.count where (mat.maps[i] != undefined) and (not YourValidateFunction mat.maps[i]) do ( mat.maps[m] = undefined ) ) )
 
Old 03 March 2011   #4
Thanks to both of you for you answers.
I will implement this now, and get it running.

I'll also share the end result of the script here, so that others can use.
__________________
http://stigatle.no
 
Old 04 April 2011   #5
I tried the above script, but it does not replace the missing texturemap.
Also I failed at making it replace it..

Any hints?

My code now is:

Code:
files = #() for o in scenematerials do ( Numsubs = getNumSubMtls o aBmaps = getClassInstances BitmapTexture function get_names name a = append a name enumerateFiles get_names files #missing for Bmap in aBmaps do ( local sFilename = Bmap.filename local sPath = getFilenamePath sFilename local sFile = getFilenameFile sFilename local sType = replace (getFilenameType sFilename) 1 1 "" for maps in files do ( MaterialNumsub = getNumSubMtls o MaterialNumsubTex = getNumSubTexmaps o print "Number of submaterials:" print MaterialNumsub print "Number of SubTextures:" print MaterialNumsubTex if (maps == sFilename)do ( print "Found missing texture:" print maps --YourValidateFunction sFilename -- undo on -- ( --TODO Scan through all slot's for bitmap --check if its being used in that slot. -- print "removing from diffuse slot" -- o.diffuseMap = undefined -- ) ) ) ) )
__________________
http://stigatle.no

Last edited by stigatle : 04 April 2011 at 06:06 AM.
 
Old 04 April 2011   #6
If I see the question right, here you go...
Code:
fn CleanMissingDiffuseMaps mtl = ( if isProperty mtl #diffuseMap and \ classOf mtl.diffuseMap == BitmapTexture and \ not doesFileExist mtl.diffuseMap.fileName do mtl.diffuseMap = undefined numSubs = getNumSubMtls mtl if numSubs > 0 do ( for i = 1 to numSubs do ( mat = getSubMtl mtl i CleanMissingDiffuseMaps mat -- recursion call ) ) ) for mat in sceneMaterials do CleanMissingDiffuseMaps mat
__________________
* everyone can win previous war
 
Old 04 April 2011   #7
thank you,
but also what I need is a way to go through all the map types.
The missing map can be in diffuse, reflection etc,
I'm wondering if there's a way to go through all of them without having "if" sentences for every map type (reflection, alpha, diffuse etc)
__________________
http://stigatle.no
 
Old 04 April 2011   #8
aha, that's different story then.
check getPropNames() and getProperty() functions.
just snippet...
Code:
mat = meditMaterials[1] propNames = getPropNames mat for p in propNames where SuperClassOf (getProperty mat p) == material do print p
__________________
* everyone can win previous war
 
Old 04 April 2011   #9
this should do what you want for any material type
Code:
fn CleanMaterial mat = ( for i = 1 to getNumSubMtls mat do ( subMat = getSubMtl mat i CleanMaterial subMat ) for i = 1 to getNumSubTexMaps mat do ( map = getSubTexMap mat i if classof map == bitmaptexture AND NOT doesFileExist map.filename do setSubTexMap mat i undefined ) )
 
Old 04 April 2011   #10
I did this more complicated, so many thanks for that function!
__________________
* everyone can win previous war
 
Old 04 April 2011   #11
Code:
fn cleanBitmapTextures mat = ( for tx in (getclassinstances bitmaptexture target:mat asTrackViewPick:on) where not doesfileexist tx.anim.filename do tx.client[tx.subNum].value = undefined )
 
Old 04 April 2011   #12
Quote:
Originally Posted by denisT
Code:
fn cleanBitmapTextures mat = ( for tx in (getclassinstances bitmaptexture target:mat asTrackViewPick:on) where not doesfileexist tx.anim.filename do tx.client[tx.subNum].value = undefined )

Hi Denis, on which Max version you test this function?
Due to the docs GetClassInstances() is fixed in Max 2011.
Not tested by me, am still on Max 2009 and here it is a real disaster.

I test your function with Blend material. The result is - Mask slot is not cleaned,
and the most worst - the materials are removed from Blend slots.
__________________
* everyone can win previous war
 
Old 04 April 2011   #13
Quote:
Originally Posted by Panayot
Hi Denis, on which Max version you test this function?
Due to the docs GetClassInstances() is fixed in Max 2011.
Not tested by me, am still on Max 2009 and here it is a real disaster.

I test your function with Blend material. The result is - Mask slot is not cleaned,
and the most worst - the materials are removed from Blend slots.


getclassinstance in max 2009 and 2010 has bug and sometime doesn't return trackpickvalue right.
the function returns wrong subNum value.
it's fixed in 2011...

here is a version to trick it:
Code:
fn cleanBitmapTextures mat = ( for tx in (getclassinstances bitmaptexture target:mat asTrackViewPick:on) where not doesfileexist tx.anim.filename do ( for s=1 to tx.client.numsubs where tx.client[s].value == tx.anim do tx.client[s].value = undefined ) )

Last edited by denisT : 04 April 2011 at 08:50 PM.
 
Old 04 April 2011   #14
Quote:
Originally Posted by denisT
getclassinstance in max 2009 and 2010 has bug and sometime doesn't return trackpickvalue right.
the function returns wrong subNum value.
it's fixed in 2011...

here is a version to trick it:
Code:
fn cleanBitmapTextures mat = ( for tx in (getclassinstances bitmaptexture target:mat asTrackViewPick:on) where not doesfileexist tx.anim.filename do ( for s=1 to tx.client.numsubs where tx.client[s].value == tx.anim do tx.client[s].value = undefined ) )

Yes, that works in Max 2009. Thanks for the reply.
__________________
* everyone can win previous war
 
Old 04 April 2011   #15
Quote:
Originally Posted by denisT
Code:
fn cleanBitmapTextures mat = ( for tx in (getclassinstances bitmaptexture target:mat asTrackViewPick:on) where not doesfileexist tx.anim.filename do tx.client[tx.subNum].value = undefined )


Thank you, this works!
__________________
http://stigatle.no
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:55 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.