示例#1
0
        public override void Export(AssetList asset, string path)
        {
            var materials = (asset as MaterialList);
            var mat = new MAT();

            foreach (Material material in materials.Entries)
            {
                mat.Materials.Add(
                    new MATMaterial(
                        material.Name,
                        material.Texture.Name
                    )
                );
            }

            mat.Save(path);
        }
        public static void ProcessTEX(string PathIn, string PathOut, out cpsxTex[] psxTex)
        {
            string pathIn = PathIn.Substring(0, PathIn.LastIndexOf("\\") + 1);
            string fileIn = PathIn.Replace(pathIn, "");

            bool bNonCars = fileIn.Contains(".MOT");

            if (!Directory.Exists(PathOut)) { Directory.CreateDirectory(PathOut); }
            if (!Directory.Exists(PathOut + "\\TIFFRGB")) { Directory.CreateDirectory(PathOut + "\\TIFFRGB"); }

            MAT m = new MAT();
            using (BinaryReader br = new BinaryReader(new FileStream(pathIn + fileIn, FileMode.Open)))
            {

                int iTexCount = br.ReadInt32();
                Color[] colours = new Color[16];

                psxTex = new cpsxTex[iTexCount];

                int k = 0;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    if (br.ReadInt32() != 0) { Console.WriteLine("int not 0"); }

                    int width = br.ReadInt16();
                    int height = br.ReadInt16();

                    // Palette
                    for (int i = 0; i < 16; i++) { colours[i] = pixelToRGB(br.ReadUInt16()); }

                    Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);

                    // Pixels
                    int x = 0;
                    int y = height - 1;
                    int j = 0;

                    psxTex[k].Width = width;
                    psxTex[k].Height = height;

                    for (int i = 0; i < ((width * height) / 2); i++)
                    {
                        int b = br.ReadByte();

                        int idxA = (b & 0xF0) >> 4;
                        int idxB = (b & 0xF);

                        bmp.SetPixel(x, y, colours[idxB]);
                        bmp.SetPixel(x + 1, y, colours[idxA]);

                        j += 2;

                        if (j % width == 0) { x = 0; y--; } else { x += 2; }
                    }

                    psxTex[k].Name = "psx" + fileIn.Replace(".TEX", "").Replace(".MOT", "").Replace(".MAT", "") + (bNonCars ? "nc" : "") + k.ToString().PadLeft(2, "0"[0]);
                    m.Materials.Add(new MATMaterial(psxTex[k].Name, psxTex[k].Name));
                    bmp.Save(PathOut + "\\TIFFRGB\\" + psxTex[k].Name + ".tif", System.Drawing.Imaging.ImageFormat.Tiff);
                    k++;
                }
            }

            m.Save(PathOut + (bNonCars ? "nc" : "") + fileIn.Replace(".TEX", ".mat").Replace(".MOT", ".mat"));
        }