Get vertex group via raycast

Hey Folks!
Mainequin here.

We are currently working on an exploded drawing for a customer of ours. This model has a few hundred pieces which need to be clickable individually. We wrote a script that creates a bone for every piece and then automatically does the keyframing. However, after exporting the GLB we noticed, that parenting the separate objects to the bones has extremely high demands on the hardware. So we joined the meshes, reexported and viola! It works fluidly and flawlessly.

Since every object needs to be clickable however, we can’t separate the information any longer, since it is a single mesh. Since every piece has a properly named vertex group that connects it to it’s bone we were thinking, that getting the linked vertex group[s] on a clicked face would give us a sufficient identifier to then display our text and image data for that part.

SO OUR QUESTION IS:

  • Can we access the vertex group data of a face through a raycast(hit)?
  • If not, would it be reasonable for you to implement this feature?
  • Alternatively: Can you think of a better solution for our problem?

As always thank you very much for your time and dedication!
Best regards
The Mainequin Team

Hey!

1.Can we access the vertex group data of a face through a raycast(hit)? Yes:) the pickingInfo object returned by scene.pick will have all that you need: PickingInfo - Babylon.js Documentation
2. Already done :slight_smile:
3. No need

Thank you for your fast reply!

So we could get the vertex group with something like mesh.getIndices()[faceID * 3].vertexGroup(), with faceID coming from the raycast hit?
Our developers will find the exact command im sure.
We did some tests with babylon files and could not find the names of the vertex groups. It would make sense that the bone influences are IDs only, since the name of the bone and the vertex group would be identical/redundant.

So it would actually be something like (with faceID coming from the raycast hit):
bones[ mesh.getIndices()[faceID * 3].boneInfluenceID ].name?

As always thank you for your time.

Almost :slight_smile:
it should be something like:

var matrixIndices = mesh.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
var vertexIndex = mesh.getIndices()[faceID * 3];

var boneID =  matrixIndices[vertexIndex];