Why do STL meshes from SolidWorks sometimes contain rendering artifacts? #850
-
I have designed mechanical parts using SolidWorks and now would like to use the parts, exported as STL files, in OpenSim Creator and OpenSim, but I'm seeing rendering artifacts like below after updating from OSC 0.5.7 to 0.5.8: Before (0.5.7): The kind of rendering artifacts that 0.5.8 shows (also show in Blender, pictured here): And how it looks in OpenSim GUI: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think I can see some of the problem. Essentially, the earlier OSC (0.5.8) was using flat shading, which you can simulate in Blender by right-clicking the mesh and then clicking "Shade Flat". If you do this then (e.g.) the bottom bracket of your Metacarpal looks flat. Here's what I see in Blender 4.1: However, if I look at the file with smooth shading (the default, and uses a similar algorithm to OSC 0.5.9), these weird shading artifacts start to pop up: They aren't related to winding (as you've already investigated). They are because the STL file is sharing vertices on sharp corners. E.g. this vertex, highlighted white: Is participating in triangles inside the barrel and on the base's surface. The surface normal inside the barrel is (e.g.) {0,0,1}, whereas the base's surface normal is {-1,0,0}. The smooth shading algorithm takes the arithmetic mean of all triangle surfaces connected to a single vertex, so this particular vertex will end up with a normal like {-0.5, 0, 0.5}, which is why you're seeing funny shading artifacts. The original algorithm (flat-shading) does not take this arithmetic mean and, instead, assigns a unique vertex for each triangle in the mesh (i.e. it ignores sharing) and assigns each vertex a normal based on each independent triangle's surface (which is why flat-shading shows those little creases you see). Solution for OpenSim/OpenSim Creator (and any software that uses smooth-shading but doesn't support normals in datafiles):
This should result in a flat-shaded representation in OSC, but it somehow manages to look even worse in OpenSim GUI. I would guess that the reason there are issues in OpenSim GUI is because it has some upper limit on the number of triangles in a mesh (e.g. 65k). I will investigate whether "Smooth by Angle" should be a default part of OSC's mesh importing (or investigate adding normals support to OpenSim itself, but that requires coordinating with other teams, etc.). Solutions for non-OpenSim platforms:
|
Beta Was this translation helpful? Give feedback.
I think I can see some of the problem. Essentially, the earlier OSC (0.5.8) was using flat shading, which you can simulate in Blender by right-clicking the mesh and then clicking "Shade Flat". If you do this then (e.g.) the bottom bracket of your Metacarpal looks flat. Here's what I see in Blender 4.1:
However, if I look at the file with smooth shading (the default, and uses a similar algorithm to OSC 0.5.9), these weird shading artifacts start to pop up:
They aren't related to winding (as you've already investigated). They are because the STL file is sharing vertices on sharp corners. E.g. this vertex, highlighted white:
Is participating in triangles inside the barrel and on the base…