Log in or register to post comments

Vuforia Unity - What am I doing wrong?

April 5, 2016 - 5:30pm #1

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?

April 7, 2016 - 8:01pm #7

Vuforia Unity - What am I doing wrong?

April 7, 2016 - 7:01pm #6
Thank you dm3d, I appreciate your help.
 
I compare Cloud Reco sample app with mi proyect and I dont find differences.
My code download a 3D model from the web then create a copy and I try to show it. When I show it, this is not in the middle of the image Target in 3D space, it is printed in the screen coord space.
What is the trouble? I can't find the bug.
 
Please, help me to find a solution.
 
Thank very much for you help.
Best regars.

Vuforia Unity - What am I doing wrong?

April 7, 2016 - 3:50pm #5

Your augmentation needs to be parented to the ImageTarget. Compare your setup to the CloudReco sample app:

https://developer.vuforia.com/downloads/samples

 

Vuforia Unity - What am I doing wrong?

April 7, 2016 - 3:36pm #4
I think there is no technical assistants in the Vuforia business.
How can I upgrade my Cloud Plans if they do not help me in this simple bug?
 
I'm very frustrated.

Vuforia Unity - What am I doing wrong?

April 7, 2016 - 1:48pm #3

Hi friends,

I can pay to fix this bug, I need it too urgent. 
 
USD $20. Maybe take you 2 minutes to fix it. 
 
Thank you, best regards.

Vuforia Unity - What am I doing wrong?

April 6, 2016 - 12:51pm #2

Please, there are some Vuforia guru over here? Help me please.

 

Thanks.

Log in or register to post comments