FastPrint / Model /STLModel.cs
Mentors4EDU's picture
Upload 6 files
b6a0fc3 verified
ο»ΏFastPrint/
β”‚
β”œβ”€β”€ Geometry/
β”‚ └── BsplineMitchellNetravali.cs
β”‚
β”œβ”€β”€ Slicing/
β”‚ └── SliceAccelerator.cs
β”‚
β”œβ”€β”€ Printer/
β”‚ └── MarlinConnector.cs
β”‚
β”œβ”€β”€ Model/
β”‚ └── STLModel.cs
β”‚
β”œβ”€β”€ UI/
β”‚ β”œβ”€β”€ MainWindow.xaml
β”‚ └── MainWindow.xaml.cs
β”‚
└── README.md
using System.Collections.Generic;
using System.IO;
using System.Globalization;
namespace FastPrint.Model
{
public class STLModel
{
public List<float[]> Triangles { get; } = new List<float[]>();
public void LoadAscii(string path)
{
using var reader = new StreamReader(path);
string line;
var currentTriangle = new List<float>();
while ((line = reader.ReadLine()) != null)
{
if (line.Trim().StartsWith("vertex"))
{
var parts = line.Trim().Split(' ');
for (int i = 1; i < 4; i++)
currentTriangle.Add(float.Parse(parts[i], CultureInfo.InvariantCulture));
}
if (currentTriangle.Count == 9)
{
Triangles.Add(currentTriangle.ToArray());
currentTriangle.Clear();
}
}
}
}
}