FBX IO: Export normals matching the mesh's normals_domain #104976

Merged
Thomas Barlow merged 4 commits from Mysteryem/blender-addons:fbx_update_for_auto_smooth into main 2023-11-03 16:42:29 +01:00
Member

The appropriate normals array and FBX layer mapping are now used
according to the Mesh.normals_domain property.

This results in slightly faster exports with smaller file size when
meshes are either fully smooth shaded or fully flat shaded because the
FACE and POINT domains almost always have fewer normals than the CORNER
domain and never have more (a fully smooth shaded mesh where each face
has its own vertices would be POINT domain with as many vertices as
corners).

Additionally, getting the normals from the new Mesh.corner_normals
property runs in about 60% of the time of getting the normals through
MeshLoop.normal.

For me with a subdivided cube with 185856 corners:
MeshLoop.normal: ~6.7ms
Mesh.corner_normals: ~4.0ms

Import is unaffected, because only custom split normals can be set.


If blender/blender#114063 makes it into Main, then getting normals through Mesh.corner_normals (and the other normals arrays) is much faster and runs in about 7.2% of the time of getting the normals through MeshLoop.normal, at ~0.5ms for a subdivided cube with 185856 corners.


Attached is a source .blend (authored in 4.1.0a) and .fbx created using the changes in this PR. The files have 1 Cube and 1 Suzanne for each Mesh.normals_domain value.

All meshes in the .fbx display as expected for me in FBX Review, Unity 2019 (and later) and Microsoft 3D Viewer, I have not tried other external software. If there are issues with some external software, getting this change in now during 4.1 Bcon1 will hopefully identify the issues before release.
image

The appropriate normals array and FBX layer mapping are now used according to the Mesh.normals_domain property. This results in slightly faster exports with smaller file size when meshes are either fully smooth shaded or fully flat shaded because the FACE and POINT domains almost always have fewer normals than the CORNER domain and never have more (a fully smooth shaded mesh where each face has its own vertices would be POINT domain with as many vertices as corners). Additionally, getting the normals from the new Mesh.corner_normals property runs in about 60% of the time of getting the normals through MeshLoop.normal. For me with a subdivided cube with 185856 corners: MeshLoop.normal: ~6.7ms Mesh.corner_normals: ~4.0ms Import is unaffected, because only custom split normals can be set. --- If https://projects.blender.org/blender/blender/pulls/114063 makes it into Main, then getting normals through Mesh.corner_normals (and the other normals arrays) is much faster and runs in about 7.2% of the time of getting the normals through MeshLoop.normal, at ~0.5ms for a subdivided cube with 185856 corners. --- Attached is a source .blend (authored in 4.1.0a) and .fbx created using the changes in this PR. The files have 1 Cube and 1 Suzanne for each Mesh.normals_domain value. All meshes in the .fbx display as expected for me in FBX Review, Unity 2019 (and later) and Microsoft 3D Viewer, I have not tried other external software. If there are issues with some external software, getting this change in now during 4.1 Bcon1 will hopefully identify the issues before release. ![image](/attachments/55f51111-716a-49ae-879f-1ed66a1a9a6a)
Thomas Barlow added 1 commit 2023-10-28 16:32:47 +02:00
f78321c58c FBX IO: Export normals matching the mesh's normals_domain
The appropriate normals array and FBX layer mapping are now used
according to the Mesh.normals_domain property.

This results in slightly faster exports with smaller file size when
meshes are either fully smooth shaded or fully flat shaded because the
FACE and POINT domains almost always have fewer normals than the CORNER
domain and never have more (a fully smooth shaded mesh where each face
has its own vertices would be POINT domain with as many vertices as
corners).

Additionally, getting the normals from the new Mesh.corner_normals
property runs in about 60% of the time of getting the normals through
MeshLoop.normal.

For me with a subdivided cube with 185856 corners:
MeshLoop.normal: ~6.7ms
Mesh.corner_normals: ~4.0ms

Import is unaffected, because only custom split normals can be set.
Thomas Barlow requested review from Bastien Montagne 2023-10-28 16:35:34 +02:00
Bastien Montagne approved these changes 2023-10-30 16:23:07 +01:00
Bastien Montagne left a comment
Owner

Patch LGTM, minor point raised in comment below can be addressed without needing another review imho.

Patch LGTM, minor point raised in comment below can be addressed without needing another review imho.
@ -1176,3 +1194,3 @@
# Since we don't care about how the normals are sorted, only that they're unique, we can use the fast unique
# helper function.
t_ln, t_lnidx = fast_first_axis_unique(t_ln.reshape(-1, 3), return_inverse=True)
t_normal, t_lnidx = fast_first_axis_unique(t_normal.reshape(-1, 3), return_inverse=True)

Shouldn't t_lnidx variable also be renamed, maybe to t_normal_idx then?

Shouldn't `t_lnidx` variable also be renamed, maybe to `t_normal_idx` then?
Thomas Barlow added 3 commits 2023-11-03 16:33:13 +01:00
a811d2fce8 Rename missed unused variables
Since the normals are no longer always loop/corner normals the "l" in
the variable names doesn't make sense anymore.

A few variable names were missed in the disabled "IndexToDirect"
code and comments.
09ac5449e6 Increase FBX minor version
This patch changes the output format of normals in some cases, so is
worth a minor version increase.
Thomas Barlow merged commit 3d823efc57 into main 2023-11-03 16:42:29 +01:00
Thomas Barlow deleted branch fbx_update_for_auto_smooth 2023-11-03 16:42:29 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#104976
No description provided.