I am pretty new to blender scripting, so I appologize if this is a silly question.
I am using blender to import obj files. The obj files I use have their own vertex normals. When the results in blender looked a little odd, I checked the python script for importing an obj, and it appears that it ignores the vertex normal inputs in the file. (and instead simply uses blender’s function for calculating the vertex normals).
So, my question is, can we use the python api to set our own vertex normals for each vertex? In other words, could the obj import script be
modified to accept the vertex normals.
I did a little research, and it appears that blender cannot modify the vertex normals, but most of the posts were from an artistic side, not the programming side. So, I am wondering if we can do this using python.
# gives you the normal of vertex with index 0
>>> bpy.context.object.data.vertices[0].normal
>>> bpy.context.object.data.vertices[3].normal.zero()
>>> bpy.context.object.data.vertices[3].normal
Vector((0.0, 0.0, 0.0))
>>> bpy.context.object.data.vertices[3].normal = Vector((1,1,1))
>>> bpy.context.object.data.vertices[3].normal
Vector((0.5773491859436035, 0.5773491859436035, 0.5773491859436035))
zeffii’s method is quite correct, however, if you enter/exit edit mode, the normals are recalculated and the values you’ve set will be lost unfortunately.
You cannot, Blender always regenerete vertex normals with own algorithm, so you need to rewrite lot of low level code to get it. For example look at source/blender/blenkernel/intern/mesh.c:1284 mesh_calc_normals()