public Ship(GameWindow gameWindow) { if (obj == null) { obj = ObjectFile.ObjectFromFile("boatFinal"); sail = obj.FindGroupByName("Sail"); cover = obj.FindGroupByName("Cover"); wheel = obj.FindGroupByName("Wheel"); boat = obj.FindGroupByName("Boat"); } myGameWindow = gameWindow; woodTexture = new Texture("woodtexture.jpg"); coverTexture = new Texture("covertexture.jpg"); sailTexture = new Texture("sailtexture.jpg"); woodTexture.LoadTexture(); coverTexture.LoadTexture(); sailTexture.LoadTexture(); }
public static ObjectFile ObjectFromFile(String fileName) { String[] lines; String currentLine; lines = File.ReadAllLines(fileName + ".obj"); ObjectFile file = new ObjectFile(); int vertexCount = 0; int facesCount = 0; int objectCount = 0; int uvCount = 0; int normalCount = 0; for (int i = 0; i < lines.Count(); i++) { currentLine = lines[i]; if (currentLine.StartsWith("v ")) { vertexCount++; continue; } if (currentLine.StartsWith("vn ")) { normalCount++; continue; } if (currentLine.StartsWith("o ")) { objectCount++; continue; } if (currentLine.StartsWith("vt ")) { uvCount++; continue; } if (currentLine.StartsWith("f ")) { facesCount++; continue; } } file.verts = new Vector3[vertexCount]; file.normals = new Vector3[normalCount]; file.uvs = new Vector2[uvCount]; file.objGroups = new ObjectGroup[objectCount]; file.faces = new Face[facesCount]; bool start = true; int j = 0, k = 0, l = 0, m = 0, n = 0; for (int i = 0; i < lines.Count(); i++) { currentLine = lines[i]; if (currentLine.StartsWith("v ")) { String[] components = currentLine.Split(' '); file.verts[j++] = new Vector3(Single.Parse(components[1]), Single.Parse(components[2]), Single.Parse(components[3])); continue; } if (currentLine.StartsWith("vn ")) { String[] components = currentLine.Split(' '); file.normals[k++] = new Vector3(Single.Parse(components[1]), Single.Parse(components[2]), Single.Parse(components[3])); continue; } if (currentLine.StartsWith("o ")) { String[] components = currentLine.Split(' '); if (!start) { file.objGroups[l++].endPosition = n * 3; } start = false; file.objGroups[l] = new ObjectGroup(components[1], n * 3, 0); continue; } if (currentLine.StartsWith("vt ")) { String[] components = currentLine.Split(' '); file.uvs[m++] = new Vector2(Single.Parse(components[2]), Single.Parse(components[1])); continue; } if (currentLine.StartsWith("f ")) { int[][] components = currentLine.Split(' ').Where((y, x) => x > 0).Select(y => y.Split('/').Select(z => Int32.Parse("0" + z)).ToArray()).ToArray(); file.faces[n++] = new Face(components); continue; } } file.objGroups[l++].endPosition = n * 3; file.FillVBO(); return(file); }