如何检测何时在AR.js中找到标记 [英] How to detect when a marker is found in AR.js

查看:256
本文介绍了如何检测何时在AR.js中找到标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用a框架在ar.js中发现/丢失标记的时候。

I'm trying to detect when a marker if found/lost in ar.js, while using a-frame.

根据我在源代码 ,应该触发 getMarker事件,而且artoolkit似乎调度了一个markerFound事件。

From what I see in the source code, when the marker is found, a 'getMarker' event should be fired, moreover artoolkit seems to dispatch a markerFound event.

我试图在上监听这些事件; a-scene> ,或在< a-marker> 上,但似乎我错了,或者我需要获取深入到 arController arToolkit 对象。

I tried to listen to those events on the <a-scene>, or on the <a-marker>, but it seems I'm either mistaken, or i need to get deeper to the arController, or arToolkit objects.

当我记录场景或标记时,我仅获得对属性的引用,这些属性似乎没有附加上述对象。(例如 marker.arController marker.getAttribute('artoolkitmarker')。arController

When i log the scene, or the marker, i only get references to the attributes, which don't seem to have the above objects attached.(like marker.arController, or marker.getAttribute('artoolkitmarker').arController)

是否有人尝试过此操作,并且有任何提示如何执行此操作?

Did anybody tried this and have any tips how to do this ?

推荐答案

PR303 会在发现和丢失标记时引入事件

PR303 introduces events when a marker is found and lost


  • markerFound

  • markerLost

  • markerFound
  • markerLost

只需添加事件侦听器即可使用它们:

You can use them by simply adding an event listener:

anchorRef.addEventListener("markerFound", (e)=>{ // your code here}

具有以下简单设置:

<a-marker id="anchor">
  <a-entity>
</a-marker>

示例此处。
请注意,自9月18日起,您需要使用 dev 分支来使用以上内容。



原始答案-如果要手动执行


通过检查是否可以找到标记该标记在需要时可见(其他事件或刻度): if(document.querySelector( a-marker)。object3D.visible == true)

example here. Please note, that as of sep 18', you need to use the dev branch to use the above.


ORIGINAL ANWSER - in case you want to do it manually

Detecting if the marker is found is possible by checking if the marker is visible when needed (other event, or on tick): if(document.querySelector("a-marker").object3D.visible == true)

例如:

init: function() {
   this.marker = document.querySelector("a-marker")
   this.markerVisible = false
},
tick: function() {
   if (!this.marker) return
   if (this.marker.object3D.visible) {
      if (!this.markerVisible) {
         // marker detected
         this.markerVisible = true
      }
   } else {
      if (this.markerVisbile) {
         // lost sight of the marker
         this.markerVisible = false
      }
   }
}



正如adrian li指出的那样,它不适用于 a标记相机,仅用于 a-ma rkers

这篇关于如何检测何时在AR.js中找到标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆