Resource: Get All Textures Function
EDIT (2014-07-11): Antomor replied with a version reduced to just 2 lines. This will give you a string array of file paths rather than the actual bitmap instances, though. Use Anubis' getClassInstances version below for bitmapTexture instances.
for obj in selection do join ff (usedMaps obj) ff = makeUniqueArray ff print ff
============================
EDIT (2011-12-20): As Anubis pointed out there is a much much better way to do this. Really to the point where there isn't any reason to make a function for it, but here is a better version anyway:
( fn GetBitmapTextures theObjects = ( texMaps = #() for obj in theObjects do ( join texMaps (getClassInstances bitmapTexture target:obj asTrackViewPick:off) ) makeUniqueArray texMaps ) texMaps = (GetBitmapTextures selection) for texMap in texMaps do print (texMap.filename) OK )
============================
ORIGINAL:
-- DON'T USE THIS. Keeping for search keywords.
Hey all,
I wrote a quick function for getting all the textures associated with an object. It seems like something a lot of other people might also need so thought I'd post it up. I've seen a couple similar functions out there, but non of them really seem to take into account either MultiMaterials, or maps that might contain submaps (like normal maps).
Thanks to the-generalist.com for posting this resource, which didn't do what I wanted, but still was a great starting point.
Just do GetBitmapTextures [object] and it will return an array of bitmapTexture maps. From there you can get/set any of the properties.. like returnedArray[1].filename for instance.
-- DON'T USE THIS. Keeping for search keywords. fn GetBitmapTextures theObjects = ( -- Because some submaps can also contain submaps we have to collect materials first, and then still append subMapContainers in the loop bitmapTextureMaps loop subMapContainers = #() for obj in theObjects do ( if obj.material != undefined then ( submatcount = getNumSubMtls obj.material for i in 1 to submatcount do ( append subMapContainers (getSubMtl obj.material i) ) append subMapContainers (obj.material) ) ) bitmapTextureMaps = #() for subMapContainer in subMapContainers do ( subtexcount = getNumSubTexmaps subMapContainer for i in 1 to subtexcount do ( theSubTexMap = (getSubTexMap subMapContainer i) if theSubTexMap != undefined then ( if (getNumSubTexmaps theSubTexMap) > 0 then ( append subMapContainers theSubTexMap ) else if classof theSubTexMap == bitmapTexture then ( append bitmapTextureMaps theSubTexMap ) ) ) ) makeUniqueArray bitmapTextureMaps ) texmaps = (GetBitmapTextures selection) for texmap in texmaps do print (texmap.filename)
Comments
good work vallex , just as
good work vallex , just as barigazy said .... need some case of thing .....and will be done...also need some consideration of vray disp map, displacement map thing, env...and else.
atomor fn is good but not
atomor fn is good but not return class bitmap instead filename only, for in anubis , its not really work on max 9 when object using mental ray material
simpler code
return all textures of selection objects
I made this one, it works
I made this one, it works fine:
Tested with most of materials and maps
...
Your fn have limitations. You will need to consider much more map types
bga
Added your version. Thanks,
Added your version. Thanks, Antomor.
it does not work for blend materials
-- Unable to convert: undefined to type: MtlBase
I mean your second code, but the first works! THX
...
... hahahaha.. man.. well thanks..
...
what about ...
texmaps = for obj selection collect (getClassInstances bitmapTexture target:obj asTrackViewPick:on)
my recent MAXScripts RSS (archive here)
I edited the post. Thanks
I edited the post. Thanks again :P