How to differenciate bump map / normal map in the bump slot

Hello everyone,

I am trying to convert a vray material into a standard material, and I have a problem to write this algorithm in MAXScript :

if (the bump map slot is not empty) do
(if (the slot contains a normal map) do (normal map goes to bump slot of the standard material)
else (bump map goes to bump slot of the standard material))

Probably I'm wrong, but the problem is that i don't know how to differentiate the 3 possible choices.

This is my actual code which is wrong :

for o in geometry do 
(
if classof o.material == VRayMtl do 
	(
		newmtl = Standardmaterial ()	
		if (o.material.texmap_bump != undefined) do
		(
			if o.material.texmap_bump.normal_map.filename != undefined then
			(
				newmtl.bumpMap.FileName =  o.material.texmap_bump.normal_map.filename
				newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
			)
			else
			(
				newmtl.bumpMap.FileName = o.material.texmap_bump.filename
				newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
				)
			)
		o.material = newmtl		
	)
)

Thank you.

AttachmentSize
preview.jpg12.95 KB

Comments

Comment viewing options

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

I found the real problem.Do

I found the real problem.

Do you know how to test if inside the Normal Map there is a map ?

Your script doesn't contain this case.
In your script, even if you remove or not the line "obj.material.texmap_bump.normal_map.filename != undefined", the VrayNormalMap won't be converted to Normal Map with a material with a Normal Map with no map inside.

In my script if I add the line "o.material.texmap_bump.normal_map.filename != undefined" as a condition, and if I have just a bump map in my material, I will have this error "Unknown property: "filename" in undefined".

I will be grateful if you can solve this problem.

if (isKindOf o.material.texmap_bump Bitmaptex) or (isKindOf o.material.texmap_bump Normal_Bump) do
(
	if (classof o.material.texmap_bump == Normal_Bump) then
	(
	newmtl.bumpMap.FileName =  o.material.texmap_bump.normal_map.filename
	newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
	)
	else
	(
	newmtl.bumpMap.FileName = o.material.texmap_bump.filename
	newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
	)
)

Rodman

barigazy's picture

if you want to test if

if you want to test if "NormalBump" have "mormal_map" use this

if isKindOf (o.material.bumpMap) Normal_Bump do
(
	local nmap = o.material.bumpMap
	if nmap.normal_map != undefined then "Have Map" else "Don't Have Map "
)

For your code not need to twice check NormalMap, try this

nMap = o.material.texmap_bump
if nMap != undefined and (isKindOf nMap Bitmaptex or isKindOf nMapNormal_Bump) do
(
	newmtl.bumpMap =  nMap.normal_map
	newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
)

bga

Rodman's picture

Thank you ! I've used both of

Thank you ! I've used both of your codes to integrate it with mine. I understand how it works now.

Rodman

barigazy's picture

fine.now you can continue

fine.now you can continue with the rest of script.
cheers!

bga

Rodman's picture

I have a new problem. I want

I have a new problem.

I want to add the case where the bump map slot contains a checker (for example)

First I transform the checker into a Bitmap inside a path name ThePath
But after this I cant insert this Bitmap inside the new bump slot of my Standardmaterial

I have this :

for o in geometry do 
(
if classof o.material == VRayMtl do 
	(
 
		newmtl = Standardmaterial ()
		newmtl.diffuse = o.material.diffuse
 
		if o.material.texmap_bump != undefined do
		(
			if isKindOf o.material.texmap_bump Checker then
			(
				fileNameImg = (
					getFilenamePath ThePath + \
					getFilenameFile ThePath + \
					getFilenameType ThePath
					)
 
				rm = renderMap o.material.texmap_refraction \ 
				size:[1024,1024] \
				fileName:fileNameImg \
				filter:true \
				save rm
				close rm
 
				o.material.texmap_bump = Bitmaptexture fileName:fileNameImg	
 
				newmtl.bumpMap.FileName = o.material.texmap_bump.filename
				newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
			)
			else
			(
				newmtl.bumpMap.FileName = o.material.texmap_bump.filename
				newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
			)
		)
 
		o.material = newmtl		
	)
)

And this error : Unknown property: "filename" in undefined

I don't know how to say that o.material.texmap_bump is not checker but Bitmap.

I need your help.

Rodman

barigazy's picture

This is your code

Don't use any more ".FileName" property to assigne bitmap.
You have more then this problem in your code.
Compare my code and your and you;ll see what i mean.

for o in geometry where not isKindOf o targetObject and classof o.material == VRayMtl do 
(
	newmtl = Standardmaterial diffuseMap:(o.material.texmap_diffuse)
	if o.material.texmap_bump != undefined do
	(
		if not (isKindOf o.material.texmap_bump Bitmaptexture) then
		(
			-- add your path (this is only for testing)
			fileNameImg = @"C:\temp\testMap.jpg"
 
			rm = renderMap o.material.texmap_bump \ 
			size:[1024,1024] \
			fileName:fileNameImg \
			filter:true \
			save rm
			close rm
 
			o.material.texmap_bump = Bitmaptexture bitmap:rm
 
			newmtl.bumpMap = o.material.texmap_bump
			newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
		)
		else
		(
			newmtl.bumpMap = o.material.texmap_bump
			newmtl.bumpMapAmount = o.material.texmap_bump_multiplier
		)
	)
	o.material = newmtl		
)

bga

Rodman's picture

Thank you very much. What

Thank you very much.

What does it mean this : "where not isKindOf o targetObject" ?

Rodman

barigazy's picture

Means that target objects

Means that target objects (camera, light target etc.) are
also geometry objects and should be isolated from for-loop
try this to see from yourself

a=targetobject()
superclassof a
--GeometryClass

bga

barigazy's picture
Rodman's picture

I saw it. But I didn't find

I saw it. But I didn't find any clue in it.

Rodman

Comment viewing options

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