示例#1
0
 public static void Write(string file, ScanData data)
 {
     using (StreamWriter w = System.IO.File.CreateText(file))
     {
         w.WriteLine(string.Format("# Create By Sardauscan V{0}", Application.ProductVersion));
         w.WriteLine("#");
         w.WriteLine("# Object");
         List <FaceInfo> faces  = new List <FaceInfo>();
         List <Vector3d> vertex = new List <Vector3d>();
         for (int i = 0; i < data.Count; i++)                 // collect vertices and face
         {
             ScanLine slice = data[i];
             if (slice.IsMesh)
             {
                 List <Triangle3D> tris = slice.GetTriangles();
                 for (int t = 0; t < tris.Count; t++)
                 {
                     Triangle3D triangle = tris[t];
                     FaceInfo   face     = new FaceInfo();
                     face.v1 = AddToList(vertex, triangle.Point1.Position);
                     face.v2 = AddToList(vertex, triangle.Point2.Position);
                     face.v3 = AddToList(vertex, triangle.Point3.Position);
                     faces.Add(face);
                 }
             }
         }
         w.WriteLine(string.Format("# Vertices {0}", vertex.Count));
         for (int i = 0; i < vertex.Count; i++)
         {
             w.WriteLine(string.Format("v {0}", vertex[i].Dump()));
         }
         w.WriteLine(string.Format("# Triangles {0}", faces.Count));
         for (int i = 0; i < faces.Count; i++)
         {
             w.WriteLine(string.Format("f {0} {1} {2}", faces[i].v1 + 1, faces[i].v2 + 1, faces[i].v3 + 1));
         }
     }
 }
示例#2
0
        /// <summary>
        /// Write ScanData (mesh) to STL
        /// </summary>
        /// <param name="file"></param>
        /// <param name="points"></param>
        public static void Write(string file, ScanData points)
        {
            /*
             * solid
             *       :
             *       :
             *       facet normal 0.0 0.0 1.0
             *       outer loop
             *                      vertex  1.0  1.0  0.0
             *                      vertex -1.0  1.0  0.0
             *                      vertex  0.0 -1.0  0.0
             *       endloop
             *       endfacet
             *       :
             *       :
             * endsolid
             */

            using (StreamWriter w = System.IO.File.CreateText(file))
            {
                w.WriteLine("solid");
                for (int i = 0; i < points.Count; i++)
                {
                    ScanLine slice = points[i];
                    if (slice.IsMesh)
                    {
                        List <Triangle3D> tris = slice.GetTriangles();
                        for (int t = 0; t < tris.Count; t++)
                        {
                            WriteTriangle(w, tris[t]);
                        }
                    }
                }
                w.WriteLine("endsolid");
            }
        }