Beispiel #1
0
        public void STLExport(MeshPrimitive mesh, string fileName, bool ascii = true, IEnumerable <Attribution> attributions = null)
        {
            try
            {
                CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
                // ...

                StlFile stlFile = new StlFile();
                stlFile.SolidName = GetAttributionExtraText(attributions);

                foreach (var triangle in mesh.EvaluateTriangles())
                {
                    stlFile.Triangles.Add(CreateStlTriangle(
                                              triangle.A.GetGeometry().GetPosition()
                                              , triangle.B.GetGeometry().GetPosition()
                                              , triangle.C.GetGeometry().GetPosition()));
                }
                // ...
                string folder = System.IO.Path.GetDirectoryName(fileName);
                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }
                using (FileStream fs = new FileStream(fileName, FileMode.Create))
                {
                    stlFile.Save(fs, ascii);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, "Error while exporting STL model");
                throw;
            }
        }