Beispiel #1
0
        protected void requestSceneObjectDetails(object sender, IRequestInterface args)
        {
            switch (args.resolved)
            {
            case SceneLoadingStatus.eMesh:
                if (_LoadMesh)
                {
                    requestMeshes(sender, args);
                }
                break;

            case SceneLoadingStatus.eMaterial:
                if (_LoadMesh)
                {
                    requestMaterials(sender, args);
                }
                break;

            case SceneLoadingStatus.eProperties:
                if (_LoadMetadata)
                {
                    requestProperties2(sender, args);
                }
                break;
            }
        }
Beispiel #2
0
        protected void requestProperties(object sender, IRequestInterface args)
        {
            PropertiesRequest reqObj = args as PropertiesRequest;

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/properties/" + reqObj.dbId.ToString());
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #3
0
        protected void requestTextures(object sender, IRequestInterface args)
        {
            // Textures are safe because they will be called only once per texture/material
            TextureRequest reqObj = args as TextureRequest;

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/texture/" + reqObj.texture.tex);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #4
0
        protected void requestMaterial(object sender, IRequestInterface args)
        {
            // Material can be shared
            MaterialRequest reqObj = args as MaterialRequest;

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/material/" + reqObj.matId + "/mat");
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #5
0
        protected void requestMesh(object sender, IRequestInterface args)
        {
            // Meshes are safe because they will be called only once
            MeshRequest reqObj = args as MeshRequest;

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/scenes/" + SCENEID + "/mesh/" + reqObj.fragId.Item1 + "/" + reqObj.fragId.Item2);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #6
0
        protected void requestProperties2(object sender, IRequestInterface args)
        {
            PropertiesRequest2 reqObj     = args as PropertiesRequest2;
            HashSet <int>      collectIds = new HashSet <int> ();

            foreach (Eppy.Tuple <int, GameObject> item in reqObj.dbIds)
            {
                collectIds.Add(item.Item1);
            }
            string propsIds = string.Join(",", collectIds);

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/properties/" + propsIds);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #7
0
        protected void requestMaterials(object sender, IRequestInterface args)            // Only works with the v2 server using the v1 API
        // Materials can be shared
        {
            MaterialsRequest reqObj     = args as MaterialsRequest;
            HashSet <int>    collectIds = new HashSet <int> ();

            foreach (int matId in reqObj.materialIds)
            {
                collectIds.Add(matId);
            }
            string matIds = string.Join(",", collectIds);

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/materials/" + matIds);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #8
0
        protected void requestMeshes(object sender, IRequestInterface args)            // Only works with the v2 server using the v1 API
        // Meshes are safe because they will be called only once
        {
            MeshesRequest reqObj     = args as MeshesRequest;
            HashSet <int> collectIds = new HashSet <int> ();

            foreach (Eppy.Tuple <int, int, OpenCTM.Mesh> item in reqObj._openctm)
            {
                collectIds.Add(item.Item1);
            }
            string dbIds = string.Join(",", collectIds);

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/meshes/" + dbIds);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
        public void AsyncRequestCompleted(object sender, AsyncCompletedEventArgs args)
        {
            if (args == null || args.UserState == null)
            {
                return;
            }
            IRequestInterface item = args.UserState as IRequestInterface;

            if (args.Error != null)
            {
                Debug.Log(ForgeLoader.GetCurrentMethod() + " " + args.Error.Message);
                item.state = SceneLoadingStatus.eError;
                return;
            }
            //item.state =item.resolved ;
            item.ProcessResponse(args);
        }
Beispiel #10
0
        protected void requestMesh2(object sender, IRequestInterface args)            // Only works with the v2 server using the v1 API
        // Meshes are safe because they will be called only once
        {
            MeshRequest2  reqObj     = args as MeshRequest2;
            HashSet <int> collectIds = new HashSet <int> ();

            foreach (Eppy.Tuple <int, int, GameObject, JSONNode> item in reqObj.fragments)
            {
                collectIds.Add(item.Item1);
            }
            if (collectIds.Count == 1)
            {
                collectIds.Add(-1);
            }
            string fragIds = string.Join(",", collectIds);

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/mesh/" + reqObj.dbId + "/" + fragIds);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
Beispiel #11
0
 protected void requestNothing(object sender, IRequestInterface args)
 {
 }
Beispiel #12
0
        public virtual void Update()
        {
            //UnityEngine.Profiling.Profiler.BeginSample ("Forge AR|VR Toolkit");
            if (!Active)
            {
                return;
            }
            // Do we got more requests to fire?
            int pending = _mgr.Count(SceneLoadingStatus.ePending);

            if (pending < ForgeLoaderConstants.NB_MAX_REQUESTS)
            {
                RequestQueueMgrEnumerator news = _mgr.GetTypeEnumerator(SceneLoadingStatus.eNew);
                pending = _mgr.Count(SceneLoadingStatus.eNew);
                if (news.MoveNext())
                {
                    //UnityEngine.Debug.Log (DateTime.Now.ToString ("HH:mm:ss.f") + " / " + ((IRequestInterface)news.Current).uri.ToString ());
                    _mgr.FireRequest(news.Current);
                }
            }

            // For each request we got an answer for, we build the corresponding scene object
            RequestQueueMgrEnumerator items = _mgr.GetCompletedEnumerator();

            while (items.MoveNext())
            {
                IRequestInterface item = items.Current;

                if (item.resolved == SceneLoadingStatus.eInstanceTree)
                {
                    item.fireRequestCallback += requestSceneObjectDetails;
                }
                else if (item.resolved == SceneLoadingStatus.eMaterial)
                {
                    item.fireRequestCallback += requestTextures;
                }

                GameObject obj = item.BuildScene(
                    item.resolved == SceneLoadingStatus.eInstanceTree ?
                    SCENEID : item.GetName(),
                    SaveToDisk
                    );
                if (obj != null && item.resolved == SceneLoadingStatus.eInstanceTree)
                {
                    if (ROOT == null)
                    {
                        ROOT = obj;
                    }
                    else
                    {
                        obj.transform.parent        = ROOT.transform;
                        obj.transform.localPosition = Vector3.zero;
                    }
                }
                else if (item.resolved == SceneLoadingStatus.eMaterial)                       // Safe as we make only 1 request per material
                {
                    _materialLib.Add((item as MaterialRequest).matId, (item as MaterialRequest).material);
                }
                else if (item.resolved == SceneLoadingStatus.eProperties)                       // Safe as we make only 1 request per propertyset
                {
                    _properties.Add((item as PropertiesRequest).dbId, (item as PropertiesRequest).properties);
                }                 // else if ( item.resolved == SceneLoadingStatus.eTexture )

                break;
            }

            // Assign Material to Mesh waiting for it
            items = _mgr.GetTypeEnumerator(SceneLoadingStatus.eWaitingMaterial);
            while (items.MoveNext())
            {
                MeshRequest item = items.Current as MeshRequest;
                if (!_materialLib.ContainsKey(item.materialId))
                {
                    continue;
                }
                MeshRenderer renderer = item.gameObject.GetComponent <MeshRenderer> ();
                renderer.sharedMaterial = _materialLib [item.materialId];
                item.state = item.resolved;
            }

            // Showing progress
            if (ProcessedNodes != null)
            {
                int total = _mgr.Count();
                int built = _mgr.Count(new SceneLoadingStatus [] {
                    SceneLoadingStatus.eInstanceTree, SceneLoadingStatus.eMesh, SceneLoadingStatus.eMaterial, SceneLoadingStatus.eTexture, SceneLoadingStatus.eProperties,
                    SceneLoadingStatus.eWaitingMaterial, SceneLoadingStatus.eWaitingTexture
                });
                int completed = _mgr.Count(SceneLoadingStatus.eReceived);

                float val = 100.0f * Math.Min(completed + built, total) / total;
                ProcessedNodes(this, val);

                if (ProcessingNodesCompleted != null)
                {
                    built = _mgr.Count(new SceneLoadingStatus [] {
                        SceneLoadingStatus.eInstanceTree, SceneLoadingStatus.eMesh, SceneLoadingStatus.eMaterial, SceneLoadingStatus.eTexture, SceneLoadingStatus.eProperties,
                    });
                    int unprocessed = _mgr.Count(new SceneLoadingStatus [] {
                        SceneLoadingStatus.eCancelled, SceneLoadingStatus.eError,
                    });

                    if (built + unprocessed == total)
                    {
                        ProcessingNodesCompleted(this, unprocessed);
                        TimeSpan tm = DateTime.Now - started;
                        UnityEngine.Debug.Log(URN + "-" + SCENEID + " loaded in: " + tm.TotalSeconds.ToString());
                        Sleep();                           // Sleep ourself
                    }
                }
            }

            //UnityEngine.Profiling.Profiler.EndSample ();
        }
 public void FireRequest(IRequestInterface item)
 {
     item.FireRequest(AsyncRequestCompleted);
 }
 public void Register(IRequestInterface item)
 {
     _queue.Add(item);
 }
 public void Add(IRequestInterface item)
 {
     _queue.Add(item);
     item.FireRequest(AsyncRequestCompleted);
 }