Exemple #1
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);
        }
Exemple #2
0
        public override GameObject BuildScene(string name, bool saveToDisk = false)
        {
            Clear();
            GameObject pivot = null;

            try {
                gameObject = new GameObject(name);
                if (lmvtkDef == null)
                {
                    return(null);
                }
                ForgeProperties properties = gameObject.AddComponent <ForgeProperties> ();
                properties.Properties = lmvtkDef ["metadata"];

                foreach (JSONNode child in lmvtkDef["childs"].AsArray)
                {
                    IteratorNodes(child, gameObject);
                }
                base.BuildScene(name, saveToDisk);

                pivot = ForgeLoaderEngine.SetupForSceneOrientationAndUnits(gameObject, properties.Properties);

                // Create as much Meshes requests we need to load chunks of 0.5Mb-0.7Mb pack files
                // 1-499 polys = factor of 25
                // >500 poly = factor of 17
                int compSize = 0;
                List <Eppy.Tuple <int, int> > components = new List <Eppy.Tuple <int, int> > ();
                List <Eppy.Tuple <int, int, GameObject, JSONNode> > fragments = new List <Eppy.Tuple <int, int, GameObject, JSONNode> > ();
                foreach (KeyValuePair <int, InstanceTreeData> data in _components)
                {
                    //if ( data.Value.fragments.Count == 0 )
                    //continue;
                    foreach (Eppy.Tuple <int, int, GameObject, JSONNode> frag in data.Value.fragments)
                    {
                        JSONArray json  = frag.Item4 ["fragments"].AsArray;
                        JSONArray json2 = frag.Item4 ["fragPolys"].AsArray;
                        int       index = 0;
                        for ( ; index < json.Count && json [index].AsInt != frag.Item1; index++)
                        {
                        }
                        if (index >= json2.Count)
                        {
                            continue;
                        }
                        compSize += json2 [index].AsInt;
                        //Debug.Log (data.Key + "-" + frag.Item1 + " " + json2 [index].AsInt);
                        components.Add(new Eppy.Tuple <int, int> (data.Key, frag.Item1));
                        fragments.Add(frag);
                    }

                    if (compSize > 29411 /* 29411 * 17 = 500kb */)
                    {
                        MeshesRequest reqMeshes = new MeshesRequest(loader, null, bearer, components, fragments, null);
                        reqMeshes.gameObject = null;
                        if (fireRequestCallback != null)
                        {
                            fireRequestCallback(this, reqMeshes);
                        }
                        compSize   = 0;
                        components = new List <Eppy.Tuple <int, int> > ();
                        fragments  = new List <Eppy.Tuple <int, int, GameObject, JSONNode> > ();
                    }
                }
                if (components.Count > 0)
                {
                    MeshesRequest reqMeshes = new MeshesRequest(loader, null, bearer, components, fragments, null);
                    reqMeshes.gameObject = null;
                    if (fireRequestCallback != null)
                    {
                        fireRequestCallback(this, reqMeshes);
                    }
                }

                if (loader.GetMgr()._materials.Count > 0)
                {
                    MaterialsRequest reqMaterials = new MaterialsRequest(loader, null, bearer, loader.GetMgr()._materials, lmvtkDef);
                    reqMaterials.gameObject = null;
                    if (fireRequestCallback != null)
                    {
                        fireRequestCallback(this, reqMaterials);
                    }
                }                 // Textures will be requested by the material request (one by one)

                // Now Properties
                int []    dbIds  = _components.Keys.ToArray();
                int [] [] chunks = dbIds
                                   .Select((s, i) => new { Value = s, Index = i })
                                   .GroupBy(x => x.Index / 100)
                                   .Select(grp => grp.Select(x => x.Value).ToArray())
                                   .ToArray();
                for (int i = 0; i < chunks.Length; i++)
                {
                    List <Eppy.Tuple <int, GameObject> > dbIdsTuple = new List <Eppy.Tuple <int, GameObject> > ();
                    foreach (int dbId in chunks[i])
                    {
                        dbIdsTuple.Add(new Eppy.Tuple <int, GameObject> (dbId, _components [dbId].obj));
                    }
                    PropertiesRequest2 reqProps = new PropertiesRequest2(loader, null, bearer, dbIdsTuple);
                    reqProps.gameObject = null;
                    if (fireRequestCallback != null)
                    {
                        fireRequestCallback(this, reqProps);
                    }
                }

                Clear();
            } catch (Exception /*ex*/) {
                if (gameObject)
                {
                    GameObject.DestroyImmediate(gameObject);
                }
                gameObject = null;
                pivot      = null;
            }
            return(pivot);
        }