BlenderKit: switch update functions to independent timers.

-seems to improve performance, and fixes assets not appending while asset bar is off.
This commit is contained in:
Vilém Duha 2019-09-04 14:39:22 +02:00
parent 5f3c703ea4
commit 16299222c4
6 changed files with 50 additions and 26 deletions

View File

@ -87,13 +87,37 @@ def append_scene(file_name, scenename=None, link=False, fake_user=False):
def link_group(file_name, obnames=[], location=(0, 0, 0), link=False, **kwargs):
'''link an instanced group - model type asset'''
sel = utils.selection_get()
bpy.ops.wm.link(directory=file_name + "/Collection/", filename=kwargs['name'], link=link, instance_collections=True,
autoselect=True)
main_object = bpy.context.active_object
with bpy.data.libraries.load(file_name, link=link, relative=True) as (data_from, data_to):
scols = []
for col in data_from.collections:
print('linking this ', col)
if col == kwargs['name']:
data_to.collections = [col]
rotation = (0,0,0)
if kwargs.get('rotation') is not None:
main_object.rotation_euler = kwargs['rotation']
main_object.location = location
rotation = kwargs['rotation']
bpy.ops.object.empty_add(type='PLAIN_AXES', location=location, rotation = rotation)
main_object = bpy.context.view_layer.objects.active
main_object.instance_type = 'COLLECTION'
for col in bpy.data.collections:
print(col.name, col.library, file_name)
if col.library is not None:
if col.library.filepath == file_name:
main_object.instance_collection = col
break;
# bpy.ops.wm.link(directory=file_name + "/Collection/", filename=kwargs['name'], link=link, instance_collections=True,
# autoselect=True)
# main_object = bpy.context.view_layer.objects.active
# if kwargs.get('rotation') is not None:
# main_object.rotation_euler = kwargs['rotation']
# main_object.location = location
utils.selection_set(sel)
return main_object, []

View File

@ -135,8 +135,9 @@ def bg_update():
p[0] = readthread
if len(bg_processes) == 0:
bpy.app.timers.unregister(bg_update)
return .1
if len(bg_processes) > 0:
return .3
return 1.
process_types = (
@ -225,17 +226,16 @@ def add_bg_process(location=None, name=None, eval_path_computing='', eval_path_s
readthread.start()
bg_processes.append([readthread, tcom])
if not bpy.app.timers.is_registered(bg_update):
bpy.app.timers.register(bg_update, persistent=True)
def stert_bg_blender():
pass;
# if not bpy.app.timers.is_registered(bg_update):
# bpy.app.timers.register(bg_update, persistent=True)
def register():
bpy.utils.register_class(KillBgProcess)
bpy.app.timers.register(bg_update, persistent=True)
def unregister():
bpy.utils.unregister_class(KillBgProcess)
bpy.app.timers.unregister(bg_update)

View File

@ -402,9 +402,9 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
shutil.copy(thumbpath, asset_thumb_path)
brush.icon_filepath = asset_thumb_path
if bpy.context.sculpt_object:
if bpy.context.view_layer.objects.active.mode == 'SCULPT':
bpy.context.tool_settings.sculpt.brush = brush
elif bpy.context.image_paint_object: # could be just else, but for future possible more types...
elif bpy.context.view_layer.objects.active.mode == 'TEXTURE_PAINT': # could be just else, but for future possible more types...
bpy.context.tool_settings.image_paint.brush = brush
# TODO set brush by by asset data(user can be downloading while switching modes.)
@ -510,7 +510,7 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff, not
sres['downloaded'] = 100
utils.p('finished download thread')
return .2
return .5
class Downloader(threading.Thread):
@ -886,7 +886,7 @@ def register_download():
bpy.utils.register_class(BlenderkitKillDownloadOperator)
bpy.app.handlers.load_post.append(scene_load)
bpy.app.handlers.save_pre.append(scene_save)
# bpy.app.timers.register(timer_update, persistent = True)
bpy.app.timers.register(timer_update, persistent = True)
def unregister_download():
@ -894,4 +894,4 @@ def unregister_download():
bpy.utils.unregister_class(BlenderkitKillDownloadOperator)
bpy.app.handlers.load_post.remove(scene_load)
bpy.app.handlers.save_pre.remove(scene_save)
# bpy.app.timers.unregister(timer_update)
bpy.app.timers.unregister(timer_update)

View File

@ -266,7 +266,7 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff.
# print('finished search thread')
mt('preview loading finished')
return .2
return .3
def load_previews():
@ -1152,7 +1152,7 @@ def register_search():
for c in classes:
bpy.utils.register_class(c)
# bpy.app.timers.register(timer_update, persistent = True)
bpy.app.timers.register(timer_update, persistent = True)
categories.load_categories()
@ -1163,5 +1163,5 @@ def unregister_search():
for c in classes:
bpy.utils.unregister_class(c)
# bpy.app.timers.unregister(timer_update)
bpy.app.timers.unregister(timer_update)

View File

@ -1229,9 +1229,9 @@ class AssetBarOperator(bpy.types.Operator):
update_ui_size(self.area, self.region)
search.timer_update()
download.timer_update()
bg_blender.bg_update()
# search.timer_update()
# download.timer_update()
# bg_blender.bg_update()
if context.region != self.region:
print(time.time(), 'pass trough because of region')

View File

@ -38,8 +38,8 @@ def activate(ob):
def selection_get():
aob = bpy.context.active_object
selobs = bpy.context.selected_objects
aob = bpy.context.view_layer.objects.active
selobs = bpy.context.view_layer.objects.selected[:]
return (aob, selobs)