Пример #1
0
 public BrgAttachpoint(BrgBinaryReader reader)
 {
     NameId = -1;
     reader.ReadVector3(out x);
     reader.ReadVector3(out y);
     reader.ReadVector3(out z);
     reader.ReadVector3(out position);
 }
        public BrgFile(System.IO.Stream fileStream)
        {
            using (BrgBinaryReader reader = new BrgBinaryReader(new LittleEndianBitConverter(), fileStream))
            {
                reader.ReadHeader(ref Header);
                if (Header.magic != EndianBitConverter.Little.ToInt32(Encoding.UTF8.GetBytes("BANG"), 0))
                {
                    throw new Exception("This is not a BRG file!");
                }

                if (Header.numMeshes > 1)
                {
                    reader.ReadAsetHeader(ref AsetHeader);
                    if (AsetHeader.magic != EndianBitConverter.Little.ToInt32(Encoding.UTF8.GetBytes("ASET"), 0))
                    {
                        throw new Exception("Improper ASET header!");
                    }
                    if (Header.numMeshes != AsetHeader.numFrames)
                    {
                        throw new Exception("Number of meshes does not match number of frames!");
                    }
                }

                Mesh = new List <BrgMesh>(Header.numMeshes);
                for (int i = 0; i < Header.numMeshes; i++)
                {
                    Mesh.Add(new BrgMesh(reader));
                }

                Material = new List <BrgMaterial>();
                for (int i = 0; i < Header.numMaterials; i++)
                {
                    Material.Add(new BrgMaterial(reader));
                }

                if (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    throw new Exception("The end of stream was not reached!");
                }
            }
        }
        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 void ReadBr3(System.IO.Stream fileStream)
        {
            using (BrgBinaryReader reader = new BrgBinaryReader(new LittleEndianBitConverter(), fileStream))
            {
                reader.ReadInt32(); // BRG3

                Header.numMeshes    = reader.ReadInt32();
                Header.numMaterials = reader.ReadInt32();

                if (Header.numMeshes > 1)
                {
                    AsetHeader.numFrames = Header.numMeshes;
                    AsetHeader.frameStep = 1f / (float)AsetHeader.numFrames;
                    AsetHeader.animTime  = reader.ReadSingle();
                    AsetHeader.frequency = 1f / (float)AsetHeader.animTime;
                    AsetHeader.spf       = AsetHeader.animTime / (float)AsetHeader.numFrames;
                    AsetHeader.fps       = (float)AsetHeader.numFrames / AsetHeader.animTime;
                }

                Mesh = new List <BrgMesh>(Header.numMeshes);
                for (int i = 0; i < Header.numMaterials; i++)
                {
                    Mesh.Add(new BrgMesh());
                    Mesh[i].ReadBr3(reader);
                }

                Material = new List <BrgMaterial>();
                for (int i = 0; i < Header.numMaterials; i++)
                {
                    Material.Add(new BrgMaterial());
                    Material[i].ReadBr3(reader);
                }

                if (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    throw new Exception("The end of stream was not reached!");
                }
            }
        }
Пример #5
0
        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 void ReadBr3(BrgBinaryReader reader)
 {
     id    = reader.ReadInt32();
     flags = (BrgMatFlag)reader.ReadInt32();
 }
        public void ReadBr3(BrgBinaryReader reader)
        {
            numVertices = reader.ReadInt16();
            numFaces    = reader.ReadInt16();
            flags       = (BrgMeshFlag)reader.ReadInt16();

            vertices = new Vector3 <float> [numVertices];
            for (int i = 0; i < numVertices; i++)
            {
                reader.ReadVector3(out vertices[i], false);
            }
            normals = new Vector3 <float> [numVertices];
            for (int i = 0; i < numVertices; i++)
            {
                reader.ReadVector3(out normals[i], false);
            }

            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]);
                    }
                }
            }

            if (!flags.HasFlag(BrgMeshFlag.NOTFIRSTMESH))
            {
                if (flags.HasFlag(BrgMeshFlag.MATERIALS))
                {
                    faceMaterials = new Int16[numFaces];
                    for (int i = 0; i < numFaces; i++)
                    {
                        faceMaterials[i] = (Int16)reader.ReadInt32();
                    }
                }

                faceVertices = new Vector3 <Int16> [numFaces];
                for (int i = 0; i < numFaces; i++)
                {
                    reader.ReadVector3(out faceVertices[i]);
                    faceVertices[i].X -= 1;
                    faceVertices[i].Y -= 1;
                    faceVertices[i].Z -= 1;
                }

                if (flags.HasFlag(BrgMeshFlag.MATERIALS))
                {
                    vertMaterials = new Int16[numVertices];
                    for (int i = 0; i < numFaces; i++)
                    {
                        vertMaterials[faceVertices[i].X] = faceMaterials[i];
                        vertMaterials[faceVertices[i].Y] = faceMaterials[i];
                        vertMaterials[faceVertices[i].Z] = faceMaterials[i];
                    }
                }
            }

            if (flags.HasFlag(BrgMeshFlag.ATTACHPOINTS))
            {
                numMatrix = (Int16)reader.ReadInt32();

                attachpoints = new List <BrgAttachpoint>(numMatrix);
                for (int i = 0; i < attachpoints.Count; i++)
                {
                    attachpoints.Add(new BrgAttachpoint());
                    attachpoints[i].NameId = BrgAttachpoint.GetIdByName(reader.ReadString());

                    Vector3 <float> x3, y3, z3;
                    reader.ReadVector3(out x3);
                    reader.ReadVector3(out y3);
                    reader.ReadVector3(out z3);
                    reader.ReadVector3(out attachpoints[i].position, false);

                    attachpoints[i].x.X = x3.Z;
                    attachpoints[i].x.Y = z3.Z;
                    attachpoints[i].x.Z = y3.Z;

                    attachpoints[i].y.X = x3.Y;
                    attachpoints[i].y.Y = z3.Y;
                    attachpoints[i].y.Z = y3.Y;

                    attachpoints[i].z.X = x3.X;
                    attachpoints[i].z.Y = z3.X;
                    attachpoints[i].z.Z = y3.X;
                }
            }
        }
        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();
                    }
                }
            }
        }