CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 03-04-2011, 01:31 PM   #1
stigatle
Expert
 
stigatle's Avatar
portfolio
Stig Atle Steffensen
Project Engineer
National Oilwell Varco
kristiansand, Norway
 
Join Date: Aug 2010
Posts: 331
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-04-2011, 02:41 PM   #2
DaveWortley
<database error>
 
DaveWortley's Avatar
portfolio
David Wortley
Technical Director
London, United Kingdom
 
Join Date: Dec 2004
Posts: 1,918
Send a message via MSN to DaveWortley
Have a look at using getNumSubMtls and getNumSubTexmaps
with
getSubMtl and getSubTexmap
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 03-04-2011, 06:19 PM   #3
biddle
Frequenter
Mike Biddlecombe
Animation Programmer
United Front Games
Vancouver, Canada
 
Join Date: Jul 2005
Posts: 160
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-07-2011, 06:22 AM   #4
stigatle
Expert
 
stigatle's Avatar
portfolio
Stig Atle Steffensen
Project Engineer
National Oilwell Varco
kristiansand, Norway
 
Join Date: Aug 2010
Posts: 331
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-13-2011, 05:44 AM   #5
stigatle
Expert
 
stigatle's Avatar
portfolio
Stig Atle Steffensen
Project Engineer
National Oilwell Varco
kristiansand, Norway
 
Join Date: Aug 2010
Posts: 331
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-13-2011 at 06:06 AM.
 
Old 04-13-2011, 11:46 AM   #6
Panayot
Frequenter
portfolio
Panayot Karabakalov
Technical Artist
Bulgaria
 
Join Date: Mar 2011
Posts: 212
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-13-2011, 11:49 AM   #7
stigatle
Expert
 
stigatle's Avatar
portfolio
Stig Atle Steffensen
Project Engineer
National Oilwell Varco
kristiansand, Norway
 
Join Date: Aug 2010
Posts: 331
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-13-2011, 12:03 PM   #8
Panayot
Frequenter
portfolio
Panayot Karabakalov
Technical Artist
Bulgaria
 
Join Date: Mar 2011
Posts: 212
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-13-2011, 12:36 PM   #9
Gravey
3D Dude
Joel Hewitt
Sydney, Australia
 
Join Date: Dec 2005
Posts: 881
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-13-2011, 02:10 PM   #10
Panayot
Frequenter
portfolio
Panayot Karabakalov
Technical Artist
Bulgaria
 
Join Date: Mar 2011
Posts: 212
I did this more complicated, so many thanks for that function!
__________________
* everyone can win previous war
 
Old 04-13-2011, 03:55 PM   #11
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,865
Send a message via ICQ to 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 )
 
Old 04-13-2011, 08:30 PM   #12
Panayot
Frequenter
portfolio
Panayot Karabakalov
Technical Artist
Bulgaria
 
Join Date: Mar 2011
Posts: 212
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-13-2011, 08:47 PM   #13
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,865
Send a message via ICQ to denisT
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-13-2011 at 08:50 PM.
 
Old 04-13-2011, 09:03 PM   #14
Panayot
Frequenter
portfolio
Panayot Karabakalov
Technical Artist
Bulgaria
 
Join Date: Mar 2011
Posts: 212
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-14-2011, 05:44 AM   #15
stigatle
Expert
 
stigatle's Avatar
portfolio
Stig Atle Steffensen
Project Engineer
National Oilwell Varco
kristiansand, Norway
 
Join Date: Aug 2010
Posts: 331
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 12:06 PM.


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