Skip to content

Commit 69ebf49

Browse files
committed
working inertial import
1 parent 7cf7a7b commit 69ebf49

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

Runtime/Scripts/Util/ImportExport/ZOImportURDF.cs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,18 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
128128
// find link parent
129129
GameObject linkParent = rootObject;
130130
GameObject linkChild = goLink.Value.Item2;
131+
XmlNode xmlChildLinkNode = goLink.Value.Item1;
132+
XmlNode xmlParentLinkNode = null;
131133
XmlNode workingJoint = null;
132134
foreach (XmlNode joint in xmlJoints) {
133-
XmlNode xmlChildLink = joint.GetChildByName("child");
134-
string childName = xmlChildLink.Attributes["link"].Value;
135+
XmlNode xmlChildLinkName = joint.GetChildByName("child");
136+
string childName = xmlChildLinkName.Attributes["link"].Value;
135137

136138
if (goLink.Value.Item2.name == childName) {
137-
XmlNode xmlParentLink = joint.GetChildByName("parent");
138-
string parentName = xmlParentLink.Attributes["link"].Value;
139+
XmlNode xmlParentLinkName = joint.GetChildByName("parent");
140+
string parentName = xmlParentLinkName.Attributes["link"].Value;
139141
linkParent = goLinks[parentName].Item2;
142+
xmlParentLinkNode = goLinks[parentName].Item1;
140143

141144
workingJoint = joint;
142145

@@ -157,8 +160,29 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
157160
linkChild.transform.localRotation = transform.Item2;
158161

159162
// add rigidbody components
160-
Rigidbody childRigidBody = linkChild.AddComponent<Rigidbody>();
161-
Rigidbody parentRigidBody = linkParent.AddComponent<Rigidbody>();
163+
Rigidbody childRigidBody = null;
164+
Rigidbody parentRigidBody = null;
165+
166+
XmlNode xmlInertial = xmlChildLinkNode.GetChildByName("inertial");
167+
if (xmlInertial != null) {
168+
childRigidBody = linkChild.AddComponent<Rigidbody>();
169+
170+
float mass = 1.0f;
171+
float.TryParse(xmlInertial.GetChildByName("mass").Attributes["value"].Value, out mass);
172+
childRigidBody.mass = mass;
173+
174+
}
175+
176+
xmlInertial = xmlParentLinkNode.GetChildByName("inertial");
177+
parentRigidBody = linkParent.GetComponent<Rigidbody>();
178+
if (xmlInertial != null && parentRigidBody == null) {
179+
parentRigidBody = linkParent.AddComponent<Rigidbody>();
180+
181+
float mass = 1.0f;
182+
float.TryParse(xmlInertial.GetChildByName("mass").Attributes["value"].Value, out mass);
183+
parentRigidBody.mass = mass;
184+
185+
}
162186

163187
// add joints
164188
string jointType = workingJoint.Attributes["type"].Value;
@@ -172,6 +196,10 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
172196
hingeJoint.Axis = xmlAxis.Attributes["xyz"].Value.FromURDFStringToVector3().Ros2Unity();
173197
}
174198

199+
if (jointType == "prismatic") {
200+
Debug.LogWarning("WARNING: Prismatic joint not yet implemented.");
201+
}
202+
175203
}
176204

177205

Samples~/ZeroSimSamples/Scenes/URDF_test.unity

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,6 +4951,36 @@ PrefabInstance:
49514951
propertyPath: m_LocalEulerAnglesHint.z
49524952
value: 0
49534953
objectReference: {fileID: 0}
4954+
- target: {fileID: 968823325036578810, guid: e40f2c3c7691c519a99f10bf56f8b75f,
4955+
type: 3}
4956+
propertyPath: m_ConnectedAnchor.x
4957+
value: -0.1500001
4958+
objectReference: {fileID: 0}
4959+
- target: {fileID: 968823325036578810, guid: e40f2c3c7691c519a99f10bf56f8b75f,
4960+
type: 3}
4961+
propertyPath: m_ConnectedAnchor.y
4962+
value: -0.009999998
4963+
objectReference: {fileID: 0}
4964+
- target: {fileID: 968823325036578810, guid: e40f2c3c7691c519a99f10bf56f8b75f,
4965+
type: 3}
4966+
propertyPath: m_ConnectedAnchor.z
4967+
value: 0.099999905
4968+
objectReference: {fileID: 0}
4969+
- target: {fileID: 968823325036578812, guid: e40f2c3c7691c519a99f10bf56f8b75f,
4970+
type: 3}
4971+
propertyPath: m_ConnectedAnchor.x
4972+
value: 0.1500001
4973+
objectReference: {fileID: 0}
4974+
- target: {fileID: 968823325036578812, guid: e40f2c3c7691c519a99f10bf56f8b75f,
4975+
type: 3}
4976+
propertyPath: m_ConnectedAnchor.y
4977+
value: -0.009999998
4978+
objectReference: {fileID: 0}
4979+
- target: {fileID: 968823325036578812, guid: e40f2c3c7691c519a99f10bf56f8b75f,
4980+
type: 3}
4981+
propertyPath: m_ConnectedAnchor.z
4982+
value: 0.099999905
4983+
objectReference: {fileID: 0}
49544984
m_RemovedComponents: []
49554985
m_SourcePrefab: {fileID: 100100000, guid: e40f2c3c7691c519a99f10bf56f8b75f, type: 3}
49564986
--- !u!1001 &3713500775682786879

0 commit comments

Comments
 (0)