[Closed] Automatic material type conversion
I’m trying to come up with a process for taking a scene (from Revit through FBX format) and exporting it to vr4max for display. The main problem is that it’s using Arch&Design materials, which vr4max doesn’t support. So what I’d like to do is make a script that will go through the scene and convert all the used materials to standard materials with the same diffuse map. I don’t particularly care about other aspects of the materials (except perhaps opacity), since vr4max isn’t nearly as realistic as a render, but going though every scene and doing this manually is quite time consuming and isn’t feasible.
I’ve never used maxscript before (I do have other scripting experience), and although I’m starting to grasp the basics of maxscript, I still have no idea how to go about this. Can anyone lend me a hand?
Thanks!
EDIT: Using 3ds Max Design 2009, if that matters at all
Anyone? I’m thinking the process would involve pulling the diffuse map off of one material, creating a new (standard) one with the same diffuse, then selecting by material and applying the new one. Iterate that through all of the materials in the scene and it’s done.
Problem is, I have no idea how to write it. Any help would be greatly appreciated.
As far as I can tell, there’s no way to change the type of a material once it’s created, but if I’m mistaken there please correct me. That would make this much easier.
I’ve got a little script that does it, It works for diffuse and cutout channels, but you could remove the cutout/opacitymap lines if you dont want those:
for i in $ do
(
diff = i.material.mapm0
op = i.material.cutoutmap
mat = standardmaterial()
mat.diffusemap = diff
mat.opacitymap = op
i.material = mat
)
this one transfers just the diffuse map:
for i in $ do
(
diff = i.material.mapm0
mat = standardmaterial()
mat.diffusemap = diff
i.material = mat
)
it works on whatever objects you have selected (it will probably bum out if you have 2 objects with the same material)
Here’s another take. Works on any Arch materials inside Multi/Sub-Object Materials as well. Runs on all geometry objects in scene, but you could replace “geometry” with “selection” to limit it to that if you wish.
fn convertArchToStandard mat = (
-- Make new Standard mat, with original's diffuse map
newMat = Standard diffuseMap:mat.diffuseMap
newMat.name = mat.name
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 == Architectural) then (
mat[i] = convertArchToStandard submat
)
)
) else if (classof mat == Architectural) then (
-- Regular, non-multi material
obj.material = convertArchToStandard mat
)
)
)
Good idea with the multi-sub loop, I just edited it to work with the mentalray Arch & Design shader rather then the max Architectural
fn convertArchToStandard mat =
(
-- Make new Standard mat, with original's diffuse map
newMat = Standard diffuseMap:mat.mapM0
newMat.name = mat.name
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
)
)
)
Thanks for the help! Unfortunately, I can’t seem to make it work. I saved the script and ran it, but the scene materials still list everything as being a ProMaterial. Am I missing something obvious?
I don’t have 3ds Max Design, so I don’t have the exact material type you’re converting from. The class name is probably just wrong in the script. Do this:
[ol]
[li]Select an object that has ProMaterial on it[/li][li]In the MXS Listener, type “classof $.material”[/li][li]Replace “Architectural” in the classof if’s above with whatever #2 printed out[/li][/ol]
There doesn’t seem to be a single type. The countertop (I’m experimenting on a simple kitchen model) gives “Simple_Mtl_Hardwood_adsk”, the walls are “Simple_Mtl_Generic_adsk”, and the sink is “Simple_Mtl_Metal_adsk”. There are a few others that I didn’t check.
If this is a problem for identifying which materials are Arch & Design, would it be possible to just convert every material instead?
I’m not sure. I think you’re into some stuff specific to the Design app. Although the ones you listed look more like material instance names than typical Max material class names.
I think it’s more specific to the new FBX importer than the design app, although for all I know that’s only in max design. How would you do a script that just converts all materials, regardless of what type they are? What effect would the fact they they seem to be instances have?
Once again, sorry for my noobness. I’d barely used Max at all (except some really basic stuff) until this summer.