RElement getElement(XElement ele) { RElement ret = new RElement(ele.Name.LocalName); ret.Value = ele.Value; if (ele.HasElements) { ret.HasElements = true; foreach (XElement xele in ele.Elements()) ret.Elements.Add(getElement(xele)); } if (ele.HasAttributes) { ret.HasAttributes = true; foreach (XAttribute att in ele.Attributes()) ret.Attributes.Add(att.Name.LocalName, getAttribute(ret, att)); } return ret; }
static void getNormals(Mesh mesh, RElement ele) { bool hasNormals = ele.HasElement("Mesh.Normals"); if (hasNormals) { foreach (RElement xe in ele.GetElement(P.Obj.Mesh + ".Normals").Elements) { mesh.Normals.Add(xe.Attributes["Vector"].ToVector3()); } } }
static void getFaces(Mesh mesh, RElement ele) { bool hasNormals = ele.HasElement("Mesh.Normals"); int i = -1; foreach (RElement xe in ele.GetElement(P.Obj.Mesh + ".Faces").Elements) { i++; string[] w = xe.Attributes["Indices"].Value.Replace(" ", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (hasNormals) { SmoothMeshTriangle fmt = new SmoothMeshTriangle(int.Parse(w[0]), int.Parse(w[1]), int.Parse(w[2]), mesh, i + "" + "smsh" + "Mesh" + mesh.Name); mesh.AddObject(fmt); } else { FlatMeshTriangle fmt = new FlatMeshTriangle(int.Parse(w[0]), int.Parse(w[1]), int.Parse(w[2]), mesh, i + "" + "fmsh" + "Mesh" + mesh.Name); fmt.ComputeNormal(false); mesh.AddObject(fmt); } } }
static void getVertices(Mesh mesh, RElement ele) { foreach (RElement xe in ele.GetElement(P.Obj.Mesh + ".Vertices").Elements) { mesh.Vertices.Add(xe.Attributes[P.Pos].ToVector3()); } }
static void transform(Instance ins, RElement ele) { if (ele.HasElement("Instance.Transforms")) foreach (RElement el in ele.GetElement("Instance.Transforms").Elements) if (el.Name == P.Trans) { ins.Transform(el.Attributes[P.Matr].ToMatrix4()); } }
static Material getMaterial(RElement ele, Dictionary<string, Texture> texts) { if (ele.HasAttribute(P.Mat)) { throw new Exception(); //Create exception for non-matching values or spelling mistakes. } else { if (ele.HasElement(ele.Name + "." + P.Mat)) { if (ele.GetElement(ele.Name + "." + P.Mat).Elements.Count > 0) { return ele.GetElement(ele.Name + "." + P.Mat).Elements[0].CreateMaterialFromElement(texts); } else { throw new Exception(); //Create exception for elements not found. } } else { return null; } } }
static bool getInstance(RElement ele) { if (ele.HasAttribute(P.Obj.Ins)) return bool.Parse(ele.Attributes[P.Obj.Ins].Value); return false; }
static bool getShadow(RElement ele) { if (ele.HasAttribute(P.Shad)) return ele.Attributes[P.Shad].ToBoolean(); return true; }
static string getName(RElement ele) { return ele.HasAttribute("Name") ? ele.Attributes[P.Name].Value : getUniqueName(); }
static GeometricObject getCObject(RElement ele) { throw new NotImplementedException(); }
RAttribute getAttribute(RElement p, XAttribute ele) { return new RAttribute() { Parent = p, Name = ele.Name.LocalName, Value = ele.Value }; }