/// <summary> /// Grabs the joints and groups from the Inventor results, /// </summary> /// <param name="results"></param> public CustomRigidResults(RigidBodyResults results) { Console.WriteLine("Building custom dataset"); groups = new List <CustomRigidGroup>(results.RigidBodyGroups.Count); joints = new List <CustomRigidJoint>(results.RigidBodyJoints.Count); foreach (RigidBodyGroup group in results.RigidBodyGroups) { CustomRigidGroup tmp = new CustomRigidGroup(group); if ((!(groupIDToCustom.ContainsKey(tmp.fullQualifier)))) { groups.Add(tmp); groupIDToCustom.Add(tmp.fullQualifier, tmp); } else { Console.WriteLine("GroupID Collision: " + groupIDToCustom[CustomRigidGroup.GetGroupQualifier(group)].ToString() + " and " + tmp.ToString()); } Console.Write("Group " + groups.Count + "/" + results.RigidBodyGroups.Count + "\tJoint " + joints.Count + "/" + results.RigidBodyJoints.Count); } foreach (RigidBodyJoint joint in results.RigidBodyJoints) { joints.Add(new CustomRigidJoint(joint, groupIDToCustom[CustomRigidGroup.GetGroupQualifier(joint.GroupOne)], groupIDToCustom[CustomRigidGroup.GetGroupQualifier(joint.GroupTwo)])); Console.Write("Group " + groups.Count + "/" + results.RigidBodyGroups.Count + "\tJoint " + joints.Count + "/" + results.RigidBodyJoints.Count); } Console.WriteLine(); Console.WriteLine("Built custom dataset"); RigidBodyCleaner.CleanMeaningless(this); }
/// <summary> /// The lightweight equivalent of the 'Add From Inventor' button in the <see cref="ExporterForm"/>. Used in <see cref="ExportMeshesLite(RigidNode_Base)"/> /// </summary> /// <param name="occurrences"></param> /// <returns></returns> public RigidNode_Base ExportSkeleteonLite(List <ComponentOccurrence> occurrences) { if (occurrences.Count == 0) { throw new ArgumentException("ERROR: 0 Occurrences passed to ExportSkeletonLite", "occurrences"); } #region CenterJoints int NumCentered = 0; SetProgressText(string.Format("Centering Joints {0} / {1}", NumCentered, occurrences.Count)); foreach (ComponentOccurrence component in occurrences) { Exporter.CenterAllJoints(component); NumCentered++; SetProgressText(string.Format("Centering Joints {0} / {1}", NumCentered, occurrences.Count)); } #endregion #region Build Models //Getting Rigid Body Info... SetProgressText("Getting Rigid Body Info...", ProgressTextType.ShortTaskBegin); NameValueMap RigidGetOptions = InventorManager.Instance.TransientObjects.CreateNameValueMap(); RigidGetOptions.Add("DoubleBearing", false); RigidBodyResults RawRigidResults = InventorManager.Instance.AssemblyDocument.ComponentDefinition.RigidBodyAnalysis(RigidGetOptions); //Getting Rigid Body Info...Done SetProgressText(null, ProgressTextType.ShortTaskEnd); CustomRigidResults RigidResults = new CustomRigidResults(RawRigidResults); //Building Model... SetProgressText("Building Model...", ProgressTextType.ShortTaskBegin); RigidBodyCleaner.CleanGroundedBodies(RigidResults); RigidNode baseNode = RigidBodyCleaner.BuildAndCleanDijkstra(RigidResults); //Building Model...Done SetProgressText(null, ProgressTextType.ShortTaskEnd); #endregion #region Cleaning Up //Cleaning Up... LiteExporterForm.Instance.SetProgressText("Cleaning Up...", ProgressTextType.ShortTaskBegin); List <RigidNode_Base> nodes = new List <RigidNode_Base>(); baseNode.ListAllNodes(nodes); foreach (RigidNode_Base node in nodes) { node.ModelFileName = ((RigidNode)node).group.ToString(); node.ModelFullID = node.GetModelID(); } //Cleaning Up...Done LiteExporterForm.Instance.SetProgressText(null, ProgressTextType.ShortTaskEnd); #endregion return(baseNode); }
public byte[] readJoints() { try { List <byte> jointBytes = new List <byte>(); NameValueMap nameMap = currentApplication.TransientObjects.CreateNameValueMap(); nameMap.Add("DoubleBearing", false); RigidBodyResults jointsContainer = currentDocument.ComponentDefinition.RigidBodyAnalysis(nameMap); RigidBodyJoints jointList = jointsContainer.RigidBodyJoints; JointData jointDataObject = null; foreach (RigidBodyJoint joint in jointList) { foreach (AssemblyJoint assemblyJoint in joint.Joints) { foreach (byte byteID in BitConverter.GetBytes(0003)) { jointBytes.Add(byteID); } foreach (JointData jointData in jointDataList) { if (jointData.jointOfType.OccurrenceOne.Name.Equals(assemblyJoint.OccurrenceOne.Name) && jointData.jointOfType.OccurrenceTwo.Name.Equals(assemblyJoint.OccurrenceTwo.Name)) { jointDataObject = jointData; } } if (joint.JointType.Equals("kSlideJointType")) { foreach (byte byteJID in BitConverter.GetBytes((ushort)0000)) { jointBytes.Add(byteJID); } foreach (byte jointSection in ProcessLinearJoint(joint, jointDataObject)) { jointBytes.Add(jointSection); } } if (joint.JointType.Equals("kRotationalJointType")) { foreach (byte byteJID in BitConverter.GetBytes((ushort)0001)) { jointBytes.Add(byteJID); } foreach (byte jointSection in ProcessRotationalJoint(joint, jointDataObject)) { jointBytes.Add(jointSection); } } } } return(jointBytes.ToArray()); } catch (Exception e) { //catches problems MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace); return(null); } }
public static RigidNode_Base ExportSkeleton(List <ComponentOccurrence> occurrences) { if (occurrences.Count == 0) { throw new Exception("No components selected!"); } SynthesisGUI.Instance.ExporterSetOverallText("Centering joints"); SynthesisGUI.Instance.ExporterReset(); SynthesisGUI.Instance.ExporterSetSubText("Centering 0 / 0"); SynthesisGUI.Instance.ExporterSetProgress(0); SynthesisGUI.Instance.ExporterSetMeshes(2); int numOccurrences = occurrences.Count; SynthesisGUI.Instance.ExporterStepOverall(); SynthesisGUI.Instance.ExporterSetOverallText("Getting rigid info"); Console.WriteLine("Get rigid info..."); //Group components into rigid bodies. NameValueMap options = InventorManager.Instance.TransientObjects.CreateNameValueMap(); options.Add("DoubleBearing", false); RigidBodyResults rigidResults = InventorManager.Instance.AssemblyDocument.ComponentDefinition.RigidBodyAnalysis(options); Console.WriteLine("Got rigid info..."); CustomRigidResults customRigid = new CustomRigidResults(rigidResults); Console.WriteLine("Build model..."); RigidBodyCleaner.CleanGroundedBodies(customRigid); //After this point, all grounded groups have been merged into one CustomRigidGroup, and their joints have been updated. RigidNode baseNode = RigidBodyCleaner.BuildAndCleanDijkstra(customRigid); Console.WriteLine("Built"); Console.WriteLine(baseNode.ToString()); SynthesisGUI.Instance.ExporterStepOverall(); List <RigidNode_Base> nodes = new List <RigidNode_Base>(); baseNode.ListAllNodes(nodes); foreach (RigidNode_Base node in nodes) { node.ModelFileName = ((RigidNode)node).group.ToString(); node.ModelFullID = node.GetModelID(); } return(baseNode); }
public byte[] ReadJoints() { try { List <byte> jointBytes = new List <byte>(); NameValueMap nameMap = currentApplication.TransientObjects.CreateNameValueMap(); nameMap.Add("DoubleBearing", false); RigidBodyResults jointsContainer = currentDocument.ComponentDefinition.RigidBodyAnalysis(nameMap); RigidBodyJoints jointList = jointsContainer.RigidBodyJoints; foreach (RigidBodyJoint rigidJoint in jointList) { foreach (AssemblyJoint assemblyJoint in rigidJoint.Joints) { if (assemblyJoint.Definition.JointType.ToString().Equals("kSlideJoint")) { jointBytes.AddRange(ProcessLinearJoint(rigidJoint)); } if (assemblyJoint.Definition.JointType.ToString().Equals("kRotationalJointType")) { jointBytes.AddRange(ProcessRotationalJoint(rigidJoint)); } if (assemblyJoint.Definition.JointType.ToString().Equals("kCylindricalJointType")) { jointBytes.AddRange(ProcessCylindricalJoint(rigidJoint)); } if (assemblyJoint.Definition.JointType.ToString().Equals("kPlanarJointType")) { jointBytes.AddRange(ProcessPlanarJoint(rigidJoint)); } if (assemblyJoint.Definition.JointType.ToString().Equals("kBallJointType")) { jointBytes.AddRange(ProcessBallJoint(rigidJoint)); } } } //Adds ID of joint section and the size of the section if there are joints in the model, to avoid excess data in the file. if (jointBytes.Count > 0) { jointBytes.AddRange(BitConverter.GetBytes(0003)); jointBytes.InsertRange(4, BitConverter.GetBytes(jointBytes.Count - 4)); } return(jointBytes.ToArray()); } catch (Exception e) { //catches problems MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace); return(null); } }
/// <summary> /// The lightweight equivalent of the 'Add From Inventor' button in the <see cref="ExporterForm"/>. Used in <see cref="ExportMeshesLite(RigidNode_Base)"/> /// </summary> /// <param name="occurrences"></param> /// <returns></returns> public RigidNode_Base ExportSkeleton(List <ComponentOccurrence> occurrences) { if (occurrences.Count == 0) { throw new Exporter.EmptyAssemblyException(); } #region Build Models //Getting Rigid Body Info... SetProgress("Getting physics info...", occurrences.Count, occurrences.Count + 3); NameValueMap RigidGetOptions = InventorManager.Instance.TransientObjects.CreateNameValueMap(); RigidGetOptions.Add("DoubleBearing", false); RigidBodyResults RawRigidResults = InventorManager.Instance.AssemblyDocument.ComponentDefinition.RigidBodyAnalysis(RigidGetOptions); //Getting Rigid Body Info...Done CustomRigidResults RigidResults = new CustomRigidResults(RawRigidResults); //Building Model... SetProgress("Building model...", occurrences.Count + 1, occurrences.Count + 3); RigidBodyCleaner.CleanGroundedBodies(RigidResults); RigidNode baseNode = RigidBodyCleaner.BuildAndCleanDijkstra(RigidResults); //Building Model...Done #endregion #region Cleaning Up //Cleaning Up... SetProgress("Cleaning up...", occurrences.Count + 2, occurrences.Count + 3); List <RigidNode_Base> nodes = new List <RigidNode_Base>(); baseNode.ListAllNodes(nodes); foreach (RigidNode_Base node in nodes) { node.ModelFileName = ((RigidNode)node).group.ToString(); node.ModelFullID = node.GetModelID(); } //Cleaning Up...Done #endregion SetProgress("Done", occurrences.Count + 3, occurrences.Count + 3); return(baseNode); }