Log in or register to post comments

Assigning a dataSet to an ImageTracker

March 21, 2013 - 3:15am #1

Hello,

 

I managed to load a dataset, using imageTracker.CreateDataSet(); and dataset.load(..)

Something like what can be found here : https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/loading-datasets-external-scources

But I can't find how to assign this to an ImageTracker, either new or already  present (new would be better!).

ImageTargetBehaviour.Trackable and ImageTargetBehaviour.ImageTarget are read only, I suppose this is not the way to do this.

I don't really see the point of being able to load a dataSet at runtime if you can't use it afterwards so I suppose this is possible. Could you help me there ?

 

Thanks a lot for helping

Assigning a dataSet to an ImageTracker

February 28, 2014 - 3:18am #9

Im able to update the .dat and .xml file from server.

Yes this should be possible at run-time

 

But I got no clue how to update image of image target.

Well, at run-time this makes no difference, because the texture of the Image Target is not used at run-time.  It is only used at design time i.e. in the Unity editor so that you can configure your scene and augmentations correctly.

 

FYI The image target textures are held in Assets/Editor/QCAR/ImageTargetTextures

 

HTH

N

Assigning a dataSet to an ImageTracker

February 27, 2014 - 5:48pm #8

Hi, thank you for your reply. I appologize for not making it clear and my poor english . What I trying to do now is making a dataset that able to update from my own server instead of using cloud database.

Im able to update the .dat and .xml file from server. But I got no clue how to update image of image target.

The code below is what i tried to replace the target's image to other image on runtime. Please refer to the image I attached on this post if I am still confusing you, Sorry. The highlighed text is the code i try to replace the image;

The code:

public Texture2D mat;

private void AttachContentToTrackables(DataSet dataSet)
{
             IEnumerable<TrackableBehaviour> trackableBehaviours =
             TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
 
             foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)
             {
                          string name = trackableBehaviour.TrackableName;
                          Debug.Log ("Trackable name: " + name);
 
             if (name.Equals("01_LittleStarz")&& !ObjectCreated)
             {
                         GameObject go = trackableBehaviour.gameObject;
                         Component[] components = go.GetComponents<Component>();
                         
                         go.name = "Jinggo Target";
                         go.AddComponent<DefaultTrackableEventHandler>();
                         go.AddComponent<MeshRenderer>();
                         go.renderer.material.mainTexture = mat;
                         Debug.Log("Texture: "+go.renderer.material.mainTexture);
 
                         GameObject jinggo = Resources.Load("Prefabs/Jinggo Prefab") as GameObject;
                         Instantiate(jinggo);
                         GameObject goJinggo = GameObject.Find("Jinggo Prefab(Clone)");
 
 
                         goJinggo.transform.parent = trackableBehaviour.transform;
                         goJinggo.transform.localScale = new Vector3(50.0f, 50.0f, 50.0f);
                         goJinggo.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
                         goJinggo.transform.localRotation = Quaternion.identity;
                         goJinggo.active = true;
                          trackableBehaviour.gameObject.active = true;
                          ObjectCreated = true;
           }
}

 

AttachmentSize
Image icon Sample.jpg216.52 KB

Assigning a dataSet to an ImageTracker

February 27, 2014 - 4:01am #7

In future it is probably better if you start a new thread rather than attempt to reuse an existing one, as this causes confusion and makes things unclear.

 

A couple of things that might help:

How to iterate through datasets:  https://developer.vuforia.com/forum/creating-ar-trackables/imagetrackergetactivedatasets-returns-0-elements

Trackable documentation: https://developer.vuforia.com/resources/api/unity/interface_trackable

...which shows the "Name" member which is the name of the Trackable identified.

 

And how can i replace the image/texture of the image target from my downloaded image?

I do not understand what you mean or what you are trying to do.  Take a step back and explain clearly what the problem is, what you have tried, and why you think it is not working.

 

thanks

N

 

Assigning a dataSet to an ImageTracker

February 26, 2014 - 5:53pm #6

I have the same problem assigning the image target dataset on runtime. If my dataset contains more than one image target, how can i know which one is assigned to the object I created using the method u mentioned here? 

And how can i replace the image/texture of the image target from my downloaded image?

My code as below......

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private bool mLoaded = false;
private DataSet mDataset = null;
string BookName;
 
 
void Start () {
 
BookName = PlayerPrefs.GetString("BookName")+".xml";
 
}
// Update is called once per frame
void Update () {
 
if (QCARRuntimeUtilities.IsQCAREnabled() && !mLoaded) {
 
string externalPath = Application.persistentDataPath+"/"+"gempakscan.xml";
 
if (mDataset == null) {
// First, create the dataset
ImageTracker tracker = TrackerManager.Instance.GetTracker<ImageTracker>();
mDataset = tracker.CreateDataSet();
}
 
if (mDataset.Load(externalPath, DataSet.StorageType.STORAGE_ABSOLUTE)) {
mLoaded = true; 
ActivateDataSet("gempakscan.xml");
AttachContentToTrackables(mDataset);
Debug.Log("Data set loaded!");
}
else {
Debug.LogError ("Failed to load dataset!"); 
}
}
}
 
private void AttachContentToTrackables(DataSet dataSet)
{
// get all current TrackableBehaviours
IEnumerable<TrackableBehaviour> trackableBehaviours =
TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
 
// Loop over all TrackableBehaviours.
foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)
{
// check if the Trackable of the current Behaviour is part of this dataset
if (dataSet.Contains(trackableBehaviour.Trackable))
{
GameObject go = trackableBehaviour.gameObject;
 
// Add a Trackable event handler to the Trackable.
// This Behaviour handles Trackable lost/found callbacks.
go.AddComponent<DefaultTrackableEventHandler>();
 
// Create a cube object.
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
 
// Attach the cube to the Trackable and make sure it has a proper size.
cube.transform.parent = trackableBehaviour.transform;
cube.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
cube.transform.localPosition = new Vector3(0.0f, 0.35f, 0.0f);
cube.transform.localRotation = Quaternion.identity;
cube.active = true;
trackableBehaviour.gameObject.active = true;
}
}
}
 
 
 
private void ActivateDataSet(string datasetPath)
{
//ImageTracker tracks ImageTargets contained in a DataSet and provides methods for creating, activating and deactivating datasets.
ImageTracker imageTracker = TrackerManager.Instance.GetTracker<ImageTracker>();
IEnumerable<DataSet> datasets = imageTracker.GetDataSets();
 
IEnumerable<DataSet> activeDataSets = imageTracker.GetActiveDataSets();
List<DataSet> activeDataSetsToBeRemoved = activeDataSets.ToList();
 
//1. Loop through all the active datasets and deactivate them.
foreach(DataSet ads in activeDataSetsToBeRemoved) {
Debug.Log("DeactivatedDataSetName: "+ads.Path);
imageTracker.DeactivateDataSet(ads);
}
 
//Swapping of the datasets should not be done while the ImageTracker is working at the same time.
//2. So, Stop the tracker first.
imageTracker.Stop();
 
//3. Then, look up the new dataset and if one exists, activate it.
foreach(DataSet ds in datasets) {
 
if(ds.Path.Contains(datasetPath)) {
Debug.Log("ActivatedDataSetName: "+ds.ToString());
 
imageTracker.ActivateDataSet(ds);
 
AttachContentToTrackables(ds);
}
}
 
//4. Finally, start the image tracker.
imageTracker.Start();
}

Assigning a dataSet to an ImageTracker

March 21, 2013 - 9:20am #5

No problem - glad it all works ....as expected !

N

Assigning a dataSet to an ImageTracker

March 21, 2013 - 9:05am #4

Ok I think I get it : when created, the dataset automatically creates a new TrackableBehaviour!! which it contains of course.

That was clearly not obvious to me. Thank you very much.

Assigning a dataSet to an ImageTracker

March 21, 2013 - 8:54am #3

I forgot to say that, but I already did what you say (activate the set).

My problem is, since there is no TrackableBehaviours/gameobject that are linked to this set in the editor (because it was runtime loaded), the set is activated but produce nothing. But I look at the link you gave me, I see 

 foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)

     {
         // check if the Trackable of the current Behaviour is part of this dataset
         if (dataSet.Contains(trackableBehaviour.Trackable))
         {
 
I don't see how my newly loaded dataset can already contains a Trackable from an older existing trackable behaviour but I will of course try this! I would be glad if you could explain this how this works to me, because it would seem like magic to me! Thanks a lot, I'll be back to tell you if this worked it out for me.
 
What I was trying to do was something like :
GameObject go = GameObject.Find("myName");
ImageTargetBehaviour itbOrig = (ImageTargetBehaviour)lgo.GetComponent("ImageTargetBehaviour");
Then try to make it link to the created dataset, which I was unable
 

Assigning a dataSet to an ImageTracker

March 21, 2013 - 8:41am #2

Hi NicoTony,

You need to use this function:

imageTracker.ActivateDataSet(dataSet);

The dev guide talks about swappable databases here:

https://developer.vuforia.com/resources/dev-guide/swappable-databases-unity

 

HTH

N

Log in or register to post comments