@@ -17,8 +17,13 @@ namespace ZO.ImportExport {
1717
1818 public class ZOImportURDF {
1919
20+ public static string WorkingDirectory {
21+ get ; set ;
22+ } = "." ;
23+
2024 public static ZOSimDocumentRoot Import ( string urdfFilePath ) {
2125 using ( StreamReader streamReader = new StreamReader ( urdfFilePath ) ) {
26+ WorkingDirectory = Path . GetDirectoryName ( urdfFilePath ) ;
2227 XmlDocument xmlDocument = new XmlDocument ( ) ;
2328 xmlDocument . Load ( streamReader ) ;
2429 return Import ( xmlDocument ) ;
@@ -28,7 +33,7 @@ public static ZOSimDocumentRoot Import(string urdfFilePath) {
2833 public static ZOSimDocumentRoot Import ( XmlDocument xmlDocument ) {
2934 XmlNode robot = xmlDocument . GetChildByName ( "robot" ) ;
3035
31- GameObject rootObject = new GameObject ( robot . Name ) ;
36+ GameObject rootObject = new GameObject ( robot . Attributes [ "name" ] . Value ) ;
3237
3338 ZOSimDocumentRoot simDocumentRoot = rootObject . AddComponent < ZOSimDocumentRoot > ( ) ;
3439
@@ -43,21 +48,45 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
4348
4449 string linkName = xmlLink . Attributes [ "name" ] . Value ;
4550 GameObject goLink = new GameObject ( linkName ) ;
46- ZOSimOccurrence occurrence = goLink . AddComponent < ZOSimOccurrence > ( ) ;
4751
4852 GameObject goVisualsEmpty = new GameObject ( "visuals" ) ;
4953 goVisualsEmpty . transform . SetParent ( goLink . transform ) ;
50-
54+
5155 GameObject goCollisionsEmpty = new GameObject ( "collisions" ) ;
5256 goCollisionsEmpty . transform . SetParent ( goLink . transform ) ;
5357
5458 goLinks [ linkName ] = new Tuple < XmlNode , GameObject > ( xmlLink , goLink ) ;
55- // // process the visuals
56- // XmlNode[] visuals = xmlLink.GetChildrenByName("visual");
5759
58- // foreach (XmlNode visual in visuals) {
60+ // process the visuals
61+ XmlNode [ ] xmlVisuals = xmlLink . GetChildrenByName ( "visual" ) ;
62+
63+ foreach ( XmlNode xmlVisual in xmlVisuals ) {
64+ XmlNode [ ] xmlGeometries = xmlVisual . GetChildrenByName ( "geometry" ) ;
65+
66+ foreach ( XmlNode xmlGeom in xmlGeometries ) {
67+ XmlNode xmlBox = xmlGeom . GetChildByName ( "box" ) ;
68+ GameObject visualGeo = null ;
69+ if ( xmlBox != null ) {
70+ visualGeo = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
71+ }
72+ XmlNode xmlCylinder = xmlGeom . GetChildByName ( "cylinder" ) ;
73+ if ( xmlCylinder != null ) {
74+ visualGeo = GameObject . CreatePrimitive ( PrimitiveType . Cylinder ) ;
75+ }
76+ XmlNode xmlSphere = xmlGeom . GetChildByName ( "sphere" ) ;
77+ if ( xmlSphere != null ) {
78+ visualGeo = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
79+ }
80+ XmlNode xmlMesh = xmlGeom . GetChildByName ( "mesh" ) ;
81+ if ( xmlMesh != null ) {
82+ // TODO
83+ }
84+ if ( visualGeo != null ) {
85+ visualGeo . transform . SetParent ( goVisualsEmpty . transform ) ;
86+ }
5987
60- // }
88+ }
89+ }
6190
6291 // get the origin
6392 // XmlNode origin =
@@ -84,6 +113,8 @@ public static ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
84113 }
85114
86115 goLink . Value . Item2 . transform . SetParent ( linkParent . transform ) ;
116+ ZOSimOccurrence occurrence = goLink . Value . Item2 . AddComponent < ZOSimOccurrence > ( ) ;
117+
87118 }
88119
89120 return simDocumentRoot ;
0 commit comments