Make plane only pickable from the front

Hello!

I have a plane that is only rendered from one side. So it is not visible from the back.
But unfortunately the plane is still pickable from the back.

Is there an easy way to make the plane only pickable from the side that is visible?

At the moment I am calculating the dot product with the ray direction and the face normal to determine the side:

       const rayDirection = pickInfo.ray?.direction
        const normalDirection = pickInfo.getNormal(true)

        if (rayDirection != null && normalDirection != null) {
            if (Vector3.Dot(rayDirection, normalDirection) > 0) {
                return null
            }
        }

Off the top of my head, i guess there are two ways of making it happen pre-pick ray.

One is the mesh predicate - this function takes a mesh and returns a boolean. If it is executed with the camera in its context you could find a good way for you to decide if this mesh should be included in the (standard) picking. This way you could also make sure that the user will be able to pick “through” objects instead of picking them and “deselecting” them if they are culled.

The second is the trianglePredicate that can be passed to scene.pick (or any other picking function). There are a few catches - first there is no “default” triangle picking function in the standard pick loop, so if you want to be able to use it you should avoid the standard pick (that is executed on each frame) and implement your own picking function. The second catch is that it won’t save you any CPU time - it will go over all triangles anyhow. Not sure this would be the best way to go.

a hecky and faster way would be to put another plane behind it and make it invisible.

2 Likes

Just putting up a blocker, was my thought as well. Especially if there is just one example. Looking at complicated code a couple of months later can be a nightmare.

2 Likes

Hi @RaananW ,

I was looking into implementing the trianglePredicate option to fix an issue where if the camera is inside of a front-face mesh, you don’t see the mesh but it still captures all picks.

However, looking at the signature for TrianglePickingPredicate, I don’t think it’s possible:

TrianglePickingPredicate: (p0: Vector3, p1: Vector3, p2: Vector3, ray: Ray) => boolean

Wouldn’t I need the normal (or at least the face index and a reference to the mesh so I can look up the normal) to determine if the ray is hitting the front or back of the triangle?

You can get the normal from the points :slight_smile: