How to generate STL from vertices?

158 Views Asked by At

I have a dictionnary containing veritces and normals of a 3D object as follow:

{
    "nbVertices": 1550,
    "nbFaces": 1245,
    "polySize": 4,
    "vertices": {...},
    "faces": {...},
    "normals": {...},
    "uvs": {...},
    "tangents": {...},
    "colors": null
}

Lengths:

vertices is a list of 3 times nbVertices

faces is a list of indeces of 4 times nbFaces

normals is a list of 3 times nbVertices

How can I convert this to an STL file?

I tried to group the vertices 3 by 3xyz to make triangles and format it as ASCII STL with no luck, I cannot figure out how the list of vertices is sorted

1

There are 1 best solutions below

0
Rémi Baudoux On

The term "polySize": 4 is the number of edges of the polygons. so we do not deal with triangles, but with 4-sided polygons.

I took the indeces 4 by 4 (4 indeces per face) for each face, took the 4 vertices of the indeces above and the corresponding normal

An STL with 4-sided polygons is possible, but not compatible with all softwares, so I divided each 4-sided polygons on the diagonal to make 2 triangles