correct bundle
parent
74724423b4
commit
92f275fcea
|
@ -356,6 +356,7 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
catalog_path.write_text('\n'.join(lines), encoding="utf-8")
|
||||
|
||||
def read_cache(self):
|
||||
print(f'Read cache from {self.cache_file}')
|
||||
return self.read_file(self.cache_file)
|
||||
|
||||
def norm_asset_datas(self, asset_file_datas):
|
||||
|
@ -471,7 +472,7 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
def generate_preview(self, asset_description):
|
||||
"""Only generate preview when conforming a library"""
|
||||
|
||||
#print('generate_preview', filepath, asset_names, data_type)
|
||||
print('\ngenerate_preview', asset_description)
|
||||
|
||||
scn = bpy.context.scene
|
||||
#Creating the preview for collection, object or material
|
||||
|
@ -533,14 +534,18 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
|
||||
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
|
||||
|
||||
def generate_previews(self):
|
||||
cache = self.fetch()
|
||||
def generate_previews(self, asset_descriptions=None):
|
||||
|
||||
print('Generate previews')
|
||||
|
||||
asset_descriptions = asset_descriptions or self.fetch()
|
||||
|
||||
|
||||
#cache_diff.sort(key=lambda x :x['filepath'])
|
||||
#blend_groups = groupby(cache_diff, key=lambda x :x['filepath'])
|
||||
|
||||
#TODO Support all multiple data_type
|
||||
for asset_description in cache:
|
||||
for asset_description in asset_descriptions:
|
||||
self.generate_preview(asset_description)
|
||||
|
||||
# filepath = asset_description['filepath']
|
||||
|
@ -558,11 +563,12 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
def set_asset_preview(self, asset, asset_data):
|
||||
'''Load an externalize image as preview for an asset'''
|
||||
|
||||
image_path = Path(asset_data['image'])
|
||||
if not image_path.is_absolute():
|
||||
image_path = Path(asset_data['filepath'], image_path)
|
||||
name = asset_data['name']
|
||||
asset_path = asset_data['filepath']
|
||||
catalog = asset_data['catalog']
|
||||
|
||||
image_path = self.get_image_path(name, asset_path, catalog)
|
||||
|
||||
image_path = self.format_path(image_path.as_posix())
|
||||
if image_path and image_path.exists():
|
||||
with bpy.context.temp_override(id=asset):
|
||||
bpy.ops.ed.lib_id_load_custom_preview(
|
||||
|
@ -671,12 +677,14 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
write_cache = False
|
||||
if not cache_diff:
|
||||
# Get list of all modifications
|
||||
cache, cache_diff = self.diff()
|
||||
asset_descriptions = self.fetch()
|
||||
|
||||
cache, cache_diff = self.diff(asset_descriptions)
|
||||
|
||||
# Only write complete cache at the end
|
||||
write_cache = True
|
||||
|
||||
self.generate_previews()
|
||||
self.generate_previews(asset_descriptions)
|
||||
|
||||
elif isinstance(cache_diff, (Path, str)):
|
||||
cache_diff = json.loads(Path(cache_diff).read_text(encoding='utf-8'))
|
||||
|
@ -780,7 +788,11 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
""" Return a new flat list of asset data
|
||||
the filepath keys are merge with the assets keys"""
|
||||
|
||||
if not cache or not isinstance(cache[0], dict):
|
||||
return []
|
||||
|
||||
new_cache = []
|
||||
|
||||
for asset_description in cache:
|
||||
asset_description = asset_description.copy()
|
||||
if 'assets' in asset_description:
|
||||
|
@ -793,7 +805,7 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
|
||||
return new_cache
|
||||
|
||||
def diff(self):
|
||||
def diff(self, asset_descriptions=None):
|
||||
"""Compare the library cache with it current state and return the difference"""
|
||||
|
||||
cache = self.read_cache()
|
||||
|
@ -802,12 +814,12 @@ class AssetLibraryAdapter(PropertyGroup):
|
|||
print(f'Fetch The library {self.library.name} for the first time, might be long...')
|
||||
cache = []
|
||||
|
||||
new_cache = self.fetch()
|
||||
asset_descriptions = asset_descriptions or self.fetch()
|
||||
|
||||
#print(cache)
|
||||
#print('\n-------------------------', cache)
|
||||
|
||||
cache = {f"{a['filepath']}/{a['name']}": a for a in self.norm_cache(cache)}
|
||||
new_cache = {f"{a['filepath']}/{a['name']}" : a for a in self.norm_cache(new_cache)}
|
||||
new_cache = {f"{a['filepath']}/{a['name']}" : a for a in self.norm_cache(asset_descriptions)}
|
||||
|
||||
assets_added = [v for k, v in new_cache.items() if k not in cache]
|
||||
assets_removed = [v for k, v in cache.items() if k not in new_cache]
|
||||
|
|
|
@ -88,7 +88,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
|||
]
|
||||
)
|
||||
|
||||
return asset_description
|
||||
return asset_description
|
||||
|
||||
# def bundle(self, cache_diff=None):
|
||||
# """Group all asset in one or multiple blends for the asset browser"""
|
||||
|
@ -120,7 +120,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
|||
entity_types = gazu.client.fetch_all('entity-types')
|
||||
entity_types_ids = {e['id']: e['name'] for e in entity_types}
|
||||
|
||||
new_cache = []
|
||||
asset_descriptions = []
|
||||
for asset_data in gazu.asset.all_assets_for_project(project)[:10]:
|
||||
asset_data['entity_type_name'] = entity_types_ids[asset_data.pop('entity_type_id')]
|
||||
asset_name = asset_data['name']
|
||||
|
@ -139,7 +139,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
|||
|
||||
#print(asset_path)
|
||||
|
||||
new_cache.append(self.get_asset_description(asset_data, asset_path))
|
||||
asset_descriptions.append(self.get_asset_description(asset_data, asset_path))
|
||||
|
||||
#asset = load_datablocks(asset_path, data_type='collections', names=asset_data['name'], link=True)
|
||||
#if not asset:
|
||||
|
@ -148,10 +148,13 @@ class KitsuLibrary(AssetLibraryAdapter):
|
|||
|
||||
#asset_description = self.get_asset_description(asset)
|
||||
|
||||
#new_cache.append(asset_description)
|
||||
#asset_descriptions.append(asset_description)
|
||||
|
||||
#print(assets)
|
||||
# for k, v in assets[0].items():
|
||||
# print(f'- {k} {v}')
|
||||
|
||||
return new_cache
|
||||
#print('+++++++++++++')
|
||||
#print(asset_descriptions)
|
||||
|
||||
return asset_descriptions
|
||||
|
|
2
prefs.py
2
prefs.py
|
@ -294,7 +294,7 @@ class AssetLibrary(PropertyGroup):
|
|||
if 'name' in value:
|
||||
setattr(obj, f'{key}_name', value.pop('name'))
|
||||
|
||||
print('Nested value', getattr(obj, key))
|
||||
#print('Nested value', getattr(obj, key))
|
||||
self.set_dict(value, obj=getattr(obj, key))
|
||||
|
||||
elif key in obj.bl_rna.properties.keys():
|
||||
|
|
Loading…
Reference in New Issue