Пример #1
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);
        }
        protected void IteratorNodes(JSONNode node, GameObject go)
        {
            GameObject obj = null;

            switch (node ["type"].Value)
            {
            case "Transform":
                int    dbId0    = node ["id"].AsInt;
                string nodeName = buildName("transform", dbId0, 0, node ["pathid"]);
                obj = new GameObject(nodeName);
                setTransform(node, obj);
                obj.transform.parent = go.transform;

                // But requesting properties here does not really make sense and is slowing down the streaming.
                // Instead, we could get properties on demand or at the end.

                if (_properties.Add(dbId0))
                {
                    PropertiesRequest req = new PropertiesRequest(loader, null, bearer, dbId0);
                    req.gameObject = obj;
                    if (fireRequestCallback != null)
                    {
                        fireRequestCallback(this, req);
                    }
                }

                break;

            case "Mesh":
                int dbId = node ["id"].AsInt;
                for (int i = 0; i < node ["fragments"].AsArray.Count; i++)
                {
                    int fragId = node ["fragments"] [i].AsInt;
                    int matId  = node ["materials"] [i].AsInt;
                    obj = CreateMeshObject(dbId, fragId, node ["pathid"]);
                    setTransform(node, obj);
                    obj.transform.parent = go.transform;

                    int polys = node ["fragPolys"] [i].AsInt;
                    if (polys > 0)
                    {
                        // Create a new request to get the Mesh definition
                        if (_fragments.Add(new Eppy.Tuple <int, int> (dbId, fragId)))
                        {
                            MeshRequest req = new MeshRequest(loader, null, bearer, new Eppy.Tuple <int, int> (dbId, fragId), matId, node);
                            req.gameObject = obj;
                            if (fireRequestCallback != null)
                            {
                                fireRequestCallback(this, req);
                            }
                        }

                        // Create a new request to get the Material definition
                        if (_materials.Add(matId))
                        {
                            MaterialRequest req = new MaterialRequest(loader, null, bearer, node ["materials"] [i].AsInt, node);
                            req.gameObject = obj;
                            if (fireRequestCallback != null)
                            {
                                fireRequestCallback(this, req);
                            }
                        }
                    }

                    // Create a new request to get the properties (but only once), and store it on the parent transform
                }

                // But requesting properties here does not really make sense and is slowing down the streaming.
                // Instead, we could get properties on demand or at the end.

                //if ( _properties.Add (dbId) ) {
                //	PropertiesRequest req = new PropertiesRequest (loader, null, bearer, dbId);
                //	req.gameObject = obj.transform.parent.gameObject;
                //	if ( fireRequestCallback != null )
                //		fireRequestCallback (this, req);
                //}

                break;

            default:
                break;
            }
            if (obj != null && node ["childs"] != null)
            {
                try {
                    foreach (JSONNode child in node["childs"].AsArray)
                    {
                        IteratorNodes(child, obj);
                    }
                } catch (System.Exception /*ex*/) {
                }
            }
        }