Esempio n. 1
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();
    }
Esempio n. 2
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();
        }
    }
Esempio n. 3
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();
    }
Esempio n. 4
0
    void show()
    {
        ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker> ();

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

        if (dataSets.Count > 0)
        {
            foreach (var dataset in dataSets)
            {
                Debug.Log("datasetName------" + GetDataSetName(dataset));
            }
        }
        Debug.Log("--------------------");
    }
Esempio n. 5
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);
            }
        }
    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);
            }
        }
    }
Esempio n. 7
0
    private IEnumerable <string> GetAllDatasets()
    {
        ObjectTracker         objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();
        IEnumerable <DataSet> datasets      = objectTracker.GetDataSets();

        List <string> datasetsName = new List <string>();

        foreach (DataSet ds in datasets)
        {
            datasetsName.Add(Path.GetFileNameWithoutExtension(ds.Path));
        }

        // Sorting the datasets names
        datasetsName = datasetsName.OrderBy(q => q).ToList();

        return(datasetsName);
    }
Esempio n. 8
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));
            }
        }
    }
Esempio n. 9
0
    private void FindDatasets()
    {
        ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        if (tracker == null)
        {
            Debug.LogError("ObjectTracker not initialized.");
            ShowError();
        }
        else
        {
            IEnumerable <DataSet> datasets = tracker.GetDataSets();
            if (datasets.Count() == 0)
            {
                Debug.LogError("Missing Database.");
                ShowError();
            }
        }
    }
Esempio n. 10
0
    private void FindDatasets()
    {
        ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        if (tracker == null)
        {
            Debug.LogError("ObjectTracker not initialized.");
            ShowError();
        }
        else
        {
            IEnumerable <DataSet> datasets = tracker.GetDataSets();
            if (datasets.Count() == 0)
            {
                Debug.LogError("Missing Database.");
                errorTitle.text   = "Database not found";
                errorMessage.text = "Please scan an object and load a database.";
                ShowError();
            }
        }
    }
Esempio n. 11
0
    private void countDatasets()
    {
        ObjectTracker         otr = TrackerManager.Instance.GetTracker <ObjectTracker>();
        IEnumerable <DataSet> ads = otr.GetActiveDataSets();

        foreach (DataSet d in ads)
        {
            Debug.Log("CountDatasets: Active dataset. " + d.ToString());

            IEnumerable <Trackable> ts = d.GetTrackables();
            foreach (Trackable t in ts)
            {
                Debug.Log("CountDatasets: Trackable: name: " + t.Name + " - id: " + t.ID);
            }
        }
        IEnumerable <DataSet> ds = otr.GetDataSets();

        foreach (DataSet d in ds)
        {
            Debug.Log("CountDatasets: all dataset. " + d.ToString());
        }
    }
Esempio n. 12
0
    private void ActivateDatasets(bool enableDataset)
    {
        //Disable/Enable dataset

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

        if (objectTracker != null)
        {
            IEnumerable <DataSet> datasets = objectTracker.GetDataSets();

            foreach (DataSet dataset in datasets)
            {
                if (enableDataset)
                {
                    objectTracker.ActivateDataSet(dataset);
                }
                else
                {
                    objectTracker.DeactivateDataSet(dataset);
                }
            }
        }
    }
Esempio n. 13
0
    void LoadDataSetFromPathWithName(LitJson.JsonData data)
    {
        logText.text = "respond success";
        //TestInstanceFromWeb ();
        string dataSetName = (string)data ["DataSetName"];

        ObjectTracker  tracker        = TrackerManager.Instance.GetTracker <ObjectTracker> ();
        List <DataSet> activeDataSets = tracker.GetDataSets().ToList();
        List <DataSet> dataSets       = tracker.GetDataSets().ToList();

        Debug.Log("activeDataset count:" + activeDataSets.Count);
        Debug.Log("Dataset count:" + dataSets.Count);

        foreach (DataSet ds in activeDataSets)
        {
            Debug.Log("dataset name-" + GetDataSetName(ds));

            string dsName = GetDataSetName(ds);
            if (dsName == dataSetName.ToLower())
            {
                return;
            }
        }

        Debug.Log("start load");
        DataSet dataSet = tracker.CreateDataSet();


        string path = Path.Combine(Application.persistentDataPath, "DataSets");

        path = Path.Combine(path, dataSetName + ".xml");
        Debug.Log("dataset filepath is:" + path);
//		#if UNITY_ANDROID
//		path="file://"+path;
//		#endif
        if (dataSet.Load(path, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
        {
            tracker.Stop();
            if (!tracker.ActivateDataSet(dataSet))
            {
                Debug.Log("fail to activate dataset" + dataSetName);
            }
            if (!tracker.Start())
            {
                Debug.Log("fail to start tracker");
            }

            IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
            foreach (TrackableBehaviour tb in tbs)
            {
                Debug.Log("memory already has imageTarget:" + tb.name);
                if (tb.name == "New Game Object")                  // 新创建的总是被命名为 "New Game Object"
                {
                    Debug.Log("new imageTarget");
                    //if (tb.TrackableName == "tarmac") {//可以通过这个属性来加载特定的模型
                    tb.gameObject.name = "DynamicImageTarget-" + tb.TrackableName;
                    tb.gameObject.AddComponent <DefaultTrackableEventHandler> ();
                    tb.gameObject.AddComponent <TurnOffBehaviour> ();
                    InstanceModel(tb);
                }
            }
        }
        else
        {
            Debug.Log("Failed to load dataset" + dataSetName);
        }

/*
 *              if (dataSet.Load (dataSetName)) {
 *                      tracker.Stop ();
 *                      if (!tracker.ActivateDataSet (dataSet)) {
 *                              Debug.Log ("fail to activate dataset" + dataSetName);
 *                      }
 *                      if (!tracker.Start ()) {
 *                              Debug.Log ("fail to start tracker");
 *                      }
 *
 *                      IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager ().GetTrackableBehaviours ();
 *                      foreach (TrackableBehaviour tb in tbs) {
 *                              Debug.Log ("memory already has imageTarget:"+tb.name);
 *                              if (tb.name == "New Game Object") {// 新创建的总是被命名为 "New Game Object"
 *                                      Debug.Log ("new imageTarget");
 *                                      //if (tb.TrackableName == "tarmac") {//可以通过这个属性来加载特定的模型
 *                                      tb.gameObject.name = "DynamicImageTarget-" + tb.TrackableName;
 *                                      tb.gameObject.AddComponent<DefaultTrackableEventHandler> ();
 *                                      tb.gameObject.AddComponent<TurnOffBehaviour> ();
 *                                      if (augmentObject != null) {
 *                                              GameObject augmentation = (GameObject)GameObject.Instantiate (augmentObject);
 *                                              augmentation.transform.transform.parent = tb.gameObject.transform;
 *                                              augmentation.transform.localPosition = new Vector3 (0f, 0f, 0f);
 *                                              //augmentation.transform.localRotation = Quaternion.identity;
 *                                              //augmentation.transform.localRotation = Quaternion.identity;
 *                                              augmentation.transform.Rotate(new Vector3 (0f, 90f, 0f));
 *                                              augmentation.transform.localScale = new Vector3 (0.07f, 0.07f, 0.07f); //maomao's size is 0.07
 *                                              //augmentation.transform.localScale = new Vector3 (0.6f, 0.6f, 0.6f);
 *                                              augmentation.gameObject.SetActive (true);
 *                                              AudioSource audio = augmentation.GetComponent<AudioSource> ();
 *                                              audio.Stop ();
 *                                      } else {
 *                                              Debug.Log ("no augmentation object for :" + tb.TrackableName);
 *                                      }
 *                                      //}
 *                              }
 *                      }
 *              } else {
 *                      Debug.Log ("Failed to load dataset" + dataSetName);
 *              }
 */
    }
Esempio n. 14
0
    void LoadDataSet()
    {
        ObjectTracker  tracker        = TrackerManager.Instance.GetTracker <ObjectTracker> ();
        List <DataSet> activeDataSets = tracker.GetDataSets().ToList();
        List <DataSet> dataSets       = tracker.GetDataSets().ToList();

        Debug.Log("activeDataset count:" + activeDataSets.Count);
        Debug.Log("Dataset count:" + dataSets.Count);

        foreach (DataSet ds in activeDataSets)
        {
            Debug.Log("dataset name-" + GetDataSetName(ds));

            string dsName = GetDataSetName(ds);
            if (dsName == dataSetName.ToLower())
            {
                return;
            }
        }

        Debug.Log("start load");
        DataSet dataSet = tracker.CreateDataSet();

        if (dataSet.Load(dataSetName))
        {
            tracker.Stop();
            if (!tracker.ActivateDataSet(dataSet))
            {
                Debug.Log("fail to activate dataset" + dataSetName);
            }
            if (!tracker.Start())
            {
                Debug.Log("fail to start tracker");
            }

            IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
            foreach (TrackableBehaviour tb in tbs)
            {
                Debug.Log("memory already has imageTarget:" + tb.name);
                if (tb.name == "New Game Object")                  // 新创建的总是被命名为 "New Game Object"
                {
                    Debug.Log("new imageTarget");
                    //if (tb.TrackableName == "tarmac") {//可以通过这个属性来加载特定的模型
                    tb.gameObject.name = "DynamicImageTarget-" + tb.TrackableName;
                    tb.gameObject.AddComponent <DefaultTrackableEventHandler> ();
                    tb.gameObject.AddComponent <TurnOffBehaviour> ();

                    if (augmentObject != null)
                    {
                        GameObject augmentation = (GameObject)GameObject.Instantiate(augmentObject);
                        augmentation.transform.transform.parent = tb.gameObject.transform;
                        augmentation.transform.localPosition    = new Vector3(0f, 0f, 0f);
                        //augmentation.transform.localRotation = Quaternion.identity;
                        //augmentation.transform.localRotation = Quaternion.identity;
                        augmentation.transform.Rotate(new Vector3(0f, 90f, 0f));
                        augmentation.transform.localScale = new Vector3(0.07f, 0.07f, 0.07f);                          //maomao's size is 0.07
                        //augmentation.transform.localScale = new Vector3 (0.6f, 0.6f, 0.6f);
                        augmentation.gameObject.SetActive(true);
                        AudioSource audio = augmentation.GetComponent <AudioSource> ();
                        if (audio != null)
                        {
                            audio.Stop();
                        }
                    }
                    else
                    {
                        Debug.Log("no augmentation object for :" + tb.TrackableName);
                    }

                    //}
                }
            }
        }
        else
        {
            Debug.Log("Failed to load dataset" + dataSetName);
        }
    }
Esempio n. 15
0
    private void LoadDataSetWithName(string dataSetName, LitJson.JsonData targetDataList)
    {
        List <DataSet> activeDataSets = tracker.GetDataSets().ToList();

        Utility.LogPrint("activeDataset count:" + activeDataSets.Count);

        foreach (DataSet ds in activeDataSets)
        {
            Utility.LogPrint("dataset name--" + Utility.GetDataSetName(ds));
            string dsName = Utility.GetDataSetName(ds);
            if (dsName == dataSetName.ToLower())
            {
                Utility.LogPrint("memory already has the dataset,name--" + Utility.GetDataSetName(ds));
                return;
            }
        }
        DataSet dataSet     = tracker.CreateDataSet();
        string  dataSetPath = Path.Combine(dataSetDir, dataSetName + ".xml");

        Utility.LogPrint("dataset filepath is:" + dataSetPath);

        if (File.Exists(dataSetPath))
        {
            if (dataSet.Load(dataSetPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
            {
                tracker.Stop();
                if (!tracker.ActivateDataSet(dataSet))
                {
                    Utility.LogPrint("fail to activate dataset" + dataSetName);
                }
                if (!tracker.Start())
                {
                    Utility.LogPrint("fail to start tracker");
                }
                List <string> keyList = new List <string> ()
                {
                    "targetName", "url", "size"
                };
                IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
                foreach (TrackableBehaviour tb in tbs)
                {
                    //tb.transform.position = new Vector3 (0, 0, 0);
                    tb.transform.rotation = Quaternion.Euler(new Vector3(tb.transform.rotation.x, tb.transform.rotation.y + 180, tb.transform.rotation.z));
                    Debug.Log("memory already has imageTarget:" + tb.name + "-----" + tb.transform.position);
                    if (tb.name.Equals("New Game Object"))
                    {                    // 新创建的总是被命名为 "New Game Object"
                        //ergodic all the targetname,if targetName = modelName then set loadPath and so on
                        for (int i = 0; i < targetDataList.Count; i++)
                        {
                            if (Utility.CheckJson(targetDataList [i], keyList))
                            {
                                Utility.LogPrint("find ImageTarget -- " + tb.TrackableName);
                                LitJson.JsonData targetData = targetDataList [i];
                                string           targetName = (string)targetData ["targetName"];
                                string           str        = dataSetName + "_" + tb.TrackableName;

                                bool result = targetName.ToLower().Equals(str.ToLower());
                                Utility.LogPrint(targetName + "----" + tb.TrackableName);

                                if (result)
                                {
                                    string targetModelPath = Path.Combine(Application.persistentDataPath, assetBundleFolder);
                                    targetModelPath    = Path.Combine(targetModelPath, targetName + assetBundleSuf);
                                    tb.gameObject.name = "DynamicImageTarget-" + tb.TrackableName;
                                    tb.gameObject.AddComponent <TrackableEventHandler> ().setModelSource(targetModelPath, targetDataList [i]);
                                    tb.gameObject.AddComponent <TurnOffBehaviour> ();
                                    break;
                                }
                            }
                            else
                            {
                                Utility.PrepareForSendMessage("LoadDataSet", "1", "Not found the key: \"dataSetName\" or \"targets\",please add the key to the json");
                            }
                        }
                    }
                }
            }
            else
            {
                Utility.LogPrint("Failed to load dataset" + dataSetName);
            }
        }
        else
        {
            Utility.LogPrint("dataset file not exist");
        }
    }