Search Unity

ArKit plugin - Loading ARReferenceObject from file on runtime.

Discussion in 'AR/VR (XR) Discussion' started by t-castelo, Mar 11, 2019.

  1. t-castelo

    t-castelo

    Joined:
    May 8, 2015
    Posts:
    4
    I am currently working on having a database of scanned objects. I have been using the arkit plugin to scan and save the objects on my Application.persistentDataPath + "/ARReferenceObjects/" folder.

    So far so good, but lets say I would like to come back and in another session and load to a List<ARReferenceObject> scannedObjects; all my previous saved objects.

    I have been doing the following:

    Code (CSharp):
    1. public void LoadObjects()
    2.     {
    3.         DirectoryInfo dir = new DirectoryInfo(filePath);
    4.         FileInfo[] info = dir.GetFiles("*.arobject");
    5.  
    6.         foreach (FileInfo f in info)
    7.         {
    8.             Debug.Log(f.ToString());
    9.             LoadARReferenceObject(f.ToString());
    10.         }
    11.     }
    12.  
    13.    
    14.     private void LoadARReferenceObject(string path)
    15.     {
    16.         Debug.Log("Trying to load a ARReferenceObject from path " + path);
    17.  
    18.         ARReferenceObject aRReferenceObject = ARReferenceObject.Load(path);
    19.  
    20.         if (aRReferenceObject != null)
    21.         {
    22.             Debug.Log("Not null");
    23.             scannedObjects.Add(aRReferenceObject);
    24.         }
    25.         else
    26.         {
    27.             Debug.Log("<color=red>Fail</color>");
    28.         }
    29.     }
    30.  
    So I am basically retrieving all the saved ".arobject" from the folder but RReferenceObject.Load(path); keeps failing and getting a Error Domain=com.apple.arkit.error Code=500 "File IO failed." with a NSLocalizedFailureReason=Unrecognized archive format.

    More in detail showing this on xcode :

    2019-03-11 12:41:05.028871+0000 ObjectScanner[1182:187799] [General] Unable to read archive at path: /var/mobile/Containers/Data/Application/70318DDB-BE5C-45DF-AFA0-6381166000B3/Documents/ARReferenceObjects/-L_bRPAu7_egITfMA7fR.arobject.

    2019-03-11 12:41:05.028964+0000 ObjectScanner[1182:187799] Error Domain=com.apple.arkit.error Code=500 "File IO failed." UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/70318DDB-BE5C-45DF-AFA0-6381166000B3/Documents/ARReferenceObjects/-L_bRPAu7_egITfMA7fR.arobject, NSLocalizedDescription=File IO failed., NSLocalizedFailureReason=Unrecognized archive format}

    I am not sure what I am doing wrong, fro originally saving I was using the code provided on the arkit plugin:

    Code (CSharp):
    1. public void SaveScannedObjects()
    2.     {
    3.         if (scannedObjects.Count == 0)
    4.             return;
    5.  
    6.         string pathToSaveTo = Path.Combine(Application.persistentDataPath, "ARReferenceObjects");
    7.  
    8.         if (!Directory.Exists (pathToSaveTo))
    9.         {
    10.             Directory.CreateDirectory (pathToSaveTo);
    11.         }
    12.  
    13.         foreach (ARReferenceObject arro in scannedObjects)
    14.         {
    15.             string fullPath = Path.Combine (pathToSaveTo, arro.name + ".arobject");
    16.             arro.Save (fullPath);
    17.         }
    18.     }
    Where the save and Load Functions are these.

    Code (CSharp):
    1.         public bool Save(string path)
    2.         {
    3.             return referenceObject_ExportObjectToURL(m_Ptr, path);
    4.         }
    5.  
    6.         public static ARReferenceObject Load(string path)
    7.         {
    8.             var ptr = referenceObject_InitWithArchiveUrl(path);
    9.             if (ptr == IntPtr.Zero)
    10.                 return null;
    11.  
    12.             return new ARReferenceObject(ptr);
    13.         }
    I would be very grateful if someone could guide me in the right direction.

    Thank you very much!

     
  2. LiamManeki

    LiamManeki

    Joined:
    Mar 31, 2014
    Posts:
    1
    Did you ever solve this problem? I'm having the same issue.