Picking polygons by ID?

Hi, I have a very basic question -

I usually work with 3D studio Max and I do not know how what I want is called in Babylon so I will do my best to explain what I am trying to achieve.

I want to be able to set POLYGON IDS to objects in 3D studio Max and then easily SELECT these polygon in Babylon.

Here is an example:
Lets say I have this object -
Imgur

I picked some of it’s polygons and gave them polygon ID 2 -
Imgur

I picked other polygons and gave them Polygon ID 3 -
(I gave different colors just for demonstration)
Imgur

Now I exported this mesh into Babylon.
How can I easily pick the polygons I chose in max with ID 2 and with ID 3?

Triangles in a mesh have no associated data that you could use to identify them, so you can’t easily retrieve a group of triangles. The only way is to know the triangle (face) indices.

The easiest way would be to export each group of faces as a separate mesh.

Hi
Thanks for your reply!

If I understand you correctly, there is no easy way for me to make a selection of these polygons (triangles) in Babylon?
I can Assign different materials to the polygons but I cannot select them?

I must say its surprising to me as this is prettty basic…

Breaking it into different meshes is not a good option for me as I need it to remain 1 mesh.
Is there no other simple workaround to easily select specific polygons (triangles)?

I never tried with 3dsMax but I know it works with Blender (it depends on how vertex buffer are parsed but there’s not so much way of doing it…)

Did you tried to compare the faceId returned by the PickingInfo object with the one shown in 3dsMax ?

scene.onPointerPick.add((event, pickingInfo) => {
  if(pickingInfo.hit) {
    console.log(pickingInfo.faceId)
  }
}

If it matches there are ways of selecting the triangles, if not it would be complicated…And it look basic but it’s not :slightly_smiling_face:, because there’s no triangle informations in the geometry files (gltf, obj, etc.).

I believe you could take advantage of this as a go-around (since, no, there is no polygon group selection in BJS). But there’s cloning of materials and texture and you can also dispose of them and replace them.
If you’d assign a cloned material to your poly-selection, you can next search it through the material id. Since it’s not a unique id, you can even assign a same id to different materials to form ‘groups of poly-selection’ or even better you can add an identifier to each id for different purposes and next split the id to transform a group that contains a same identifier. After the process is done, you could simply assign the final material to all and dispose of those that are just duplicates. I know it’s not ideal. It’s a work-around but I believe it should still be manageable.

Edit: I realize my answer is just ‘high-level’ and may not be applicable. May be you could tell us a bit more about what you want to do with these ‘polys-selections’? It will only make our answers more accurate.

It’s basic in a 3D modelling app but not necessarly in an engine. Though, I’m not saying, improvements can still be made (and are made every day) and now with i.e. ray marching and the new stuff, may be one day in a near or less near future, it will enter the list of potential improvements (just a guess). Meanwhile, I believe we need to make with what’s available and there’s nearly always a solution as a work-around. May be not always the one we would have wanted but yes, that’s what it is I suppose :grin:

If you can’t solve a problem from the right side, it’s best to look at it from the other side to at least come up with a new approach.
How can you assign multiple materials to an object in Babylon? Via subMeshes!

Example:

StM Remeshed | Babylon.js Playground (babylonjs.com)

4 Likes

Indeed. I had the same sort of approach. Working with submeshes might be even better. And then, with the example in PG… what more can you ask for? :smile:

1 Like