File size: 1,393 Bytes
b6a0fc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
ο»Ώ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();
                }
            }
        }
    }
}