Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2016-12-01 15:00:30 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-12-01 15:00:30 +0300
commitecf6619d82058d808a4c17629e96db6b02b29b80 (patch)
treeeddeffdb087952d0cb23c9e43980de38a9e7b9dc /io_blend_utils
parent26b6c193ee9d42c522e9d20e9c3a895c999bfb37 (diff)
blendfile.py: Add support reading single char DNA values as unsigned integer.
A single char is nearly never a string or byte, but rather a small int or bitflag value. ;)
Diffstat (limited to 'io_blend_utils')
-rw-r--r--io_blend_utils/blend/blendfile.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/io_blend_utils/blend/blendfile.py b/io_blend_utils/blend/blendfile.py
index 012719fb..c7a83c38 100644
--- a/io_blend_utils/blend/blendfile.py
+++ b/io_blend_utils/blend/blendfile.py
@@ -768,6 +768,7 @@ class DNAStruct:
dna_type = field.dna_type
dna_name = field.dna_name
+ dna_size = field.dna_size
if dna_name.is_pointer:
return DNA_IO.read_pointer(handle, header)
@@ -788,6 +789,9 @@ class DNAStruct:
return [DNA_IO.read_float(handle, header) for i in range(dna_name.array_size)]
return DNA_IO.read_float(handle, header)
elif dna_type.dna_type_id == b'char':
+ if dna_size == 1:
+ # Single char, assume it's bitflag or int value, and not a string/bytes data...
+ return DNA_IO.read_char(handle, header)
if use_str:
if use_nil:
return DNA_IO.read_string0(handle, dna_name.array_size)
@@ -882,6 +886,13 @@ class DNA_IO:
add = data.find(b'\0')
return data[:add]
+ UCHAR = struct.Struct(b'<b'), struct.Struct(b'>b')
+
+ @staticmethod
+ def read_char(handle, fileheader):
+ st = DNA_IO.UCHAR[fileheader.endian_index]
+ return st.unpack(handle.read(st.size))[0]
+
USHORT = struct.Struct(b'<H'), struct.Struct(b'>H')
@staticmethod