Start a new topic

MULTIPLE OBJECT TARGETS WITH DIFFERENT AUGMENTATION

What i want to achieve : I take the camera and scan a place. On several scenes, i want to add distinct augmentations. I managed to augment a single scene in. I want to be able to scan different scenes/objects and have different augmentations during the same app run. I do NOT need to have all object augmentation objects appear at the same time. One object at a time is fine for my use case.


What I tried

-I tried adding many ObjectTrackers with different .WTO files and different drawables within their corresponding Trackables but when i edit one Object Tracker, all of them seems to have the same .WTO file and it does not work. 


-Then i tried putting many Targets/Objects into 1 project on Wikitude Studio and downloaded the .WTO file(with many objects in it) and imported it in my Unity project. but i don't know how to put distinct augmentations if i have all the targets in 1 WTO file.


-I tried putting the .WTO file with many objects in it in the ObjectTracker and in it's Trackable, i added a script with this code below(found on Wikitude documentation) but no augmentation at all, nothing works.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Wikitude;

public class ObjectIdentifier : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void OnImageRecognized(ImageTarget recognizedTarget)
    {
        //Debug.Log("ImageTarget ID: "+recognizedTarget.ID+" "+recognizedTarget.Name);
        // Create the custom augmentation.
        // You can use recognizedTarget.Name and recognizedTarget.ID 
        // if you need custom augmentations for each target and instance.
        GameObject newAugmentation = GameObject.Find("mySnowman");

        // Set the newAugmentation to be a child of the Drawable.
        newAugmentation.transform.parent = recognizedTarget.Drawable.transform;


        // Position the augmentation relative to the Drawable by using the localPosition.
        newAugmentation.transform.localPosition = Vector3.zero;
    }
}

 

Can anybody help me with this providing sample codes if available and how to update scripts if needed on Unity. I have a feeling that the scripts need to be changed and adjusted



1 person has this problem

PS: I am using Wikitude Unity extension V 2018.2.18f1 , Wikitude SDK 8.0. Thanks

Hi Etienne Silvio,


Since you are using Unity then you need to go with the second scenario. So you need to have only one .wto file and place all your target objects in there. 


The procedure from then on is the same that would be with having only one object target. You simply follow the instructions here and define for each different target a custom augmentation.


Let me know if you are having issues,

Eva

Hi Eva,


Thanks for your answer. Eventually, i followed the second scenario and have a clear understanding now but now the issue is that, under trackable, i have my 3D models and i am trying to use them to augment my targets but each time a target is detected, all models just pop up.

My codes go like this:


  

public void OnObjectRecognized(ObjectTarget recognizedTarget)
    {

        //label_id = recognizedTarget.ID.ToString();
        label_name = recognizedTarget.Name;
        // Create the custom augmentation.
        // You can use recognizedTarget.Name and recognizedTarget.ID 
        //GameObject newAugmentation = GameObject.Find("mySnowman");

        // Set the newAugmentation to be a child of the Drawable.
        if (recognizedTarget.Name == "pdrive")
        {
            print("pdrive found");
            
     
            snowman.transform.parent = recognizedTarget.Drawable.transform;
            snowman.transform.localPosition = Vector3.zero;
        }
        else if (recognizedTarget.Name == "box") {
            print("box found");
           
            cube.transform.parent = recognizedTarget.Drawable.transform;
            cube.transform.localPosition = Vector3.zero;
        }
        


        // Position the augmentation relative to the Drawable by using the localPosition.
        
    }

  

I got two points to clarity:

1) I really need to add distinct augmentation to different targets. Each time an object is recognized, all my 3D models are used to augment, i see everything! 

I even tried adding several Object Trackable under Object Tracker and it doesn't just as would Image Tracker. I see no documentation at all regarding this purpose.


2) I feel OnObjectLost() is destroying my objects and if it recognizes the same target later, it crashes with a MissingReferenceException...

Note that in the scripts that i have added(shown up), i did not write anything in OnObjectLost()


Please help me with that.

Thanks

Hi, 


OnObjectLost is destroying the recognizedTarget.Drawable, as mentioned here, so any children that are attached to it will be destroyed as well.

The way to deal with this is to implement an OnObjectLost callback and unparent your augmentation from the drawable.


I assume one reason why you are seeing all augmentations, instead of just the one you are interested in, is that they are all visible when the scene starts. By default they should be disabled, and enabled only when they are parented to the drawable. And then, when the object is lost and they are unparanted from the drawable, the augmentation should be disabled again.


Please let us know if this fixes your issues.


Best regards,

Alexandru

Thanks Alexandru,


I did not get what you mean by OnObjectLost callback. I have tried to override it but it just destroys the objects automatically even if i leave the OnObjectLost method empty.


What worked for me is removing this :

 

models_dict["cube"].transform.parent = recognizedTarget.Drawable.transform;
models_dict["cube"].transform.localPosition = Vector3.zero;

 

and just use  models_dict["cube"].SetActive(true) or models_dict["cube"].SetActive(false) to make the augmentations appear and disappear, that is showing one and hiding the remaining objects each time an object is recognized. I don't know if it is the best way to do it or if it might impact on the performance but it's not leaving me with any errors and in OnObjectLost i've just applied ...SetActive(false) on all my objects.


Regards,

Thanks.

          

Hi, Etienne Silvio


I have a similar use case. Did you manage to fix it and do it correctly ?

Regards,

Riken


Hello Riken, I would suggest you to not use the drawable objet to put your augmentations. Rather use the OnObjectLost/OnObjectRecognized event to set active unity gameObjects (thats where you define your augmentations ) . It makes it more manageable . Let me know if you have any other questions. Thanks.
Login or Signup to post a comment