private static void SaveNudXml(string sourceDir, string outputDir, string file)
 {
     string xmlName = ModelViewport.ConvertDirSeparatorsToUnderscore(file, sourceDir);
     NUD nud = new NUD(file);
     string outputFileName = $"{ outputDir }\\{ xmlName }.xml";
     MaterialXML.ExportMaterialAsXml(nud, outputFileName);
 }
Ejemplo n.º 2
0
        private void btnOpenSandbox_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            if ((bool)ofd.ShowDialog())
            {
                var h3 = new Halo3(ofd.FileName);
                lblSandboxPath.Text = ofd.FileName;

                var container = new Model3DCollection();
                foreach (var placedObject in h3.SandboxObjects.Where(placedObject => placedObject.TagIndex != -1))
                {
                    // Try to load Model
                    if (placedObject.TagEntry.Tag.TagPath.Contains("spawning"))
                    {
                    }

                    string gameAssetPath;
                    try
                    {
                        gameAssetPath = VariousFunctions.GetGameAsset(Halo3.GameId, placedObject.TagEntry.Tag.TagPath);
                    }
                    catch (FileNotFoundException)
                    {
                        ActionLog.AddEntry("Missing Game Asset");
                        continue;
                    }

                    var model = (Model3D)ModelImporter.Load(gameAssetPath);
                    model.Transform = CreateTransformGroup(placedObject);
                    container.Add(model);
                }

                ModelViewport.Children.Clear();
                ModelViewport.Children.Add(new GridLines());
                foreach (var model in container)
                {
                    ModelViewport.Children.Add(new ModelVisual3D
                    {
                        Content = model
                    });
                }
                var light        = new LightVisual3D();
                var ambientLight = new AmbientLight(Colors.WhiteSmoke)
                {
                    Transform = new MatrixTransform3D(new Matrix3D
                    {
                        OffsetX = 0,
                        OffsetY = 0,
                        OffsetZ = 100
                    })
                };
                light.Content = ambientLight;
                ModelViewport.Children.Add(light);

                ModelViewport.ShowCameraInfo = true;
                ModelViewport.ZoomExtents();
                ModelViewport.IsHeadLightEnabled = true;
            }
        }
Ejemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();

            modelViewport = new ModelViewport
            {
                Dock = DockStyle.Fill
            };

            fileTreeContextMenu = new ContextMenu();

            iconList           = iconList = new ImageList();
            iconList.ImageSize = new Size(24, 24);

            iconList.Images.Add("unknown", Properties.Resources.ico_unknown);
            iconList.Images.Add("folder", Properties.Resources.ico_folder);
            iconList.Images.Add("model", Properties.Resources.ico_model);
            iconList.Images.Add("mesh", Properties.Resources.ico_mesh);
            iconList.Images.Add("material", Properties.Resources.ico_material);
            iconList.Images.Add("skeleton", Properties.Resources.ico_skeleton);
            iconList.Images.Add("texture", Properties.Resources.ico_texture);
            iconList.Images.Add("animation", Properties.Resources.ico_animation);

            fileTree.ImageList = iconList;

            exportAnimationToGifToolStripMenuItem.Click += ExportAnimationToGifToolStripMenuItem_Click;
        }
Ejemplo n.º 4
0
        public MainForm()
        {
            InitializeComponent();

            modelViewport = new ModelViewport
            {
                Dock = DockStyle.Fill
            };

            fileTreeContextMenu = new ContextMenu();
        }
Ejemplo n.º 5
0
        public static void OpenBfres(string file, ModelViewport viewport)
        {
            MainForm.Instance.OpenBfres(MainForm.GetUncompressedSzsSbfresData(file), file, "", viewport);

            string nameNoExtension = Path.GetFileNameWithoutExtension(file);
            string textureFileName = Path.GetDirectoryName(file) + "\\" + $"{nameNoExtension}.Tex1.sbfres";

            if (File.Exists(textureFileName))
            {
                MainForm.Instance.OpenBfres(MainForm.GetUncompressedSzsSbfresData(textureFileName), textureFileName, "", viewport);
            }
        }
Ejemplo n.º 6
0
        public static void RenderModels(ModelViewport modelViewport, TreeView fileTree)
        {
            if (!FileTools.TryOpenFolderDialog(out string folderPath, "Select Source Directory"))
            {
                return;
            }

            if (!FileTools.TryOpenFolderDialog(out string outputPath, "Select PNG Output Directory"))
            {
                return;
            }

            modelViewport.BeginBatchRenderMode();
            fileTree.BeginUpdate();

            foreach (var file in Directory.EnumerateFiles(folderPath, "*model.numdlb", SearchOption.AllDirectories))
            {
                string sourceFolder = Directory.GetParent(file).FullName;

                try
                {
                    WorkSpaceTools.LoadWorkspace(fileTree, modelViewport, sourceFolder);
                    modelViewport.RenderFrame();

                    // Save screenshot.
                    using (var bmp = modelViewport.GetScreenshot())
                    {
                        string condensedName = GetCondensedPathName(folderPath, file);
                        bmp.Save(Path.Combine(outputPath, $"{condensedName}.png"));
                    }
                }
                catch (Exception)
                {
                    continue;
                }
                finally
                {
                    WorkSpaceTools.ClearWorkspace(fileTree, modelViewport);
                }

                System.Diagnostics.Debug.WriteLine($"Rendered {sourceFolder}");
            }

            fileTree.EndUpdate();
            modelViewport.EndBatchRenderMode();
        }
Ejemplo n.º 7
0
        public static async Task ConvertAnimationToGif(ModelViewport viewport)
        {
            if (!viewport.HasAnimation)
            {
                MessageBox.Show("Please open an animation file and select an animation.", "No animation selected");
                return;
            }

            FileTools.TryOpenSaveFileDialog(out string fileName, "GIF|*.gif", "animation");

            var progressViewer = new ProgressViewer {
                Text = "Processing GIF"
            };

            progressViewer.Show();
            var progress = new Progress <int>(percent =>
                                              progressViewer.SetProgress(percent));

            await viewport.RenderAnimationToGifAsync(fileName, progress);

            progressViewer.Close();
        }
Ejemplo n.º 8
0
        public static void ExportFramesToFolder(ModelViewport viewport)
        {
            if (!viewport.HasAnimation)
            {
                MessageBox.Show("Please open an animation file and select an animation.", "No animation selected");
                return;
            }

            FileTools.TryOpenFolderDialog(out string folderPath, "animation");

            var progressViewer = new ProgressViewer {
                Text = "Processing Animation"
            };

            progressViewer.Show();
            var progress = new Progress <int>(percent =>
                                              progressViewer.SetProgress(percent));

            viewport.RenderAnimationToFolder(folderPath);

            progressViewer.Close();
        }
Ejemplo n.º 9
0
        private static void AssignNodesAndSelectNumdlb(TreeView fileTree, ModelViewport modelViewport, DirectoryNode mainNode)
        {
            // Enable rendering of the model if we have directly selected a model file.
            // Nested ones won't render a model
            fileTree.Nodes.Add(mainNode);
            SkelNode skelNode = null;

            foreach (FileNode node in mainNode.Nodes)
            {
                if (node.Text.EndsWith("numdlb"))
                {
                    fileTree.SelectedNode = node;
                    modelViewport.HideExpressionMeshes();
                }
                else if (skelNode == null && node is SkelNode)
                {
                    skelNode = node as SkelNode;
                }
            }

            if (skelNode == null)
            {
                return;
            }
            foreach (FileNode node in mainNode.Nodes)
            {
                if (node is ScriptNode scriptNode)
                {
                    scriptNode.SkelNode      = skelNode;
                    modelViewport.ScriptNode = scriptNode;
                    //only do this once, there should only be one anyway
                    break;
                }
            }

            ParamNodeContainer.SkelNode = skelNode;
        }
Ejemplo n.º 10
0
 public static void ClearWorkspace(TreeView fileTree, ModelViewport viewport)
 {
     fileTree.Nodes.Clear();
     ParamNodeContainer.Unload();
     viewport.ClearFiles();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Loads a directory and all sub-directories into the filetree.
        /// </summary>
        /// <param name="fileTree"></param>
        /// <param name="modelViewport"></param>
        /// <param name="folderPath"></param>
        public static void LoadWorkspace(TreeView fileTree, ModelViewport modelViewport, string folderPath)
        {
            var mainNode = CreateDirectoryNodeAndOpenSubNodes(folderPath);

            AssignNodesAndSelectNumdlb(fileTree, modelViewport, mainNode);
        }
Ejemplo n.º 12
0
 public static void OpenNud(string file, ModelViewport viewport)
 {
     MainForm.Instance.OpenNud(file, "", viewport);
 }
Ejemplo n.º 13
0
 public static void OpenMeleeDat(string file, ModelViewport viewport)
 {
     byte[] data = File.ReadAllBytes(file);
     MainForm.Instance.OpenMeleeDat(data, file, "", viewport);
 }