BoundingBoxGizmo does not respect panning button when reattaching camera

I’m seeing an issue with BoundingBoxGizmo illustrated in this PG

In the PG, I have disabled camera rotation and set the camera to pan using the left mouse button. This works until I select the box which attaches the gizmo. After attaching the gizmo, the camera panning button is reset.

I have traced the problem to line 395 in BaseSixDofDragBehavior (Babylon.js/baseSixDofDragBehavior.ts at b24d65a53e12cc138495ae64cbacfbd0b126d83d · BabylonJS/Babylon.js · GitHub) where it reattaches the camera controls with only the preventDefault arg specified, so the panningMouseButton is reset to 2.

if (this.detachCameraControls && this._attachedToElement && this._pointerCamera && !this._pointerCamera.leftCamera) {
                            this._attachedToElement = false;

I believe that BaseSixDofDragBehavior should do the same thing DragBehavior does, which is to preserve the original values if the camera is an ArcRotateCamera

if (this._scene.activeCamera.getClassName() === "ArcRotateCamera") {
                const arcRotateCamera = this._scene.activeCamera as ArcRotateCamera;
                    arcRotateCamera.inputs ? arcRotateCamera.inputs.noPreventDefault : true,
            } else {
                this._scene.activeCamera.attachControl(this._scene.activeCamera.inputs ? this._scene.activeCamera.inputs.noPreventDefault : true);
            this._attachedToElement = false;

Note that in my case (not represented in the PG), I don’t want the BB Gizmo to ever allow moving position so I disable movement and attach PointerDragBehavior to the mesh. For some reason, when I attach the gizmo to the third mesh, the SixDofDragBehavior fires on pointer up instead of the DragBehavior and resets my panning buttons. I don’t know why this happens (I suspect a race condition of some sort) but I figure in any case, the solution is to make sure BaseSixDofDragBehavior does the right thing.

Happy to submit a PR for this if the team agrees this is unintended behavior and with my solution.

Yup a PR would be great !!! @Cedric can confirm :slight_smile:

Thanks a lot for the contribution.

Yep, more than happy to review the PR :slight_smile:

1 Like

PR is live Preserve camera control settings when reattaching camera controls by ericwood73 · Pull Request #13300 · BabylonJS/Babylon.js · GitHub

1 Like