hiukim / mind-ar-js

Web Augmented Reality. Image Tracking, Face Tracking. Tensorflow.js
MIT License
2.24k stars 417 forks source link

Show scene when tracking is lost #211

Closed Zaniyar closed 2 years ago

Zaniyar commented 2 years ago

How can I force to make the object visible even on markerlost event? I would like to be able show the scene when tracking is lost.

Wirivera commented 2 years ago

You can force it to reappear once it hides:

    <script>
        document.addEventListener("DOMContentLoaded", function () {
            let target = document.querySelector('a-entity[mindar-image-target]'); //Get ImageTarget
            let delay = 1; // Milliseconds of delay to reactivate

            //target lost event
            target.addEventListener("targetLost", event => {
                console.log("target lost");

                //waiting to reactivate
                setTimeout(function () {
                    target.object3D.visible = true; //making it visible
                }, delay);
            })
        });
    </script>
Zaniyar commented 2 years ago

thx. worked. despite of the thread is closed, but it is a related question: why is target.object3D.position, target.position, camera postion or rotation always (0,0,0)? How could I move the object3D in front of the camera? camera.lookAt(target.object3D.position) is also not working. I want to get the position of the camera (phone?) and the position in the world of the marker.