3dsMax2022->GLTF Material Custom Attributes Not Exported

Hi,

I’m using 3dsmax 2022 and I have an object with a material that has a custom attribute. The custom attribute is shown in the image below.

When I try to export this scene as a GLTF I don’t get any “extras” in the resulting GLTF file. I can see that its reaching the point of attempting to export custom attributes but to no avail.The output log is shown in the image below.

The image below shows the same material as it appears in the resulting GLTF file. I’m expecting an “extras” field containing an “is_decal” boolean.


(Sorry, I put all images into one image because it won’t let me post more than one)

Any ideas on what I’m doing wrong?

Thanks!

Adding @Guillaume_Pelletier

I decided to use fbx instead of gltf but I did track down the issue with the babylon exporter. I’ll post the fix here to help anyone with the same issue or if the dev team wants to add the gist of it to the official github repo.

The issue is babylon doesn’t handle multi materials. The fix is to detect what kind of material it is and handle accordingly. Here is an example of how that could be done:

fn process_material mat &s = 
(
    for objDef in (custAttributes.getDefs mat) do
    (
        --s = s + mat.name
        pbArray = custAttributes.getPBlockDefs objdef
        for indexPBlock = 1 to pbArray.count do
        (
            itms = pbArray[indexPBlock]
            for y = 5 to itms.Count do
            (
                s = s + "_$€PParam_" + itms[y][1]
                for z = 1 to itms[y][2].Count by 2 do
                (
                    key = itms[y][2][z] as string
                    if (findString key "type") != undefined then
                    (
                        s = s + "_$€PType_" + itms[y][2][z+1]
                    )
                )
            )
        )
    )
)

/*material_data = sceneMaterials["StandardMat_0"]*/
material_data = sceneMaterials["MultiMat_0"]; /*In the github repo this is fed in as a variable*/

s = ""
if getNumSubMtls(material_data) == 0 then
    process_material material_data &s
else
    for mat in material_data do
    (
        process_material mat &s
    )
print(s)
2 Likes

I realized today that my solution above only applies to my heavily modified version of the exporter where the multimaterial (instead of the submaterial) is the object that is attempted to be extracted in “ExportExtraAttributes()” of BabylonExporter.CustomAttributes.cs.

Here is the same idea for use in the original BabylonExporter.CustomAttributes.cs:

string cmd = @"objectName = """ + objectName + "\"\r\n" +

                        @"if(obj == undefined) then
                        (
                            notfound = true
                            for i = 1 to sceneMaterials.count while notfound do
                            (
                                if classOf sceneMaterials[i] == MultiMaterial then
                                (
                                    for j = 1 to sceneMaterials[i].numsubs while notfound do
                                    (
                                        if sceneMaterials[i].material[j].name == objectName then
                                        (
                                            obj = sceneMaterials[i].material[j]
                                            notfound = false
                                        )
                                    )
                                )
                            )
                        )

                        s = """"

                        for objDef in (custAttributes.getDefs obj) do
                        (
                            pbArray = custAttributes.getPBlockDefs objdef
                            for indexPBlock = 1 to pbArray.count do
                            (
                                itms = pbArray[indexPBlock]
                                for y = 5 to itms.Count do
                                (
                                     s = s + ""_$€PParam_"" + itms[y][1]
                                    for z = 1 to itms[y][2].Count by 2 do
                                    (
                                        key = itms[y][2][z] as string
                                        if (findString key ""type"") != undefined then
                                        (
                                            s = s + ""_$€PType_"" + itms[y][2][z + 1]
                                        )
                                    )
                                )
                            )
                        )

                        s";

You will also have to modify _ExportExtraAttributes() to take in the objectName (e.g. “gameMaterial.MaterialName” for the gameMaterial overload or “” for the gameNode overload).

1 Like