Pio*_*ski 4 three.js artoolkit aframe ar.js
我正在尝试检测何时在ar.js中找到/丢失标记,同时使用a-frame.
从我在源代码中看到的,当找到标记时,应该触发'getMarker'事件,而且artoolkit似乎派遣了一个markerFound事件.
我试图听那些事件的<a-scene>,或上<a-marker>,但似乎我现在不是弄错了,或者我需要得到更深层次的arController,或arToolkit对象.
当我记录场景或标记时,我只获得对属性的引用,这些属性似乎没有附加上述对象.(例如marker.arController,或marker.getAttribute('artoolkitmarker').arController)
有没有人试过这个并有任何提示如何做到这一点?
Pio*_*ski 11
PR303在找到并丢失标记时引入事件
markerFoundmarkerLost您只需添加一个事件监听器即可使用它们:
anchorRef.addEventListener("markerFound", (e)=>{ // your code here}
Run Code Online (Sandbox Code Playgroud)
使用这样的简单设置:
<a-marker id="anchor">
<a-entity>
</a-marker>
Run Code Online (Sandbox Code Playgroud)
这里的例子.请注意,从第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
}
}
}
Run Code Online (Sandbox Code Playgroud)
a-marker-camera,只有a-markers
| 归档时间: |
|
| 查看次数: |
5286 次 |
| 最近记录: |