public void Load(string filename = SceneFile) { InitilizeGL(); XmlReader sceneReader = XmlTextReader.Create(filename); while(sceneReader.Read ()) { if(sceneReader.Name == "camera") { Camera camera = new CameraFPS(); if(sceneReader.HasAttributes) while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "eye") { camera.Eye = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "origin") { camera.Origin = ParseVector(sceneReader.Value); } } sceneReader.MoveToElement(); this.camera = camera; objects.Add(camera); } if(sceneReader.Name == "model" && sceneReader.HasAttributes) { Model model = new Model(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "emblem" && sceneReader.HasAttributes) { Emblem model = new Emblem(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "sky" && sceneReader.HasAttributes) { SkySphere model = new SkySphere(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "field" && sceneReader.HasAttributes) { String meshName = "", materialName = ""; int x = 0, y = 0; Vector3 position; while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { meshName = sceneReader.Value; } else if(sceneReader.Name == "material") { materialName = sceneReader.Value; } else if(sceneReader.Name == "x") { x = int.Parse(sceneReader.Value); } else if(sceneReader.Name == "z") { y = int.Parse(sceneReader.Value); } else if(sceneReader.Name == "position") { position = ParseVector(sceneReader.Value); } } Field model = new Field(x, y, meshName, materialName); model.Position = position; sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "numPad" && sceneReader.HasAttributes) { String materialName = ""; float width = 0.0f, height = 0.0f; Vector3 position; Quaternion orientation; while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "material") { materialName = sceneReader.Value; } else if(sceneReader.Name == "width") { width = float.Parse(sceneReader.Value); } else if(sceneReader.Name == "height") { height = float.Parse(sceneReader.Value); } else if(sceneReader.Name == "position") { position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { orientation = ParseQuaternion(sceneReader.Value); } } Numpad numpad = new Numpad(materialName, width, height); numpad.Position = position; numpad.Orientation = orientation; this.objects.Add(numpad); sceneReader.MoveToElement(); } if(sceneReader.Name == "light") { Light light = new Light(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "position") { light.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "origin") { light.Origin = ParseVector(sceneReader.Value); } } SceneManager.Light = light; this.objects.Add(light); sceneReader.MoveToElement(); } if(sceneReader.Name == "emblems" && sceneReader.HasAttributes) { EmblemPanel panel = new EmblemPanel(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "distanceBetween") { panel.DistanceBetween = float.Parse(sceneReader.Value); } else if(sceneReader.Name == "position") { panel.Position = ParseVector(sceneReader.Value); } } sceneReader.MoveToElement(); sceneReader.ReadToDescendant("emblem"); do { Emblem model = new Emblem(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } //sceneReader.MoveToElement(); panel.AddEmblem(model); } while(sceneReader.ReadToNextSibling("emblem")); this.objects.Add(panel); sceneReader.MoveToElement(); } } }
public void Load(string filename = SceneFile) { InitilizeGL(); XmlReader sceneReader = XmlTextReader.Create(filename); while(sceneReader.Read ()) { if(sceneReader.Name == "camera") { Camera camera = new CameraFPS(); if(sceneReader.HasAttributes) while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "eye") { camera.Eye = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "origin") { camera.Origin = ParseVector(sceneReader.Value); } } sceneReader.MoveToElement(); this.camera = camera; objects.Add(camera); } if(sceneReader.Name == "model" && sceneReader.HasAttributes) { Model model = new Model(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "emblem" && sceneReader.HasAttributes) { Emblem model = new Emblem(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "sky" && sceneReader.HasAttributes) { SkySphere model = new SkySphere(); while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { model.AddComponent(MeshLoader.GetMesh(sceneReader.Value)); } else if(sceneReader.Name == "material") { model.AddMaterial(MaterialLoader.GetMaterial(sceneReader.Value)); } else if(sceneReader.Name == "position") { model.Position = ParseVector(sceneReader.Value); } else if(sceneReader.Name == "orientation") { model.Orientation = ParseQuaternion(sceneReader.Value); } } sceneReader.MoveToElement(); this.objects.Add(model); } if(sceneReader.Name == "field" && sceneReader.HasAttributes) { String meshName = "", materialName = ""; int x = 0, y = 0; while(sceneReader.MoveToNextAttribute()) { if(sceneReader.Name == "mesh") { meshName = sceneReader.Value; } else if(sceneReader.Name == "material") { materialName = sceneReader.Value; } else if(sceneReader.Name == "x") { x = int.Parse(sceneReader.Value); } else if(sceneReader.Name == "z") { y = int.Parse(sceneReader.Value); } } Field model = new Field(x, y, meshName, materialName); sceneReader.MoveToElement(); this.objects.Add(model); } } }