Log in or register to post comments

Issua loading and activataing new database

July 16, 2017 - 7:17pm #1

Hello, I'm really stuck on this would love some help.



I'm trying to download a database and load it in runtime.

I download the database and use this code to try and activate it. it's pretty much code from this post.

https://developer.vuforia.com/forum/faq/unity-load-dataset-setup-trackables-runtime



it seems to load all the image targets but the database is nowhere to be found. If I add a temp database (one with the same name but no targets that I'm downloading) to the QCAR folder it loads all the image targets but they don't have the image target set correctly, there's only the temp database targets not the new ones I'm trying to load.



this is with the temp database

   http://imgur.com/geJyyOz



when I load it without any database in QCAR it loads all the target objects but they don't have any targets assigned to them.

http://imgur.com/VCUWAVn



<pre class="brush: csharp">

void LoadDataSet()

    {

 

        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

        

        DataSet dataSet = objectTracker.CreateDataSet();

 

  string dataSetPath = streamPath + dataSetName + ".xml";



  debugText.text = dataSetPath + "\n";

  debugText.text += "Dir exists?" + Directory.Exists(streamPath) + "\n";

 

  print("Loading: " + dataSetPath);

  if(!Directory.Exists(streamPath)){

   Directory.CreateDirectory(streamPath);

  }

 

        if (dataSet.Load(dataSetPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) {

            

            objectTracker.Stop();  // stop tracker so that we can add new dataset



            if (!objectTracker.ActivateDataSet(dataSet)) {

                // Note: ImageTracker cannot have more than 100 total targets activated

   

                Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>");

            }



            if (!objectTracker.Start()) {

                Debug.Log("<color=yellow>Tracker Failed to Start.</color>");

            }



            int counter = 0;



            IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();

            foreach (TrackableBehaviour tb in tbs) {

                if (tb.name == "New Game Object") {



                    // change generic name to include trackable name

                    tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName;



                    // add additional script components for trackable

                    tb.gameObject.AddComponent<DefaultTrackableEventHandler>();

                    tb.gameObject.AddComponent<TurnOffBehaviour>();



                    if (augmentationObject != null) {

                        // instantiate augmentation object and parent to trackable

                        GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject);

                        augmentation.transform.SetParent(tb.gameObject.transform,true);

                        augmentation.gameObject.SetActive(true);

                    } else {

                        Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>");

                    }

                }

            }

        } else {

   debugText.text += "<color=red>Failed to load dataset: '" + dataSetName + "'</color>";

            Debug.LogError("<color=red>Failed to load dataset: '" + dataSetName + "'</color>");

  }

}

</pre>

 

Issua loading and activataing new database

July 19, 2017 - 9:56am #3

thanks for the quick response medabit.



I actually found out what the problem was. I was trying to activate the database before it was finished downloading. It seems to be working pretty decently now. thank you.

Issua loading and activataing new database

July 17, 2017 - 1:52pm #2

Hello,

I'm not understanding the issue you're facing. Is it that detection and tracking do not work with the dynamically added device database? Or that the UI representation in the Unity Editor after loading the device database dynamically does not look consistent with what you expected?

Thanks,

Vuforia Support

Log in or register to post comments