public SCBFile(string Location) { using (BinaryReader br = new BinaryReader(File.OpenRead(Location))) { string Magic = Encoding.ASCII.GetString(br.ReadBytes(8)); if (Magic != "r3d2Mesh") { throw new InvalidFileMagicException(); } UInt16 Major = br.ReadUInt16(); UInt16 Minor = br.ReadUInt16(); if (Major != 3 && Major != 2 && Minor != 1) //There are versions [2][1] and [1][1] aswell { throw new UnsupportedFileVersionException(); } this.Name = Encoding.ASCII.GetString(br.ReadBytes(128)).Replace("\0", ""); UInt32 VertexCount = br.ReadUInt32(); UInt32 FaceCount = br.ReadUInt32(); SCBFlags Flags = (SCBFlags)br.ReadUInt32(); this.BoundingBox = new R3DBoundingBox(br); bool HasTangents = false; if (Major == 3 && Minor == 2) { HasTangents = br.ReadUInt32() == 1; } for (int i = 0; i < VertexCount; i++) { this.Vertices.Add(new Vector3(br)); } if (Major == 3 && Minor == 2 && Flags.HasFlag(SCBFlags.Tangents) && HasTangents) { for (int i = 0; i < VertexCount; i++) { this.Tangents.Add(new Vector4Byte(br)); } } this.CentralPoint = new Vector3(br); for (int i = 0; i < FaceCount; i++) { this.Faces.Add(new SCBFace(br)); } if (Flags.HasFlag(SCBFlags.VertexColors)) { this.VertexColors.Add(new Vector3Byte(br)); } } }
public SCBFile(Stream stream) { using (BinaryReader br = new BinaryReader(stream)) { string magic = Encoding.ASCII.GetString(br.ReadBytes(8)); if (magic != "r3d2Mesh") { throw new Exception("This is not a valid SCB file"); } ushort major = br.ReadUInt16(); ushort minor = br.ReadUInt16(); if (major != 3 && major != 2 && minor != 1) { throw new Exception(string.Format("The Version: {0}.{1} is not supported", major, minor)); } string Name = Encoding.ASCII.GetString(br.ReadBytes(128)).Replace("\0", ""); uint vertexCount = br.ReadUInt32(); uint faceCount = br.ReadUInt32(); SCBFlags flags = (SCBFlags)br.ReadUInt32(); Vector3 Org = new Vector3(br); Vector3 Size = new Vector3(br); bool hasTangents = false; if (major == 3 && minor == 2) { hasTangents = br.ReadUInt32() == 1; } for (int i = 0; i < vertexCount; i++) { Vertices.Add(new Vector3(br)); } if (major == 3 && minor == 2 && flags.HasFlag(SCBFlags.TANGENTS) && hasTangents) { for (int i = 0; i < vertexCount; i++) { byte o = br.ReadByte(); byte k = br.ReadByte(); byte m = br.ReadByte(); byte n = br.ReadByte(); } } float u = br.ReadSingle(); float j = br.ReadSingle(); float b = br.ReadSingle(); for (int i = 0; i < faceCount; i++) { SCBFace face = new SCBFace(br); if (!Materials.ContainsKey(face.Material)) { Materials.Add(face.Material, new List <SCBFace>()); } Materials[face.Material].Add(face); } } }
public SCBFile(Stream stream) { using (BinaryReader br = new BinaryReader(stream)) { string magic = Encoding.ASCII.GetString(br.ReadBytes(8)); if (magic != "r3d2Mesh") { throw new Exception("This is not a valid SCB file"); } ushort major = br.ReadUInt16(); ushort minor = br.ReadUInt16(); if (major != 3 && major != 2 && minor != 1) //There are versions [2][1] and [1][1] aswell { throw new Exception(string.Format("The Version: {0}.{1} is not supported", major, minor)); } this.Name = Encoding.ASCII.GetString(br.ReadBytes(128)).Replace("\0", ""); uint vertexCount = br.ReadUInt32(); uint faceCount = br.ReadUInt32(); SCBFlags flags = (SCBFlags)br.ReadUInt32(); this.BoundingBox = new R3DBoundingBox(br); bool hasTangents = false; if (major == 3 && minor == 2) { hasTangents = br.ReadUInt32() == 1; } for (int i = 0; i < vertexCount; i++) { this.Vertices.Add(new Vector3(br)); } if (major == 3 && minor == 2 && flags.HasFlag(SCBFlags.TANGENTS) && hasTangents) { for (int i = 0; i < vertexCount; i++) { this.Tangents.Add(new Vector4Byte(br)); } } this.CentralPoint = new Vector3(br); for (int i = 0; i < faceCount; i++) { SCBFace face = new SCBFace(br); if (!this.Materials.ContainsKey(face.Material)) { this.Materials.Add(face.Material, new List <SCBFace>()); } this.Materials[face.Material].Add(face); } if (flags.HasFlag(SCBFlags.VERTEX_COLORS)) { this.VertexColors.Add(new Vector3Byte(br)); } } }