Log in or register to post comments

Deactivate/Activate Datasets for Model target

May 3, 2018 - 1:38am #1

Hi I am using Unity 2017.3.1f1 and latest Vuforia with it.

I am trying to understand Model Target but the documenation I find and posts are all not up to date or just doesn't have my issue described.

I have 3 model targets (which will be many more if this succeeds)

Now, it doesn't seem to work to load 3 model target databases and have them activated since vuforia will throw "Could not activate dataset" on every dataset except the first. I then tried to only activate any 1 of them first and not click in "activate" on the other 2. This worked.

But then when I try to deactivate one dataset and activate the next I always get the same error (could not activate/deactivate dataset)

How on earth should I write code to change the activated dataset in runtime?

I have tried to do something like this;

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

        IEnumerable<DataSet> dataSets = objectTracker.GetDataSets();

        int index = 0;

        DataSet activeDataSet = null;

        foreach(DataSet ds in dataSets)

        {

            if(index == currentIndex)

            {

                activeDataSet = ds;

break;

            }

            else

            {

                index++;

            }

        }

        objectTracker.Stop();

        objectTracker.DeactivateDataSet(activeDataSet);

        models[currentIndex].SetActive(false);

        currentIndex = (currentIndex + 1) % models.Length;

        activeDataSet = null;

        foreach (DataSet ds in dataSets)

        {

            if (index == currentIndex)

            {

                activeDataSet = ds;

break;

            }

            else

            {

                index++;

            }

        }

        objectTracker.ActivateDataSet(activeDataSet);

        objectTracker.Start();

 

But this code does not work! I have tried many versions of the above code but none of them managed to do this. Please help me!

Deactivate/Activate Datasets for Model target

May 3, 2018 - 10:01am #2

Hello ChoArrim,

The following function will disable all active datasets and then activate that dataset passed into the function. It will also set the Model Target activated to use a 2D GuideView.

private void SwapActiveDatasets( string datasetToActivate )
    {
        // ObjectTracker tracks targets contained in a DataSet and provides methods for creating and (de)activating datasets.
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
        IEnumerable<DataSet> datasets = objectTracker.GetDataSets();

        IEnumerable<DataSet> activeDataSets = objectTracker.GetActiveDataSets();
        List<DataSet> activeDataSetsToBeRemoved = activeDataSets.ToList();

        // 1. Loop through all the active datasets and deactivate them.
        foreach (DataSet ads in activeDataSetsToBeRemoved)
        {
            objectTracker.DeactivateDataSet(ads);
        }

        // Swapping of the datasets should NOT be done while the ObjectTracker is running.
        // 2. So, Stop the tracker first.
        objectTracker.Stop();

        // 3. Then, look up the new dataset and if one exists, activate it.
        foreach (DataSet ds in datasets)
        {
            if (ds.Path.Contains(datasetToActivate))
            {
                objectTracker.ActivateDataSet(ds);
            }
        }

        // 4. Loop through the trackable behaviours and set the GuideView.
        IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
        foreach( TrackableBehaviour tb in tbs )
        {
            if( tb is ModelTargetBehaviour && tb.isActiveAndEnabled )
            {
                Debug.Log( "TrackableName: " + tb.TrackableName );
                (tb as ModelTargetBehaviour).GuideViewMode = ModelTargetBehaviour.GuideViewDisplayMode.GuideView2D;
            }
                
        }

        // 5. Finally, restart the object tracker.
        objectTracker.Start();
    }

Thanks,

Vuforia Support

Log in or register to post comments