start kitsu adapter
This commit is contained in:
+32
-8
@@ -16,6 +16,8 @@ import shutil
|
||||
import os
|
||||
import json
|
||||
import uuid
|
||||
import time
|
||||
from functools import partial
|
||||
|
||||
|
||||
class AssetLibraryAdapter(PropertyGroup):
|
||||
@@ -59,8 +61,20 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||
def data_types(self):
|
||||
return self.library.data_types
|
||||
|
||||
@property
|
||||
def is_conform(self):
|
||||
prefs = self.addon_prefs
|
||||
for lib in prefs.libraries:
|
||||
if lib.adapter == self:
|
||||
return False
|
||||
if lib.conform.adapter == self:
|
||||
return True
|
||||
|
||||
@property
|
||||
def blend_depth(self):
|
||||
if self.is_conform:
|
||||
return self.library.conform.blend_depth
|
||||
|
||||
return self.library.blend_depth
|
||||
|
||||
@property
|
||||
@@ -331,19 +345,28 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||
return
|
||||
|
||||
#Creating the preview for collection, object or material
|
||||
src_asset = self.load_datablocks(asset_data['filepath'], names=asset_data['name'], link=True, type=self.data_types)
|
||||
src_asset = self.load_datablocks(asset_data['filepath'], names=asset_data['name'], link=False, type=self.data_types)
|
||||
if not src_asset:
|
||||
print(f'No asset named {asset_data["name"]} in {asset_data["filepath"]}')
|
||||
return
|
||||
|
||||
bpy.ops.ed.lib_id_generate_preview({"id": src_asset})
|
||||
#time.sleep(0.01)
|
||||
|
||||
#Transfering pixels between previews
|
||||
pixels = [0] * (128*128*4)
|
||||
w, h = src_asset.preview.image_size
|
||||
pixels = [0] * (w*h*4)
|
||||
src_asset.preview.image_pixels_float.foreach_get(pixels)
|
||||
|
||||
asset.preview_ensure()
|
||||
asset.preview.image_size = src_asset.preview.image_size
|
||||
asset.preview.image_pixels_float.foreach_set(pixels)
|
||||
|
||||
getattr(bpy.data, self.data_types).remove(src_asset)
|
||||
#print('pixels transfered')
|
||||
|
||||
bpy.app.timers.register(partial(getattr(bpy.data, self.data_types).remove, src_asset), first_interval=1)
|
||||
|
||||
#getattr(bpy.data, self.data_types).remove(src_asset)
|
||||
|
||||
|
||||
def set_asset_catalog(self, asset, asset_data, catalog_data):
|
||||
@@ -408,7 +431,7 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||
else:
|
||||
cache_diff.sort(key=self.group_key)
|
||||
groups = groupby(cache_diff, key=self.group_key)
|
||||
|
||||
|
||||
total_assets = len(cache_diff)
|
||||
print(f'total_assets={total_assets}')
|
||||
|
||||
@@ -474,14 +497,13 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||
blend_path.parent.mkdir(exist_ok=True, parents=True)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(blend_path), compress=True)
|
||||
|
||||
if write_cache:
|
||||
self.write_cache(cache)
|
||||
#if write_cache:
|
||||
# self.write_cache(cache)
|
||||
|
||||
self.write_catalog(catalog_data)
|
||||
#self.write_catalog(catalog_data)
|
||||
|
||||
bpy.ops.wm.quit_blender()
|
||||
|
||||
|
||||
def norm_cache(self, cache):
|
||||
""" Return a new flat list of asset data
|
||||
the filepath keys are merge with the assets keys"""
|
||||
@@ -510,6 +532,8 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||
|
||||
new_cache = self.fetch()
|
||||
|
||||
#print(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)}
|
||||
|
||||
|
||||
+7
-7
@@ -21,8 +21,6 @@ import urllib3
|
||||
import traceback
|
||||
import time
|
||||
|
||||
gazu = install_module('gazu')
|
||||
|
||||
|
||||
class KitsuLibrary(AssetLibraryAdapter):
|
||||
|
||||
@@ -38,6 +36,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||
def connect(self, url=None, login=None, password=None):
|
||||
'''Connect to kitsu api using provided url, login and password'''
|
||||
|
||||
gazu = install_module('gazu')
|
||||
urllib3.disable_warnings()
|
||||
|
||||
if not self.url:
|
||||
@@ -74,7 +73,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||
asset_name = self.norm_file_name(data['name'])
|
||||
|
||||
asset_description = dict(
|
||||
filepath='{source_directory}/' + asset_path.as_posix(),
|
||||
filepath=asset_path.as_posix(),
|
||||
modified=modified,
|
||||
library_id=self.library.id,
|
||||
assets=[dict(
|
||||
@@ -91,10 +90,10 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||
|
||||
return asset_description
|
||||
|
||||
def bundle(self, cache_diff=None):
|
||||
"""Group all asset in one or multiple blends for the asset browser"""
|
||||
# def bundle(self, cache_diff=None):
|
||||
# """Group all asset in one or multiple blends for the asset browser"""
|
||||
|
||||
return super().bundle(cache_diff=cache_diff)
|
||||
# return super().bundle(cache_diff=cache_diff)
|
||||
|
||||
def get_preview(self, asset_data):
|
||||
|
||||
@@ -116,6 +115,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||
|
||||
print(f'Fetch Assets for {self.library.name}')
|
||||
|
||||
gazu = install_module('gazu')
|
||||
self.connect()
|
||||
|
||||
template_file = Template(self.template_file)
|
||||
@@ -126,7 +126,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||
entity_types_ids = {e['id']: e['name'] for e in entity_types}
|
||||
|
||||
new_cache = []
|
||||
for asset_data in gazu.asset.all_assets_for_project(project):
|
||||
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']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user