Keep models 3D or videos always visible using MindAR

ingcarlosreina solucionando el problema de MindAR donde los objetos no se mantienen en pantalla sin marcador
Keep objects always visible Augmented Reality Tutorial using MindAR

One of the most frustrating default behaviors in WebAR development (specifically with libraries like MindAR or A-Frame) is content volatility: the moment your camera loses the image target, your 3D model or video vanishes instantly.

For many simple experiences, this logic holds up. But what if you are building a more immersive experience?

  • What if you want a video to keep playing while the user looks around?.
  • What if you want to Ā«freezeĀ» a 3D model in mid-air so the user can inspect it closely without holding their phone perfectly still over a card?.

If you’ve tried to solve this using arSystem.pause(true), you probably hit a wall: it pauses the video, but it also kills the tracking engine, making it impossible to recover the target later.

Take a look at the pull requests on the MindAR GitHub:

In today’s post, I’m going to explain the Ā«Decoupling ArchitectureĀ» we used to solve this problem effectively.

The Problem: The Parent-Child Trap

In 99% of MindAR tutorials, you are taught to structure your HTML like this:

<a-entity mindar-image-target="targetIndex: 0">
<!-- The model is a CHILD of the target -->
<a-gltf-model src="#myModel"></a-gltf-model>
</a-entity>

The logic is simple: The Target is the parent. When MindAR detects the target is lost, it sets visible=»false» on the parent. By inheritance, every child inside that entity also becomes invisible.

Looking to create custom .mind targets for your MindAR projects? Check out the link below.

The Solution: The «Decoupling» Secret

To achieve persistence, we must break this family relationship. The content cannot be a child of the target; it must be its sibling.

Instead of nesting, we place the content directly in the scene root (<a-scene>). Then, we create a custom relationship script that acts like a manual «magnet.»

  • When Target Found (targetFound – Event): We turn the magnet ON. The content snaps to the target’s position and follows it.
  • When Target Lost (targetLost – Event): This is the key. Instead of hiding the object (the default behavior), we simply turn the magnet OFF.

The result? The object stops moving but remains rendered in the 3D world at the last known coordinate where the marker was seen. It stays «frozen» in reality, waiting for you to find the marker again.

šŸ”’ Want the code?

Below, I provide the full, copy-paste solution, including:

  • The correct HTML structure to decouple your assets.
  • The custom A-Frame Component (follow-target) that handles the Ā«magnetĀ» logic.
  • The precise Event Listeners to handle the freeze/unfreeze mechanic without breaking the AR engine.

Join my Patreon to unlock the full tutorial and source code below (Click the image)! šŸ‘‡

logo de realidad aumentada empezando desde cero y patreon
Realidad Aumentada Empezando Desde Cero y Patreon

Check this out:

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll al inicio
0
Would love your thoughts, please comment.x
()
x