예제 #1
0
    public MGeneralCurveFace CreateGeneralCurveFace(Mesh mesh)
    {
        MGeneralCurveFace face = new MGeneralCurveFace(mesh);

        if (!face.IsValid())
        {
            return(null);
        }
        int i;

        if ((i = AddFaceToMesh(face)) != -1)
        {
            return(faceList[i] as MGeneralCurveFace);
        }
        else
        {
            return(face);
        }
    }
예제 #2
0
 private bool Equals(MGeneralCurveFace obj)
 {
     return(mesh.Equals(obj.mesh));
 }
예제 #3
0
 public bool ExportObject(string filename)
 {
     StringBuilder sb = new StringBuilder();
     List<MPoint> pointList = mesh.pointList;
     List<MEdge> edgeList = mesh.edgeList;
     List<MFace> faceList = mesh.faceList;
     foreach(MPoint point in pointList)
     {
         sb.Append(string.Format("p {0} {1} {2}\n", point.position.x, point.position.y, point.position.z));
     }
     foreach(MEdge edge in edgeList)
     {
         switch (edge.edgeType)
         {
             case MEdge.MEdgeType.LINEAR:
                 int start = pointList.IndexOf(((MLinearEdge)edge).start);
                 int end = pointList.IndexOf(((MLinearEdge)edge).end);
                 sb.Append(string.Format("le {0} {1}\n", start, end));
                 break;
             case MEdge.MEdgeType.CURVE:
                 MCurveEdge ce = edge as MCurveEdge;
                 int center = pointList.IndexOf(ce.center);
                 sb.Append(string.Format("ce {0} {1} {2} {3} {4}\n", center, ce.radius, ce.normal.x, ce.normal.y, ce.normal.z));
                 break;
             case MEdge.MEdgeType.GENERAL:
                 MGeneralEdge ge = edge as MGeneralEdge;
                 sb.Append("ge\n");
                 foreach(Vector3 v in ge.points)
                 {
                     sb.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, v.z));
                 }
                 break;
         }
     }
     foreach(MFace face in faceList)
     {
         switch (face.faceType)
         {
             case MFace.MFaceType.POLYGON:
                 sb.Append("polyf\n");
                 foreach(MLinearEdge edge in ((MPolygonFace)face).edgeList)
                 {
                     int index = edgeList.IndexOf(edge);
                     sb.Append(string.Format("e {0}\n", index));
                 }
                 break;
             case MFace.MFaceType.CIRCLE:
                 MCircleFace circf = face as MCircleFace;
                 int circle = edgeList.IndexOf(circf.circle);
                 sb.Append(string.Format("circf {0}\n", circle));
                 break;
             case MFace.MFaceType.CONE:
                 MConeFace conf = face as MConeFace;
                 int top = pointList.IndexOf(conf.top);
                 int bottom = edgeList.IndexOf(conf.bottom);
                 sb.Append(string.Format("conf {0} {1}\n", top, bottom));
                 break;
             case MFace.MFaceType.CYLINDER:
                 MCylinderFace cylindf = face as MCylinderFace;
                 top = edgeList.IndexOf(cylindf.top);
                 bottom = edgeList.IndexOf(cylindf.bottom);
                 sb.Append(string.Format("cylf {0} {1}\n", top, bottom));
                 break;
             case MFace.MFaceType.SPHERE:
                 MSphereFace sf = face as MSphereFace;
                 int center = pointList.IndexOf(sf.center);
                 sb.Append(string.Format("sf {0} {1}\n", center, sf.radius));
                 break;
             case MFace.MFaceType.GENERAL_FLAT:
                 MGeneralFlatFace gff = face as MGeneralFlatFace;
                 sb.Append("gff\n");
                 foreach (Vector3 v in gff.points)
                 {
                     sb.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, v.z));
                 }
                 break;
             case MFace.MFaceType.GENERAL_CURVE:
                 MGeneralCurveFace gcf = face as MGeneralCurveFace;
                 sb.Append("gcf\n");
                 foreach(Vector3 v in gcf.mesh.vertices)
                 {
                     sb.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, v.z));
                 }
                 int count = gcf.mesh.triangles.Length / 3;
                 for(int i = 0; i < count; i++)
                 {
                     sb.Append(string.Format("f {0} {1} {2}\n", gcf.mesh.triangles[3 * i], gcf.mesh.triangles[3 * i + 1], gcf.mesh.triangles[3 * i + 2]));
                 }
                 break;
         }
     }
     if (!Directory.Exists(MDefinitions.SAVE_PATH))
     {
         Directory.CreateDirectory(MDefinitions.SAVE_PATH);
     }
     using (StreamWriter sw = new StreamWriter(MDefinitions.SAVE_PATH+"/" + filename))
     {
         sw.Write(sb.ToString());
         sw.Flush();
         sw.Close();
     }
     return true;
 }