//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 { } }
//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 { } }
// Define recursive function to traverse object hierarchy. Each object is shifted away // from the bbox center of its parent. // number nodeId: dbId of the current instanceTree node // int depth: tracks hierarchy level (0 for root) // vec3 (cx,cy,cz): center of the parent object (after applying the displacement to the parent object) // vec3 (ox,oy,oz): accumuled displacement from all parents on the path to root protected void explodeRec(float scale, GameObject nodeId, int depth, Vector3 parentCenter, Vector3 accumulatedDisplacement) { var oscale = scale * 2; // TODO: also possibly related to depth if (depth == _explodeDepth) { oscale *= _currentSegmentFraction; // smooth transition of this tree depth from non-exploded to exploded state } // get bbox center of this node Bounds tmpBox = GameObjectBounds(nodeId); Vector3 mycx = tmpBox.center; // The root node (depth==0) has no parent to shift away from. // For child nodes with level > explodDepth, we don't apply additional displacement anymore - just pass the displacement of the parents. if (depth > 0 && depth <= _explodeDepth) { // add displacement to move this object away from its parent's bbox center (cx, cy, cz) Vector3 dx = (mycx - parentCenter) * oscale; dx.z = (mycx.z - parentCenter.z) * oscale; //var omax =Math.max (dx.x, Math.max (dx.y, dx.z)) ; // sum up offsets: The final displacement of a node is accumulated by its own shift and // the shifts of all nodes up to the root. accumulatedDisplacement += dx; } // continue recursion with child objects (if any) for (int i = 0; i < nodeId.transform.childCount; i++) { GameObject dbId = nodeId.transform.GetChild(i).gameObject; explodeRec(scale, dbId, depth + 1, mycx, accumulatedDisplacement); } Vector3 pt = accumulatedDisplacement; // set translation as anim transform for all fragments associated with the current node MeshFilter [] filters = nodeId.GetComponentsInChildren <MeshFilter> (); foreach (MeshFilter filter in filters) { int dbId = 0, fragId = 0; string pathid = ""; RequestObjectInterface.decodeName(filter.gameObject.name, ref dbId, ref fragId, ref pathid); updateAnimTransformPos(fragId, ref pt); } }
//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 { } }