diff options
-rw-r--r-- | blenderkit/append_link.py | 34 | ||||
-rw-r--r-- | blenderkit/bg_blender.py | 16 | ||||
-rw-r--r-- | blenderkit/download.py | 10 | ||||
-rw-r--r-- | blenderkit/search.py | 6 | ||||
-rw-r--r-- | blenderkit/ui.py | 6 | ||||
-rw-r--r-- | blenderkit/utils.py | 4 |
6 files changed, 50 insertions, 26 deletions
diff --git a/blenderkit/append_link.py b/blenderkit/append_link.py index efbd1492..61808af7 100644 --- a/blenderkit/append_link.py +++ b/blenderkit/append_link.py @@ -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, [] diff --git a/blenderkit/bg_blender.py b/blenderkit/bg_blender.py index 9ed68128..c0982702 100644 --- a/blenderkit/bg_blender.py +++ b/blenderkit/bg_blender.py @@ -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) + diff --git a/blenderkit/download.py b/blenderkit/download.py index 9f5f0314..3131ad10 100644 --- a/blenderkit/download.py +++ b/blenderkit/download.py @@ -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) diff --git a/blenderkit/search.py b/blenderkit/search.py index 96c50a0e..83bdb2ec 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -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) diff --git a/blenderkit/ui.py b/blenderkit/ui.py index 7d60ef8c..e35a9298 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -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') diff --git a/blenderkit/utils.py b/blenderkit/utils.py index a6bb407d..20dcaec8 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -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) |