Fix missing animations when converting some FBX from json to binary #104911

Merged
Member

Animations would be missing in external software when importing FBX that
have their AnimationLayer or AnimationStack element as the last element
in a block. Importing such files through Blender, however, would import
the animations without issue.

AnimationLayer and AnimationStack elements are an exception to normal
FBX behaviour in that they always need to write a block sentinel after
them. However, this was not happening when the AnimationLayer was the
last element in a block.

With this patch, the block sentinel is now always written for
AnimationLayer and AnimationStack elements.

This patch should only affect FBX files converted from json to binary
with the json2fbx.py script because FBX exported from Blender always
writes the AnimationStack, AnimationLayer and then AnimationCurveNodes
and AnimationCurves of that AnimationLayer, so the only time the
AnimationLayer could be the last element in the block is when there are
no animations in the AnimationLayer to begin with.


I was working on #104684 using the https://archive.blender.org/developer/F13133131/test_track.fbx from #98604 and was finding that the animations would be missing in FBX Review and Unity. Comparing the original file to the file converted to .json and then back to .fbx, I found that the only relevant difference between the two was a sentinel block after the AnimationLayer in the original .fbx, but not in the converted .fbx.

In the converted .json, it can be seen that the AnimationLayer is at the end of its block:
image

Because this is a version 7500+ FBX, the block sentinels are 25 bytes each, so it should be clear that the converted .fbx only has a single block sentinel (from its parent element), whereas the original has both a block sentinel from its parent element and an extra sentinel for the AnimationLayer.
The selected sections aren't exactly the block sentinels because I counted the size wrong, thinking it was 24.

Original Converted
image image
Animations would be missing in external software when importing FBX that have their AnimationLayer or AnimationStack element as the last element in a block. Importing such files through Blender, however, would import the animations without issue. AnimationLayer and AnimationStack elements are an exception to normal FBX behaviour in that they always need to write a block sentinel after them. However, this was not happening when the AnimationLayer was the last element in a block. With this patch, the block sentinel is now always written for AnimationLayer and AnimationStack elements. This patch should only affect FBX files converted from json to binary with the json2fbx.py script because FBX exported from Blender always writes the AnimationStack, AnimationLayer and then AnimationCurveNodes and AnimationCurves of that AnimationLayer, so the only time the AnimationLayer could be the last element in the block is when there are no animations in the AnimationLayer to begin with. --- I was working on #104684 using the https://archive.blender.org/developer/F13133131/test_track.fbx from #98604 and was finding that the animations would be missing in FBX Review and Unity. Comparing the original file to the file converted to .json and then back to .fbx, I found that the only relevant difference between the two was a sentinel block after the AnimationLayer in the original .fbx, but not in the converted .fbx. In the converted .json, it can be seen that the AnimationLayer is at the end of its block: ![image](/attachments/e34a1016-3fbe-4592-94c9-7796ab65cd16) Because this is a version 7500+ FBX, the block sentinels are 25 bytes each, so it should be clear that the converted .fbx only has a single block sentinel (from its parent element), whereas the original has both a block sentinel from its parent element and an extra sentinel for the AnimationLayer. The selected sections aren't exactly the block sentinels because I counted the size wrong, thinking it was 24. | Original | Converted | | -- | -- | | ![image](/attachments/bf86374b-f97d-42b5-b712-e69ad53e5919) | ![image](/attachments/a11b71a3-af70-48ea-ab80-b3f45b85fcfc) |
Thomas Barlow requested review from Bastien Montagne 2023-09-24 01:50:09 +02:00
Thomas Barlow force-pushed fbx_fix_always_sentinel_when_last from a109c60456 to 9b6ea1eca4 2023-10-01 15:01:22 +02:00 Compare
Thomas Barlow changed title from Fix missing animations when converting some FBX from json to binary to Fix missing animations when converting some FBX from json to binary 2023-10-01 15:01:42 +02:00
Thomas Barlow changed target branch from main to blender-v4.0-release 2023-10-01 15:01:43 +02:00
Bastien Montagne approved these changes 2023-10-04 18:01:26 +02:00
Thomas Barlow added 2 commits 2023-10-06 00:02:46 +02:00
Thomas Barlow merged commit dad3a29a12 into blender-v4.0-release 2023-10-06 00:06:11 +02:00
Thomas Barlow deleted branch fbx_fix_always_sentinel_when_last 2023-10-06 00:06:12 +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#104911
No description provided.