blender-to-gmstudio / blender-to-smf

Import-Export of Blender model from/to SMF model format
MIT License
11 stars 2 forks source link

Guarantee the same shading of faces in SMF and in Blender, look into how Blender works with normals #34

Closed bartteunis closed 1 year ago

bartteunis commented 2 years ago

Have a detailed look at all Blender functionality related to normals and shading and adjust the export so it exports the data in a way that the model is shaded the same as in Blender.

bartteunis commented 2 years ago

See Normals under Mesh Structure.\ Also see relevant bpy properties:

Another important thing is that loop normals have to be calculated, see bpy.types.Mesh.calc_normals_split.

Also see this important bit of info on Blender's use of normals: https://github.com/BadDogSkyrim/PyNifly/wiki/Spelunking-the-Blender-Data-Model

bartteunis commented 2 years ago

See the Alembic exporter's notes on Custom Split Normals of Meshes

bartteunis commented 1 year ago

The missing piece appears to be the property MeshVertex.use_smooth. More info on this can be found in this post:: https://blender.stackexchange.com/a/17930

bartteunis commented 1 year ago

After some thorough testing it turns out that the correct normals are always written to the loop normals after a call to calc_normals_split and so can be accessed through the MeshLoop.normal property.

The BMesh library however, which is used in this exporter, doesn't support this (yet, see T45151 - Bmesh module does not support smooth shading / split normals) This may be the root cause, as the prep_mesh function makes use of the BMesh library to apply some transformations to meshes.

bartteunis commented 1 year ago

Another reference to the same issue, confirming the previous comment: https://blender.stackexchange.com/a/249857

Accessing split normals for a bmesh (Edit mode) is unsupported

Always calculate split normals first (Meshloop.normal) and then export those. Don't use BMesh.