something like this would let you determine if the polygon is back or front facing in the current view context, given a bm and a polygon to check:
def is_front_facing(context, bm, polygon):
When deciding if a polygon is facing the camera, you need
only calculate the dot product of the normal vector of
that polygon, with a vector from the camera to one of the
- If the dot product is less than zero, the polygon is facing the camera.
- If the value is greater than zero, it is facing away from the camera.
region = context.region
rv3d = context.space_data.region_3d
# neat eye location code with the help of paleajed
eye = Vector(rv3d.view_matrix[:3])
eye.length = rv3d.view_distance
eye_location = rv3d.view_location + eye
pnormal = obj.matrix_world.to_3x3() * polygon.normal
world_coordinate = obj.matrix_world * polygon.verts.co
result_vector = eye_location - world_coordinate
dot_value = pnormal.dot(result_vector)
return not (dot_value < 0.0)
I ripped this out of some old code, it might help to see it in context if it doesn't work. It will be important to establish which
rv3d to use, because a polygon that is back-facing if viewed from the top, will be reversed if viewed from the bottom.