I want to create a point light for each face of a mesh with a specific material.
My first attempt looked something like this:
for face in obj.data.faces: mat = bpy.data.materials[face.material_index] if mat.name == 'Lamp' bpy.ops.object.lamp_add(location=face.center)
Besides the fact that the script did not create any point lights, the locations all would have been wrong anyway (i guess face.center is in local coordinates?). I actually found a small article about getting the world coordinates of a vertex on a bezier curve, and tried the proposed solution in my script:
wmtx = obj.matrix_world for face in obj.data.faces: mat = bpy.data.materials[face.material_index] if mat.name == 'Lamp' loc = face.center * wmtx bpy.ops.object.lamp_add(location=loc)
Yet the calculated locations are still nowhere near any face of my mesh