Skip to content

Commit 7cf7a7b

Browse files
committed
working hinge joint import
1 parent 0191e3e commit 7cf7a7b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Runtime/Scripts/Physics/ZOHingeJoint.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public Vector3 Axis {
7979
return UnityHingeJoint.axis;
8080
}
8181
set {
82+
_axis = value;
8283
UnityHingeJoint.axis = value;
8384
}
8485
}
@@ -92,6 +93,7 @@ public Vector3 Anchor {
9293
return UnityHingeJoint.anchor;
9394
}
9495
set {
96+
_anchor = value;
9597
UnityHingeJoint.anchor = value;
9698
}
9799
}
@@ -112,6 +114,7 @@ public Rigidbody ConnectedBody {
112114
}
113115
set {
114116
if (UnityHingeJoint.connectedBody != value) {
117+
_connectedBody = value;
115118
UnityHingeJoint.connectedBody = value;
116119
}
117120

Runtime/Scripts/Util/ImportExport/ZOImportURDF.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,28 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
150150

151151
// set transform
152152
if (workingJoint != null) {
153+
// set the transform
153154
XmlNode xmlOrigin = workingJoint.GetChildByName("origin");
154155
Tuple<Vector3, Quaternion> transform = OriginXMLToUnity(xmlOrigin);
155156
linkChild.transform.localPosition = transform.Item1;
156157
linkChild.transform.localRotation = transform.Item2;
157158

159+
// add rigidbody components
160+
Rigidbody childRigidBody = linkChild.AddComponent<Rigidbody>();
161+
Rigidbody parentRigidBody = linkParent.AddComponent<Rigidbody>();
162+
163+
// add joints
164+
string jointType = workingJoint.Attributes["type"].Value;
165+
if (jointType == "revolute") {
166+
167+
ZOHingeJoint hingeJoint = linkParent.AddComponent<ZOHingeJoint>();
168+
hingeJoint.ConnectedBody = childRigidBody;
169+
hingeJoint.Anchor = transform.Item1;
170+
171+
XmlNode xmlAxis = workingJoint.GetChildByName("axis");
172+
hingeJoint.Axis = xmlAxis.Attributes["xyz"].Value.FromURDFStringToVector3().Ros2Unity();
173+
}
174+
158175
}
159176

160177

0 commit comments

Comments
 (0)