Log in or register to post comments

Activate a model target database in Unity

July 3, 2018 - 11:19pm #1

Hi, I looked for two hours in all the topics regarding this argument, but I still don't understand how I can do this.

I'm developing an app in which I have 4 scenes: 1 home with buttons that lead in 3 different model target scenes.

Vuforia doesn't let activate more than one database at a time, so I have to activate the respective databases in the different scenes.

How do I do this?

 

Activate a model target database in Unity

July 8, 2018 - 3:05pm #3

Hi Strasza, thanks for the reply.

What should I do with this script?

I tried to attatch it as a component of the Model target which I want to activate but it doesn't work.

Please be clear, I do not have much time left to finish my project.

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

using System.Linq;

public class ActivateDataset : MonoBehaviour

{

    public void SwitchTargetByName(string activateThisDataset)

    {

        TrackerManager trackerManager = (TrackerManager)TrackerManager.Instance;

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

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

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

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

        //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 working at the same time.

        //So, Stop the tracker first.

        objectTracker.Stop();

        //Then, look up the new dataset and if one exists, activate it.

        foreach (DataSet ds in datasets)

        {

            if (ds.Path.Contains(activateThisDataset))

            {

                objectTracker.ActivateDataSet(ds);

            }

        }

        //Finally, start the object tracker.

        objectTracker.Start();

    }

}

Activate a model target database in Unity

July 5, 2018 - 2:35pm #2

Hello Bibbios,

The following function will disable all active datasets and then activate the specified dataset. I believe this will resolve your issue.

public void SwitchTargetByName(string activateThisDataset)
{
    TrackerManager trackerManager = (TrackerManager)TrackerManager.Instance;
    ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

    IEnumerable<DataSet> datasets = objectTracker.GetDataSets();
    IEnumerable<DataSet> activeDataSets = objectTracker.GetActiveDataSets();
    List<DataSet> activeDataSetsToBeRemoved = activeDataSets.ToList();
        
    //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 working at the same time.
    //So, Stop the tracker first.
    objectTracker.Stop();
        
    //Then, look up the new dataset and if one exists, activate it.
    foreach (DataSet ds in datasets)
    {
        if (ds.Path.Contains(activateThisDataset))
        {
            objectTracker.ActivateDataSet(ds);
        }
        
    }
    //Finally, start the object tracker.
    objectTracker.Start();
}

Thanks,

Vuforia Engine Support

Log in or register to post comments