Log in or register to post comments

Assigning different user defined targets to different image targets

May 16, 2013 - 12:34am #1

how do you assign each user defined target to different imagetargets? 

Assigning different user defined targets to different image targ

May 30, 2013 - 2:48pm #9

Also, how do you keep track of which trackable to delete? 

Assigning different user defined targets to different image targ

May 30, 2013 - 1:00pm #8

Also, how are you calling mTargetBuildingBehaviour.BuildNewTarget() ? 

 

This reference in the example BuildNewTarget method pulls a NullReferenceException for multile ImageTargets set to UDT

mCurrentTargetName = string.Format("{0}-{1}", ImageTargetTemplate.TrackableName, mTargetCounter);

 

Assigning different user defined targets to different image targ

May 30, 2013 - 4:33am #7

Hi David, this error shows up for multiple user defined targets:

Duplicate Trackables detected: "". Only one of the Trackables and its respective Augmentation will be selected for use at runtime - that selection is indeterminate here.
UnityEngine.Debug:LogWarning(Object)
SceneManager:CheckForDuplicates(IEditorTrackableBehaviour[]) (at Assets/Editor/QCAR/Scripts/SceneManager.cs:517)
SceneManager:EditorUpdate() (at Assets/Editor/QCAR/Scripts/SceneManager.cs:203)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Assigning different user defined targets to different image targ

May 16, 2013 - 5:51pm #6

Perhaps I'm confused as to what you're trying to accomplish, but the method I've described is very easy to implement.

You can add another ImageTarget prefab instance to your scene, define it as a User Defined type, and name the instance so that you can obtain it using GameObject.Find(). Add a model to confirm that you're getting the right target.

Let's say you have an ImageTarget named  AlternateUDT in the scene.

private ImageTargetBehaviour altImageTarget;

...

    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);
            }
        }
		
		if( mBuiltDataSet.GetTrackables().Count() == 0 ){
	        // get predefined trackable and instantiate it
	        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);
	
	        // add the duplicated trackable to the data set and activate it
	        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);
		}else{
			
			altImageTarget = GameObject.Find("AlternateUDT").GetComponent<ImageTargetBehaviour>();
			
			mBuiltDataSet.CreateTrackable( trackableSource , altImageTarget.gameObject );
		}

        mTargetCounter++;

        // activate the dataset again
        mImageTracker.ActivateDataSet(mBuiltDataSet);

    }

 

So in the code above, the first UDT instance will be assigned the template and the second will use the AlternateUDT ImageTarget.

Is that what you're trying to accomplish?

Assigning different user defined targets to different image targ

May 16, 2013 - 3:07pm #5

Have you tested this to work? If so, how do you get the other user defined targets to not also collide with the same imagetarget? It seems all the user defined targets show up on the same image target?  

 

Can you include the unity scene file or export package

 

DavidBeard wrote:

Take look at the UserDefinedTargetEventHandler.cs file that's included w/ the UDT sample, specifically the OnNewTrackableSource method. This shows you how to access the active trackables and how they are identified. Each is a distinct trackable w/ a corresponding ImageTargetBehaviour. If you want to associate a given UDT trackable with a distinct ImageTarget instance, you can implement that here by instantiating that ImageTarget rather than the template.

 

Assigning different user defined targets to different image targ

May 16, 2013 - 2:27pm #4

Take look at the UserDefinedTargetEventHandler.cs file that's included w/ the UDT sample, specifically the OnNewTrackableSource method. This shows you how to access the active trackables and how they are identified. Each is a distinct trackable w/ a corresponding ImageTargetBehaviour. If you want to associate a given UDT trackable with a distinct ImageTarget instance, you can implement that here by instantiating that ImageTarget rather than the template.

 

    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);

        // add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        mTargetCounter++;

        // activate the dataset again
        mImageTracker.ActivateDataSet(mBuiltDataSet);

    }

 

Assigning different user defined targets to different image targ

May 16, 2013 - 2:02pm #3

I guess what I mean is how do you identify each user defined target that has been detected, to assign it to a different image target? Is it possible to do such?

Assigning different user defined targets to different image targ

May 16, 2013 - 2:02am #2

Hi, a user defined target is an Image Target;

so, can you clarify your question ?

Log in or register to post comments