M
M
mIka012021-04-12 13:54:22
3D
mIka01, 2021-04-12 13:54:22

How to build stl with c#?

Hello, how to build an stl model from an array of points?
There is an array of points in three-dimensional space, they can be combined into triangles (if necessary). It seems that the layout of the document speaks of a simple stl structure, but I am a beginner and therefore most likely I will not be able to figure it out. Is there a ready-made library, but rather a guide on how to do it.

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-04-12
@mIka01

There are several libraries:
Free: https://www.nuget.org/packages/QuantumConcepts.For...
Paid: https://products.aspose.com/cad/net

There is an array of points in three-dimensional space, they can be combined into triangles (if necessary).

It is necessary, because STL operates with triangles - you still have to determine the normals of these triangles in your point cloud and write the triangles in the correct order (there are no fields for normals in the format itself)
It seems that the layout of the document speaks of a simple stl structure, but I am a beginner and therefore most likely I will not be able to figure it out.

If you can't already (even text format), then the library won't help. If you haven't tried it yet, go try it.

M
mIka01, 2021-04-12
@mIka01

If needed, there is a library.
Download directly from NuGet.

using System.IO;
using IxMilia.Stl;

StlFile stlFile = new StlFile();
            stlFile.SolidName = "my-solid";

            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 0, 0), new StlVertex(0, 100, 0), new StlVertex(100, 0, 0)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(100, 0, 0), new StlVertex(0, 100, 0), new StlVertex(100, 100, 0)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 0, 100), new StlVertex(100, 0, 100), new StlVertex(0, 100, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(100, 0, 100), new StlVertex(0, 100, 100), new StlVertex(100, 100, 100)));

            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 0, 0), new StlVertex(100, 0, 0), new StlVertex(0, 0, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 0, 100), new StlVertex(100, 0, 0), new StlVertex(100, 0, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 100, 0), new StlVertex(100, 100, 0), new StlVertex(0, 100, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 100, 100), new StlVertex(100, 100, 0), new StlVertex(100, 100, 100)));

            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 0, 0), new StlVertex(0, 100, 0), new StlVertex(0, 0, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(0, 0, 100), new StlVertex(0, 100, 0), new StlVertex(0, 100, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(100, 0, 0), new StlVertex(100, 100, 0), new StlVertex(100, 0, 100)));
            stlFile.Triangles.Add(new StlTriangle(new StlNormal(1, 0, 0), new StlVertex(100, 0, 100), new StlVertex(100, 100, 0), new StlVertex(100, 100, 100)));

            using (FileStream fs = new FileStream(@"C:\Users\...\1.stl", FileMode.Open))
            {
                stlFile.Save(fs);
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question