Beispiel #1
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 ());
            DownloadStringCompletedEventArgs args = e as DownloadStringCompletedEventArgs;
            string result = "";

            if (args == null)
            {
                DownloadDataCompletedEventArgs args2 = e as DownloadDataCompletedEventArgs;
                byte [] bytes = args2.Result;
                //WebHeaderCollection headerCollection = this.client.ResponseHeaders;
                //for ( int i = 0 ; i < headerCollection.Count ; i++ ) {
                //	if ( headerCollection.GetKey (i).ToLower () == "content-encoding" && headerCollection.Get (i).ToLower () == "gzip" ) {
                //		Debug.Log (headerCollection.GetKey (i));
                //	}
                //}
                byte [] b = RequestObjectInterface.Decompress(bytes);
                result = Encoding.UTF8.GetString(b);
            }
            else
            {
                result = args.Result;
            }
            try {
                lmvtkDef = JSON.Parse(result);
                state    = SceneLoadingStatus.eReceived;
            } catch (Exception ex) {
                Debug.Log(ForgeLoader.GetCurrentMethod() + " " + ex.Message);
                state = SceneLoadingStatus.eError;
            } finally {
            }
        }
Beispiel #2
0
        //public override void FireRequest () ;

        //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);
                }

                int      nbCoords = getInt(bytes, 0);
                int      index    = sizeof(Int32);
                float [] coords   = getFloats(bytes, nbCoords, sizeof(int));
                index    += nbCoords * sizeof(float);
                _vertices = new Vector3 [nbCoords / 3];
                for (int i = 0, ii = 0; i < nbCoords; i += 3, ii++)
                {
                    _vertices [ii] = new Vector3(coords [i], coords [i + 1], coords [i + 2]);
                }

                int nbTriangles = getInt(bytes, index);
                index     += sizeof(Int32);
                _triangles = getInts(bytes, nbTriangles, index);
                index     += nbTriangles * sizeof(Int32);

                int nbUVs = getInt(bytes, index);
                index += sizeof(Int32);
                float [] uv_a = nbUVs != 0 ? getFloats(bytes, nbUVs, index) : null;
                _uvs = nbUVs != 0 ? new Vector2 [nbUVs / 2] : null;
                for (int i = 0, ii = 0; i < nbUVs; i += 2, ii++)
                {
                    _uvs [ii] = new Vector2(uv_a [i], uv_a [i + 1]);
                }

                state = SceneLoadingStatus.eReceived;
            } catch (Exception ex) {
                Debug.Log(ForgeLoader.GetCurrentMethod() + " " + ex.Message);
                state = SceneLoadingStatus.eError;
            } finally {
            }
        }
        //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 {
            }
        }