minor edits to blendfile
This commit is contained in:
@@ -19,10 +19,10 @@
|
|||||||
# (c) 2009, At Mind B.V. - Jeroen Bakker
|
# (c) 2009, At Mind B.V. - Jeroen Bakker
|
||||||
# (c) 2014, Blender Foundation - Campbell Barton
|
# (c) 2014, Blender Foundation - Campbell Barton
|
||||||
|
|
||||||
|
import gzip
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import logging
|
|
||||||
import gzip
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
log = logging.getLogger("blendfile")
|
log = logging.getLogger("blendfile")
|
||||||
@@ -79,9 +79,8 @@ def open_blend(filename, access="rb"):
|
|||||||
raise Exception("filetype not a blend or a gzip blend")
|
raise Exception("filetype not a blend or a gzip blend")
|
||||||
|
|
||||||
|
|
||||||
def align(offset, by):
|
def pad_up_4(offset):
|
||||||
n = by - 1
|
return (offset + 3) & ~3
|
||||||
return (offset + n) & ~n
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@@ -168,10 +167,9 @@ class BlendFile:
|
|||||||
Close the blend file
|
Close the blend file
|
||||||
writes the blend file to disk if changes has happened
|
writes the blend file to disk if changes has happened
|
||||||
"""
|
"""
|
||||||
if not self.is_modified:
|
|
||||||
self.handle.close()
|
|
||||||
else:
|
|
||||||
handle = self.handle
|
handle = self.handle
|
||||||
|
|
||||||
|
if self.is_modified:
|
||||||
if self.is_compressed:
|
if self.is_compressed:
|
||||||
log.debug("close compressed blend file")
|
log.debug("close compressed blend file")
|
||||||
handle.seek(os.SEEK_SET, 0)
|
handle.seek(os.SEEK_SET, 0)
|
||||||
@@ -223,7 +221,7 @@ class BlendFile:
|
|||||||
names.append(DNAName(tName))
|
names.append(DNAName(tName))
|
||||||
del names_len
|
del names_len
|
||||||
|
|
||||||
offset = align(offset, 4)
|
offset = pad_up_4(offset)
|
||||||
offset += 4
|
offset += 4
|
||||||
types_len = intstruct.unpack_from(data, offset)[0]
|
types_len = intstruct.unpack_from(data, offset)[0]
|
||||||
offset += 4
|
offset += 4
|
||||||
@@ -234,7 +232,7 @@ class BlendFile:
|
|||||||
types.append(DNAStruct(dna_type_id))
|
types.append(DNAStruct(dna_type_id))
|
||||||
offset += len(dna_type_id) + 1
|
offset += len(dna_type_id) + 1
|
||||||
|
|
||||||
offset = align(offset, 4)
|
offset = pad_up_4(offset)
|
||||||
offset += 4
|
offset += 4
|
||||||
log.debug("building #%d type-lengths" % types_len)
|
log.debug("building #%d type-lengths" % types_len)
|
||||||
for i in range(types_len):
|
for i in range(types_len):
|
||||||
@@ -243,7 +241,7 @@ class BlendFile:
|
|||||||
types[i].size = tLen
|
types[i].size = tLen
|
||||||
del types_len
|
del types_len
|
||||||
|
|
||||||
offset = align(offset, 4)
|
offset = pad_up_4(offset)
|
||||||
offset += 4
|
offset += 4
|
||||||
|
|
||||||
structs_len = intstruct.unpack_from(data, offset)[0]
|
structs_len = intstruct.unpack_from(data, offset)[0]
|
||||||
|
Reference in New Issue
Block a user