public void Set(List <byte> _rawdata) { /* * DO KEEP IN MIND THAT THE COUNTERS HERE REFER TO BYTES. */ /*Using BitConverter would be a bit longer, but maybe clearer? * I think that once understood the principle, this is better. * This would be the same thing with BitConverter: * * */ //Size = BitConverter.ToUInt32(_rawdata.GetRange(0, 4).ToArray(), 0); Size = ((Data4Bytes)(_rawdata.GetRange(0, 4))).ui; ID = ((Data4Bytes)(_rawdata.GetRange(4, 4))).ui; VertexCount = ((Data4Bytes)(_rawdata.GetRange(8, 4))).ui; uint currentPositionInData = 12; //should allow for vertex size that is more than 32 bytes. uint i = VertexCount; while (i-- > 0) { uint tempsize = ((Data4Bytes)(_rawdata.GetRange((int)currentPositionInData, 4))).ui; TPVertex temp; /* We get a number of bytes that is the size + 4, because we also supply the size to the vertex object. */ temp = new TPVertex(_rawdata.GetRange((int)currentPositionInData, (int)(tempsize + 4))); Vertices.Add(temp); if (temp.PeekLog() != "") { log.AppendLine("Vertex " + i + ": " + temp.DumpLog()); } currentPositionInData += tempsize + 4; } log.AppendLine("Added " + VertexCount + " vertices"); FaceCount = ((Data4Bytes)(_rawdata.GetRange((int)currentPositionInData, 4))).ui; currentPositionInData += 4; i = FaceCount; while (i-- > 0) { uint tempsize = ((Data4Bytes)(_rawdata.GetRange((int)currentPositionInData, 4))).ui; TPFace temp; //adds face data to temp face, remembering that we are dealing with 4-byte data and the size counter counts single bytes temp = new TPFace(_rawdata.GetRange((int)currentPositionInData, (int)(tempsize + 4))); Faces.Add(temp); if (temp.PeekLog() != "") { log.AppendLine("Face " + i + ": " + temp.DumpLog()); } currentPositionInData += tempsize + 4; } log.AppendLine("Added " + FaceCount + " face(s)."); AnimationFrameCount = ((Data4Bytes)(_rawdata.GetRange((int)currentPositionInData, 4))).ui; currentPositionInData += 4; i = AnimationFrameCount; while (i-- > 0) { uint tempsize = ((Data4Bytes)(_rawdata.GetRange((int)currentPositionInData, 4))).ui; TPAnimFrame temp; temp = new TPAnimFrame(_rawdata.GetRange((int)currentPositionInData, (int)(tempsize + 4))); AnimationFrames.Add(temp); if (temp.PeekLog() != null) { log.AppendLine("Face " + i + ": " + temp.DumpLog()); } currentPositionInData += tempsize + 4; } log.AppendLine("Added " + AnimationFrameCount + " animation frame(s)."); }
public void AddFrame(Rectangle rectangle) { AnimationFrames.Add(rectangle); CurrentRectangle = AnimationFrames[0]; }