Skip to content

Commit

Permalink
InputManager: Fix Picking on PointerUp and add bool to skip pointerup…
Browse files Browse the repository at this point in the history
… picking (BabylonJS#12524)

* Add bool to skip picking on up and fix pointerup picking

* Remove left over comment

* Update skipPointerUpPicking to be true by default

* Changed skipped pointerup picking info to just be _currentPickResult

* Re-added !pickResult

* feedback

* Add additional check for picking to _initActionManager

* feedback

* Re-added missing line
  • Loading branch information
PolygonalSun authored and alvov-evo committed Jun 16, 2022
1 parent d0a3529 commit f3ea6fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit f3ea6fe

Please sign in to comment.