Ejemplo n.º 1
0
        private void ImportBack(string filename)
        {
            if (dontModify)
            {
                return;
            }

            NutTexture tex = textureFromFile[filename];

            try
            {
                Dds        dds  = new Dds(new FileData(filename));
                NutTexture ntex = dds.ToNutTexture();

                tex.Height = ntex.Height;
                tex.Width  = ntex.Width;
                tex.pixelInternalFormat = ntex.pixelInternalFormat;
                tex.surfaces            = ntex.surfaces;
                tex.pixelFormat         = ntex.pixelFormat;

                //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
                currentNut.glTexByHashId.Remove(tex.HashId);
                currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));

                FillForm();
                textureListBox.SelectedItem = tex;
                glControl1.Invalidate();
            }
            catch
            {
                Console.WriteLine("Could not be open for editing");
            }
        }
Ejemplo n.º 2
0
        private void ExportNutToFolder(object sender, EventArgs e)
        {
            using (FolderSelectDialog f = new FolderSelectDialog())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (!Directory.Exists(f.SelectedPath))
                    {
                        Directory.CreateDirectory(f.SelectedPath);
                    }

                    ShowGtxMipmapWarning(currentNut);

                    foreach (NutTexture tex in currentNut.Nodes)
                    {
                        if (tex.pixelInternalFormat == PixelInternalFormat.Rgba)
                        {
                            string filename = Path.Combine(f.SelectedPath, $"{tex.HashId.ToString("X")}.png");
                            ExportPng(filename, tex);
                        }
                        else
                        {
                            string filename = Path.Combine(f.SelectedPath, $"{tex.HashId.ToString("X")}.dds");
                            Dds    dds      = new Dds();
                            dds.FromNutTexture(tex);
                            dds.Save(filename);
                        }
                    }

                    Process.Start("explorer.exe", f.SelectedPath);
                }
            }
        }
Ejemplo n.º 3
0
        private void ExportDds(string filename, NutTexture tex)
        {
            Dds dds = new Dds();

            dds.FromNutTexture(tex);
            dds.Save(filename);
        }
Ejemplo n.º 4
0
        // I'm completely totally serious

        public static Nud Create(VBN vbn)
        {
            Dictionary <string, string> files = new Dictionary <string, string>();
            ZipArchive zip = ZipFile.OpenRead("lib\\Skapon.zip");

            Random random       = new Random();
            int    randomNumber = random.Next(0, 0xFFFFFF);

            NUT nut = new NUT();

            foreach (ZipArchiveEntry e in zip.Entries)
            {
                byte[] b;
                using (BinaryReader br = new BinaryReader(e.Open()))
                {
                    b = br.ReadBytes((int)e.Length);
                }
                var    stream = new StreamReader(new MemoryStream(b));
                string s      = stream.ReadToEnd();
                files.Add(e.Name, s);

                if (e.Name.EndsWith(".dds"))
                {
                    NutTexture tex = new Dds(new FileData(b)).ToNutTexture();
                    nut.Nodes.Add(tex);
                    tex.HashId = 0x40000000 + randomNumber;
                    nut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                }
            }

            Nud nud = new Nud();

            Nud.Mesh head = new Nud.Mesh();
            nud.Nodes.Add(head);
            head.Text = "Skapon";

            head.Nodes.Add(setToBone(scale(readPoly(files["head.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("HeadN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["body.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("BustN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RHandN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), -1, -1, 1), vbn.bones[vbn.boneIndex("LHandN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RFootJ")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), -1, -1, -1), vbn.bones[vbn.boneIndex("LFootJ")], vbn));

            foreach (Nud.Polygon p in head.Nodes)
            {
                p.materials[0].textures[0].hash = 0x40000000 + randomNumber;
            }

            nud.UpdateRenderMeshes();

            return(nud);
        }
Ejemplo n.º 5
0
 private void chr_13_renderer_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         foreach (string filePath in files)
         {
             if (filePath.ToLower().EndsWith(".dds"))
             {
                 Dds dds = new Dds(new FileData(filePath));
                 if (sender == chr_13_renderer)
                 {
                     chr13 = ReplaceTexture(dds.ToNutTexture(), 416, 416, chr13);
                     if (chr13Loc != null)
                     {
                         chr13.Save(chr13Loc);
                     }
                 }
                 if (sender == chr_00_renderer)
                 {
                     chr00 = ReplaceTexture(dds.ToNutTexture(), 128, 128, chr00);
                     if (chr00Loc != null)
                     {
                         chr00.Save(chr00Loc);
                     }
                 }
                 if (sender == chr_11_renderer)
                 {
                     chr11 = ReplaceTexture(dds.ToNutTexture(), 384, 384, chr13);
                     if (chr11Loc != null)
                     {
                         chr11.Save(chr11Loc);
                     }
                 }
             }
             if (filePath.ToLower().EndsWith(".png"))
             {
                 if (sender == stock_90_renderer)
                 {
                     stock90 = ReplaceTexture(NutEditor.FromPng(filePath, 0), 64, 64, chr13);
                     if (stock90Loc != null)
                     {
                         stock90.Save(stock90Loc);
                     }
                 }
             }
         }
         ((GLControl)sender).Invalidate();
     }
 }
Ejemplo n.º 6
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentNut == null || textureListBox.SelectedItem == null)
            {
                return;
            }
            using (var ofd = new OpenFileDialog())
            {
                NutTexture texture = (NutTexture)(textureListBox.SelectedItem);

                ofd.Filter = "Supported Formats|*.dds;*.png|" +
                             "DirectDraw Surface (.dds)|*.dds|" +
                             "Portable Network Graphics (.png)|*.png|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    NutTexture newTexture = null;
                    string     extension  = Path.GetExtension(ofd.FileName).ToLowerInvariant();
                    if (extension == ".dds")
                    {
                        Dds dds = new Dds(new FileData(ofd.FileName));
                        newTexture = dds.ToNutTexture();
                    }
                    else if (extension == ".png")
                    {
                        newTexture = FromPng(ofd.FileName, 1);
                    }
                    else
                    {
                        return;
                    }

                    texture.Height = newTexture.Height;
                    texture.Width  = newTexture.Width;
                    texture.pixelInternalFormat = newTexture.pixelInternalFormat;
                    texture.surfaces            = newTexture.surfaces;
                    texture.pixelFormat         = newTexture.pixelFormat;

                    Edited = true;

                    //GL.DeleteTexture(NUT.glTexByHashId[texture.HASHID]);
                    currentNut.glTexByHashId.Remove(texture.HashId);
                    currentNut.glTexByHashId.Add(texture.HashId, NUT.CreateTexture2D(texture));

                    FillForm();
                }
            }
        }
Ejemplo n.º 7
0
        private void extractAndPickAProgramToEditWithToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string tempFileName;
            bool   setupFileModifying = false;

            dontModify             = true;
            fw.EnableRaisingEvents = true;
            if (!fileFromTexture.ContainsKey((NutTexture)(textureListBox.SelectedItem)))
            {
                tempFileName = Path.GetTempFileName();
                DeleteIfExists(Path.ChangeExtension(tempFileName, ".dds"));
                File.Move(tempFileName, Path.ChangeExtension(tempFileName, ".dds"));
                tempFileName = Path.ChangeExtension(tempFileName, ".dds");
                fileFromTexture.Add((NutTexture)(textureListBox.SelectedItem), tempFileName);
                textureFromFile.Add(tempFileName, (NutTexture)textureListBox.SelectedItem);
                setupFileModifying = true;
            }
            else
            {
                tempFileName = fileFromTexture[(NutTexture)textureListBox.SelectedItem];
            }

            Dds dds = new Dds();

            dds.FromNutTexture((NutTexture)(textureListBox.SelectedItem));
            dds.Save(tempFileName);
            ShowOpenWithDialog(tempFileName);
            if (setupFileModifying)
            {
                if (fw.Filter.Equals("*.*"))
                {
                    fw.Filter = Path.GetFileName(tempFileName);
                }
                else
                {
                    fw.Filter += "|" + Path.GetFileName(tempFileName);
                }
                Console.WriteLine(fw.Filter);
            }

            dontModify = false;
        }
Ejemplo n.º 8
0
        public void ConvertToDdsNut(bool regenerateMipMaps = true)
        {
            for (int i = 0; i < Nodes.Count; i++)
            {
                NutTexture originalTexture = (NutTexture)Nodes[i];

                // Reading/writing mipmaps is only supported for DDS textures,
                // so we will need to convert all the textures.
                Dds        dds        = new Dds(originalTexture);
                NutTexture ddsTexture = dds.ToNutTexture();
                ddsTexture.HashId = originalTexture.HashId;

                if (regenerateMipMaps)
                {
                    RegenerateMipmapsFromTexture2D(ddsTexture);
                }

                Nodes[i] = ddsTexture;
            }
        }
Ejemplo n.º 9
0
        private void replaceTextureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                BRTI t = (BRTI)(textureListBox.SelectedItem);

                ofd.Filter = "Portable Network Graphic (.png)|*.png;|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    BRTI.BRTI_Texture newTexture = null;
                    if (Path.GetExtension(ofd.FileName).ToLower().Equals(".png"))
                    {
                        newTexture = FromPng(ofd.FileName, 1);
                    }
                    if (Path.GetExtension(ofd.FileName).ToLower().Equals(".dds"))
                    {
                        Dds dds = new Dds(new FileData(ofd.FileName));
                        newTexture = dds.ToBrtiTexture();
                    }

                    t.texture.height = newTexture.height;
                    t.texture.width  = newTexture.width;
                    t.texture.pixelInternalFormat = newTexture.pixelInternalFormat;
                    t.texture.mipmaps             = newTexture.mipmaps;
                    t.texture.pixelFormat         = newTexture.pixelFormat;
                    newTexture.mipmaps.Add(t.texture.mipmaps[0]);

                    bntx.glTexByName.Add(ofd.FileName, BRTI.CreateTexture2D(t.texture));

                    if (newTexture == null)
                    {
                        return;
                    }

                    FillForm();
                }
            }
        }
Ejemplo n.º 10
0
        private void ImportNutFromFolder(object sender, EventArgs e)
        {
            using (FolderSelectDialog f = new FolderSelectDialog())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    if (!Directory.Exists(f.SelectedPath))
                    {
                        Directory.CreateDirectory(f.SelectedPath);
                    }
                    NUT nut;
                    nut = currentNut;

                    foreach (var texPath in Directory.GetFiles(f.SelectedPath))
                    {
                        string extension = Path.GetExtension(texPath).ToLowerInvariant();
                        if (!(extension == ".dds" || extension == ".png"))
                        {
                            continue;
                        }
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);

                        NutTexture texture = null;
                        if (isTex)
                        {
                            foreach (NutTexture tex in nut.Nodes)
                            {
                                if (tex.HashId == texId)
                                {
                                    texture = tex;
                                }
                            }
                        }

                        if (texture == null)
                        {
                            //new texture
                            NutTexture tex = null;
                            if (extension == ".dds")
                            {
                                Dds dds = new Dds(new FileData(texPath));
                                tex = dds.ToNutTexture();
                            }
                            else if (extension == ".png")
                            {
                                tex = FromPng(texPath, 1);
                            }

                            if (isTex)
                            {
                                tex.HashId = texId;
                            }
                            else
                            {
                                tex.HashId = nut.Nodes.Count;
                            }
                            nut.Nodes.Add(tex);
                            currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                            FillForm();
                        }
                        else
                        {
                            //existing texture
                            NutTexture tex = texture;

                            NutTexture ntex = null;
                            if (extension == ".dds")
                            {
                                Dds dds = new Dds(new FileData(texPath));
                                ntex = dds.ToNutTexture();
                            }
                            else if (extension == ".png")
                            {
                                ntex = FromPng(texPath, 1);
                            }

                            tex.Height = ntex.Height;
                            tex.Width  = ntex.Width;
                            tex.pixelInternalFormat = ntex.pixelInternalFormat;
                            tex.surfaces            = ntex.surfaces;
                            tex.pixelFormat         = ntex.pixelFormat;

                            //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
                            currentNut.glTexByHashId.Remove(tex.HashId);
                            currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                            FillForm();
                        }
                    }
                    if (!Runtime.textureContainers.Contains(nut))
                    {
                        Runtime.textureContainers.Add(nut);
                    }
                }
            }
            FillForm();
        }
Ejemplo n.º 11
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentNut == null)
            {
                return;
            }
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Supported Formats|*.dds;*.png|" +
                             "DirectDraw Surface (.dds)|*.dds|" +
                             "Portable Network Graphics (.png)|*.png|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    int  texId;
                    bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(ofd.FileName), NumberStyles.HexNumber,
                                              new CultureInfo("en-US"), out texId);

                    if (isTex)
                    {
                        foreach (NutTexture te in currentNut.Nodes)
                        {
                            if (texId == te.HashId)
                            {
                                isTex = false;
                            }
                        }
                    }

                    NutTexture tex       = null;
                    string     extension = Path.GetExtension(ofd.FileName).ToLowerInvariant();
                    if (extension == ".dds")
                    {
                        Dds dds = new Dds(new FileData(ofd.FileName));
                        tex = dds.ToNutTexture();
                    }
                    else if (extension == ".png")
                    {
                        tex = FromPng(ofd.FileName, 1);
                    }
                    else
                    {
                        return;
                    }

                    Edited = true;

                    if (isTex)
                    {
                        tex.HashId = texId;
                    }
                    else
                    {
                        tex.HashId = 0x40FFFF00 | (currentNut.Nodes.Count);
                    }

                    // Replace OpenGL texture.
                    if (currentNut.glTexByHashId.ContainsKey(tex.HashId))
                    {
                        currentNut.glTexByHashId.Remove(tex.HashId);
                    }

                    currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));

                    currentNut.Nodes.Add(tex);
                    FillForm();
                }
            }
        }