Pick bone only Is it possible?

Hello,

Is it possible to choose a bone only? For example, I have a character with a skeleton and I wish for example by clicking on the head to select the bone of the head and not the mesh to make a rotation on the bone select.

Or I wish I could get the index of the bone by clicking on the head for example.

How can we do that?

Hey!

once you have the picked mesh, and the picked face you can probably get (not easy but I can help) the matricesIndices values that are the IDs of the bones that influence the current mesh

Ok, I’ll try to follow this track in a PG to see how I can get that.

But I can not find the matricesIndices values ​​so far. And I’m not sure of my method for selecting a face.

https://www.babylonjs-playground.com/#BCU1XR#725

Thanks for the help

So yes this is correct and now instead of getNormal you need to come with something like getTExtureCoordinates but with the VertexBuffer.MatricesIndices instead:

I use now this:

var matricesIndices = pickResult.pickedMesh.getVerticesData(BABYLON.VertexBuffer.matricesIndices);

But it return “Null”. Did I do something wrong?

https://www.babylonjs-playground.com/#BCU1XR#731

I think I do not even understand what I’m doing. :upside_down_face:

This will work better:

var matricesIndices = pickResult.pickedMesh.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);

What a small typo can do to your confidence :slight_smile:

Seems like you know exactly what you are doing, as always

Thank you Deltakosh, I get data in a large table. But whatever the location of the mesh where I click, it’s the same table of data.

What should I do now to retrieve the index of the selected face bone.

https://www.babylonjs-playground.com/#BCU1XR#733

Hi @RaananW ,

Down I happen to do things without really understanding what I’m doing. I do it because I imagine it must be like that, but without understanding what I write, why.
Here for example, I recover the MatricesIndices but I do not know what I have to do and I do not know what are matrices concretely. :confused:

Once you get the matrices indices data, you need to do like in the code I linked, you need to

So let say we have something like:

let vertexId = indices[this.faceId * 3];
let bone0 = matricesIndices[vertexId * 4];
let bone1 = matricesIndices[vertexId * 4 + 1];
let bone2 = matricesIndices[vertexId * 4 + 2];
let bone3 = matricesIndices[vertexId * 4 + 3];
1 Like

Ok, so if I understand correctly, bone0 corresponds to the index of the selected bone.

I have difficulties to understand. Sometimes the return data is 2, 3, 0, 0, or 5, 0, 2, 0 or 64, 0, 0, 0

https://www.babylonjs-playground.com/#BCU1XR#734

yes the data is correct (0 means no bone)

So, bone0 is the bone I need? How to know if it is the index of the bone of the head for example when I get a value bone0 and bone2.

I see that bone0 always has a value, I guess it’s the index I’m looking for. So I can ignore others. Is it correct ?

Thank you Deltakosh

If you are sure that only one bone is used to influence a vertex then yes, bone0 is enough

then you should be able to do something like skeletons.bones[bone0] to get your bone object

Ok, that’s perfect then. Thank you very much for your help.

1 Like

Always :wink:

Final code encapsulate in a function.

Could not this be added to the engine in the file pickingInfo.ts ? I can do the PR if needed

https://www.babylonjs-playground.com/#BCU1XR#735

It is a bit complicate as people may want to get all the bones and not the first one. There is also the case where we have 8 and not 4 bones (and in this case the MatricesIndicesExtraKind is used)