Jump to content

How can I clear selection when picking nothing


BlackMojito
 Share

Recommended Posts

Hi Guys,

I am doing selection by adding a pointer observer like below. But there is one thing that this can not work which is clearing the selection(s) when clicking on the "empty" place. I know that I can add an observer with POINTERDOWN(or POINTERUP), but what I wish is when I rotate the camera by left click + dragging, the "selection event" will not be triggered. Only when I click at the empty place without rotating the camera, the selection will be cleared. How can I do this though?

 

addPickingObserver(observer: (eventData: BABYLON.PointerInfo, eventState: BABYLON.EventState) => void): void {
    this._scene.onPointerObservable.add(observer, BABYLON.PointerEventTypes.POINTERPICK);
}


private createDefaultPicker(): void {
    let observer = (eventData: BABYLON.PointerInfo, eventState: BABYLON.EventState) => {
        this._selector.clearSelections();
        if (eventData.pickInfo.hit) {
            let renderModel = this._renderScene.getRenderModel(eventData.pickInfo.pickedMesh);
            let selection = new Selection(new PickingInfoEx(eventData.pickInfo, renderModel));
            this._selector.addSelection(selection);
        }
    }

    this._renderScene.addPickingObserver(observer);
}

 

Link to comment
Share on other sites

Won t help here as we still pick on move:

you can easily do like here: https://www.babylonjs-playground.com/#IEQ92B

var ok = true;
 
scene.onPointerObservable.add(function()
{
ok = true;
}, BABYLON.PointerEventTypes.POINTERDOWN);
 
scene.onPointerObservable.add(function()
{
ok = false;
}, BABYLON.PointerEventTypes.POINTERMOVE);
 
scene.onPointerObservable.add(function()
{
if (ok) {
alert();
}
}, BABYLON.PointerEventTypes.POINTERUP);
Link to comment
Share on other sites

Hi @BlackMojito

If i understood correctly, believe you're in need of a pointer cache.
This will allow you to pick with single clicks (including failed picks) and ignore picking on panning, etc,
clickSensibility controls how much the pointer is allowed to move while still considdering it a picking click. 

http://playground.babylonjs.com/#XZS5CB#4

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...