Weighted vertex normals from STL file

Hi.

I need to calculate the weighted (by triangle area) vertex normals for lightning purposes for meshes created from STL files (CAD models). For now I’m (temporarily) using each triangles normal for each of its vertices normal which causes flat shading for each triangles of course. In specific, my problem is that I don’t know what kind of an approach to take to avoid looping all the mesh triangle/vertices several times through to find out the adjacent triangles. What would be the approach to take? Knowing how the triangles/vertices are initially generated would probably help to get the adjacent fellas with less work but I don’t have that information available and need a general approach anyway. (I’m mostly using STL files generated by Rhinoceros 5 at the moment).
Thanks,

Rob

(PS. I’m not using the normalized normals from the file, but calculating them from vertices for weighting purposes.)

I need to calculate the weighted (by triangle area) vertex normals for lightning purposes for meshes created from STL files (CAD models). For now I’m (temporarily) using each triangles normal for each of its vertices normal which causes flat shading for each triangles of course. In specific, my problem is that I don’t know what kind of an approach to take to avoid looping all the mesh triangle/vertices several times through to find out the adjacent triangles. What would be the approach to take? Knowing how the triangles/vertices are initially generated would probably help to get the adjacent fellas with less work but I don’t have that information available and need a general approach anyway. (I’m mostly using STL files generated by Rhinoceros 5 at the moment).
You’ve encountered a drawback to .stl format. It’s very primitive. You could have 6 polygons sharing a vertex, but those vertex coordinates would be repeated 6 times in the .stl file. You probably will have to do something like looping through all of the triangles multiple times.

Maybe there’s a shorter way. I assume Rhino has a vertex merge function? Most modeling programs do. It checks a set of selected vertices, looking for duplicates. If duplicates are found, they are ‘merged’ into 1 vertex (internal to Rhino). After the merge, output the model in .obj format, which is a simple ASCII format that is easy to read. Try this on some very simple .stl models. You’ll see that .obj format will define your triangles using a non-redundant set of vertices. This assumes you’ve performed the ‘merge’ operation in Rhino. Read in the .obj file and I think you’ll see how to proceed.

If you get this far and don’t know how to continue, let us know.

Good luck.

[QUOTE=Carmine;1261872]You’ve encountered a drawback to .stl format. It’s very primitive. You could have 6 polygons sharing a vertex, but those vertex coordinates would be repeated 6 times in the .stl file. You probably will have to do something like looping through all of the triangles multiple times.

Maybe there’s a shorter way. I assume Rhino has a vertex merge function? <snip>.

[/QUOTE]

Actually the vertices can be repeated far more than 6 times. A sphere form has been the worst so far, the first and last vertices (the poles) are repeated 1x times the amount of vertical divisions of the sphere. The .obj format is easier sure, I know, but I need to get this done with STL.

Thanks,
Rob

edited: removed incorrect statement

… I need to get this done with STL.
What do you mean by ‘get this done’? What’s your final objective? I’m guessing that you want to bring an STL(s) file(s) into OpenGL to put into some sort of simulation? How does Rhino come into the picture? Are you creating models from scratch in Rhino? Are you using Rhino as a converter to translate the models into a simple format that you can read into a GL program? STL files are easy to read, but hard to work with. If you output your Rhino models in OBJ format, the normals are generated for you. Good luck.

It means that I must be able to handle STL files as well as some other formats. It seems that I first need to make a decision of some proper internal polygon mesh model to use, winged-edge, openmesh or something else. After that calculating weighted vertex normals should be a pretty straightforward task. Focusing on that now. Rhino 5 is just my modeling tool with plenty of options for file format.

-rob