Can anyone point me to a code example for adding a custom event listener to the VR and AR Buttons to detect between immersive-ar and immersive-vr sessions? Is there something like sessionstart and sesssionend event listener that I can call? If not, how would I extend the current ARbutton or VRbutton scripts to detect?
Can’t you just use this simple pattern?
let xrMode = '';
const button = ARButton.createButton( renderer );
document.body.appendChild( button );
button.addEventListener( 'pointerdown', function() {
xrMode = 'ar';
} );
You do the same for VRButton
but set xrMode
to vr
instead. In this way, you know which button was pressed last.
Excellent! Thank you!
@Mugen87 I got a version of this working and can toggle between VR and AR modes, thanks!
The issues I’m running into now is that when I go from AR mode to VR mode I’m in the floor. I tried directly setting my XRpawn group that I created as well as the camera manually on start/stop but I think it has something to do with local space being set by the ARButton to ground level and I can’t figure out how to force VR mode again when selecting the VRButton?
Any ideas on areas I could look, things to try?
Thanks!
I think I figured out a solution. On ar session end I set the reference space back to local-floor and that seems to work.