Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/@dcl/inspector/src/lib/babylon/decentraland/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,25 @@ export class CameraManager {
return false
}

let isAltKeyDown = false
scene.onPreKeyboardObservable.add((ev) => {
const isAltKeyDown = ev.type === BABYLON.KeyboardEventTypes.KEYDOWN && ev.event.inputIndex === Keys.KEY_ALT
const oldAltKeyState = isAltKeyDown
if (ev.type === BABYLON.KeyboardEventTypes.KEYDOWN && ev.event.inputIndex === Keys.KEY_ALT) {
isAltKeyDown = true
}

if (ev.type === BABYLON.KeyboardEventTypes.KEYUP && ev.event.inputIndex === Keys.KEY_ALT) {
isAltKeyDown = false
}

if (isAltKeyDown) {
mouseInput.buttons = [LEFT_BUTTON, RIGHT_BUTTON] // move camera with left/right mouse buttons
} else {
mouseInput.buttons = [RIGHT_BUTTON] // move camera with right mouse button only
// reattach control to avoid camera sticking to the pointer bug...
this.reattachControl()
if (oldAltKeyState) {
// reattach control to avoid camera sticking to the pointer bug...
this.reattachControl()
}
}
})

Expand Down
3 changes: 3 additions & 0 deletions packages/@dcl/inspector/src/lib/babylon/setup/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function initKeyboard(canvas: HTMLCanvasElement, scene: BABYLON.Scene) {
canvas.addEventListener('keydown', (e) => {
keyState[Keys.KEY_SHIFT] = e.shiftKey
keyState[Keys.KEY_CTRL] = e.ctrlKey
keyState[Keys.KEY_ALT] = e.altKey
keyState[e.keyCode] = true
if (e.shiftKey) {
isSnapEnabled = snapManager.toggle()
Expand All @@ -29,13 +30,15 @@ export function initKeyboard(canvas: HTMLCanvasElement, scene: BABYLON.Scene) {

keyState[Keys.KEY_SHIFT] = e.shiftKey
keyState[Keys.KEY_CTRL] = e.ctrlKey
keyState[Keys.KEY_ALT] = e.altKey
keyState[e.keyCode] = false
})

// When the canvas lost the focus, clear the special keys state
canvas.addEventListener('blur', () => {
keyState[Keys.KEY_SHIFT] = false
keyState[Keys.KEY_CTRL] = false
keyState[Keys.KEY_ALT] = false
})

// Event to store the ctrlKey when the canvas has lost the focus
Expand Down
Loading