How to access Babylon material attributes in Maxscript

I use a maxscript to export my scenes into glTF and I was wondering how I can access the Babylon material attributes. I can see them and set using the GUI but I don’t know how set them in Maxscript.
I am using maxScriptManager = dotNetObject “Max2Babylon.MaxScriptManager” to access the exporter.

Pinging el Maestro @Drigax

I’m not totally sure, we have an obsolete material initialization script here (Since then we moved to a automated workflow for initializing these custom parameters):

since then attributes have been changed to:
babylonUnlit
babylonTransparencyMode (0 for opaque, 1 for AlphaTest, 2 for AlphaBlend)
babylonMaxSimultaneousLights

I’ll do some messing around in Maxscript to make a definitive guide

@Matt_Mackowski

Here’s a quick sample script to access the values.

function decodeBabylonTransparencyMode value =
(
	if value == 0 do return "Opaque"
	if value == 1 do return "Cutoff"
	if value == 2 do return "Blend"
	return "Unknown"
)

function printBabylonMaterialAttributes mat =
(
	materialType = (classOf mat) as string
	if (materialType == "ai_standard_surface" or materialType == "Standardmaterial" or materialType == "Physicalmaterial" ) then (
		print ("Printing Babylon Attributes for selected material " + mat.Name) 
		print ("Unlit: " + (mat.babylonUnlit as string)) 
		print ("MaxSimultaneousLights: " + (mat.babylonMaxSimultaneousLights as string))
		print ("TransparencyMode: " + (mat.babylonTransparencyMode as string) + " - " + (decodeBabylonTransparencyMode mat.babylonTransparencyMode))
	) else (
		print "Material type does not use babylon custom attributes: "
		print (classOf mat)
	)
)

objMats = for obj in selection where \
	obj.mat != undefined collect obj.mat

maxIndex = objMats.count
for i = 1 to maxIndex do (
	printBabylonMaterialAttributes objMats[i]
)
2 Likes