bool ParseNode(Mat4 nodeTransform, XmlNode node) { string nodeId = XmlUtils.GetAttribute(node, "id"); Mat4 currentTransform = nodeTransform; foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "matrix") { float[] values = ConvertStringToFloatArray(childNode.InnerText); if (values == null || values.Length != 16) { Error("Invalid format of \"matrix\" node. Node \"{0}\".", nodeId); return(false); } Mat4 matrix = new Mat4(values); currentTransform *= matrix; continue; } if (childNode.Name == "translate") { float[] values = ConvertStringToFloatArray(childNode.InnerText); if (values == null || values.Length != 3) { Error("Invalid format of \"translate\" node. Node \"{0}\".", nodeId); return(false); } Vec3 translate = new Vec3(values[0], values[1], values[2]); currentTransform *= Mat4.FromTranslate(translate); continue; } if (childNode.Name == "rotate") { float[] values = ConvertStringToFloatArray(childNode.InnerText); if (values == null || values.Length != 4) { Error("Invalid format of \"rotate\" node. Node \"{0}\".", nodeId); return(false); } Vec3 axis = new Vec3(values[0], values[1], values[2]); Radian angle = new Degree(values[3]).InRadians(); if (axis != Vec3.Zero) { axis.Normalize(); float halfAngle = .5f * angle; float sin = MathFunctions.Sin(halfAngle); float cos = MathFunctions.Cos(halfAngle); Quat r = new Quat(axis * sin, cos); r.Normalize(); currentTransform *= r.ToMat3().ToMat4(); } continue; } if (childNode.Name == "scale") { float[] values = ConvertStringToFloatArray(childNode.InnerText); if (values == null || values.Length != 3) { Error("Invalid format of \"scale\" node. Node \"{0}\".", nodeId); return(false); } Vec3 scale = new Vec3(values[0], values[1], values[2]); currentTransform *= Mat3.FromScale(scale).ToMat4(); continue; } if (childNode.Name == "node") { if (!ParseNode(currentTransform, childNode)) { return(false); } continue; } if (childNode.Name == "instance_geometry") { if (!ParseNodeInstanceGeometry(currentTransform, childNode)) { return(false); } continue; } } return(true); }