public MCylinderFace CreateCylinderFace(MCurveEdge top, MCurveEdge bottom) { MCylinderFace face = new MCylinderFace(top, bottom); if (!face.IsValid()) { return(null); } int i; if ((i = AddFaceToMesh(face)) != -1) { return(faceList[i] as MCylinderFace); } else { return(face); } }
private bool Equals(MCylinderFace obj) { return((top.Equals(obj.top) && bottom.Equals(obj.bottom)) || (top.Equals(obj.bottom) && bottom.Equals(obj.top))); }
private int AddFaceToMesh(MFace face) { int i, j; if ((i = faceList.IndexOf(face)) == -1) { faceList.Add(face); switch (face.faceType) { case MFace.MFaceType.POLYGON: MPolygonFace pf = face as MPolygonFace; int count = pf.edgeList.Count; for (int k = 0; k < count; k++) { j = AddEdgeToMesh(pf.edgeList[k]); if (j != -1) { pf.edgeList[k] = edgeList[j] as MLinearEdge; } pf.edgeList[k].faces.Add(face); } break; case MFace.MFaceType.CIRCLE: MCircleFace cirf = face as MCircleFace; j = AddEdgeToMesh(cirf.circle); if (j != -1) { cirf.circle = edgeList[j] as MCurveEdge; } cirf.circle.faces.Add(face); break; case MFace.MFaceType.CONE: MConeFace conf = face as MConeFace; j = AddEdgeToMesh(conf.bottom); if (j != -1) { conf.bottom = edgeList[j] as MCurveEdge; } conf.bottom.faces.Add(face); j = AddPointToMesh(conf.top); if (j != -1) { conf.top = pointList[j]; } conf.top.faces.Add(face); break; case MFace.MFaceType.CYLINDER: MCylinderFace cylf = face as MCylinderFace; j = AddEdgeToMesh(cylf.top); if (j != -1) { cylf.top = edgeList[j] as MCurveEdge; } cylf.top.faces.Add(face); j = AddEdgeToMesh(cylf.bottom); if (j != -1) { cylf.bottom = edgeList[j] as MCurveEdge; } cylf.bottom.faces.Add(face); break; case MFace.MFaceType.SPHERE: MSphereFace sf = face as MSphereFace; j = AddPointToMesh(sf.center); if (j != -1) { sf.center = pointList[j]; } sf.center.faces.Add(face); break; case MFace.MFaceType.GENERAL_FLAT: break; case MFace.MFaceType.GENERAL_CURVE: break; default: Debug.Log("MMesh: AddFaceToList: unhandled edge type " + face.faceType); break; } boundingBox.AdjustToContain(face.boundingBox); } return(i); }
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; }