Topic locked

ImageTargetBehaviour - change just image target, not dataset, help please!

September 18, 2013 - 4:17pm #1

Hi there!

I have a problem.

 

I have a dataset with 20 imageTargets, so far so good, if I define manually, in the edtor, the Image Target I want to use, that works fine, lets say it's named track01.

 

Now in runtime I want to change, within the same ImageTarget object, in it's ImgeTargetBehaviour, the image target defined, so I can use track02.

 

Both image targets are inside the same data set, but i don't know how can I chage form 1 image target to another in the same dataset.

 

I've looked all over the forums here and with google and inside Unity forums, but I can't find anything.

 

Help please!

 

Cheers.

ImageTargetBehaviour - change just image target, not dataset, he

March 23, 2015 - 11:21pm #7

Hi AlessandroB,

                           this script work only for display target name in console only, but it doesn't create object for different target

                          Please help me

ImageTargetBehaviour - change just image target, not dataset, he

September 22, 2013 - 10:32am #6

Glad to help!

ImageTargetBehaviour - change just image target, not dataset, he

September 22, 2013 - 9:19am #5

Thank you very much!!!

That was exactly what I was looking for! :)

I've evolved it to change everything and adapt it to my content, it's perfect.

Again, thank you very much!

 

Cheers!

ImageTargetBehaviour - change just image target, not dataset, he

September 19, 2013 - 1:41am #4

You can also create targets programmatically; for instance, based on the desired name of the target that you want to augment, you could intercept that specific target and attach an augmentation (e.g. a 3D model) on the fly;

then you can change the name that you want to augment at runtime; the following snippet shows a possible way to do this:

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

public class DynamicTargets : MonoBehaviour {
	
	private bool mChipsObjectCreated = false;
	
	
	// Update is called once per frame
	void Update () 
	{
		IEnumerable<TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager().GetActiveTrackableBehaviours();
 
		// Loop over all TrackableBehaviours.
		foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)
		{
			string name = trackableBehaviour.TrackableName;
			Debug.Log ("Trackable name: " + name);
			
			if (name.Equals("chips") && !mChipsObjectCreated)
			{
				// chips target detected for the first time
				// augmentation object has not yet been created for this target
				// let's create it
				GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
				// attach cube under target
				cube.transform.parent = trackableBehaviour.transform;
				
				// Add a Trackable event handler to the Trackable.
                // This Behaviour handles Trackable lost/found callbacks.
                trackableBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();
				
				// set local transformation (i.e. relative to the parent target)
				cube.transform.localPosition = new Vector3(0,0.2f,0);
				cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
				cube.transform.localRotation = Quaternion.identity;
				cube.gameObject.SetActive(true);
				
				mChipsObjectCreated = true;
			}
		}
	}
}

You can attach such a script to the ARCamera in your scene.

 

ImageTargetBehaviour - change just image target, not dataset, he

September 19, 2013 - 12:07am #3

what happens if in the future I need to change the dataset and assign different targets, or if right now I have 20 imageTargets, but in the future I may change programatically the dataset, download a new one as a package and enable it, but this new dataset has 30 image targets.

 

How can I define the image targets from 20 to 30?

 

Unless I can create an imageTarget programatically, I won't be able to support those new imageTargets.

 

In fact I need to know how to change the image target in my actual Image target object, because in my app I just need one imageTarget object, and in the future I won't be able to know how many targets I will have, it will be defined by an xml file, the targets are always going to be local, but I have to be able to change from an old one to another.

 

Is that not possible?

 

Cheers.

ImageTargetBehaviour - change just image target, not dataset, he

September 18, 2013 - 11:47pm #2

You can achieve this by creating more targets in your scene, and assigning each a different target; then at runtime you can enable/disable specific targets (just enable / disable their gameObject).

 

Topic locked