Author Topic: Maxscript shenanigans  (Read 1197 times)

2022-04-13, 03:42:34

CarlosMiguelKlein

  • Active Users
  • **
  • Posts: 10
    • View Profile
hey there folks, I'm looking for a way to create a script that changes Corona Physical Mtl to Standart Mtl, as it's better for some FBX exportations, well, the thing is I managed to adapt and old script to work with Corona Legacy, and it was very easy considering it has a Diffuse color, but Physical has a Color Base, and I don't know how to transcribe that to max scripting language, I want the Diffuse map from Physical Mtl to go to Diffuse map in Standart Mtl.
The script is like that at the moment:

fn convertCoronaPhysicalMtlToStandard mat =
(
   -- Make new Standard mat, with original's diffuse map
   newMat = Standardmaterial mapMO:mat.texmapBase
   newMat.name = mat.name
   
   -- diffuse
newMat.diffuse=mat.colorBase
newMat.diffuseMap=mat.texmapBase
newMat.diffuseMapEnable=mat.texmapOnbase
newMat.diffuseMapAmount=mat.levelBase


-- opacity
newMat.opacityMap=mat.texmapOpacity
newMat.opacityMapEnable=mat.texmapOnOpacity
newMat.opacityMapAmount=mat.levelOpacity

--bump map
newMat.bumpMap=mat.texmapbump
newMat.bumpMapEnable=mat.texmapOnBump

   showTextureMap newMat on
      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
            if (classof submat == CoronamPhysicalMtl) then
            (
               replaceinstances submat (convertCoronaPhysicalMtlToStandard submat)
            )
         )
      )

      else if (classof mat == CoronaPhysicalmtl) then
      (
         -- Regular, non-multi material
         replaceinstances mat (convertCoronaPhysicalMtlToStandard mat)
      )
   )
)



Right at the start where newmat=standartmaterial I CANNOT fing a way to change the mapMO: mat.textmapBase and --diffuse stuff to the correct name, anyone knows what to put in there to make this work?
Thanks a bunch.

2022-04-13, 09:48:33
Reply #1

Frood

  • Active Users
  • **
  • Posts: 2002
    • View Profile
    • Rakete GmbH
Just try

Code: [Select]
test=CoronaPhysicalMtl name:"TestMaterial"
showproperties test

in the console to get a list of all properties. So for diffuse:

Code: [Select]
newMat.diffuse=mat.baseColor
newMat.diffuseMap=mat.baseTexmap
newMat.diffuseMapEnable=mat.baseTexmapOn
newMat.diffuseMapAmount=mat.baseLevel

And I think you have to multiply baseLevel by 100 because it goes to diffuseMapAmount of a standard material which is 0-100. ("baseMapAmount" would be the corresponding property actually, that one in the "Maps" section of a material while "baseLevel" is the spinner value next to the colour swatch).


Good Luck



Never underestimate the power of a well placed level one spell.