/// <summary>
        ///
        /// Meshes
        ///
        /// Parse mesh data
        /// Function decides if we are updating an already existing mesh or creating a new one.
        /// If a new mesh has been created this function will go through stored mesh instances
        /// and check if it can create new mesh instances.
        /// </summary>
        public static void ParseMeshData(System.IntPtr meshDataPtr)
        {
            try
            {
                var meshData = (MeshData)System.Runtime.InteropServices.Marshal.PtrToStructure(meshDataPtr, typeof(MeshData));

                // Convert unmanaged to managed memory
                ManagedMeshData managedMeshData = MeshHandler.ManageMeshMemory(meshData);

                // If all dependants are here, create or update the mesh
                bool dependencySuccess = MeshHandler.DependencyCheck(managedMeshData, meshData.entityToken);
                if (dependencySuccess)
                {
                    ParseMeshData(meshData, managedMeshData);

                    // Delete the data
                    ImportMenu.stpUnityDeleteMeshData(meshDataPtr);
                }
                else
                {
                    // If we are not able to create or update store the mesh data and try later
                    meshDataStore.Add(meshDataPtr);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);

                // Delete the data
                ImportMenu.stpUnityDeleteMeshData(meshDataPtr);
            }
        }
        private static void PushMesh(GameObject obj)
        {
            // Get the mesh from object
            Mesh mesh = obj.GetComponent <MeshFilter>().sharedMesh;

            // Get the prefab and extract material data and get or generate a mesh token
            var prefab = PackageMapper.GetPrefabFromMesh(mesh);

            string uniqueToken;

            if (!prefab)
            {
                // Create unique mesh token
                uniqueToken = GenerateMeshToken(mesh);
            }
            else
            {
                // Grab existing token or generate a new one
                uniqueToken = GetTokenFromStorage(prefab);
                if (System.String.IsNullOrEmpty(uniqueToken))
                {
                    uniqueToken = GenerateMeshToken(mesh);
                }
            }

            // Gather material unique tokens
            List <string> materialTokens = new List <string>();
            var           meshRenderer   = obj.GetComponent <MeshRenderer>();

            if (meshRenderer)
            {
                for (var i = 0; i < meshRenderer.sharedMaterials.Length; i++)
                {
                    var materialPrefab = PackageMapper.GetPrefabFromMaterial(meshRenderer.sharedMaterials[i]);

                    var tokenStore = materialPrefab.GetComponent <FoundryUniqueToken>();
                    if (tokenStore && !System.String.IsNullOrEmpty(tokenStore.uniqueToken))
                    {
                        materialTokens.Add(tokenStore.uniqueToken);
                    }
                    else
                    {
                        materialTokens.Add("");
                    }
                }
            }

            // Send the mesh package to the server
            MeshHandler.CreateAndSendMeshRequest(mesh, materialTokens, uniqueToken);
        }
        // Iterate through mesh store that were missing dependants and check if we can create new mesh objects
        // or update existing mesh objects
        public static void IterateMeshStore()
        {
            for (int i = meshDataStore.Count - 1; i >= 0; i--)
            {
                MeshData meshData = (MeshData)System.Runtime.InteropServices.Marshal.PtrToStructure(meshDataStore[i], typeof(MeshData));

                // Convert unmanaged to managed memory
                ManagedMeshData managedMeshData = MeshHandler.ManageMeshMemory(meshData);

                // If all dependants are here, create or update the mesh
                if (MeshHandler.DependencyCheck(managedMeshData, meshData.entityToken))
                {
                    ParseMeshData(meshData, managedMeshData);

                    // Delete the data
                    ImportMenu.stpUnityDeleteMeshData(meshDataStore[i]);

                    // Remove from the store
                    meshDataStore.RemoveAt(i);
                }
            }
        }
        private static void ParseMeshData(MeshData meshData, ManagedMeshData managedMeshData)
        {
            // Check if the mesh already exists in the package mapper
            if (PackageMapper.TokenExistsInCache(meshData.entityToken))
            {
                // If mesh exists try to update it
                MeshHandler.UpdateMesh(meshData, managedMeshData);
            }
            else
            {
                // Create a new mesh object in Unity
                MeshHandler.CreateMesh(meshData, managedMeshData);

                // This loop starts over if we created a parent and a child is waiting in the store
                bool newItemCreated = true;
                while (newItemCreated)
                {
                    // Iterate through mesh instance store and try to create or update
                    // mesh instances that this mesh is a dependent of
                    IterateMeshInstanceStore(out newItemCreated);
                }
            }
        }