Guest User

VuforiaTrackable

a guest
Nov 19th, 2020
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. StartCoroutine(CreateImageTargetFromDownloadedTexture());
  2.  
  3. IEnumerator CreateImageTargetFromDownloadedTexture()
  4. {
  5.     using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("https://vuforialibrarycontent.vuforia.com/Images/devGuide_ImageTargets.jpg"))
  6.     {
  7.         yield return uwr.SendWebRequest();
  8.  
  9.         if (uwr.isNetworkError || uwr.isHttpError)
  10.         {
  11.             Debug.Log(uwr.error);
  12.         }
  13.         else
  14.         {
  15.             var objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
  16.  
  17.             // Get downloaded texture once the web request completes
  18.             var texture = DownloadHandlerTexture.GetContent(uwr);
  19.  
  20.             // get the runtime image source and set the texture
  21.             var runtimeImageSource = objectTracker.RuntimeImageSource;
  22.             runtimeImageSource.SetImage(texture, 0.15f, "myTargetName");
  23.  
  24.             // create a new dataset and use the source to create a new trackable
  25.             var dataset = objectTracker.CreateDataSet();
  26.             var trackableBehaviour = dataset.CreateTrackable(runtimeImageSource, "myTargetName");
  27.  
  28.             // add the DefaultTrackableEventHandler to the newly created game object
  29.             trackableBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();
  30.  
  31.             // activate the dataset
  32.             objectTracker.ActivateDataSet(dataset);
  33.  
  34.             // TODO: add virtual content as child object(s)
  35.             var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  36.             cube.transform.SetParent(trackableBehaviour.gameObject.transform);
  37.         }
  38.     }
  39. }
RAW Paste Data