SOLVED! Problem with face align (three points)

SOLVED!

To solve the problem with align you have to separate the triangle of the face mesh. After this you can aligh without problem.
To solve the problem with empty, you have to make two comands, because Blender late to rotate the camera to normal align. Command 1) Align to selectec normal and 2) Add Empty with align to view.

A big hug!

==============================

Hello my friends!

I’m trying to create a way to align and re scale a scanned face in Blender. I have the solution for the second, but with the first I’m having some troubles.

I’ll explain.


I Use OrtogOnBlender addon to scan a face with photogrammetry inside Blender. When the process finish I have a mesh without a usually alignment (the face “lonking” to front.


To solve this I select three points (two in cantal eyes and one n the middle of the month).


The behavior expected was to align the view with the Z-axis (the axis is in normal), but it doesn’t happen.

So, the code I created was this:

import bpy
from mathutils import Matrix, Vector




def AlinhaRostoDef(self, context):
    
    context = bpy.context
    obj = context.active_object
    scn = context.scene




# Create a face, align with view and creat a empty with align view active
    bpy.context.object.name = "Rosto"
    bpy.ops.mesh.edge_face_add() 
    bpy.ops.view3d.viewnumpad(type='TOP', align_active=True) 
    bpy.ops.view3d.snap_cursor_to_selected()
    bpy.ops.mesh.delete(type='EDGE_FACE')
    bpy.ops.object.editmode_toggle()
    bpy.ops.object.select_all(action='DESELECT')
    bpy.ops.object.add(radius=1.0, type='EMPTY', view_align=True)


    bpy.context.object.name = "Alinhador" 


# Parent face to empty,
    a = bpy.data.objects['Rosto']
    b = bpy.data.objects['Alinhador']


    bpy.ops.object.select_all(action='DESELECT') #deselect all object
    a.select = True
    b.select = True 
    bpy.context.scene.objects.active = b
    bpy.ops.object.parent_set()


# Reset the rotation and clean the parent
    bpy.ops.object.rotation_clear(clear_delta=False)

More than the problem with the align that doesn’t work well, the empty alignment appear do not respect the “Align to View” too.

Before use this method I tried to use the normal Vetors (mathutils.Vector), but the aligment based this numbers didnt worked too, I didnt understand well how the numbers works, because it is different of usually degrees, and when I tried to convert to Euler, the rotation was not right.

I think I’m doing somthing wrong.

Thanks for the attention.

SOLVED!

To solve the problem with align you have to separate the triangle of the face mesh. After this you can aligh without problem.
To solve the problem with empty, you have to make two comands, because Blender late to rotate the camera to normal align. Command 1) Align to selectec normal and 2) Add Empty with align to view.

A big hug!