BlenderKit: fix data update
-older fines could act as broken
(cherry picked from commit e1dae55cca
)
This commit is contained in:
parent
06181ee994
commit
fb3d2715ce
|
@ -88,6 +88,8 @@ def append_scene(file_name, scenename=None, link=False, fake_user=False):
|
|||
def link_collection(file_name, obnames=[], location=(0, 0, 0), link=False, parent = None, **kwargs):
|
||||
'''link an instanced group - model type asset'''
|
||||
sel = utils.selection_get()
|
||||
print('link collection')
|
||||
print(kwargs)
|
||||
|
||||
with bpy.data.libraries.load(file_name, link=link, relative=True) as (data_from, data_to):
|
||||
scols = []
|
||||
|
@ -115,6 +117,12 @@ def link_collection(file_name, obnames=[], location=(0, 0, 0), link=False, paren
|
|||
main_object.instance_collection = col
|
||||
break;
|
||||
|
||||
#sometimes, the lib might already be without the actual link.
|
||||
if not main_object.instance_collection and kwargs['name']:
|
||||
col = bpy.data.collections.get(kwargs['name'])
|
||||
if col:
|
||||
main_object.instance_collection = col
|
||||
|
||||
main_object.name = main_object.instance_collection.name
|
||||
|
||||
# bpy.ops.wm.link(directory=file_name + "/Collection/", filename=kwargs['name'], link=link, instance_collections=True,
|
||||
|
|
|
@ -343,6 +343,13 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
|
|||
parent=kwargs.get('parent'))
|
||||
|
||||
else:
|
||||
# parent, newobs = append_link.link_collection(file_names[-1],
|
||||
# location=downloader['location'],
|
||||
# rotation=downloader['rotation'],
|
||||
# link=False,
|
||||
# name=asset_data['name'],
|
||||
# parent=kwargs.get('parent'))
|
||||
|
||||
parent, newobs = append_link.append_objects(file_names[-1],
|
||||
location=downloader['location'],
|
||||
rotation=downloader['rotation'],
|
||||
|
@ -364,10 +371,17 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
|
|||
name=asset_data['name'],
|
||||
parent=kwargs.get('parent'))
|
||||
else:
|
||||
# parent, newobs = append_link.link_collection(file_names[-1],
|
||||
# location=kwargs['model_location'],
|
||||
# rotation=kwargs['model_rotation'],
|
||||
# link=False,
|
||||
# name=asset_data['name'],
|
||||
# parent=kwargs.get('parent'))
|
||||
parent, newobs = append_link.append_objects(file_names[-1],
|
||||
location=kwargs['model_location'],
|
||||
rotation=kwargs['model_rotation'],
|
||||
link=link,
|
||||
name=asset_data['name'],
|
||||
parent=kwargs.get('parent'))
|
||||
if parent.type == 'EMPTY' and link:
|
||||
bmin = asset_data['bbox_min']
|
||||
|
@ -723,8 +737,8 @@ def try_finished_append(asset_data, **kwargs): # location=None, material_target
|
|||
for f in file_names:
|
||||
try:
|
||||
os.remove(f)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
except Exception as e:
|
||||
# e = sys.exc_info()[0]
|
||||
print(e)
|
||||
pass;
|
||||
done = False
|
||||
|
@ -934,7 +948,7 @@ class BlenderkitDownloadOperator(bpy.types.Operator):
|
|||
|
||||
if self.replace: # cleanup first, assign later.
|
||||
obs = utils.get_selected_replace_adepts()
|
||||
print(obs)
|
||||
# print(obs)
|
||||
for ob in obs:
|
||||
print('replace attempt ', ob.name)
|
||||
if self.asset_base_id != '':
|
||||
|
|
|
@ -101,22 +101,40 @@ def refresh_token_timer():
|
|||
|
||||
return max(3600, user_preferences.api_key_life - 3600)
|
||||
|
||||
def update_ad(ad):
|
||||
if not ad.get('assetBaseId'):
|
||||
ad['assetBaseId'] = ad['asset_base_id'] # this should stay ONLY for compatibility with older scenes
|
||||
ad['assetType'] = ad['asset_type'] # this should stay ONLY for compatibility with older scenes
|
||||
ad['canDownload'] = ad['can_download'] # this should stay ONLY for compatibility with older scenes
|
||||
ad['verificationStatus'] = ad['verification_status'] # this should stay ONLY for compatibility with older scenes
|
||||
ad['author'] = {}
|
||||
ad['author']['id'] = ad['author_id'] # this should stay ONLY for compatibility with older scenes
|
||||
return ad
|
||||
|
||||
def update_assets_data(): # updates assets data on scene load.
|
||||
'''updates some properties that were changed on scenes with older assets.
|
||||
The properties were mainly changed from snake_case to CamelCase to fit the data that is coming from the server.
|
||||
'''
|
||||
for ob in bpy.context.scene.objects:
|
||||
if ob.get('asset_data') != None:
|
||||
ad = ob['asset_data']
|
||||
if not ad.get('assetBaseId'):
|
||||
ad['assetBaseId'] = ad['asset_base_id'], # this should stay ONLY for compatibility with older scenes
|
||||
ad['assetType'] = ad['asset_type'], # this should stay ONLY for compatibility with older scenes
|
||||
ad['canDownload'] = ad['can_download'], # this should stay ONLY for compatibility with older scenes
|
||||
ad['verificationStatus'] = ad[
|
||||
'verification_status'], # this should stay ONLY for compatibility with older scenes
|
||||
ad['author'] = {}
|
||||
ad['author']['id'] = ad['author_id'], # this should stay ONLY for compatibility with older scenes
|
||||
data = bpy.data
|
||||
|
||||
datablocks = [
|
||||
bpy.data.objects,
|
||||
bpy.data.materials,
|
||||
bpy.data.brushes,
|
||||
]
|
||||
for dtype in datablocks:
|
||||
for block in dtype:
|
||||
if block.get('asset_data') != None:
|
||||
update_ad(block['asset_data'])
|
||||
|
||||
dicts = [
|
||||
'assets used',
|
||||
'assets rated',
|
||||
]
|
||||
for d in dicts:
|
||||
for k in d.keys():
|
||||
update_ad(d[k])
|
||||
# bpy.context.scene['assets used'][ad] = ad
|
||||
|
||||
|
||||
@persistent
|
||||
|
|
|
@ -1033,9 +1033,10 @@ def is_rating_possible():
|
|||
m = ao.active_material
|
||||
if m is not None:
|
||||
ad = m.get('asset_data')
|
||||
if ad is not None:
|
||||
if ad is not None and ad.get('assetBaseId'):
|
||||
rated = bpy.context.scene['assets rated'].get(ad['assetBaseId'])
|
||||
return True, rated, m, ad
|
||||
if rated:
|
||||
return True, rated, m, ad
|
||||
|
||||
# if t>2 and t<2.5:
|
||||
# ui_props.rating_on = False
|
||||
|
|
|
@ -1048,7 +1048,12 @@ def draw_asset_context_menu(self, context, asset_data):
|
|||
op.author_id = author_id
|
||||
|
||||
op = layout.operator('view3d.blenderkit_search', text='Search Similar')
|
||||
op.keywords = asset_data['name'] + ' ' + asset_data['description'] + ' ' + ' '.join(asset_data['tags'])
|
||||
#build search string from description and tags:
|
||||
op.keywords = asset_data['name']
|
||||
if asset_data.get('description'):
|
||||
op.keywords += ' ' + asset_data.get('description')
|
||||
op.keywords += ' '.join(asset_data.get('tags'))
|
||||
|
||||
if asset_data.get('canDownload') != 0:
|
||||
if len(bpy.context.selected_objects) > 0 and ui_props.asset_type == 'MODEL':
|
||||
aob = bpy.context.active_object
|
||||
|
|
Loading…
Reference in New Issue