Search code examples
three.jsvirtual-realitywebvr

WEBVR and threejs, how can I check whether the user is in VR mode or not?


All the examples and tutorials on the threejs site and elsewhere offer this line:

document.body.appendChild( WEBVR.createButton( renderer ) );

Which adds a nice little button to enter VR mode. But there doesn't seem to be any way to detect whether or not the user has pressed it and entered VR mode or not. And there doesn't seem to be any way to enter VR mode besides using that button. Have I missed something?


Solution

  • You can use the following line of code to check if the XR device has an active session.

    renderer.xr.isPresenting()