Esempio n. 1
0
        public static MAT Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            MAT mat = new MAT();

            MATMaterial M      = new MATMaterial();
            bool        bDebug = false;

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                br.ReadBytes(16); // Header

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag    = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                    case 0x4:
                        // C1 mat file
                        M = new MATMaterial();

                        M.DiffuseColour[0]    = br.ReadByte();  // R
                        M.DiffuseColour[1]    = br.ReadByte();  // G
                        M.DiffuseColour[2]    = br.ReadByte();  // B
                        M.DiffuseColour[3]    = br.ReadByte();  // A
                        M.AmbientLighting     = br.ReadSingle();
                        M.DirectionalLighting = br.ReadSingle();
                        M.SpecularLighting    = br.ReadSingle();
                        M.SpecularPower       = br.ReadSingle();
                        M.SetFlags((int)br.ReadUInt16());     // Flags
                        if (M.GetFlag(MATMaterial.Settings.UnknownSetting) || M.GetFlag(MATMaterial.Settings.IFromV) || M.GetFlag(MATMaterial.Settings.UFromI) || M.GetFlag(MATMaterial.Settings.VFromI))
                        {
                            bDebug = true;
                        }
                        M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        byte x1 = br.ReadByte();     // ??
                        byte x2 = br.ReadByte();     // ??
                        M.Name = br.ReadString();

                        if (bDebug)
                        {
                            Console.WriteLine(path + " :: " + M.Name); bDebug = false;
                        }
                        break;

                    case 0x3c:
                        M = new MATMaterial();

                        M.DiffuseColour[0]    = br.ReadByte();  // R
                        M.DiffuseColour[1]    = br.ReadByte();  // G
                        M.DiffuseColour[2]    = br.ReadByte();  // B
                        M.DiffuseColour[3]    = br.ReadByte();  // A
                        M.AmbientLighting     = br.ReadSingle();
                        M.DirectionalLighting = br.ReadSingle();
                        M.SpecularLighting    = br.ReadSingle();
                        M.SpecularPower       = br.ReadSingle();
                        M.SetFlags((int)br.ReadUInt32());     // Flags
                        M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        if (br.ReadUInt32() != 169803776)
                        {
                            Console.WriteLine("Weird Beard! (" + path + ")");
                        }
                        br.ReadBytes(13);     // 13 bytes of nothing
                        M.Name = br.ReadString();
                        break;

                    case 0x1c:
                        M.Texture = br.ReadString();
                        break;

                    case 0x1f:
                        string _ = br.ReadString();     // shadetable
                        break;

                    case 0x0:
                        mat.Materials.Add(M);
                        break;

                    default:
                        Logger.LogToFile(Logger.LogLevel.Error, "Unknown MAT tag: {0} ({1})", tag, br.BaseStream.Position.ToString("X"));
                        return(null);
                    }
                }
            }

            return(mat);
        }
Esempio n. 2
0
        public static MAT Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            MAT mat = new MAT();

            MATMaterial M = new MATMaterial();
            bool bDebug = false;

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                br.ReadBytes(16); // Header

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                        case 0x4:
                            // C1 mat file
                            M = new MATMaterial();

                            M.DiffuseColour[0] = br.ReadByte(); // R
                            M.DiffuseColour[1] = br.ReadByte(); // G
                            M.DiffuseColour[2] = br.ReadByte(); // B
                            M.DiffuseColour[3] = br.ReadByte(); // A
                            M.AmbientLighting = br.ReadSingle();
                            M.DirectionalLighting = br.ReadSingle();
                            M.SpecularLighting = br.ReadSingle();
                            M.SpecularPower = br.ReadSingle();
                            M.SetFlags((int)br.ReadUInt16()); // Flags
                            if (M.GetFlag(MATMaterial.Settings.UnknownSetting) || M.GetFlag(MATMaterial.Settings.IFromV) || M.GetFlag(MATMaterial.Settings.UFromI) || M.GetFlag(MATMaterial.Settings.VFromI)) { bDebug = true; }
                            M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            byte x1 = br.ReadByte(); // ??
                            byte x2 = br.ReadByte(); // ??
                            M.Name = br.ReadString();

                            if (bDebug) { Console.WriteLine(path + " :: " + M.Name); bDebug = false; }
                            break;

                        case 0x3c:
                            M = new MATMaterial();

                            M.DiffuseColour[0] = br.ReadByte(); // R
                            M.DiffuseColour[1] = br.ReadByte(); // G
                            M.DiffuseColour[2] = br.ReadByte(); // B
                            M.DiffuseColour[3] = br.ReadByte(); // A
                            M.AmbientLighting = br.ReadSingle();
                            M.DirectionalLighting = br.ReadSingle();
                            M.SpecularLighting = br.ReadSingle();
                            M.SpecularPower = br.ReadSingle();
                            M.SetFlags((int)br.ReadUInt32()); // Flags
                            M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            if (br.ReadUInt32() != 169803776) { Console.WriteLine("Weird Beard! (" + path + ")"); }
                            br.ReadBytes(13); // 13 bytes of nothing
                            M.Name = br.ReadString();
                            break;

                        case 0x1c:
                            M.Texture = br.ReadString();
                            break;

                        case 0x1f:
                            string s = br.ReadString(); // shadetable
                            break;

                        case 0x0:
                            mat.materials.Add(M);
                            break;

                        default:
                            Logger.LogToFile(Logger.LogLevel.Error, "Unknown MAT tag: {0} ({1})", tag, br.BaseStream.Position.ToString("X"));
                            return null;
                    }
                }
            }

            return mat;
        }