@@ -14,6 +14,9 @@ namespace ZO.ImportExport {
1414
1515
1616 public class ZOExportURDF {
17+ public XDocument XML {
18+ get ; set ;
19+ } = new XDocument ( ) ;
1720
1821 protected readonly struct URDFJoint {
1922 public URDFJoint ( ZOSimOccurrence child , ZOSimOccurrence parent , Vector3 anchor , Vector3 connectedAnchor ) {
@@ -56,7 +59,24 @@ public Vector3 ConnectedAnchor {
5659 /// <param name="robot">The robot XML document</param>
5760 /// <param name="simOccurrence">The root `ZOSimOccurence`</param>
5861 /// <param name="baseTransform">The base relative transform, usually the transform of the `ZODocumentRoot`</param>
59- public void BuildURDF ( XElement robot , ZOSimOccurrence simOccurrence , Matrix4x4 baseTransform ) {
62+ public XDocument BuildURDF ( ZOSimDocumentRoot documentRoot ) {
63+
64+ // create root document and robot element
65+ XElement robot = new XElement ( "robot" ) ;
66+ robot . SetAttributeValue ( "name" , documentRoot . Name ) ;
67+ XML = new XDocument ( robot ) ;
68+
69+ // go through the ZOSimOccurrences and convert into URDF Links and Joints
70+ ZOSimOccurrence simOccurrence = null ;
71+ foreach ( Transform child in documentRoot . transform ) { // BUG: Should only ever be one base object for URDF!!!
72+ simOccurrence = child . GetComponent < ZOSimOccurrence > ( ) ;
73+ if ( simOccurrence ) {
74+ break ; // BUG: stops at first sim occurrence
75+ }
76+ }
77+
78+ Matrix4x4 baseTransform = documentRoot . transform . WorldTranslationRotationMatrix ( ) ;
79+
6080
6181 List < URDFJoint > joints = new List < URDFJoint > ( ) ;
6282
@@ -66,7 +86,7 @@ public void BuildURDF(XElement robot, ZOSimOccurrence simOccurrence, Matrix4x4 b
6686 // build links
6787 HashSet < ZOSimOccurrence > links = new HashSet < ZOSimOccurrence > ( ) ;
6888 foreach ( URDFJoint joint in joints ) {
69-
89+
7090 if ( links . Contains ( joint . Parent ) == false ) { // build parent link if not exist
7191 Vector3 offset = - 1.0f * joint . ConnectedAnchor ;
7292 if ( joints [ 0 ] == joint ) { // if base joint do not apply any offset to parent link
@@ -105,6 +125,8 @@ public void BuildURDF(XElement robot, ZOSimOccurrence simOccurrence, Matrix4x4 b
105125
106126 }
107127
128+ return XML ;
129+
108130 }
109131
110132 protected void BuildURDFJoints ( XElement robot , ZOSimOccurrence parent , ZOSimOccurrence child , Matrix4x4 worldJointMatrix , ref List < URDFJoint > joints ) {
0 commit comments