Log in or register to post comments

Multiple Model Targets

January 17, 2018 - 2:08am #1

Hi, everything works awesome with model targets , but I got an issues, I'm not be use multiple model targets in one application.

When i enable two DataSets in vuforia configuration, only one works, is there any way to load data sets run-time? or i can use multiple model Targets  in the first place?

Multiple Model Targets

January 2, 2019 - 3:50pm #15

Multiple Model Targets

January 2, 2019 - 2:10am #14

can you help me how to  stop object tracker and activate it 

Multiple Model Targets

February 14, 2018 - 1:27am #13

Okay, I'll try it :)

 

Thanks for the answer

Multiple Model Targets

February 13, 2018 - 11:32am #12

pflamant wrote:

So we have to change scene to change target? Is there no way to do it in the same scene?

 

I'll try do my own tests on the matter in the next days but an official response would be great :)

It should work in the same scene, but as mentioned by SmartFactoryLab, make sure the ObjectTracker is disabled when performing any loading, activating, and de-activating.

Thanks,

Vuforia Support

Multiple Model Targets

February 13, 2018 - 4:03am #11

I guess, it also works in the same scene (but haven't tried it yet). Most important thing is to stop the objectTracker before changing the dataset and then start it again.

Multiple Model Targets

February 13, 2018 - 1:24am #10

So we have to change scene to change target? Is there no way to do it in the same scene?

 

I'll try do my own tests on the matter in the next days but an official response would be great :)

Multiple Model Targets

February 13, 2018 - 12:53am #9

I was able to solve it now. Supposed you have a main menu scene with a list of 3d targets you want to load dynamically...

- Deactivate the Vuforia Behaviour for this scene

- In the Vuforia Configuration check all the databases you want to load but do not check the "Activate" box.

- On Button Click load a new scene that contains the configured model target game object. In this scene the Vuforia Behaviour is activated.

 

This way it works and you can load/unload as many targets as you want.

Multiple Model Targets

February 9, 2018 - 3:34am #8

Hi,

I also have some problems here. Below you see my script for dynamically activating/deactivating datasets from the Vuforia configuration. But somehow it just doesn't work with my model targets. The targets do not get active. So is there a way to do this? I also attached a screenshot from my database configuration below.

public void SwitchTargetByName(string aName)
{
  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();

  //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 working at the same time.
  //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(aName))
   {
    objectTracker.ActivateDataSet(ds);
   }
  }

  //4. Finally, start the object tracker.
  objectTracker.Start();
}

 

AttachmentSize
Image icon Capture.PNG7.07 KB

Multiple Model Targets

January 24, 2018 - 10:05am #7

saiunity wrote:

Hi,

        I can't find unity API there, can you please share a small script regarding loading & activating multiple Model Target Data bases may be something like onbutton click. It will be really helpful.

 

Thank you,

saikiran

That doc provides pseudo code examples, for specific APIs please refer here: https://library.vuforia.com/content/vuforia-library/en/reference/unity/index.html

Thanks,

Vuforia Support

Multiple Model Targets

January 24, 2018 - 3:26am #6

Hi Saikiran,

I actually did this a few days ago for the HoloLens, but you can use the most part of the code. Just change some events and you are done.

(I tried to use a coroutine so the frame won't freeze, but it seems like it doesn't work)

This code actually switch between two targets, but I'm sure you will be able to build your own functionality with this.

using HoloToolkit.Unity.InputModule;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Vuforia;
using System;
using UnityEngine.SceneManagement;

public class ChangeTarget : MonoBehaviour, IInputClickHandler {

    #region MEMBER_VARIABLES

    private ObjectTracker mTracker = null;
    private DataSet previousSet;
    private DataSet currentSet;
    public string nextTarget;
    public string currentTarget;

    #endregion // PRIVATE_MEMBER_VARIABLES

    protected virtual void Start()
    {
        DontDestroyOnLoad(this.gameObject); //Keep this gameobject alive between scenes
        VuforiaARController.Instance.RegisterVuforiaStartedCallback(GetObjectTracker);

    }


    void GetObjectTracker()
    {
        TrackerManager tm = (TrackerManager)TrackerManager.Instance;

        Debug.Log(tm.ToString());
        Debug.Log(CameraDevice.Instance.IsActive());
        mTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
        if (mTracker == null)
            return;
        Debug.Log(mTracker.IsActive);
        currentSet = mTracker.GetActiveDataSets().FirstOrDefault();

        bool tracking = ((ModelTarget)currentSet.GetTrackables().FirstOrDefault()).IsExtendedTrackingStarted();
        currentTarget = currentSet.GetTrackables().FirstOrDefault().Name;

        Debug.Log("Extented tracking: " +currentTarget +" " +tracking);
    }

    IEnumerator ChangeTarget()
    {
        Debug.Log("Change Target");
        mTracker.Stop();
        mTracker.DeactivateDataSet(currentSet);
        Debug.Log("Deactived dataset");


        currentSet = mTracker.CreateDataSet();
        if (currentSet.Load(nextTarget))
        {
            nextTarget = currentTarget;
            currentTarget = currentSet.GetTrackables().FirstOrDefault().Name;
            Debug.Log("next target: " + nextTarget + " current target: " + currentTarget);
            mTracker.ActivateDataSet(currentSet);
            mTracker.Start();
            yield return true;
        }

        yield return false;
    }
    // Update is called once per frame
    void Update () {
  
}

    public void OnInputClicked(InputClickedEventData eventData)
    {
        StartCoroutine(ChangeTarget());
    }
}

Multiple Model Targets

January 23, 2018 - 9:29pm #5

Hi,

        I can't find unity API there, can you please share a small script regarding loading & activating multiple Model Target Data bases may be something like onbutton click. It will be really helpful.

 

Thank you,

saikiran

Multiple Model Targets

January 19, 2018 - 8:04am #4

Hello again,

Please refer to this documentation: https://library.vuforia.com/articles/Solution/model-targets-workflow.html

Thanks,

Vuforia Support

Multiple Model Targets

January 17, 2018 - 8:08pm #3

Hi Strasza,

Exactly, I need the API or sample code, it will be great if, i will be guided to some detailed explanation

Regards,

saikiran

Multiple Model Targets

January 17, 2018 - 3:36pm #2

Hello saiunity,

You can only have a single Model Target dataset activated at a time. You can load multiple datasets as needed, but if you'd like to use a different dataset you'll have to de-activate the first dataset and activate the second one.

Thanks,

Vuforia Support

Log in or register to post comments