也许这是一个比我意识到的更简单的问题,但我对 HTML/JS 有点陌生,在我看来这是此代码的一个特定问题。我正在使用 Google VR 查看器在我的网页中嵌入 360 度元素。
他们的文档 here非常简单,如果我也使用托管在谷歌域上的媒体,那么按照他们网站上的布局进行设置就可以正常工作。这是我正在使用的代码,非常好用:
<script src="https://storage.googleapis.com/vrview/2.0/build/vrview.min.js"></script>
<script>
window.addEventListener('load', onVrViewLoad);
function onVrViewLoad() {
vrView = new VRView.Player('#vrview', {
width: '100%',
height: 480,
image: 'https://storage.googleapis.com/vrview/examples/coral.jpg',
is_stereo: true,
is_autopan_off: true
});
}
</script>
但是,我需要将 .js 文件托管在我自己的服务器上,而不是仅仅链接到 Google。所以我尝试下载脚本并使用以下代码,但我无法让它工作。任何人都可以发现问题所在吗?
<script src="build/vrview.min.js"></script>
<script>
window.addEventListener('load', onVrViewLoad);
function onVrViewLoad() {
vrView = new VRView.Player('#vrview', {
width: '100%',
height: 480,
image: '360/coral.jpg',
is_stereo: true,
is_autopan_off: true
});
}
</script>
作为引用,我得到的错误是
Cannot GET /index.html?image=http://127.0.0.1:61060/360/coral.jpg&is_stereo=true&is_autopan_off=true&
谢谢!希望这不是一个太愚蠢的问题。
最佳答案
这确实是缺少有关(存档的)Google VRView 的文档。
您需要从this branch 下载所有文件 VRView repo 协议(protocol)。您可以安全地删除示例文件夹,但保留其他所有内容。将所有这些文件和文件夹放在您站点的子文件夹中。
例如文件夹结构可以是:
yoursite/index.html <-- Your website
yoursite/ <-- Anything else you want, img/, css/, other root .html files
yoursite/googlevr/ <-- all the files from VRView repo
这应该使您拥有 yoursite/googlevr/build、yoursite/googlevr/images 等,以及 googlevr/根目录中的 index.html 和 style.css 文件
在此之后,您可以通过
使用您自己的 index.html(或该文件夹中的任何其他 .html)中的 .js<script src="/googlevr/build/vrview.min.js"></script>
请注意,Google VRView 现在已存档在 Github 中,他们似乎已停止对此的任何支持。另请注意,默认情况下,VR View 在 iOS 12.1 设备和新设备上不起作用,因为默认情况下禁用了设备方向的隐私设置。您的用户需要在其设备设置中手动打开方向传感器。
关于javascript - Google VR View - 托管代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50932050/