ScriptSpot

Forum topic · General Scripting

detect scene texture -- please answer!!!

By artrender.info · 2013-04-11

Description

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

wow

artrender.info · 2013-04-15

they look wonderful! You're a great specialist!

Thx Barigazy!

artrender.info · 2013-04-14

I will try and I will let you know how it works later!!!
I'm working now with buttons that you told me to use! I'm starting to understand how they work! It's very interesting! But what kind of architecture you do, may I see some of your portfolio projects?

:)

barigazy · 2013-04-14

I prepare my site when I have free time.
Here a post some images for John script Cobwebs http://jokermartini.com/2012/05/09/cobwebs/ (named by Branko Zivkovic)
I will send you a few links in PM.

Thx, I know how to detect missing files!

artrender.info · 2013-04-14

The question is:

I download often 3d models from internet with missing files inside scene. There are cases when some textures are important for the object, but there are situations when a scene had missing textures from other objects, but when save/selected there were saved missing paths for those unused files from objects that are not in the new scene anymore! How do you get rid of them?

I thought to make smth like this:

1 find textures used in all hidden and unhidden models (material and modifiers)
2 find textures used in lights
3 find textures used in environment map
4 after these find textures from all scene and those textures that are not mentioned in first 3 situations - are unused--it means I can delete them somehow(I don't know how)

Am I right or not?

barigazy · 2013-04-14

U can delete missing maps:
Find all materials and props that have theses maps (create multidimensional array)


--example
tempArr = #(#($Box001.material, #DiffuseMap),#($.Cone001.material, #BumpMap))
for i = 1 to tempArr.count do setproperty tempArr[1] tempArr[2] undefined
--how to delete only unused mtl in M.Editor
for i in 1 to meditMaterials.count where (MeditUtilities.isMaterialInUse meditMaterials[i] == false) do meditMaterials[i] = Standard()
--Sometime asset tracking hold path strings
ATSOps.Refresh()
--is good to use this function at the end
freeSceneBitmaps()

Also slate M.Editor can hold materials
Look these thread for some useful infos how to acess
http://www.scriptspot.com/forums/3ds-max/general-scripting/how-to-loop-t…

barigazy · 2013-04-14

I can't remeber what more can cause problems, maybe someone have better idea?

Barigazy

artrender.info · 2013-04-19

Take a look to this max file! How to detect the location of its 2 missing files? and how to clean them?

By the way, Buttons started to work as I want, just remained to update location when scrolling, but I know how to do this.

Take a look please to this max file!

Attachments

I LOVE this website, because here you can find GREAT PEOPLE

artrender.info · 2013-04-14

I would mention also Swordslayer! He is also a very great programmer and knows very very deep how maxscript works!

I LOVE YOU ALL!!!

By the way, I've found sometime ago a script which could delete missing textures, and I can't find again!

How to detect unused files, because in ZOA path editor it's difficult to understand!

fajar · 2013-04-14

never to think that you use getprop names, I only using getpropname for collecting ies, ...hahah, i guest I must need train tooo....btw barigazy has you even try your script that collecting material by that ways, it look like to its heavy compute if I must loop thru' every material thru' every property in every material in every object , say if I had 500 obj in different material...cause it compute loop in loop....btw I'll try your script tommorow in much more object scene with many material. But I must say its good thing other than using getClassInstance....

barigazy · 2013-04-14

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

fajar · 2013-04-14

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 · 2013-04-14

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.

Thank you, barigazy!!!

artrender.info · 2013-04-13

I wonder, how you find time to help us!

;)

barigazy · 2013-04-13

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!

the best solution I guess is this

artrender.info · 2013-04-12

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????

collect modifier maps

barigazy · 2013-04-12

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

error when I have color correction inside texture map

artrender.info · 2013-04-11

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

Ok! Thanks! Is this code for detecting all material textures?

artrender.info · 2013-04-11

does it always work?

:) WOW HOLD ON

barigazy · 2013-04-11

I recently start to write my repath tool for all maxobjects (material,modifier,light,environment etc.) that contains bitmaptexture.
Asset Tracking is not the right choise for that. I can not share my unfinished code but maybe this snippet of RECURSIVE function can helps.


(
	clearlistener()
	mapsArr=#()
	fn getMtlMaps mtl maps = 
	(
		if mtl != undefined and mtl.numsubs != 0 do 
		(
			for m = 1 to mtl.numsubs where (mtl[m] != undefined) do 
			(
				if (isKindOf mtl[m] SubAnim) and (isKindOf mtl[m].Object textureMap) do append maps mtl[m].Object
				getMtlMaps mtl[m] maps
			)
		) 
	)
	getMtlMaps $.material mapsArr
	mapsArr
)

maybe this can be also useful
http://www.scriptspot.com/3ds-max/scripts/zoa-path-editor
http://www.scriptspot.com/3ds-max/scripts/relink-vraybmpfilter-maps