Skip to content

Commit 7d09bf9

Browse files
committed
fixed joint naming in URDF import
1 parent 563f507 commit 7d09bf9

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

Runtime/Scripts/Physics/ZOHingeJoint.cs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,22 @@ public Rigidbody ConnectedBody {
119119
}
120120

121121
// update the name
122-
_name = Type;
122+
if (string.IsNullOrEmpty(Name)) {
123+
Name = Type;
123124

124-
ZOSimOccurrence occurrence = GetComponent<ZOSimOccurrence>();
125-
if (occurrence) {
126-
_name = _name + "_from_" + occurrence.Name;
127-
}
125+
ZOSimOccurrence occurrence = GetComponent<ZOSimOccurrence>();
126+
if (occurrence) {
127+
Name = Name + "_from_" + occurrence.Name;
128+
}
128129

129-
if (UnityHingeJoint.connectedBody) {
130-
ZOSimOccurrence connected_occurrence = UnityHingeJoint.connectedBody.gameObject.GetComponent<ZOSimOccurrence>();
130+
if (UnityHingeJoint.connectedBody) {
131+
ZOSimOccurrence connected_occurrence = UnityHingeJoint.connectedBody.gameObject.GetComponent<ZOSimOccurrence>();
131132

132-
if (connected_occurrence) {
133-
_name = _name + "_to_" + connected_occurrence.Name;
133+
if (connected_occurrence) {
134+
Name = Name + "_to_" + connected_occurrence.Name;
135+
}
134136
}
137+
135138
}
136139

137140
}
@@ -288,19 +291,19 @@ public void CreateRequirements() {
288291
_hingeJoint = gameObject.AddComponent<UnityEngine.HingeJoint>();
289292
}
290293

291-
if (_name == null) {
292-
_name = Type;
294+
if (string.IsNullOrEmpty(Name)) {
295+
Name = Type;
293296

294297
ZOSimOccurrence occurrence = GetComponent<ZOSimOccurrence>();
295298
if (occurrence) {
296-
_name = _name + "_from_" + occurrence.Name;
299+
Name = Name + "_from_" + occurrence.Name;
297300
}
298301

299302
if (UnityHingeJoint.connectedBody) {
300303
ZOSimOccurrence connected_occurrence = UnityHingeJoint.connectedBody.gameObject.GetComponent<ZOSimOccurrence>();
301304

302305
if (connected_occurrence) {
303-
_name = _name + "_to_" + connected_occurrence.Name;
306+
Name = Name + "_to_" + connected_occurrence.Name;
304307
}
305308
}
306309
}
@@ -314,7 +317,6 @@ public void CreateRequirements() {
314317
// }
315318

316319

317-
#region ZOSerializationInterface
318320
public string Type {
319321
get { return "joint.hinge"; }
320322
}
@@ -324,24 +326,13 @@ public string Name {
324326
get {
325327
return _name;
326328
}
327-
private set {
329+
set {
328330
_name = value;
329331
}
330332
}
331333

332-
private JObject _json;
333-
public JObject JSON {
334-
get {
335-
// if (_json == null) {
336-
// _json = BuildJSON();
337-
// }
338-
return _json;
339-
340-
}
341-
}
342334

343335

344-
#endregion
345336

346337
}
347338

Runtime/Scripts/Util/ImportExport/ZOImportURDF.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument, string workingDi
234234
GameObject linkChild = goLink.Value.Item2;
235235
XmlNode xmlChildLinkNode = goLink.Value.Item1;
236236
XmlNode xmlParentLinkNode = null;
237-
XmlNode workingJoint = null;
237+
XmlNode xmlWorkingJoint = null;
238238
foreach (XmlNode joint in xmlJoints) {
239239
XmlNode xmlChildLinkName = joint.GetChildByName("child");
240240
string childName = xmlChildLinkName.Attributes["link"].Value;
@@ -245,7 +245,7 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument, string workingDi
245245
linkParent = goLinks[parentName].Item2;
246246
xmlParentLinkNode = goLinks[parentName].Item1;
247247

248-
workingJoint = joint;
248+
xmlWorkingJoint = joint;
249249

250250
break;
251251
}
@@ -256,9 +256,9 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument, string workingDi
256256
ZOSimOccurrence occurrence = linkChild.AddComponent<ZOSimOccurrence>();
257257

258258
// set transform
259-
if (workingJoint != null) {
259+
if (xmlWorkingJoint != null) {
260260
// set the transform
261-
XmlNode xmlOrigin = workingJoint.GetChildByName("origin");
261+
XmlNode xmlOrigin = xmlWorkingJoint.GetChildByName("origin");
262262
Tuple<Vector3, Quaternion> transform = OriginXMLToUnity(xmlOrigin);
263263
linkChild.transform.localPosition = transform.Item1;
264264
linkChild.transform.localRotation = transform.Item2;
@@ -289,15 +289,20 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument, string workingDi
289289
}
290290

291291
// add joints
292-
string jointType = workingJoint.Attributes["type"].Value;
292+
string jointType = xmlWorkingJoint.Attributes["type"].Value;
293293
if (jointType == "revolute") {
294294

295295
ZOHingeJoint hingeJoint = linkParent.AddComponent<ZOHingeJoint>();
296296
hingeJoint.ConnectedBody = childRigidBody;
297297
hingeJoint.Anchor = transform.Item1;
298298

299-
XmlNode xmlAxis = workingJoint.GetChildByName("axis");
299+
XmlNode xmlAxis = xmlWorkingJoint.GetChildByName("axis");
300300
hingeJoint.Axis = xmlAxis.Attributes["xyz"].Value.FromURDFStringToVector3().Ros2Unity();
301+
302+
if (xmlWorkingJoint.Attributes["name"] != null) {
303+
hingeJoint.Name = xmlWorkingJoint.Attributes["name"].Value;
304+
}
305+
301306
}
302307

303308
if (jointType == "prismatic") {
@@ -313,9 +318,6 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument, string workingDi
313318
}
314319

315320
protected static Tuple<Vector3, Quaternion> OriginXMLToUnity(XmlNode xmlOrigin) {
316-
if (xmlOrigin == null) {
317-
Debug.Log("BLAH");
318-
}
319321
Vector3 translation = Vector3.zero;
320322
string xyz = xmlOrigin.Attributes["xyz"].Value;
321323
if (xyz != null && xyz != "") {

0 commit comments

Comments
 (0)