It would be really nice if we had an action that fires when a user clicks anything other than the mesh the action manager is attached to. This would support, e.g. an unselect action. The only thing I have up with is this, which seems clunky, and doesn’t really leverage actions well. I am aware that I could do the whole thing with pointer observables; however, those fire on every pointer event, including move and we can’t leverage the power of actions. Is there a better way that I’m missing? If not, this would be a great enhancement to have to actions.
// Register an action to track when the pointer enters and exits the
// mesh
this.actionManager.registerAction(new BABYLON.ExecuteCodeAction(
{ trigger: BABYLON.ActionManager.OnPointerOutTrigger },
(e) => {
console.log("Pointer out " + this.id);
this._pointerIn = false;
}
));
this.actionManager.registerAction(new BABYLON.ExecuteCodeAction(
{ trigger: BABYLON.ActionManager.OnPointerOverTrigger },
(e) => {
console.log("Pointer over " + this.id);
this._pointerIn = true;
}
));
// Register a pointer observable to detect clicks on or off the
// mesh. Can't use an action for this as it won't fire when we click off of the mesh
scene.onPointerObservable.add((e) => {
if (e.type === BABYLON.PointerEventTypes.POINTERTAP &&
e.event.button === 0) {
if (this._pointerIn) {
console.log("mesh was picked")
} else {
console.log("something else was picked")
}
}
});
The onAttachedToMeshObservable is actually invoked with an null-mesh for each detach event. However, also for any click on the background. It sounds easy to add a onDetachFromMeshObservable, yet I have no clue, how to even test it with the local Babylon copy after forking. The code should to be changed in here:
and somewhere in the docs.
A question is also whether the “onAttachToMeshObservable” should actually fire upon detaching.
Hi, Hope you are well.
(Once again), your post is quite interesting and might deserve to be looked at.
However, what do you expect from it? I mean you are replying to a 1y old topic marked with a solution.
My advise (if you want to pursue this discussion) would be to open a new topic and eventually a Feature requests so the Team and Community would give it another/fresh look at it. You could link this post as a reference. Else, it might just slip under the radar Of course, my opinion only and have a great day