Exemplo n.º 1
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "MT5 file (*.mt5)|*.mt5|MT7 file (*.mt7)|*.mt7";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (m_modelType == ModelType.MT5)
                {
                    MT5 mt5 = (MT5)m_model;
                    mt5.Write(saveFileDialog.FileName);
                }
            }
        }
Exemplo n.º 2
0
        static void ExportCHRT(string path, string outPath, string archiveDir)
        {
            if (archiveDir == null)
            {
                Console.WriteLine("No archive directory supplied.");
                return;
            }

            if (!File.Exists(path))
            {
                Console.WriteLine("{0} does not exist as a file, falling back to batch mode.", path);

                if (Directory.Exists(path))
                {
                    var ext = new List <string> {
                        ".chrt"
                    };
                    var myFiles = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s).ToLower()));

                    foreach (string file in myFiles)
                    {
                        var    currentChildDir = outPath + "\\" + Path.GetDirectoryName(file.Replace(path, ""));
                        string filename        = Path.GetFileName(file);
                        string dest            = currentChildDir + "\\_" + filename + "_\\" + Path.ChangeExtension(filename, ".chrt.obj");
                        string dir             = Path.GetDirectoryName(dest);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        try
                        {
                            ExportCHRT(file, dest, archiveDir);

                            if (bVerbose)
                            {
                                Console.WriteLine("Converting {0} to {1}", file, dest);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Oops! {0} failed!\nException: {1}", file, e.ToString());

                            ++iNumFailedOperations;
                        }

                        ++iNumOperations;
                    }
                }
                else
                {
                    Console.WriteLine("{0} does not exist. Cancelling operation.", path);
                    return;
                }
            }
            else
            {
                try
                {
                    CHRT chrt = new CHRT();
                    chrt.Read(path);

                    if (chrt != null)
                    {
                        foreach (ModelNode node in chrt.RootNode.GetAllNodes())
                        {
                            if (node.ModelName == "" || node.CHRTID == null)
                            {
                                continue;
                            }

                            if (node.Position == Vector3.Zero)
                            {
                                continue;
                            }

                            var tempOutputPath = outPath;
                            var ext            = new List <string> {
                                ".mt5", ".MT5"
                            };
                            var myFiles = Directory.GetFiles(archiveDir, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s).ToLower()));

                            foreach (string file in myFiles)
                            {
                                string filename = Path.GetFileName(file);
                                try
                                {
                                    if (Path.GetFileNameWithoutExtension(file).ToUpper() == node.ModelName.ToUpper())
                                    {
                                        tempOutputPath += "\\" + node.ModelName + ".chrt.obj";

                                        MT5 newNode  = new MT5(file);
                                        OBJ newModel = new OBJ(newNode);

                                        if (newNode != null && newModel != null)
                                        {
                                            newModel.RootNode.Position = node.Position;
                                            newModel.RootNode.Rotation = node.Rotation;
                                            newModel.RootNode.Scale    = node.Scale;

                                            newModel.Write(tempOutputPath);
                                        }
                                        Console.WriteLine("Converted {0} into {1}", node.ModelName, tempOutputPath);
                                        break;
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Oops! {0} failed!\nException: {1}", file, e.ToString());
                                    ++iNumFailedOperations;
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Oops! {0} failed!\nException: {1}", path, e.ToString());
                    ++iNumFailedOperations;
                }
                ++iNumOperations;
            }
            return;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Exports a given MT5 file into an OBJ file at the requested directory
        /// </summary>
        /// <param name="path">Path to MT5</param>
        /// <param name="objFilepath">Path to output the resulting OBJ file</param>
        static void ExportMT5(string path, string objFilepath)
        {
            if (!File.Exists(path))
            {
                Console.WriteLine("{0} does not exist as a file, falling back to batch mode.", path);

                if (Directory.Exists(path))
                {
                    var ext = new List <string> {
                        ".mt5", ".mapm", ".prop", ".chrm"
                    };
                    var myFiles = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s).ToLower()));

                    foreach (string file in myFiles)
                    {
                        var    currentChildDir = objFilepath + "\\" + Path.GetDirectoryName(file.Replace(path, ""));
                        string filename        = Path.GetFileName(file);
                        string dest            = currentChildDir + "\\_" + filename + "_\\" + Path.ChangeExtension(filename, ".obj");
                        string dir             = Path.GetDirectoryName(dest);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        try
                        {
                            ExportMT5(file, dest);

                            if (bVerbose)
                            {
                                Console.WriteLine("Converting {0} to {1}", file, dest);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Oops! {0} failed!\nException: {1}", file, e.ToString());

                            ++iNumFailedOperations;
                        }

                        ++iNumOperations;
                    }
                }
                else
                {
                    Console.WriteLine("{0} does not exist. Cancelling operation.", path);
                    return;
                }
            }
            else
            {
                var destFile = Path.GetFileName(objFilepath);
                objFilepath += "_\\";

                Directory.CreateDirectory(objFilepath);
                objFilepath += destFile;

                try
                {
                    MT5 mt5 = new MT5(path);

                    /*foreach(ModelNode node in mt5.GetAllNodes())
                     * {
                     *  if (node.BoneID == BoneID.LeftUpperArm)
                     *      node.Rotation.Y += 90.0f;
                     *  else if(node.BoneID == BoneID.RightUpperArm)
                     *      node.Rotation.Y -= 90.0f;
                     * }*/

                    OBJ obj = new OBJ(mt5);
                    if (obj != null && mt5 != null)
                    {
                        obj.Write(objFilepath);
                    }

                    if (bVerbose)
                    {
                        Console.WriteLine("Converted {0} to {1}", path, objFilepath);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Oops! {0} failed!\nException: {1}", path, e.ToString());

                    ++iNumFailedOperations;
                }

                ++iNumOperations;
            }
            return;
        }
Exemplo n.º 4
0
 private void ReadFileRecursive(byte[] data)
 {
     if (GZ.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             GZ gz = new GZ(memstream);
             ReadFileRecursive(gz.ContentBuffer);
         }
     }
     if (AFS.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             AFS afs = new AFS(memstream);
             foreach (var entry in afs.Entries)
             {
                 ReadFileRecursive(entry.Buffer);
             }
         }
     }
     if (PKF.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             PKF pkf = new PKF(memstream);
             foreach (var entry in pkf.Entries)
             {
                 ReadFileRecursive(entry.Buffer);
             }
         }
     }
     if (PKS.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             PKS pks = new PKS(memstream);
             foreach (var entry in pks.IPAC.Entries)
             {
                 ReadFileRecursive(entry.Buffer);
             }
         }
     }
     if (TEXN.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             TEXN     tex   = new TEXN(memstream);
             TexEntry entry = new TexEntry();
             entry.texID = tex.TextureID;
             entry.image = tex.Texture;
             textures.Add(entry);
         }
     }
     if (MT5.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             MT5 mt5 = new MT5(memstream);
             foreach (var tex in mt5.Textures)
             {
                 if (tex.Image != null)
                 {
                     TexEntry entry = new TexEntry();
                     entry.texID = tex.TextureID;
                     entry.image = tex.Image;
                     textures.Add(entry);
                 }
             }
         }
     }
     if (MT7.IsValid(data))
     {
         using (MemoryStream memstream = new MemoryStream(data))
         {
             MT7 mt7 = new MT7(memstream);
             foreach (var tex in mt7.Textures)
             {
                 if (tex.Image != null)
                 {
                     TexEntry entry = new TexEntry();
                     entry.texID = tex.TextureID;
                     entry.image = tex.Image;
                     textures.Add(entry);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        public static string GetExtensionFromBuffer(byte[] buffer)
        {
            //Archives
            if (AFS.IsValid(buffer))
            {
                return("AFS");
            }
            if (GZ.IsValid(buffer))
            {
                return("GZ");
            }
            if (IDX.IsValid(buffer))
            {
                return("IDX");
            }
            if (IPAC.IsValid(buffer))
            {
                return("IPAC");
            }
            if (PKF.IsValid(buffer))
            {
                return("PKF");
            }
            if (PKS.IsValid(buffer))
            {
                return("PKS");
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return("TAD");
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return("TEXN");
            }
            if (PVRT.IsValid(buffer))
            {
                return("PVRT");
            }
            if (DDS.IsValid(buffer))
            {
                return("DDS");
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return("MT5");
            }
            if (MT7.IsValid(buffer))
            {
                return("MT7");
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return("SUB");
            }

            return("UNKNOWN");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Trys to find the fitting file type for the given file with the file signature.
        /// </summary>
        public static Type GetFileTypeFromSignature(Stream stream)
        {
            byte[] buffer = new byte[8];
            stream.Read(buffer, 0, buffer.Length);

            //Archives
            if (AFS.IsValid(buffer))
            {
                return(typeof(AFS));
            }
            if (GZ.IsValid(buffer))
            {
                return(typeof(GZ));
            }
            if (IDX.IsValid(buffer))
            {
                return(typeof(IDX));
            }
            if (IPAC.IsValid(buffer))
            {
                return(typeof(IPAC));
            }
            if (PKF.IsValid(buffer))
            {
                return(typeof(PKF));
            }
            if (PKS.IsValid(buffer))
            {
                return(typeof(PKS));
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return(typeof(TAD));
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return(typeof(TEXN));
            }
            if (PVRT.IsValid(buffer))
            {
                return(typeof(PVRT));
            }
            if (DDS.IsValid(buffer))
            {
                return(typeof(DDS));
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return(typeof(MT5));
            }
            if (MT7.IsValid(buffer))
            {
                return(typeof(MT7));
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return(typeof(SUB));
            }

            return(null);
        }
Exemplo n.º 7
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Supported files|*.mt5;*.mt7;*.mapm;*.chrm;*.prop;*.fbx;*.obj";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string extension = Path.GetExtension(openFileDialog.FileName);

                byte[] buffer = new byte[4];
                using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open))
                {
                    stream.Read(buffer, 0, 4);
                    stream.Seek(0, SeekOrigin.Begin);
                }

                if (MT5.IsValid(buffer))
                {
                    m_model         = new MT5(openFileDialog.FileName);
                    m_primitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip;
                    view3D.SetTextures(m_model.Textures);
                    view3D.SetModel(m_model, m_primitiveType);
                    m_modelType = ModelType.MT5;
                }
                else if (MT7.IsValid(buffer))
                {
                    m_model         = new MT7(openFileDialog.FileName);
                    m_primitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles;
                    view3D.SetTextures(m_model.Textures);
                    view3D.SetModel(m_model, m_primitiveType);
                    m_modelType = ModelType.MT7;
                }
                else if (FBXD3T.IsValid(buffer))
                {
                    m_model     = new FBXD3T(openFileDialog.FileName);
                    m_modelType = ModelType.FBXD3T;
                }
                else if (extension == ".obj")
                {
                    m_model         = new OBJ(openFileDialog.FileName);
                    m_primitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles;
                    view3D.SetTextures(m_model.Textures);
                    view3D.SetModel(m_model, m_primitiveType);
                }
                else
                {
                    Console.WriteLine("Invalid file format!");
                }

                treeView_MeshNodes.Nodes.Clear();
                listBox_Textures.Items.Clear();

                m_model.RootNode.GenerateTree(null);
                TreeNode treeNode = new TreeNode(openFileDialog.FileName);
                GenerateTree(treeNode, m_model.RootNode);
                treeView_MeshNodes.Nodes.Add(treeNode);

                foreach (Texture texture in m_model.Textures)
                {
                    if (texture == null)
                    {
                        continue;
                    }
                    listBox_Textures.Items.Add(texture);
                }
            }

            if (m_modelType == ModelType.MT5)
            {
                mt5Control.Enabled = true;
                mt7Control.Enabled = false;
            }
            if (m_modelType == ModelType.MT7)
            {
                mt5Control.Enabled = false;
                mt7Control.Enabled = true;
            }
        }