I had planned to do some modeling today, and ended up coding again...
I was trying to make shapes with flat faces and smoothly rounded edges, and noticed that they looked really crappy in Uru (top right cube in the following picture).
This is because to compute the vertex normals (that are exported by PyPRP), Blender averages the face normals of all adjacent faces of a vertex, which means that even the normals of the cube faces that are supposed to be flat are bent outward and the face is shaded as if it was curved (bottom right in the picture). What I want is the look at the top left, which is achieved by vertex normals as shown at the bottom left.
So I searched the web for a while and came to the conclusion that Blender just can't do that. It does not have the capability to let the user arbitrarily modify vertex normals. The normals can be modified from Python (which is how I got the screenshot), but they are reset to the default averaged normals again as soon as edit mode is left.
What to do? Since the normals can
be modified at least temporarily, we could do that right before exporting, inside PyPRP. So that's what I did, and the result is available as revision 318 in my experimental branch http://svn.guildofwriters.com/pyprp/contrib/CWalther/experimental/
With this extension, every object that has property renormal
set to areaweighted
, either as a Blender property or in AlcScript, has its normals recomputed. All other objects are left alone with their default Blender-computed normals. To compute a vertex normal, it still averages the face normals of the adjacent faces, but it does this weighted by the area of each face. That way, my big cube faces contribute the major part of the resulting normal, while the small bevel faces have little influence. Other algorithms could conceivably be added to this system in the future, such as weighting by some power of the face area or by the angles of the face corners, explicitly specified normals encoded in a vertex color layer, etc.
Perhaps some of you find this useful too. Testing and feedback is welcome!Edit:
For those who don't wan't to deal with Subversion and/or with the unstable trunk version of PyPRP, here is the relevant file from PyPRP 1.5.0 with just this modification applied - unzip and drop into your .blender/scripts folder (after renaming the existing one as a backup):