public DdtFile(System.IO.Stream fileStream) { using (BrgBinaryReader reader = new BrgBinaryReader(new LittleEndianBitConverter(), fileStream)) { reader.ReadInt32(); type = (DdtType)reader.ReadByte(); alphaBits = reader.ReadByte(); texelFormat = (DdtTexelFormat)reader.ReadByte(); mipMap = reader.ReadByte(); Height = reader.ReadInt32(); Width = reader.ReadInt32(); int length = 0; for (int i = 0; i < mipMap; i++) { reader.ReadInt32(); length += reader.ReadInt32(); } imageData = reader.ReadBytes(length); } }
public BrgMaterial(BrgBinaryReader reader) { magic = reader.ReadInt32(); if (magic != EndianBitConverter.Little.ToInt32(Encoding.UTF8.GetBytes("MTRL"), 0)) { throw new Exception("Incorrect material header!"); } id = reader.ReadInt32(); flags = (BrgMatFlag)reader.ReadInt32(); unknown01b = reader.ReadInt32(); nameLength = reader.ReadInt32(); reader.ReadVector3(out color); reader.ReadVector3(out specular); reader.ReadVector3(out reflection); reader.ReadVector3(out ambient); name = reader.ReadString(nameLength); alpha = reader.ReadSingle(); if (flags.HasFlag(BrgMatFlag.SOLIDCOLOR)) { unknown05 = reader.ReadSingle(); } if (flags.HasFlag(BrgMatFlag.SFX)) { byte numSFX = reader.ReadByte(); sfx = new List <BrgMatSFX>(numSFX); for (int i = 0; i < numSFX; i++) { sfx.Add(reader.ReadMaterialSFX()); } } else { sfx = new List <BrgMatSFX>(); } }
public BrgMesh(BrgBinaryReader reader) { magic = reader.ReadInt32(); if (magic != EndianBitConverter.Little.ToInt32(Encoding.UTF8.GetBytes("MESI"), 0)) { throw new Exception("Improper mesh header!"); } meshFormat = reader.ReadInt16(); unknown01b = reader.ReadInt16(); numVertices = reader.ReadInt16(); numFaces = reader.ReadInt16(); unknown02 = reader.ReadInt32(); unknown03 = new float[9]; for (int i = 0; i < 9; i++) { unknown03[i] = reader.ReadSingle(); } unknown04 = new byte[6]; unknown04 = reader.ReadBytes(6); flags = (BrgMeshFlag)reader.ReadInt16(); unknown07 = new float[3]; for (int i = 0; i < 3; i++) { unknown07[i] = reader.ReadSingle(); } meshX = reader.ReadSingle(); meshY = reader.ReadSingle(); meshZ = reader.ReadSingle(); vertices = new Vector3 <float> [numVertices]; for (int i = 0; i < numVertices; i++) { reader.ReadVector3(out vertices[i], true, true); } normals = new Vector3 <float> [numVertices]; for (int i = 0; i < numVertices; i++) { reader.ReadVector3(out normals[i], true, true); } if (!flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH) || flags.HasFlag(BrgMeshFlag.MOVINGTEX)) { if (flags.HasFlag(BrgMeshFlag.TEXTURE)) { texVertices = new Vector2 <float> [numVertices]; for (int i = 0; i < numVertices; i++) { reader.ReadVector2(out texVertices[i], true); } } } if (!flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH)) { if (flags.HasFlag(BrgMeshFlag.MATERIALS)) { faceMaterials = new Int16[numFaces]; for (int i = 0; i < numFaces; i++) { faceMaterials[i] = reader.ReadInt16(); } } faceVertices = new Vector3 <Int16> [numFaces]; for (int i = 0; i < numFaces; i++) { reader.ReadVector3(out faceVertices[i]); } if (flags.HasFlag(BrgMeshFlag.MATERIALS)) { vertMaterials = new Int16[numVertices]; for (int i = 0; i < numVertices; i++) { vertMaterials[i] = reader.ReadInt16(); } } } unknown09 = new float[12]; for (int i = 0; i < 12; i++) { unknown09[i] = reader.ReadHalf(); } checkSpace = reader.ReadInt16(); unknown09e = reader.ReadInt16(); if (checkSpace == 0) { unknown09b = reader.ReadSingle(); lenSpace = reader.ReadInt32(); //09c unknown09d = reader.ReadInt32(); } // Implement this later //if (unknown05 == 97 || unknown06 == 200 || unknown06 == 204 || unknown06 == 72 || (unknown06 == 76 && unknown05 != 98)) { // byte unknown0a[4 * numVertices]; //} if (flags.HasFlag(BrgMeshFlag.ATTACHPOINTS)) { numMatrix = reader.ReadInt16(); numIndex = reader.ReadInt16(); unknown10 = reader.ReadInt16(); BrgAttachpoint[] attpts = new BrgAttachpoint[numMatrix]; for (int i = 0; i < numMatrix; i++) { attpts[i] = new BrgAttachpoint(); } for (int i = 0; i < numMatrix; i++) { reader.ReadVector3(out attpts[i].x, true, true); } for (int i = 0; i < numMatrix; i++) { reader.ReadVector3(out attpts[i].y, true, true); } for (int i = 0; i < numMatrix; i++) { reader.ReadVector3(out attpts[i].z, true, true); } for (int i = 0; i < numMatrix; i++) { reader.ReadVector3(out attpts[i].position, true, true); } for (int i = 0; i < numMatrix; i++) { reader.ReadVector3(out attpts[i].unknown11a, true, true); } for (int i = 0; i < numMatrix; i++) { reader.ReadVector3(out attpts[i].unknown11b, true, true); } List <int> nameId = new List <int>(); for (int i = 0; i < numIndex; i++) { int duplicate = reader.ReadInt32(); // have yet to find a model with duplicates reader.ReadInt32(); // Skip the id (at least I think its an ID) for (int j = 0; j < duplicate; j++) { nameId.Add(i); } } attachpoints = new List <BrgAttachpoint>(nameId.Count); for (int i = 0; i < nameId.Count; i++) { attachpoints.Add(new BrgAttachpoint(attpts[reader.ReadByte()])); attachpoints[i].NameId = nameId[i]; } if (checkSpace == 0 && lenSpace > 0) { unknown14 = new float[lenSpace]; for (int i = 0; i < lenSpace; i++) { unknown14[i] = reader.ReadSingle(); } } } }