如何 运行 iframe 中的 WebVR 内容?

How do I run WebVR content within in an iframe?

我有一个 A-Frame WebVR 场景。我想把它放在 iframe 中。

<iframe src="https://aframe.io/aframe/examples/boilerplate/hello-world/"></iframe>

但是当我进入 VR 时,它不会全屏显示并渲染到 VR 耳机。如何在 iframe 中启用立体 VR?

您必须在 iframe 上设置 allowvr="yes"。如果您转到 https://aframe.io,您会看到所有示例都是 iframed,因此您可以按照他们的示例进行操作。

<iframe allowvr="yes" src="https://aframe.io/aframe/examples/boilerplate/hello-world/"></iframe>

请注意,这还不适用于移动智能手机,因为 iOS Safari 等移动浏览器不允许 iframe 访问设备方向和设备运动传感器。这可以通过 post 向 iframe 发送设备方向数据来解决。这是在 https://github.com/googlevr/webvr-polyfill/issues/173

提交的

一个页面上只能存在一个 <a-scene>。或者,我们可以使用带有 allowfullscreen="yes"allowvr="yes"<iframe>

<iframe allowvr="yes" allowfullscreen="yes" src="https://aframe.io/aframe/examples/boilerplate/hello-world/"></iframe>