Skip to content

Commit db281d8

Browse files
committed
start of urdf import.
1 parent a80214e commit db281d8

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Xml;
2+
using System.Collections.Generic;
3+
4+
namespace ZO.Util.Extensions {
5+
public static class ZOXMLExtensions {
6+
static public XmlNode GetChildByName(this XmlNode xmlNode, string name) {
7+
foreach (XmlNode child in xmlNode) {
8+
if (child.Name == name) {
9+
return child;
10+
}
11+
}
12+
13+
return null;
14+
}
15+
16+
public static XmlNode[] GetChildrenByName(this XmlNode xmlNode, string name, bool recursive = false) {
17+
18+
List<XmlNode> children = new List<XmlNode>();
19+
foreach (XmlNode child in xmlNode.ChildNodes) {
20+
if (child.Name == name) {
21+
children.Add(child);
22+
}
23+
24+
if (recursive) {
25+
XmlNode[] recursiveChildren = child.GetChildrenByName(name, recursive);
26+
foreach (XmlNode childrensChild in recursiveChildren) {
27+
children.Add(childrensChild);
28+
}
29+
}
30+
}
31+
32+
return children.ToArray();
33+
34+
}
35+
36+
37+
}
38+
}

Runtime/Scripts/Util/Extensions/ZOXMLExtensions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Util/ImportExport/ZOImportURDF.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,39 @@
99
using ZO.Math;
1010
using ZO.Util.Extensions;
1111
using System.Xml.Linq;
12+
using System.Xml;
1213

1314
namespace ZO.ImportExport {
1415

1516

1617
public class ZOImportURDF {
18+
19+
public ZOSimDocumentRoot Import(string urdfFilePath) {
20+
using(StreamReader streamReader = new StreamReader(urdfFilePath)) {
21+
XmlDocument xmlDocument = new XmlDocument();
22+
xmlDocument.Load(streamReader);
23+
return Import(xmlDocument);
24+
}
25+
}
26+
27+
public ZOSimDocumentRoot Import(XmlDocument xmlDocument) {
28+
XmlNode robot = xmlDocument.GetChildByName("robot");
29+
30+
GameObject rootObject = new GameObject(robot.Name);
31+
32+
ZOSimDocumentRoot simDocumentRoot = rootObject.AddComponent<ZOSimDocumentRoot>();
33+
34+
35+
// create the URDF links in Unity
36+
XmlNode[] links = robot.GetChildrenByName("link");
37+
foreach(XmlNode link in links) {
38+
// process the visuals
39+
XmlNode[] visuals = link.GetChildrenByName("visual");
40+
41+
}
42+
43+
return simDocumentRoot;
44+
}
45+
1746
}
1847
}

0 commit comments

Comments
 (0)