public RobotRenderer() { robotModel = ObjMeshLoader.Load("Data/Models/dragon.obj"); xPosition = 0; yPosition = -0.25; zPosition = 0; }
static ObjMesh load(TextReader textReader) { vertices = new List<Vector3>(); normals = new List<Vector3>(); texCoords = new List<Vector2>(); objVerticesIndexDictionary = new Dictionary<ObjVertex, int>(); objVertices = new List<ObjVertex>(); objTriangles = new List<ObjTriangle>(); objQuads = new List<ObjQuad>(); ObjMesh mesh = new ObjMesh(); string line; while ((line = textReader.ReadLine()) != null) { line = line.Trim(SPLIT_CHARACTERS); line = line.Replace(" ", " "); string[] parameters = line.Split(SPLIT_CHARACTERS); switch (parameters[0]) { case "p": // Point break; case "v": // Vertex float x = float.Parse(parameters[1], CultureInfo.InvariantCulture); float y = float.Parse(parameters[2], CultureInfo.InvariantCulture); float z = float.Parse(parameters[3], CultureInfo.InvariantCulture); vertices.Add(new Vector3(x, y, z)); break; case "vt": // TexCoord float u = float.Parse(parameters[1], CultureInfo.InvariantCulture); float v = float.Parse(parameters[2], CultureInfo.InvariantCulture); texCoords.Add(new Vector2(u, v)); break; case "vn": // Normal float nx = float.Parse(parameters[1], CultureInfo.InvariantCulture); float ny = float.Parse(parameters[2], CultureInfo.InvariantCulture); float nz = float.Parse(parameters[3], CultureInfo.InvariantCulture); normals.Add(new Vector3(nx, ny, nz)); break; case "f": switch (parameters.Length) { case 4: ObjTriangle objTriangle = new ObjTriangle(); objTriangle.Index0 = parseFaceParameter(parameters[1]); objTriangle.Index1 = parseFaceParameter(parameters[2]); objTriangle.Index2 = parseFaceParameter(parameters[3]); objTriangles.Add(objTriangle); break; case 5: ObjQuad objQuad = new ObjQuad(); objQuad.Index0 = parseFaceParameter(parameters[1]); objQuad.Index1 = parseFaceParameter(parameters[2]); objQuad.Index2 = parseFaceParameter(parameters[3]); objQuad.Index3 = parseFaceParameter(parameters[4]); objQuads.Add(objQuad); break; } break; } } mesh.Vertices = objVertices.ToArray(); mesh.Triangles = objTriangles.ToArray(); mesh.Quads = objQuads.ToArray(); return mesh; }