Hi there,
I am currently trying to load and unload datasets, but without any succes thusfar. My projects consist of 12 different databases (each with several ImageTargets) and I need the user to be able to select which one to use. Currently I'm doing this by simply setting the parent of the targets to active and inactive, but this causes the image tracking to work really bad. For this reason I thought loading and unloading datasets would be perfect. Loading a dataset works like a charm, but for some reason I can't seem to find out how to unload a dataset. I think activating and deactivating would be fine as well.
Below is the code I currently use for loading a dataset, something I did find strange though, was that I am not able to edit this method like so; void LoadDataSet(string dataset)
, since it's called like this;
VuforiaARController.Instance.RegisterVuforiaStartedCallback(LoadDataSet);
But that's simply a sidenote.
void LoadDataSet()
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
DataSet dataSet = objectTracker.CreateDataSet();
if (dataSet.Load(dataSetName))
{
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(augmentationObject1);
augmentation.transform.parent = tb.gameObject.transform;
augmentation.transform.localPosition = new Vector3(0f, 0f, 0f);
augmentation.transform.localRotation = Quaternion.identity;
augmentation.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f);
augmentation.gameObject.SetActive(true);
}
else
{
Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>");
}
}
}
}
else
{
Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>");
}
}
And the following to deactivate/destroy the datasets, but this unfortunately isn't working.
private void DestroyDataSets()
{
ObjectTracker imageTracker = (ObjectTracker)TrackerManager.Instance.GetTracker<ObjectTracker>();
List<DataSet> dataSets = imageTracker.GetActiveDataSets().ToList();
for (int i = 0; i < dataSets.Count; i++)
{
StateManager stateManager = TrackerManager.Instance.GetStateManager();
List<TrackableBehaviour> tb = stateManager.GetTrackableBehaviours().ToList();
foreach (TrackableBehaviour t in tb)
{
if (dataSets[i].Contains(t.Trackable))
{
stateManager.DestroyTrackableBehavioursForTrackable(t.Trackable, true);
}
}
imageTracker.DeactivateDataSet(dataSets[i]);
imageTracker.DestroyDataSet(dataSets[i], true);
}
}
Hi,
Hi,
In order to de-activated the dataSet you would first need to stop the objectTracker and only afterwards de-activate it.