Can I avoid the XRButton ? #220
-
Hello, I am looking to develop an XR app for the meta store through a PWA+WEB XR. Is this possible or is it a limitation of web xr ? Thanks for helping, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
WebXR requires interaction to start a session, so you could place a button beforehand (you'll often see immersive sites have a button gate to get the same permission for audio), and eagerly create a session once granted. Maybe react-xr can export a method to do this. This would be the relevant code: function XRSessionInit() {
const set = useXR(state => state.set)
useLayoutEffect(() => {
let session
try {
navigator.xr
.requestSession('immersive-vr', {
optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers'],
})
.then((session) => {
// Check if unmounted
if (session === null) return
// Otherwise, init react-xr
set(() => ({ session }))
})
} catch(e) {
// Session unsupported
console.error(e)
}
return () => {
session?.end()
session = null
set(() => ({ session }))
}
}, [set])
}
{hasInteraction && (
<Canvas>
<XR>
<XRSessionInit />
</XR>
</Canvas>
)} |
Beta Was this translation helpful? Give feedback.
WebXR requires interaction to start a session, so you could place a button beforehand (you'll often see immersive sites have a button gate to get the same permission for audio), and eagerly create a session once granted. Maybe react-xr can export a method to do this. This would be the relevant code: