Fix #104672: FBX Byte type unsupported #104681

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fbx_byte_type_support_pr into blender-v3.6-release 2023-06-09 14:36:33 +02:00
6 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,7 @@
# Script copyright (C) 2013 Blender Foundation # Script copyright (C) 2013 Blender Foundation
BOOL = b'C'[0] BOOL = b'C'[0]
INT8 = b'Z'[0]
INT16 = b'Y'[0] INT16 = b'Y'[0]
INT32 = b'I'[0] INT32 = b'I'[0]
INT64 = b'L'[0] INT64 = b'L'[0]

View File

@ -56,6 +56,13 @@ class FBXElem:
self.props_type.append(data_types.BOOL) self.props_type.append(data_types.BOOL)
self.props.append(data) self.props.append(data)
def add_int8(self, data):
assert(isinstance(data, int))
data = pack('<b', data)
self.props_type.append(data_types.INT8)
self.props.append(data)
def add_int16(self, data): def add_int16(self, data):
assert(isinstance(data, int)) assert(isinstance(data, int))
data = pack('<h', data) data = pack('<h', data)

View File

@ -28,6 +28,7 @@ for each property.
The types are as follows: The types are as follows:
* 'Z': - INT8
* 'Y': - INT16 * 'Y': - INT16
* 'C': - BOOL * 'C': - BOOL
* 'I': - INT32 * 'I': - INT32
@ -106,6 +107,7 @@ def unpack_array(read, array_type, array_stride, array_byteswap):
read_data_dict = { read_data_dict = {
b'Z'[0]: lambda read: unpack(b'<b', read(1))[0], # 8 bit int
b'Y'[0]: lambda read: unpack(b'<h', read(2))[0], # 16 bit int b'Y'[0]: lambda read: unpack(b'<h', read(2))[0], # 16 bit int
b'C'[0]: lambda read: unpack(b'?', read(1))[0], # 1 bit bool (yes/no) b'C'[0]: lambda read: unpack(b'?', read(1))[0], # 1 bit bool (yes/no)
b'I'[0]: lambda read: unpack(b'<i', read(4))[0], # 32 bit int b'I'[0]: lambda read: unpack(b'<i', read(4))[0], # 32 bit int
@ -221,6 +223,7 @@ def parse(fn, use_namedtuple=True):
data_types = type(array)("data_types") data_types = type(array)("data_types")
data_types.__dict__.update( data_types.__dict__.update(
dict( dict(
INT8 = b'Z'[0],
INT16 = b'Y'[0], INT16 = b'Y'[0],
BOOL = b'C'[0], BOOL = b'C'[0],
INT32 = b'I'[0], INT32 = b'I'[0],

View File

@ -722,6 +722,10 @@ def elem_data_single_bool(elem, name, value):
return _elem_data_single(elem, name, value, "add_bool") return _elem_data_single(elem, name, value, "add_bool")
def elem_data_single_int8(elem, name, value):
return _elem_data_single(elem, name, value, "add_int8")
def elem_data_single_int16(elem, name, value): def elem_data_single_int16(elem, name, value):
return _elem_data_single(elem, name, value, "add_int16") return _elem_data_single(elem, name, value, "add_int16")

View File

@ -27,6 +27,7 @@ for each property.
The types are as follows: The types are as follows:
* 'Z': - INT8
* 'Y': - INT16 * 'Y': - INT16
* 'C': - BOOL * 'C': - BOOL
* 'I': - INT32 * 'I': - INT32
@ -65,6 +66,8 @@ def parse_json_rec(fbx_root, json_node):
for d, dt in zip(data, data_types): for d, dt in zip(data, data_types):
if dt == "C": if dt == "C":
e.add_bool(d) e.add_bool(d)
elif dt == "Z":
e.add_int8(d)
elif dt == "Y": elif dt == "Y":
e.add_int16(d) e.add_int16(d)
elif dt == "I": elif dt == "I":

View File

@ -67,6 +67,7 @@ def unpack_array(read, array_type, array_stride, array_byteswap):
read_data_dict = { read_data_dict = {
b'Z'[0]: lambda read: unpack(b'<b', read(1))[0], # byte
b'Y'[0]: lambda read: unpack(b'<h', read(2))[0], # 16 bit int b'Y'[0]: lambda read: unpack(b'<h', read(2))[0], # 16 bit int
b'C'[0]: lambda read: unpack(b'?', read(1))[0], # 1 bit bool (yes/no) b'C'[0]: lambda read: unpack(b'?', read(1))[0], # 1 bit bool (yes/no)
b'I'[0]: lambda read: unpack(b'<i', read(4))[0], # 32 bit int b'I'[0]: lambda read: unpack(b'<i', read(4))[0], # 32 bit int