Skip to content

Commit a58a334

Browse files
authored
update left/right click button behaviour on renderer (#1078)
* update left/right click button behaviour on renderer * remove gizmo right click button * fixed review comments
1 parent 5b19f0f commit a58a334

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

packages/@dcl/inspector/src/lib/babylon/decentraland/camera.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as BABYLON from '@babylonjs/core'
2+
23
import { CameraManager } from './camera'
4+
import { MIDDLE_BUTTON, RIGHT_BUTTON } from './mouse-utils'
35

46
describe('Camera manager', () => {
57
let engine: BABYLON.Engine
@@ -28,15 +30,15 @@ describe('Camera manager', () => {
2830
cameraManager = new CameraManager(scene, document.createElement('canvas'), [0, 1, 2], 1, 1, 1)
2931
mouseDown = {
3032
type: BABYLON.PointerEventTypes.POINTERDOWN,
31-
event: { pointerType: 'mouse' }
33+
event: { pointerType: 'mouse', button: RIGHT_BUTTON }
3234
} as unknown as BABYLON.PointerInfo
3335
mouseWheelUp = {
3436
type: BABYLON.PointerEventTypes.POINTERWHEEL,
35-
event: { deltaY: -240 }
37+
event: { deltaY: -240, button: MIDDLE_BUTTON }
3638
} as unknown as BABYLON.PointerInfo
3739
mouseWheelDown = {
3840
type: BABYLON.PointerEventTypes.POINTERWHEEL,
39-
event: { deltaY: 240 }
41+
event: { deltaY: 240, button: MIDDLE_BUTTON }
4042
} as unknown as BABYLON.PointerInfo
4143
})
4244
it('should start with correct default speed', () => {

packages/@dcl/inspector/src/lib/babylon/decentraland/camera.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as BABYLON from '@babylonjs/core'
2-
import { Keys, keyState } from './keys'
3-
import { PARCEL_SIZE } from '../../utils/scene'
2+
import { Vector3, Quaternion } from '@dcl/ecs-math'
43
import mitt, { Emitter } from 'mitt'
4+
5+
import { Keys, keyState } from './keys'
56
import { EcsEntity } from './EcsEntity'
7+
import { RIGHT_BUTTON } from './mouse-utils'
68
import { fitSphereIntoCameraFrustum } from '../../logic/math'
7-
import { Vector3, Quaternion } from '@dcl/ecs-math'
9+
import { PARCEL_SIZE } from '../../utils/scene'
810

911
type SpeedChangeEvent = { change: number }
1012

@@ -135,8 +137,11 @@ export class CameraManager {
135137
const center = new BABYLON.Vector3(PARCEL_SIZE / 2, 0, PARCEL_SIZE / 2)
136138
const size = center.length()
137139
const camera = new BABYLON.FreeCamera('editorCamera', center.subtractFromFloats(size, -size * 1.5, size * 2), scene)
140+
const mouseInput = camera.inputs.attached.mouse as BABYLON.FreeCameraMouseInput
138141
camera.target = center
139142

143+
mouseInput.buttons = [RIGHT_BUTTON] // disable all buttons except right mouse button
144+
140145
camera.inertia = 0
141146
camera.speed = this.speeds[this.speedIndex]
142147
camera.angularSensibility = CameraManager.ANGULAR_SENSIBILITY
@@ -160,10 +165,10 @@ export class CameraManager {
160165

161166
let holdingMouseButton = false
162167
scene.onPointerObservable.add((ev) => {
163-
if (ev.type === BABYLON.PointerEventTypes.POINTERDOWN) {
168+
if (ev.type === BABYLON.PointerEventTypes.POINTERDOWN && ev.event.button === RIGHT_BUTTON) {
164169
holdingMouseButton = true
165170
}
166-
if (ev.type === BABYLON.PointerEventTypes.POINTERUP) {
171+
if (ev.type === BABYLON.PointerEventTypes.POINTERUP && ev.event.button === RIGHT_BUTTON) {
167172
holdingMouseButton = false
168173
}
169174
if (ev.type === BABYLON.PointerEventTypes.POINTERWHEEL) {

packages/@dcl/inspector/src/lib/babylon/decentraland/gizmo-manager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import {
1010
} from '@babylonjs/core'
1111
import { Entity, TransformType } from '@dcl/ecs'
1212
import { Vector3 as DclVector3, Quaternion as DclQuaternion } from '@dcl/ecs-math'
13+
1314
import { GizmoType } from '../../utils/gizmo'
1415
import { EcsEntity } from './EcsEntity'
1516
import { snapManager, snapPosition, snapRotation, snapScale } from './snap-manager'
1617
import { SceneContext } from './SceneContext'
1718
import { PatchedGizmoManager } from './gizmo-patch'
1819
import { ROOT } from '../../sdk/tree'
20+
import { LEFT_BUTTON } from './mouse-utils'
1921

2022
const GIZMO_DUMMY_NODE = 'GIZMO_DUMMY_NODE'
2123

@@ -31,6 +33,12 @@ function releaseDragFromGizmo({ xGizmo, yGizmo, zGizmo }: GizmoAxis) {
3133
zGizmo.dragBehavior.releaseDrag()
3234
}
3335

36+
function configureGizmoButtons(gizmo: GizmoAxis, buttons: number[]) {
37+
gizmo.xGizmo.dragBehavior.dragButtons = buttons
38+
gizmo.yGizmo.dragBehavior.dragButtons = buttons
39+
gizmo.zGizmo.dragBehavior.dragButtons = buttons
40+
}
41+
3442
function areProportional(a: number, b: number) {
3543
// this leeway is here to account for rounding errors due to serializing/deserializing floating point numbers
3644
return Math.abs(a - b) < 1e-5
@@ -65,6 +73,11 @@ export function createGizmoManager(context: SceneContext) {
6573
gizmoManager.gizmos.positionGizmo!.updateGizmoRotationToMatchAttachedMesh = false
6674
gizmoManager.gizmos.rotationGizmo!.updateGizmoRotationToMatchAttachedMesh = true
6775

76+
// Configure all gizmos to only work with left click
77+
if (gizmoManager.gizmos.positionGizmo) configureGizmoButtons(gizmoManager.gizmos.positionGizmo, [LEFT_BUTTON])
78+
if (gizmoManager.gizmos.rotationGizmo) configureGizmoButtons(gizmoManager.gizmos.rotationGizmo, [LEFT_BUTTON])
79+
if (gizmoManager.gizmos.scaleGizmo) configureGizmoButtons(gizmoManager.gizmos.scaleGizmo, [LEFT_BUTTON])
80+
6881
let selectedEntities: EcsEntity[] = []
6982
let rotationGizmoAlignmentDisabled = false
7083
let positionGizmoAlignmentDisabled = false

packages/@dcl/inspector/src/lib/babylon/decentraland/mouse-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { Scene, Vector3 } from '@babylonjs/core'
22
import future from 'fp-future'
33

4+
export const LEFT_BUTTON = 0
5+
export const MIDDLE_BUTTON = 1
6+
export const RIGHT_BUTTON = 2
7+
48
export async function getPointerCoords(scene: Scene) {
59
const coords = future<Vector3>()
610
scene.onPointerObservable.addOnce(() => {

0 commit comments

Comments
 (0)