Esempio n. 1
0
        static void OnMapCallback(int TrackerID, IntPtr receivedData, int Length)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            while (!File.Exists("temp.raw.area"))
            {
                TimeSpan ts = sw.Elapsed;
                if (ts.TotalSeconds > 4)
                {
                    break;
                }
            }
            sw.Restart();
            bool didComplete = false;

            byte[] received = null;
            while (!didComplete)//this sucks, but it's the only way to wait til the zed has actually _finished_ writing the file
            {
                try{
                    #if ZED_SDK
                    received = System.IO.File.ReadAllBytes("temp.raw.area");
                    #else
                    received = System.IO.File.ReadAllBytes("temp.raw");
                    #endif

                    didComplete = true;//will flag the pass is complete
                }catch (System.Exception e) {
                    Debug.LogError(e);
                    TimeSpan ts = sw.Elapsed;
                    if (ts.TotalSeconds > 4)
                    {
                        break;
                    }
                }
            }
            if (didComplete)
            {
                UnityEngine.Debug.Log("Received map data of length: " + received.Length);
                if (instances[TrackerID] != null)
                {
                    EskyMap retEskyMap = new EskyMap();
                    retEskyMap.mapBLOB = received;
                    instances[TrackerID].SetEskyMapInstance(retEskyMap);
                    //I should collect the mesh data here
                }
                else
                {
                    UnityEngine.Debug.LogError("The instance of the tracker was null, cancelling data map export");
                }
            }
            else
            {
                UnityEngine.Debug.LogError("Problem exporting the map, *shrug*");
            }
            //System.IO.File.WriteAllBytes("Assets/Resources/Maps/mapdata.txt",received);
        }
Esempio n. 2
0
 public override void LoadEskyMap(EskyMap m)
 {
     retEskyMap = m;
     if (File.Exists("temp.raw"))
     {
         File.Delete("temp.raw");
     }
     System.IO.File.WriteAllBytes("temp.raw", m.mapBLOB);
     FlagMapImport(TrackerID);
 }
Esempio n. 3
0
 public override void LoadEskyMap(EskyMap m)
 {
     retEskyMap = m;
     if (File.Exists("temp.raw"))
     {
         File.Delete("temp.raw");
     }
     System.IO.File.WriteAllBytes("temp.raw", m.mapBLOB);
     SetMapData(new byte[] {}, 0);
 }
Esempio n. 4
0
        public void SetEskyMapInfo(EskyMap information)
        {
            foreach (KeyValuePair <string, EskyAnchorContentInfo> content in information.contentLocations)
            {
                if (myContent.ContainsKey(content.Key))
                {
                    myContent[content.Key].transform.localPosition = content.Value.localPosition;
                    myContent[content.Key].transform.localRotation = content.Value.localRotation;
                }
                else
                {
                    Debug.LogWarning("Careful, we don't have this content id in the scene: " + content.Key);
                }
            }
            if (loadMapMesh)
            {
                List <Mesh> meshes = new List <Mesh>();
                try
                {
                    meshes = (List <Mesh>)ProjectEsky.Utilities.EskyMeshSerializer.Deserialize(information.meshDataArray);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e);
                }
//                Debug.Log("Deserialized")
                Material matm = new Material(meshMaterial);
                for (int j = 0; j < meshes.Count; j++)
                {
                    GameObject gg = new GameObject();
                    gg.name = "Esky Loaded Mesh: " + j;
                    gg.AddComponent <MeshFilter>();
                    gg.GetComponent <MeshFilter>().mesh = meshes[j];
                    gg.layer = LayerMask.NameToLayer("WorldReconstruction");
                    gg.AddComponent <MeshRenderer>();
                    gg.AddComponent <MeshCollider>();
                    gg.transform.parent = meshRoot.transform;
                    gg.GetComponent <MeshRenderer>().sharedMaterial = matm;
                    gg.GetComponent <MeshRenderer>().enabled        = true;
                    gg.GetComponent <MeshRenderer>().receiveShadows = true;
                    gg.GetComponent <MeshCollider>().sharedMesh     = null;
                    gg.GetComponent <MeshCollider>().sharedMesh     = meshes[j];
                }
            }
            ProjectEsky.Utilities.EskyMeshSerializer.Deserialize(information.meshDataArray);
        }
Esempio n. 5
0
        public static EskyMap GetMapFromArray(byte[] data)
        {
            MemoryStream      ms = new MemoryStream(data);
            BinaryFormatter   bf = new BinaryFormatter();
            SurrogateSelector surrogateSelector = new SurrogateSelector();

            surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), new Vector3SerializationSurrogate());
            surrogateSelector.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), new QuaternionSerializationSurrogate());
            bf.SurrogateSelector = surrogateSelector;
            try{
                EskyMap em = (EskyMap)bf.Deserialize(ms);
                return(em);
            }catch (System.Exception e) {
                UnityEngine.Debug.LogError("Couldn't load esky map from data!: " + e);
                return(null);
            }
        }
Esempio n. 6
0
 public virtual void LoadEskyMap(EskyMap m)
 {
 }
Esempio n. 7
0
 public void SetEskyMapInstance(EskyMap em)
 {
     ShouldCallBackMap = true;
     retEskyMap        = em;
 }