# SPDX-License-Identifier: GPL-2.0-or-later # Script copyright (C) 2013 Campbell Barton try: from . import data_types except: import data_types from struct import pack import array import zlib _BLOCK_SENTINEL_LENGTH = 13 _BLOCK_SENTINEL_DATA = (b'\0' * _BLOCK_SENTINEL_LENGTH) _IS_BIG_ENDIAN = (__import__("sys").byteorder != 'little') _HEAD_MAGIC = b'Kaydara FBX Binary\x20\x20\x00\x1a\x00' # fbx has very strict CRC rules, all based on file timestamp # until we figure these out, write files at a fixed time. (workaround!) # Assumes: CreationTime _TIME_ID = b'1970-01-01 10:00:00:000' _FILE_ID = b'\x28\xb3\x2a\xeb\xb6\x24\xcc\xc2\xbf\xc8\xb0\x2a\xa9\x2b\xfc\xf1' _FOOT_ID = b'\xfa\xbc\xab\x09\xd0\xc8\xd4\x66\xb1\x76\xfb\x83\x1c\xf7\x26\x7e' # Awful exceptions: those "classes" of elements seem to need block sentinel even when having no children and some props. _ELEMS_ID_ALWAYS_BLOCK_SENTINEL = {b"AnimationStack", b"AnimationLayer"} class FBXElem: __slots__ = ( "id", "props", "props_type", "elems", "_props_length", # combine length of props "_end_offset", # byte offset from the start of the file. ) def __init__(self, id): assert(len(id) < 256) # length must fit in a uint8 self.id = id self.props = [] self.props_type = bytearray() self.elems = [] self._end_offset = -1 self._props_length = -1 def add_bool(self, data): assert(isinstance(data, bool)) data = pack('?', data) self.props_type.append(data_types.BOOL) self.props.append(data) def add_int16(self, data): assert(isinstance(data, int)) data = pack('