Esempio n. 1
0
        private void parseFaces(String[] _line, Mesh _mesh)
        {
            String[] vertex1 = null;
            String[] vertex2 = null;
            String[] vertex3 = null;

            if (_mesh != null)
            {
                if (_line[0].Equals("f"))
                {
                    if (_line.Length == 4)
                    {
                        vertex1 = _line[1].Split('/');
                        vertex2 = _line[2].Split('/');
                        vertex3 = _line[3].Split('/');

                        if (vertex1.Length >= 3 && vertex2.Length >= 2 && vertex3.Length >= 3)
                        {
                            if (_vertices.Count > 0 && _uvs.Count > 0 && _normals.Count > 0)
                            {
                                double[] v1_pos = _vertices[(int.Parse(vertex1[0]) - 1)];
                                double[] v1_uv = _uvs[(int.Parse(vertex1[1]) - 1)];
                                double[] v1_normal = _normals[(int.Parse(vertex1[2]) - 1)];

                                double[] v2_pos = _vertices[(int.Parse(vertex2[0]) - 1)];
                                double[] v2_uv = _uvs[(int.Parse(vertex2[1]) - 1)];
                                double[] v2_normal = _normals[(int.Parse(vertex2[2]) - 1)];

                                double[] v3_pos = _vertices[(int.Parse(vertex3[0]) - 1)];
                                double[] v3_uv = _uvs[(int.Parse(vertex3[1]) - 1)];
                                double[] v3_normal = _normals[(int.Parse(vertex3[2]) - 1)];

                                Vertex v1 = new Vertex(v1_pos, v1_uv, v1_normal);
                                Vertex v2 = new Vertex(v2_pos, v2_uv, v2_normal);
                                Vertex v3 = new Vertex(v3_pos, v3_uv, v3_normal);

                                Face f = new Face(v1, v2, v3);
                                _mesh.AddFace(f);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public Face(Vertex v1, Vertex v2, Vertex v3)
 {
     vertices[0] = v1;
     vertices[1] = v2;
     vertices[2] = v3;
 }