예제 #1
0
파일: StlWriter.cs 프로젝트: IxMilia/Stl
        private void WriteBinary(StlFile file, Stream stream)
        {
            var writer = new BinaryWriter(stream);

            // write header
            var header = new byte[80]; // can be a garbage value
            writer.Write(header);

            // write vertex count
            writer.Write((uint)file.Triangles.Count);

            // write triangles
            foreach (var triangle in file.Triangles)
            {
                writer.Write(triangle.Normal.X);
                writer.Write(triangle.Normal.Y);
                writer.Write(triangle.Normal.Z);

                writer.Write(triangle.Vertex1.X);
                writer.Write(triangle.Vertex1.Y);
                writer.Write(triangle.Vertex1.Z);

                writer.Write(triangle.Vertex2.X);
                writer.Write(triangle.Vertex2.Y);
                writer.Write(triangle.Vertex2.Z);

                writer.Write(triangle.Vertex3.X);
                writer.Write(triangle.Vertex3.Y);
                writer.Write(triangle.Vertex3.Z);

                writer.Write((ushort)0); // garbage value
            }

            writer.Flush();
        }
예제 #2
0
파일: StlWriter.cs 프로젝트: IxMilia/Stl
 public void Write(StlFile file, Stream stream, bool asAscii)
 {
     if (asAscii)
         WriteAscii(file, stream);
     else
         WriteBinary(file, stream);
 }
예제 #3
0
파일: StlFile.cs 프로젝트: IxMilia/Stl
 public static StlFile Load(Stream stream)
 {
     var file = new StlFile();
     var reader = new StlReader(stream);
     file.SolidName = reader.ReadSolidName();
     file.Triangles = reader.ReadTriangles();
     return file;
 }
        public static StlFile Load(Stream stream)
        {
            var file   = new StlFile();
            var reader = new StlReader(stream);

            file.SolidName = reader.ReadSolidName();
            file.Triangles = reader.ReadTriangles();
            return(file);
        }
예제 #5
0
파일: StlWriter.cs 프로젝트: xfischer/Stl
 public void Write(StlFile file, Stream stream, bool asAscii)
 {
     if (asAscii)
     {
         WriteAscii(file, stream);
     }
     else
     {
         WriteBinary(file, stream);
     }
 }
예제 #6
0
파일: StlWriter.cs 프로젝트: IxMilia/Stl
        private void WriteAscii(StlFile file, Stream stream)
        {
            var writer = new StreamWriter(stream);
            writer.WriteLine(string.Format("solid {0}", file.SolidName));
            foreach (var triangle in file.Triangles)
            {
                writer.WriteLine(string.Format("  facet normal {0}", NormalToString(triangle.Normal)));
                writer.WriteLine("    outer loop");
                writer.WriteLine(string.Format("      vertex {0}", VertexToString(triangle.Vertex1)));
                writer.WriteLine(string.Format("      vertex {0}", VertexToString(triangle.Vertex2)));
                writer.WriteLine(string.Format("      vertex {0}", VertexToString(triangle.Vertex3)));
                writer.WriteLine("    endloop");
                writer.WriteLine("  endfacet");
            }

            writer.WriteLine(string.Format("endsolid {0}", file.SolidName));
            writer.Flush();
        }
예제 #7
0
파일: StlWriter.cs 프로젝트: xfischer/Stl
        private void WriteAscii(StlFile file, Stream stream)
        {
            var writer = new StreamWriter(stream);

            writer.WriteLine(string.Format("solid {0}", file.SolidName));
            foreach (var triangle in file.Triangles)
            {
                writer.WriteLine(string.Format("  facet normal {0}", NormalToString(triangle.Normal)));
                writer.WriteLine("    outer loop");
                writer.WriteLine(string.Format("      vertex {0}", VertexToString(triangle.Vertex1)));
                writer.WriteLine(string.Format("      vertex {0}", VertexToString(triangle.Vertex2)));
                writer.WriteLine(string.Format("      vertex {0}", VertexToString(triangle.Vertex3)));
                writer.WriteLine("    endloop");
                writer.WriteLine("  endfacet");
            }

            writer.WriteLine(string.Format("endsolid {0}", file.SolidName));
            writer.Flush();
        }
예제 #8
0
파일: StlWriter.cs 프로젝트: xfischer/Stl
        private void WriteBinary(StlFile file, Stream stream)
        {
            var writer = new BinaryWriter(stream);

            // write header
            var header = new byte[80]; // can be a garbage value

            writer.Write(header);

            // write vertex count
            writer.Write((uint)file.Triangles.Count);

            // write triangles
            foreach (var triangle in file.Triangles)
            {
                writer.Write(triangle.Normal.X);
                writer.Write(triangle.Normal.Y);
                writer.Write(triangle.Normal.Z);

                writer.Write(triangle.Vertex1.X);
                writer.Write(triangle.Vertex1.Y);
                writer.Write(triangle.Vertex1.Z);

                writer.Write(triangle.Vertex2.X);
                writer.Write(triangle.Vertex2.Y);
                writer.Write(triangle.Vertex2.Z);

                writer.Write(triangle.Vertex3.X);
                writer.Write(triangle.Vertex3.Y);
                writer.Write(triangle.Vertex3.Z);

                writer.Write((ushort)0); // garbage value
            }

            writer.Flush();
        }