Script to adjust vertex normals for rendering

Here’s a script that I’m releasing in case someone finds it useful. It adjust vertex normals to get uniform smooth shading over split edges that are manually marked as sharp.

vertexnormal.blend (633 KB)
http://www.pasteall.org/47111/python

The purpose for writing it was to fiddle more with Python and Blender API which are both somewhat new to me. In that regard it was a success but it’s not that useful, which is why I didn’t turn it into an addon.

The script does what it’s supposed to but otherwise it’s slow and horrible. The slowness comes from crude algorithm that is used to find the nearest vertices and partially because its Python. Sharp edges are needed to limit the amount of vertices that are handled, of which it then loops through in a very straightforward manner:

  • get a list of unique vertices
  • get first vertex and remove it from the list
  • calculate relative distance and order them
  • find closest vertices within given distance
  • adjust normals for the picked vertex and all close to it
  • remove found vertices from the list
  • repeat until no more vertices are left


Split edges that render as connected after adjusting normals with the script.

The obvious place where this could be useful would be to use it with cell fracture addon. Good idea but cell fracture result has bigger problems than vertex normals that break the shading. Wasn’t obvious before writing a script to adjust the normals and seeing how much it helps.



And it doesn’t really. Adjusting normals does help with the shading (shadow line and specular reflection) and hides some of the visible edges but fractured pieces have so bad topology that the result is crap. Cell fracture also leaves gaps, although the margin was 0 for that test.