Ejemplo n.º 1
0
        private static void ExportTextureWithColors(string n3dPath, string outPath, string colors)
        {
            string name = Path.GetFileNameWithoutExtension(n3dPath);
            string path = Path.Combine(outPath, name);

            // Get texture file
            Npck pack    = new Npck(n3dPath);
            Btx0 texture = new Btx0(pack[0]);

            // Parse colors
            string[] strColors = colors.Split(' ');
            Color[]  newColors = new Color[strColors.Length];
            for (int i = 0; i < strColors.Length; i++)
            {
                int hexColor = Convert.ToInt32(strColors[i], 16);
                newColors[i]       = new Color();
                newColors[i].Alpha = 255;
                newColors[i].Red   = (hexColor >> 00) & 0xFF;
                newColors[i].Green = (hexColor >> 08) & 0xFF;
                newColors[i].Blue  = (hexColor >> 16) & 0xFF;
            }

            // Create and export palette
            Palette palette = new Palette(newColors);

            palette.ToWinPaletteFormat(path + "_palGimp.pal", 0, true);
            palette.ToWinPaletteFormat(path + "_pal.pal", 0, false);
            palette.CreateBitmap(0).Save(path + "_pal.png");

            // For each image, set new palette and export it
            for (int i = 0; i < texture.NumTextures; i++)
            {
                texture.CreateBitmap(i, palette).Save(path + "_" + i.ToString() + ".png");
            }
        }
Ejemplo n.º 2
0
        private static void ExportTexture(string n3dPath, string outPath)
        {
            string filename = Path.GetFileNameWithoutExtension(n3dPath);

            // Get texture file
            Npck pack    = new Npck(n3dPath);
            Btx0 texture = new Btx0(pack[0]);

            // Export images and palettes
            for (int i = 0; i < texture.NumTextures; i++)
            {
                string name = filename + "_" + i.ToString();
                string path = Path.Combine(outPath, name);
                if (File.Exists(path + ".png"))
                {
                    path += Path.GetRandomFileName();
                }

                texture.CreateBitmap(i).Save(path + ".png");
                texture.GetPalette(i).ToWinPaletteFormat(path + "_gimp.pal", 0, true);
                texture.GetPalette(i).ToWinPaletteFormat(path + ".pal", 0, false);
                texture.GetPalette(i).ToAcoFormat(path + ".aco", 0);
            }
        }
Ejemplo n.º 3
0
        private static void ExportTextureWithColors(string n3dPath, string outPath, string colors)
        {
            string name = Path.GetFileNameWithoutExtension(n3dPath);
            string path = Path.Combine(outPath, name);

            // Get texture file
            Npck pack = new Npck(n3dPath);
            Btx0 texture = new Btx0(pack[0]);

            // Parse colors
            string[] strColors = colors.Split(' ');
            Color[] newColors = new Color[strColors.Length];
            for (int i = 0; i < strColors.Length; i++) {
                int hexColor = Convert.ToInt32(strColors[i], 16);
                newColors[i] = new Color();
                newColors[i].Alpha = 255;
                newColors[i].Red   = (hexColor >> 00) & 0xFF;
                newColors[i].Green = (hexColor >> 08) & 0xFF;
                newColors[i].Blue  = (hexColor >> 16) & 0xFF;
            }

            // Create and export palette
            Palette palette = new Palette(newColors);
            palette.ToWinPaletteFormat(path + "_palGimp.pal", 0, true);
            palette.ToWinPaletteFormat(path + "_pal.pal", 0, false);
            palette.CreateBitmap(0).Save(path + "_pal.png");

            // For each image, set new palette and export it
            for (int i = 0; i < texture.NumTextures; i++)
                texture.CreateBitmap(i, palette).Save(path + "_" + i.ToString() + ".png");
        }
Ejemplo n.º 4
0
        public static Npck ChangeTextureImages(EmguImage[] images, int[] frames, Palette palOut, Npck original)
        {
            // Get an original texture file to get images and the texture to modify
            long start = original[0].Position;

            Btx0 oriTexture = new Btx0(original[0]);
            original[0].Position = start;

            Btx0 newTexture = new Btx0(original[0]);
            original[0].Position = start;

            // Create importer and remove all images
            TextureImporter importer = new TextureImporter(newTexture);
            importer.RemoveImages();

            // Add images from arguments or original texture if not presents.
            List<int> frameList = frames.ToList();
            for (int i = 0; i < oriTexture.NumTextures; i++) {
                int idx = frameList.IndexOf(i);

                // Set quantization to original palette or argument palette
                Color[] originalPalette = oriTexture.GetPalette(i).GetPalette(0);
                if (idx != -1 && palOut != null)
                    importer.Quantization = new FixedPaletteQuantization(palOut.GetPalette(idx));
                else
                    importer.Quantization = new FixedPaletteQuantization(originalPalette);

                // Keep original color format and name
                string name = oriTexture.GetTextureName(i);
                importer.Format = oriTexture.GetImage(i).Format;

                // Keep original unknown values
                int[] texUnks = oriTexture.GetTextureUnknowns(i);
                int[] palUnks = oriTexture.GetPaletteUnknowns(i);

                // Import :D
                if (idx != -1)
                    importer.AddImage(images[idx], name, texUnks, palUnks, originalPalette);
                else
                    importer.AddImage(oriTexture.CreateBitmap(i), name, texUnks, palUnks);
            }

            // Write the new texture file
            MemoryStream textureStream = new MemoryStream();
            newTexture.Write(textureStream);
            textureStream.Position = 0;

            // Create a copy of the NPCK from the original
            Npck npck = new Npck();
            npck.AddSubfile(textureStream);
            for (int i = 1; i < 6; i++)
                npck.AddSubfile(original[i]);

            return npck;
        }
Ejemplo n.º 5
0
        private static void ExportTexture(string n3dPath, string outPath)
        {
            string filename = Path.GetFileNameWithoutExtension(n3dPath);

            // Get texture file
            Npck pack = new Npck(n3dPath);
            Btx0 texture = new Btx0(pack[0]);

            // Export images and palettes
            for (int i = 0; i < texture.NumTextures; i++) {
                string name = filename + "_" + i.ToString();
                string path = Path.Combine(outPath, name);
                if (File.Exists(path + ".png"))
                    path += Path.GetRandomFileName();

                texture.CreateBitmap(i).Save(path + ".png");
                texture.GetPalette(i).ToWinPaletteFormat(path + "_gimp.pal", 0, true);
                texture.GetPalette(i).ToWinPaletteFormat(path + ".pal", 0, false);
                texture.GetPalette(i).ToAcoFormat(path + ".aco", 0);
            }
        }