From bd73b9c44df107f3285a6efd477369aecff47409 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Sun, 24 Sep 2023 18:34:28 +0100 Subject: [PATCH 1/2] 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. --- io_scene_fbx/data_types.py | 3 ++- io_scene_fbx/encode_bin.py | 8 ++++++++ io_scene_fbx/export_fbx_bin.py | 12 +++++++++--- io_scene_fbx/fbx2json.py | 9 ++++++--- io_scene_fbx/fbx_utils.py | 4 ++++ io_scene_fbx/json2fbx.py | 8 ++++++-- io_scene_fbx/parse_fbx.py | 3 ++- 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/io_scene_fbx/data_types.py b/io_scene_fbx/data_types.py index ac7b32a42..328ba3a9c 100644 --- a/io_scene_fbx/data_types.py +++ b/io_scene_fbx/data_types.py @@ -3,7 +3,8 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -BOOL = b'C'[0] +BOOL = b'B'[0] +CHAR = b'C'[0] INT8 = b'Z'[0] INT16 = b'Y'[0] INT32 = b'I'[0] diff --git a/io_scene_fbx/encode_bin.py b/io_scene_fbx/encode_bin.py index fe2bef09d..030f960cb 100644 --- a/io_scene_fbx/encode_bin.py +++ b/io_scene_fbx/encode_bin.py @@ -56,6 +56,14 @@ class FBXElem: self.props_type.append(data_types.BOOL) self.props.append(data) + def add_char(self, data): + assert(isinstance(data, bytes)) + assert(len(data) == 1) + data = pack(' Date: Tue, 26 Sep 2023 02:40:53 +0100 Subject: [PATCH 2/2] Increase FBX IO version --- io_scene_fbx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 19d765fcb..75a4ab720 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -5,7 +5,7 @@ bl_info = { "name": "FBX format", "author": "Campbell Barton, Bastien Montagne, Jens Restemeier, @Mysteryem", - "version": (5, 8, 1), + "version": (5, 8, 2), "blender": (3, 6, 0), "location": "File > Import-Export", "description": "FBX IO meshes, UVs, vertex colors, materials, textures, cameras, lamps and actions", -- 2.30.2