blender-to-gmstudio / blender-to-smf

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

Blender 4 compatibility #52

Closed bartteunis closed 1 month ago

bartteunis commented 1 month ago

Look into the changes that have been introduced with the Blender 4.X Python API. This appears to include mesh properties and functions related to smooth normals, such as auto_smooth_angle and calc_normals_split() and may include other changes. See Blender 4.1: Python API for the changes to the smooth normals. Also check the others.

It looks like the call to Mesh.calc_normals_split() throws an error, starting from Blender release 4.1. Also happens in Blender 4.2.

bartteunis commented 1 month ago

As far as it looks, the call to Mesh.calc_normals_split() can be simply left out, since MeshLoop.normal is now updated automatically. Comparing Blender 4.0's MeshLoop.normal to Blender 4.2's Meshloop.normal shows that it was necessary before to update custom split normals explicitly. In Blender 4.0's docs:

normal Local space unit length split normal vector of this vertex for this face (must be computed beforehand using calc_normals_split or calc_tangents)

In Blender 4.1's docs and up:

normal The normal direction of the face corner, taking into account sharp faces, sharp edges, and custom normal data

It should be safe to leave out the call to Mesh.calc_normals_split() when the value contained in bpy.app.version >= 4.1.

Exporter docs should also mention this change to custom split normals and refer to official Blender docs to provide more clarity.

bartteunis commented 1 month ago

Tested with a basic cube model in Blender 3.4 and 4.1. Normal and tangent values can be found in the mBuff buffer (debugged by setting a breakpoint in smf_model_load_from_buffer()).