EddyVerbruggen / nativescript-ar

Augmented Reality NativeScript plugin
https://www.nativescript.org/blog/preview-of-augmented-reality-in-nativescript
MIT License
118 stars 36 forks source link

dynamic trackingImagesBundle #105

Closed felicks closed 3 years ago

felicks commented 3 years ago

Is it in some way possible to use dynamic images that are stored with firebase storage, as tracking image references? Or does it just workes with images that are stored in the App Resources folder?

nickolanack commented 3 years ago

yes you can track images dynamically. I'm assuming that firebase storage just gives you urls...

let image ='https://some image...'
ar.trackImage({
        image: image,
        width:1, //detection is much faster with defined widths (I seem to recall)
        onDetectedImage: (args) => {

          console.log('found image');

          args.imageTrackingActions.addImage({
            position: {
              x: 0, y: -0.1, z: 0
            },
            image: fromFontIconCode("Hello World", new Font('FontAwesome', 100, 'normal', "100"), new Color("black"));
          }).catch(console.error);
        }
      })
nickolanack commented 3 years ago

oops - sorry didn't mean to close this on you...

felicks commented 3 years ago

Thanks a lot @nickolanack. Unfortunatly I get the following error: ERROR Error: 'trackImage' is only supported with trackingMode: IMAGE

here is my code: <AR trackingMode="IMAGE"></AR>

    ngOnInit(): void {
        firebase.getValue('/components')
        .then(result => (this.info = JSON.stringify(result.value)) )
        .catch(error => console.log("Error: " + error));

       setTimeout(() => { this.loaded = true; }, 1000);

        let image ='https://images-na.ssl-images-amazon.com/images/I/61Qdz0MHRrL._AC_SX466_.jpg'

        AR.prototype.trackImage({
            image: image,
            width:1,
            onDetectedImage: (args) => {
            console.log('found Fritzbox');
            }
        })
    }
nickolanack commented 3 years ago

I'm pretty sure that calling trackImage like: AR.prototype.trackImage(...) is the issue.

I think you need to capture the arLoaded event <AR (arLoaded)="arLoaded($event)" arLoaded></AR> then use event.object as your AR instance. ie `event.object.trackImage(...)'

felicks commented 3 years ago

thanks for your help, works like a charm! Do you know if multiple images are supported? @nickolanack

nickolanack commented 3 years ago

Yes, you can track multiple images.

felicks commented 3 years ago

I couldn't get it working just by using an array of URLs. What did I do wrong?

nickolanack commented 3 years ago

you'll have to call .trackImage for each image. ie:

someImageUrls.forEach((url)=>{ 
   ar.trackImage({
        image: url, 
        //...
   });
});