Jump to content

How to get submeshes by name?


hit2501
 Share

Recommended Posts

Hi, I was playing with a model exported from Blender and I can retrieve its submeshes with:

var my_model = newMeshes[0];
var my_submesh = my_model.subMeshes[0];

But now I would like to know how can I retrieve a submesh from its name instead its number (like I can see in Blender).

Can anybody help me?

Thanks in advance.

Link to comment
Share on other sites

Not sure what you are seeing in Blender, but submesh does not have a name.  You might be able to something to retrieve by corresponding material name.  Going the opposite direction is

let matName = my_model.materials[my_model.subMeshes[0].materialIndex].name;
getSubMesh(mesh, name) {
    let mat = mesh.materials;
    let idx;
    for (let i = 0, len = mat.length; i < len; i++) {
        if (mat[i].name === name) {
            idx = i;
            break;
        }
    }
    return idx ? mesh.submeshes[idx] : null;
}

   

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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