Python: fix normal of a new polygon I've been working on retopo tools. I have created polygon loops with "bmesh.faces.new()". But i get a problem with face normal orientation. Some faces get inverted direction.

Here is my test:
http://youtu.be/AfsMQRLa7Zo

Here is the code where i create faces:
https://github.com/mifth/mifthtools/blob/4f3fec160c820dc66516a94ffa070261bafb9962/blender/addons/mira_tools/mi_curve_surfaces.py#L489-L501

Also, i added recalculation of normals "bmesh.ops.recalc_face_normals()"  but it did not help me.

It would be great if you have some ideas how to fix it. Thanks.
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 
    polygon's vertices. 

    - 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[2][: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[0].co

    result_vector = eye_location - world_coordinate
    dot_value = pnormal.dot(result_vector)            

    return not (dot_value &lt; 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.