public SerializedBundle(TerraMesh _tm) { Version = CUR_VERSION; //Vector3 -- 12 bytes Vertices = _tm.Vertices; //TODO Broken //int - 4 bytes Triangles = _tm.Triangles; //int - 4 bytes HullSites = _tm.HullSites; //3 ints - 12 bytes SiteCorners = _tm.SiteCorners; //3 ints - 12 bytes SiteNeighbors = _tm.SiteNeighbors; //Vector3 -- 12 bytes //SitePositions = _tm.SitePositions; //TODO BROKEN //Variable -- need to track length for each set SitesHavingCorner = _tm.SitesHavingCorner; var totalSetCount = 0; for (var cornerIdx = 0; cornerIdx < SitesHavingCorner.Length; ++cornerIdx) { totalSetCount += _tm.SitesHavingCorner[cornerIdx].Count; } var dataLen = sizeof(int); //Total size header dataLen += sizeof(int); // Version dataLen += sizeof(int); // Vertex count header dataLen += Vertices.Length * sizeof(float) * 2; // Vector2 dataLen += sizeof(int); // Triangle count header dataLen += Triangles.Length * sizeof(int); //int dataLen += sizeof(int); // HullSites count header dataLen += HullSites.Length * sizeof(int); //int dataLen += sizeof(int); // SiteCorners count header dataLen += SiteCorners.Length * sizeof(int) * 3; //int * 3 dataLen += sizeof(int); // SiteNeighbors count header dataLen += SiteNeighbors.Length * sizeof(int) * 3; // int * 3 dataLen += sizeof(int); // SitePositions count header dataLen += SitePositions.Length * sizeof(float) * 3; // Vector3 dataLen += sizeof(int); // Site having corner set count dataLen += SitesHavingCorner.Length * sizeof(int); //Site Having corner count headers dataLen += totalSetCount * sizeof(int); //Sites having corner set indexes SerializedData = new byte[dataLen]; BufIdx = 0; byte32 = new Byte32(); bytesVec2 = new ByteVector2(); bytesVec3 = new ByteVector3(); byte32.Write(SerializedData, ref BufIdx, dataLen); byte32.Write(SerializedData, ref BufIdx, Version); SerializeVertices(ref BufIdx, SerializedData); SerializeTris(ref BufIdx, SerializedData); SerializeHullSites(ref BufIdx, SerializedData); SerializeSiteCorners(ref BufIdx, SerializedData); SerializeSiteNeighbors(ref BufIdx, SerializedData); SerializeSitePositions(ref BufIdx, SerializedData); SerializeSitesHavingCorner(ref BufIdx, SerializedData); }
public void Write(byte[] _buffer, ref int _curIdx) { xData.Write(_buffer, ref _curIdx, x); yData.Write(_buffer, ref _curIdx, y); }