Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Lazy Picking for POINTERMOVE #13044

Merged
merged 29 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bf65e33
Lazy Pick on Move
PolygonalSun Sep 8, 2022
07785a7
Change to account for undefined
PolygonalSun Sep 8, 2022
757a531
cameras using DSM
PolygonalSun Sep 8, 2022
5c4cd98
Check for reasons to pick before picking
PolygonalSun Sep 8, 2022
ec05176
Addressed some feedback (missing meshUnderPointer)
PolygonalSun Sep 15, 2022
2fbd9db
Modified get meshUnderPointer
PolygonalSun Sep 16, 2022
166a60c
Add frame awareness picking for move
PolygonalSun Sep 17, 2022
a81875c
Merge branch 'master' into input-perf-test
PolygonalSun Sep 20, 2022
fa70f57
Caching Test
PolygonalSun Sep 27, 2022
d7d0986
Merge branch 'master' into input-perf-test
PolygonalSun Sep 27, 2022
b4db311
format
PolygonalSun Sep 27, 2022
0502afa
Merge branch 'input-perf-test' of https://github.com/PolygonalSun/Bab…
PolygonalSun Sep 27, 2022
fdf4934
Merge branch 'master' into input-perf-test
PolygonalSun Sep 28, 2022
568d43a
import fix
PolygonalSun Sep 28, 2022
5dd409d
Removed test code
PolygonalSun Sep 28, 2022
85c814f
PR Feedback
PolygonalSun Oct 6, 2022
0ccc7a2
fixed import
PolygonalSun Oct 6, 2022
a0ffe9c
removed gesture recognizer and reverted inputs
PolygonalSun Oct 7, 2022
51ee8cd
Revert videoDome because it uses picking info
PolygonalSun Oct 7, 2022
a9801ee
formatting
PolygonalSun Oct 7, 2022
3aab516
Changed to just MOVE Lazy Picking
PolygonalSun Oct 12, 2022
ee240e5
Format
PolygonalSun Oct 12, 2022
a3e5370
Removed comment
PolygonalSun Oct 12, 2022
f032d99
PR Feedback
PolygonalSun Oct 14, 2022
4a29d5a
Re-added meshunderpointer code back
PolygonalSun Oct 14, 2022
7b42a02
More feedback
PolygonalSun Oct 14, 2022
4d5dc2c
Comment
PolygonalSun Oct 14, 2022
eba0051
PR Feedback part 1
PolygonalSun Oct 17, 2022
dc3c171
comment
PolygonalSun Oct 17, 2022
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
Prev Previous commit
Next Next commit
cameras using DSM
  • Loading branch information
PolygonalSun committed Sep 8, 2022
commit 757a531e7eba3908ceddd6aa7b3a4bef828ca681
40 changes: 26 additions & 14 deletions packages/dev/core/src/Cameras/Inputs/BaseCameraMouseWheelInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { Observer } from "../../Misc/observable";
import { Observable } from "../../Misc/observable";
import type { Camera } from "../../Cameras/camera";
import type { ICameraInput } from "../../Cameras/cameraInputsManager";
import type { PointerInfo } from "../../Events/pointerEvents";
import { PointerEventTypes } from "../../Events/pointerEvents";
import type { IWheelEvent } from "../../Events/deviceInputEvents";
import type { IPointerEvent, IWheelEvent } from "../../Events/deviceInputEvents";
import { EventConstants } from "../../Events/deviceInputEvents";
import { Tools } from "../../Misc/tools";
import type { DeviceSourceType } from "../../DeviceInput/internalDeviceSourceManager";
import { DeviceType } from "../../DeviceInput/InputDevices/deviceEnums";

/**
* Base class for mouse wheel input..
Expand Down Expand Up @@ -47,8 +47,10 @@ export abstract class BaseCameraMouseWheelInput implements ICameraInput<Camera>
*/
public onChangedObservable = new Observable<{ wheelDeltaX: number; wheelDeltaY: number; wheelDeltaZ: number }>();

private _wheel: Nullable<(pointer: PointerInfo) => void>;
private _observer: Nullable<Observer<PointerInfo>>;
private _wheel: (event: IWheelEvent) => void;
private _observer: Nullable<Observer<IPointerEvent | IWheelEvent>>;
private _connectedObserver: Nullable<Observer<DeviceSourceType>>;
private _disconnectedObserver: Nullable<Observer<DeviceSourceType>>;

/**
* Attach the input controls to a specific dom element to get the input from.
Expand All @@ -59,14 +61,24 @@ export abstract class BaseCameraMouseWheelInput implements ICameraInput<Camera>
public attachControl(noPreventDefault?: boolean): void {
noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);

this._wheel = (pointer) => {
// sanity check - this should be a PointerWheel event.
if (pointer.type !== PointerEventTypes.POINTERWHEEL) {
return;
this._connectedObserver = this.camera._deviceSourceManager!.onDeviceConnectedObservable.add((deviceSource) => {
if (deviceSource.deviceType === DeviceType.Mouse) {
this._observer = deviceSource.onInputChangedObservable.add((eventData) => {
if ("deltaY" in eventData) {
this._wheel(eventData);
}
});
}
});

const event = <IWheelEvent>pointer.event;
this._disconnectedObserver = this.camera._deviceSourceManager!.onDeviceDisconnectedObservable.add((deviceSource) => {
if (deviceSource.deviceType === DeviceType.Mouse) {
deviceSource.onInputChangedObservable.remove(this._observer);
this._observer = null;
}
});

this._wheel = (event) => {
const platformScale = event.deltaMode === EventConstants.DOM_DELTA_LINE ? this._ffMultiplier : 1; // If this happens to be set to DOM_DELTA_LINE, adjust accordingly

if (event.deltaY !== undefined) {
Expand Down Expand Up @@ -96,18 +108,18 @@ export abstract class BaseCameraMouseWheelInput implements ICameraInput<Camera>
}
}
};

this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, PointerEventTypes.POINTERWHEEL);
}

/**
* Detach the current controls from the specified dom element.
*/
public detachControl(): void {
if (this._observer) {
this.camera.getScene().onPointerObservable.remove(this._observer);
this.camera._deviceSourceManager?.onDeviceConnectedObservable.remove(this._connectedObserver);
this.camera._deviceSourceManager?.onDeviceDisconnectedObservable.remove(this._disconnectedObserver);
const mouse = this.camera._deviceSourceManager?.getDeviceSource(DeviceType.Mouse);
mouse?.onInputChangedObservable.remove(this._observer);
this._observer = null;
this._wheel = null;
}
if (this.onChangedObservable) {
this.onChangedObservable.clear();
Expand Down
100 changes: 78 additions & 22 deletions packages/dev/core/src/Cameras/Inputs/BaseCameraPointersInput.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { Nullable } from "../../types";
import { serialize } from "../../Misc/decorators";
import type { EventState, Observer } from "../../Misc/observable";
import type { Observer } from "../../Misc/observable";
import { Tools } from "../../Misc/tools";
import type { Camera } from "../../Cameras/camera";
import type { ICameraInput } from "../../Cameras/cameraInputsManager";
import type { PointerInfo, PointerTouch } from "../../Events/pointerEvents";
import type { PointerTouch } from "../../Events/pointerEvents";
import { PointerEventTypes } from "../../Events/pointerEvents";
import type { IPointerEvent } from "../../Events/deviceInputEvents";
import type { IPointerEvent, IWheelEvent } from "../../Events/deviceInputEvents";
import type { DeviceSourceType } from "../../DeviceInput/internalDeviceSourceManager";
import { DeviceType, PointerInput } from "../../DeviceInput/InputDevices/deviceEnums";
import { InputManager } from "../../Inputs/scene.inputManager";

/**
* Base class for Camera Pointer Inputs.
Expand Down Expand Up @@ -36,6 +39,8 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {

private _currentActiveButton: number = -1;
private _contextMenuBind: EventListener;
private _previousStartingPointerTime = 0;
private _doubleClickOccured = false;

/**
* Defines the buttons associated with the input to handle camera move.
Expand Down Expand Up @@ -64,15 +69,63 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
this._shiftKey = false;
this._buttonsPressed = 0;

this._pointerInput = (p) => {
const evt = <IPointerEvent>p.event;
this._connectedObserver = this.camera._deviceSourceManager!.onDeviceConnectedObservable.add((deviceSource) => {
if (deviceSource.deviceType === DeviceType.Mouse) {
this._mouseObserver = deviceSource.onInputChangedObservable.add((eventData) => {
if (!("deltaY" in eventData)) {
let type = PointerEventTypes.POINTERMOVE;

if (eventData.inputIndex !== PointerInput.Move) {
type = deviceSource.getInput(eventData.inputIndex) === 1 ? PointerEventTypes.POINTERDOWN : PointerEventTypes.POINTERUP;
}

this._pointerInput(eventData, type);

if (Date.now() - this._previousStartingPointerTime < InputManager.DoubleClickDelay && !this._doubleClickOccured && type === PointerEventTypes.POINTERUP) {
this._doubleClickOccured = true;
type = PointerEventTypes.POINTERDOUBLETAP;
this._pointerInput(eventData, type);
} else {
this._doubleClickOccured = false;
}

if (type === PointerEventTypes.POINTERUP || type === PointerEventTypes.POINTERDOUBLETAP) {
this._previousStartingPointerTime = Date.now();
}
}
});
} else if (deviceSource.deviceType === DeviceType.Touch) {
this._touchObservers[deviceSource.deviceSlot] = deviceSource.onInputChangedObservable.add((eventData) => {
let type = PointerEventTypes.POINTERMOVE;

if (eventData.inputIndex !== PointerInput.Move) {
type = deviceSource.getInput(eventData.inputIndex) === 1 ? PointerEventTypes.POINTERDOWN : PointerEventTypes.POINTERUP;
}

this._pointerInput(eventData, type);
});
}
});

this._disconnectedObserver = this.camera._deviceSourceManager!.onDeviceDisconnectedObservable.add((deviceSource) => {
if (deviceSource.deviceType === DeviceType.Mouse) {
deviceSource.onInputChangedObservable.remove(this._mouseObserver);
this._mouseObserver = null;
} else if (deviceSource.deviceType === DeviceType.Touch) {
deviceSource.onInputChangedObservable.remove(this._touchObservers[deviceSource.deviceSlot]);
this._touchObservers[deviceSource.deviceSlot] = null;
}
});

this._pointerInput = (p, t) => {
const evt = p;
const isTouch = evt.pointerType === "touch";

if (engine.isInVRExclusivePointerMode) {
return;
}

if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {
if (t !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1) {
return;
}

Expand All @@ -91,7 +144,7 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
this.onTouch(null, offsetX, offsetY);
this._pointA = null;
this._pointB = null;
} else if (p.type === PointerEventTypes.POINTERDOWN && (this._currentActiveButton === -1 || isTouch)) {
} else if (t === PointerEventTypes.POINTERDOWN && (this._currentActiveButton === -1 || isTouch)) {
try {
srcElement?.setPointerCapture(evt.pointerId);
} catch (e) {
Expand Down Expand Up @@ -123,9 +176,9 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
evt.preventDefault();
element && element.focus();
}
} else if (p.type === PointerEventTypes.POINTERDOUBLETAP) {
} else if (t === PointerEventTypes.POINTERDOUBLETAP) {
this.onDoubleTap(evt.pointerType);
} else if (p.type === PointerEventTypes.POINTERUP && (this._currentActiveButton === evt.button || isTouch)) {
} else if (t === PointerEventTypes.POINTERUP && (this._currentActiveButton === evt.button || isTouch)) {
try {
srcElement?.releasePointerCapture(evt.pointerId);
} catch (e) {
Expand Down Expand Up @@ -177,7 +230,7 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
if (!noPreventDefault) {
evt.preventDefault();
}
} else if (p.type === PointerEventTypes.POINTERMOVE) {
} else if (t === PointerEventTypes.POINTERMOVE) {
if (!noPreventDefault) {
evt.preventDefault();
}
Expand Down Expand Up @@ -214,13 +267,6 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
}
};

this._observer = this.camera
.getScene()
.onPointerObservable.add(
this._pointerInput,
PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE | PointerEventTypes.POINTERDOUBLETAP
);

this._onLostFocus = () => {
this._pointA = this._pointB = null;
previousPinchSquaredDistance = 0;
Expand Down Expand Up @@ -250,9 +296,16 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
}
}

if (this._observer) {
this.camera.getScene().onPointerObservable.remove(this._observer);
this._observer = null;
if (this._connectedObserver || this._disconnectedObserver) {
this.camera._deviceSourceManager?.onDeviceConnectedObservable.remove(this._connectedObserver);
this.camera._deviceSourceManager?.onDeviceDisconnectedObservable.remove(this._disconnectedObserver);
const mouse = this.camera._deviceSourceManager?.getDeviceSource(DeviceType.Mouse);
const touches = this.camera._deviceSourceManager?.getDeviceSources(DeviceType.Touch);

mouse?.onInputChangedObservable.remove(this._mouseObserver);
touches?.forEach((touch) => {
touch.onInputChangedObservable.remove(this._touchObservers[touch.deviceSlot]);
});

if (this._contextMenuBind) {
const inputElement = this.camera.getScene().getEngine().getInputElement();
Expand Down Expand Up @@ -357,8 +410,11 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
*/
public onLostFocus(): void {}

private _pointerInput: (p: PointerInfo, s: EventState) => void;
private _observer: Nullable<Observer<PointerInfo>>;
private _pointerInput: (p: IPointerEvent, type: PointerEventTypes) => void;
private _connectedObserver: Nullable<Observer<DeviceSourceType>>;
private _disconnectedObserver: Nullable<Observer<DeviceSourceType>>;
private _mouseObserver: Nullable<Observer<IPointerEvent | IWheelEvent>>;
private _touchObservers: Array<Nullable<Observer<IPointerEvent>>> = [];
private _onLostFocus: Nullable<(e: FocusEvent) => any>;
private _pointA: Nullable<PointerTouch>;
private _pointB: Nullable<PointerTouch>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Nullable } from "../../types";
import { serialize } from "../../Misc/decorators";
import type { EventState, Observer } from "../../Misc/observable";
import type { Observer } from "../../Misc/observable";
import type { ArcRotateCamera } from "../../Cameras/arcRotateCamera";
import type { ICameraInput } from "../../Cameras/cameraInputsManager";
import { CameraInputTypes } from "../../Cameras/cameraInputsManager";
import type { PointerInfo } from "../../Events/pointerEvents";
import { PointerEventTypes } from "../../Events/pointerEvents";
import { Plane } from "../../Maths/math.plane";
import { Vector3, Matrix, TmpVectors } from "../../Maths/math.vector";
import { Epsilon } from "../../Maths/math.constants";
import type { IWheelEvent } from "../../Events/deviceInputEvents";
import type { IPointerEvent, IWheelEvent } from "../../Events/deviceInputEvents";
import { EventConstants } from "../../Events/deviceInputEvents";
import { Scalar } from "../../Maths/math.scalar";
import { Tools } from "../../Misc/tools";
import type { DeviceSourceType } from "../../DeviceInput/internalDeviceSourceManager";
import { DeviceType } from "../../DeviceInput/InputDevices/deviceEnums";

/**
* Firefox uses a different scheme to report scroll distances to other
Expand Down Expand Up @@ -58,8 +58,10 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
*/
public customComputeDeltaFromMouseWheel: Nullable<(wheelDelta: number, input: ArcRotateCameraMouseWheelInput, event: IWheelEvent) => number> = null;

private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;
private _observer: Nullable<Observer<PointerInfo>>;
private _wheel: (event: IWheelEvent) => void;
private _observer: Nullable<Observer<IPointerEvent | IWheelEvent>>;
private _connectedObserver: Nullable<Observer<DeviceSourceType>>;
private _disconnectedObserver: Nullable<Observer<DeviceSourceType>>;
private _hitPlane: Nullable<Plane>;

protected _computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta: number, radius: number) {
Expand All @@ -79,12 +81,25 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
*/
public attachControl(noPreventDefault?: boolean): void {
noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);
this._wheel = (p) => {
//sanity check - this should be a PointerWheel event.
if (p.type !== PointerEventTypes.POINTERWHEEL) {
return;

this._connectedObserver = this.camera._deviceSourceManager!.onDeviceConnectedObservable.add((deviceSource) => {
if (deviceSource.deviceType === DeviceType.Mouse) {
this._observer = deviceSource.onInputChangedObservable.add((eventData) => {
if ("deltaY" in eventData) {
this._wheel(eventData);
}
});
}
});

this._disconnectedObserver = this.camera._deviceSourceManager!.onDeviceDisconnectedObservable.add((deviceSource) => {
if (deviceSource.deviceType === DeviceType.Mouse) {
deviceSource.onInputChangedObservable.remove(this._observer);
this._observer = null;
}
const event = <IWheelEvent>p.event;
});

this._wheel = (event) => {
let delta = 0;

const mouseWheelLegacyEvent = event as any;
Expand Down Expand Up @@ -137,8 +152,6 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
}
};

this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, PointerEventTypes.POINTERWHEEL);

if (this.zoomToMouseLocation) {
this._inertialPanning.setAll(0);
}
Expand All @@ -149,9 +162,11 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
*/
public detachControl(): void {
if (this._observer) {
this.camera.getScene().onPointerObservable.remove(this._observer);
this.camera._deviceSourceManager?.onDeviceConnectedObservable.remove(this._connectedObserver);
this.camera._deviceSourceManager?.onDeviceDisconnectedObservable.remove(this._disconnectedObserver);
const mouse = this.camera._deviceSourceManager?.getDeviceSource(DeviceType.Mouse);
mouse?.onInputChangedObservable.remove(this._observer);
this._observer = null;
this._wheel = null;
}
}

Expand Down
Loading