Log in or register to post comments

Multi User Defined Targets

March 26, 2013 - 10:12am #1

Hi everybody.

My problem is quite simple, but i did not found a working solution to do what i want on Unity.

My goal is to create a runtime system which let the user create some diferent User Defined Targets.

"diferent" means "each with an unique content to display"

 

 

for example, the firstOne could display a teapot, and the secondOne a flower.

When the program is running, the user should be able to independently choose where to place the teapot or the flower (Symply by Defining Targets)

Then, when the camera detects the 2 markers in the same frame, both objects should appear above their respectively defined target.

 

 

I need help to understand what is the best strategy, using the existing UDT structure, to avoid conflicts starting from Unity UDT project.

Does anyone have an idee ?

Multi User Defined Targets

October 3, 2017 - 4:58pm #10

Hello, I could tell if they could add the model through the script?? And as they did, try the code AlessandroB but when you add the new code, I do not see any model (object).

Multi User Defined Targets

March 7, 2017 - 8:41am #9

I have the same issue and the current solution is pretty dumb. 

 

I tagged the teapot and iterate over all unneccessary teapots to deactivate them. Deactivating the GameObject on the imageTargetCopy also disables the new model. 

 

Teapots = GameObject.FindGameObjectsWithTag ("Teapot");

  foreach (GameObject Teapot in Teapots)

{

   Teapot.active = false;

  }

Multi User Defined Targets

March 7, 2017 - 7:48am #8

Hi is there really no other option to implement this behaviour? I would like to be able to drag and drop the models from the Inspector onto the script. It seems to be not possible to have more than one ImageTargetTemplate. Other ones do not appear in the inspector. The same is true for GameObjects which I cannot drag onto the script. If I have to load all Models as proposed by AllesandroB each and every GameObjects needs to have the settings set from the UDTEvent Handler. This does not seem the correct way to do it. In particular I want to attatch my script for touch manipulation of objects and I do not know how to do this. 

Multi User Defined Targets

November 20, 2013 - 8:26am #7

Hi AlessandroB

 

I am trying to reproduce your example of the cube, but it is not working.

Actually i am trying to add in my own objects, but it is failing.

If i remove all teh "new code"then i get to see the teapot again.

If i add your "new code" then i see nothing.

I don't get any error reports. so i have no idea why?

maybe did i forget something?

 

I hope you can help me

 

III

Multi User Defined Targets

May 24, 2013 - 7:41am #6

 

Hi Oclamarius / everybody

i have the same problem you had with this code. all models were displayed on first trackable, i kept looking for clue for doing it. but in fact my intention is to have only one imagetarget and be able to change the model displayed at runtime always on the same target. i'm not sure if i should open a new topic for that.

i moved to this code https://developer.vuforia.com/forum/faq/unity-how-can-i-dynamically-swap-3d-model-target?sort=2 (thanks AlessandroB) which adds the cube to my models on my application, without disabling the old model too. (and attached to ARCamera, i think it should be attached to the UserDefined Target).

in my script, i define an 3d models array  private GameObject[] listamodelos = new GameObject[10];

and add all 3d models from my scene to it:

GameObject taza = GameObject.Find("model1");

listamodelos[0] = taza;

...

GameObject palo = GameObject.Find("model10");

listamodelos[9] = palo;

i've tried to use a counter from the model swapper buton on original script to set all scene objects deactivated excepts the counter''s position one. listamodelos[counter].active = true;                                                                                                                                                                  and on void Start() i force to listamodelos[].active = false all models.

i'm not being able to reactivate a previously deactivated model, so the first model is shown but when i press swap button, first get deactivated and the second one is not activated again.

i have two main doubts: should i deactivate UserDefined Target before change the status of their childs? can i re-activate gameobjects on the same Target?

thank you, i hope you could understand what i'm trying to mean.

Multi User Defined Targets

March 27, 2013 - 7:54am #5

Hi

After doing some experiments, I got a problem that i dont understand.

Here the code you gave to me

        // get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);
    
        /////////////////
        // NEW CODE
        // Disable predefined game object
        imageTargetCopy.gameObject.active = false;
        
        // Create a custom game object (for instance a cube)
        // and attach it as child of the ImageTarget
        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube.name = "mycube";
        cube.transform.parent = imageTargetCopy.transform;
        cube.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
        cube.transform.localPosition = new Vector3(0,0,0);
        cube.transform.localRotation = Quaternion.identity;
        cube.active = true;
        ///////////////////////

Now, what i did is to create a Class with a ImageTargetBehaviour list.

Then, each call to OnNewTrackableSource automaticly add a new instance of ImageTargetTemplate to the list.

Now, when i want to add a new model to one of the list Item, i do exactly item.transform.parent = ITBList[i].transform;

but in the facts:
all the items are only displayed on the first trackable ...
i dont understand why, because this system should permit to access each target...
i maybe have forgotten something... (Keeping searching ^^)

 

Multi User Defined Targets

March 27, 2013 - 3:59am #4

Glad to help ;-)

Concerning your other question:

 

Firstly, why desable imageTargetCopy? (i just dont understand)

// Disable predefined game object
imageTargetCopy.gameObject.active = false;

I am not disabling the image target, I'm just disabling the game object attached to it (i.e. the teapot or other 3D model), because then I am attaching a new 3d object (the cube in my example) and I am activating the new object (see "cube.active = true")

So, it's just a way of swapping the old model with the new one.

 

Concerning your last question:

Secondly, in a 3 trackable case, if i want to only modify the second one, keeping the first and the third as before, where could i access this second trackable?

You could probably do this jusy by iterating over the list of trackables in your UDT dataset, and then check the name of each trackable to identify the one that you want to change; see this code:

IEnumerable<Trackable> trackables = mBuiltDataSet.GetTrackables();

Multi User Defined Targets

March 27, 2013 - 2:25am #3

Hello Alessandro

 

Your solution works fine. My previous solution was a target Manager based on the copy/pasting of UserDefinedTarget and UserDefinedTargetBuilder prefabs, but it made my app crash.

Now with your solution, i can choose a trackable list, all tracked in the same time.  Very Good Job, Thank you !!

 

I have a few questions about this new solution :

 

Firstly, why desable imageTargetCopy? (i just dont understand)

// Disable predefined game object
        imageTargetCopy.gameObject.active = false;

 

Secondly, in a 3 trackable case, if i want to only modify the second one, keeping the first and the third as before, where could i access this second trackable?

 

Thank you for your replies.

Multi User Defined Targets

March 26, 2013 - 1:48pm #2

Hi,

your question is quite broad, I will try to give my contribution to some aspects of it:

first, I would start from the UserDefinedTarget sample and make the necessary changes to that;

second, you will need to enable the support of multiple simultaneous targets in your view; this can be done by increasing the Max Simultaneous Image Targets parameter in the QCARBehaviour (which is by default set to 1... so you need to set it set it to 2 or more); you can do that via the Unity Inspector in the Editor

third, if you look at the code in UserDefinedTargetEventHandler.cs, you will find a method called OnNewTrackableSource, which is called whenever a new User Defined Target is created; in that method, you can adjust the code so to add your custom 3D model as a child of the created  ImageTarget; I show here below a simple example of that, which creates a simple Cube object and attach it to the target:

public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        // deactivates the dataset first
        mImageTracker.DeactivateDataSet(mBuiltDataSet);
        
        // Destroy the oldest target if the dataset is full or the dataset 
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= 5)
        {
            IEnumerable<Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
                if (oldest == null || trackable.ID < oldest.ID)
                    oldest = trackable;

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);
	
		/////////////////
		// NEW CODE
		// Disable predefined game object 
		imageTargetCopy.gameObject.active = false;
		
		// Create a custom game object (for instance a cube)
		// and attach it as child of the ImageTarget
		GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
		cube.name = "mycube";
		cube.transform.parent = imageTargetCopy.transform;
		cube.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
		cube.transform.localPosition = new Vector3(0,0,0);
		cube.transform.localRotation = Quaternion.identity;
		cube.active = true;
		///////////////////////
		

Then, instead of creating a simple Cube object like in my sample code snippet, you can of course instantiate any custom Prefab of your desired 3D model.

Once you have done that, each newly created target will be kept in memory togetehr with its associated 3D model, as you defined it above, and so whenever one of those targets is detected again in the view, its associated augementation will show up consistently.

 

I hope this can help you to find your way in this project development.

 

Log in or register to post comments