public Texture Create(String fileName, String path = "Data/Textures/") { String key = path + fileName; if (!_textureDictionary.ContainsKey(key)) { Texture newTexture = new Texture(_device, fileName, path); _textureDictionary.Add(key, newTexture); return newTexture; } return _textureDictionary[key]; }
public ObjModel(Device device, String modelFileName, Texture texture) { StreamReader reader = new StreamReader("Data/Models/"+modelFileName); List<Vector3> vertices = new List<Vector3>(); List<Vector2> textures = new List<Vector2>(); List<Vector3> normals = new List<Vector3>(); List<Tuple<int,int,int>> points = new List<Tuple<int, int, int>>(); while (!reader.EndOfStream) { String line = reader.ReadLine(); if (String.IsNullOrWhiteSpace(line) || line[0] =='#') continue; String[] items = line.Split(' '); if(items[0] == "v") vertices.Add(new Vector3(float.Parse(items[1]), float.Parse(items[2]), -float.Parse(items[3]))); if (items[0] == "vt") textures.Add(new Vector2(float.Parse(items[1]), 1.0f - float.Parse(items[2]))); if (items[0] == "vn") normals.Add(new Vector3(float.Parse(items[1]), float.Parse(items[2]), -float.Parse(items[3]))); if (items[0] == "f") { for (int i = 3; i >0; i--) { String[] items2 = items[i].Split('/'); points.Add(new Tuple<int, int, int>(Int32.Parse(items2[0]),Int32.Parse(items2[1]),Int32.Parse(items2[2]))); } } } LightShader.Vertex[] verticesDefinition = new LightShader.Vertex[points.Count]; for (int i = 0; i < points.Count; i++) { verticesDefinition[i].position = vertices[points[i].Item1-1]; verticesDefinition[i].texture = textures[points[i].Item2-1]; verticesDefinition[i].normal = normals[points[i].Item3-1]; } VertexCount = points.Count; Int32[] indicesDefinition = new int[points.Count]; for (int i = 0; i < points.Count; i++) indicesDefinition[i] = i; IndexCount = points.Count; Texture = texture; VertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, verticesDefinition); IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indicesDefinition); }
public Model(Device device) { VertexCount = 4; IndexCount = 6; // Create the vertex array and load it with data. var vertices = new[] { new LightShader.Vertex { position = new Vector3(-1, -1, 0), texture = new Vector2(0, 0), normal = new Vector3(0, 0, -1.0f) }, new LightShader.Vertex { position = new Vector3(-1, 1, 0), texture = new Vector2(0, 1), normal = new Vector3(0, 0, -1.0f) }, new LightShader.Vertex { position = new Vector3(1, 1, 0), texture = new Vector2(1, 1), normal = new Vector3(0, 0, -1.0f) }, new LightShader.Vertex { position = new Vector3(1, -1, 0), texture = new Vector2(1, 0), normal = new Vector3(0, 0, -1.0f) } }; var indices = new[] { 0, 1, 3, 1, 2, 3 }; Texture = new Texture(device, "seafloor.dds"); VertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, vertices); IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices); }
public Font(Device device, String font, int height) { Texture = new Texture(device, font + "-" + height + "px.png", @"Data/Fonts/"); ParseFileData(@"Data/Fonts/"+font+"-"+height+"px.fnt",Texture.Width, Texture.Height); }