コード例 #1
0
ファイル: Mesh.cs プロジェクト: nerai/Console-Graphics
 public Mesh(point3[] meshVerts, triangle[] meshFaces, point2[] meshUvs, Material[] mtls = null)
 {
     verts = meshVerts;
     vertCount = verts.Length;
     faces = meshFaces;
     faceCount = faces.Length;
     uvVerts = meshUvs;
     matIDs = mtls;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: nerai/Console-Graphics
        static Mesh loadObj(string loc)
        {
            StreamReader r = new StreamReader(loc + ".obj");
            List<Mesh.point3> loadedVerts = new List<Mesh.point3>();
            List<Mesh.point2> loadedUvs = new List<Mesh.point2>();
            List<Mesh.triangle> loadedFaces = new List<Mesh.triangle>();
            List<Mesh.triangle> loadedUvFaces = new List<Mesh.triangle>();
            List<Material> mtls = new List<Material>();
            int vertCount = 0;
            int faceCount = 0;

            while (!r.EndOfStream)
            {
                string e1 = r.ReadLine();
                if (e1 != "")
                {
                    if (e1[0] == 'v' && e1[1] == 't')//texture verticies
                    {
                        string temp = e1.Substring(3, e1.Length - 3);
                        string[] coords = temp.Split(' ');
                        Mesh.point2 p = new Mesh.point2(float.Parse(coords[0]), float.Parse(coords[1]));
                        loadedUvs.Add(p);
                    }
                    else if (e1[0] == 'v')//vertex
                    {
                        vertCount++;
                        string temp = e1.Substring(3, e1.Length - 3);
                        string[] coords = temp.Split(' ');
                        Mesh.point3 p = new Mesh.point3(float.Parse(coords[0]) * 100, float.Parse(coords[1]) * 100, float.Parse(coords[2]));
                        //if z is positive it's off screen, z=0 we clip
                        loadedVerts.Add(p);
                    }
                    else if (e1[0] == 'u')
                    {//use this mtl for rest of faces faces material
                        Material m = new Material(e1.Substring(7, e1.Length - 7));
                        mtls.Add(m);
                    }
                    else if (e1[0] == 'f')//edge
                    {
                        faceCount++;
                        string temp = e1.Substring(2, e1.Length - 2);
                        string[] coords = temp.Split(' ', '/');
                        Mesh.triangle f = new Mesh.triangle(int.Parse(coords[0]) - 1, int.Parse(coords[2]) - 1, int.Parse(coords[4]) - 1, /*UV ID's*/ int.Parse(coords[1]) - 1, int.Parse(coords[3]) - 1, int.Parse(coords[5]) - 1, mtls.Count);
                        // Mesh.triangle uvf = new Mesh.triangle(int.Parse(coords[1]), int.Parse(coords[3]), int.Parse(coords[5]));
                        loadedFaces.Add(f);
                        // loadedUvFaces.Add(uvf);
                    }
                }
            }
            return (new Mesh(loadedVerts.ToArray(), loadedFaces.ToArray(), loadedUvs.ToArray(), mtls.ToArray()));
        }