Skip to content

Commit 5ba94b3

Browse files
Merge pull request #38 from Unity-Technologies/dev
Release 0.1.2
2 parents 68d91b3 + c72ad20 commit 5ba94b3

File tree

14 files changed

+257
-90
lines changed

14 files changed

+257
-90
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
[CustomPropertyDrawer(typeof(InspectorReadOnlyAttribute))]
5+
public class InspectorReadOnlyAttributeDrawer : PropertyDrawer
6+
{
7+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
8+
{
9+
return isHidden? 0: EditorGUI.GetPropertyHeight(property, label, true);
10+
}
11+
12+
public bool isHidden => (EditorApplication.isPlaying ?
13+
((InspectorReadOnlyAttribute)attribute).hideInPlayMode :
14+
((InspectorReadOnlyAttribute)attribute).hideInEditMode);
15+
16+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
17+
{
18+
if (!isHidden)
19+
{
20+
EditorGUI.LabelField(position, property.displayName + ": " + property.stringValue, EditorStyles.boldLabel);
21+
}
22+
}
23+
}

Editor/CustomEditors/InspectorReadOnlyAttributeDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/CustomEditors/UrdfRobotEditor.cs

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ You may obtain a copy of the License at
1212
limitations under the License.
1313
*/
1414

15+
using System.IO;
1516
using UnityEditor;
1617
using UnityEngine;
1718

@@ -22,6 +23,7 @@ public class UrdfRobotEditor : UnityEditor.Editor
2223
{
2324
private UrdfRobot urdfRobot;
2425
private static GUIStyle buttonStyle;
26+
private string exportRoot = "";
2527
SerializedProperty axisType;
2628

2729
public void OnEnable()
@@ -35,16 +37,20 @@ public override void OnInspectorGUI()
3537

3638
urdfRobot = (UrdfRobot) target;
3739

40+
EditorGUILayout.PropertyField(axisType, new GUIContent("Axis Type"));
41+
serializedObject.ApplyModifiedProperties();
42+
UrdfRobotExtensions.CorrectAxis(urdfRobot.gameObject);
43+
3844
GUILayout.Space(5);
3945
GUILayout.Label("All Rigidbodies", EditorStyles.boldLabel);
40-
DisplaySettingsToggle(new GUIContent("Use Gravity"), urdfRobot.SetRigidbodiesUseGravity);
41-
DisplaySettingsToggle(new GUIContent("Use Inertia from URDF", "If disabled, Unity will generate new inertia tensor values automatically."),
42-
urdfRobot.SetUseUrdfInertiaData);
43-
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);
4450

4551
GUILayout.Space(5);
4652
GUILayout.Label("All Colliders", EditorStyles.boldLabel);
47-
DisplaySettingsToggle(new GUIContent("Convex"), urdfRobot.SetCollidersConvex);
53+
DisplaySettingsToggle(new GUIContent("Convex"), urdfRobot.SetCollidersConvex,UrdfRobot.collidersConvex);
4854

4955
GUILayout.Space(5);
5056
GUILayout.Label("All Joints", EditorStyles.boldLabel);
@@ -55,22 +61,44 @@ public override void OnInspectorGUI()
5561
EditorGUILayout.EndHorizontal();
5662

5763
GUILayout.Space(5);
58-
EditorGUILayout.PropertyField(axisType, new GUIContent("Axis Type"));
64+
EditorGUILayout.PropertyField(axisType, new GUIContent("Axis Type", "Adjust this if the models that make up your robot are facing the wrong direction."));
5965
serializedObject.ApplyModifiedProperties();
6066
UrdfRobotExtensions.CorrectAxis(urdfRobot.gameObject);
61-
GUILayout.Label("Helper Scripts", EditorStyles.boldLabel);
62-
DisplaySettingsToggle(new GUIContent("Controller Script"), urdfRobot.AddController);
63-
DisplaySettingsToggle(new GUIContent("Forward Kinematics Script"), urdfRobot.AddFkRobot);
67+
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+
}
6485

6586
GUILayout.Space(5);
66-
if (GUILayout.Button("Export robot to URDF file"))
87+
GUILayout.Label("URDF Files", EditorStyles.boldLabel);
88+
GUILayout.BeginHorizontal();
89+
if (GUILayout.Button("Export robot to URDF"))
6790
{
68-
// Get existing open window or if none, make a new one:
69-
UrdfExportEditorWindow window = (UrdfExportEditorWindow)EditorWindow.GetWindow(typeof(UrdfExportEditorWindow));
70-
window.urdfRobot = urdfRobot;
71-
window.minSize = new Vector2(500, 200);
72-
window.GetEditorPrefs();
73-
window.Show();
91+
exportRoot = EditorUtility.OpenFolderPanel("Select export directory", exportRoot, "");
92+
93+
if (exportRoot.Length == 0)
94+
return;
95+
else if (!Directory.Exists(exportRoot))
96+
EditorUtility.DisplayDialog("Export Error", "Export root folder must be defined and folder must exist.", "Ok");
97+
else
98+
{
99+
urdfRobot.ExportRobotToUrdf(exportRoot);
100+
SetEditorPrefs();
101+
}
74102
}
75103

76104
GUILayout.Space(5);
@@ -81,20 +109,25 @@ public override void OnInspectorGUI()
81109
window.GetEditorPrefs();
82110
window.Show();
83111
}
112+
GUILayout.EndHorizontal();
84113
}
85114

86-
private delegate void SettingsHandler(bool enable);
115+
private delegate void SettingsHandler();
87116

88-
private static void DisplaySettingsToggle(GUIContent label, SettingsHandler handler)
117+
private static void DisplaySettingsToggle(GUIContent label, SettingsHandler handler, bool currentState)
89118
{
90119
EditorGUILayout.BeginHorizontal();
91120
EditorGUILayout.PrefixLabel(label);
92-
if (GUILayout.Button("Enable", buttonStyle))
93-
handler(true);
94-
if (GUILayout.Button("Disable", buttonStyle))
95-
handler(false);
121+
string buttonName = currentState ? "Disable" : "Enable";
122+
if (GUILayout.Button(buttonName, buttonStyle))
123+
handler();
96124
EditorGUILayout.EndHorizontal();
97125
}
98126

127+
private void SetEditorPrefs()
128+
{
129+
EditorPrefs.SetString("UrdfExportRoot", exportRoot);
130+
}
131+
99132
}
100133
}

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

Editor/MenuItems/UrdfExportEditorWindow.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ public class UrdfExportEditorWindow : EditorWindow
2525
public string subfolder = "";
2626
public int selectedSubfolder;
2727

28-
private static string[] subfolderOptions = { "Export URDF to root folder", "Export URDF to the following subfolder:" };
29-
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+
3035
private void OnGUI()
3136
{
3237
//Styles definitions
@@ -47,7 +52,7 @@ private void OnGUI()
4752
exportRoot = EditorGUILayout.TextField(
4853
new GUIContent("Export root folder", "Corresponds to ROS package root folder."),
4954
exportRoot);
50-
if (GUILayout.Button("Select", buttonStyle))
55+
if (GUILayout.Button("Browse", buttonStyle))
5156
{
5257
exportRoot = EditorUtility.OpenFolderPanel("Select export root folder", exportRoot, "");
5358
}
@@ -67,7 +72,7 @@ private void OnGUI()
6772
subfolder = EditorGUILayout.TextField(
6873
new GUIContent("Subfolder", "Corresponds to URDF subfolder in ROS package."),
6974
subfolder);
70-
if (GUILayout.Button("Select", buttonStyle))
75+
if (GUILayout.Button("Browse", buttonStyle))
7176
{
7277
string subfolderPath = EditorUtility.OpenFolderPanel(
7378
"Select export destination for robot asset files (such as meshes, images, etc)",

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("Assets/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("Assets/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
}

Editor/NeedsRuntimeConversion/Extensions/UrdfRobotExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static void CreateCollisionExceptions(Robot robot, GameObject robotGameO
129129

130130
#region Export
131131

132-
public static void ExportRobotToUrdf(this UrdfRobot urdfRobot, string exportRootFolder, string exportDestination)
132+
public static void ExportRobotToUrdf(this UrdfRobot urdfRobot, string exportRootFolder, string exportDestination="")
133133
{
134134
UrdfExportPathHandler.SetExportPath(exportRootFolder, exportDestination);
135135

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)