Start a new topic

How to get .wto file (object tracking ) from web service using android javascript API

Hi,

How to get .wto file (object tracking ) from web service using android javascript API?

Because on the Wikitude sample we need to import our .wto file.

All I need is my project can automatically get the new .wto file that I uploaded on my web service.


I'm using Wikitude SDK Android 8.10


Thanks


Hi Sarah,


you can also store the .wto file on your servers and load it from there (You just need to put the server url of the .wto file once you create the TargetCollectionResource --> AR.TargetCollectionResource("https://.....",....


Thx and greetings

Nicola



1 person likes this
Hi, Nicola Thankyou for the answer. I have one more question, how about make the different augmentation for each object inside the .wto file? I've try this case using unity, but I've no idea how to solve this using android javascript API. Thanks

Hi,

Let me explain about the project that I will make and the issue that I need to solve. 

 


1. I need to add new objects to the .wto file periodically, when there are new objects, I have to download a new .wto file and upload it to the web service. The function is that every time there are additional objects, I don't need to change the code or re-import the .wto file manually .


2. I don't display object 3d as augmentation. I display the description text of each detected object (each object has a different description). this also required to new objects added to the .wto file. I think it's almost like cloud recognition. But I need object detection not image detection.

 

What should I do to resolve the issue?


Regards

Sarah

Hi Sarah,


When you have created an ObjectTracker, then you will have to create an ObjectTrackable that let you to draw an augmentation for the .wto file. If you have more than one object to track inside the .wto file, you can create as many ObjectTrackables as objects are in the file:


this.objectTrackable = new AR.ObjectTrackable(this.tracker, "NAME_OF_THE_OBJECT_TO_TRACK", {
    drawables: {
        cam: [...]
    }
});


Take a look at the API reference:  https://www.wikitude.com/external/doc/documentation/latest/Reference/JavaScript%20API/classes/ObjectTrackable.html  and you will see that you can create an ObjectTrackable that points to an specific object of the TargetCollection you are loading and then, draw an augmentation that depends direcly on that object.


Regards,


Aitor. 

Hi, Aitor Thanks for the answer, but I'm sorry I think you don't get what I mean. Based on your explanation, all of my object target must be declared on the code. So, everytime I add the new object target, I need to modify my code too. But in my case, I need the code that don't need to modify everytime I add more object on my target collection. It means like my code automatically know that there's a new object, without I'm telling it. Most likely the cloud recognition. I really need to know is that possible to do something like that? Thanks Regards, Sarah

Hi Sarah,


We don't provide that kind of service by our own, but it could be possible if alongside you .wto file, you have another file (a json for example) which lists the targets and their descriptions. In your code, you could download the .wto + the json files and iterate through it, adding an ObjectTrackable for each item.


Regards,


Aitor.

Hi Aitor,


Thanks fot the solution that could be possible to do. But I don't really understand how to do this statement 


"In your code, you could download the .wto + the json files and iterate through it, adding an ObjectTrackable for each item"


Could you hep me with an example what should I do and where should I put my code in Android Studio or javascript file? I really need your help.

Thank You


Regards,

Sarah.

Hi,


As you mentioned previously, you have a .wto file uploaded to a web service which is updated everytime you need to add some objects. In the same way, you could have a .json file uploaded to a web service that contains the list of the targets and their descriptions. Once both are downloaded, you just need to iterate the .json file, and for every item that exists, create an ObjectTrackable in the same way we are doing in the Wikitude Sample app, attaching the description that is in the .json file.


Regards,


Aitor.

Hi, I know generaly what I sould do, but I don't really understand how to implement that condition into my code. Could you give me an example code based on that condition? For the .wto files I just need to put my link on the TargetCollectionResource, right? but for the .json files where sould I put the link? and how to iterate it on javascript? I'm sorry because I really new in this. Thank you Regards, Sarah.

Hi Sarah,


For the .wto file you are right you should put the link on the TargetCollectionResource. For the .json file we don't provide anything to handle it, so it should be handled by yourself. This could be an example:


this.targetCollectionResource = new AR.TargetCollectionResource("file_name.wto", {
            onError: World.onError
        });

        this.tracker = new AR.ObjectTracker(this.targetCollectionResource, {
            onError: World.onError
        });

for (var i = 0; i < jsonItems.length; i++) {
        this.objectTrackable = new AR.ObjectTrackable(this.tracker, jsonItems[i].itemId, {
            drawables: {
                cam: createDescriptionDrawable(jsonItems[i].description,
            },
            onObjectRecognized: World.objectRecognized,
            onObjectLost: World.objectLost,
            onError: World.onError
        });
}


The previous code i sent is a modification of the SimpleObjectTracking sample that is in the example project we provide:  https://www.wikitude.com/download-wikitude-sdk-for-android/. The difference is, after you get the .json file in the javascript code, you can iterate it and create different objectTrackables depending of the id that it should be tracking from the .wto file. Once you know which item you have, you can add a drawable from it (in this case the description).


Regards,


Aitor.

Login or Signup to post a comment