Jump to content

Obj file loader:create one mesh with multi-material got wrong


Recommended Posts

Hi everyone,

In the obj file, when an object has multi-material, the obj file loader will create several meshes.


I want to only create one mesh with multi-material, but got the wrong result:


I attached the obj file and the new obj file loader I modified(objFileLoader_new.js ), can anybody help to have a look why it is wrong. It troubled me a whole day now.


Link to comment
Share on other sites


What I want is not a really a single mesh, but a mesh with BABYLON.MultiMaterial, it will have multiple submesh.

my code is like:

                if (handledMesh.materials.length > 1) {
                    babylonMesh.subMeshes = [];
                    var multimat = new BABYLON.MultiMaterial("multi", scene);
                    babylonMesh.material = multimat;
                    for (var i = 0; i < handledMesh.materials.length; i++) {
                        var submat = materialsFromMTLFile.materials[handledMesh.materials];
                        var submesh = new BABYLON.SubMesh(i, 0, handledMesh.positions.length/3, handledMesh.spans[0], handledMesh.spans[1], babylonMesh);
                else {
                    babylonMesh.material = materialsFromMTLFile.materials[handledMesh.materials[0]];

You can have a look of my entire code in the attachment in the top post

Link to comment
Share on other sites

@fdeng I took a quick read-through and one thing that seems to be missing is adding the submesh to the your handledMesh array:

Something like this:



This playground may be a good reference in getting MultiMaterials to work with multiple submeshes if you haven't seen this one yet.



Let me know if that helps.

Link to comment
Share on other sites

Hi @kcoley

It seems not the reason, when create a submesh like below, 

var submesh = new BABYLON.SubMesh(..., mesh);   

Actually the created submesh will be pushed to subMeshes array of the parent mesh automatically.

You can verify it in  this new PG:


I removed these push actions:
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...