[Bf-extensions-cvs] [903a0f01] master: BlenderKit: fix replace model, was broken. -should also WIP work in selected model panel. -deleted commented out filtering code
Vilém Duha
noreply at git.blender.org
Wed Jul 1 16:13:04 CEST 2020
Commit: 903a0f01b5f7e0285a7f5a2c14dd9fbb1ba9f1df
Author: Vilém Duha
Date: Wed Jun 24 10:20:23 2020 +0200
Branches: master
https://developer.blender.org/rBA903a0f01b5f7e0285a7f5a2c14dd9fbb1ba9f1df
BlenderKit: fix replace model, was broken.
-should also WIP work in selected model panel.
-deleted commented out filtering code
===================================================================
M blenderkit/__init__.py
M blenderkit/download.py
M blenderkit/search.py
M blenderkit/ui_panels.py
M blenderkit/upload.py
M blenderkit/utils.py
===================================================================
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index 4a6ef2f0..de47ed86 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -1600,6 +1600,8 @@ class BlenderKitAddonPreferences(AddonPreferences):
layout.prop(self, "max_assetbar_rows")
layout.prop(self, "tips_on_start")
layout.prop(self, "search_in_header")
+ if bpy.context.preferences.view.show_developer_ui:
+ layout.prop(self, "use_timers")
# registration
diff --git a/blenderkit/download.py b/blenderkit/download.py
index b2ef67f6..7ec425ce 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -282,7 +282,6 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
#
scene = bpy.context.scene
-
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
if user_preferences.api_key == '':
@@ -306,12 +305,12 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
sprops.append_link = 'APPEND'
sprops.import_as = 'INDIVIDUAL'
- #copy for override
+ # copy for override
al = sprops.append_link
import_as = sprops.import_as
# set consistency for objects already in scene, otherwise this literally breaks blender :)
ain = asset_in_scene(asset_data)
- #override based on history
+ # override based on history
if ain is not False:
if ain == 'LINKED':
al = 'LINK'
@@ -320,7 +319,6 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
al = 'APPEND'
import_as = 'INDIVIDUAL'
-
# first get conditions for append link
link = al == 'LINK'
# then append link
@@ -338,11 +336,11 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
if sprops.import_as == 'GROUP':
parent, newobs = append_link.link_collection(file_names[-1],
- location=downloader['location'],
- rotation=downloader['rotation'],
- link=link,
- name=asset_data['name'],
- parent=kwargs.get('parent'))
+ location=downloader['location'],
+ rotation=downloader['rotation'],
+ link=link,
+ name=asset_data['name'],
+ parent=kwargs.get('parent'))
else:
parent, newobs = append_link.append_objects(file_names[-1],
@@ -360,11 +358,11 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
elif kwargs.get('model_location') is not None:
if sprops.import_as == 'GROUP':
parent, newobs = append_link.link_collection(file_names[-1],
- location=kwargs['model_location'],
- rotation=kwargs['model_rotation'],
- link=link,
- name=asset_data['name'],
- parent=kwargs.get('parent'))
+ location=kwargs['model_location'],
+ rotation=kwargs['model_rotation'],
+ link=link,
+ name=asset_data['name'],
+ parent=kwargs.get('parent'))
else:
parent, newobs = append_link.append_objects(file_names[-1],
location=kwargs['model_location'],
@@ -441,7 +439,7 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
scene['assets rated'][id] = scene['assets rated'].get(id, False)
parent['asset_data'] = asset_data # TODO remove this??? should write to blenderkit Props?
- bpy.ops.wm.undo_push_context(message = 'add %s to scene'% asset_data['name'])
+ bpy.ops.wm.undo_push_context(message='add %s to scene' % asset_data['name'])
# moving reporting to on save.
# report_use_success(asset_data['id'])
@@ -525,7 +523,7 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff, not
def download_file(asset_data):
- #this is a simple non-threaded way to download files for background resolution genenration tool
+ # this is a simple non-threaded way to download files for background resolution genenration tool
file_name = paths.get_download_filenames(asset_data)[0] # prefer global dir if possible.
if check_existing(asset_data):
@@ -552,6 +550,7 @@ def download_file(asset_data):
f.write(data)
return file_name
+
class Downloader(threading.Thread):
def __init__(self, asset_data, tcom, scene_id, api_key):
super(Downloader, self).__init__()
@@ -883,6 +882,11 @@ class BlenderkitDownloadOperator(bpy.types.Operator):
)
asset_index: IntProperty(name="Asset Index", description='asset index in search results', default=-1)
+ asset_base_id: StringProperty(
+ name="Asset base Id",
+ description="Asset base id, used instead of search result index.",
+ default="")
+
target_object: StringProperty(
name="Target Object",
description="Material or object target for replacement",
@@ -905,14 +909,23 @@ class BlenderkitDownloadOperator(bpy.types.Operator):
def execute(self, context):
s = bpy.context.scene
- sr = s['search results']
- asset_data = sr[self.asset_index].to_dict() # TODO CHECK ALL OCCURRENCES OF PASSING BLENDER ID PROPS TO THREADS!
+ if self.asset_index > -1:
+ # either get the data from search results
+ sr = s['search results']
+ asset_data = sr[
+ self.asset_index].to_dict() # TODO CHECK ALL OCCURRENCES OF PASSING BLENDER ID PROPS TO THREADS!
+ asset_base_id = asset_data['assetBaseId']
+ else:
+ # or from the scene.
+ asset_base_id = self.asset_base_id
+
au = s.get('assets used')
if au == None:
s['assets used'] = {}
- if asset_data['assetBaseId'] in s.get('assets used'):
- asset_data = s['assets used'][asset_data['assetBaseId']].to_dict()
+ if asset_base_id in s.get('assets used'):
+ # already used assets have already download link and especially file link.
+ asset_data = s['assets used'][asset_base_id].to_dict()
atype = asset_data['assetType']
if bpy.context.mode != 'OBJECT' and (
@@ -920,9 +933,16 @@ class BlenderkitDownloadOperator(bpy.types.Operator):
bpy.ops.object.mode_set(mode='OBJECT')
if self.replace: # cleanup first, assign later.
- obs = utils.get_selected_models()
-
+ obs = utils.get_selected_replace_adepts()
+ print(obs)
for ob in obs:
+ print('replace attempt ', ob.name)
+ if self.asset_base_id != '':
+ # this is for a case when replace is called from a panel, this makes the first of the objects not replacable.
+ if ob.get('asset_data') is not None and ob['asset_data']['assetBaseId'] == self.asset_base_id:
+ print('skipping this oneli')
+ continue;
+
kwargs = {
'cast_parent': self.cast_parent,
'target_object': ob.name,
diff --git a/blenderkit/search.py b/blenderkit/search.py
index cc3a6b63..cf662f4d 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -262,7 +262,7 @@ def parse_result(r):
#attempt to switch to use original data gradually, since the parsing as itself should become obsolete.
asset_data.update(r)
- return asset_data
+ return asset_data
# @bpy.app.handlers.persistent
@@ -338,7 +338,8 @@ def timer_update():
bpy.ops.object.run_assetbar_fix_context()
for r in rdata['results']:
asset_data = parse_result(r)
- result_field.append(asset_data)
+ if asset_data != None:
+ result_field.append(asset_data)
# results = rdata['results']
s[search_name] = result_field
@@ -884,21 +885,6 @@ class Searcher(threading.Thread):
mt('data parsed ')
- # filter results here:
- # todo remove this in future
- # nresults = []
- # for d in rdata.get('results', []):
- # # TODO this code is for filtering brush types, should vanish after we implement filter in Elastic
- # mode = None
- # if query['asset_type'] == 'brush':
- # for p in d['parameters']:
- # if p['parameterType'] == 'mode':
- # mode = p['value']
- # if query['asset_type'] != 'brush' or (
- # query.get('mode') != None and query['mode']) == mode:
- # nresults.append(d)
- # rdata['results'] = nresults
-
# print('number of results: ', len(rdata.get('results', [])))
if self.stopped():
utils.p('stopping search : ' + str(query))
diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index aa1cc556..a1fb89d2 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -435,7 +435,7 @@ clas
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list