By Tucmagames
on Wed, 04/06/2016 - 00:30
Hi friends.
I have a very BIG trouble with my Unity Vuforia Proyect.
Why my 3D models are in "CAMERA" world center mode?
Here is my code of "CloudRecoEventHandler" class.
using System; using UnityEngine; using System.Collections; using Vuforia; public class CloudRecoEventHandler : MonoBehaviour, ICloudRecoEventHandler { private GameObject mParentOfImageTargetTemplate; private ObjectTracker mImageTracker; private int progress; public int guiOffset = 20; private WWW www; private string BundleURL; private string resultado; private CloudRecoBehaviour mCloudRecoBehaviour; private bool mIsScanning = false; private string mTargetMetadata = ""; TargetFinder.TargetSearchResult TargetResults; GameObject GO; GameObject ImageTargetUsed = null; #region PUBLIC_MEMBERS /// <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 //PUBLIC_MEMBERS // GameObject ImageTargetUsed = null; void Start() { try { if (ImageTargetTemplate) { mParentOfImageTargetTemplate = ImageTargetTemplate.gameObject; } } catch (Exception e) { // UnityEngine.Debug.Log(e.ToString()); throw; } // register this event handler at the cloud reco behaviour mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>(); if (mCloudRecoBehaviour) { mCloudRecoBehaviour.RegisterEventHandler(this); } } public void OnInitialized() { Debug.Log("Cloud Reco initialized"); //mParentOfImageTargetTemplate = ImageTargetTemplate.gameObject; } public void OnInitError(TargetFinder.InitState initError) { Debug.Log("Cloud Reco init error " + initError.ToString()); } public void OnUpdateError(TargetFinder.UpdateState updateError) { Debug.Log("Cloud Reco update error " + updateError.ToString()); } public void OnStateChanged(bool scanning) { mIsScanning = scanning; if (scanning) { // clear all known trackables ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); tracker.TargetFinder.ClearTrackables(false); } } IEnumerator GetAssetBundle() { // string AssetName = ""; resultado+= "Cargando"; www = new WWW(BundleURL); // www = WWW.LoadFromCacheOrDownload(BundleURL, 1); yield return www; // www = WWW.LoadFromCacheOrDownload(BundleURL, 1); // www = new WWW.LoadFromCacheOrDownload("file:///mnt/sdcard/testbundle/test.unity3d", 1); // Debug.Log("The last BundleURL " + BundleURL); // resultado = "Se esta cargando"; // AssetBundle bundle = www.assetBundle; /* if (AssetName == "") Instantiate(bundle.mainAsset); else Instantiate(bundle.LoadAsset(AssetName)); */ resultado+= "Leyendo"; AssetBundleRequest request; // AssetBundle bundle = www.assetBundle; try { // if (bundle == null) // { // resultado += " Bundle es null "; // } resultado += www.assetBundle; string[] s = www.assetBundle.GetAllAssetNames(); resultado+= "Leyendo"+s.Length; foreach (string asset in s) { resultado += asset + "--"; } request = www.assetBundle.LoadAssetAsync("king", typeof(GameObject)); } catch (Exception e) { resultado+= "ERROR"+e.ToString(); throw; } // AssetBundleRequest request = www.assetBundle.LoadAllAssetsAsync(); yield return request; resultado+= "1"; resultado+= "Paso request"; // Transform IC = GameObject.Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity) as Transform; GO = Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject; // Put the stream model under the image target // GameObject ImageTargetUsed = GameObject.Find("CloudRecoTarget"); // Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity); // Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity); resultado+= "2"; // AssetBundle assetBundle = www.assetBundle; // Instantiate(assetBundle.mainAsset); // Instantiate(assetBundle.Load("AssetName")); ImageTargetUsed = GameObject.Find("ImageTarget"); if (ImageTargetUsed==null) { resultado += "NULLL"; } resultado += "3"; // GameObject ModelIpadClone = GameObject.Find("Lionel_Messi(clone)"); // GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject; if (mParentOfImageTargetTemplate) { // enable the new result with the same ImageTargetBehaviour: ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); tracker.TargetFinder.EnableTracking(TargetResults, mParentOfImageTargetTemplate); resultado += "4"; } // if (ImageTargetUsed == null) // { // resultado += "nullTarget"; // } /* if (ModelIpadClone == null) { resultado += "ModelIpadCloneNULL"; } */ if (mParentOfImageTargetTemplate) { resultado += "4.5"; GO.transform.parent = mParentOfImageTargetTemplate.transform; } resultado += "5"; // GO.SetActive(true); // bundle.Unload(false); // www.Dispose(); // yield return ImageTargetUsed; } // Here we handle a cloud target recognition event public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) { resultado = ""; TargetResults = targetSearchResult; // do something with the target metadata BundleURL = mTargetMetadata = targetSearchResult.MetaData; // stop the target finder (i.e. stop scanning the cloud) mCloudRecoBehaviour.CloudRecoEnabled = false; if (!ImageTargetTemplate) resultado += " ImageTargetTemplate es nulo "; else resultado += " ImageTargetTemplate ES OK "; StartCoroutine(GetAssetBundle()); } void Update() { // Vector3 vect = new Vector3(1,1,1); // if(GO) // GO.transform.parent.Rotate(GO.transform.parent.rotation.eulerAngles + vect); } void OnGUI() { GUILayout.Space(guiOffset); progress = (int)(www.progress * 100); GUILayout.Label("download: " + progress + "% " + resultado); // GUILayout.Label("download: " + progress + "%"); GUILayout.Label("ValuesXYZ: " + mParentOfImageTargetTemplate.transform.position.x + " y=" + mParentOfImageTargetTemplate.transform.position.y + " z=" + mParentOfImageTargetTemplate.transform.position.z); // Display current 'scanning' status GUI.Box(new Rect(100, 100, 200, 50), mIsScanning ? "Scanning" : "Not scanning"); // Display metadata of latest detected cloud-target GUI.Box(new Rect(100, 200, 500, 50), "Metadata: " + mTargetMetadata); // If not scanning, show button // so that user can restart cloud scanning if (!mIsScanning) { if (GUI.Button(new Rect(100, 300, 200, 50), "Restart Scanning")) { // Restart TargetFinder mCloudRecoBehaviour.CloudRecoEnabled = true; } } } }
Vuforia Unity - What am I doing wrong?
Please, there are some Vuforia guru over here? Help me please.
Thanks.
Vuforia Unity - What am I doing wrong?
Hi friends,
Vuforia Unity - What am I doing wrong?