Skip to content

Commit 4f82961

Browse files
committed
document root urdf moved
1 parent 4a2c470 commit 4f82961

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

Runtime/Scripts/Document/ZOSimDocumentRoot.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public JObject JSON {
5353
set => _json = value;
5454
}
5555

56-
public XDocument XML {
57-
get; set;
58-
} = new XDocument();
5956

6057

6158

@@ -253,22 +250,10 @@ public ZOSimOccurrence GetOccurrence(string occurrenceName) {
253250
public void ExportURDF(string exportDirectory) {
254251
URDFExportDirectory = exportDirectory;
255252

256-
// create root document and robot element
257-
XElement robot = new XElement("robot");
258-
robot.SetAttributeValue("name", Name);
259-
XML = new XDocument(robot);
260-
261-
// go through the ZOSimOccurrences and convert into URDF Links and Joints
262-
foreach (Transform child in transform) { // BUG: Should only ever be one base object for URDF!!!
263-
ZOSimOccurrence simOccurence = child.GetComponent<ZOSimOccurrence>();
264-
if (simOccurence) {
265-
ZOExportURDF exportURDF = new ZOExportURDF();
266-
exportURDF.BuildURDF(robot, simOccurence, this.transform.WorldTranslationRotationMatrix());
267-
}
268-
}
269-
253+
ZOExportURDF exportURDF = new ZOExportURDF();
254+
XDocument urdfXML = exportURDF.BuildURDF(this);
270255
string urdfFilePath = Path.Combine(URDFExportDirectory, $"{Name}.urdf");
271-
XML.Save(urdfFilePath);
256+
urdfXML.Save(urdfFilePath);
272257

273258
}
274259

Runtime/Scripts/Util/ImportExport/ZOExportURDF.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)