diff --git a/__init__.py b/__init__.py index e3176b0..3575888 100755 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,7 @@ bl_info = { "name": "gp interpolate", "author": "Christophe Seux, Samuel Bernou", - "version": (0, 7, 3), + "version": (0, 7, 4), "blender": (3, 6, 0), "location": "Sidebar > Gpencil Tab > Interpolate", "description": "Interpolate Grease pencil strokes over 3D", diff --git a/utils.py b/utils.py index 4556295..7bab0c0 100644 --- a/utils.py +++ b/utils.py @@ -35,12 +35,30 @@ class attr_set(): # --- Vector -def triangle_normal(a, b, c): - x = a[1] * b[2] - a[2] * b[1] - y = a[2] * b[0] - a[0] * b[2] - z = a[0] * b[1] - a[1] * b[0] - - return np.array([x, y, z], dtype='float64') +def triangle_normal(p1, p2, p3): + """ + Calculate the normal of a triangle given its three vertices. + + Parameters: + p1, p2, p3: the 3 vertices of the triangle + + Returns: + mathutils.Vector: The normalized normal vector of the triangle. + """ + ## Get edge vectors + edge1 = Vector(p2) - Vector(p1) + edge2 = Vector(p3) - Vector(p1) + ## Get normal (Cross product of the edge vectors) + normal = edge1.cross(edge2) + normal.normalize() + return normal + +## Bad normal calculation !! +# def triangle_normal(a, b, c): +# x = a[1] * b[2] - a[2] * b[1] +# y = a[2] * b[0] - a[0] * b[2] +# z = a[0] * b[1] - a[1] * b[0] +# return np.array([x, y, z], dtype='float64') def plane_coords(size=1): v = size * 0.5