public void ReadFile(string filename) { string BlenderFilesDirectory = GlsTutorialsClass.ProjectDirectory + @"/Blender/"; string nextLine; blenderObjects = new List<BlenderObject>(); using (StreamReader sr = new StreamReader(new FileStream(BlenderFilesDirectory + filename, FileMode.Open))) { short vertexCount = 1; short normalCount = 1; short previousObjectVertexCount = 1; // change from 1 to zero based short previousObjectNormalCount = 1; // change from 1 to zero based nextLine = sr.ReadLine(); while (!sr.EndOfStream) { if (nextLine[0] == 'o') { BlenderObject bo = new BlenderObject(nextLine); while (!sr.EndOfStream) { nextLine = sr.ReadLine(); if (nextLine[0] == 'o') break; if (nextLine[0] == 'v') { if (nextLine[1] == ' ') { bo.AddVertex(nextLine); vertexCount++; } if (nextLine[1] == 'n') { bo.AddNormal(nextLine); normalCount++; } } if (nextLine[0] == 'f') { bo.AddTriangle(nextLine, previousObjectVertexCount, previousObjectNormalCount); } } previousObjectVertexCount = vertexCount; previousObjectNormalCount = normalCount; bo.Setup(); blenderObjects.Add(bo); } else { if (!sr.EndOfStream) nextLine = sr.ReadLine(); } } } }