korrbit
korrbit

Reputation: 57

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?

Upvotes: 0

Views: 1711

Answers (2)

Thushara Buddhika
Thushara Buddhika

Reputation: 1820

Hope this may help someone who use react-three/fiber,

import { useThree } from "@react-three/fiber";

const { gl } = useThree();

gl.xr.isPresenting

Upvotes: 0

Mugen87
Mugen87

Reputation: 31086

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

renderer.xr.isPresenting()

Upvotes: 7

Related Questions