Beispiel #1
0
        // Add a Physic Plane to the world
        public void AddPlane(PhysicWorldModel worldModel, OnPlaneModelChanged callback, object context, params FixedVector3[] paramPoints)
        {
            PhysicPlaneModel planeModel = new PhysicPlaneModel(paramPoints);

            addPlaneCallbacks[planeModel] = new Eppy.Tuple <OnPlaneModelChanged, object>(callback, context);
            StateManager.state.AddModel(planeModel, OnPlaneAdded, worldModel);
        }
Beispiel #2
0
 public MeshRequest(IForgeLoaderInterface _loader, Uri _uri, string _bearer, Eppy.Tuple <int, int> _fragId, int _materialId, JSONNode node) : base(_loader, _uri, _bearer)
 {
     resolved    = SceneLoadingStatus.eMesh;
     fragId      = _fragId;
     materialId  = _materialId;
     lmvtkDef    = node;
     compression = true;
 }
Beispiel #3
0
 public void changeRoad(int index, Vector2 newOrigin, Vector2 newDestination, float newMaxSlope, float newBridgePenalty)
 {
     roadsDefinitionData [index] = new Eppy.Tuple<Vector2, Vector2, float, float> (newOrigin, newDestination, newMaxSlope, newBridgePenalty);
     roads [index].Clear ();
     ULE.setRoadStatus (index, UIElement.UIStatus.Loading);
     ChunkLoader.Instance.ReloadAllChunks ();
     RecalculateRoads (index);
 }
Beispiel #4
0
        //public override void CancelRequest () ;

        public override void ProcessResponse(AsyncCompletedEventArgs e)
        {
            //TimeSpan tm = DateTime.Now - emitted;
            //UnityEngine.Debug.Log ("Received: " + tm.TotalSeconds.ToString () + " / " + uri.ToString ());
            DownloadDataCompletedEventArgs args = e as DownloadDataCompletedEventArgs;

            try {
                byte [] bytes = args.Result;
                if (compression)
                {
                    bytes = RequestObjectInterface.Decompress(bytes);
                }

                List <Eppy.Tuple <int, int, OpenCTM.Mesh> > tmp = new List <Eppy.Tuple <int, int, OpenCTM.Mesh> > ();
                int len = BitConverter.ToInt32(bytes, 0);
                for (int i = 0; i < len; i++)
                {
                    int dbId   = BitConverter.ToInt32(bytes, ((i * 3) + 1) * sizeof(Int32));
                    int fragId = BitConverter.ToInt32(bytes, ((i * 3) + 2) * sizeof(Int32));
                    int offset = BitConverter.ToInt32(bytes, ((i * 3) + 3) * sizeof(Int32));
                    int end    = bytes.Length;
                    if (i < len - 1)
                    {
                        end = BitConverter.ToInt32(bytes, (((i + 1) * 3) + 3) * sizeof(Int32));
                    }

                    byte [] ctm = RequestObjectInterface.Decompress(bytes.Skip(offset).Take(end - offset).ToArray());

                    System.IO.Stream      readMemory = new System.IO.MemoryStream(ctm);                // (bytes, offset, end - offset);
                    OpenCTM.CtmFileReader reader     = new OpenCTM.CtmFileReader(readMemory);
                    //_openctm.Add (new Eppy.Tuple<int, int, OpenCTM.Mesh> (dbId, fragId, reader.decode ()));
                    Eppy.Tuple <int, int, OpenCTM.Mesh> mesh = _openctm.Single(x => x.Item1 == dbId && x.Item2 == fragId);
                    tmp.Add(new Eppy.Tuple <int, int, OpenCTM.Mesh> (mesh.Item1, mesh.Item2, reader.decode()));
                }
                _openctm.Clear();
                _openctm = tmp;

                state = SceneLoadingStatus.eReceived;
            } catch (Exception ex) {
                Debug.Log(ForgeLoader.GetCurrentMethod() + " " + ex.Message);
                state = SceneLoadingStatus.eError;
            } finally {
            }
        }
Beispiel #5
0
        public override GameObject BuildScene(string name, bool saveToDisk = false)
        {
            try {
                foreach (Eppy.Tuple <int, OpenCTM.Mesh> openctm in _openctm)
                {
                    OpenCTM.Mesh ctmMesh = openctm.Item2;
                    if (ctmMesh == null || ctmMesh.getVertexCount() == 0 || ctmMesh.getTriangleCount() == 0)
                    {
                        state = SceneLoadingStatus.eCancelled;
                        return(gameObject);
                    }

                    Eppy.Tuple <int, int, GameObject, JSONNode> item = fragments.Single(x => x.Item1 == openctm.Item1);
                    GameObject meshObject = item.Item3;

                    Mesh       mesh     = new Mesh();
                    Vector3 [] vertices = MeshRequest2.getAsVector3(ctmMesh.vertices);
                    mesh.vertices  = vertices;
                    mesh.triangles = ctmMesh.indices;
                    if (ctmMesh.hasNormals())
                    {
                        mesh.normals = MeshRequest2.getAsVector3(ctmMesh.normals);
                    }
                    for (int i = 0; i < ctmMesh.getUVCount(); i++)
                    {
                        mesh.SetUVs(i, MeshRequest2.getAsVector2List(ctmMesh.texcoordinates [i].values));
                    }

                    mesh.RecalculateNormals();
                    mesh.RecalculateBounds();

                    MeshFilter filter = meshObject.AddComponent <MeshFilter> ();
                    filter.sharedMesh = mesh;
                    MeshRenderer renderer = meshObject.AddComponent <MeshRenderer> ();
                    renderer.sharedMaterial = ForgeLoaderEngine.GetDefaultMaterial();
                    if (createCollider)
                    {
                        MeshCollider collider = meshObject.AddComponent <MeshCollider> ();
                        collider.sharedMesh = mesh;
                    }
#if UNITY_EDITOR
                    if (saveToDisk)
                    {
                        AssetDatabase.CreateAsset(mesh, ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + GetName(item.Item1) + ".asset");
                        //AssetDatabase.SaveAssets () ;
                        //AssetDatabase.Refresh () ;
                        //mesh =AssetDatabase.LoadAssetAtPath<Mesh> (ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + name + ".asset") ;
                    }
#endif

                    // Add our material to the queue
                    loader.GetMgr()._materials.Add(item.Item2);
                    //if ( loader.GetMgr ()._materials.Add (item.Item2) ) {
                    //	MaterialRequest req = new MaterialRequest (loader, null, bearer, item.Item2, item.Item4);
                    //	req.gameObject = meshObject;
                    //	if ( fireRequestCallback != null )
                    //		fireRequestCallback (this, req);
                    //}
                }
                base.BuildScene(name, saveToDisk);
                state = SceneLoadingStatus.eWaitingMaterial;
            } catch (Exception ex) {
                Debug.Log(ForgeLoader.GetCurrentMethod() + " " + ex.Message);
                state = SceneLoadingStatus.eError;
            }
            return(gameObject);
        }
Beispiel #6
0
 // Remove a Physic Plane from the world
 public void RemovePlane(PhysicWorldModel worldModel, PhysicPlaneModel planeModel, OnPlaneModelChanged callback = null, object context = null)
 {
     removePlaneCallbacks[planeModel] = new Eppy.Tuple <OnPlaneModelChanged, object>(callback, context);
     StateManager.state.RemoveModel(planeModel, OnPlaneRemoved, worldModel);
 }
Beispiel #7
0
 // Remove a Physic Point from the world
 public void RemovePoint(PhysicWorldModel world, PhysicPointModel pointModel, OnPointModelChanged callback = null, object context = null)
 {
     removePointCallbacks[pointModel] = new Eppy.Tuple <OnPointModelChanged, object>(callback, context);
     StateManager.state.RemoveModel(pointModel, OnPointRemoved, world);
 }
Beispiel #8
0
 // Add a Physic Point to the world
 public ModelReference AddPoint(PhysicWorldModel world, PhysicPointModel pointModel, OnPointModelChanged callback = null, object context = null)
 {
     addPointCallbacks[pointModel] = new Eppy.Tuple <OnPointModelChanged, object>(callback, context);
     return(StateManager.state.AddModel(pointModel, OnPointAdded, world));
 }