Skip to content

Commit 9b28771

Browse files
committed
somewhat working URDF export with mesh. Orientation and scale seem to be broken.
1 parent 3192f69 commit 9b28771

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

Editor/CustomEditors/ZODocumentRootEditor.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,7 @@ public override void OnInspectorGUI() {
5050
} else if (!System.IO.Directory.Exists(_URDFExportDirectory)) {
5151
EditorUtility.DisplayDialog("URDF Export Error", "Export root folder must be defined and folder must exist.", "Ok");
5252
} else {
53-
// documentRoot.ExportURDF(_URDFExportDirectory);
54-
ZOExportURDF exportURDF = new ZOExportURDF();
55-
XDocument urdfXML = exportURDF.BuildURDF(documentRoot);
56-
string urdfFilePath = Path.Combine(_URDFExportDirectory, $"{documentRoot.Name}.urdf");
57-
urdfXML.Save(urdfFilePath);
58-
59-
Debug.Log($"INFO: ZOSimDocumentRoot Saved URDF: {urdfFilePath}");
60-
53+
ZOExportURDF.ExportToDirectory(documentRoot, _URDFExportDirectory);
6154
}
6255

6356

Runtime/Scripts/Util/ImportExport/ZOExportURDF.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,38 @@ public Vector3 ConnectedAnchor {
5252

5353
}
5454

55+
private List<Transform> _visualMeshesToExport = new List<Transform>();
56+
public List<Transform> VisualMeshesToExport {
57+
get {return _visualMeshesToExport; }
58+
}
59+
60+
private List<Transform> _collisionMeshesToExport = new List<Transform>();
61+
public List<Transform> CollisionMeshesToExport {
62+
get { return _collisionMeshesToExport; }
63+
}
64+
65+
public static void ExportToDirectory(ZOSimDocumentRoot documentRoot, string directoryPath) {
66+
ZOExportURDF exportURDF = new ZOExportURDF();
67+
XDocument urdfXML = exportURDF.BuildURDF(documentRoot);
68+
string urdfFilePath = Path.Combine(directoryPath, $"{documentRoot.Name}.urdf");
69+
urdfXML.Save(urdfFilePath);
70+
71+
// save out visual and collision meshes
72+
foreach(Transform meshTransform in exportURDF.VisualMeshesToExport) {
73+
ZOExportOBJ exportOBJ = new ZOExportOBJ();
74+
exportOBJ.ExportToDirectory(meshTransform.gameObject, directoryPath, true, true);
75+
}
76+
77+
foreach(Transform meshTransform in exportURDF.CollisionMeshesToExport) {
78+
ZOExportOBJ exportOBJ = new ZOExportOBJ();
79+
exportOBJ.ExportToDirectory(meshTransform.gameObject, directoryPath, true, true);
80+
}
81+
82+
Debug.Log($"INFO: ZOExportURDF Saved URDF: {urdfFilePath}");
83+
84+
}
85+
86+
5587
/// <summary>
5688
/// Recursively build a URDF xml document given the base/root `ZOSimOccurrence`.
5789
/// Really should only be used by `ZODocumentRoot`. See: `ZODocumentRoot.ExportURDF`.
@@ -246,8 +278,6 @@ protected void BuildURDFLink(ZOSimOccurrence simOccurrence, XElement robot, Vect
246278
}
247279

248280

249-
private List<Transform> _visualMeshesToExport = new List<Transform>();
250-
private List<Transform> _collisionMeshesToExport = new List<Transform>();
251281
protected void BuildURDFVisuals(Transform visualTransform, XElement link, Vector3 anchorOffset) {
252282
// build 3d primitive if exists
253283
MeshFilter meshFilter = visualTransform.GetComponent<MeshFilter>();

0 commit comments

Comments
 (0)