/// <summary> /// Method called from the CloudRecoEventHandler /// when a new target is created /// </summary> public void TargetCreated(TargetFinder.CloudRecoSearchResult targetSearchResult) { string metadata = targetSearchResult.MetaData; if (metadata != null) { string[] splitStrings = metadata.Split(' '); if (splitStrings[0].Equals("2")) { isVideoPlayer = true; } /* * else if (splitStrings[0].Equals("1")) * { * isImage = true; * } */ } m_CloudContentManager.HandleTargetFinderResult(targetSearchResult); }
/// <summary> /// Method called from the CloudRecoEventHandler /// when a new target is created /// </summary> public void TargetCreated(TargetFinder.TargetSearchResult targetSearchResult) { m_CloudContentManager.HandleTargetFinderResult(targetSearchResult); }
/// <summary> /// Handles new search results /// </summary> /// <param name="targetSearchResult"></param> public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) { Debug.Log("<color=blue>OnNewSearchResult(): </color>" + targetSearchResult.TargetName); // This code demonstrates how to reuse an ImageTargetBehaviour for new search results and modifying it according to the metadata // Depending on your application, it can make more sense to duplicate the ImageTargetBehaviour using Instantiate(), // or to create a new ImageTargetBehaviour for each new result // Vuforia will return a new object with the right script automatically if you use // TargetFinder.EnableTracking(TargetSearchResult result, string gameObjectName) m_CloudContentManager.HandleTargetFinderResult(targetSearchResult); //Check if the metadata isn't null if (targetSearchResult.MetaData == null) { Debug.Log("Target metadata not available."); //return; } else //this was used for an easy quick demo. //each of targets used in the demo had a simple string metadata //where I parsed and showed all of the elements where nessecary { if (targetSearchResult.MetaData == "metrocard") { Debug.Log("Found Courtney! showing data"); shows.SetActive(true); map.SetActive(false); countdown.SetActive(false); magIssue.SetActive(false); } else if (targetSearchResult.MetaData == "magazine") { Debug.Log("Found magazine! showing data"); shows.SetActive(false); map.SetActive(false); countdown.SetActive(true); magIssue.SetActive(false); } else if (targetSearchResult.MetaData == "magCover") { Debug.Log("Found cover of Salt Mag! showing data"); shows.SetActive(false); map.SetActive(false); countdown.SetActive(false); magIssue.SetActive(true); } Debug.Log("MetaData: " + targetSearchResult.MetaData); Debug.Log("TargetName: " + targetSearchResult.TargetName); Debug.Log("Pointer: " + targetSearchResult.TargetSearchResultPtr); Debug.Log("TargetSize: " + targetSearchResult.TargetSize); Debug.Log("TrackingRating: " + targetSearchResult.TrackingRating); Debug.Log("UniqueTargetId: " + targetSearchResult.UniqueTargetId); } // First clear all trackables m_ObjectTracker.TargetFinder.ClearTrackables(false); // enable the new result with the same ImageTargetBehaviour: ImageTargetBehaviour imageTargetBehaviour = m_ObjectTracker.TargetFinder.EnableTracking(targetSearchResult, m_ImageTargetTemplate.gameObject) as ImageTargetBehaviour; }
public void TargetCreated(TargetFinder.CloudRecoSearchResult targetSearchResult) { m_CloudContentManager.HandleTargetFinderResult(targetSearchResult); this.gameObject.transform.localScale = Vector3.one; }
// https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.htm#How-To-Update-a-Target IEnumerator PutUpdateTarget(bool updateImage = false) { Debug.Log("CustomMessage: PutUpdateTarget()"); // Setting up query. string requestPath = "/targets/" + currentImageData.UniqueTargetId; string serviceURI = url + requestPath; string httpAction = "PUT"; string contentType = "application/json"; string date = string.Format("{0:r}", DateTime.Now.ToUniversalTime()); string metadataStr = jsonData; byte[] metadata = System.Text.ASCIIEncoding.ASCII.GetBytes(metadataStr); // Create new model to prepare for sending. PostNewTrackableRequest model = new PostNewTrackableRequest(); model.name = targetName; model.width = 64.0f; model.application_metadata = System.Convert.ToBase64String(metadata); if (updateImage) { // Create texture and encode pixels to base64. Texture2D tex = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false); tex.SetPixels(texture.GetPixels()); tex.Apply(); byte[] image = tex.EncodeToPNG(); model.image = System.Convert.ToBase64String(image); } // Convert model to json. string requestBody = JsonUtility.ToJson(model); // Create ContentMD5. MD5 md5 = MD5.Create(); var contentMD5bytes = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(requestBody)); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < contentMD5bytes.Length; i++) { sb.Append(contentMD5bytes[i].ToString("x2")); } string contentMD5 = sb.ToString(); string stringToSign = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", httpAction, contentMD5, contentType, date, requestPath); // Build signature. HMACSHA1 sha1 = new HMACSHA1(System.Text.Encoding.ASCII.GetBytes(secret_key)); byte[] sha1Bytes = System.Text.Encoding.ASCII.GetBytes(stringToSign); MemoryStream stream = new MemoryStream(sha1Bytes); byte[] sha1Hash = sha1.ComputeHash(stream); string signature = System.Convert.ToBase64String(sha1Hash); Debug.Log("<color=green>Signature: " + signature + "</color>"); // Build Http Request. BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(serviceURI)); request.MethodType = BestHTTP.HTTPMethods.Put; request.RawData = Encoding.UTF8.GetBytes(requestBody); request.AddHeader("Authorization", string.Format("VWS {0}:{1}", access_key, signature)); request.AddHeader("Content-Type", contentType); request.AddHeader("Date", date); request.Send(); yield return(StartCoroutine(request)); switch (request.State) { case BestHTTP.HTTPRequestStates.Error: Debug.Log("request error: " + request.Exception.Message); string errorText = request.Exception.Message; PrintStatusText("Exception: " + errorText); break; case BestHTTP.HTTPRequestStates.Finished: // There is an error if (request.Response.StatusCode != 200) { Debug.Log("request error: " + request.Response.Message); string result_code = JsonUtility.FromJson <VWSResponse>(request.Response.DataAsText).result_code; // The target is still being processed in Vuforia API. if (result_code == "TargetStatusNotSuccess") { PrintStatusText("Error: Profile is still being processed in Vuforia!"); } else { PrintStatusText("Error: " + result_code); } } else { Debug.Log("request success"); PrintStatusText("Saved!"); if (rescanCloudAfterEdit) { // We disable cloud tracking for x seconds. The reason why we do this is because it takes time for // Vuforia to actually delete the record. If we continue cloud tracking, it would retrack the record. DisableCloudTracking(2f); // To get all the tracked targets. For testing. // IEnumerable<Vuforia.ObjectTarget> obj = Vuforia.TrackerManager.Instance.GetTracker<Vuforia.ObjectTracker>().GetTargetFinder<Vuforia.ImageTargetFinder>().GetObjectTargets(); // IEnumerator myEnum = obj.GetEnumerator(); // while(myEnum.MoveNext()){ // print(myEnum.Current); // } // Clear local copy. Vuforia.TrackerManager.Instance.GetTracker <Vuforia.ObjectTracker>().GetTargetFinder <Vuforia.ImageTargetFinder>().ClearTrackables(false); } else { // Since the image is saved to the cloud, we can change the local copy. currentImageData.MetaData = metadataStr; currentImageData.TargetName = targetName; // Force update of target info. cloudContentManager.HandleTargetFinderResult(currentImageData); // The only issue with this method is we do not know the new tracking rating of the copy. // However, since our version of profiler does not show tracking rating, it should work fine. // Also, if the new image fails the processor on Vuforia's side, it wouldn't make sense to // change the local copy's data. However, it would be more convenient for the user to see // the new updated version. Therefore, when changing the local copy, we are assuming the // new image to be processed successfully. } // Close edit menu. ToggleEditMenu(); } break; } // Enable buttons. deleteDeleteButton.interactable = true; putEditButton.interactable = true; editButton.interactable = true; }