public void DestroyLastTrackable()
    {
        // Deactivates the dataset first
        m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);

        IEnumerable <Trackable> trackables = m_UDT_DataSet.GetTrackables();
        Trackable newest = null;

        foreach (Trackable trackable in trackables)
        {
            if (newest == null || trackable.ID > newest.ID)
            {
                newest = trackable;
            }
        }

        if (newest != null)
        {
            Debug.Log("Destroying newest trackable in UDT dataset: " + newest.Name);
            m_UDT_DataSet.Destroy(newest, true);
            Debug.Log("destroyed");
        }
        // Activate the dataset again
        m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);
        // Make sure TargetBuildingBehaviour keeps scanning...
        m_TargetBuildingBehaviour.StartScanning();
    }
Пример #2
0
 public void DeleteTrackable()
 {
     if (dataSet != null)
     {
         objectTracker.DeactivateDataSet(dataSet);
         dataSet.DestroyAllTrackables(false);
         objectTracker.ActivateDataSet(dataSet);
     }
 }
Пример #3
0
    void ActivateDataSets(bool enableDataset)
    {
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        // We must stop the ObjectTracker before activating/deactivating datasets
        if (objectTracker.IsActive)
        {
            objectTracker.Stop();
        }

        if (!objectTracker.IsActive)
        {
            IEnumerable <DataSet> datasets = objectTracker.GetDataSets();
            foreach (DataSet dataset in datasets)
            {
                // Activate or Deactivate each DataSet
                if (enableDataset)
                {
                    objectTracker.ActivateDataSet(dataset);
                }
                else
                {
                    objectTracker.DeactivateDataSet(dataset);
                }
            }
        }

        if (!objectTracker.IsActive)
        {
            objectTracker.Start();
        }
    }
Пример #4
0
    //This function will de-activate all current datasets and activate the designated dataset.
    //It is assumed the dataset being activated has already been loaded (either through code
    //elsewhere or via the Vuforia Configuration).
    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();
    }
Пример #5
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {                                                                     //将新的目标添加到数据集
        count++;
        objectTracker.DeactivateDataSet(dataSet);                         //禁用数据集
        if (dataSet.HasReachedTrackableLimit())                           //数据集上限
        {
            IEnumerable <Trackable> trackables = dataSet.GetTrackables(); //拿到数据集
            Trackable oldTrackable             = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldTrackable.ID > trackable.ID || oldTrackable == null)
                {
                    oldTrackable = trackable;
                }
            }
            if (oldTrackable != null)
            {
                dataSet.Destroy(oldTrackable, true);//删除最早的数据
            }
        }
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTarget);

        imageTargetCopy.gameObject.name = "UseTarget_" + count;               //修改名字
        dataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject); //创建到数据集
        objectTracker.ActivateDataSet(dataSet);                               //激活数据库
    }
    private void DeactivateGloveTargetTracking()
    {
        //get the object tracker instance
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        if (objectTracker == null)
        {
            return;
        }

        //get all available datasets and momentarily stop tracking
        List <DataSet> dataSets = objectTracker.GetActiveDataSets().ToList();

        objectTracker.Stop();

        //find the mainGloveTarget, and deactivate it
        foreach (DataSet dataSet in dataSets)
        {
            if (dataSet.Path.IndexOf(mainGloveTarget) != -1)
            {
                objectTracker.DeactivateDataSet(dataSet);
            }
        }


        objectTracker.Start();
    }
    void OnVuforiaStarted()
    {
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        objectTracker.Stop();
        IEnumerable <DataSet> dataSetList = objectTracker.GetActiveDataSets();

        foreach (DataSet set in dataSetList)
        {
            if (set.Path != ("Vuforia/" + datasetName + ".xml"))
            {
                objectTracker.DeactivateDataSet(set);
                continue;
            }
            objectTracker.Start();

            IEnumerable <TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
            foreach (TrackableBehaviour tb in trackableBehaviours)
            {
                if (set.Contains(tb.Trackable))
                {
                    GameObject go = tb.gameObject;
                    go.AddComponent <DefaultTrackableEventHandler>();
                    //Insert code here :
                    GameObject model = Instantiate(prefab) as GameObject;
                    model.transform.parent = tb.transform;
                    model.SetActive(true);

                    tb.gameObject.SetActive(true);
                }
            }
            break;
        }
    }
    // Method for unloading active data sets once user exits the scene. This is to prevent
    // presence of multiple copies of same data sets when re-entering scene.
    public void UnloadActiveDataSets()
    {
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        System.Collections.ObjectModel.ReadOnlyCollection <DataSet> activeDataSets = objectTracker.GetActiveDataSets().ToReadOnlyCollection();

        for (int i = 0; i < activeDataSets.Count; i++)
        {
            DataSet currDataSet = activeDataSets[i];

            StateManager stateManager     = TrackerManager.Instance.GetStateManager();
            List <TrackableBehaviour> tbs = (List <TrackableBehaviour>)TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();

            for (int j = 0; j < tbs.Count; j++)
            {
                if (activeDataSets[i].Contains(tbs[j].Trackable))
                {
                    stateManager.DestroyTrackableBehavioursForTrackable(tbs[j].Trackable, true);
                }
            }

            if (!objectTracker.DeactivateDataSet(currDataSet))
            {
                Debug.Log("Could not deactive data set!");
            }

            if (!objectTracker.DestroyDataSet(currDataSet, false))
            {
                Debug.Log("Could not destroy data set!");
            }
        }
    }
Пример #9
0
        /// <summary>
        /// 关闭指定识别数据集
        /// </summary>
        /// <param name="datasetName">数据集名称或绝对路径</param>
        public static void DeactivateDateset(string datasetName)
        {
            ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

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

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

            List <DataSet> dataSetsToBeActive = new List <DataSet>();

            foreach (DataSet ads in activeDataSetsToBeRemoved)
            {
                objectTracker.DeactivateDataSet(ads);
                if (!ads.Path.Contains(datasetName))
                {
                    dataSetsToBeActive.Add(ads);
                }
                else
                {
                    objectTracker.DestroyDataSet(ads, false);
                    var trackables = ads.GetTrackables();
                    foreach (var item in trackables)
                    {
                        TrackerManager.Instance.GetStateManager().DestroyTrackableBehavioursForTrackable(item, true);
                    }
                }
            }
            objectTracker.Stop();
            foreach (DataSet ds in dataSetsToBeActive)
            {
                objectTracker.ActivateDataSet(ds);
            }
            objectTracker.Start();
        }
Пример #10
0
    public void ActivateDataSet(string datasetName)
    {
        // ObjectTracker tracks ImageTargets 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(datasetName))
            {
                objectTracker.ActivateDataSet(ds);
            }
        }

        // 4. Finally, restart the object tracker.
        objectTracker.Start();
    }
Пример #11
0
        //This function will de-activate all current datasets and activate the designated dataset.
        //It is assumed the dataset being activated has already been loaded (either through code
        //elsewhere or via the Vuforia Configuration).
        public void DisableAllAndSet(NamedDataSet setAsActive)
        {
            ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

            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);
            }

            if (setAsActive == null)
            {
                return;
            }
            //Swapping of the datasets should not be done while the ObjectTracker is working at the same time.
            //So, Stop the tracker first.
            objectTracker.Stop();

            objectTracker.ActivateDataSet(setAsActive.set);

            //Finally, start the object tracker.
            objectTracker.Start();
        }
Пример #12
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        // deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full
        if (mBuiltDataSet.HasReachedTrackableLimit())
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }
            if (oldest != null)
            {
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // get predefined trackable (template) and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        // add the trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Re-activate the dataset
        mObjectTracker.ActivateDataSet(mBuiltDataSet);
    }
Пример #13
0
 public void OnNewTrackableSource(TrackableSource trackableSource)// метод который отвечает за новую отслеживаемую цель, подробнее по ссылке https://library.vuforia.com/articles/Training/User-Defined-Targets-Guide
 {
     targetCount++;
     ObjTracker.DeactivateDataSet(dataSet);                                // поскольку мы собираемся использовать новый набор данных нужно Deactivate старый набор.
     dataSet.CreateTrackable(trackableSource, targetBehaviour.gameObject); // узнаем что отслеживается нами// первая переменная это отслеживаемый источник в данный момент, а второй это цель т.е. ImageTraget если не понятно то по ссылке https://library.vuforia.com/articles/Training/User-Defined-Targets-Guide
     ObjTracker.ActivateDataSet(dataSet);                                  // активация нового набора данных
     UDT_BuildingBehaviour.StartScanning();                                // начать отслеживание
 }
Пример #14
0
 public void OnNewTrackableSource(TrackableSource trackableSource)
 {
     targetCounter++;
     objectTracker.DeactivateDataSet(dataSet);
     dataSet.CreateTrackable(trackableSource, targetBehaviour.gameObject); // create a new trackable image and add it to dataset
     objectTracker.ActivateDataSet(dataSet);                               // re-activate data set
     udt_targetBuildingBehavior.StartScanning();                           // start tracking
 }
Пример #15
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        targetCounter++;
        objectTracker.DeactivateDataSet(dataSet);

        dataSet.CreateTrackable(trackableSource, targetBehavior.gameObject);
        objectTracker.ActivateDataSet(dataSet);
        udt_targetBuildingBehavior.StartScanning();
    }
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        m_TargetCounter++;

        // Deactivates the dataset first
        m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (m_UDT_DataSet.HasReachedTrackableLimit() || m_UDT_DataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = m_UDT_DataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                m_UDT_DataSet.Destroy(oldest, true);
            }
        }

        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + m_TargetCounter;
        imageTargetCopy.gameObject.SetActive(true);

        // Add the duplicated trackable to the data set and activate it
        m_UDT_DataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);

        // Make sure TargetBuildingBehaviour keeps scanning...
        m_TargetBuildingBehaviour.StartScanning();
    }
Пример #17
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        targetCounter++;
        objectTracker.DeactivateDataSet(dataSet);
        ImageTargetBehaviour imageTargetCopy = Instantiate(imageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserTarget-" + targetCounter;
        dataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);
        objectTracker.ActivateDataSet(dataSet);
    }
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full
        if (mBuiltDataSet.HasReachedTrackableLimit())
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;
        textMesh      = imageTargetCopy.gameObject.GetComponentInChildren <TextMesh>();
        textMesh.text = "Target #" + mTargetCounter;


        // add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);


        // activate the dataset again
        mObjectTracker.ActivateDataSet(mBuiltDataSet);

        //Extended Tracking with user defined targets only works with the most recently defined target.
        //If tracking is enabled on previous target, it will not work on newly defined target.
        //Don't need to call this if you don't care about extended tracking.
        //StopExtendedTracking();
        bool persist = mObjectTracker.PersistExtendedTracking(true);

        if (persist)
        {
            mObjectTracker.Stop();
            mObjectTracker.ResetExtendedTracking();
            mObjectTracker.Start();
        }
    }
Пример #19
0
        public void OnNewTrackableSource(TrackableSource trackableSource)
        {
            _objectTracker.DeactivateDataSet(_udtDataSet);
            _udtDataSet.DestroyAllTrackables(true);
            var instance = Instantiate(_imageTargetTemplate);

            instance.gameObject.name = string.Format("{0}_instance", _imageTargetTemplate.TrackableName);
            instance.gameObject.SetActive(true);
            _udtDataSet.CreateTrackable(trackableSource, instance.gameObject);
            _objectTracker.ActivateDataSet(_udtDataSet);
            StopExtendedTracking();
            _objectTracker.Stop();
            _objectTracker.ResetExtendedTracking();
            if (OnTargetBuilt != null)
            {
                OnTargetBuilt(this, new TargetBuiltEventArgs(instance.GetComponent <TrackableObject>()));
            }
            _objectTracker.Start();
            _targetBuildingBehaviour.StartScanning();
        }
Пример #20
0
    /// <summary>
    /// Create or destroy the virtual button with the given name.
    /// </summary>
    public void ToggleVirtualButton(string name)
    {
        if (mImageTargetWood.ImageTarget != null)
        {
            // Get the virtual button if it exists.
            VirtualButton vb = mImageTargetWood.ImageTarget.GetVirtualButtonByName(name);

            if (vb != null)
            {
                // Destroy the virtual button if it exists.
                mImageTargetWood.DestroyVirtualButton(name);
            }
            else
            {
                // Get the position and scale originally used for this virtual button.
                Vector3 position, scale;
                if (mVBPositionDict.TryGetValue(name, out position) &&
                    mVBScaleDict.TryGetValue(name, out scale))
                {
                    // Deactivate the dataset before creating the virtual button.
                    ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();
                    DataSet       dataSet       = objectTracker.GetActiveDataSets().First();
                    objectTracker.DeactivateDataSet(dataSet);

                    // Create the virtual button.
                    VirtualButtonBehaviour vbb = mImageTargetWood.CreateVirtualButton(
                        name,
                        new Vector2(position.x, position.z),
                        new Vector2(scale.x, scale.z)) as VirtualButtonBehaviour;

                    if (vbb != null)
                    {
                        // Register the button with the event handler on the Wood target.
                        vbb.RegisterEventHandler(mImageTargetWood.GetComponent <VirtualButtonEventHandler>());

                        // Add a mesh to outline the button.
                        CreateVBMesh(vbb);

                        // If the Wood target isn't currently tracked hide the button.
                        if (mImageTargetWood.CurrentStatus == TrackableBehaviour.Status.NOT_FOUND)
                        {
                            vbb.GetComponent <Renderer>().enabled = false;
                        }
                    }

                    // Reactivate the dataset.
                    objectTracker.ActivateDataSet(dataSet);
                }
            }
        }

        base.CloseMenu();
    }
Пример #21
0
        /// <summary>
        /// On Vuforia, enables a specific set of data, either image targets, object targets, or
        /// scanned model targets.
        /// </summary>
        /// <param name="dataSetName">Data set name.</param>
        void EnableDataSet(string dataSetName)
        {
            if (dataSetName != null)
            {
                foreach (var ds in tracker.GetActiveDataSets())
                {
                    tracker.DeactivateDataSet(ds);
                }

                LoadDataSet(dataSetName);
            }
        }
Пример #22
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // Deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            Debug.Log(" text 123456789");
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }


        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;

        // Add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        mObjectTracker.ActivateDataSet(mBuiltDataSet);

        // Extended Tracking with user defined targets only works with the most recently defined target.
        // If tracking is enabled on previous target, it will not work on newly defined target.
        // Don't need to call this if you don't care about extended tracking.
        StopExtendedTracking();
        mObjectTracker.Stop();
        mObjectTracker.ResetExtendedTracking();
        mObjectTracker.Start();

        // Make sure TargetBuildingBehaviour keeps scanning...
        mTargetBuildingBehaviour.StartScanning();
    }
Пример #23
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        targetCounter++;
        objectTracker.DeactivateDataSet(dataSet);

        dataSet.CreateTrackable(trackableSource, targetBehaviour.gameObject);

        objectTracker.ActivateDataSet(dataSet);

        udt_targetBuildingBehaviour.StartScanning();

        //throw new System.NotImplementedException();
    }
Пример #24
0
        /* Starts the next unfinished task from the current setup */
        private void nextTask()
        {
            connectedPartsMax = 0;
            if (setup.tasks.Count > finishedTasks)
            {
                currentTask = setup.tasks[finishedTasks];
                Debug.Log("Next task: " + (finishedTasks + 1) + " / " + setup.tasks.Count);

                // Disable all Vuforia datasets except the one needed for the current task
                string        dataset      = currentTask.dataset;
                ObjectTracker imageTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();
                foreach (DataSet ds in imageTracker.GetDataSets())
                {
                    // determine whether the dataset is alreay active
                    bool isActive = false;
                    foreach (DataSet other in imageTracker.GetActiveDataSets())
                    {
                        if (ds.Equals(other))
                        {
                            isActive = true;
                        }
                    }

                    if (ds.Path.Contains(dataset) && !isActive)
                    {
                        imageTracker.ActivateDataSet(ds);
                        Debug.Log(ds.Path + " activated");
                    }
                    else if (!ds.Path.Contains(dataset) && isActive)
                    {
                        imageTracker.DeactivateDataSet(ds);
                        Debug.Log(ds.Path + " deactivated");
                    }
                }

                SoundManager.Instance.playFile("Sounds/Tasks/" + currentTask.audio);

                Debug.Log("Next Task: " + currentTask.ToString());
                Debug.Log(parts.Length + " active parts");
                connectionStateChanged();
            }
            else
            {
                currentSetupFinished = true;
                setupFinished        = SetupFinished();
                StartCoroutine(setupFinished);
            }
        }
Пример #25
0
    private void SwitchDatabase(string[] dataSetsToBeActivated)
    {
        if (Input.GetKeyDown(KeyCode.D))
        {
            IEnumerable <DataSet> activeDataSets            = objectTracker.GetActiveDataSets();
            List <DataSet>        activeDataSetsToBeRemoved = new List <DataSet>();
            activeDataSetsToBeRemoved.AddRange(activeDataSets);

            foreach (DataSet set in activeDataSetsToBeRemoved)
            {
                objectTracker.DeactivateDataSet(set);
            }

            objectTracker.Stop();


            DataSet dataSet = objectTracker.CreateDataSet();

            if (DataSet.Exists(dataSetNames[dataSetCounter]))
            {
                dataSet.Load(dataSetNames[dataSetCounter]);
                objectTracker.ActivateDataSet(dataSet);

                if (dataSetCounter == dataSetNames.Length - 1)
                {
                    dataSetCounter = 0;
                }
                else
                {
                    dataSetCounter++;
                }
            }


            IEnumerable <TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
            foreach (TrackableBehaviour tb in trackableBehaviours)
            {
                if (tb is ModelTargetBehaviour && tb.isActiveAndEnabled)
                {
                    Debug.Log("TrackableName: " + tb.TrackableName);
                    (tb as ModelTargetBehaviour).GuideViewMode = ModelTargetBehaviour.GuideViewDisplayMode.GuideView2D;
                    mModelTarget = tb.GetComponent <ModelTargetBehaviour>();
                }
            }

            objectTracker.Start();
        }
    }
Пример #26
0
    private void LoadNewTargetModel(string dataBaseName)
    {
        TrackerManager tm = (TrackerManager)TrackerManager.Instance;

        objTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();
        if (objTracker == null)
        {
            return;
        }
        currentDataSet = objTracker.GetActiveDataSets().FirstOrDefault();
        objTracker.Stop();
        objTracker.DeactivateDataSet(currentDataSet);
        currentDataSet = objTracker.CreateDataSet();
        currentDataSet.Load(dataBaseName);
        objTracker.ActivateDataSet(currentDataSet);
        objTracker.Start();
    }
    public void ActivateDatasets(bool enableDataset)
    {
        ObjectTracker         objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();
        IEnumerable <DataSet> datasets      = objectTracker.GetDataSets();

        foreach (DataSet dataset in datasets)
        {
            if (enableDataset)
            {
                objectTracker.ActivateDataSet(dataset);
            }
            else
            {
                objectTracker.DeactivateDataSet(dataset);
            }
        }
    }
Пример #28
0
        public void OnNewTrackableSource(TrackableSource trackableSource)
        {
            _objectTracker.DeactivateDataSet(_udtDataSet);
            _udtDataSet.DestroyAllTrackables(true);
            var instance = Instantiate(_imageTargetTemplate);

            instance.gameObject.name = string.Format("{0}_instance", _imageTargetTemplate.TrackableName);
            instance.gameObject.SetActive(true);
            //TODO make more abstract
            MainSceneController.Instance.SceneContainer = instance.GetComponent <SceneContainer>();
            _udtDataSet.CreateTrackable(trackableSource, instance.gameObject);
            _objectTracker.ActivateDataSet(_udtDataSet);
            StopExtendedTracking();
            _objectTracker.Stop();
            _objectTracker.ResetExtendedTracking();
            _objectTracker.Start();
            _targetBuildingBehaviour.StartScanning();
        }
Пример #29
0
    void UnloadDataSet()
    {
        ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker> ();

        if (tracker != null)
        {
            tracker.Stop();
        }
        List <DataSet> activeDataSets = tracker.GetActiveDataSets().ToList();

        if (activeDataSets.Count > 0)
        {
            DataSet ds = activeDataSets.ElementAt(0);
            IEnumerable <Trackable> tbs          = ds.GetTrackables();
            StateManager            stateManager = TrackerManager.Instance.GetStateManager();
            tracker.DeactivateDataSet(ds);
            foreach (Trackable tb in tbs)
            {
                Debug.Log(tb.Name);

                stateManager.DestroyTrackableBehavioursForTrackable(tb, false);
                GameObject ob = GameObject.Find("DynamicImageTarget-" + tb.Name);
                if (ob != null)
                {
                    Debug.Log(tb.Name);
                    ob.SetActive(false);
                    Destroy(ob);
                }
            }
            tracker.DestroyDataSet(ds, false);
            Resources.UnloadUnusedAssets();
        }
        tracker.Start();

        List <DataSet> dataSets = tracker.GetDataSets().ToList();

        if (dataSets.Count > 0)
        {
            foreach (var dataset in dataSets)
            {
                Debug.Log("datasetName------" + GetDataSetName(dataset));
            }
        }
    }
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= 5)
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;

        // add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);
        // call animatioPlay and audioPlay methods.

        // activate the dataset again
        mObjectTracker.ActivateDataSet(mBuiltDataSet);
        StartCoroutine(hideForShotButtons());
    }