public void Read(XmlNode root) { root = root.ChildNodes[0]; id = (string)root.Attributes["id"].Value; name = (string)root.Attributes["name"].Value; foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("node")) { ColladaNode n = new ColladaNode(); n.Read(node, null); nodes.Add(n); foreach (var v in n.materialIds) { if (!MaterialIds.ContainsKey(v.Key)) { MaterialIds.Add(v.Key, v.Value); } } } } }
public void Read(XmlNode root, ColladaNode parent) { this.parent = parent; id = (string)root.Attributes["id"].Value; name = (string)root.Attributes["name"].Value; if (root.Attributes["type"] != null) { type = (string)root.Attributes["type"].Value; } foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("node")) { ColladaNode n = new ColladaNode(); n.Read(node, this); children.Add(n); } else if (node.Name.Equals("matrix")) { string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' '); mat = new Matrix4(); mat.M11 = float.Parse(data[0]); mat.M12 = float.Parse(data[1]); mat.M13 = float.Parse(data[2]); mat.M14 = float.Parse(data[3]); mat.M21 = float.Parse(data[4]); mat.M22 = float.Parse(data[5]); mat.M23 = float.Parse(data[6]); mat.M24 = float.Parse(data[7]); mat.M31 = float.Parse(data[8]); mat.M32 = float.Parse(data[9]); mat.M33 = float.Parse(data[10]); mat.M34 = float.Parse(data[11]); mat.M41 = float.Parse(data[12]); mat.M42 = float.Parse(data[13]); mat.M43 = float.Parse(data[14]); mat.M44 = float.Parse(data[15]); pos = new Vector3(mat.M14, mat.M24, mat.M34); scale = mat.ExtractScale(); mat.ClearScale(); mat.ClearTranslation(); mat.Invert(); var quat = mat.ExtractRotation(); rot = Switch_Toolbox.Library.AssimpHelper.ToEular(quat); if (float.IsNaN(rot.X)) { rot.X = 0; } if (float.IsNaN(rot.Y)) { rot.Y = 0; } if (float.IsNaN(rot.Z)) { rot.Z = 0; } mat.M11 = float.Parse(data[0]); mat.M12 = float.Parse(data[1]); mat.M13 = float.Parse(data[2]); mat.M14 = float.Parse(data[3]); mat.M21 = float.Parse(data[4]); mat.M22 = float.Parse(data[5]); mat.M23 = float.Parse(data[6]); mat.M24 = float.Parse(data[7]); mat.M31 = float.Parse(data[8]); mat.M32 = float.Parse(data[9]); mat.M33 = float.Parse(data[10]); mat.M34 = float.Parse(data[11]); mat.M41 = float.Parse(data[12]); mat.M42 = float.Parse(data[13]); mat.M43 = float.Parse(data[14]); mat.M44 = float.Parse(data[15]); } else if (node.Name.Equals("extra")) { } else if (node.Name.Equals("instance_controller") || node.Name.Equals("instance_geometry")) { if (node.Name.Equals("instance_geometry")) { geom_id = node.Attributes["url"].Value.Replace("#", ""); } foreach (XmlNode node1 in node.ChildNodes) { if (node1.Name.Equals("bind_material")) { foreach (XmlNode node2 in node1.ChildNodes) { if (node2.Name.Equals("technique_common")) { if (node2.ChildNodes[0].Attributes["symbol"] != null && !materialIds.ContainsKey(node2.ChildNodes[0].Attributes["symbol"].Value)) { materialIds.Add(node2.ChildNodes[0].Attributes["symbol"].Value, node2.ChildNodes[0].Attributes["target"].Value); } } } } } } else if (node.Name.Equals("translate")) { string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' '); pos = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2])); } else if (node.Name.Equals("scale")) { string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' '); scale = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2])); } else if (node.Name.Equals("rotate")) { string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' '); rot = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2])); } } }