AddTab() public méthode

Open a new tab given a scene file to load. If the specified scene is already open in a tab, the existing tab is selected in the UI (if requested) and no tab is added.
public AddTab ( string file, bool async = true, bool setActive = true ) : void
file string Source file
async bool Specifies whether the data is loaded asynchr.
setActive bool Specifies whether the newly added tab will /// be selected when the loading process is complete.
Résultat void
Exemple #1
0
        static void Main(string[] args)
        {
            MainWindow mainWindow = null;
            RunOnceGuard.Guard("open3mod_global_app",

                    // what to do if this is the first instance of the application
                    () =>
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);

                        mainWindow = new MainWindow();
                        if (args.Length > 0)
                        {
                            mainWindow.AddTab(args[0]);
                        }
                        Application.Run(mainWindow);
                        mainWindow = null;

                        TextureQueue.Terminate();
                    },

                    // what do invoke if this is the first instance of the application,
                    // and another (temporary) instance messages it to open a new tab
                    (String absPath) =>
                    {
                        if (mainWindow != null)
                        {
                            mainWindow.BeginInvoke(new MethodInvoker(() =>
                            {
                                mainWindow.Activate();
                                mainWindow.AddTab(absPath);
                            }));                        
                        }
                    },

                    // what to send to the first instance of the application if the
                    // current instance is only temporary.
                    () =>
                    {
                        if(args.Length == 0)
                        {
                            return null;
                        }
                        // note: have to get absolute path because the working dirs
                        // of the instances may be different.
                        return Path.GetFullPath(args[0]);
                    }
                );

            
        }
Exemple #2
0
        static void Main(string[] args)
        {
            MainWindow mainWindow = null;

            RunOnceGuard.Guard("open3mod_global_app",

                               // what to do if this is the first instance of the application
                               () =>
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                mainWindow = new MainWindow();
                if (args.Length > 0)
                {
                    mainWindow.AddTab(args[0]);
                }
                Application.Run(mainWindow);
                mainWindow = null;

                TextureQueue.Terminate();
            },

                               // what do invoke if this is the first instance of the application,
                               // and another (temporary) instance messages it to open a new tab
                               (String absPath) =>
            {
                if (mainWindow != null)
                {
                    mainWindow.BeginInvoke(new MethodInvoker(() =>
                    {
                        mainWindow.Activate();
                        mainWindow.AddTab(absPath);
                    }));
                }
            },

                               // what to send to the first instance of the application if the
                               // current instance is only temporary.
                               () =>
            {
                if (args.Length == 0)
                {
                    return(null);
                }
                // note: have to get absolute path because the working dirs
                // of the instances may be different.
                return(Path.GetFullPath(args[0]));
            }
                               );
        }
Exemple #3
0
        private void DoExport(Scene scene, string id)
        {
            var overwriteWithoutConfirmation = checkBoxNoOverwriteConfirm.Checked;

            var path = textBoxPath.Text.Trim();

            path = (path.Length > 0 ? path : scene.BaseDir);
            var name     = textBoxFileName.Text.Trim();
            var fullPath = Path.Combine(path, name);

            if (!overwriteWithoutConfirmation && Path.GetFullPath(fullPath) == Path.GetFullPath(scene.File))
            {
                if (MessageBox.Show("This will overwrite the current scene's source file. Continue?", "Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    PushLog("Canceled");
                    return;
                }
            }

            var copyTextures          = checkBoxCopyTexturesToSubfolder.Checked;
            var relativeTexturePaths  = checkBoxUseRelativeTexturePaths.Checked;
            var includeAnimations     = checkBoxIncludeAnimations.Checked;
            var includeSceneHierarchy = checkBoxIncludeSceneHierarchy.Checked;

            var textureCopyJobs          = new Dictionary <string, string>();
            var textureDestinationFolder = textBoxCopyTexturesToFolder.Text;

            PushLog("*** Export: " + scene.File);

            if (copyTextures)
            {
                try
                {
                    Directory.CreateDirectory(Path.Combine(path, textureDestinationFolder));
                }
                catch (Exception)
                {
                    PushLog("Failed to create texture destination directory " + Path.Combine(path, textureDestinationFolder));
                    return;
                }
            }

            progressBarExport.Style = ProgressBarStyle.Marquee;
            progressBarExport.MarqueeAnimationSpeed = 5;

            // Create a shallow copy of the original scene that replaces all the texture paths with their
            // corresponding output paths, and omits animations if requested.
            var sourceScene = new Assimp.Scene {
            };

            sourceScene.Textures.AddRange(scene.Raw.Textures);
            sourceScene.SceneFlags = scene.Raw.SceneFlags;
            sourceScene.RootNode   = scene.Raw.RootNode;
            sourceScene.Meshes.AddRange(scene.Raw.Meshes);
            sourceScene.Lights.AddRange(scene.Raw.Lights);
            sourceScene.Cameras.AddRange(scene.Raw.Cameras);

            if (includeAnimations)
            {
                sourceScene.Animations.AddRange(scene.Raw.Animations);
            }

            var uniques        = new HashSet <string>();
            var textureMapping = new Dictionary <string, string>();

            PushLog("Locating all textures");
            foreach (var texId in scene.TextureSet.GetTextureIds())
            {
                // TODO(acgessler): Verify if this handles texture replacements and GUID-IDs correctly.
                var destName = texId;

                // Broadly skip over embedded (in-memory) textures
                if (destName.StartsWith("*"))
                {
                    PushLog("Ignoring embedded texture: " + destName);
                    continue;
                }

                // Locate the texture on-disk
                string diskLocation;
                try
                {
                    TextureLoader.ObtainStream(texId, scene.BaseDir, out diskLocation).Close();
                } catch (IOException)
                {
                    PushLog("Failed to locate texture " + texId);
                    continue;
                }

                if (copyTextures)
                {
                    destName = GeUniqueTextureExportPath(path, textureDestinationFolder, diskLocation, uniques);
                }

                if (relativeTexturePaths)
                {
                    textureMapping[texId] = GetRelativePath(path + "\\", destName);
                }
                else
                {
                    textureMapping[texId] = destName;
                }
                textureCopyJobs[diskLocation] = destName;

                PushLog("Texture " + texId + " maps to " + textureMapping[texId]);
            }

            foreach (var mat in scene.Raw.Materials)
            {
                sourceScene.Materials.Add(CloneMaterial(mat, textureMapping));
            }

            var t = new Thread(() =>
            {
                using (var v = new AssimpContext())
                {
                    PushLog("Exporting using Assimp to " + fullPath + ", using format id: " + id);
                    var result = v.ExportFile(sourceScene, fullPath, id, includeSceneHierarchy
                        ? PostProcessSteps.None
                        : PostProcessSteps.PreTransformVertices);
                    _main.BeginInvoke(new MethodInvoker(() =>
                    {
                        progressBarExport.Style = ProgressBarStyle.Continuous;
                        progressBarExport.MarqueeAnimationSpeed = 0;

                        if (!result)
                        {
                            // TODO: get native error message
                            PushLog("Export failure");
                            MessageBox.Show("Failed to export to " + fullPath, "Export error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            if (copyTextures)
                            {
                                PushLog("Copying textures");
                                foreach (var kv in textureCopyJobs)
                                {
                                    PushLog(" ... " + kv.Key + " -> " + kv.Value);
                                    try
                                    {
                                        File.Copy(kv.Key, kv.Value, false);
                                    }
                                    catch (IOException)
                                    {
                                        if (!File.Exists(kv.Value))
                                        {
                                            throw;
                                        }
                                        if (!overwriteWithoutConfirmation && MessageBox.Show("Texture " + kv.Value +
                                                                                             " already exists. Overwrite?", "Overwrite Warning",
                                                                                             MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                        {
                                            PushLog("Exists already, skipping");
                                            continue;
                                        }
                                        PushLog("Exists already, overwriting");
                                        File.Copy(kv.Key, kv.Value, true);
                                    }
                                    catch (Exception ex)
                                    {
                                        PushLog(ex.Message);
                                    }
                                }
                            }
                            if (checkBoxOpenExportedFile.Checked)
                            {
                                _main.AddTab(fullPath, true, false);
                            }
                            PushLog("Export completed");
                        }
                    }));
                }
            });

            t.Start();
        }