How to export metallicFactor using Maxscript with Custom Attributes

Hello!

What I want to do is to export from 3ds Max as a gltf with custom values of the metallicFactor.

What I do is to add Custom Attribute to Physical material in 3ds Max and to use this CA to set the Metallic value of the material.

This is the code that I use:

(
	-- Create Babylon material attributes
	CAT_DEF1 = attributes Babylon_Attributes
	(
		Parameters main rollout:params
		(
			metallicFactor Type:#float UI:metallicFactor default:0.7
-- 			babylonAlphaTest Type:#BOOLEAN UI:babylonAlphaTest Default:False
-- 			babylonAlphaTestPercent Type:#FLOAT UI:babylonAlphaTestPercent Default:0.50
		)
		Rollout Params "Babylon Attributes"
		(
-- 			checkbox babylonUnlit "Unlit" Width:70 Height:15 Align:#Left Offset:[0,0] Type:#BOOLEAN
-- 			checkbox babylonAlphaTest "Alpha Test" Width:70 Height:15 Align:#Left Offset:[0,0] Type:#BOOLEAN
			spinner metallicFactor "Metallic" width:140 height:15 align:#Left offset:[0,0] type:#FLOAT Range:[0.0,1.0, 0]
		)
	)
	
	for mat in scenematerials do
	(
		print ("Adding attributes to " + mat.name)
		defs = custAttributes.getDefs mat;
		if defs != undefined then
		(
			--Check if babylon material attributes are present
			alreadyAdded = false;
			for def in defs do
			(
				format "def.name: % \n" def.name
				-- if attribute already exists, update the definition to use this version.
				if def.name == #Babylon_Attributes then
				(
					alreadyAdded = true;
					CustAttributes.redefine def CAT_DEF1.source
				)
			)
			
			-- Add babylon material attributes if not present
			if alreadyAdded == false then
			(
				CustAttributes.add mat CAT_DEF1;
			)
		)
		else
		(
			CustAttributes.add mat CAT_DEF1;
		)
	)
)

The metallicFactor has to be the proper parameter to be set to desired value.

If I have an object in the scene with Physical material applied and I run the code above the CA is created and when I open the Material Editor I can see the “Metallic” spinner and I can change its value. If I select the object and then execute:

selection[1].material.metallicfactor

in the MaxScript Listener is printed the current value.

But, when I export as gltf, using the default Babylon Exporter or my custom exporter the Metallic slider(under Metaillc Workflow group of controls) always shows 1.0. The value of the spinner in the Material Editor is not exported as a valid parameter and in my browser Babylon.

I just saw that there is thread, posted 3h ago, with almost the same question. :slight_smile:

pinging @Guillaume_Pelletier

Hi. If you use bitmap for metallic rough your metallic or rough factor ignore and always export as 1 and i think this is correct because you drive this parameter through you bitmap pixel value. How to export 3DS MAX scene as glTF | Babylon.js Documentation
Like for base color and transparency, the basic parameter value is used as default value when binded map is not provided. So you can export this values only if you not use bitmap.

Actually, with no metallic map in use and with metallness set to 0, the exporter still creates a ORM texture with the Blue channel filled with black and the metallicfactor set to 1.

If no metallic map is used and Metallness is set to 0.5, the Metallic in Babylon viewer is 1.0.
If no metallic map is used, Metallness is set to 0.5, Custom Attributes is added to the material and the metallicFactor(with CA) is set to 0.5, the Metallic in Babylon viewer is 1.0.

the Max2020 last exporter version work correctly using


give

with the following gltf file

“materials”: [{
“pbrMetallicRoughness”: {
“baseColorTexture”: {
“index”: 0,
“extensions”: {
“KHR_texture_transform”: {
“offset”: [0.0, 0.0],
“scale”: [1.0, 1.0],
“texCoord”: 0
}
}
},
“metallicFactor”: 0.0,
“roughnessFactor”: 0.0
},
“alphaMode”: “BLEND”,
“name”: “Building”
}],

Hmm, if I have a texture in roughness and an ao-texture in diffuse roughness, but no metallic texture and metallness set to zero, it exports a complete ORM with black in blue channel and metallicfactor set to 1. That could be ok but the problem with this approach is that during jpeg-compression we get a blue channel with noise due to compression. A workaround would be to leave a noisy blue channel but force metallicfactor to 0.

if you provide the BOTH map as png, then ORM texture will be PNG so no compression artifat. If any of the map is Jpg or any other loseless format, then the orm will be jpeg.
I’m agree that we must always put the correct value into blue channel. If you found this is not the case, please open an issue with reproductible scene.
Thanks for the input, team work is always better.

1 Like

I think it will be hard to use jpeg without compression spilling over from green channel (roughness) to the blue channel (metallness). However, if one could simply force metallicfactor=0 at export, the blue channel (black but with unwanted jpeg artifacts) would be ignored and the result better.

1 Like