Filter mouse buttons for PointerDragBehavior?

Hello,
I have a PointerDragBehavior, and I was trying to make it drag only on left click (it seems like a basic feature a lot of dev might want to use : actions are often different depending on the mouse button you use).
Sadly, I found no easy way to do it. The currentDraggingPointerID doesn’t seem to bring any button info…
So I had to change the dragBehavior._pointerObserver.callback to do it :

    const currentCallback = dragBehavior._pointerObserver.callback;
    dragBehavior._pointerObserver.callback = (pointerInfo, eventState) => {
            if (pointerInfo.event.button !== 0 && pointerInfo.event.type !== "pointermove") {
                return;
            }
            currentCallback(pointerInfo, eventState);
    };

It’s working, but it’s not really nice to have to do this sort of thing just to drag on left click only…
Am I missing something ? If not, it would be nice to add a allowed mouse button(s) parameter to the PointerDragBehavior, and maybe to the gizmos too.

1 Like

Pinging @trevordev

1 Like

Hey @Eole211, welcome to the forum.

This seems reasonably useful. Would you want to try to create a PR to support this? The file can be found here Babylon.js/pointerDragBehavior.ts at master · BabylonJS/Babylon.js · GitHub . I always struggle with how many options/settings should be exposed on helper classes like these but am happy to review/accept a PR.

Also I would note that if in your code you are using variables/methods starting with _ (eg. _pointerObserver) those are internal and may be renamed or modified in future version of babylon.

2 Likes

Ok, I’ll see to it next week maybe.

1 Like