PointerDragBehaviour to pick selected mesh

I am facing an issue with plane dragging.
When the plane that I need to drag, gets inside some mesh, scene picker picks those meshes which the ray is intersecting in the very beginning.

Thus when the plane gets trapped inside a geometry it fails to drag.

Replicated the issue here
https://playground.babylonjs.com/#S2NTDA#3

One fix that I can think of is making the isPickable property to false for all other meshes.That seems very expensive for my usecase.

Is there someway to restrict pointerDragBehaviour to pick specific meshes.

isPickable was meant exactly for that :slight_smile:

But, there is of course another way, that in your case might come in handy.Every pointer event has its own predicate - pointer down, up and move. The predicate is nothing more than a function that takes a mesh and returns boolean - should this mesh be picked or not. In the default predicate we check for visibility, enabled, and pickable. You can write your own function (which can be dynamic, according to the current state of the scene). Something like this:

Babylon.js Playground (babylonjs.com)

3 Likes

Thanks for the crisp answer. Is there some way to dispose the predicate afterwards if needed?

You can set it to whatever you want, whenever you want. The latest version will be taken on the current pick. Seeing it to undefined or null will revert back to the defaults.

1 Like