Пример #1
0
        /// <summary>
        ///     Exports a file of a given type.
        ///     Formats available to export will depend on the type of the data.
        /// </summary>
        /// <param name="type">Type of the data to be exported</param>
        /// <param name="data">The data</param>
        /// <param name="arguments">Optional arguments to be used by the exporter</param>
        public static void export(fileType type, object data, params object[] arguments)
        {
            using (SaveFileDialog saveDlg = new SaveFileDialog())
            {
                switch (type)
                {
                case fileType.model:
                    OModelExportForm exportMdl = new OModelExportForm((RenderBase.OModelGroup)data, (int)arguments[0]);
                    exportMdl.Show();
                    break;

                case fileType.texture:
                    OTextureExportForm exportTex = new OTextureExportForm((RenderBase.OModelGroup)data, (int)arguments[0]);
                    exportTex.Show();
                    break;

                case fileType.skeletalAnimation:
                    saveDlg.Title  = "Export Skeletal Animation";
                    saveDlg.Filter = "Source Model|*.smd";
                    if (saveDlg.ShowDialog() == DialogResult.OK)
                    {
                        switch (saveDlg.FilterIndex)
                        {
                        case 1:
                            SMD.export((RenderBase.OModelGroup)data, saveDlg.FileName, (int)arguments[0], (int)arguments[1]);
                            break;
                        }
                    }
                    break;
                }
            }
        }
Пример #2
0
        private void smd_export_show_warnings(RenderBase.OModelGroup model, string fileName, int modelIndex, int skeletalAnimationIndex = -1)
        {
            var warnings = SMD.export(model, fileName, modelIndex, skeletalAnimationIndex);

            foreach (var warning in warnings)
            {
                MessageBox.Show(warning, "SMD Exporter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        public static void ExportSkeletalAnimations(this RenderBase.OModelGroup model_group, int model_index, string out_directory)
        {
            var duplicate_anim_name_counters = model_group.skeletalAnimation.GroupBy((v) => v.name).Where(g => g.Count() > 1).Select(g => g.Key).ToDictionary(name => name, name => 0);

            for (int i = 0; i < model_group.skeletalAnimation.Count; i++)
            {
                var anim = model_group.skeletalAnimation[i];
                var name = anim.name;
                if (duplicate_anim_name_counters.ContainsKey(name))
                {
                    duplicate_anim_name_counters[name] += 1;
                    name = String.Format("{0} ({1})", name, duplicate_anim_name_counters[name]);
                }
                string path = Path.Combine(out_directory, name + ".anim.smd");
                Console.WriteLine("Exporting " + path);
                var warnings = SMD.export(model_group, path, model_index, i);
                foreach (var warning in warnings)
                {
                    Console.Error.WriteLine("Warning when exporting " + name + ": " + warning);
                }
            }
        }
Пример #4
0
        /// <summary>
        ///     Exports a file of a given type.
        ///     Formats available to export will depend on the type of the data.
        /// </summary>
        /// <param name="type">Type of the data to be exported</param>
        /// <param name="data">The data</param>
        /// <param name="arguments">Optional arguments to be used by the exporter</param>
        public static void export(FileIO.fileType type, object data, params int[] arguments)
        {
            using (SaveFileDialog saveDlg = new SaveFileDialog())
            {
                switch (type)
                {
                case FileIO.fileType.model:
                    OModelExportForm exportMdl = new OModelExportForm((RenderBase.OModelGroup)data, arguments[0]);
                    exportMdl.Show();
                    break;

                case FileIO.fileType.texture:
                    OTextureExportForm exportTex = new OTextureExportForm((RenderBase.OModelGroup)data, arguments[0]);
                    exportTex.Show();
                    break;

                case FileIO.fileType.skeletalAnimation:
                    saveDlg.Title  = "Export Skeletal Animation";
                    saveDlg.Filter = "Source Model|*.smd";
                    if (saveDlg.ShowDialog() == DialogResult.OK)
                    {
                        switch (saveDlg.FilterIndex)
                        {
                        case 1:
                            var warnings = SMD.export((RenderBase.OModelGroup)data, saveDlg.FileName, arguments[0], arguments[1]);
                            foreach (var warning in warnings)
                            {
                                MessageBox.Show(warning, "SMD Exporter", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
Пример #5
0
        /// <summary>
        ///     Exports a file of a given type.
        ///     Formats available to export will depend on the type of the data.
        /// </summary>
        /// <param name="type">Type of the data to be exported</param>
        /// <param name="data">The data</param>
        /// <param name="arguments">Optional arguments to be used by the exporter</param>
        public static void export(fileType type, object data, params int[] arguments)
        {
            string fileName = null;

            switch (type)
            {
            case fileType.container:
                foreach (OContainer.fileEntry file in ((OContainer)data).content)
                {
                    Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name);

                    fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name, file.name);
                    string dir = Path.GetDirectoryName(fileName);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    byte[] buffer;

                    if (file.loadFromDisk)
                    {
                        buffer = new byte[file.fileLength];
                        ((OContainer)data).data.Seek(file.fileOffset, SeekOrigin.Begin);
                        ((OContainer)data).data.Read(buffer, 0, buffer.Length);
                    }
                    else
                    {
                        buffer = file.data;
                    }

                    if (file.doDecompression)
                    {
                        buffer = LZSS_Ninty.decompress(buffer);
                    }

                    File.WriteAllBytes(fileName, buffer);
                    Console.WriteLine("Extracted file: " + fileName);
                }
                break;

            case fileType.model:
                for (int i = 0; i < ((RenderBase.OModelGroup)data).model.Count; i++)
                {
                    fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[i].name);

                    switch (arguments[0])
                    {
                    case 0: DAE.export(((RenderBase.OModelGroup)data), fileName + ".dae", i); break;

                    case 1: SMD.export(((RenderBase.OModelGroup)data), fileName + ".smd", i); break;

                    case 2: OBJ.export(((RenderBase.OModelGroup)data), fileName + ".obj", i); break;

                    case 3: CMDL.export(((RenderBase.OModelGroup)data), fileName + ".cmdl", i); break;
                    }

                    Console.WriteLine("Extracted file: " + fileName);
                }
                break;

            case fileType.texture:
                if (data.GetType().Equals(typeof(RenderBase.OModelGroup)))       //if extracting textures from a model
                {
                    Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex");

                    foreach (RenderBase.OTexture tex in ((RenderBase.OModelGroup)data).texture)
                    {
                        fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex", tex.name + ".png");
                        tex.texture.Save(fileName);
                        Console.WriteLine("Extracted file: " + fileName);
                    }
                }
                else     // not a model
                {
                    fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OTexture)data).name + ".png");
                    ((RenderBase.OTexture)data).texture.Save(fileName);
                    Console.WriteLine("Extracted file: " + fileName);
                }
                break;

            case fileType.skeletalAnimation:
                fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[0].name);
                SMD.export((RenderBase.OModelGroup)data, fileName, arguments[0], arguments[1]);
                Console.WriteLine("Extracted file: " + fileName);
                break;
            }
            Console.WriteLine("Extracting files completed!");
        }
        private void ok()
        {
            if (!Directory.Exists(TxtOutFolder.Text))
            {
                MessageBox.Show("Invalid output directory!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            Settings.Default.meOutFolder = TxtOutFolder.Text;

            int format = 0;

            if (RadioSMD.Checked)
            {
                format = 1;
            }
            else if (RadioOBJ.Checked)
            {
                format = 2;
            }
            else if (RadioCMDL.Checked)
            {
                format = 3;
            }

            Settings.Default.meFormat        = format;
            Settings.Default.meExportAllMdls = ChkExportAllModels.Checked;
            Settings.Default.meExportAllAnms = ChkExportAllAnimations.Checked;

            Settings.Default.Save();

            if (ChkExportAllModels.Checked && !ChkExportAllAnimations.Checked)
            {
                for (int i = 0; i < mdls.model.Count; i++)
                {
                    string fileName = Path.Combine(TxtOutFolder.Text, mdls.model[i].name);

                    switch (format)
                    {
                    case 0: DAE.export(mdls, fileName + ".dae", i); break;

                    case 1: SMD.export(mdls, fileName + ".smd", i); break;

                    case 2: OBJ.export(mdls, fileName + ".obj", i); break;

                    case 3: CMDL.export(mdls, fileName + ".cmdl", i); break;
                    }
                }
            }
            else if (mdlIndex > -1)
            {
                string fileName = Path.Combine(TxtOutFolder.Text, TxtModelName.Text);

                switch (format)
                {
                case 0: DAE.export(mdls, fileName + ".dae", mdlIndex); break;

                case 1:
                    SMD.export(mdls, fileName + ".smd", mdlIndex);
                    if (ChkExportAllAnimations.Checked)
                    {
                        for (int i = 0; i < mdls.skeletalAnimation.list.Count; i++)
                        {
                            string name = mdls.skeletalAnimation.list[i].name + ".smd";
                            SMD.export(mdls, Path.Combine(TxtOutFolder.Text, name), mdlIndex, i);
                        }
                    }
                    break;

                case 2: OBJ.export(mdls, fileName + ".obj", mdlIndex); break;

                case 3: CMDL.export(mdls, fileName + ".cmdl", mdlIndex); break;
                }
            }

            Close();
        }