Ar.js: Event when a marker is found

Created on 27 Jun 2017  路  9Comments  路  Source: jeromeetienne/AR.js

is it possible to have a call back end a marker is found / lost?

For example I'd like to play a sound when a marker is found

Most helpful comment

Yes, it is possible. Not a callback though
Just do this

if(document.querySelector("a-marker").object3D.visible == true)

Furthermore I think an event should be emitted but the above works well too.

All 9 comments

Yes, it is possible. Not a callback though
Just do this

if(document.querySelector("a-marker").object3D.visible == true)

Furthermore I think an event should be emitted but the above works well too.

Thanks!

in the aframe-ar.js, and the artoolkit-webvr-polyfill.js there is a listener for the getMarker event, isn't it possible to catch it somehow by listening to a marker or any of the components ?

There is an event in the back 'markerFound'. but im not how well it is supported at the moment.
I do agree that even is better. Just a matter of testing and all.

https://github.com/jeromeetienne/AR.js/blob/master/three.js/threex-armarkercontrols.js#L109

it is used in deadreckoning

    artoolkitMarker.addEventListener('markerFound', function(event){
               // ...
    })

Is there a way to stop tracking my object after the marker found?
lets say you have a marker hiro, once the camera found it, a 3d object like a cube shows up,
But if we moving the phone and the markers no longer visible, the cube should still be there and the user can go around it. Is this possible to do with this frame work?

If you want to keep the object on screen after the marker is no longer visible you might be interested in this answer (basically changing your "a-marker" to "a-marker-camera").

Is there a way to stop tracking my object after the marker found?
lets say you have a marker hiro, once the camera found it, a 3d object like a cube shows up,
But if we moving the phone and the markers no longer visible, the cube should still be there and the user can go around it. Is this possible to do with this frame work?

Hey,
Did you solve the problem?

Hello,
I use custom markers and managed to perfectly detect if the 3d object is visible or not on mobile android. On the other hand nothing happens with an ios, the following javascript code does not seem to be activated on ios, did you find this on safari? and have you seen an example that works? Thank you
AFRAME.registerComponent ('registerevents', {
init: function () {
var marker = this.el;
marker.addEventListener ('markerFound', function () {
var markerId = marker.id;
console.log ('! markerFound', markerId);
object_found (markerId);
});

The answer I found here, worked very well for me:
https://stackoverflow.com/questions/44799413/how-to-detect-when-a-marker-is-found-in-ar-js

Basically, there is this latest version which supports the events markerFound and markerLost on marker anchor elements.

I hope it helps.

Was this page helpful?
0 / 5 - 0 ratings