How to use multi/sub object - "MultiMaterial" (3ds max)?

Hello there!

I have two questions. I’ve seen this sample source code here: https://www.babylonjs-playground.com/#2Q4S2S#0
The problem is I have to work with the vertex. I need the following workflow, see pic1.

  1. How to use multi / sub material from max? How to program/realize it? When I use this code:

BABYLON.SceneLoader.ImportMesh ("", “C: / Users / JohnyCage / Desktop /”, “teapot.babylon”, scene, function (newMeshes2, particleSystems2, skeletons2) {
var dude = newMeshes2 [0];

= I only get this result, see picture 2. Material is not correctly displayed., even partly invisible.

  1. How to apply onto part of my model =teapot = id =2, my own Babylon.js (not from 3ds max) material like this:

var plastic = new BABYLON.PBRMaterial (“plastic”, scenes);
plastic.reflectionTexture = hdrTexture;
plastic.microSurface = 0.96;
plastic.albedoColor = new BABYLON.Color3 (0.206, 0.94, 1);
plastic.reflectivityColor = new BABYLON.Color3 (0.003, 0.003, 0.003);
spherePlastic.material = plastic;

Pinging @PatrickRyan

Can you share your 3dsmax scene? This should work

Hello there,

(messgae: sorry new users cant upload attachments, nice forum)
file is stored here: http://lekarna-luhacovice.czechian.net/teapot-multi.rar.
I had also the second question :slight_smile:

Using the inspector, you may seen that your gltf exported mesh is divided into separate meshes during the import : one per material, and your object is handled as a TransformNode

So, if your mesh is named “wonderfullTeapot” in 3dsMax, and the material you want to replace “myGorgeousMtl”, you can detect the separate mesh like this, for example:


scene.getTransformNodeByName("wonderfullTeapot").getChildren().forEach(
    function(mesh){
        if(mesh.material.name === "myGorgeousMtl"){
            mesh.material = newMaterial;
        }
    }
);

https://www.babylonjs-playground.com/#4AJ16M#17

1 Like

Hello there,

thank you for reaction.

When I am trying use your code, like that:

        var metal = new BABYLON.PBRMaterial("metal", scene);
        metal.reflectionTexture = hdrTexture;
        metal.microSurface = 0.96;
        metal.reflectivityColor = new BABYLON.Color3(0.85, 0.85, 0.85);
        metal.albedoColor = new BABYLON.Color3(0.01, 0.01, 0.01);

        //load meshes
        BABYLON.SceneLoader.ImportMesh("", "C:/Users/JohnyCage/Desktop/", "teapot.gltf", scene, function (newMeshes2, particleSystems2, skeletons2) {
                dude2 = newMeshes2[0];

                scene.getTransformNodeByName("Teapot001").getChildren().forEach(
function(mesh){
    if(mesh.material.name === "Material #36"){
        mesh.material = metal;
    }
}

);

results are on the attached picture (Material #36 is detected inside babylon.js).

the post with the scene is pending approval.

Can you post the gltf somewhere on github and create a repro of your code on the playground? That should work so I just want to be sure we do not have a bug:)

I tried load any mesh model but it doesnt work. Help please.

https://www.babylonjs-playground.com/#UKNERM#61

here is a fix:
https://www.babylonjs-playground.com/#UKNERM#62
but you need to have the .bin side by side with the gltf (or use glb)

1 Like

I tried to use simplier glb format… but it does not work yet.

https://www.babylonjs-playground.com/#UKNERM#63
https://www.babylonjs-playground.com/#UKNERM#64

you have to use the raw.githuvusercontent link

https://www.babylonjs-playground.com/#UKNERM#65

(I will add this tip into this page soon : Available Meshes to Import - Babylon.js Documentation )

1 Like

Hello there, code is uploaded on the playghound:

https://www.babylonjs-playground.com/#8MGKWK#115

How to solve my problem, please?

Before going further, is your mesh inside 3dsmax cleaned? (transform, scale, xform especially) And don’t forget to disable backfaceCulling too, so as to be sure your normals are OK.
I see your mesh is an editable mesh, I’m not sure if the exporter take it well into account, but I’m sure that Autodesk doesn’t update this since many, many years. Prefer using editable poly instead for your safety.

1 Like

I tested collapse stack in 3ds max, also export from editable poly - not edit mesh…, also I tested only simple box for exporting but result is the same like you can see on the pictures up…

I cleaned a bit your importMeshes function : https://www.babylonjs-playground.com/#8MGKWK#116
Note that I had to change material sideOrientation.

There was a little mess with a metal material var I think, but actually your last playground was working: your material was black because you’ve simply set it as nearly black :smiley:

1 Like

Thank you very much. The solution sounds pretty funny. I will be study it early.