Panning ArcRotateCamera with keyboard without using Ctrl Key

The ArcRotateCameraKeyboardMoveInput has no option for make the default keys events (up, down, left, right) to pan the camera instead of rotate it, like when you pressed Ctrl + move keys (it activates panning).

There is a _ctrlPressed variable on the object but can’t be setted, because it will be updated when pressed Ctrl on scene.

Is there a way to make the default movement of the camera, with the direction keys, will be panning instead of rotation?

Adding @PolygonalSun

I’d love an arc rotate camera where you could swap between rotate as pimary and pan as primary easily. Is this something that’s supported yet or could be considered as an option?

Currently, arcRotateCamera.attachControl takes a useCtrlForPanning option that defaults to true and leads to rotation as default motion and panning as secondary option (ctrl pressed).

I’d like to propose adding one more option that would default to false and would swaps the 2, so a user can easily switch to pan as default and rotate when ctrl is pressed. This would impact both arcRotateCameraKeyboardMoveInput and arcRotateCameraPointersInput. This could be useful for some setups (mine is consistency between a 3D viewer and a map viewer). It could also let developers build keyboard-less experiences where a user can press a button to switch between panning and rotating.

I don’t mind trying my hand at a PR, although i’m not super familiar with the codebase and may need some pointers. And if there is a better way to do this, let me know.

Tagging @Evgeni_Popov and @PolygonalSun who seem to be involved in this type of stuff. Hope that’s ok.

cc @amoebachant and @georgie, but it looks like a good idea!

my only concern is that having 2 parameters which are not mutually exclusive may get confusing – what if both are set to true, what behavior does ctrl invoke ?

we could perhaps add a setting which can be enabled ontop of useCtrlForPanning – where if useCtrlForPanning is true (ctrl pans, regular rotates) but if false, it swaps (ctrl rotates, regular pans)

@amoebachant is out of office, once he returns we will discuss and recommend a solution or create PR to solve

Thanks @Evgeni_Popov .

And @georgie I’m 100% with you on that, i was wondering what was the best approach as well. I feel it’s almost more of an English and naming problem (plus clear documentation) than a technical one.

I noted that useCtrlForPanning default to true and can be set to false to disable panning altogether. And we need to keep backward compatibility. So there are 3 possible behaviors and we’re forced to keep one boolean setting. I see 2 approaches:

  1. add swapPanAndRotate option conditioned by useCtrlForPanning
    1. useCtrlForPanning false, ignore swapPanAndRotate → disable panning
    2. useCtrlForPanning true, swapPanAndRotate false (default) → current behaviour
    3. useCtrlForPanning true, swapPanAndRotate true → swap
  2. add useCtrlForRotation
    1. useCtrlForPanning true (default), useCtrlForRotation false (default) → current default
    2. useCtrlForPanning false, useCtrlForRotation false (default) → disable panning
    3. useCtrlForPanning false, useCtrlForRotation true → rotate on ctrl
    4. useCtrlForPanning true (default), useCtrlForRotation true → ignore useCtrlForRotation if useCtrlForPanning is true

Just some ideas, I hope this helps. And let me know if there is anything I can help with.

You want the ctrl key to do something, right? If so, why not simply:

enum CtrlKeyBehaviours {...}
/** 
@param ctrlKeyBehaviour : bool -  useCtrlForPanning (back compat) | CtrlKeyBehaviours - behaviour flag
*/
arcRotateCamera.attachControl( ctrlKeyBehaviour : bool|CtrlKeyBehaviours  )

That’s much better yes. I didn’t realize we could rename the argument while maintaining backward compatibility. I thought it was a single object argument with named parameters. :face_with_peeking_eye:

Hi @georgie, I wanted to check in if you had had the opportunity to make progress on this? Thanks :slight_smile:

@tibotiber does the solution provided by @Joe_Kerr solve your issue without API changes?

Thanks for the reply @georgie. I thought @Joe_Kerr proposed an API design for the suggested changes that handles backward compat. I didn’t think this API exists as of today.

Did I miss something?

@georgie @Joe_Kerr @tibotiber This is exactly the area that I am focused on. It is irritating. Is it possible to have a dropdown of the different Camera types and the options for each? Just asked AI how to replace it. The response does seem off - incorrect:

“how to change babylonjs sandbox camera“
How to change babylonjs sandbox camera

To change the Babylon.js sandbox camera, you can follow these steps:

  1. Set the active camera: Use the scene.activeCamera property to set the camera you want to use in the scene. For example, scene.activeCamera = myCamera;.

  2. Attach the camera to the canvas: Use the attachControl method to attach the active camera to the canvas. This method takes parameters like canvas, noPreventDefault, and scene.activeCamera.attachControl(canvas, true);.

  3. Customize camera inputs: Use the inputs property to manage and customize the camera’s inputs, such as mouse, keyboard, gamepad, or device orientation. This allows you to add, remove, enable, or disable any input available for the camera.
    By following these steps, you can effectively change and customize the camera used in your Babylon.js sandbox project.

and @tibotiber

Yes, I thought so, too. Maybe if you do not want to touch Camera.attachControl, have it something like this?

enum CtrlKeyBehaviours {...}

//back compat
private ctrlBehaviour : CtrlKeyBehaviours = CtrlKeyBehaviours.CurrentBabylonBehaviour;

public setCtrlBehaviourToModeX() { this.ctrlBehaviour = CtrlKeyBehaviours.X }
// or a setter via enum param...?

to me the first suggestion from @Joe_Kerr aligns the best with the current API design.

enum CtrlKeyBehaviours {…}
/**
@param ctrlKeyBehaviour : bool -  useCtrlForPanning (back compat) | CtrlKeyBehaviours - behaviour flag
*/
arcRotateCamera.attachControl( ctrlKeyBehaviour : bool|CtrlKeyBehaviours  )

@georgie is this still something you and @amoebachant want to discuss first?

Ah yes I now see that it is a proposed change not a reference to existing API - my apologies.

Yes @amoebachant and I will discuss API changes to make after the 9.0 release! Can address this alongside the changes to introduce framerate independent movement to camera

Awesome, thanks @georgie and ping me here if I can be of any help.

When will this feature be released? We urgently need it

Hi all, this work will be released after the 9.0 release - there has been a lot of feedback around camera / inputs so i want to tackle all together into a more configurable system, thank you for the feedback and will keep you updated as work evolves!

Understanding it is really urgent, feel free to contribute it and we ll be happy to review it.