Fix FBX char type being interpreted as bool #104914

Merged
Thomas Barlow merged 2 commits from Mysteryem/blender-addons:fbx_fix_char_type into main 2023-09-26 03:44:45 +02:00
Member

Blender has been interpreting the FBX 'C' type as bool, however, it is
actually an 8-bit integer that is separate from the already existing
byte/int8 type. FBX does have 'B' as a bool type, but it seems to be
unused.

FBX Converter displays what it calls "byte" ('Z' type) numerically,
but displays what it calls "int8" ('C' type) with both the numeric value
and the ascii character for that value, which leads me to believe that
this 'C' type should be interpreted as a single char. While there
doesn't appear to be many places that the 'C' type is used, it appears
to usually be set to a printable character.

Python doesn't have a char type, so the single char is read and
written as bytes with length equal to 1.

There are no expected changes to the import or export of FBX files with
this patch because the only FBX element that was incorrectly being
exported as a bool is now exported as the '\x01' char, which has the
same raw value as the True value that was being exported before.

The main benefit to this patch is that FBX files converted to .json with
fbx2json.py (and optionally back to .fbx with json2fbx.py) will now
maintain any 'C' type values instead of reducing them to True or False.

Additionally, should FBX files using the 'B' bool type be encountered in
the future, they are now supported.


The different types as seen in FBX Converter

'Z' (byte/int8) 'C' (char) 'B' (bool)
image image image image
Blender has been interpreting the FBX 'C' type as bool, however, it is actually an 8-bit integer that is separate from the already existing byte/int8 type. FBX does have 'B' as a bool type, but it seems to be unused. FBX Converter displays what it calls "byte" ('Z' type) numerically, but displays what it calls "int8" ('C' type) with both the numeric value and the ascii character for that value, which leads me to believe that this 'C' type should be interpreted as a single `char`. While there doesn't appear to be many places that the 'C' type is used, it appears to usually be set to a printable character. Python doesn't have a `char` type, so the single `char` is read and written as `bytes` with length equal to 1. There are no expected changes to the import or export of FBX files with this patch because the only FBX element that was incorrectly being exported as a bool is now exported as the '\x01' char, which has the same raw value as the `True` value that was being exported before. The main benefit to this patch is that FBX files converted to .json with fbx2json.py (and optionally back to .fbx with json2fbx.py) will now maintain any 'C' type values instead of reducing them to True or False. Additionally, should FBX files using the 'B' bool type be encountered in the future, they are now supported. --- The different types as seen in FBX Converter | 'Z' (byte/int8) | 'C' (char) | 'B' (bool) | | -- | -- | -- | | ![image](/attachments/31ede6fd-a151-4732-804c-6c60318de879) | ![image](/attachments/9d2d7e78-9ad9-4e2d-a180-9ba0aeb1ecfd) ![image](/attachments/d35234f8-11f7-44b3-a606-d666a12a7a9e) | ![image](/attachments/369da6d3-d522-4712-b575-023cdfed47eb) |
Thomas Barlow added 1 commit 2023-09-25 05:23:43 +02:00
bd73b9c44d Fix FBX char type being interpreted as bool
Blender has been interpreting the FBX 'C' type as bool, however, it is
actually an 8-bit integer that is separate from the already existing
byte/int8 type. FBX does have 'B' as a bool type, but it seems to be
unused.

FBX Converter displays what it calls "byte" ('Z' type) numerically,
but displays what it calls "int8" ('C' type) with both the numeric value
and the ascii character for that value, which leads me to believe that
this 'C' type should be interpreted as a single `char`. While there
doesn't appear to be many places that the 'C' type is used, it appears
to usually be set to a printable character.

Python doesn't have a `char` type, so the single `char` is read and
written as `bytes` with length equal to 1.

There are no expected changes to the import or export of FBX files with
this patch because the only FBX element that was incorrectly being
exported as a bool is now exported as the '\x01' char, which has the
same raw value as the `True` value that was being exported before.

The main benefit to this patch is that FBX files converted to .json with
fbx2json.py (and optionally back to .fbx with json2fbx.py) will now
maintain any 'C' type values instead of reducing them to True or False.

Additionally, should FBX files using the 'B' bool type be encountered in
the future, they are now supported.
Thomas Barlow requested review from Bastien Montagne 2023-09-25 05:25:30 +02:00
Bastien Montagne approved these changes 2023-09-25 16:37:09 +02:00
Bastien Montagne left a comment
Owner

Nice find... Gotta love the opacity of FBX specs :(

Nice find... Gotta love the opacity of FBX specs :(
Thomas Barlow added 1 commit 2023-09-26 03:41:26 +02:00
Thomas Barlow merged commit d6ea3b5452 into main 2023-09-26 03:44:45 +02:00
Thomas Barlow deleted branch fbx_fix_char_type 2023-09-26 03:44:46 +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#104914
No description provided.