detect scene texture -- please answer!!!

I've found some ideas here:
http://forums.cgsociety.org/archive/index.php/t-1028393.html :

gc() -- just for this example, to make sure everything is nice and clean
 
-- find the scene root. The rootnode, medit, etc are references off this scene root
sceneroot = (for r in (refs.dependents rootnode) where (classof r == Scene) collect r)[1]
 
-- collect all the assets
origAssets = for i = 1 to AssetManager.GetNumAssets() collect (AssetManager.GetAssetByIndex i)
 
-- for each of the assets...
for AUIO in origAssets do
(
-- dump info on the asset
local AID = AUIO.GetAssetId() --get the Asset�s ID
local AType = AUIO.getType() --get the Asset�s Type
local AFile = AUIO.getfilename() --get the Asset�s File Name
format "ID:% Type:% File:%\n" AID AType AFile --format the info
-- generate new filename, prepend "XXXX_"
local lFile = filenameFromPath AFile
local lPath = getFileNamePath AFile
local lNewName = lPath + "\\" + "XXXX_" + lFile
-- do the retargetting
atsops.RetargetAssets sceneroot AFile lNewName CreateOutputFolder:false
)

and here:

http://www.scriptspot.com/forums/3ds-max/general-scripting/resource-get-...

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)

Here is how I detect textures inside materials for the selected objects:

		for s in selection do		
		(
			--textID = 0
			if s.material!=undefined then
			(
				if (finditem uniquematerials s.material==0) do
				(
					append uniquematerials s.material
					newbitmaps=getclassinstances Bitmaptexture target:s.material
				)
			)
		)

I don't use this code:

	fn getmapsfromselection = 
	(
		for s in selection do 
		(
			if s.material!=undefined then 
			(
				newbitmaps=getclassinstances Bitmaptexture target:s.material
                    		for b in newbitmaps do 
					if (finditem bitmaps_for_selection b==0) then append bitmaps_for_selection b
			)
		)
         )

because I need to investigate the materials for map tree, id and so on.

Now the question is:
1. Is the code I have enough and correct for detecting textures inside material?
2. How to detect the textures inside modifiers for the selected objects?
3. How to detect textures used in any other places(sky, hdr etc)
4. How to detect all scene textures
5. How to detect unused textures!

Please answer!!!

Comments

Comment viewing options

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

...

It is fester way than using getClassInstance, and for better performance when you use let say for materials you can predefine getpropname for some materials (VRayMat or Arch&Design). In your scene you definitely not use more then 10 different type of materials.
Also at least 90% of material props have slot for map input and you must loop through all.
For modifiers and lights a few props have map inputs.
This method supports VRayBmpFilter map (asset tracking not).

bga

fajar's picture

thanks, barigazy, because

thanks, barigazy, because someone like you this kind of thing can easly develop, further and futher. ma I dont hate money mongrel who develop one script then suck up money without any helping to community that help him. first of BOBO, anubis, Barigazy, theres miauu too n unnamed artist that trying to help each other to make something beyond boundary happen. I can say youre rock man.....I like you brigazy, thanks alot for helping community and thanks for donating one of your best tool too.

barigazy's picture

Hey fajar, thanks for the

Hey fajar,
thanks for the kind words.
We share the same opinion and i can tell same about you.
People you mentioned know and respect the meaning of the word "Thanks".
I will also start with Kostadin Kotev "miauu", Denis Trofimov "DenisT", Borislav Petrov "Bobo", Panayot Karabakalov "Anubis", John Martin "JokerMartini",Alexander Kramer "Track", Pete "LoneRobot", Dave Stewart, James Haywood, Josef Wienerroither "spacefrog" and many others.

bga

artrender.info's picture

Thank you, barigazy!!!

I wonder, how you find time to help us!

barigazy's picture

;)

It's a secret.
I like to help from time to time those who are persistent in
the implementation of some good ideas.
And this forum is the right place to meet such people and share new ideas and tricks.
Anyway the method that I post last time u can easy modify and use it also for materials and lights etc. Consider this as a homework :)
Cheers!

bga

artrender.info's picture

the best solution I guess is this

I just didn't understand that the first code was better:

http://www.scriptspot.com/forums/3ds-max/general-scripting/resource-get-...

(
	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
)

The only thing, how to detect textures from modifiers????

barigazy's picture

collect modifier maps

It's not big deal for modifiers because only a few have map support. Anyway try
this code on selection with already assigned mods (vrayDisplacement,Displace,Vol.Select etc.)

modTexMaps = #()
for obj in geometry where obj.modifiers.count != 0 do
(
	for m = 1 to obj.modifiers.count do
	(
		for p in (getpropnames obj.modifiers[m]) \
        where isKindOf (tex = getproperty obj.modifiers[m] p) texturemap do 
		(
			append modTexMaps tex
		)
	)
)
modTexMaps

bga

artrender.info's picture

both scripts still give errors for certain materials

your script gives error when there is

diffuse/Color Correction/texture
....../Vray color

and this script http://www.scriptspot.com/forums/3ds-max/general-scripting/resource-get-...

gives error when there is blend material

artrender.info's picture

this code works for selected object

from here

http://www.scriptspot.com/forums/3ds-max/general-scripting/resource-get-...

(second code posted at the beginning) does not give this error!

artrender.info's picture

error when I have color correction inside texture map

-- Error occurred in m loop; filename: material textures.ms; position: 426; line: 16
-- Frame:
-- m: Map #79:Color Correction
-- called in anonymous codeblock; filename: E:\Soft\scripts\x\Textures\material textures.ms; position: 456; line: 17
-- Frame:
-- getMtlMaps: getMtlMaps()
-- mapsArr: #(Map #79:Color Correction, DiffMap1:Bitmap, ReflMap:Bitmap, BumpMap:Bitmap, GlMap:Bitmap)
-- Error occurred during fileIn in #E:\Soft\scripts\x\Textures\material textures.ms; line number: 16
>> MAXScript FileIn Exception:
-- Unknown property: "filename" in Map #79:Color Correction <<

Comment viewing options

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