private static void ParseMeshInstanceData(MeshInstanceData meshInstData, out bool newItemCreated)
        {
            newItemCreated = false;
            // Check if the object already exists in the package mapper
            if (PackageMapper.TokenExistsInCache(meshInstData.entityToken))
            {
                // If object exists try to update it
                MeshInstanceHandler.UpdateMeshInstance(meshInstData);
            }
            else
            {
                // Create a new GameObject in the hierarchy
                GameObject meshInst = MeshInstanceHandler.CreateMeshInstance(meshInstData);

                if (meshInst)
                {
                    PackageMapper.MapTokenToObject(meshInstData.entityToken, meshInst);
                    newItemCreated = true;
                }
            }
        }
        private static void PushMeshInstance(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);

            // Get or generate unique mesh token
            string meshToken;

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

            // Grab existing instance token or generate a new one
            string instanceToken = GetTokenFromStorage(obj);

            if (System.String.IsNullOrEmpty(instanceToken))
            {
                // Create unique instance token
                instanceToken = GenerateMeshInstanceToken(obj);
            }

            // Send the mesh instance package to the server
            MeshInstanceHandler.CreateAndSendMeshInstanceRequest(obj, instanceToken, meshToken, "");
        }
        /// <summary>
        ///
        /// Mesh Instances
        ///
        /// Parse mesh instance data
        /// Function decides if we are updating an already existing mesh instance ( GameObject ) or creating a new one.
        /// </summary>
        public static void ParseMeshInstanceData(System.IntPtr meshInstanceDataPtr)
        {
            try
            {
                var meshInstanceData = (MeshInstanceData)System.Runtime.InteropServices.Marshal.PtrToStructure(meshInstanceDataPtr, typeof(MeshInstanceData));

                // If all dependants are here, create or update the mesh instance
                if (MeshInstanceHandler.DependencyCheck(meshInstanceData))
                {
                    bool newItemCreated;
                    ParseMeshInstanceData(meshInstanceData, out newItemCreated);

                    // Delete the data
                    ImportMenu.stpUnityDeleteMeshInstanceData(meshInstanceDataPtr);

                    // This loop starts over if we created a parent and a child is waiting in the store
                    while (newItemCreated)
                    {
                        // Iterate through mesh instance store and try to create or update
                        // mesh instances that this mesh instance is a dependent of
                        IterateMeshInstanceStore(out newItemCreated);
                    }
                }
                else
                {
                    // If we are not able to create or update store the mesh data and try later
                    meshInstanceDataStore.Add(meshInstanceDataPtr);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);

                // Delete the data
                ImportMenu.stpUnityDeleteMeshInstanceData(meshInstanceDataPtr);
            }
        }
        // Iterate through mesh instance store that were missing dependants
        // and check if we can create new mesh instance objects or update existing mesh objects
        public static void IterateMeshInstanceStore(out bool newItemCreated)
        {
            newItemCreated = false;
            for (int i = meshInstanceDataStore.Count - 1; i >= 0; i--)
            {
                MeshInstanceData meshInstanceData = (MeshInstanceData)System.Runtime.InteropServices.Marshal.PtrToStructure(meshInstanceDataStore[i], typeof(MeshInstanceData));
                // If all dependants are here, create or update the mesh
                bool currentItemCreated = false;
                bool dependencySuccess  = MeshInstanceHandler.DependencyCheck(meshInstanceData);
                if (dependencySuccess)
                {
                    ParseMeshInstanceData(meshInstanceData, out currentItemCreated);

                    // Delete the data
                    ImportMenu.stpUnityDeleteMeshInstanceData(meshInstanceDataStore[i]);

                    // Remove from the store
                    meshInstanceDataStore.RemoveAt(i);
                }

                // True if at least one item was created
                newItemCreated = newItemCreated || currentItemCreated;
            }
        }