Exemplo n.º 1
0
        public STLModel DeepCopy()
        {
            var model = new STLModel(Name)
            {
                Facets = Facets.ConvertAll(facet => new Facet(facet))
            };

            return(model);
        }
Exemplo n.º 2
0
        public static STLModel FromBinaryFile(string filename)
        {
            var model = new STLModel("model");

            using (var fs = File.OpenRead(filename))
                using (var br = new BinaryReader(fs))
                {
                    br.BaseStream.Seek(80, SeekOrigin.Begin);
                    int facetCount = (int)br.ReadUInt32();
                    for (int i = 0; i < facetCount; i++)
                    {
                        var facet = new Facet
                        {
                            Normal  = new Vec3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                            Vertex1 = new Vec3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                            Vertex2 = new Vec3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                            Vertex3 = new Vec3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle())
                        };
                        model.AddFacet(facet);
                        br.BaseStream.Seek(2, SeekOrigin.Current);
                    }
                }
            return(model);
        }
Exemplo n.º 3
0
 public static STLModel FromAsciiFile(string filename)
 {
     using (var fs = File.OpenRead(filename))
         using (var sr = new StreamReader(fs))
         {
             string solidName = sr.ReadLine();
             var    model     = new STLModel(solidName.Split()[1]);
             while (!sr.EndOfStream)
             {
                 string line = sr.ReadLine().Trim();
                 if (line == "endsolid")
                 {
                     break;
                 }
                 string[] normal = line.Split();
                 sr.ReadLine();
                 line = sr.ReadLine().Trim();
                 string[] vertex1 = line.Split();
                 line = sr.ReadLine().Trim();
                 string[] vertex2 = line.Split();
                 line = sr.ReadLine().Trim();
                 string[] vertex3 = line.Split();
                 sr.ReadLine();
                 var facet = new Facet
                 {
                     Normal  = new Vec3(float.Parse(normal[2]), float.Parse(normal[3]), float.Parse(normal[4])),
                     Vertex1 = new Vec3(float.Parse(vertex1[1]), float.Parse(vertex1[2]), float.Parse(vertex1[3])),
                     Vertex2 = new Vec3(float.Parse(vertex2[1]), float.Parse(vertex2[2]), float.Parse(vertex2[3])),
                     Vertex3 = new Vec3(float.Parse(vertex3[1]), float.Parse(vertex3[2]), float.Parse(vertex3[3]))
                 };
                 model.AddFacet(facet);
                 sr.ReadLine();
             }
             return(model);
         }
 }