Need help replacing some maps in my scene.

Hi I'm a new at using MAXScript, and I need to replace a lot of Normal Bump maps in my scene. I imported some models and they have a Multimaterial with several VrayMtl on them, and in some of those VrayMtls there is a Normal Bump map which I need to replace with a VrayNormalMap with the same Bitmap as before.

I searched the forums and someone had a similar problem (actually was the exact opposite), and I found a script that replaces VrayNormalMap with a Normal Bump map, so I tryed to tweak it to do the inverse, but I can't seem to make it work. I believe I need to specify that it is inside a multimaterial, and then a VrayMtl submaterial, but now I'm totally lost.

Any help would be really aprecciated.

This is the script I found earlier from barigazy:

try(destroydialog ::vrnRoll) catch() 
rollout vrnRoll " VrayNormalMap Convertor" width:168 height:30
(
	fn filterNMap obj = 
	(
		isKindOf obj.material VRayMtl and \
		isKindOf obj.material.texmap_bump VRayNormalMap and \
		isKindOf obj.material.texmap_bump.normal_map Bitmaptex and \
		obj.material.texmap_bump.normal_map.filename != undefined
	)	
	button btn "VrayNormalMap to NormalMap"
	on btn pressed do
	(
		if (getClassInstances VRayNormalMap).count != 0 do
		(
			local objMtlsArr = for g in geometry where filterNMap g collect g.material
			if objMtlsArr.count != 0 do
			(
				for m in objMtlsArr do
				(
					local NMap = Normal_Bump name:(m.texmap_bump.name) normal_map:(m.texmap_bump.normal_map)
					m.texmap_bump = NMap
				)
				free objMtlsArr				
			)
		)
	)	
)
createDialog vrnRoll style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)	

Comments

Comment viewing options

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

VrayLighrMtl Material to VrayMtl Material

Hello,
I would be appreciated if someone help me to make the script above to convert VrayLighrMtl Material to VrayMtl Material.

Pleaaaaase!

tomastnt's picture

Would be possible change also a Gamma to 1.0?

Hi!
Its great script! Might you know there is a bug with Vray and normal bump in proxy objects. So all proxy objects has to have material with vraynormalmap, not with normalbump and this script is a solution.
I would be very pleased to have also an option to load every bitmap in converted vraynormalmap with gamma 1.0 in 3DS Max 2010 :) Pleasssss :)
Thanks

nacho008's picture

Nevermind, I found the error,

Nevermind, I found the error, a couple of materials had no bitmap assigned to the Normal Bump, thats where it crashed.

In any other case it works perfectly! Thanks again barigazy!!

barigazy's picture

...

Try this

try(destroydialog ::vrnRoll) catch() 
rollout vrnRoll "NormalMap Convertor" width:168 height:30
(
	button btn "NormalMap to VrayNormalMap"
	fn getMaterial arr = for i in arr where isKindOf i VRayMtl collect i
	on btn pressed do
	(
		for g in geometry where g.mat != undefined and (ins = getClassInstances Normal_Bump target:g.mat).count != 0 do
		(
			for m in ins where (isKindOf m.Normal_map Bitmaptex) do
			(
				NMap = VRayNormalMap name:(m.name) normal_map:(m.Normal_map)
				if (arr = getMaterial (refs.dependents m.Normal_map)).count > 0 do (for n in arr do n.texmap_bump = NMap)
			)
		)
	)	
)
createDialog vrnRoll style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

nacho008's picture

Yeah, I tried that same

Yeah, I tried that same thing, but it doesn't work. It returns a dialog that reads:

MaxScript Rollout Handler Exception
 
--No "map" function for undefined.

On the Listener it reads the following:

Rollout:vrnRoll
true
-- Error occurred in getMaterial(); filename: ; position: 213; line: 5
--  Frame:
--   arr: undefined
--   called in m loop; filename: ; position: 554; line: 14
--  Frame:
--   arr: undefined
--   m: Map #443:Normal Bump
--   NMap: Map #443:VRayNormalMap
--   called in g loop; filename: ; position: 614; line: 15
--  Frame:
--   ins: #(Map #443:Normal Bump, Map #45:Normal Bump)
--   g: $VRayProxy_AM_133_building_003_001_hi
--   called in btn.pressed(); filename: ; position: 619; line: 16
--  Frame:
>> MAXScript Rollout Handler Exception:
-- No "map" function for undefined <<
OK
Rollout:vrnRoll
true
-- Error occurred in getMaterial(); filename: ; position: 213; line: 5
--  Frame:
--   arr: undefined
--   called in m loop; filename: ; position: 554; line: 14
--  Frame:
--   arr: undefined
--   m: Map #443:Normal Bump
--   NMap: Map #443:VRayNormalMap
--   called in g loop; filename: ; position: 614; line: 15
--  Frame:
--   ins: #(Map #443:Normal Bump, Map #45:Normal Bump)
--   g: $VRayProxy_AM_133_building_003_001_hi
--   called in btn.pressed(); filename: ; position: 619; line: 16
--  Frame:
>> MAXScript Rollout Handler Exception:
-- No "map" function for undefined <<
barigazy's picture

...

send me test scene for testing

bga

barigazy's picture

try(destroydialog ::vrnRoll)

try(destroydialog ::vrnRoll) catch() 
rollout vrnRoll "NormalMap Convertor" width:168 height:30
(
	button btn "NormalMap to VrayNormalMap"
	fn getMaterial arr = for i in arr where isKindOf i VRayMtl collect i
	on btn pressed do
	(
		for g in geometry where g.mat != undefined and (ins = getClassInstances Normal_Bump target:g.mat).count != 0 do
		(
			for m in ins do
			(
				NMap = VRayNormalMap name:(m.name)
				if isKindOf m.Normal_map Bitmaptex do NMap.normal_map = m.Normal_map
				if (arr = getMaterial (refs.dependents m.Normal_map)).count > 0 do (for n in arr do n.texmap_bump = NMap)
			)
		)
	)	
)
createDialog vrnRoll style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

nacho008's picture

Thanks barigazy!! but your

Thanks barigazy!! but your script does the opposite of what I want, it replaces any VrayNormalMap with a Normal Bump.

I need every Normal Bump replaced with a VrayNormalMap.

barigazy's picture

...

try(destroydialog ::vrnRoll) catch() 
rollout vrnRoll " VrayNormalMap Convertor" width:168 height:30
(
	button btn "VrayNormalMap to NormalMap"
	fn getMaterial arr = for i in arr where isKindOf i VRayMtl collect i
	on btn pressed do
	(
		for g in geometry where g.mat != undefined and (ins = getClassInstances VRayNormalMap target:g.mat).count != 0 do
		(
			for m in ins do
			(
				NMap = Normal_Bump name:(m.name)
				if isKindOf m.Normal_map Bitmaptex do NMap.normal_map = m.Normal_map
				if (arr = getMaterial (refs.dependents m.Normal_map)).count > 0 do (for n in arr do n.texmap_bump = NMap)
			)
		)
	)	
)
createDialog vrnRoll style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

Comment viewing options

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