Exemplo n.º 1
0
        public override GameObject BuildScene(string name, bool saveToDisk = false)
        {
            try {
                properties = gameObject.AddComponent <ForgeProperties> ();
                //properties.PropertiesString = lmvtkDef [0].ToString();
                properties.Properties = lmvtkDef [0];

                JSONNode j = FindProperty(lmvtkDef [0], "name");
                if (j != null)
                {
                    name = GetDefaultValueIfUndefined(j, "value", "");
                    if (!string.IsNullOrEmpty(name))
                    {
                        gameObject.name = name;
                    }
                }
            } catch (Exception ex) {
                Debug.Log(ForgeLoader.GetCurrentMethod() + " " + ex.Message);
                state = SceneLoadingStatus.eError;
            }

            base.BuildScene(name, saveToDisk);
            return(gameObject);
        }
        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);
        }
Exemplo n.º 3
0
        public void LoadProperties(ForgeProperties props, Vector3 position, Vector3 normal)
        {
            JSONNode json = props.Properties;

            LoadProperties(json, position, normal);
        }