/// <summary> /// Creates a surface product definition shape representation. /// </summary> /// <remarks> /// If a body representation is supplied, then we expect that this is already contained in a representation list, inside /// a product representation. As such, just modify the list and return. /// </remarks> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="exportBoundaryRep">If this is true, it will export boundary representations.</param> /// <param name="exportAsFacetation">If this is true, it will export the geometry as facetation.</param> /// <param name="bodyRep">Body representation.</param> /// <param name="boundaryRep">Boundary representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateSurfaceProductDefinitionShape(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, bool exportBoundaryRep, bool exportAsFacetation, ref IFCAnyHandle bodyRep, ref IFCAnyHandle boundaryRep) { bool hasOriginalBodyRepresentation = bodyRep != null; bool success = SurfaceExporter.ExportSurface(exporterIFC, element, geometryElement, exportBoundaryRep, exportAsFacetation, ref bodyRep, ref boundaryRep); if (!success) { return(null); } // If we supplied a body representation, then we expect that this is already contained in a representation list, inside // a product representation. As such, just modify the list and return. if (hasOriginalBodyRepresentation) { return(null); } List <IFCAnyHandle> representations = new List <IFCAnyHandle>(); representations.Add(bodyRep); if (exportBoundaryRep && !IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryRep)) { representations.Add(boundaryRep); } IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geometryElement, Transform.Identity); if (boundingBoxRep != null) { representations.Add(boundingBoxRep); } return(IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, representations)); }
public static List <BXDAMesh> ExportMeshes(RigidNode_Base baseNode, bool useOCL = false) { SurfaceExporter surfs = new SurfaceExporter(); BXDJSkeleton.SetupFileNames(baseNode, true); List <RigidNode_Base> nodes = new List <RigidNode_Base>(); baseNode.ListAllNodes(nodes); SynthesisGUI.Instance.ExporterSetMeshes(nodes.Count); List <BXDAMesh> meshes = new List <BXDAMesh>(); foreach (RigidNode_Base node in nodes) { SynthesisGUI.Instance.ExporterSetOverallText("Exporting " + node.ModelFileName); if (node is RigidNode && node.GetModel() != null && node.ModelFileName != null && node.GetModel() is CustomRigidGroup) { Console.WriteLine("Exporting " + node.ModelFileName); try { SynthesisGUI.Instance.ExporterReset(); CustomRigidGroup group = (CustomRigidGroup)node.GetModel(); surfs.Reset(node.GUID); Console.WriteLine("Exporting meshes..."); surfs.ExportAll(group, (long progress, long total) => { double totalProgress = (((double)progress / (double)total) * 100.0); SynthesisGUI.Instance.ExporterSetSubText(String.Format("Export {1} / {2}", Math.Round(totalProgress, 2), progress, total)); SynthesisGUI.Instance.ExporterSetProgress(totalProgress); }); Console.WriteLine(); BXDAMesh output = surfs.GetOutput(); Console.WriteLine("Output: " + output.meshes.Count + " meshes"); Console.WriteLine("Computing colliders..."); output.colliders.Clear(); output.colliders.AddRange(ConvexHullCalculator.GetHull(output)); meshes.Add(output); } catch (Exception e) { Console.WriteLine(e.ToString()); throw new Exception("Error exporting mesh: " + node.GetModelID()); } } SynthesisGUI.Instance.ExporterStepOverall(); } return(meshes); }
/// <summary> /// Exports the BXDF and BXDA files. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Exporter_DoWork(object sender, DoWorkEventArgs e) { if (FilePathTextBox.Text.Length == 0 || FileNameTextBox.Text.Length == 0 || FileNameTextBox.Text.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0) { e.Result = "Invalid Export Parameters."; return; } FieldDefinition fieldDefinition = new FieldDefinition(FileNameTextBox.Text); SurfaceExporter exporter = new SurfaceExporter(); ComponentOccurrencesEnumerator componentOccurrences = ((AssemblyDocument)Program.INVENTOR_APPLICATION.ActiveDocument).ComponentDefinition.Occurrences.AllLeafOccurrences; for (int i = 0; i < componentOccurrences.Count; i++) { progressWindow.Invoke(new Action(() => { progressWindow.ProcessInfoLabel.Text = "Exporting: " + (Math.Round((i / (float)componentOccurrences.Count) * 100.0f, 2)).ToString() + "%"; progressWindow.ProcessProgressBar.Value = i; })); if (componentOccurrences[i + 1].Visible) { exporter.Reset(); exporter.Export(componentOccurrences[i + 1], false, true); // Index starts at 1? BXDAMesh output = exporter.GetOutput(); FieldNode outputNode = new FieldNode(componentOccurrences[i + 1].Name, CollisionObjectsView.Nodes.Find(componentOccurrences[i + 1].Name, true).Length > 0 ? FieldNodeCollisionType.MESH : FieldNodeCollisionType.NONE); outputNode.AddSubMeshes(output); fieldDefinition.AddChild(outputNode); } } BXDFProperties.WriteProperties(FilePathTextBox.Text + "\\" + FileNameTextBox.Text + ".bxdf", fieldDefinition); fieldDefinition.CreateMesh(); fieldDefinition.GetMeshOutput().WriteToFile(FilePathTextBox.Text + "\\" + FileNameTextBox.Text + ".bxda"); FieldDefinition_Base copyDefinition = BXDFProperties.ReadProperties(FilePathTextBox.Text + "\\" + FileNameTextBox.Text + ".bxdf"); e.Result = "Export Successful!"; }
/// <summary> /// The lite equivalent of the 'Start Exporter' <see cref="Button"/> in the <see cref="ExporterForm"/>. Used in <see cref="ExporterWorker_DoWork(Object, "/> /// </summary> /// <seealso cref="ExporterWorker_DoWork"/> /// <param name="baseNode"></param> /// <returns></returns> public List <BXDAMesh> ExportMeshesLite(RigidNode_Base baseNode) { SurfaceExporter surfs = new SurfaceExporter(); BXDJSkeleton.SetupFileNames(baseNode, true); List <RigidNode_Base> nodes = new List <RigidNode_Base>(); baseNode.ListAllNodes(nodes); List <BXDAMesh> meshes = new List <BXDAMesh>(); foreach (RigidNode_Base node in nodes) { SetProgressText("Exporting " + node.ModelFileName); if (node is RigidNode && node.GetModel() != null && node.ModelFileName != null && node.GetModel() is CustomRigidGroup) { try { CustomRigidGroup group = (CustomRigidGroup)node.GetModel(); surfs.Reset(node.GUID); surfs.ExportAll(group, (long progress, long total) => { SetProgressText(String.Format("Export {0} / {1}", progress, total)); }); BXDAMesh output = surfs.GetOutput(); output.colliders.Clear(); output.colliders.AddRange(ConvexHullCalculator.GetHull(output)); meshes.Add(output); } catch (Exception e) { throw new Exception("Error exporting mesh: " + node.GetModelID(), e); } } } return(meshes); }
/// <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); } }
/// <summary> /// The lite equivalent of the 'Start Exporter' <see cref="Button"/> in the <see cref="ExporterForm"/>. Used in <see cref="ExporterWorker_DoWork(Object, "/> /// </summary> /// <seealso cref="ExporterWorker_DoWork"/> /// <param name="baseNode"></param> /// <returns></returns> public List <BXDAMesh> ExportMeshesLite(RigidNode_Base baseNode, float totalMassKg) { SurfaceExporter surfs = new SurfaceExporter(); BXDJSkeleton.SetupFileNames(baseNode); List <RigidNode_Base> nodes = new List <RigidNode_Base>(); baseNode.ListAllNodes(nodes); List <BXDAMesh> meshes = new List <BXDAMesh>(); SetProgress(0, "Exporting Model"); for (int i = 0; i < nodes.Count; i++) { RigidNode_Base node = nodes[i]; if (node is RigidNode && node.GetModel() != null && node.ModelFileName != null && node.GetModel() is CustomRigidGroup) { try { CustomRigidGroup group = (CustomRigidGroup)node.GetModel(); BXDAMesh output = surfs.ExportAll(group, node.GUID, (long progress, long total) => { SetProgress(((double)progress / total) / nodes.Count + (double)i / nodes.Count); }); output.colliders.Clear(); output.colliders.AddRange(ConvexHullCalculator.GetHull(output)); meshes.Add(output); } catch (Exception e) { throw new Exception("Error exporting mesh: " + node.GetModelID(), e); } } } // Apply custom mass to mesh if (totalMassKg > 0) // Negative value indicates that default mass should be left alone (TODO: Make default mass more accurate) { float totalDefaultMass = 0; foreach (BXDAMesh mesh in meshes) { totalDefaultMass += mesh.physics.mass; } for (int i = 0; i < meshes.Count; i++) { meshes[i].physics.mass = totalMassKg * (float)(meshes[i].physics.mass / totalDefaultMass); } } // Add meshes to all nodes for (int i = 0; i < meshes.Count; i++) { ((OGL_RigidNode)nodes[i]).loadMeshes(meshes[i]); } // Get wheel information (radius, center, etc.) for all wheels foreach (RigidNode_Base node in nodes) { SkeletalJoint_Base joint = node.GetSkeletalJoint(); // Joint will be null if the node has no connection. // cDriver will be null if there is no driver connected to the joint. if (joint != null && joint.cDriver != null) { WheelDriverMeta wheelDriver = (WheelDriverMeta)joint.cDriver.GetInfo(typeof(WheelDriverMeta)); // Drivers without wheel metadata do not need radius, center, or width info. if (wheelDriver != null) { (node as OGLViewer.OGL_RigidNode).GetWheelInfo(out float radius, out float width, out BXDVector3 center); wheelDriver.radius = radius; wheelDriver.center = center; wheelDriver.width = width; joint.cDriver.AddInfo(wheelDriver); } } } return(meshes); }