Hey, im trying out webXR with ThreeJs. Currently Im creating the VRButton and can enter the vr world and everything works well. But what I dont find on the web is how to get the navigator or the XRSession.
And further on how to get events from XRSession. I need to know when the user exits VR.
this is my onClick function which gets fired when clicking on VRButton.
private onClick() {
Globals.vrEnabled = !Globals.vrEnabled
this.sceneSetup.renderer.setAnimationLoop(this.xrRenderLoop.bind(this))
this.sceneSetup.xrSession = this.sceneSetup.renderer.xr.getSession() // getSession() return null
// Results in: VR SESSION null true
console.log('VR SESSION', this.sceneSetup.xrSession, this.sceneSetup.renderer.xr.isPresenting)
// Error because XRSession is null
this.sceneSetup.xrSession.addEventListener('end', ()=> {
console.log('END OF SESSION - NO VR ANYMORE')
})
}
Problem is that the XRSession returned from getSession() is always null. Why is that? How to get the XRSession properly