Import normalmaps in slate material editor bases on bitmap file location

Import normalmaps in slate material editor bases on bitmap file location

peterv42
Participant Participant
2,621 Views
8 Replies
Message 1 of 9

Import normalmaps in slate material editor bases on bitmap file location

peterv42
Participant
Participant

Hello,

 

This is the last step in automating a workflow i use the confert FBX to a 3th party format.

 

In this stage I am in the slate material editor and I have materials with a linked diffuse bitmap. 

I want to inport a normal/bump map on al materials based on the folder of the diffuse map.

for the right filename of the normal map i have this:

NormalMapName = (getFilenamePath file + getFilenameFile file + "_n" + getFilenameType file)

sceneMaterials["naam_opaque"].bumpMap = Bitmaptexture fileName:NormalMapName

I found how i can read the Bitmaptexture name

bMaps = getClassInstances Bitmaptexture

but i need the bitmap folderlocation.

 

I hope that sameone can help me with this.

 

Greeting Peter

 

0 Likes
Accepted solutions (1)
2,622 Views
8 Replies
Replies (8)
Message 2 of 9

peterv42
Participant
Participant

I now have this:

mMaps = getClassInstances bitmaptexture

--itterate all bitmaps
for m in mMaps do
(
	print(m)
	pName = getFilenamePath m.filename
	fName = getFileNameFile m.filename
	fExt = getFileNameType m.filename
	NormalMapName = (pName + fName + "_n" + fExt)
	--rename bitmapName
	m.Name = newPath+fName+fExt
	--rename/set location
	m.filename = newPath+fName+fExt
	sceneMaterials["naam_keyed_test"].bumpMap = Bitmaptexture fileName:(NormalMapName)
)

This script places a bitmap with the correct filename and connects it to the bumpmap but of cource only on the "naam_keyd_test" material. 

how do i make it that it will put it on all materials?

 

This did not do the trick:

sceneMaterials[m].bumpMap = Bitmaptexture fileName:(NormalMapName)

 

Greetings Peter

0 Likes
Message 3 of 9

denisT.MaxDoctor
Advisor
Advisor

It seems to me that you are not quite accurate in formulating the problem ... judging by the code I see above:

Do you want to set the material's Normal bitmap using the same material's Diffuse bitmap information (filename)?

 

0 Likes
Message 4 of 9

peterv42
Participant
Participant

Sorry for not explaining it correctly.

 

Do you want to set the material's Normal bitmap using the same material's Diffuse bitmap information (filename)?

Yes this is what i am trying. I found how to itterate over the materials

mMaps = getClassInstances bitmaptexture

--itterate all materials
for mat in scenematerials do
(
   print(mat) 
)

--itterate all bitmaps
	for m in mMaps do
		(
			pName = getFilenamePath m.filename
			fName = getFileNameFile m.filename
			fExt = getFileNameType m.filename
			NormalMapName = (pName + fName + "_n" + fExt)
			sceneMaterials[mat].bumpMap = Bitmaptexture fileName:NormalMapName
		)

now i think i need to first itterate the material and then the textures. i tried same variation but got errors as a result.

 

hope you can help with the last stap.

 

Greetings Peter

 

0 Likes
Message 5 of 9

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

how to collect materials you already know... 

here is how to replace Bump Map bitmaptexture based on Diffuse Map texture filename:

 

fn makeSpecialName filename postfix:"" tag: =
(
	path = getfilenamepath filename
	file = getfilenamefile filename
	type = getfilenametype filename
	
	if iskindof tag String then
	(
		if matchpattern file pattern:("*" + tag) do 
			file = replace file (file.count - tag.count + 1) tag.count postfix 
	)
	else file += postfix
	
	path + file + type
)

fn xchangeBumpTextures mats: = 
(
	for mat in mats where isproperty mat #diffuseMap and isproperty mat #bumpMap do
	(
		dtex = getproperty mat #diffuseMap
		if iskindof dtex Bitmaptexture and iskindof dtex.filename String do
		(
			file = makeSpecialName dtex.filename postfix:"_n"
			btex = Bitmaptexture filename:file 
			setproperty mat #bumpMap btex 
		)
	)
)

/* using:  for example for all medit materials >>
xchangeBumpTextures mats:meditmaterials
*/

 

 

when you make the new filename you have two options:
1. replace old tag (for example, filename: small_table_c.jpg and where tag is "_c") with new postfix

2. just add a new postix to filename

  

Message 6 of 9

peterv42
Participant
Participant

Hello,

 

Again thank you for your time. It could by i do not understand your script or I explained my goal not good enough.

I do not want to replace myBump map. I only have meterials (more then 1) and on all of them I only have a Diffuse color texture (see screenshot 1)

screenshot1.png

In my sceneassets/images folder I have the diffuse texture "ker_pichlavej_3_ca.tga" and the BumpMap texture "ker_pichlavej_3_ca_n.tga" for all my scenes and there materials.

 

the result must be as in screenshot 2

screenshot2.png

Greetings Peter

 

 

 

0 Likes
Message 7 of 9

denisT.MaxDoctor
Advisor
Advisor

it's exactly what my last code does do... 

xchangeBumpTextures mats:(sme_getSelectedMaterials())
Message 8 of 9

peterv42
Participant
Participant

Hello dennisT,

 

Your last hint did the trick. I was trying to get it to work on the code below becouse I wrote about it in the beginning of the mail.

mMaps = getClassInstances bitmaptexture

for mat in scenematerials do
(
   print(mat) 
)

But you were pointing to a other mail correspondens we we had about naming material with script.

So for who did not see that other mail or like me who do not get the hint the below total script.

With this script you need to select your material in the 'slate material editor' and it will place a Bumpmap bases on the name of your Diffusemap. 

 

fn makeSpecialName filename postfix:"" tag: =
(
	path = getfilenamepath filename
	file = getfilenamefile filename
	type = getfilenametype filename
	
	if iskindof tag String then
	(
		if matchpattern file pattern:("*" + tag) do 
			file = replace file (file.count - tag.count + 1) tag.count postfix 
	)
	else file += postfix
	
	path + file + type
)

fn xchangeBumpTextures mats: = 
(
	for mat in mats where isproperty mat #diffuseMap and isproperty mat #bumpMap do
	(
		dtex = getproperty mat #diffuseMap
		if iskindof dtex Bitmaptexture and iskindof dtex.filename String do
		(
			file = makeSpecialName dtex.filename postfix:"_n"
			btex = Bitmaptexture filename:file 
			setproperty mat #bumpMap btex 
		)
	)
)

fn sme_getSelectedMaterials view: = 
(
	if view == unsupplied do view = sme.getview sme.activeview

	tv = trackviewnodes[#sme]
	vsub = tv[view.name]
	for k=1 to vsub.numsubs collect
	(
		sub = vsub[k]
		ref = sub.reference
		node = view.getnodebyref ref
		if node.selected and iskindof ref Material then ref else dontcollect
	)
)

xchangeBumpTextures mats:(sme_getSelectedMaterials())

 

@denisT.MaxDoctor thank you for your help hints and patience

0 Likes
Message 9 of 9

peterv42
Participant
Participant

It has been some time since I last used this script but It looks like this script is not working anymore in 3dsMax version 2020. Does anyone know if the Max version could be the problem?

 

Greetings,

Peter

0 Likes