public SkyBox(string directory, string ext = ".png") { Texture = new TextureCube(directory, ext); Vector3[] positions = new Vector3[] { new Vector3(1.0f, -1.0f, -1.0f), new Vector3(1.0f, -1.0f, 1.0f), new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(1.0f, 1.0f, -1.0f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(-1.0f, 1.0f, -1.0f) }; uint[] elements = new uint[] { 0, 1, 2, 3, 4, 7, 6, 5, 0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 0, 3, 7 }; Vao = new VAO(positions); Vao.addElementArray(elements); Shader = Shaders.SkyboxShader(); }
public static VAO LoadAsVAO(string path) { List <Vector3> positions = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <Vector3> normals = new List <Vector3>(); List <VertexData> verts = new List <VertexData>(); hasUvs = false; hasNormals = false; if (!File.Exists(path)) { throw new FileNotFoundException(); } string[] lines = File.ReadAllLines(path); foreach (string str in lines) { if (!string.IsNullOrWhiteSpace(str) && str.Length > 2) { switch (str.Substring(0, 2)) { case "v ": parseVert(str, positions); break; case "vt": parseTexture(str, uvs); break; case "vn": parseNormal(str, normals); break; case "f ": parseFace(str, positions, uvs, normals, verts); break; } } } Console.WriteLine("Loaded file {0}, with {1} with vertices", path, verts.Count); List <Vector3> p = new List <Vector3>(); List <Vector2> u = new List <Vector2>(); List <Vector3> n = new List <Vector3>(); uint[] e = new uint[verts.Count]; Dictionary <VertexData, int> vertices = new Dictionary <VertexData, int>(); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < verts.Count; i++) { if (!vertices.ContainsKey(verts[i])) { p.Add(verts[i].position); u.Add(verts[i].uv); n.Add(verts[i].normal); e[i] = (uint)p.Count - 1; vertices.Add(verts[i], vertices.Count); } else { e[i] = (uint)vertices[verts[i]]; } } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds); VAO vao = new VAO(p.ToArray()); if (hasUvs) { vao.addAttributeArray(u.ToArray(), 2, 1); } if (hasNormals) { vao.addAttributeArray(n.ToArray(), 3, 2); } vao.addElementArray(e); return(vao); }