How to get a certain point on the face

Hello guys I have some questions about creating lines.

As shown in the figure, I have an imported object B. When I click to select a face(named selected face), a plane can be seen. Now I want to create a line between A and the selected face. For this I need three points, and two of the endpoints are: one is the bottom midpoint of the plane, the other is a point on the selected face (the center is offset by a little bit), is there any way to get these two points?

I try to create two lights, and then move the lights to the position I want, but no matter how I adjust the lights, they are always offset, so I want to know if there is any better way to help me get these two points?

Thanks in advance!!

I think you will have to perform the computation yourself, there’s no helper to do that.

Also, a repro in the PG would probably help to understand better what you want to do.

To get the point in the bottom middle of a plane you either:

  • Know its size and subtract half the size from its position.y (This is the easiest way in case it is standing upright, otherwise you have to account for its rotation).

Or

  • You get the planes vertices or its bounding box vertices and find out which are the bottom two corner points.
    Subtract the first from the second vector and half the result. The halved result plus the first vector then makes up the bottom middle of the plane. Something like this (Second.subtract(First)).multiplyByFloats(0.5, 0.5, 0.5).add(First);

For the point on the selected face I take it you want the point where it got clicked?
Take a look at this playground where exactly that gets calculated when you double click on the mesh: https://playground.babylonjs.com/#TZTHV1#2

3 Likes

Thank you so much!! :smiley:

1 Like

Thank you !