The points where the annotation is picked are snapped parallel to the surface of the object

I am doing a fitting point to mark the position to be picked. The desired effect is that the marked point is parallel to the surface of the object.
playground:https://playground.babylonjs.com/#NBK6X6#1

The specific method is to click to select a file to select a model, and then click the upload button.
Move the mouse, the fitting point cannot be parallel to the surface of the object, a solution is needed, thank you.
The expected effect is as follows:


1 Like

This example should help you make the right calculations:

Just replace line 68 with const normal = pickResult.getNormal(); to use the normal to the picked point instead of the direction of the view to the camera.

DiZuodrc.zip (683.3 KB)

I tried your solution, but it is not feasible to use it on the uploaded model, please use this model as a reference to help

That’s because of the default orientation of the cylinder. You need to rotate it by 90° around the X axis:

demo.zip (494.6 KB)
It seems using different model would behave differently.

Hello, your solution is very important. Based on this solution, I modified the 96 lines of code, and the modified code can solve my problem. Thank you for your help!
before fixing:
const normal = pickInfo.getNormal();
After modification:
const normal = pickInfo.getNormal(true, true);

1 Like

@kzhsw I think the latest PG from @lxq100 should work.

How can I get picked normal for meshes without indices?
example model:
example.zip (923 Bytes)

Here are some info when debugging getNormal:


It seems to read normal form NaN offset.

This PR will fix getNormal when the mesh is unindexed:

2 Likes