AR.js:如何通过单击按钮启用/禁用相机以及显示/隐藏 AR 内容

Vja*_*jay 5 javascript augmented-reality aframe ar.js

所有通过浏览器演示 AR.js AR 功能的示例和代码在网页加载后即可运行。不过,我想为用户提供一个选项,手动启动和停止扫描过程以及隐藏 AR 内容。

基本上,我想仅在用户单击网页上的按钮时加载 a-frame、AR.js 脚本和其他 a-frame html 元素。

请告诉我 AR.js 中是否有任何参数可以传递以表明用户启动相机/扫描/显示我们的内容的意图。


脚本版本:
A-Frame 版本:0.7.1(日期 18-10-2017,提交 #b9a751e)
三个版本:^0.87.0
WebVR Polyfill 版本:^0.9.36


Pio*_*ski 1

由于ar.js将相机提要附加到body元素中,因此很难将其包含在典型网站的容器中。我建议:

1)ar在外部.html文件中包含一个场景,因此您可以将其放置在<i-frame>
2) 当单击按钮(或任何其他事件)时创建 iframe,并将其放置在您的网站上:

function addScene() {
  var scene = document.createElement("i-frame")
  scene.setAttribute("src", "ar.html")
  scene.setAttribute("height", "300")
  scene.setAttribute("width", "300")
  document.querySelector("#somecontainer").appendChild(scene)
}
Run Code Online (Sandbox Code Playgroud)

检查一下这个故障