How to get vertex normals from polygon?

(Qai) #1

Can someone help me how to get the vertex normals from a polygon? I can’t just do a sweep of all the vertices in the mesh and get the normals that way. I need to have the vertices associated with the specific polygon they form.

Below is a brief snippet of my script.

import bpy

selectedObjects = bpy.context.selected_objects
for obj in selectedObjects:
    if objType in ['MESH']:
        msh = obj.data
        for f in msh.polygons:
            # how to get vertices in f, then get associated normals of those vertices?
(Qai) #2

I think I figured it out. I’ll post the code in case anyone else might find it useful.

import bpy

selectedObjects = bpy.context.selected_objects
for obj in selectedObjects:
    if objType in ['MESH']:
        msh = obj.data
        for f in msh.polygons:
            for v in f.vertices:
                print(msh.vertices[v].normal) # or normal.x, normal.y, normal.z for individual components