Пример #1
0
        private void OnSetFileAssociations(object sender, EventArgs e)
        {
            using (var imp = new Assimp.AssimpContext())
            {
                var list = imp.GetSupportedImportFormats();

                // do not associate .xml - it is too generic
                var filteredList = list.Where(s => s != ".xml").ToArray();

                var listString = string.Join(", ", filteredList);
                if (DialogResult.OK == MessageBox.Show(this, "The following file extensions will be associated with open3mod: " + listString,
                                                       "Set file associations",
                                                       MessageBoxButtons.OKCancel))
                {
                    if (!FileAssociations.SetAssociations(list))
                    {
                        MessageBox.Show(this, "Failed to set file extensions", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(this, "File extensions have been successfully associated", "open3mod", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
Пример #2
0
        private void OnDrag(object sender, DragEventArgs e)
        {
            // code based on http://www.codeproject.com/Articles/3598/Drag-and-Drop
            try
            {
                var a = (Array)e.Data.GetData(DataFormats.FileDrop);

                if (a != null && a.GetLength(0) > 0)
                {
                    for (int i = 0, count = a.GetLength(0); i < count; ++i)
                    {
                        var s = a.GetValue(i).ToString();

                        // check if the dragged file is a folder. In this case,
                        // we load all applicable files in the folder.

                        // TODO this means, files with no proper file extension
                        // won't load this way.
                        try
                        {
                            FileAttributes attr = File.GetAttributes(s);
                            if (attr.HasFlag(FileAttributes.Directory))
                            {
                                string[] formats;
                                using (var tempImporter = new Assimp.AssimpContext())
                                {
                                    formats = tempImporter.GetSupportedImportFormats();
                                }

                                string[] files = Directory.GetFiles(s);
                                foreach (var file in files)
                                {
                                    var ext = Path.GetExtension(file);
                                    if (ext == null)
                                    {
                                        continue;
                                    }
                                    var lowerExt = ext.ToLower();
                                    if (formats.Any(format => lowerExt == format))
                                    {
                                        AddTab(file);
                                    }
                                }
                                continue;
                            }
                        }
                        // ReSharper disable EmptyGeneralCatchClause
                        catch (Exception)
                        // ReSharper restore EmptyGeneralCatchClause
                        {
                            // ignore this - AddTab() handles the failure
                        }

                        // Call OpenFile asynchronously.
                        // Explorer instance from which file is dropped is not responding
                        // all the time when DragDrop handler is active, so we need to return
                        // immediately (of particular importance if OpenFile shows MessageBox).
                        AddTab(s);
                    }

                    // in the case Explorer overlaps this form
                    Activate();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error in DragDrop function: " + ex.Message);
            }
        }
Пример #3
0
        private void OnSetFileAssociations(object sender, EventArgs e)
        {
            using (var imp = new Assimp.AssimpContext())
            {
                var list = imp.GetSupportedImportFormats();

                // do not associate .xml - it is too generic 
                var filteredList = list.Where(s => s != ".xml").ToArray();           

                var listString = string.Join(", ", filteredList);
                if(DialogResult.OK == MessageBox.Show(this, "The following file extensions will be associated with open3mod: " + listString,
                    "Set file associations",
                    MessageBoxButtons.OKCancel))
                {
                    if (!FileAssociations.SetAssociations(list))
                    {
                        MessageBox.Show(this, "Failed to set file extensions","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(this, "File extensions have been successfully associated", "open3mod", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
Пример #4
0
        private void OnDrag(object sender, DragEventArgs e)
        {
            // code based on http://www.codeproject.com/Articles/3598/Drag-and-Drop
            try
            {
                var a = (Array)e.Data.GetData(DataFormats.FileDrop);

                if (a != null && a.GetLength(0) > 0)
                {
                    for (int i = 0, count = a.GetLength(0); i < count; ++i)
                    {
                        var s = a.GetValue(i).ToString();

                        // check if the dragged file is a folder. In this case,
                        // we load all applicable files in the folder.

                        // TODO this means, files with no proper file extension
                        // won't load this way.
                        try
                        {
                            FileAttributes attr = File.GetAttributes(s);
                            if (attr.HasFlag(FileAttributes.Directory))
                            {
                                string[] formats;
                                using (var tempImporter = new Assimp.AssimpContext())
                                {
                                    formats = tempImporter.GetSupportedImportFormats();
                                }

                                string[] files = Directory.GetFiles(s);
                                foreach (var file in files)
                                {
                                    var ext = Path.GetExtension(file);
                                    if (ext == null)
                                    {
                                        continue;
                                    }
                                    var lowerExt = ext.ToLower();
                                    if (formats.Any(format => lowerExt == format))
                                    {
                                        AddTab(file);
                                    }
                                }
                                continue;
                            }
                        }
                        // ReSharper disable EmptyGeneralCatchClause
                        catch (Exception)
                        // ReSharper restore EmptyGeneralCatchClause
                        {
                            // ignore this - AddTab() handles the failure
                        }

                        // Call OpenFile asynchronously.
                        // Explorer instance from which file is dropped is not responding
                        // all the time when DragDrop handler is active, so we need to return
                        // immediately (of particular importance if OpenFile shows MessageBox).
                        AddTab(s);
                    }

                    // in the case Explorer overlaps this form
                    Activate();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error in DragDrop function: " + ex.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Converts a given .GR2 file to a .dae file for rendering and further conversion.
        /// </summary>
        /// <param name="filename">The file name.</param>
        /// <returns>The .dae converted model file.</returns>
        private static HelixToolkitScene LoadFile(string filename)
        {
            var dae = $"{filename}.dae";

            if (!File.Exists(dae))
            {
                GeneralHelper.WriteToConsole($"Converting model to .dae for rendering...\n");
                var divine    = $" -g \"bg3\" --action \"convert-model\" --output-format \"dae\" --source \"\\\\?\\{filename}.GR2\" --destination \"\\\\?\\{dae}\" -l \"all\"";
                var process   = new Process();
                var startInfo = new ProcessStartInfo
                {
                    FileName               = Properties.Settings.Default.divineExe,
                    Arguments              = divine,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                };
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
                GeneralHelper.WriteToConsole(process.StandardOutput.ReadToEnd());
                GeneralHelper.WriteToConsole(process.StandardError.ReadToEnd());
            }
            try
            {
                var importer = new Importer();
                // Update material here?
                var file = importer.Load(dae);
                if (file == null && File.Exists(dae))
                {
                    GeneralHelper.WriteToConsole("Fixing vertices...\n");
                    try
                    {
                        var xml          = XDocument.Load(dae);
                        var geometryList = xml.Descendants().Where(x => x.Name.LocalName == "geometry").ToList();
                        foreach (var lod in geometryList)
                        {
                            var vertexId = lod.Descendants().Where(x => x.Name.LocalName == "vertices").Select(x => x.Attribute("id").Value).First();
                            var vertex   = lod.Descendants().Single(x => x.Name.LocalName == "input" && x.Attribute("semantic").Value == "VERTEX");
                            vertex.Attribute("source").Value = $"#{vertexId}";
                        }
                        xml.Save(dae);
                        GeneralHelper.WriteToConsole("Model conversion complete!\n");
                        file = importer.Load(dae);
                    }
                    catch (Exception ex)
                    {
                        // in use by another process
                        GeneralHelper.WriteToConsole($"Error : {ex.Message}\n");
                    }
                }

                if (!File.Exists($"{filename}.fbx"))
                {
                    var converter     = new Assimp.AssimpContext();
                    var exportFormats = converter.GetSupportedExportFormats().Select(e => e.FormatId);
                    var importFormats = converter.GetSupportedImportFormats();
                    var imported      = converter.ImportFile(dae);
                    converter.ExportFile(imported, $"{filename}.fbx", "fbx");
                }
                importer.Dispose();
                return(file);
            }
            catch (Exception ex)
            {
                GeneralHelper.WriteToConsole($"Error loading .dae: {ex.Message}. Inner exception: {ex.InnerException?.Message}\n");
            }
            return(null);
        }