I use Solid Inspector a lot (one of my favorite extensions actually, and most useful) when I am manually modeling. However I’ve potentially encountered solid geometry (within my own plugins) that is unpredictable so now I need to write a compact and efficient way to check for reversed faces within a solid group and then correct them.
I can’t assume that any of the faces are correctly oriented, so I have to start with the assumption that any, all or none of the faces might be reversed.
At the moment I really don’t have a solid or good idea on how to approach this but I may post up a few sample blocks of code after some testing.
Try this:
To be a ‘proper’ solid each edge is part of two faces (duh) and will be used in the forward direction in one face and in the reverse direction in the other. If this condition isn’t true then one of the faces is misoriented.
This is based on the face-to-face orientation method, which is not robust, since there is a risk of taking two incorrectly oriented faces as a reference. This is equivalent to the orient function with a right click on a face (which only works if you choose a correctly oriented face).
If the shape is a true solid, you can determine the correct orientation of a face.
take one face
take a half-line from the center of the face oriented along it’s normal vector.
count the intersections with the other faces of the shape (use classify_point, and if the intersection point happens to be a vertex or on an edge , count it once).
if the count is even (0, 2, 4), then the face is correctly oriented.
Then, you can propagate the orientation to the adjacent faces by using edge.reverse_in? method at their common edge.