three.jsaframewebxr

A-frame exit vr mode on function


I am wondering using A-frame (https://aframe.io) how I can get a user to exit vr mode if they're in vr mode when a function called myFunction() occurs. Just for clarification. When a function called myFunction() occurs, if the user isn't in vr mode, there won't we an effect but if the user is in vr mode, they will be exited from vr mode. How can this be done?


Solution

  • This code worked for me,

    import {useThree} from "@react-three/fiber";
    
    const ABC = ({ x, y, x}) => {
    
        const { gl } = useThree();
    
        const exitXR = async (gl) => {
            const session = gl.xr.getSession();
            if ( session !== null ) {
                await session.end();
            }
        }
        
    return (
            <group>
                <Html>
                    <div onClick={()=>exitXR(gl)}> EXIT </div>
                </Html>
            </group>
        )
    }