Skip to content

Commit

Permalink
Merge pull request #2 from AdrienTD/main
Browse files Browse the repository at this point in the history
Correct 16-bit float decoding for compressed keyframes
  • Loading branch information
Psycrow101 authored Feb 13, 2023
2 parents e591fb5 + ab6b1f7 commit 4da456f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion io_scene_rw_anm/anm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
ANM_ACTION_PARENT_NONE_OFFSET = 0xFF30C9D8


def decode_float16(value):
sign = -1.0 if (value >> 15) else 1.0
if (value & 0x7FFF) == 0:
return sign * 0.0
exponent = ((value >> 11) & 15) - 15
mantissa = (value & 0x07FF) / 0x800 + 1.0
return sign * mantissa * 2**exponent


def read_float16(fd, num=1, en='<'):
res = struct.unpack('%s%de' % (en, num), fd.read(2 * num))
res = struct.unpack('%s%dH' % (en, num), fd.read(2 * num))
res = tuple(map(decode_float16, res))
return res if num > 1 else res[0]


Expand Down

0 comments on commit 4da456f

Please sign in to comment.