/// <summary> /// Returns the TabPage in which the given node is located. /// </summary> /// <param name="key"></param> /// <returns>The TabPage (if it exists, otherwise null)</returns> public ComponentPropertiesTabPage GetParentTabPage(string key) { foreach (TabPage t in TabPages) { if (t is ComponentPropertiesTabPage) { ComponentPropertiesTabPage tabPage = (ComponentPropertiesTabPage)t; if (tabPage.ChildForm.inventorTreeView.Nodes.Find(key, true).Length > 0) { return(tabPage); } } } return(null); }
/// <summary> /// Creates tabs from a list of property sets. /// </summary> /// <param name="propertySets">Property sets to base tabs off of.</param> public void ApplyPropertySets(List <PropertySet> propertySets) { var tmp = Handle; // Forces creation of window handle so that tabs will appear foreach (PropertySet p in propertySets) { ComponentPropertiesTabPage newPage = new ComponentPropertiesTabPage(this, p.PropertySetID); newPage.ChildForm.Collider = p.Collider; newPage.ChildForm.Friction = p.Friction; newPage.ChildForm.Mass = p.Mass; TabPages.Insert(TabPages.Count - 1, newPage); } SelectedTab = TabPages[0]; }
/// <summary> /// Scans each nonexcluded InventorTreeView and determines if they contian the supplied key. /// </summary> /// <param name="key"></param> /// <param name="excludedPages"></param> /// <returns></returns> public bool NodeExists(string key, params ComponentPropertiesTabPage[] excludedPages) { foreach (TabPage t in TabPages) { if (t is ComponentPropertiesTabPage) { ComponentPropertiesTabPage tabPage = (ComponentPropertiesTabPage)t; if (!excludedPages.Contains <ComponentPropertiesTabPage>(tabPage)) { if (tabPage.ChildForm.inventorTreeView.Nodes.Find(key, true).Length > 0) { return(true); } } } } return(false); }
/// <summary> /// Scans each nonexcluded InventorTreeView and removes nodes with the supplied key. /// </summary> /// <param name="key"></param> /// <param name="excludedPages"></param> public void RemoveNode(string key, params ComponentPropertiesTabPage[] excludedPages) { foreach (TabPage t in TabPages) { if (t is ComponentPropertiesTabPage) { ComponentPropertiesTabPage tabPage = (ComponentPropertiesTabPage)t; if (!excludedPages.Contains <ComponentPropertiesTabPage>(tabPage)) { TreeNode[] nodeCollection = tabPage.ChildForm.inventorTreeView.Nodes.Find(key, true); for (int i = 0; i < nodeCollection.Length; i++) { nodeCollection[i].Remove(); } } } } }
/// <summary> /// Translates the information in each ComponentPropertiesTabPage to a List of PhysicsGroups. /// </summary> /// <returns>The translation</returns> public List <PropertySet> TranslateToPropertySets() { List <PropertySet> translation = new List <PropertySet>(); foreach (TabPage t in TabPages) { if (t is ComponentPropertiesTabPage) { ComponentPropertiesTabPage tabPage = (ComponentPropertiesTabPage)t; tabPage.Invoke(new Action(() => { translation.Add(new PropertySet( tabPage.Name, tabPage.ChildForm.GetCollider(), tabPage.ChildForm.GetFriction(), tabPage.ChildForm.GetMass())); })); } } return(translation); }
/// <summary> /// Adds a ComponentPropertiesTab if the EnterNameDialog returns OK and the name isn't already taken. /// </summary> /// <returns>true if OK is pressed</returns> public bool AddComponentPropertiesTab() { EnterNameDialog nameDialog = new EnterNameDialog(); if (nameDialog.ShowDialog(this).Equals(DialogResult.OK)) { if (TabPages.ContainsKey(nameDialog.nameTextBox.Text)) { MessageBox.Show("Name is already taken.", "Invalid name."); return(false); } else { ComponentPropertiesTabPage page = new ComponentPropertiesTabPage(this, nameDialog.nameTextBox.Text); TabPages.Insert(TabPages.Count - 1, page); SelectedTab = page; return(true); } } else { return(false); } }
/// <summary> /// Translates the information in each ComponentPropertiesTabPage to a List of PhysicsGroups. /// </summary> /// <returns>The translation</returns> public Exporter.Gamepiece[] TranslateToGamepieces() { List <Exporter.Gamepiece> translation = new List <Exporter.Gamepiece>(); foreach (TabPage t in TabPages) { if (t is ComponentPropertiesTabPage) { ComponentPropertiesTabPage tabPage = (ComponentPropertiesTabPage)t; tabPage.Invoke(new Action(() => { Exporter.Gamepiece gp = tabPage.ChildForm.Gamepiece; if (gp != null) { translation.Add(gp); } })); } } return(translation.ToArray()); }
/// <summary> /// Executes the actual exporting. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exporter_DoWork(object sender, DoWorkEventArgs e) { FieldDefinition fieldDefinition = FieldDefinition.Factory(Guid.NewGuid(), Program.ASSEMBLY_DOCUMENT.DisplayName); foreach (PropertySet ps in Program.MAINWINDOW.GetPropertySetsTabControl().TranslateToPropertySets()) { fieldDefinition.AddPropertySet(ps); } SurfaceExporter surfaceExporter = new SurfaceExporter(); List <string> exportedMeshes = new List <string>(); List <string> exportedColliders = new List <string>(); StringBuilder pathBuilder = new StringBuilder(); int numOccurrences = Program.ASSEMBLY_DOCUMENT.ComponentDefinition.Occurrences.AllLeafOccurrences.Count; int progressPercent = 0; int currentOccurrenceID = 0; foreach (ComponentOccurrence currentOccurrence in Program.ASSEMBLY_DOCUMENT.ComponentDefinition.Occurrences.AllLeafOccurrences) { if (exporter.CancellationPending) { e.Cancel = true; return; } progressPercent = (int)Math.Floor((currentOccurrenceID / (double)numOccurrences) * 100.0); exporter.ReportProgress(progressPercent, "Exporting... " + progressPercent + "%"); if (currentOccurrence.Visible && currentOccurrence.ReferencedDocumentDescriptor != null && currentOccurrence.ReferencedDocumentDescriptor.ReferencedDocumentType == DocumentTypeEnum.kPartDocumentObject && currentOccurrence.SurfaceBodies.Count > 0) { FieldNode outputNode = new FieldNode(currentOccurrence.Name); outputNode.Position = Utilities.ToBXDVector(currentOccurrence.Transformation.Translation); outputNode.Rotation = Utilities.QuaternionFromMatrix(currentOccurrence.Transformation); if (!exportedMeshes.Contains(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName)) { surfaceExporter.Reset(); surfaceExporter.Export(((PartDocument)currentOccurrence.ReferencedDocumentDescriptor.ReferencedDocument).ComponentDefinition, false, true); BXDAMesh.BXDASubMesh outputMesh = surfaceExporter.GetOutput().meshes.First(); exportedMeshes.Add(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); fieldDefinition.AddSubMesh(outputMesh); } outputNode.SubMeshID = exportedMeshes.IndexOf(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); ComponentPropertiesTabPage componentProperties = Program.MAINWINDOW.GetPropertySetsTabControl().GetParentTabPage(currentOccurrence.Name); if (componentProperties != null) { outputNode.PropertySetID = componentProperties.Name; PropertySet propertySet = fieldDefinition.GetPropertySets()[outputNode.PropertySetID]; if (propertySet.Collider.CollisionType == PropertySet.PropertySetCollider.PropertySetCollisionType.MESH && ((PropertySet.MeshCollider)propertySet.Collider).Convex) { if (!exportedColliders.Contains(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName)) { exportedColliders.Add(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); fieldDefinition.AddCollisionMesh(ConvexHullCalculator.GetHull(fieldDefinition.GetSubMesh(outputNode.SubMeshID))); } outputNode.CollisionMeshID = exportedColliders.IndexOf(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); } } pathBuilder.Clear(); foreach (ComponentOccurrence co in currentOccurrence.OccurrencePath) { pathBuilder.Append(co.Name + "/"); } pathBuilder.Length--; fieldDefinition.NodeGroup[pathBuilder.ToString()] = outputNode; } currentOccurrenceID++; } exporter.ReportProgress(100, "Export Successful!"); fieldDefinition.GetMeshOutput().WriteToFile(filePathTextBox.Text + "\\mesh.bxda"); BXDFProperties.WriteProperties(filePathTextBox.Text + "\\definition.bxdf", fieldDefinition); // Use the commented code below for debugging. /** / * string result; * FieldDefinition readDefinition = BXDFProperties.ReadProperties(filePathTextBox.Text + "\\definition.bxdf", out result); * MessageBox.Show(result); * /**/ }
/// <summary> /// Executes the actual exporting. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exporter_DoWork(object sender, DoWorkEventArgs e) { string directory = FIELD_FOLDER + fieldNameTextBox.Text; // Create directory if it does not exist if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // Warn user of overwrite if it does exist else if (MessageBox.Show("A field with this name already exists. Continue?", "Overwrite Existing Field", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { e.Cancel = true; return; } FieldDefinition fieldDefinition = FieldDefinition.Factory(Guid.NewGuid(), Program.ASSEMBLY_DOCUMENT.DisplayName); foreach (PropertySet ps in Program.MAINWINDOW.GetPropertySetsTabControl().TranslateToPropertySets()) { fieldDefinition.AddPropertySet(ps); } SurfaceExporter surfaceExporter = new SurfaceExporter(); List <string> exportedMeshes = new List <string>(); List <string> exportedColliders = new List <string>(); StringBuilder pathBuilder = new StringBuilder(); int numOccurrences = Program.ASSEMBLY_DOCUMENT.ComponentDefinition.Occurrences.AllLeafOccurrences.Count; int progressPercent = 0; int currentOccurrenceID = 0; foreach (ComponentOccurrence currentOccurrence in Program.ASSEMBLY_DOCUMENT.ComponentDefinition.Occurrences.AllLeafOccurrences) { if (exporter.CancellationPending) { e.Cancel = true; return; } progressPercent = (int)Math.Floor((currentOccurrenceID / (double)numOccurrences) * 100.0); exporter.ReportProgress(progressPercent, "Exporting... " + progressPercent + "%"); if (currentOccurrence.Visible && currentOccurrence.ReferencedDocumentDescriptor != null && currentOccurrence.ReferencedDocumentDescriptor.ReferencedDocumentType == DocumentTypeEnum.kPartDocumentObject && currentOccurrence.SurfaceBodies.Count > 0) { FieldNode outputNode = new FieldNode(currentOccurrence.Name); outputNode.Position = Utilities.ToBXDVector(currentOccurrence.Transformation.Translation); outputNode.Rotation = Utilities.QuaternionFromMatrix(currentOccurrence.Transformation); if (!exportedMeshes.Contains(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName)) { surfaceExporter.Reset(); surfaceExporter.Export(((PartDocument)currentOccurrence.ReferencedDocumentDescriptor.ReferencedDocument).ComponentDefinition, false, true); BXDAMesh.BXDASubMesh outputMesh = surfaceExporter.GetOutput().meshes.First(); exportedMeshes.Add(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); fieldDefinition.AddSubMesh(outputMesh); } outputNode.SubMeshID = exportedMeshes.IndexOf(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); ComponentPropertiesTabPage componentProperties = Program.MAINWINDOW.GetPropertySetsTabControl().GetParentTabPage(currentOccurrence.Name); if (componentProperties != null) { outputNode.PropertySetID = componentProperties.Name; PropertySet propertySet = fieldDefinition.GetPropertySets()[outputNode.PropertySetID]; if (propertySet.Collider.CollisionType == PropertySet.PropertySetCollider.PropertySetCollisionType.MESH && ((PropertySet.MeshCollider)propertySet.Collider).Convex) { if (!exportedColliders.Contains(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName)) { exportedColliders.Add(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); var test = fieldDefinition.GetSubMesh(outputNode.SubMeshID); fieldDefinition.AddCollisionMesh(ConvexHullCalculator.GetHull(fieldDefinition.GetSubMesh(outputNode.SubMeshID))); } outputNode.CollisionMeshID = exportedColliders.IndexOf(currentOccurrence.ReferencedDocumentDescriptor.FullDocumentName); } } pathBuilder.Clear(); foreach (ComponentOccurrence co in currentOccurrence.OccurrencePath) { pathBuilder.Append(co.Name + "/"); } pathBuilder.Length--; fieldDefinition.NodeGroup[pathBuilder.ToString()] = outputNode; } currentOccurrenceID++; } exporter.ReportProgress(100, "Export Successful!"); fieldDefinition.GetMeshOutput().WriteToFile(directory + "\\mesh.bxda"); // Field data such as spawnpoints and gamepieces ExportFieldData(directory); // Property sets BXDFProperties.WriteProperties(directory + "\\definition.bxdf", fieldDefinition); // Open the export directory when done if (openFolderCheckBox.Checked) { Process.Start("explorer.exe", "/select, " + directory); } }