Compute surface/faceId world position from pickWithRay


I’m trying to create some pin point on a mesh. I create this pin point from the pickWithRay method.
Here is an example, double click on the mesh to pick a point.
On simple use cases it works well :

I’m mainly trying to create that for animated models. So I try to reuse to faceId return by pickWithRay to compute the current world position of the face.

And here is my problems.
On some meshes, the points seems to be offset. Again double click, the blue point is the hit.pickedPoint and the red point is the computed point from the faceId.
On the Skull, it is offset :
On the Alien, it is offset at the base and offset/inverted on the head :
On the Khronos Helmet it is always on the ground :
On the Khronos animated Fox it is inverted :

I’m quite a newbie when it comes to 3D stuff, so I’m probably missing something obvious.
If you would be kind enough to help me :slight_smile:



What you was missing is taking into account the World Transform of the meshes (Position, Rotation, Scale) It worked by chance on the Dude because it was all 0,0,0 (and 1,1,1 for scale)

After mesh load, compute matrices :

meshes.forEach(function(mesh) {

And before projecting from 3D to 2D, transform your point :

const worldMatrix = pickedMesh.getWorldMatrix();
worldPosition = BABYLON.Vector3.TransformCoordinates(worldPosition, worldMatrix);

And here you go : this Playground works on all the examples you provide :slight_smile:



Thanks, I get it now !

@Tricotou striked again :slight_smile: