Пример #1
0
 public void swapTriangles()
 {
     for (int i = 0; i < faces.Count; i++)
     {
         ObjFace f = faces[i];
         int     k = f.getNumVerts() - 1;
         for (int j = 0; j < k; j++, k--)
         {
             ObjFaceVertex tmp = faceVerts[f.getFirstVert() + j];
             faceVerts[f.getFirstVert() + j] = faceVerts[f.getFirstVert() + k];
             faceVerts[f.getFirstVert() + k] = tmp;
         }
     }
 }
Пример #2
0
        public void iterateXYZTriangles(IXYZTrianglesIterator l)
        {
            for (int i = 0; i < faces.Count; i++)
            {
                ObjFace f = faces[i];
                for (int j = 2; j < f.getNumVerts(); j++)
                {
                    int i0 = f.getFirstVert() + 0;
                    int i1 = f.getFirstVert() + j - 1;
                    int i2 = f.getFirstVert() + j;

                    ObjFaceVertex v0 = faceVerts[i0];
                    ObjFaceVertex v1 = faceVerts[i1];
                    ObjFaceVertex v2 = faceVerts[i2];

                    Vec3 xyz0 = xyzs[v0.getXYZIndex() - 1];
                    Vec3 xyz1 = xyzs[v1.getXYZIndex() - 1];
                    Vec3 xyz2 = xyzs[v2.getXYZIndex() - 1];
                    l.addXYZTriangle(xyz0, xyz1, xyz2);
                }
            }
        }
Пример #3
0
 public bool saveObjModel(string fileName)
 {
     System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
     file.WriteLine("# obj file exported by objFileExplorer");
     for (int i = 0; i < xyzs.Count; i++)
     {
         file.WriteLine("v " + xyzs[i].ToString().Replace(',', '.'));
     }
     for (int i = 0; i < texCoords.Count; i++)
     {
         file.WriteLine("vt " + texCoords[i].ToString().Replace(',', '.'));
     }
     for (int i = 0; i < normals.Count; i++)
     {
         file.WriteLine("vn " + normals[i].ToString().Replace(',', '.'));
     }
     for (int i = 0; i < objects.Count; i++)
     {
         ObjObject obj = objects[i];
         file.WriteLine("o " + obj.getName());
         for (int j = 0; j < obj.getNumFaces(); j++)
         {
             ObjFace face = faces[obj.getFirstFace() + j];
             file.Write("f");
             for (int k = 0; k < face.getNumVerts(); k++)
             {
                 int           faceVertIndex  = k + face.getFirstVert();
                 ObjFaceVertex faceVertex     = faceVerts[faceVertIndex];
                 string        faceVertString = " " + faceVertex.ToString();
                 file.Write(faceVertString);
             }
             file.WriteLine();
         }
     }
     for (int i = 0; i < groups.Count; i++)
     {
         ObjGroup g = groups[i];
         file.WriteLine("g " + g.getName());
         for (int j = 0; j < g.getNumFaces(); j++)
         {
             ObjFace face = faces[g.getFirstFace() + j];
             file.Write("f");
             for (int k = 0; k < face.getNumVerts(); k++)
             {
                 int           faceVertIndex  = k + face.getFirstVert();
                 ObjFaceVertex faceVertex     = faceVerts[faceVertIndex];
                 string        faceVertString = " " + faceVertex.ToString();
                 file.Write(faceVertString);
             }
             file.WriteLine();
         }
     }
     if (groups.Count == 0 && objects.Count == 0)
     {
         for (int j = 0; j < faces.Count; j++)
         {
             ObjFace face = faces[j];
             file.Write("f");
             for (int k = 0; k < face.getNumVerts(); k++)
             {
                 int           faceVertIndex  = k + face.getFirstVert();
                 ObjFaceVertex faceVertex     = faceVerts[faceVertIndex];
                 string        faceVertString = " " + faceVertex.ToString();
                 file.Write(faceVertString);
             }
             file.WriteLine();
         }
     }
     file.Close();
     return(false);
 }