@@ -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
0 commit comments