By Alfox
on Wed, 03/30/2016 - 06:44
hi everyone, I have problem with this code, and Im not clearly understand it. I want to make cloud reco can scanning more than one image target. I have added chips and tarmac cloud target and at this point I want to show 2 different 3D models, "ana" and "ironman" but thats not success. when I scan it, both of image target only show "ana" . please help me
Im using this code:
using UnityEngine; using System.Collections; using Vuforia; public class SimpleCloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler { #region PRIVATE_MEMBER_VARIABLES // CloudRecoBehaviour reference to avoid lookups private CloudRecoBehaviour mCloudRecoBehaviour; // ImageTracker reference to avoid lookups private ObjectTracker mImageTracker; private GameObject ana, ironman; #endregion // PRIVATE_MEMBER_VARIABLES #region EXPOSED_PUBLIC_VARIABLES /// <summary> /// can be set in the Unity inspector to reference a ImageTargetBehaviour that is used for augmentations of new cloud reco results. /// </summary> public ImageTargetBehaviour ImageTargetTemplate; #endregion #region UNTIY_MONOBEHAVIOUR_METHODS /// <summary> /// register for events at the CloudRecoBehaviour /// </summary> void Start() { // register this event handler at the cloud reco behaviour CloudRecoBehaviour CloudRecoBehaviour = GetComponent<CloudRecoBehaviour>(); if (CloudRecoBehaviour) { CloudRecoBehaviour.RegisterEventHandler(this); } // remember cloudRecoBehaviour for later mCloudRecoBehaviour = CloudRecoBehaviour; /* teapot = GameObject.Find("teapot"); dragon = GameObject.Find("Dragon"); Hide( teapot ); Hide( dragon ); */ //teapot.SetActive( false ); //dragon.SetActive( false ); } #endregion // UNTIY_MONOBEHAVIOUR_METHODS #region ICloudRecoEventHandler_IMPLEMENTATION /// <summary> /// called when TargetFinder has been initialized successfully /// </summary> public void OnInitialized() { Debug.Log("Cloud Reco initialized"); // get a reference to the Image Tracker, remember it ObjectTracker imageTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); //mImageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER); } /// <summary> /// visualize initialization errors /// </summary> public void OnInitError(TargetFinder.InitState initError) { Debug.Log("Cloud Reco init error " + initError.ToString()); } /// <summary> /// visualize update errors /// </summary> public void OnUpdateError(TargetFinder.UpdateState updateError) { Debug.Log("Cloud Reco update error " + updateError.ToString()); } /// <summary> /// when we start scanning, unregister Trackable from the ImageTargetTemplate, then delete all trackables /// </summary> public void OnStateChanged(bool scanning) { } /// <summary> /// Handles new search results /// </summary> /// <param name="targetSearchResult"></param> public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) { // duplicate the referenced image target GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject; GameObject augmentation = null; string model_name = targetSearchResult.MetaData; if( augmentation != null ) augmentation.transform.parent = newImageTarget.transform; // enable the new result with the same ImageTargetBehaviour: //ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); //ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget); ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)mImageTracker.TargetFinder.EnableTracking( targetSearchResult, newImageTarget); Debug.Log("Metadata value is " + model_name ); switch( model_name ){ case "ana" : Destroy( imageTargetBehaviour.gameObject.transform.Find("ana").gameObject ); break; case "ironman" : Destroy( imageTargetBehaviour.gameObject.transform.Find("ironman").gameObject ); break; } if (imageTargetBehaviour != null) { // stop the target finder mCloudRecoBehaviour.CloudRecoEnabled = false; } } #endregion // ICloudRecoEventHandler_IMPLEMENTATION private void Hide( GameObject model ){ Debug.Log( "Hiding "+ model.name ); Renderer[] rendererComponents = model.GetComponentsInChildren<Renderer>(); Collider[] colliderComponents = model.GetComponentsInChildren<Collider>(); // Disable rendering: foreach (Renderer component in rendererComponents) { component.enabled = false; } // Disable colliders: foreach (Collider component in colliderComponents) { component.enabled = false; } //Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost"); } }
Hi,
Hi,
Does Vuforia planned anything about this ? The first post about multiple image targets reco is now 4 years old, is any improvement coming ? (or maybe it is a paid feature ?)
Thanks for any informations about this !
I have the same problem too.
I have the same problem too. Dose vuforia team members have any solutions?
Hello Vuforia Support
Hello Vuforia Support
I want to recognize multiple targets at the same time by using Vuforia Cloud.
Is this possible now?
Thanks