Exemple #1
0
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog loadobj = new OpenFileDialog();

            loadobj.Filter      = "COLLADA Files (*.dae)|*.dae|TEXTURE Files|*.*";
            loadobj.FilterIndex = 1;

            if (loadobj.ShowDialog() == DialogResult.OK)
            {
                textPath.Text = loadobj.FileName;
                if (Path.GetExtension(loadobj.FileName) == ".dae")
                {
                    //sFileName = loadobj.FileName;
                    if (Regex.Matches(File.ReadAllText(sFileName), "<geometry").Count != 1)
                    {
                        if (Regex.Matches(File.ReadAllText(sFileName), "<geometry").Count == 0)
                        {
                            MessageBox.Show("This collada file doesn't contain any geometry!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        for (int i = 0; i < Regex.Matches(File.ReadAllText(sFileName), "<geometry").Count; i++)
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.Load(sFileName);
                            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                            mgr.AddNamespace("df", doc.DocumentElement.NamespaceURI);
                            XmlNodeList geometrytags = doc.SelectNodes("//df:COLLADA/df:library_geometries/df:geometry", mgr);
                            string      oh           = "";
                            foreach (XmlNode geometrytag in geometrytags)
                            {
                                if (geometrytag == geometrytags[i])
                                {
                                    oh = geometrytag.Attributes["name"].Value;
                                }
                                else
                                {
                                    geometrytag.ParentNode.RemoveChild(geometrytag);
                                }
                            }
                            doc.SelectSingleNode("//df:COLLADA/df:asset/df:contributor/df:author", mgr).InnerText         = "DAE2BMF";
                            doc.SelectSingleNode("//df:COLLADA/df:asset/df:contributor/df:authoring_tool", mgr).InnerText = "DAE2BMF for ONE64 Engine (https://discord.gg/9Ej79C3)";
                            doc.SelectSingleNode("//df:COLLADA/df:asset/df:modified", mgr).InnerText = DateTime.Now.ToString(@"yyyy-MM-ddTHH\:mm\:ss\:ff");
                            doc.Save(Path.GetDirectoryName(sFileName) + "\\" + Path.GetFileNameWithoutExtension(sFileName) + "_" + oh + Path.GetExtension(sFileName));
                        }
                    }
                    //textPath.Text = sFileName;
                    buttonSaveBmf.Enabled = true;
                    sFileName             = textPath.Text;
                    File.WriteAllText(Path.GetDirectoryName(Application.ExecutablePath) + "/settings.bmfo", sFileName + "\n" + Directory.GetCurrentDirectory());
                }
                else
                {
                    if (Path.GetExtension(loadobj.FileName).Contains("RGBA") || Path.GetExtension(loadobj.FileName).Contains("IA") || Path.GetExtension(loadobj.FileName).Contains("I") || Path.GetExtension(loadobj.FileName).Contains("CI"))
                    {
                        var    x         = Interaction.InputBox("Image width (X):", "Extra params", "");
                        var    y         = Interaction.InputBox("Image height (Y):", "Extra params", "");
                        Bitmap converted = texconv.ExtractTex(File.ReadAllBytes(loadobj.FileName), Regex.Replace(Path.GetExtension(loadobj.FileName), "[^A-Z _]", ""), int.Parse(Regex.Replace(Path.GetExtension(loadobj.FileName), "[^1-9 _]", "")), int.Parse(x), int.Parse(y));
                        MessageBox.Show(converted.GetPixel(0, 0).ToString());
                        converted.Save(Path.ChangeExtension(loadobj.FileName, "bmp"));
                    }
                    File.WriteAllText(Path.GetDirectoryName(Application.ExecutablePath) + "/settings.bmfo", sFileName + "\n" + Directory.GetCurrentDirectory() + "\nTEXONLY");
                    buttonSaveBmf.Enabled = false;
                }
            }
            button4.PerformClick();
            button1.Enabled = false;

            /*FolderBrowserDialog texdir = new FolderBrowserDialog();
             *
             * if (texdir.ShowDialog() == DialogResult.OK)
             * {
             *  tFileName = texdir.SelectedPath;
             * }*/
        }