Log in or register to post comments

load dat and xml file at runtime on mobile

July 21, 2013 - 11:10pm #1

I have device database in vuforia website. I don't want store dat and xml file in unity project but i want that when i start my apk at that time one download option is come and from url i download dat and xml file in mobile then image recognition is done of image target. What is a procedure for same. I am able to reach to the url ogf dat and xml file but how to download it in device and where to store in moblie? Thabks in advance

load dat and xml file at runtime on mobile

July 19, 2014 - 11:39pm #26

Hello

That you did last year is like i will try. So, please I hope you let me know what is the result about your trial and instruction guide.

Thanks

load dat and xml file at runtime on mobile

August 9, 2013 - 6:03am #25

ok thank you so much for your co-operation.

load dat and xml file at runtime on mobile

August 9, 2013 - 5:55am #24

Well, it's not working now.

Can you download the 2.6 SDK and try again from scratch.

N

load dat and xml file at runtime on mobile

August 9, 2013 - 5:44am #23

My version is 2.5. I have check example of device database and cloud database it works at the time of downloading vuforia. I have also prpare my own  project for device, cloud and multi target.

load dat and xml file at runtime on mobile

August 9, 2013 - 5:31am #22

So this proves my point :)

There is something wrong with the dataset.

So go to the TMS and create a new test dataset and see if you can get this working locally first.  The TMS had a few changes that might have afected you.

 

Which version of Vuforia are you using?  If it is 1.5 you will have to upgrade to the latest - this is normally the best thing to do.

 

N

load dat and xml file at runtime on mobile

August 9, 2013 - 5:24am #21

Ok

I have check it .

It write both file but it stop at if(!DataSet.Exists(path,storageType))

in both.

load dat and xml file at runtime on mobile

August 9, 2013 - 5:09am #20

Yes I know this.

However I want to check whether the file actually works locally at all, so can you please test it so that the problem can be narrowed down?

 

N

load dat and xml file at runtime on mobile

August 9, 2013 - 5:07am #19

Actually I want to download this file from url and then perform detection. So I have deleted this file from project and at runtime I am downloading it. it download successfully but for detection i found this code and at that time i found this problem

https://developer.vuforia.com/resources/dev-guide/swappable-databases-unity

load dat and xml file at runtime on mobile

August 9, 2013 - 5:02am #18

Have you tested both of these locally?

i.e. on the device without any download to see if there is any problem there?

 

N

 

load dat and xml file at runtime on mobile

August 9, 2013 - 4:26am #17

i have make two different function for loading dat file and xml file.

For dat file it stop in fail to load dataset.     if(!dataSet.Load(path,storageType))

For xml it stop in dataset not exist.                 if (!DataSet.Exists(path1,storageType1))

What can I do next? Both files are written in mobile Application.persistencedatapath successfully.

Take ref of this

https://developer.vuforia.com/resources/dev-guide/swappable-databases-unity

 

load dat and xml file at runtime on mobile

August 7, 2013 - 2:11am #16

File is downloaded but 3d model is not loaded. my 3d model is not null

Typically we do not debug code on the forums like this.

To increase you chances of someone helping you, it will help enormously if you can try to narrow down the problem because bascially all you have said is "it does not work".

It seems that something downloads for you, but you do not know exactly what it is and you cannot see it.  I am not sure how anyone can actually help you until you can investigate this in more detail to answer why this is happening?

 

N

 

 

 

load dat and xml file at runtime on mobile

August 7, 2013 - 1:58am #15

using UnityEngine;

using System.Collections;

using     System.IO;

 

public  class LoadDat: MonoBehaviour {

 

//public WWW www,www1;

 public string url = "url for dat";

                public string url1="url for xml";

             

public string path1= Path.Combine(Application.persistentDataPath, "AugmentDAT.unity3d");

                public string path2=Path.Combine(Application.persistentDataPath,"AugmentXML.unity3d");

public int guiOffset = 20;

 public AssetBundle assetBundle;

 public Object instanced;

 public string str;

 private GameObject go;

 private int progress;

                ImageTargetBehaviour imageTarBeh=new ImageTargetBehaviour();

public LoadDat()

 {

 }

 

 // Use this for initialization

 IEnumerator Start1()

 {

                                                using(WWW www=new WWW(url))

                                {

                                                yield return www;

                                                str=str=str+"go into www1";

                                                if(www.isDone && string.IsNullOrEmpty(www.error))

                                                {

                                                                str=str=str+"go into if";

                                               

                                                                File.WriteAllBytes(Application.persistentDataPath+"/filenME.unity3d",www.bytes);

                                                               

                                                                str=str+"write completed";

                                                                                                                }

                                                                                                 LoadDataSet1(Application.persistentDataPath+"/filename.unity3d",DataSet.StorageType.STORAGE_APPRESOURCE);

                                }

                                 

 

 }

                IEnumerator Start2()     

                {

                                using(WWW www1=new WWW(url1))

                                {

                                                 yield return www1;

                                                str=str+"go into www2";

                                                if(www1.isDone && string.IsNullOrEmpty(www1.error))

                                                {

                                                                str=str+"go into if";

                                                                                File.WriteAllBytes(Application.persistentDataPath+"/filename.unity3d",www1.bytes);

                                                                                                }

               

                                                 LoadDataSet2(Application.persistentDataPath+"/filename.unity3d",DataSet.StorageType.STORAGE_APPRESOURCE);

                                }

 // LoadDataSet(path2,DataSet.StorageType.STORAGE_APPRESOURCE);

               

                }

 // Update is called once per frame

 void OnGUI()

 {

 GUILayout.Space(guiOffset);

  GUI.Label(new Rect(40,40,700,700),str);

                                if(GUI.Button(new Rect(0,0,60,60),"Click"))

                               

                StartCoroutine(Start1());

                               

                                if(GUI.Button(new Rect(60,60,60,60),"Click"))

                                                StartCoroutine(Start2());

               

 private bool LoadDataSet1(string dataSetPath1, DataSet.StorageType storageType)

{

    // Check if the data set exists at the given path.

    str="go into  load dataset";

                               

    // Request an ImageTracker instance from the TrackerManager.

  

    ImageTracker imageTracker =

        (ImageTracker)TrackerManager.Instance.GetTracker(

                                        Tracker.Type.IMAGE_TRACKER);

 

    // Create a new empty data set.

  

    DataSet dataSet = imageTracker.CreateDataSet();

 

    // Load the data set from the given path.

  

   if (!dataSet.Load(dataSetPath1, storageType) )

    {

   str="fail to load dataset1";

        Debug.LogError("Failed to load data set1.");

        return false;

    }

               

    // (Optional) Activate the data set.

  

    imageTracker.ActivateDataSet(dataSet);

        

  str="dataset load successfully";

                       

    return true;

}

               

                 private bool LoadDataSet2(string dataSetPath1, DataSet.StorageType storageType)

{

    // Check if the data set exists at the given path.

    str="go into  load dataset";

               

               

 

    // Request an ImageTracker instance from the TrackerManager.

  

    ImageTracker imageTracker =

        (ImageTracker)TrackerManager.Instance.GetTracker(

                                        Tracker.Type.IMAGE_TRACKER);

 

    // Create a new empty data set.

  

    DataSet dataSet = imageTracker.CreateDataSet();

 

    // Load the data set from the given path.

  

   if (!dataSet.Load(dataSetPath1, storageType) )

    {

   str="fail to load dataset2";

        Debug.LogError("Failed to load data set2.");

        return false;

    }

               

    // (Optional) Activate the data set.

  

    imageTracker.ActivateDataSet(dataSet);

                               

                                               

                                QCARBehaviour obj=new QCARBehaviour();

                                  str="dataset2 load successfully";

                                                                AttachContentToTrackables(dataSet);

 

                               

    return true;

}

               

 

                 private void AttachContentToTrackables(DataSet dataSet)

 {

               

             GameObject g = GameObject.Find("teapot1");

                                if(g!=null)

                                {

                                                                g.AddComponent<DefaultTrackableEventHandler>();

                                             // Attach the cube to the Trackable and make sure it has a proper size.

                                                                g.transform.parent=GameObject.Find("ImageTargetStones").transform;

                                                                               

                                                else{

                                                                                                                }

         

                                                g.transform.localScale = new Vector3(5.0f, 5.0f, 5.0f);

                               

                                                             g.transform.localPosition = new Vector3(0.0f, 0.35f, 0.0f);

                                               

             g.active = true;

                                               

                                }

                                else{

                                                str=str+"2";

 

                                }

         }

}

i have write this code . File is downloaded but 3d model is not loaded. my 3d model is not null. I have try by changing its scalling.all messages are alo printed,

load dat and xml file at runtime on mobile

August 5, 2013 - 7:00am #14

You may find these threads helpful:

https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/please-provide-sample-swapping-dataset-unity3d

https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/dynamically-load-unity-trackable-file-web

 

However, the definitive code is shown in the Developer Guide:

https://developer.vuforia.com/resources/dev-guide/swappable-databases-unity

 

Failing all this, if you cannot get it working, why not just use CloudReco, that's what it's there for.

 

N

 

load dat and xml file at runtime on mobile

August 4, 2013 - 10:03pm #13

ok i am successful for downloadng this file. Now how to set image target behaviour's dataset and image target.what to do next for image recognition?

I have write

obj.startqcar();

 but not succeded.

I think i should image target behaviour's  dataset and imageTarget  but how?

load dat and xml file at runtime on mobile

August 1, 2013 - 9:54pm #12

Hi 

I am successful to find downloading but downloading is not completed. After downloading xml file not write to my device. It print success but not download complete.My file is also not too large.Here is my code

function Start1() {
str=str+"start call";
var www = new WWW(url);
 
while(!www.isDone)
{
str=str+"Progress";
Debug.Log("www progress ");
yield  www;
 
}
{
str=str+"Success";
str=str+Application.persistentDataPath;
System.IO.File.WriteAllBytes(Application.persistentDataPath,www.bytes);
str=str+"download complete";
 
}
else
{
str=str+"fail";
Debug.Log("Fail");
}
}
Here I got msg uccess but not msg download complete. What can i do further?

load dat and xml file at runtime on mobile

July 30, 2013 - 11:02pm #11

Hi 

I think so dat and xml is not save in device. What to do for saving this file?

 

load dat and xml file at runtime on mobile

July 30, 2013 - 6:05am #10

I have write

File.WriteAllBytes(Application.persistentDataPath + "/imagetargetXml.xml", www.bytes);

and try it

filepath = Application.persistentDataPath+ @"/settings.xml";

LoadDataSet(filepath,DataSet.StorageType.STORAGE_APPRESOURCE);

but not succed

load dat and xml file at runtime on mobile

July 30, 2013 - 5:54am #9

Best would be to use the Unity abstraction path Application.persistentDataPath

http://docs.unity3d.com/Documentation/ScriptReference/Application-persistentDataPath.html

 

load dat and xml file at runtime on mobile

July 29, 2013 - 10:53pm #8

Hi all

I have given /sdcard0 as a path and /storage/sdcard0 as a path but it goes in this condition

 if (!DataSet.Exists(dataSetPath, storageType)) and return 0. What should I give as a path?

load dat and xml file at runtime on mobile

July 29, 2013 - 2:04am #7

Hi

i found this code for downloading dat and xml.

I found messsage download 100%

but not any other message can you tell me what modification is require for same.and recognition of imae target is also not done

 

Thanks n advance.

 

using UnityEngine;
using System.Collections;

public class LoadAssetBundle : MonoBehaviour {

public WWW www;
 public string url = "my URL";
 public string resourcePath = "Cube";
 public int guiOffset = 20;
 public AssetBundle assetBundle;
 public Object instanced;
 public string str;
 private GameObject go;
 private int progress;

 public LoadAssetBundle()
 {
 }

 // Use this for initialization
 IEnumerator Start()
 {
 // Start a download of the given URL
 www = WWW.LoadFromCacheOrDownload(url, 1);

 // Wait for download to complete
 yield return www;

 // Load and retrieve the AssetBundle
 assetBundle = www.assetBundle;

 // Load the GameObject
 //go = assetBundle.Load("mainAsset", typeof(GameObject)) as GameObject;
 go = (GameObject)assetBundle.mainAsset;

 // Instantiate the GameObject
 Instantiate(go);

  LoadDataSet(url,DataSet.StorageType.STORAGE_APP);
 GameObject goImageTarget = GameObject.Find("ImageTargetStones");
 GameObject goCube = GameObject.Find("teapot1(Clone)");
 goCube.transform.parent = goImageTarget.transform;
 }

 // Update is called once per frame
 void OnGUI()
 {
 GUILayout.Space(guiOffset);
 progress = (int)(www.progress * 100);
 GUILayout.Label("download: " + progress + "%");
  GUI.Label(new Rect(0,0,400,400),str);
 }
 private bool LoadDataSet(string dataSetPath, DataSet.StorageType storageType)
{
    // Check if the data set exists at the given path.
    str=str+"go into  load dataset";
    if (!DataSet.Exists(dataSetPath, storageType))
    {
   str=str+"dataset exist";
        Debug.LogError("Data set " + dataSetPath + " does not exist.");
        return false;
    }

    // Request an ImageTracker instance from the TrackerManager.
   
    ImageTracker imageTracker =
        (ImageTracker)TrackerManager.Instance.GetTracker(
                                        Tracker.Type.IMAGE_TRACKER);

    // Create a new empty data set.
   
    DataSet dataSet = imageTracker.CreateDataSet();

    // Load the data set from the given path.
   
    if (!dataSet.Load(dataSetPath, storageType))
    {
   str=str+"fail to load dataset";
        Debug.LogError("Failed to load data set " + dataSetPath + ".");
        return false;
    }

    // (Optional) Activate the data set.
   
    imageTracker.ActivateDataSet(dataSet);
  str=str+"dataset load successfully";
    return true;
}
}

load dat and xml file at runtime on mobile

July 22, 2013 - 11:54pm #6

If you are using Android, the sdcard could be a good candidate.

 

load dat and xml file at runtime on mobile

July 22, 2013 - 11:51pm #5

I found code for downloading and saving file and i have store one simple file from url also in my computer. Can you tell me where should i should store dat and xml file in my device.

Thanks n advance.

load dat and xml file at runtime on mobile

July 22, 2013 - 5:11am #4

You can use the Search functionality of the Forum; for instance this is one that I have found by searching "download xml";

https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/loading-datasets-external-scources

 

load dat and xml file at runtime on mobile

July 22, 2013 - 4:36am #3

Can you please share some links that i can refer i have find through forum post but not succeded.

load dat and xml file at runtime on mobile

July 21, 2013 - 11:59pm #2

Hi,

it is definitely possible to do what you describe here;

if you search the Forum, this topic has been discussed a few times, so you should be able to find some threads about it.

Note however that:

  •  how to download a file from the network is a general programming question, not something that relates to Vuforia, therefore it would be good to search for this information somewhere else
  •  how to store a file into the device local storage is also not related to Vuforia (same as above)

 

Log in or register to post comments