Skip to content

Commit c00ea2d

Browse files

File tree

8 files changed

+224
-59
lines changed

8 files changed

+224
-59
lines changed

Editor/CustomEditors/UrdfRobotEditor.cs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public override void OnInspectorGUI()
4343

4444
GUILayout.Space(5);
4545
GUILayout.Label("All Rigidbodies", EditorStyles.boldLabel);
46-
DisplaySettingsToggle(new GUIContent("Use Gravity"), urdfRobot.SetRigidbodiesUseGravity);
47-
DisplaySettingsToggle(new GUIContent("Use Inertia from URDF", "If disabled, Unity will generate new inertia tensor values automatically."),
48-
urdfRobot.SetUseUrdfInertiaData);
49-
DisplaySettingsToggle(new GUIContent("Default Space"), urdfRobot.ChangeToCorrectedSpace);
46+
DisplaySettingsToggle(new GUIContent("Use Gravity", "If disabled, robot is not affected by gravity."), urdfRobot.SetRigidbodiesUseGravity, UrdfRobot.useGravity);
47+
DisplaySettingsToggle(new GUIContent("Use Inertia from URDF", "If disabled, Unity will generate new inertia tensor values automatically."),urdfRobot.SetUseUrdfInertiaData,
48+
UrdfRobot.useUrdfInertiaData);
49+
DisplaySettingsToggle(new GUIContent("Default Space"), urdfRobot.ChangeToCorrectedSpace,UrdfRobot.changetoCorrectedSpace);
5050

5151
GUILayout.Space(5);
5252
GUILayout.Label("All Colliders", EditorStyles.boldLabel);
53-
DisplaySettingsToggle(new GUIContent("Convex"), urdfRobot.SetCollidersConvex);
53+
DisplaySettingsToggle(new GUIContent("Convex"), urdfRobot.SetCollidersConvex,UrdfRobot.collidersConvex);
5454

5555
GUILayout.Space(5);
5656
GUILayout.Label("All Joints", EditorStyles.boldLabel);
@@ -61,22 +61,32 @@ public override void OnInspectorGUI()
6161
EditorGUILayout.EndHorizontal();
6262

6363
GUILayout.Space(5);
64-
65-
GUILayout.Label("Helper Scripts", EditorStyles.boldLabel);
66-
DisplaySettingsToggle(new GUIContent("Controller Script"), urdfRobot.AddController);
67-
DisplaySettingsToggle(new GUIContent("Forward Kinematics Script"), urdfRobot.AddFkRobot);
64+
EditorGUILayout.PropertyField(axisType, new GUIContent("Axis Type", "Adjust this if the models that make up your robot are facing the wrong direction."));
65+
serializedObject.ApplyModifiedProperties();
66+
UrdfRobotExtensions.CorrectAxis(urdfRobot.gameObject);
6867

69-
GUILayout.Space(5);
68+
if (urdfRobot.GetComponent<RosSharp.Control.Controller>() == null || urdfRobot.GetComponent<RosSharp.Control.FKRobot>() == null)
69+
{
70+
GUILayout.Label("Components", EditorStyles.boldLabel);
71+
GUILayout.BeginHorizontal();
72+
if (GUILayout.Button(urdfRobot.GetComponent<RosSharp.Control.Controller>() == null? "Add Controller": "Remove Controller"))
73+
{
74+
urdfRobot.AddController();
75+
}
76+
if (urdfRobot.GetComponent<RosSharp.Control.FKRobot>() == null)
77+
{
78+
if (GUILayout.Button("Add Forward Kinematics"))
79+
{
80+
urdfRobot.gameObject.AddComponent<RosSharp.Control.FKRobot>();
81+
}
82+
}
83+
GUILayout.EndHorizontal();
84+
}
7085

71-
GUILayout.Label("URDF Options", EditorStyles.boldLabel);
86+
GUILayout.Space(5);
87+
GUILayout.Label("URDF Files", EditorStyles.boldLabel);
7288
GUILayout.BeginHorizontal();
73-
StlWriter.fileType = (StlWriter.FileType) EditorGUILayout.EnumPopup("Export new URDF meshes to:", StlWriter.fileType);
74-
GUILayout.Label("STL files");
75-
bool export = GUILayout.Button("Export to URDF");
76-
EditorGUILayout.EndHorizontal();
77-
78-
//Export Robot button
79-
if (export)
89+
if (GUILayout.Button("Export robot to URDF"))
8090
{
8191
exportRoot = EditorUtility.OpenFolderPanel("Select export directory", exportRoot, "");
8292

@@ -99,18 +109,18 @@ public override void OnInspectorGUI()
99109
window.GetEditorPrefs();
100110
window.Show();
101111
}
112+
GUILayout.EndHorizontal();
102113
}
103114

104-
private delegate void SettingsHandler(bool enable);
115+
private delegate void SettingsHandler();
105116

106-
private static void DisplaySettingsToggle(GUIContent label, SettingsHandler handler)
117+
private static void DisplaySettingsToggle(GUIContent label, SettingsHandler handler, bool currentState)
107118
{
108119
EditorGUILayout.BeginHorizontal();
109120
EditorGUILayout.PrefixLabel(label);
110-
if (GUILayout.Button("Enable", buttonStyle))
111-
handler(true);
112-
if (GUILayout.Button("Disable", buttonStyle))
113-
handler(false);
121+
string buttonName = currentState ? "Disable" : "Enable";
122+
if (GUILayout.Button(buttonName, buttonStyle))
123+
handler();
114124
EditorGUILayout.EndHorizontal();
115125
}
116126

Editor/MenuItems/CompareURDF.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ public class CompareURDF : EditorWindow
1111
public string originalFile = "";
1212
public string exportedFile = "";
1313
public string logFileLocation = ""; // Defaults to the location of exported file location
14-
private static string[] windowOptions = { "originalFile","exportedFile","logFileLocation" };
14+
private static string[] windowOptions = { "originalFile", "exportedFile", "logFileLocation" };
15+
16+
private void Awake()
17+
{
18+
this.titleContent = new GUIContent("Compare URDF Files");
19+
}
1520

1621
private void OnGUI()
1722
{
@@ -23,17 +28,13 @@ private void OnGUI()
2328
};
2429
GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButtonRight) { fixedWidth = 75 };
2530

26-
//Window title
27-
GUILayout.Space(10);
28-
GUILayout.Label("Compare URDF files", titleStyle);
29-
3031
//Select imported URDF file
3132
GUILayout.Space(5);
3233
EditorGUILayout.BeginHorizontal();
3334
originalFile = EditorGUILayout.TextField(
3435
new GUIContent("Source URDF file : ", "The original robot URDF file"),
3536
originalFile);
36-
if (GUILayout.Button("Select", buttonStyle))
37+
if (GUILayout.Button("Browse", buttonStyle))
3738
{
3839
originalFile = EditorUtility.OpenFilePanel("Select source URDF file", originalFile, "");
3940
}
@@ -47,7 +48,7 @@ private void OnGUI()
4748
exportedFile = EditorGUILayout.TextField(
4849
new GUIContent("Exported URDF file : ", "The exported robot URDF file"),
4950
exportedFile);
50-
if (GUILayout.Button("Select", buttonStyle))
51+
if (GUILayout.Button("Browse", buttonStyle))
5152
{
5253
exportedFile = EditorUtility.OpenFilePanel("Select exported URDF file", exportedFile, "");
5354
logFileLocation = Path.GetDirectoryName(exportedFile);
@@ -61,7 +62,7 @@ private void OnGUI()
6162
logFileLocation = EditorGUILayout.TextField(
6263
new GUIContent("Log File Save Location : ", "Log File Location "),
6364
logFileLocation);
64-
if (GUILayout.Button("Select", buttonStyle))
65+
if (GUILayout.Button("Browse", buttonStyle))
6566
{
6667
logFileLocation = EditorUtility.OpenFolderPanel("Log File Save Location Folder", exportedFile, "");
6768
}
@@ -93,7 +94,7 @@ private void OnGUI()
9394
/// <returns></returns>
9495
private bool FileCheck(string filePath)
9596
{
96-
if(filePath == " ")
97+
if (filePath == " ")
9798
{
9899
return false;
99100
}

Editor/MenuItems/FileImportMenu.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public class FileImportMenu : EditorWindow
1111
public ImportSettings settings = new ImportSettings();
1212
private static string[] windowOptions = { };
1313

14+
private void Awake()
15+
{
16+
this.titleContent = new GUIContent("URDF Import Settings");
17+
}
18+
1419
private void OnGUI()
1520
{
1621
//Styles definitions
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
© Siemens AG, 2018
3+
Author: Suzannah Smith (suzannah.smith@siemens.com)
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
<http://www.apache.org/licenses/LICENSE-2.0>.
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
using System.IO;
16+
using UnityEditor;
17+
using UnityEngine;
18+
19+
namespace RosSharp.Urdf.Editor
20+
{
21+
public class UrdfExportEditorWindow : EditorWindow
22+
{
23+
public UrdfRobot urdfRobot;
24+
public string exportRoot = "";
25+
public string subfolder = "";
26+
public int selectedSubfolder;
27+
28+
private static string[] subfolderOptions = { "Export URDF to root folder", "Export URDF to the following subfolder:" };
29+
30+
private void Awake()
31+
{
32+
this.titleContent = new GUIContent("Export URDF");
33+
}
34+
35+
private void OnGUI()
36+
{
37+
//Styles definitions
38+
GUIStyle titleStyle = new GUIStyle(EditorStyles.boldLabel)
39+
{
40+
alignment = TextAnchor.MiddleCenter,
41+
fontSize = 13
42+
};
43+
GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButtonRight) {fixedWidth = 75};
44+
45+
//Window title
46+
GUILayout.Space(10);
47+
GUILayout.Label("Export " + urdfRobot.gameObject.name + " to URDF", titleStyle);
48+
49+
//Select export root folder
50+
GUILayout.Space(5);
51+
EditorGUILayout.BeginHorizontal("HelpBox");
52+
exportRoot = EditorGUILayout.TextField(
53+
new GUIContent("Export root folder", "Corresponds to ROS package root folder."),
54+
exportRoot);
55+
if (GUILayout.Button("Browse", buttonStyle))
56+
{
57+
exportRoot = EditorUtility.OpenFolderPanel("Select export root folder", exportRoot, "");
58+
}
59+
60+
EditorGUILayout.EndHorizontal();
61+
62+
//Select subfolder
63+
GUILayout.Space(5);
64+
selectedSubfolder =
65+
GUILayout.SelectionGrid(selectedSubfolder, subfolderOptions, 1, EditorStyles.radioButton);
66+
67+
EditorGUI.BeginDisabledGroup(selectedSubfolder != 1);
68+
69+
EditorGUILayout.BeginHorizontal();
70+
GUILayout.Space(30);
71+
EditorGUILayout.BeginHorizontal("HelpBox");
72+
subfolder = EditorGUILayout.TextField(
73+
new GUIContent("Subfolder", "Corresponds to URDF subfolder in ROS package."),
74+
subfolder);
75+
if (GUILayout.Button("Browse", buttonStyle))
76+
{
77+
string subfolderPath = EditorUtility.OpenFolderPanel(
78+
"Select export destination for robot asset files (such as meshes, images, etc)",
79+
exportRoot,
80+
"");
81+
82+
subfolder = subfolderPath.Contains(exportRoot) ? subfolderPath.Substring(exportRoot.Length) : "";
83+
}
84+
85+
EditorGUILayout.EndHorizontal();
86+
EditorGUILayout.EndHorizontal();
87+
88+
EditorGUI.EndDisabledGroup();
89+
90+
//Choose STL export type
91+
GUILayout.Space(10);
92+
EditorGUILayout.BeginHorizontal();
93+
StlWriter.fileType =
94+
(StlWriter.FileType) EditorGUILayout.EnumPopup("Export new meshes to", StlWriter.fileType);
95+
EditorGUILayout.LabelField(" STL files");
96+
EditorGUILayout.EndHorizontal();
97+
98+
//Export Robot button
99+
GUILayout.Space(10);
100+
if (GUILayout.Button("Export Robot"))
101+
{
102+
if (exportRoot == "" || !Directory.Exists(exportRoot))
103+
EditorUtility.DisplayDialog("Export Error",
104+
"Export root folder must be defined and folder must exist.", "Ok");
105+
else
106+
{
107+
if (selectedSubfolder == 0)
108+
subfolder = "";
109+
else
110+
subfolder = subfolder.TrimStart(Path.DirectorySeparatorChar)
111+
.TrimStart(Path.AltDirectorySeparatorChar);
112+
113+
urdfRobot.ExportRobotToUrdf(exportRoot, subfolder);
114+
SetEditorPrefs();
115+
Close();
116+
}
117+
}
118+
}
119+
120+
public void GetEditorPrefs()
121+
{
122+
exportRoot = EditorPrefs.HasKey("UrdfExportRoot") ?
123+
EditorPrefs.GetString("UrdfExportRoot") : "";
124+
125+
subfolder = EditorPrefs.HasKey("UrdfExportSubfolder") ?
126+
EditorPrefs.GetString("UrdfExportSubfolder") : "";
127+
128+
selectedSubfolder = EditorPrefs.HasKey("UrdfExportSubfolderOption") ?
129+
EditorPrefs.GetInt("UrdfExportSubfolderOption") : 0;
130+
}
131+
private void SetEditorPrefs()
132+
{
133+
EditorPrefs.SetString("UrdfExportRoot", exportRoot);
134+
EditorPrefs.SetString("UrdfExportSubfolder", subfolder);
135+
EditorPrefs.SetInt("UrdfExportSubfolderOption", selectedSubfolder);
136+
}
137+
}
138+
}

Editor/MenuItems/UrdfImporterContextMenuItem.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
 /*
1+
/*
22
© Siemens AG, 2018
33
Author: Suzannah Smith (suzannah.smith@siemens.com)
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -10,7 +10,7 @@ You may obtain a copy of the License at
1010
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
See the License for the specific language governing permissions and
1212
limitations under the License.
13-
*/
13+
*/
1414

1515
using System.IO;
1616
using UnityEditor;
@@ -19,18 +19,18 @@ limitations under the License.
1919
namespace RosSharp.Urdf.Editor
2020
{
2121
public static class UrdfImporterContextMenuItem
22-
{
23-
[MenuItem("Assets/Import Robot from URDF", true, 0)]
22+
{
23+
[MenuItem("Robotics/Import Robot from Selected URDF file", true, 0)]
2424
public static bool CreateUrdfObject_IsValid()
2525
{
2626
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
2727

2828
return (Path.GetExtension(assetPath)?.ToLower() == ".urdf");
2929
}
3030

31-
[MenuItem("Assets/Import Robot from URDF")]
31+
[MenuItem("Robotics/Import Robot from Selected URDF file")]
3232
private static void CreateUrdfObject()
33-
{
33+
{
3434
//Get path to asset, check if it's a urdf file
3535
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
3636

@@ -44,7 +44,7 @@ private static void CreateUrdfObject()
4444
}
4545
else
4646
EditorUtility.DisplayDialog("URDF Import",
47-
"The file you selected was not a URDF file. A robot can only be imported from a valid URDF file.", "Ok");
47+
"The file you selected was not a URDF file. Please select a valid URDF file.", "Ok");
4848
}
4949
}
5050
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ URDF Importer allows you to import a robot defined in [URDF](http://wiki.ros.org
2020

2121
1. Copy the URDF and the associated files in the assets folder in the Project window. Make sure the [location](https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/urdf_importer/urdf_appendix.md#file-hierarchy) of the mesh files is correct.
2222

23-
2. Right Click on the URDF file and click `Import Robot from URDF`.
23+
2. Right Click on the URDF file and click `Import Robot from Selected URDF file`.
2424

2525
<img src = "images~/URDF%20Menu.png" width = 40% height = 40%>
2626

0 commit comments

Comments
 (0)