This JavaScript program reads in an stl file and outputs the number of triangular faces, sides, and vertices, as well as the number of regular faces, sides, and vertices that the 3D object has. It also renders the 3D object using three.js.
Open stl_reader.html in a browser (preferably Chrome) and choose an stl file to read.
Sample stl files are located in the repo.
-
Divide the total number of vertices in the stl file by three.
-
Sides are identified as a sorted-pair of vertices.
-
All sides are saved as keys in a Hash pointing to true.
-
Same idea as the side counting logic.
-
Vertices are identified as an array of x, y, z coordinates.
-
All vertices are saved as keys in a Hash pointing to true.
-
Check which sides are connected to each other.
-
If two connected faces have the same normal, they are in the same regular face.
-
If a side connects two faces with the same normal, the side is not a regular side.
-
If all faces connected to the vertex have the same normal, the vertex is not a regular vertex.
-
There are no repeated faces
-
Each face is a triangle (consisting of three vertices)
-
There is only one solid object
-
Camera controls are clunky.
-
Does not seem to work for bigger objects.