Fix duplicate shape key import when the FBX connections are duplicated #104954

Merged
Member

Rarely, FBX files with duplicate ShapeKey-related connections are
encountered. The FBX IO addon would add a ShapeKey for each duplicate,
however external software appears to ignore the duplicates, or
overwrite the existing duplicates such that the same effect as ignoring
new duplicates is achieved.

This patch modifies the FBX importer to skip all duplicate ShapeKey-
related connections when finding the ShapeKeys to add to each Mesh.

While it is unclear if they are ever encountered, importing multi-user
Shapes/BlendShapeChannels/etc. as single-users remains supported, e.g.
a Mesh with a BlendShape with two different BlendShapeChannels that both
have the same Shape will still import that Shape as two separate
ShapeKeys.

The code needed for iterating through each type of connection was
duplicated and was getting rather large with the newly added code, so
it has been refactored into calling a generator helper function.

The outermost loop had an unnecessary line of code that would re-get
values from fbx_table_nodes, this has been removed.


The attached .fbx is a default cube with "Move Up" and "Move Down" ShapeKeys added, but I have modified it by duplicating each of the ShapeKey-related connections once. With the old code, this would import 8 copies of each ShapeKey. With this patch, only a single ShapeKey of each is imported.

This fixes the import of hundreds of thousands of Shape Keys when importing the files in #104909 due to their excessively duplicated connections, but the import will still fail due to #84111 because the files contain extraneous FullWeights.

Rarely, FBX files with duplicate ShapeKey-related connections are encountered. The FBX IO addon would add a ShapeKey for each duplicate, however external software appears to ignore the duplicates, or overwrite the existing duplicates such that the same effect as ignoring new duplicates is achieved. This patch modifies the FBX importer to skip all duplicate ShapeKey- related connections when finding the ShapeKeys to add to each Mesh. While it is unclear if they are ever encountered, importing multi-user Shapes/BlendShapeChannels/etc. as single-users remains supported, e.g. a Mesh with a BlendShape with two different BlendShapeChannels that both have the same Shape will still import that Shape as two separate ShapeKeys. The code needed for iterating through each type of connection was duplicated and was getting rather large with the newly added code, so it has been refactored into calling a generator helper function. The outermost loop had an unnecessary line of code that would re-get values from `fbx_table_nodes`, this has been removed. --- The attached .fbx is a default cube with "Move Up" and "Move Down" ShapeKeys added, but I have modified it by duplicating each of the ShapeKey-related connections once. With the old code, this would import 8 copies of each ShapeKey. With this patch, only a single ShapeKey of each is imported. This fixes the import of hundreds of thousands of Shape Keys when importing the files in #104909 due to their excessively duplicated connections, but the import will still fail due to #84111 because the files contain extraneous FullWeights.
Thomas Barlow added 2 commits 2023-10-15 05:02:23 +02:00
b2cfaa146d Fix duplicate shape key import when FBX connections are duplicated
Added some comments explaining the different FBX types and their
relationships.

Removed an unnecessary re-get, of the Shape being iterated, from
fbx_table_nodes.
31157d409d Deduplicate shape key connection iteration code
The main loop was getting rather long so its inner loops have been
replaced with a helper generator function.
Thomas Barlow requested review from Bastien Montagne 2023-10-16 05:25:35 +02:00
Bastien Montagne approved these changes 2023-10-16 11:32:04 +02:00
Thomas Barlow added 2 commits 2023-10-18 17:21:30 +02:00
Thomas Barlow merged commit 1edbfe9249 into blender-v4.0-release 2023-10-18 17:24:37 +02:00
Thomas Barlow deleted branch fbx_fix_duplicate_shapekey_connections 2023-10-18 17:24:38 +02: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#104954
No description provided.