I am currently trying to write a script that creates a light at every polygon oriented to each polygon. The script takes as an input the active mesh. It iterates over the polygons of the mesh and gets their global position. It then creates a light at that position. The problem is that I cannot get the light to be rotated so that they are perpendicular to the face, is the same as the normal. I tired using the function
polygon.normal but this does not give me a vector I can apply as a rotation. Instead
.normal gives me a local position vector. It is local in the sense that it sees the polygon center as
0, 0, 0, basically the
.normal function is no good for me in this case.
Here is what my script currently does:
Here is what I want it to do: I do not care about the yaw of the light only the orientations matters to me atm.
def create_light_at_face(): """ layers: tuple. 20 booleans where exaclty one boolen is True return: None creates an area light the has the same orientation as the normal at the center of each face """ for poly in mesh.polygons: loc = get_global_poly_pos(poly) normal = get_normal(poly) # this is probably needed somehow # get the rotation needed for each polygon face, idk how # default values in RADIANS, actual values will be computed somehow rot_x = 0 rot_y = 0 rot_z = 0 bpy.ops.object.lamp_add(type='AREA', view_align=False, location=(loc, loc, loc), rotation=(rot_x, rot_y, rot_z), layers=get_layers()) # scale lamp up a little fo we can see the area bpy.context.object.data.size = 3