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

InputManager: Fix Picking on PointerUp and add bool to skip pointerup picking #12524

Merged
merged 9 commits into from May 27, 2022
8 changes: 5 additions & 3 deletions packages/dev/core/src/Inputs/scene.inputManager.ts
Expand Up @@ -405,7 +405,7 @@ export class InputManager {

private _processPointerUp(pickResult: Nullable<PickingInfo>, evt: IPointerEvent, clickInfo: _ClickInfo): void {
const scene = this._scene;
if (pickResult && pickResult && pickResult.pickedMesh) {
if (pickResult && pickResult.hit && pickResult.pickedMesh) {
this._pickedUpMesh = pickResult.pickedMesh;
if (this._pickedDownMesh === this._pickedUpMesh) {
if (scene.onPointerPick) {
Expand Down Expand Up @@ -463,7 +463,6 @@ export class InputManager {

if (!clickInfo.ignore) {
type = PointerEventTypes.POINTERUP;

const pi = new PointerInfo(type, evt, pickResult);
this._setRayOnPointerInfo(pi);
scene.onPointerObservable.notifyObservers(pi, type);
Expand Down Expand Up @@ -508,9 +507,12 @@ export class InputManager {
}
this._deviceSourceManager = new DeviceSourceManager(engine);

// Because this is only called from _initClickEvent, which is called in _onPointerUp, we'll use the pointerUpPredicate for the pick call
this._initActionManager = (act: Nullable<AbstractActionManager>): Nullable<AbstractActionManager> => {
if (!this._meshPickProceed) {
const pickResult = scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerDownPredicate, false, scene.cameraToUseForPointers);
const pickResult = scene.skipPointerUpPicking
? null
: scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerUpPredicate, false, scene.cameraToUseForPointers);
this._currentPickResult = pickResult;
if (pickResult) {
act = pickResult.hit && pickResult.pickedMesh ? pickResult.pickedMesh._getActionManagerForTrigger() : null;
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/core/src/scene.ts
Expand Up @@ -697,6 +697,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
* Gets or sets a predicate used to select candidate meshes for a pointer up event
*/
public pointerUpPredicate: (Mesh: AbstractMesh) => boolean;

/**
* Gets or sets a predicate used to select candidate meshes for a pointer move event
*/
Expand All @@ -712,6 +713,11 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
*/
public skipPointerDownPicking = false;

/**
* Gets or sets a boolean indicating if the user want to entirely skip the picking phase when a pointer up event occurs. Off by default.
*/
public skipPointerUpPicking = false;

/** Callback called when a pointer move is detected */
public onPointerMove: (evt: IPointerEvent, pickInfo: PickingInfo, type: PointerEventTypes) => void;
/** Callback called when a pointer down is detected */
Expand Down