public static SceneGraph Deserialize(string XMLString) { // TODO KAM: Complete the deserialize here (and also in your actions, camera...) XElement xe = XElement.Parse(XMLString); if (xe.Name != "SceneGraph") { return(null); } else { Vector3 translation = Util.DeserializeVector((xe.Nodes().First((x) => (x as XElement).Name == "Translation") as XElement).FirstNode.ToString()); Quaternion rotation = Util.DeserializeQuaternion((xe.Nodes().First((x) => (x as XElement).Name == "Rotation") as XElement).FirstNode.ToString()); Vector3 scale = Util.DeserializeVector((xe.Nodes().First((x) => (x as XElement).Name == "Scaling") as XElement).FirstNode.ToString()); var fn = (xe.Nodes().First((x) => (x as XElement).Name == "Renderable") as XElement).FirstNode; IRenderable child = (fn == null) ? null : RenderableFactory.Deserialize(fn.ToString()); var tr = new SceneGraph(Matrix.Transformation(Vector3.Zero, Quaternion.Identity, scale, Vector3.Zero, rotation, translation), child); // Do all children... foreach (var xchild in (xe.Nodes().Where((x) => (x as XElement).Name == "Child"))) { tr.AttachChild( ((xchild as XElement).Nodes().First((x) => (x as XElement).Name == "Name") as XElement).Value, SceneGraph.Deserialize(((xchild as XElement).Nodes().First((x) => (x as XElement).Name == "SceneGraph") as XElement).ToString()) ); } return(tr); } }
public void Serialization() { var tr = new TestRenderable(); var tr2 = RenderableFactory.Deserialize(RenderableFactory.Serialize(tr).ToString()); Assert.IsInstanceOfType(tr2, typeof(TestRenderable), "Deserialized result should be an instance of TestRenderable"); }