Notifications
Clear all

[Closed] Material Conversion with MaxScript

Hi

 I found a script a long time ago to convert Arch & Design materials to Standard materials, posted below (I've tweaked it slightly for my own purposes, but I did not write the original - credit to the creator).
 
 But what I'm trying to do now is the opposite. That is, Standard to Arch & Design. Unfortunately my scripting knowledge ends at very minor tweaks, so I've been unable to reverse the process of the original script - I tried a few obvious things, but it didn't work out (also posted below).

Could anyone fill me in on how to achieve this? Thanks!
(sorry for the formating of the code – the ‘tab spacing’ is really large for some reason)

 The original Arch to Standard:
fn convertArchToStandard mat =
    (
    	-- Make new Standard mat, with original's diffuse map
    	newMat = Standard diffuseMap:mat.mapM0
    	newMat.name = mat.name
    	newMat.diffuse = mat.diff_color
    	showTextureMap newMat on
    	newMat.specularLevel = 30
    	newMat.glossiness = 20
    	return newMat
    )
    
    -- Loop through all objects, checking material on each
    for obj in geometry do
    (
    	mat = obj.material
    
    	if (mat != undefined) then 
    		(
    		if (classof mat == Multimaterial) then 
    			(
    			-- This is a multi-sub material, so loop through all submaterials
    			for i in mat.materialIdList do 
    				(
    				submat = mat[i]
    				if (classof submat == Arch___Design__mi) then 
    					(
    					mat[i] = convertArchToStandard submat
    					)
    				)
    			)
    
    	else if (classof mat == Arch___Design__mi) then
    		(
    		-- Regular, non-multi material
    		obj.material = convertArchToStandard mat
    		)
    	)
    )
 My failed Standard to Arch
fn convertStandardToArch mat =
    (
    	-- Make new Arch mat, with original's diffuse map
    	newMat = Arch___Design__mi diffuseMap:mat.mapM0
    	newMat.name = mat.name
    	newMat.diffuse = mat.diff_color
    	showTextureMap newMat on
    	newMat.refl_weight = 0.6
	newMat.refl_gloss = 0.5
    	return newMat
    )
    
    -- Loop through all objects, checking material on each
    for obj in geometry do
    (
    	mat = obj.material
    
    	if (mat != undefined) then 
    		(
    		if (classof mat == Multimaterial) then 
    			(
    			-- This is a multi-sub material, so loop through all submaterials
    			for i in mat.materialIdList do 
    				(
    				submat = mat[i]
    				if (classof submat == Standard) then 
    					(
    					mat[i] = convertStandardToArch submat
    					)
    				)
    			)
    
    	else if (classof mat == Standard) then
    		(
    		-- Regular, non-multi material
    		obj.material = convertStandardToArch mat
    		)
    	)
    )
7 Replies

i think these 2 lines in convertStandardToArch

newMat = Arch___Design__mi diffuseMap:mat.mapM0
...
newMat.diffuse = mat.diff_color

should be

newMat = Arch___Design__mi mapM0:mat.diffuseMap 
...
newMat.diff_color = mat.diffuse
 lo1

in general, you can see the properties of any material by using the showproperties command.
for example:

showproperties (standardmaterial())

@ caibird: thank you, works great with 1 exception. For some reason if I have 1 Standard Material on 10 different objects, when I run the script it creates 10 different Arch&Design (all with the same name and properties). This seems really weird to me – double checked that its just 1 Standard Mat applied to all 10 objects, so I’m not sure why it would be duplicating the Mat when converted.

@lo: ah yes, I forgot about that – been so long since I’ve done any scripting, thanks for reminding me.

2 Replies
(@pixel_monkey)
Joined: 11 months ago

Posts: 0

That is because you are looping through the geometry and changing those materials. You would need to use something like what denisT provided here, which will change the material in the scenematerials array, or code like this:

replaceinstance object.material (convertStandardToArch object.material)

Which should replace all instances of the material, rather than telling it to change the material of that specific object.

-Eric

(@noisymonk)
Joined: 11 months ago

Posts: 0

That makes sense, unfortuately I’m not really sure how to implement this code. Like I said before, my scripting skills are pretty weak >_<

Could you explain it abit more? Thanks in advance!

This should do what you need:

fn convertStandardToArch mat =
(
	-- Make new Arch mat, with original's diffuse map
	newMat = Arch___Design__mi mapMO:mat.diffuseMap
	newMat.name = mat.name
	newMat.diff_color = mat.diffuse
	showTextureMap newMat on
	newMat.refl_weight = 0.6
	newMat.refl_gloss = 0.5
	return newMat
)
-- Loop through all objects, checking material on each
for obj in geometry do
(
	mat = obj.material

	if (mat != undefined) then 
	(
		if (classof mat == Multimaterial) then 
		(
			-- This is a multi-sub material, so loop through all submaterials
			for i in mat.materialIdList do 
			(
				submat = mat[i]
				if (classof submat == Standard) then 
				(
					replaceinstances submat (convertStandardToArch submat)
				)
			)
		)

		else if (classof mat == Standard) then
		(
			-- Regular, non-multi material
			replaceinstances mat (convertStandardToArch mat)
		)
	)
)

Hope that helps,
-Eric

here is my version:


    fn convertAllStandardMaterials = 
    (
    	fn standardToArch mat = 
    	(
    		new = Arch___Design__mi name:mat.name
    		/*
    			do with new Arch material whatever you want
    			...
    		*/
    		new
    	)
   
    	for mat in (getclassinstances Standard) do replaceinstances mat (standardToArch mat)
    )
    

that should be enough…