jeromeetienne / AR.js

Efficient Augmented Reality for the Web - 60fps on mobile!
MIT License
15.79k stars 2.22k forks source link

Need a way stop AR on a-scene unloading #255

Closed paztis closed 5 years ago

paztis commented 6 years ago

Currently, when we remove the dom element, all 3d is stopped. But the video and the overlay helpers (markersAreaEnabled and trackingBackend) are still present. If I restart again the AR, new overlay helpers arppears near the first one.

Is there a way to stop properly the AR (ie stop video, remove overlays, destroy ARController, ...) ? I really need it to display/hide the AR in an applicaiton lifetime.

paztis commented 6 years ago

I was trying to access to the ARCotroller without success on my code (because it's created automatically by the a-frame tag. No root accessor of the arController instance on window)

But I just found an accessor : aSceneEl.systems.arjs._arSession.arContext.arController.dispose()

Hard to access it ^^ I try to access to the video also now.

But the graphic helpers are still on the screen.

The library is not really planned to do this. Everything is accessible to start AR, but then nothing during its lifetime...

paztis commented 6 years ago

another problem is the video resize interval continue to run: var timerId = setInterval(function(){ if( Date.now() - startedAt > 10000*1000 ){ clearInterval(timerId) return } // onResize() window.dispatchEvent(new Event('resize')); }, 1000/30)

So if I remove manually the video element, it crashes. And more after AR suppression it continues to run

Is it possible to reflect about a proper way to load / unload the controller ?

paztis commented 6 years ago

In fact it seems that all the window resize handlers are persistant. On each window resize (real ones or triggered ones) there's multiple functions that tries to exec on already deleted obejcts, (dom, video element, canvas, ...) and it always throws exceptions So there's really no way to stop properly an instance here

Vamoss commented 6 years ago

I am also looking for it, the component doesn't seem to be built for single page apps. I also couldn't find a way to trigger the capture start, once you add aframe-ar.js in your html, it start capturing. Even when you don't have the <a-scene arjs> instantiated. So, we will move forward to change the component itself to add these features. I am not will be a solution.

letsrock85 commented 6 years ago

Yep, I am looking for it as well. Any updates/luck to have this be solved?

AndiDomi commented 6 years ago

I'm using Vue.js 2 and had the exact same problem. The way I did it was to create an iframe pragmatically with <component v-bind:is="get_iframe"></component> which resides inside a <div v-if='create_iframe_true'><div>. If create_iframe_true is true the component gets created and you can access it (also a good solution to resize the video) if not then the iframe is destroyed and the video goes away. Hope this helps

nicolocarpignoli commented 5 years ago

This PR has been closed due to inactivity for over one year. Please open a new, updated issue if the problem or the question is still relevant.

frederic-bonjour commented 2 years ago

Hi! Same problem here: I need to remove the scene/camera from the DOM after the marker has been detected. I'm using Vue. Thank you very much!