How to add event listener in WEBXR immersive ar session

I need to add event listener in immersive ar to rotate the model on y axis, but none of the eventlistener options are working , so far i have tried using

canvas.addEventListener,add eventlistener, xr.baseExperience.sessionmanager.session.addeventlistener, but no of them are working ,

I also tried direclty using scene.onpointerdown etc, but they all are not working in immersive AR,

is there any other way to do this ?

here is the playground https://playground.babylonjs.com/#5KTRDD#81

ping @RaananW

What events are you trying to register? Are you referring to the pointer events you are registering at the end?

You can use Babylon’s pointer system (scene.onPointerObservable) in WebXR, you can then get the type of the pointer event and do what you want with it :slight_smile:

1 Like

It is as you said, I am trying to register pointer events that are written in the end ,which are pointerdown, pointermove and pointer up events , so far i have tried using scene.onpointerdown , scene.onpontermove, scene.onpointerup, but its not working,

thanx for recommendation, I will try scene.onPointerObservable and see if it works

Input sources might not be registered when in AR ((which is then a WebXR limitation). I have to check that and get back you.

In any case you can register the session’s select (and selectstart / selectend) if you want to be sure native events are used. XR doesn’t have pointer events (natively) but select and squeeze events. They are registered on the session object in the session manager.

No, actually the solution you provided worked, it worked scene.onPointerobservable , its working fine , thank you for looking into this matter

1 Like