Support for mesh external data
also cleaner fix for confusing blend files with textures allow default argument for BlendFileBlock.get()
This commit is contained in:
@@ -344,6 +344,7 @@ class BlendFileBlock:
|
|||||||
self.refine_type_from_index(self.file.sdna_index_from_id[dna_type_id])
|
self.refine_type_from_index(self.file.sdna_index_from_id[dna_type_id])
|
||||||
|
|
||||||
def get(self, path,
|
def get(self, path,
|
||||||
|
default=...,
|
||||||
sdna_index_refine=None,
|
sdna_index_refine=None,
|
||||||
use_nil=True, use_str=True,
|
use_nil=True, use_str=True,
|
||||||
):
|
):
|
||||||
@@ -357,7 +358,9 @@ class BlendFileBlock:
|
|||||||
self.file.handle.seek(self.file_offset, os.SEEK_SET)
|
self.file.handle.seek(self.file_offset, os.SEEK_SET)
|
||||||
return dna_struct.field_get(
|
return dna_struct.field_get(
|
||||||
self.file.header, self.file.handle, path,
|
self.file.header, self.file.handle, path,
|
||||||
use_nil=use_nil, use_str=use_str)
|
default=default,
|
||||||
|
use_nil=use_nil, use_str=use_str,
|
||||||
|
)
|
||||||
|
|
||||||
def set(self, path, value,
|
def set(self, path, value,
|
||||||
sdna_index_refine=None,
|
sdna_index_refine=None,
|
||||||
@@ -605,11 +608,16 @@ class DNAStruct:
|
|||||||
return field.dna_type.field_from_path(header, handle, name_tail)
|
return field.dna_type.field_from_path(header, handle, name_tail)
|
||||||
|
|
||||||
def field_get(self, header, handle, path,
|
def field_get(self, header, handle, path,
|
||||||
use_nil=True, use_str=True):
|
default=...,
|
||||||
|
use_nil=True, use_str=True,
|
||||||
|
):
|
||||||
assert(type(path) == bytes)
|
assert(type(path) == bytes)
|
||||||
|
|
||||||
field = self.field_from_path(header, handle, path)
|
field = self.field_from_path(header, handle, path)
|
||||||
if field is None:
|
if field is None:
|
||||||
|
if default is not ...:
|
||||||
|
return default
|
||||||
|
else:
|
||||||
raise KeyError("%r not found in %r (%r)" % (path, [f.dna_name.name_only for f in self.fields], self.dna_type_id))
|
raise KeyError("%r not found in %r (%r)" % (path, [f.dna_name.name_only for f in self.fields], self.dna_type_id))
|
||||||
|
|
||||||
dna_type = field.dna_type
|
dna_type = field.dna_type
|
||||||
|
@@ -133,6 +133,10 @@ class FilePath:
|
|||||||
return (len_prev != len(expand_codes))
|
return (len_prev != len(expand_codes))
|
||||||
|
|
||||||
def block_expand(block, code):
|
def block_expand(block, code):
|
||||||
|
assert(block.code == code)
|
||||||
|
if code == b'ENDB':
|
||||||
|
return
|
||||||
|
|
||||||
if _expand_codes_add_test(block, code):
|
if _expand_codes_add_test(block, code):
|
||||||
yield block
|
yield block
|
||||||
|
|
||||||
@@ -154,6 +158,10 @@ class FilePath:
|
|||||||
block_codes_idlib = None
|
block_codes_idlib = None
|
||||||
|
|
||||||
def block_expand(block, code):
|
def block_expand(block, code):
|
||||||
|
assert(block.code == code)
|
||||||
|
if code == b'ENDB':
|
||||||
|
return
|
||||||
|
|
||||||
yield block
|
yield block
|
||||||
|
|
||||||
# ------
|
# ------
|
||||||
@@ -290,6 +298,11 @@ class FilePath:
|
|||||||
if fn is not None:
|
if fn is not None:
|
||||||
yield from fn(block, basedir, rootdir, level)
|
yield from fn(block, basedir, rootdir, level)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _from_block_MC(block, basedir, rootdir, level):
|
||||||
|
# TODO, image sequence
|
||||||
|
yield FilePath(block, b'name', basedir, level), rootdir
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _from_block_IM(block, basedir, rootdir, level):
|
def _from_block_IM(block, basedir, rootdir, level):
|
||||||
# (IMA_SRC_FILE, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)
|
# (IMA_SRC_FILE, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)
|
||||||
@@ -301,9 +314,27 @@ class FilePath:
|
|||||||
yield FilePath(block, b'name', basedir, level), rootdir
|
yield FilePath(block, b'name', basedir, level), rootdir
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _from_block_LI(block, basedir, rootdir, level):
|
def _from_block_VF(block, basedir, rootdir, level):
|
||||||
if block[b'packedfile']:
|
if block[b'packedfile']:
|
||||||
return
|
return
|
||||||
|
yield FilePath(block, b'name', basedir, level), rootdir
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _from_block_SO(block, basedir, rootdir, level):
|
||||||
|
if block[b'packedfile']:
|
||||||
|
return
|
||||||
|
yield FilePath(block, b'name', basedir, level), rootdir
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _from_block_ME(block, basedir, rootdir, level):
|
||||||
|
block_external = block.get_pointer(b'ldata.external')
|
||||||
|
if block_external is not None:
|
||||||
|
yield FilePath(block_external, b'filename', basedir, level), rootdir
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _from_block_LI(block, basedir, rootdir, level):
|
||||||
|
if block.get(b'packedfile', None):
|
||||||
|
return
|
||||||
|
|
||||||
yield FilePath(block, b'name', basedir, level), rootdir
|
yield FilePath(block, b'name', basedir, level), rootdir
|
||||||
|
|
||||||
@@ -384,10 +415,6 @@ class ExpandID:
|
|||||||
if item_type != 221: # CMP_NODE_R_LAYERS
|
if item_type != 221: # CMP_NODE_R_LAYERS
|
||||||
yield item.get_pointer(b'id', sdna_index_refine=sdna_index_bNode)
|
yield item.get_pointer(b'id', sdna_index_refine=sdna_index_bNode)
|
||||||
|
|
||||||
# import IPython; IPython.embed()
|
|
||||||
# print(item.get(b'name', sdna_index_refine=sdna_index_bNode))
|
|
||||||
# print(item.get(b'type', sdna_index_refine=sdna_index_bNode))
|
|
||||||
#
|
|
||||||
def _expand_generic_nodetree_id(block):
|
def _expand_generic_nodetree_id(block):
|
||||||
block_ntree = block.get_pointer(b'nodetree')
|
block_ntree = block.get_pointer(b'nodetree')
|
||||||
if block_ntree is not None:
|
if block_ntree is not None:
|
||||||
@@ -419,6 +446,13 @@ class ExpandID:
|
|||||||
yield from ExpandID._expand_generic_animdata(block)
|
yield from ExpandID._expand_generic_animdata(block)
|
||||||
yield from ExpandID._expand_generic_material(block)
|
yield from ExpandID._expand_generic_material(block)
|
||||||
|
|
||||||
|
sub_block = block.get_pointer(b'vfont')
|
||||||
|
if sub_block is not None:
|
||||||
|
yield sub_block
|
||||||
|
yield block.get_pointer(b'vfontb')
|
||||||
|
yield block.get_pointer(b'vfonti')
|
||||||
|
yield block.get_pointer(b'vfontbi')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def expand_MB(block): # 'MBall'
|
def expand_MB(block): # 'MBall'
|
||||||
yield from ExpandID._expand_generic_animdata(block)
|
yield from ExpandID._expand_generic_animdata(block)
|
||||||
@@ -584,7 +618,9 @@ def pack(blendfile_src, blendfile_dst):
|
|||||||
else:
|
else:
|
||||||
fp.filepath = b'//' + path_base
|
fp.filepath = b'//' + path_base
|
||||||
|
|
||||||
# add to copylist
|
# add to copy-list
|
||||||
|
# never copy libs (handled separately)
|
||||||
|
if fp.block.code != b'LI':
|
||||||
path_copy_files.add((path_src, path_dst))
|
path_copy_files.add((path_src, path_dst))
|
||||||
|
|
||||||
del lib_visit
|
del lib_visit
|
||||||
@@ -603,9 +639,6 @@ def pack(blendfile_src, blendfile_dst):
|
|||||||
shutil.copyfile(fn, fn[:-1])
|
shutil.copyfile(fn, fn[:-1])
|
||||||
|
|
||||||
for src, dst in path_copy_files:
|
for src, dst in path_copy_files:
|
||||||
if dst + TEMP_SUFFIX in path_temp_files:
|
|
||||||
continue
|
|
||||||
|
|
||||||
assert(b'.blend' not in dst)
|
assert(b'.blend' not in dst)
|
||||||
|
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
|
Reference in New Issue
Block a user