public void OnInitialized() { _objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); if (_objectTracker != null) { _dataSet = _objectTracker.CreateDataSet(); _objectTracker.ActivateDataSet(_dataSet); } }
/// <summary> /// Called when UserDefinedTargetBuildingBehaviour has been initialized successfully /// </summary> public void OnInitialized () { mObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); if (mObjectTracker != null) { // create a new dataset mBuiltDataSet = mObjectTracker.CreateDataSet(); mObjectTracker.ActivateDataSet(mBuiltDataSet); } }
public void OnInitialized() { // look up the ImageTracker once and store a reference mObjectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); if (mObjectTracker != null) { // create a new dataset mBuiltDataSet = mObjectTracker.CreateDataSet(); mObjectTracker.ActivateDataSet(mBuiltDataSet); // remember that the component has been initialized mUdtInitialized = true; } }
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); } }
/// <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. int Max = 2; //if (controlador.GetTipoARcapturar()) //{ // Max = MAX_TARGETS_GAME_MODE; //} //else //{ // Max = MAX_TARGETS; //} if (!controlador.GetIsMultiTarget()) { Max = MAX_TARGETS_GAME_MODE; } else { Max = MAX_TARGETS; } if (m_UDT_DataSet.HasReachedTrackableLimit() || m_UDT_DataSet.GetTrackables().Count() >= Max) { 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; // 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(); }
public void OnNewTrackableSource(TrackableSource trackableSource) { targetCounter++; objectTracker.DeactivateDataSet(dataSet); ImageTargetBehaviour imageTargetCopy = Instantiate(imageTargetTemplate); //imageTargetCopy.gameObject.name = "new_Target" + targetCounter; dataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject); if (GlobalVariable.MulOrNot == false) { if (SetSource.isOn == true) { //Set Source if (GlobalVariable.EmitterOnly == true) // Emitter Only { GameObject capsule; if (haveEmitter == 0) { //the first SOURCE,then create SOURCE imageTargetCopy.gameObject.name = "Emitter_Field"; // Name the Target( Target is also a GameObject!) capsule = GameObject.Instantiate(Axis); //capsule = GameObject.CreatePrimitive (PrimitiveType.Capsule); capsule.name = "eemitter"; capsule.transform.parent = imageTargetCopy.transform; capsule.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); capsule.transform.localPosition = new Vector3(0, 0, 0); capsule.transform.Rotate(new Vector3(90, 180, 180)); //cylinder.transform.localPosition = imageTargetCopy.transform.position; //print (imageTargetCopy.transform.position.x+","+imageTargetCopy.transform.position.y+","+imageTargetCopy.transform.position.z); capsule.transform.localRotation = Quaternion.identity; //cylinder.transform.parent = imageTargetCopy.gameObject.transform; haveEmitter = 1; } else if (haveEmitter == 1) { //not the first SOURCE,then renew SOURCE GameObject ob = GameObject.Find("Emitter_Field"); ob.name = "Destroyed_Emitter_Field"; // disconnect the old one imageTargetCopy.gameObject.name = "Emitter_Field"; // Name the Target( Target is also a GameObject!) capsule = GameObject.Find("eemitter"); capsule.transform.parent = imageTargetCopy.transform; capsule.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); capsule.transform.localPosition = new Vector3(0, 0, 0); capsule.transform.localRotation = Quaternion.identity; capsule.transform.Rotate(new Vector3(90, 180, 180)); //cylinder.transform.localPosition = imageTargetCopy.transform.position; //print (imageTargetCopy.transform.position.x+","+imageTargetCopy.transform.position.y+","+imageTargetCopy.transform.position.z); } } else if (GlobalVariable.EmitterOnly == false) // Source { GameObject cylinder; if (haveSource == 0) //the first SOURCE,then create SOURCE { imageTargetCopy.gameObject.name = "Source_Field"; // Name the Target( Target is also a GameObject!) cylinder = GameObject.Instantiate(Axis); //cylinder = GameObject.CreatePrimitive (PrimitiveType.Cylinder); cylinder.name = "ssource"; cylinder.transform.parent = imageTargetCopy.transform; cylinder.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); cylinder.transform.localPosition = new Vector3(0, 0, 0); //cylinder.transform.localPosition = imageTargetCopy.transform.position; //print (imageTargetCopy.transform.position.x+","+imageTargetCopy.transform.position.y+","+imageTargetCopy.transform.position.z); cylinder.transform.localRotation = Quaternion.identity; cylinder.transform.Rotate(new Vector3(90, 180, 180)); //cylinder.transform.parent = imageTargetCopy.gameObject.transform; source_field = StartCoroutine(CreateSourceField()); //start coroutine haveSource = 1; } else if (haveSource == 1) //not the first SOURCE,then renew SOURCE { GameObject ob = GameObject.Find("Source_Field"); ob.name = "Destroyed_Source_Field"; // disconnect the old one imageTargetCopy.gameObject.name = "Source_Field"; // Name the Target( Target is also a GameObject!) cylinder = GameObject.Find("ssource"); cylinder.transform.parent = imageTargetCopy.transform; cylinder.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); cylinder.transform.localPosition = new Vector3(0, 0, 0); cylinder.transform.localRotation = Quaternion.identity; cylinder.transform.Rotate(new Vector3(90, 180, 180)); //cylinder.transform.localPosition = imageTargetCopy.transform.position; //print (imageTargetCopy.transform.position.x+","+imageTargetCopy.transform.position.y+","+imageTargetCopy.transform.position.z); StopCoroutine(source_field); //end coroutine source_field = StartCoroutine(CreateSourceField()); //start a new coroutine } } } else if (SetSink.isOn == true) { GameObject sphere; if (haveSink == 0) { //the first SINK,then create SINK imageTargetCopy.gameObject.name = "Sink_Field"; // Name the Target( Target is also a GameObject!) sphere = GameObject.Instantiate(Axis); //sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere); sphere.name = "ssink"; sphere.transform.parent = imageTargetCopy.transform; sphere.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); sphere.transform.localPosition = new Vector3(0, 0, 0); sphere.transform.localRotation = Quaternion.identity; sphere.transform.Rotate(new Vector3(90, 90, 180)); haveSink = 1; } else if (haveSink == 1) { //not the first SINK,then renew SINK GameObject ob = GameObject.Find("Sink_Field"); ob.name = "Destroyed_Sink_Field"; // disconnect the old one imageTargetCopy.gameObject.name = "Sink_Field"; // Name the Target( Target is also a GameObject!) sphere = GameObject.Find("ssink"); sphere.transform.parent = imageTargetCopy.transform; sphere.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); sphere.transform.localPosition = new Vector3(0, 0, 0); sphere.transform.localRotation = Quaternion.identity; sphere.transform.Rotate(new Vector3(90, 90, 180)); } } else if (SetVortex.isOn == true) { GameObject cube; if (haveVortex == 0) { //the first VORTEX,then create VORTEX imageTargetCopy.gameObject.name = "Vortex_Field"; // Name the Target( Target is also a GameObject!) cube = GameObject.Instantiate(Axis); //cube = GameObject.CreatePrimitive (PrimitiveType.Cube); cube.name = "vvortex"; cube.transform.parent = imageTargetCopy.transform; cube.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); //cube.transform.localScale = new Vector3(0.00f,0.00f,0.00f); cube.transform.localPosition = new Vector3(0, 0, 0); cube.transform.localRotation = Quaternion.identity; cube.transform.Rotate(new Vector3(90, 90, 180)); print("vvortex"); haveVortex = 1; } else if (haveVortex == 1) { //not the first VORTEX,then renew VORTEX GameObject ob = GameObject.Find("Vortex_Field"); ob.name = "Destroyed_Vortex_Field"; // disconnect the old one imageTargetCopy.gameObject.name = "Vortex_Field"; // Name the Target( Target is also a GameObject!) cube = GameObject.Find("vvortex"); cube.transform.parent = imageTargetCopy.transform; cube.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); //cube.transform.localScale = new Vector3(0.00f,0.00f,0.00f); cube.transform.localPosition = new Vector3(0, 0, 0); cube.transform.localRotation = Quaternion.identity; cube.transform.Rotate(new Vector3(90, 90, 180)); print("vvortex"); } } else if (SetUniform.isOn == true) { GameObject cylinder; if (haveUniform == 0) { //the first UNIFROM,then create UNIFORM imageTargetCopy.gameObject.name = "Uniform_Field"; // Name the Target( Target is also a GameObject!) cylinder = GameObject.Instantiate(Axis); //cylinder = GameObject.CreatePrimitive (PrimitiveType.Cylinder); cylinder.name = "uuniform"; cylinder.transform.parent = imageTargetCopy.transform; cylinder.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); //cylinder.transform.localScale = new Vector3 (0.00f, 0.00f, 0.00f); cylinder.transform.localPosition = new Vector3(0, 0, 0); cylinder.transform.localRotation = Quaternion.identity; cylinder.transform.Rotate(new Vector3(90, 90, 180)); //cylinder.transform.Rotate (0, 0, 90); haveUniform = 1; } else if (haveUniform == 1) { //not the first UNIFORM,then renew UNIFORM GameObject ob = GameObject.Find("Uniform_Field"); ob.name = "Destroyed_Unfirom_Field"; // disconnect the old one imageTargetCopy.gameObject.name = "Uniform_Field"; // Name the Target( Target is also a GameObject!) cylinder = GameObject.Find("uuniform"); cylinder.transform.parent = imageTargetCopy.transform; cylinder.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); //cylinder.transform.localScale = new Vector3 (0.00f, 0.00f, 0.00f); cylinder.transform.localPosition = new Vector3(0, 0, 0); cylinder.transform.localRotation = Quaternion.identity; cylinder.transform.Rotate(new Vector3(90, 90, 180)); //cylinder.transform.Rotate (0, 0, 90); } } else if (SetEmitter.isOn == true) { GameObject sphere; if (haveEmitter == 0) { //the first SINK,then create SINK imageTargetCopy.gameObject.name = "Emitter_Field"; // Name the Target( Target is also a GameObject!) sphere = GameObject.Instantiate(Axis); //sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere); sphere.name = "eemitter"; sphere.transform.parent = imageTargetCopy.transform; sphere.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); sphere.transform.localPosition = new Vector3(0, 0, 0); sphere.transform.localRotation = Quaternion.identity; sphere.transform.Rotate(new Vector3(90, 90, 180)); haveEmitter = 1; } else if (haveEmitter == 1) { //not the first SINK,then renew SINK GameObject ob = GameObject.Find("Emitter_Field"); ob.name = "Destroyed_Emitter_Field"; // disconnect the old one imageTargetCopy.gameObject.name = "Emitter_Field"; // Name the Target( Target is also a GameObject!) sphere = GameObject.Find("eemitter"); sphere.transform.parent = imageTargetCopy.transform; sphere.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); sphere.transform.localPosition = new Vector3(0, 0, 0); sphere.transform.localRotation = Quaternion.identity; sphere.transform.Rotate(new Vector3(90, 90, 180)); } } } else if (GlobalVariable.MulOrNot == true) { if (SetSource.isOn == true) { //Set Source GameObject cylinder; GlobalVariable.num_sources = GlobalVariable.num_sources + 1; imageTargetCopy.gameObject.name = "Source_Field" + GlobalVariable.num_sources; // Name the Target( Target is also a GameObject!) cylinder = GameObject.Instantiate(Axis); //cylinder = GameObject.CreatePrimitive (PrimitiveType.Cylinder); cylinder.name = "ssource" + GlobalVariable.num_sources; cylinder.transform.parent = imageTargetCopy.transform; cylinder.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); cylinder.transform.localPosition = new Vector3(0, 0, 0); cylinder.transform.localRotation = Quaternion.identity; cylinder.transform.Rotate(new Vector3(90, 90, 180)); source_field = StartCoroutine(CreateSourceField()); //start coroutine } else if (SetSink.isOn == true) { GameObject sphere; GlobalVariable.num_sinks = GlobalVariable.num_sinks + 1; imageTargetCopy.gameObject.name = "Sink_Field" + GlobalVariable.num_sinks; // Name the Target( Target is also a GameObject!) sphere = GameObject.Instantiate(Axis); //sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere); sphere.name = "ssink" + GlobalVariable.num_sinks; sphere.transform.parent = imageTargetCopy.transform; sphere.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); sphere.transform.localPosition = new Vector3(0, 0, 0); sphere.transform.localRotation = Quaternion.identity; sphere.transform.Rotate(new Vector3(90, 90, 180)); } else if (SetVortex.isOn == true) { GameObject cube; GlobalVariable.num_vortexes = GlobalVariable.num_vortexes + 1; imageTargetCopy.gameObject.name = "Vortex_Field" + GlobalVariable.num_vortexes; // Name the Target( Target is also a GameObject!) cube = GameObject.Instantiate(Axis); //cube = GameObject.CreatePrimitive (PrimitiveType.Cube); cube.name = "vvortex" + GlobalVariable.num_vortexes; cube.transform.parent = imageTargetCopy.transform; cube.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); cube.transform.localPosition = new Vector3(0, 0, 0); cube.transform.localRotation = Quaternion.identity; cube.transform.Rotate(new Vector3(90, 90, 180)); //print ("vvortex"); } else if (SetUniform.isOn == true) { GameObject cylinder; GlobalVariable.num_uniforms = GlobalVariable.num_uniforms + 1; imageTargetCopy.gameObject.name = "Uniform_Field" + GlobalVariable.num_uniforms; // Name the Target( Target is also a GameObject!) cylinder = GameObject.Instantiate(Axis); //cylinder = GameObject.CreatePrimitive (PrimitiveType.Cylinder); cylinder.name = "uuniform" + GlobalVariable.num_uniforms; cylinder.transform.parent = imageTargetCopy.transform; cylinder.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); cylinder.transform.localPosition = new Vector3(0, 0, 0); cylinder.transform.localRotation = Quaternion.identity; cylinder.transform.Rotate(new Vector3(90, 90, 180)); //cylinder.transform.Rotate (0, 0, 90); } else if (SetEmitter.isOn == true) { GameObject sphere; GlobalVariable.num_emitters = GlobalVariable.num_emitters + 1; imageTargetCopy.gameObject.name = "Emitter_Field" + GlobalVariable.num_emitters; // Name the Target( Target is also a GameObject!) sphere = GameObject.Instantiate(Axis); //sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere); sphere.name = "eemitter" + GlobalVariable.num_emitters; sphere.transform.parent = imageTargetCopy.transform; sphere.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); sphere.transform.localPosition = new Vector3(0, 0, 0); sphere.transform.localRotation = Quaternion.identity; sphere.transform.Rotate(new Vector3(90, 90, 180)); } } objectTracker.ActivateDataSet(dataSet); }
void LoadDataSet() { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(dataSetName)) { objectTracker.Stop(); // stop tracker so that we can add new dataset if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 100 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>"); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } int counter = 0; IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { // change generic name to include trackable name tb.gameObject.name = "DynamicImageTarget-" + tb.TrackableName; ++counter; // add additional script components for trackable tb.gameObject.AddComponent <DefaultTrackableEventHandler>(); tb.gameObject.AddComponent <TurnOffBehaviour>(); if (canvasForPoi != null) { // instantiate augmentation object and parent to trackable GameObject augmentation = (GameObject)GameObject.Instantiate(canvasForPoi); //augmentation.transform.parent = tb.gameObject.transform; augmentation.transform.SetParent(tb.gameObject.transform); augmentation.transform.localPosition = new Vector3(0f, 0f, 0f); Quaternion target = Quaternion.Euler(90f, 0, 0); augmentation.transform.localRotation = target;// Quaternion.identity; augmentation.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f); augmentation.gameObject.SetActive(true); augmentation.name = tb.TrackableName; foreach (POI p in area.POIs) {//if id from xml from server == image name from vuforia if (p.Id == tb.TrackableName) { //p.SetinfoBoard(augmentation); //p.openBoard(); Debug.Log("Info is seted up"); DefaultTrackableEventHandler h = tb.gameObject.GetComponent <DefaultTrackableEventHandler>(); h.poiForScene = p; } } //GameObject second = (GameObject)GameObject.Instantiate(secondObject); //second.transform.parent = tb.gameObject.transform; //second.transform.localPosition = new Vector3(0f, 0f, 0f); //second.gameObject.SetActive(true); } else { Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>"); foreach (POI p in area.POIs) {//if id from xml from server == image name from vuforia if (p.Id == tb.TrackableName) { //p.SetinfoBoard(augmentation); //p.openBoard(); Debug.Log("Info is seted up"); DefaultTrackableEventHandler h = tb.gameObject.GetComponent <DefaultTrackableEventHandler>(); h.poiForScene = p; } } } } } } else { Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>"); } }
void LoadDataSet() { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); if (objectTracker.IsActive) { objectTracker.Stop(); objectTracker.DestroyAllDataSets(false); } DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(dataSetName)) { objectTracker.Stop(); // stop tracker so that we can add new dataset if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 100 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>"); } else { Debug.Log("<color=blue>DataSet Activated : " + dataSetName + "</color>"); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } int counter = 0; IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { // change generic name to include trackable name tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName; // add additional script components for trackable tb.gameObject.AddComponent<DefaultTrackableEventHandler>(); tb.gameObject.AddComponent<TurnOffBehaviour>(); if (augmentationObject != null) { // instantiate augmentation object and parent to trackable GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject); augmentation.transform.parent = tb.gameObject.transform; augmentation.transform.localPosition = new Vector3(0f, 0f, 0f); augmentation.transform.localRotation = Quaternion.identity; augmentation.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f); augmentation.gameObject.SetActive(true); } else { Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>"); } } } } else { Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>"); } }
void LoadDataSet(MarkerDatabase database) { if (m_loadedDatabases.Contains(database.Id)) { m_logger.Debug("Loading {0} - already loaded!", database.Id); return; } if (!VuforiaARController.Instance.HasStarted || !IsActive) { m_logger.Debug("Loading {0} - delaying load", database.Id); m_toLoad.Add(database); return; } m_logger.Debug("Loading {0}", database.Id); ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); DataSet dataSet = objectTracker.CreateDataSet(); var fileName = WebServices.Instance.MediaDownloadManager.GetSystemUrl(database.XmlFile.Url); m_logger.Debug("Loading {0} from {1}", database.Id, fileName); if (dataSet.Load(fileName, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { objectTracker.Stop(); // stop tracker so that we can add new dataset if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 100 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + fileName + "</color>"); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } m_loadedDatabases.Add(database.Id); //var vuMark = Instantiate(VuMarkPrefab); int counter = 0; IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { // change generic name to include trackable name tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName; // add additional script components for trackable //tb.gameObject.AddComponent<DefaultTrackableEventHandler>(); tb.gameObject.AddComponent <TurnOffBehaviour>(); var vb = tb.gameObject.GetComponent <VuMarkBehaviour>(); if (vb) { var h = tb.gameObject.AddComponent <VuMarkTrackableEventHandler>(); h.TargetName = tb.TrackableName; h.DatabaseId = database.Id; } else { var ib = tb.gameObject.GetComponent <ImageTargetBehaviour>(); if (ib) { var h = tb.gameObject.AddComponent <ImageTargetTrackableEventHandler>(); h.TargetName = tb.TrackableName; h.DatabaseId = database.Id; } } //tb.gameObject.AddComponent<SphereCollider>(); } } } else { Debug.LogError("<color=yellow>Failed to load dataset: '" + fileName + "'</color>"); } }
void LoadDataSets() { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); objectTracker.Stop(); string[] files; if (string.IsNullOrEmpty(dataSetDir)) { Debug.Log("Persistent Data Path: " + Application.persistentDataPath); Debug.Log("Streaming Assets Path: " + Application.streamingAssetsPath); files = Directory.GetFiles(Application.persistentDataPath + "/ImageTargetDataSets", "*.xml"); // files = Directory.GetFiles(Application.streamingAssetsPath + "/Vuforia", "*.xml"); } else { files = Directory.GetFiles(dataSetDir, "*.xml"); } foreach (string dataSetFile in files) { string dataSetName = dataSetFile.Split('/').Last().Split('.')[0]; Debug.Log("Found dataset: " + dataSetName); DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(dataSetFile, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 1000 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>"); } SetActiveOverlayObject(dataSetName); IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { Debug.Log("Found TrackableBehavior: " + tb.name + ", in " + dataSetName); string[] trackableInfo = tb.TrackableName.Split(new string[] { "_-_" }, 2, StringSplitOptions.None); var contentId = trackableInfo[0]; var modelName = trackableInfo[1]; tb.gameObject.name = "ImageTarget:" + dataSetName + ":" + modelName + ":" + contentId; UnityEngine.Object prefab; if (string.Equals(dataSetName, NativeAppInterface.CurrentExperience, StringComparison.OrdinalIgnoreCase)) { Debug.Log("^In current experience"); prefab = Resources.Load("Prefabs/" + modelName, typeof(GameObject)); tb.gameObject.AddComponent(Type.GetType(activeHandlerName)); } else { Debug.Log("^Not in current experience"); prefab = Resources.Load("Prefabs/" + inactivePrefab, typeof(GameObject)); tb.gameObject.AddComponent <InactiveExperienceTrackableEventHandler>(); } tb.gameObject.AddComponent <TurnOffBehaviour>(); if (prefab == null) { Debug.Log("<color=yellow>Warning: No augmentation object available for: " + tb.TrackableName + "</color>"); } else { GameObject augmentation = Instantiate(prefab) as GameObject; augmentation.transform.parent = tb.gameObject.transform; augmentation.transform.localPosition = new Vector3(0f, 0f, 0f); augmentation.gameObject.SetActive(true); } } } } else { Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>"); } } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } NativeAppInterface.NotifyVuforiaLoaded((int)VuforiaUnity.InitError.INIT_SUCCESS); }
// Load and activate a data set at the given path. private bool LoadDataSet(string dataSetPath) { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(dataSetPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { objectTracker.Stop(); // stop tracker so that we can add new dataset if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 100 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSet + "</color>"); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } int counter = 0; IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { tb.gameObject.transform.parent = ObjectsGameObject.transform; // change generic name to include trackable name tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName; // add additional script components for trackable tb.gameObject.AddComponent <TrackableEventHandler>(); tb.gameObject.AddComponent <TurnOffBehaviour>(); if (SuccessGameObject != null && ErrorGameObject != null) { // instantiate augmentation object and parent to trackable GameObject augmentation = EventManager.Instance.IsDeviceAccessible(tb.TrackableName) ? Instantiate(SuccessGameObject) : Instantiate(ErrorGameObject); augmentation.transform.parent = tb.gameObject.transform; augmentation.transform.localPosition = new Vector3(0f, 0f, 0f); augmentation.transform.localRotation = Quaternion.identity; augmentation.transform.Find("Canvas").gameObject.SetActive(false); //add button event if (EventManager.Instance.IsDeviceAccessible(tb.TrackableName)) { augmentation.transform.Find("HiddenName").gameObject.GetComponent <Text>().text = tb.TrackableName; augmentation.transform.Find("Canvas").gameObject.GetComponentInChildren <Button>().onClick .AddListener( delegate { var canvas = transform.Find("/Objects") .Find(tb.TrackableName + "_canvas"); if (canvas != null) { UIManager.Instance.PanelBackClick(canvas.gameObject); } EventManager.Instance.ObjectClicked(augmentation, augmentation.transform.Find("HiddenName").gameObject.GetComponent <Text>().text); }); } augmentation.SetActive(true); } else { Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>"); } } } } else { Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetPath + "'</color>"); } return(true); }
IEnumerator LoadDataSet() { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker> (); objectTracker.DestroyAllDataSets(false); objectTracker.Stop(); // stop tracker so that we can add new dataset var tNodes = data.Element("trackings").Nodes(); foreach (XElement node in tNodes) { string dataSetName = Xml.Attribute(node, "src"); DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(GetAssetsPath(dataSetName), VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 100 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>"); } } } //int counter = 0; IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { Logger.Log(tb.TrackableName, "purple"); tb.gameObject.name = "AR-" + tb.TrackableName; XElement info = Xml.GetChildByAttribute(itemInfos, "id", tb.TrackableName); if (info == null) { continue; } string objType = Xml.Attribute(info, "type"); tb.gameObject.AddComponent <DefaultTrackableEventHandler> (); tb.gameObject.AddComponent <CustomTrackableEventHandler> (); tb.gameObject.AddComponent <TurnOffBehaviour> (); CustomTrackableEventHandler cte = tb.gameObject.GetComponent <CustomTrackableEventHandler> (); cte.type = objType; cte.subtitlePath = GetAssetsPath(Xml.Attribute(info, "subtitle"), true); UnityEngine.Object asset = null; if (objType == "object") { asset = loadedAssets.ContainsKey(tb.TrackableName) ? loadedAssets [tb.TrackableName] : new GameObject(); } else if (objType == "video") { asset = planePrefab; //Renderer render = (planePrefab).GetComponent<Renderer> (); //render.material = videoMaterial; cte.videoPath = GetAssetsPath(Xml.Attribute(info, "videosrc"), true); //cte.mediaPlayer = mediaPlayer; } else if (objType == "menu4") { //asset = planePrefab; //Renderer render = (planePrefab).GetComponent<Renderer> (); //render.material = videoMaterial; //CustomTrackableEventHandler cte = tb.gameObject.GetComponent<CustomTrackableEventHandler> (); //cte.videoPath = GetAssetsPath (tb.TrackableName + ".mp4"); //cte.mediaPlayer = mediaPlayer; tb.gameObject.AddComponent <PopMenu> (); PopMenu popmenu = tb.gameObject.GetComponent <PopMenu> (); popmenu.menuItems = new List <PopMenuItem> (); //popmenu.playerMateral = videoMaterial; var menuNodes = info.Elements(); //XElement res = null; int index = 0; foreach (XElement n in menuNodes) { GameObject planeItem = GameObject.Instantiate(Resources.Load("Prefabs/PlaneItem4")) as GameObject; PopMenuItem pmi = planeItem.GetComponent <PopMenuItem> (); popmenu.menuItems.Add(pmi); pmi.floatSpeed = 5f; pmi.floatAmplitude = 0.03f; pmi.index = index; pmi.menu = popmenu; pmi.trackableHandler = cte; planeItem.transform.SetParent(tb.gameObject.transform, false); Vector3 position = planeItem.transform.localPosition; if (index == 1) { planeItem.transform.localPosition = position.SetX(-position.x); } else if (index == 2) { planeItem.transform.localPosition = position.SetZ(-position.z); } else if (index == 3) { planeItem.transform.localPosition = new Vector3(-position.x, position.y, -position.z); } pmi.Initiate(); string itemSrc = Xml.Attribute(n, "src"); string videoPath = Xml.Attribute(n, "videosrc"); pmi.subtitlePath = GetAssetsPath(Xml.Attribute(n, "subtitle"), true); if (!string.IsNullOrEmpty(videoPath)) { pmi.videoPath = GetAssetsPath(videoPath); } else { GameObject prefab = loadedAssets [Xml.Attribute(n, "prefab")] as GameObject; pmi.threeDObject = GameObject.Instantiate(prefab, prefab.transform.position, prefab.transform.rotation) as GameObject; pmi.threeDObject.transform.SetParent(tb.gameObject.transform, false); ApplyItemInfo(pmi.threeDObject, n); } WWW www = new WWW(GetAssetsPath(itemSrc, true)); yield return(www); Logger.Log(GetAssetsPath(itemSrc, true) + " " + www.texture.ToString()); pmi.material.mainTexture = www.texture; //Logger.Log (planeItem.transform.localPosition.x.ToString() + " " +planeItem.transform.localPosition.y+ " " + planeItem.transform.localPosition.z, "blue"); index++; } popmenu.Hide(); } //GameObject obj = (GameObject)GameObject.Instantiate (asset); if (asset != null) { GameObject prefab = asset as GameObject; GameObject obj = (GameObject)GameObject.Instantiate(prefab, prefab.transform.position, prefab.transform.rotation); obj.transform.SetParent(tb.gameObject.transform, false); ApplyItemInfo(obj, Xml.GetChildByAttribute(itemInfos, "id", tb.TrackableName)); } //obj.gameObject.SetActive (true); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } }
//uses vuforia library to load a dataset with all the image targets then creates image target objects that are AR trackable void LoadDataSet() { //object tracker is what finds targets on the camera feed. ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); DataSet dataSet = objectTracker.CreateDataSet(); string dataSetPath = streamPath + dataSetName + ".xml"; //debugText.text += dataSetPath + "\n"; //load dataset if (dataSet.Load(dataSetPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { objectTracker.Stop(); // stop tracker so that we can add new dataset if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 1000 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>"); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } float lastTime = Time.time; debugText.text += "Loading dataset @ time: " + lastTime + "\n"; //create image targets and add vuforia components int counter = 0; IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { // change generic name to include trackable name tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName; lastTime = Time.time; // add additional script components for trackable tb.gameObject.AddComponent <DefaultTrackableEventHandler>(); tb.gameObject.AddComponent <TurnOffBehaviour>(); // attaches all the gameobjects for functionality like video and contact card if (augmentationObject != null) { // instantiate augmentation object and parent to trackable GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject); augmentation.transform.SetParent(tb.gameObject.transform, true); augmentation.gameObject.SetActive(true); } else { Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>"); } lastTime = Time.time; } } } else { //debugText.text += "<color=red>Failed to load dataset: '" + dataSetName + "'</color>"; Debug.LogError("<color=red>Failed to load dataset: '" + dataSetName + "'</color>"); } }
private void LoadDataSet() { ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); if (tracker != null) { Debug.Log("tracker here"); } DataSet dset = tracker.CreateDataSet(); if (dset.Load(DSPath + "/ds.xml", VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { Debug.Log("Dataset loaded"); if (tracker.ActivateDataSet(dset)) { Debug.Log("DS activated"); requestCheck = true; // deb3.text = "DS activated"; } else { Debug.Log("DS not activated"); } } else { Debug.LogError("Failed to load dataset!"); // deb3.text = "Failed to load dataset!"; } int counter = 0; IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { // change generic name to include trackable name tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName; // add additional script components for trackable if (tb.TrackableName.Contains("vid_")) { VideoTrackableEventHandler vteh = tb.gameObject.AddComponent <VideoTrackableEventHandler>(); vteh.mainCanv = mainCanvas; vteh.riglaCanv = riglaCanvas; GameObject vGO = Instantiate(videoGO, tb.gameObject.transform); ImageTargetBehaviour itb = (ImageTargetBehaviour)tb; if (tb.TrackableName.Contains("stre")) { if (itb.GetSize().x > itb.GetSize().y) { vGO.transform.localScale = new Vector3(itb.GetSize().x / 100, vGO.transform.localScale.y, itb.GetSize().y / 100); } else { vGO.transform.localScale = new Vector3(itb.GetSize().x / (itb.GetSize().y * 10), vGO.transform.localScale.y, itb.GetSize().y / (itb.GetSize().y * 10)); } } else { // Debug.Log(itb.GetSize()); //LOAD videoscale StartCoroutine(DownloadVideoScale(vGO, tb.TrackableName)); //END LOAD videoscale } vGO.GetComponentInChildren <VideoPlayer>().url = "http://glazar.pa.infobox.ru/ar/GlazAR/Video/" + tb.TrackableName + ".mp4"; VideoController v = vGO.GetComponent <VideoController>(); if (tb.TrackableName.Contains("play")) { v.playOnAwake = true; } HandsDeleter hd = tb.gameObject.AddComponent <HandsDeleter>(); hd.hands = handsOn; hd.mainCanv = mainCanvas; hd.riglaCanv = riglaCanvas; StatGrabber sg = tb.gameObject.AddComponent <StatGrabber>(); sg.initstat = initstat; v.statGrabber = sg; // v.stat } else { tb.gameObject.AddComponent <ABLoader>(); GameObject prl = Instantiate(preloader, tb.gameObject.transform); // prl.transform.localScale = prl.transform.lossyScale; if (tb.TrackableName.Contains("deadpool")) { deadpoolInteractive a = tb.gameObject.AddComponent <deadpoolInteractive>(); a.tagbtns = "deadbuttons"; } if (tb.TrackableName.Contains("robottank")) { deadpoolInteractive a = tb.gameObject.AddComponent <deadpoolInteractive>(); a.tagbtns = "deadrobotbtns"; } if (tb.TrackableName.Contains("tank") || tb.TrackableName.Contains("deadpool")) { ((ImageTarget)tb.Trackable).StartExtendedTracking(); } TrackableHandler tr = tb.gameObject.AddComponent <TrackableHandler>(); tr.hands = handsOn; tr.mainCanv = mainCanvas; tr.riglaCanv = riglaCanvas; if (tb.TrackableName.Contains("pavelg")) { PavelMarker pm = tb.gameObject.AddComponent <PavelMarker>(); pm.gatchinaUI = gatchinaPanel; } } tb.gameObject.AddComponent <TurnOffBehaviour>(); } } handsOn.SetActive(true); isRunning = false; }
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"); } }