public Window() : base(640, 480, GraphicsMode.Default, "HyperCycles!") { this.WindowBorder = WindowBorder.Resizable; this.WindowState = WindowState.Maximized; this._Manifold = Manifold.Load("../../Maps/1.obj"); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); }
/// <summary> /// Loads (and smooths) a manifold from the individual lines of a OBJ file. /// </summary> public static Manifold Load(string[] Lines) { List<Vector> verts = new List<Vector>(); List<List<int>> faces = new List<List<int>>(); foreach (string line in Lines) { if (line != "") { string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts[0] == "v") { verts.Add(new Vector( double.Parse(parts[1], CultureInfo.InvariantCulture), double.Parse(parts[2], CultureInfo.InvariantCulture), double.Parse(parts[3], CultureInfo.InvariantCulture))); } if (parts[0] == "f") { List<int> vs = new List<int>(); for(int t = 1; t < parts.Length; t++) { vs.Add(int.Parse(parts[t]) - 1); } faces.Add(vs); } } } Manifold mf = new Manifold(); mf._Vertices = verts; mf._Triangles = new List<Triangle<int>>(); mf._Segments = new Dictionary<Segment<int>, Triangle<int>>(); foreach (List<int> face in faces) { int first = face[0]; for (int i = 2; i < face.Count; i++) { mf._AddTriangle(new Triangle<int>(first, face[i - 1], face[i])); } } return mf; }