@@ -128,8 +128,13 @@ ARjs.Context.prototype.update = function (srcElement) {
128128 }
129129 this . _updatedAt = present
130130
131- // mark all markers to invisible before processing this frame
131+ var prevVisibleMarkers = [ ]
132+
133+ // mark all markers to invisible before processing this frame & store prev state
132134 this . _arMarkersControls . forEach ( function ( markerControls ) {
135+ if ( markerControls . object3d . visible ) {
136+ prevVisibleMarkers . push ( markerControls )
137+ }
133138 markerControls . object3d . visible = false
134139 } )
135140
@@ -145,6 +150,22 @@ ARjs.Context.prototype.update = function (srcElement) {
145150 type : 'sourceProcessed'
146151 } ) ;
147152
153+ // After frame is processed, check visibility of each marker to determine if it was found or lost
154+ this . _arMarkersControls . forEach ( function ( markerControls ) {
155+ var wasVisible = prevVisibleMarkers . includes ( markerControls ) ;
156+ var isVisible = markerControls . object3d . visible ;
157+
158+ if ( isVisible === true && wasVisible === false ) {
159+ window . dispatchEvent ( new CustomEvent ( 'markerFound' , {
160+ detail : markerControls ,
161+ } ) )
162+ } else if ( isVisible === false && wasVisible === true ) {
163+ window . dispatchEvent ( new CustomEvent ( 'markerLost' , {
164+ detail : markerControls ,
165+ } ) )
166+ }
167+ } )
168+
148169
149170 // return true as we processed the frame
150171 return true ;
0 commit comments