我想,当一个标记,如果发现/迷失在ar.js,而使用帧来检测。
从我在source code看到,当标志被发现,一个“getMarker”事件应该被解雇,而且似乎的ARToolKit派遣markerFound事件。
我想听听这些事件在<a-scene>
,或在<a-marker>
,但似乎我现在不是弄错了,或者我需要得到更深层次的arController
,或arToolkit
对象。
当我登录的场景,或标记,我只得到的属性,这似乎并不具有连接上述对象的引用。(如marker.arController
,或marker.getAttribute('artoolkitmarker').arController
)
有没有人尝试这样做,有什么秘诀如何做到这一点?
当一个标记被发现,失去PR303介绍事件
markerFound
markerLost
您可以通过简单地增加一个事件监听器使用它们:
anchorRef.addEventListener("markerFound", (e)=>{ // your code here}
用一个简单的设置是这样的:
<a-marker id="anchor">
<a-entity>
</a-marker>
例如here。请注意,由于09月18' ,你需要使用dev
分公司使用以上。
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
}
}
}
a-marker-camera
, only with a-markers
我用肮脏的黑客潜入内部,切记去什么我提供了可能不足以因为该事件得到的每一个叫做标记被发现的时候,不幸的是我无法找到一个事件挂钩到了标记丢失。
const arController = document.querySelector("a-scene").systems.arjs._arSession.arContext.arController;
arController.addEventListener("getMarker", (evt) => {
const markerType = evt.data.type;
const patternType = 0;
//console.log("onMarkerFound!!");
if (markerType == patternType) {
//console.log("onMarkerFound out pattern!!");
//Do stuff...
}
});