Search code examples
3dsmaxmaxscript

Add texture with output modifier to material with MaxScript


I have a scene with a texture connected to an Output modifier then connected to the Diffuse slot of a material (CoronaMtl).

I need to loop thru multiple textures inside a folder, assign them to the material (which is assigned to an object), render it, and save the image.

Everything is working, but the Output modifier that I just can't understand how to apply. My current script already search for the files, creates the array, apply the texture to the right material, render and saves, but, without the Output adjustments, it's all pointless.

Anybody can shine a light on it?

Here's my material: https://i.sstatic.net/AZe1r.png

And here's the script so far:

carMake = "Chevy" -- Case Sensitive

liveriesFiles = "C:\\Path\\PaintSchemes\\" + carMake as string + "\\PAINT_*_PRIMARY.png"
glossFiles = "C:\\Path\\PaintSchemes\\" + carMake as string + "\\PAINT_*_PRIMARY_MAT_ID.png"

liveries = getFiles liveriesFiles
gloss = getFiles glossFiles

for livery in liveries do ( 
    sceneMaterials["CHEVY"].texmapDiffuse = Bitmaptexture fileName: livery      
    index = findItem liveries livery

    sceneMaterials["CHEVY"].texmapReflectGlossiness = Bitmaptexture fileName: gloss[index]

    CoronaRenderer.CoronaFp.showvfb true
    actionMan.executeAction 0 "50031" -- Render

    splitString = filterString livery "\ ."
    elementName = replace splitString[12] 1 6 ""

    savePath = "C:\\Path\\PaintSchemes\\" + carMake as string + "\\renders\\" + elementName as string + ".png"  
    CoronaRenderer.CoronaFp.saveAllElements savePath
)

Solution

  • To create an Output texture use outputTex = Output map1:bitmapTex where bitmapTex is a variable holding the BitmapTexture you wish to assign. The Output properties of the Output texture map (double usage of the term might be confusing here) will be in outputTex.output.

    You can inspect the available properties using showproperties outputTex and showproperties outputTex.output. Setting the invert and clamp checkboxes is done via outputTex.output.clamp = true and outputTex.output.invert = true for example. Another point, you can preface a string constant with @ to indicate a literal path string which ignores escape characters, or, use / as a replacement for \ in MaxScript path strings.

    Note - you cannot create a color curve for the Output texture map if one does not already exist. The curve is only createable through the UI by clicking "Enable Color Map". This is a limitation of MaxScript. However, the limitation could be worked around via C++ (more details on request).

    Using Standard material instead of CoronaMtl and Corona renderer, here's an example script:

    -- See available properties the Output map, assuming on the Diffuse slot of Standard material
    showproperties (sceneMaterials["CHEVY"].diffusemap)
    showproperties (sceneMaterials["CHEVY"].diffusemap.output)
    
    -- Run the test
    carMake = "Chevy" -- Case Sensitive
    rootPath = @"D:\Temp\PaintSchemes" + carMake as string + @"\"
    liveriesFiles = rootPath + @"Test_Map*A.png"
    glossFiles = rootPath + @"Test_Map*B.png"
    
    liveries = getFiles liveriesFiles
    gloss = getFiles glossFiles
    
    for livery in liveries do ( 
        bitmap1 = Bitmaptexture fileName: livery      
        output1 = Output map1:bitmap1
        output1.output.clamp = true
        sceneMaterials["CHEVY"].diffuseMap = output1
    
        index = findItem liveries livery
        bitmap2 = Bitmaptexture fileName: gloss[index]      
        output2 = Output map1:bitmap2
        output2.output.invert = true
        sceneMaterials["CHEVY"].glossinessMap = output2
    
        max quick render
    
        splitString = filterString livery "\ ."
        elementName = splitString[4]
    
        r = getLastRenderedImage()
        r.filename = rootPath + @"\renders\" + elementName as string + ".png"  
        save r
    )