oculus go全屏模式自动进入A字框
A-frame automatically entering in full screen mode oculus go
我正在使用 A-frame 构建 VR 网站。我希望无需多次按下 oculus go 上的 'enter-vr' 眼镜即可进入虚拟现实模式。对于我的应用程序,大多数 html(包括 a 场景)都会重新加载(但 header/footer 保留在原位)。对于 pc 浏览器,此代码有效:
HTML:
<a-scene id="eqvrscene">
</a-scene>
<button id="enterVRButton" onclick="$('#eqvrscene')[0].enterVR();"> Enter VR </button>
JS:
$("#enterVRButton")[0].click();
但不幸的是,这对 oculus go 没有任何帮助。有没有人建议如何解决这个问题?
这可能相关也可能不相关,但您的 <a-scene>
标签中有错字。
很难从您的代码中判断出来,但是您确定单击按钮时场景已加载吗?
尝试先监听场景的 loaded
事件,然后为按钮设置监听器:
// Scene entity element
var scene = document.querySelector('a-scene');
// Button element
var enterVRButton = document.querySelector('#enterVRButton');
// Check if scene has loaded, otherwise set up listener for when it does.
if (scene.hasLoaded) {
addButtonListener();
} else {
scene.addEventListener('loaded', addButtonListener);
}
// Add our button click listener.
function addButtonListener() {
enterVRButton.addEventListener('click', function() {
scene.enterVR();
});
}
在A-Frame master
分支中,有一个API用于添加自定义进入VR的按钮,因此可能会在0.9.0
中发布。请参阅 master
文档:https://aframe.io/docs/master/components/vr-mode-ui.html#specifying-a-custom-enter-vr-button
如果您尝试使 click
事件自动化,我认为这在许多浏览器中都行不通,因为 enterVR()
.
需要用户交互
这是不可能的。 WebVR API 不允许自动进入 VR 模式。它需要像点击这样的用户手势,不能像您的示例那样合成。唯一的例外是当页面在用户手势后进入 VR 模式时,新页面被授予在导航后自动进入 VR 的权限。 A-Frame已经考虑到场景,不需要额外的应用代码。
Firefox 还允许在页面重新加载时自动进入 VR。这就是为什么您可能会在桌面上看到不同的行为。您的代码不是必需的,A-Frame auto 已经自动进入 VR。 Oculus 浏览器不包含此案例
我正在使用 A-frame 构建 VR 网站。我希望无需多次按下 oculus go 上的 'enter-vr' 眼镜即可进入虚拟现实模式。对于我的应用程序,大多数 html(包括 a 场景)都会重新加载(但 header/footer 保留在原位)。对于 pc 浏览器,此代码有效:
HTML:
<a-scene id="eqvrscene">
</a-scene>
<button id="enterVRButton" onclick="$('#eqvrscene')[0].enterVR();"> Enter VR </button>
JS:
$("#enterVRButton")[0].click();
但不幸的是,这对 oculus go 没有任何帮助。有没有人建议如何解决这个问题?
这可能相关也可能不相关,但您的 <a-scene>
标签中有错字。
很难从您的代码中判断出来,但是您确定单击按钮时场景已加载吗?
尝试先监听场景的 loaded
事件,然后为按钮设置监听器:
// Scene entity element
var scene = document.querySelector('a-scene');
// Button element
var enterVRButton = document.querySelector('#enterVRButton');
// Check if scene has loaded, otherwise set up listener for when it does.
if (scene.hasLoaded) {
addButtonListener();
} else {
scene.addEventListener('loaded', addButtonListener);
}
// Add our button click listener.
function addButtonListener() {
enterVRButton.addEventListener('click', function() {
scene.enterVR();
});
}
在A-Frame master
分支中,有一个API用于添加自定义进入VR的按钮,因此可能会在0.9.0
中发布。请参阅 master
文档:https://aframe.io/docs/master/components/vr-mode-ui.html#specifying-a-custom-enter-vr-button
如果您尝试使 click
事件自动化,我认为这在许多浏览器中都行不通,因为 enterVR()
.
这是不可能的。 WebVR API 不允许自动进入 VR 模式。它需要像点击这样的用户手势,不能像您的示例那样合成。唯一的例外是当页面在用户手势后进入 VR 模式时,新页面被授予在导航后自动进入 VR 的权限。 A-Frame已经考虑到场景,不需要额外的应用代码。
Firefox 还允许在页面重新加载时自动进入 VR。这就是为什么您可能会在桌面上看到不同的行为。您的代码不是必需的,A-Frame auto 已经自动进入 VR。 Oculus 浏览器不包含此案例