FBX IO: Export normals with IndexToDirect reference mode #105020

Merged
Thomas Barlow merged 3 commits from Mysteryem/blender-addons:fbx_normals_IndexToDirect into main 2023-12-02 02:08:21 +01:00
Member

The FBX SDK documentation says that normals should be IndexToDirect
mapped. 9 years ago, we didn't export with IndexToDirect mode because
apps at the time didn't support it well.

9 years is a long time and the apps I've tried all work with
IndexToDirect, so the export of normals has been updated to use the
IndexToDirect mode, using the already existing, but disabled code.

This will slightly increase export times, and will slightly increase
exported file size in cases that don't have lots of duplicate normals.

In the worst case scenario of exporting only geometry with the 'CORNER'
normals domain and nothing else, exports can be about 1.28 times slower
and result in a about a 1.08 times larger file size.

The FBX importer was not previously set up to handle the import of
ByVertice-IndexToDirect normals, so this has been added to ensure that
the normals of FBX IO exported .fbx files are imported correctly.

If older versions of FBX IO attempt to import ByVertice-IndexToDirect
normals, a warning will be printed to the System Console that the
mapping type and ref type are not supported and custom normals will not
be set. However, the normals of the imported mesh will still match the
expected imported normals because they are the same as the imported
mesh's vertex normals. This is only applicable to ByVertice normals
exported by FBX IO, because they are only exported when
Mesh.normals_domain is 'POINT', which requires no sharp edges, no
sharp faces and no custom normals.


FBX SDK documentation specifies in the normals layer's detailed description that it should use IndexToDirect, though it does not elaborate on why: https://help.autodesk.com/view/FBX/2020/ENU/?guid=FBX_Developer_Help_cpp_ref_class_fbx_layer_element_normal_html

This isn't a strictly necessary change, since the Direct reference mode seems to be working fine in external apps, but it at least gets rid of having some code commented out by if 0:.

The worst case scenario for export duration I could come up with is exporting plain geometry with no extra layers, but with custom normals, so that corner normals (the largest normals domain) are exported. In that case, export duration is 1.28 times slower:
Exporting 16 default cubes each subdivided 6 times and with custom normals:
Before: 0.59s
After: 0.75s
1.28 times slower and 1.08 times larger file size.

My typical rigged character model exports are around 1.02 to 1.04 times slower, with export times before ranging from about 3.0s to 0.2s respectively. The larger exports tend to have more data to export that isn't normals, so they are comparatively less affected.

The FBX SDK documentation says that normals should be IndexToDirect mapped. 9 years ago, we didn't export with IndexToDirect mode because apps at the time didn't support it well. 9 years is a long time and the apps I've tried all work with IndexToDirect, so the export of normals has been updated to use the IndexToDirect mode, using the already existing, but disabled code. This will slightly increase export times, and will slightly increase exported file size in cases that don't have lots of duplicate normals. In the worst case scenario of exporting only geometry with the 'CORNER' normals domain and nothing else, exports can be about 1.28 times slower and result in a about a 1.08 times larger file size. The FBX importer was not previously set up to handle the import of ByVertice-IndexToDirect normals, so this has been added to ensure that the normals of FBX IO exported .fbx files are imported correctly. If older versions of FBX IO attempt to import ByVertice-IndexToDirect normals, a warning will be printed to the System Console that the mapping type and ref type are not supported and custom normals will not be set. However, the normals of the imported mesh will still match the expected imported normals because they are the same as the imported mesh's vertex normals. This is only applicable to ByVertice normals exported by FBX IO, because they are only exported when `Mesh.normals_domain` is `'POINT'`, which requires no sharp edges, no sharp faces and no custom normals. --- FBX SDK documentation specifies in the normals layer's detailed description that it should use IndexToDirect, though it does not elaborate on why: https://help.autodesk.com/view/FBX/2020/ENU/?guid=FBX_Developer_Help_cpp_ref_class_fbx_layer_element_normal_html This isn't a strictly necessary change, since the Direct reference mode seems to be working fine in external apps, but it at least gets rid of having some code commented out by `if 0:`. The worst case scenario for export duration I could come up with is exporting plain geometry with no extra layers, but with custom normals, so that corner normals (the largest normals domain) are exported. In that case, export duration is 1.28 times slower: Exporting 16 default cubes each subdivided 6 times and with custom normals: Before: 0.59s After: 0.75s 1.28 times slower and 1.08 times larger file size. My typical rigged character model exports are around 1.02 to 1.04 times slower, with export times before ranging from about 3.0s to 0.2s respectively. The larger exports tend to have more data to export that isn't normals, so they are comparatively less affected.
Thomas Barlow added 1 commit 2023-11-22 05:50:23 +01:00
The FBX SDK documentation says that normals should be IndexToDirect
mapped. 9 years ago, we didn't export with IndexToDirect mode because
apps at the time didn't support it well.

9 years is a long time and the apps I've tried all work with
IndexToDirect, so the export of normals has been updated to use the
IndexToDirect mode, using the already existing, but disabled code.

The FBX importer was not previously set up to handle the import of
ByVertice-IndexToDirect normals, so this has been added to ensure that
FBX IO exported .fbx files can also be imported.
Thomas Barlow changed title from WIP: FBX IO: Export normals with IndexToDirect reference mode to FBX IO: Export normals with IndexToDirect reference mode 2023-11-23 03:00:27 +01:00
Thomas Barlow requested review from Bastien Montagne 2023-11-23 03:01:14 +01:00
Bastien Montagne approved these changes 2023-11-27 12:14:42 +01:00
Bastien Montagne left a comment
Owner

LGTM

LGTM
Author
Member

I've added an extra paragraph to the description clarifying the behaviour of importing ByVertice-IndexToDirect normals with older versions of the FBX IO addon (reproduced below). Simply put, the normals of the imported mesh will be as expected, but custom normals will not be set.

If older versions of FBX IO attempt to import ByVertice-IndexToDirect
normals, a warning will be printed to the System Console that the
mapping type and ref type are not supported and custom normals will not
be set. However, the normals of the imported mesh will still match the
expected imported normals because they they are the same as the imported
mesh's vertex normals. This is only applicable to ByVertice normals
exported by FBX IO, because they are only exported when
Mesh.normals_domain is 'POINT', which requires no sharp edges, no
sharp faces and no custom normals.

I've added an extra paragraph to the description clarifying the behaviour of importing ByVertice-IndexToDirect normals with older versions of the FBX IO addon (reproduced below). Simply put, the normals of the imported mesh will be as expected, but custom normals will not be set. > If older versions of FBX IO attempt to import ByVertice-IndexToDirect normals, a warning will be printed to the System Console that the mapping type and ref type are not supported and custom normals will not be set. However, the normals of the imported mesh will still match the expected imported normals because they they are the same as the imported mesh's vertex normals. This is only applicable to ByVertice normals exported by FBX IO, because they are only exported when `Mesh.normals_domain` is `'POINT'`, which requires no sharp edges, no sharp faces and no custom normals.
Thomas Barlow added 2 commits 2023-12-02 02:04:28 +01:00
Thomas Barlow merged commit 791b042c3a into main 2023-12-02 02:08:21 +01:00
Thomas Barlow deleted branch fbx_normals_IndexToDirect 2023-12-02 02:08:21 +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#105020
No description provided.