public WorldObject Import(string fileName) { //try //{ if (fileName != null) { minX = float.MaxValue; maxX = float.MinValue; minY = float.MaxValue; maxY = float.MinValue; using (StreamReader sr = new StreamReader(fileName)) { while (!sr.EndOfStream) { String line = sr.ReadLine(); if (line.Contains("; Object connections")) { break; } if (line.Contains("Vertices:")) { nextSet = SetX; line = sr.ReadLine(); line = line.Split(':')[1]; do { String[] linePoints = line.Split(','); for (int i = 0; i < linePoints.Length; i++) { if (linePoints[i].Length > 0) { nextSet(float.Parse(linePoints[i].Replace('.', ','))); } } }while ((line = sr.ReadLine()).Contains("}") == false); } if (line.Contains("PolygonVertexIndex:")) { nextVertex = SetVertex1; line = sr.ReadLine(); line = line.Split(':')[1]; do { String[] lineTriangles = line.Split(','); for (int i = 0; i < lineTriangles.Length; i++) { if (lineTriangles[i].Length > 0) { nextVertex(Convert.ToInt16(lineTriangles[i])); } } }while ((line = sr.ReadLine()).Contains("}") == false); } if (line.Contains("LayerElementUV:")) { line = sr.ReadLine(); while (!line.Contains("UV:")) { line = sr.ReadLine(); } nextUV = SetUV1; line = sr.ReadLine(); line = line.Split(':')[1]; do { String[] lineUVs = line.Split(','); for (int i = 0; i < lineUVs.Length; i++) { if (lineUVs[i].Length > 0) { nextUV(float.Parse(lineUVs[i].Replace('.', ','))); } } }while ((line = sr.ReadLine()).Contains("}") == false); } if (line.Contains("Materials: ")) { line = sr.ReadLine(); line = line.Split(':')[1]; int count = 0; do { String[] lineTriangles = line.Split(','); for (int i = 0; i < lineTriangles.Length; i++) { if (lineTriangles[i].Length > 0) { triangles[count++].TextureIndex = Convert.ToInt32(lineTriangles[i]); } } }while ((line = sr.ReadLine()).Contains("}") == false); } if (line.Contains("Texture::Map")) { line = sr.ReadLine(); while (!line.Contains("FileName: ")) { line = sr.ReadLine(); } String texturePath = line.Substring(line.IndexOf(": ") + 3); texturePath = texturePath.Remove(texturePath.Length - 1); textures.Add(texturePath); } } } //} //catch (Exception e) //{ // Console.WriteLine("The file could not be read:"); // Console.WriteLine(e.Message); //} float height = maxY - minY; float width = maxX - minX; return(new WorldObject(vertices, triangles, uvs, textures)); } return(null); }
private void SetUV1(float value) { u = value; nextUV = SetUV2; }
private void SetUV2(float value) { v = 1 - value; uvs.Add(new UV(u, v)); nextUV = SetUV1; }