[Bf-extensions-cvs] [05fd1e08] master: BlenderKit: resolutions

Vilém Duha noreply at git.blender.org
Sat Dec 5 19:33:22 CET 2020


Commit: 05fd1e08cfb277b1ea13bfca47fbb56dca156032
Author: Vilém Duha
Date:   Sat Dec 5 18:26:05 2020 +0100
Branches: master
https://developer.blender.org/rBA05fd1e08cfb277b1ea13bfca47fbb56dca156032

BlenderKit: resolutions

This introduces resolutins into the addon.
This update should enhance the usability of the addon, especially for people with weaker computers.
It downloads reduced version of the assets - only images are scaled down by now. Images are also converted in some cases from .png to .jpgs to save space.

 - there's a default resolution setting
 - resolutions can be swapped by user
 - resolutions apply only to textured models and materials with textures larger than 1024px
 - Resolutions aren't yet generated on the server, so will be visible after a few days.

Version of the addon was bumped up to 1.0.40.

===================================================================

M	blenderkit/__init__.py
M	blenderkit/append_link.py
A	blenderkit/asset_pack_bg.py
M	blenderkit/autothumb.py
M	blenderkit/bg_blender.py
M	blenderkit/blendfiles/material_thumbnailer_cycles.blend
M	blenderkit/download.py
M	blenderkit/overrides.py
M	blenderkit/paths.py
M	blenderkit/rerequests.py
A	blenderkit/resolutions.py
A	blenderkit/resolutions_bg.py
M	blenderkit/search.py
M	blenderkit/tasks_queue.py
M	blenderkit/ui.py
M	blenderkit/ui_panels.py
M	blenderkit/upload.py
M	blenderkit/upload_bg.py
M	blenderkit/utils.py

===================================================================

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index c6aa82d7..3726a3c2 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -19,8 +19,8 @@
 bl_info = {
     "name": "BlenderKit Online Asset Library",
     "author": "Vilem Duha, Petr Dlouhy",
-    "version": (1, 0, 32),
-    "blender": (2, 83, 0),
+    "version": (1, 0, 40),
+    "blender": (2, 92, 0),
     "location": "View3D > Properties > BlenderKit",
     "description": "Online BlenderKit library (materials, models, brushes and more). Connects to the internet.",
     "warning": "",
@@ -47,10 +47,11 @@ if "bpy" in locals():
     categories = reload(categories)
     bkit_oauth = reload(bkit_oauth)
     tasks_queue = reload(tasks_queue)
+    resolutions = reload(resolutions)
 else:
     from blenderkit import asset_inspector, search, download, upload, ratings, autothumb, ui, icons, bg_blender, paths, \
         utils, \
-        overrides, ui_panels, categories, bkit_oauth, tasks_queue
+        overrides, ui_panels, categories, bkit_oauth, tasks_queue, resolutions
 
 import os
 import math
@@ -86,7 +87,8 @@ from bpy.types import (
 
 @persistent
 def scene_load(context):
-    search.load_previews()
+    if not bpy.app.background:
+        search.load_previews()
     ui_props = bpy.context.scene.blenderkitUI
     ui_props.assetbar_on = False
     ui_props.turn_off = False
@@ -488,6 +490,29 @@ class BlenderKitCommonSearchProps(object):
         update=search.search_update,
     )
 
+    #resolution download/import settings
+    resolution: EnumProperty(
+        name="Max resolution",
+        description="Cap texture sizes in the file to this resolution",
+        items=
+        (
+            # ('256', '256x256', ''),
+            ('512', '512x512', ''),
+            ('1024', '1024x1024', ''),
+            ('2048', '2048x2048', ''),
+            ('4096', '4096x4096', ''),
+            ('8192', '8192x8192', ''),
+            ('ORIGINAL', 'ORIGINAL FILE', ''),
+
+        ),
+        default='1024',
+    )
+
+    unpack_files: BoolProperty(name="Unpack Files",
+                                   description="Unpack files after download",
+                                   default=True
+                                   )
+
 
 def name_update(self, context):
     ''' checks for name change, because it decides if whole asset has to be re-uploaded. Name is stored in the blend file
@@ -725,6 +750,16 @@ class BlenderKitMaterialSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
         default="",
         update=search.search_update,
     )
+    append_method: EnumProperty(
+        name="Import Method",
+        items=(
+            ('LINK', 'Link', "Link Material - will be in external file and can't be directly edited"),
+            ('APPEND', 'Append', 'Append if you need to edit the material'),
+        ),
+        description="Appended materials are editable in your scene. Linked assets are saved in original files, "
+                    "aren't editable directly, but also don't increase your file size",
+        default="APPEND"
+    )
     automap: BoolProperty(name="Auto-Map",
                           description="reset object texture space and also add automatically a cube mapped UV "
                                       "to the object. \n this allows most materials to apply instantly to any mesh",
@@ -1195,9 +1230,9 @@ class BlenderKitSceneUploadProps(PropertyGroup, BlenderKitCommonUploadProps):
         default=(.25, .25, .5),
     )
 
-    texture_resolution_min: IntProperty(name="Texture Eesolution Min",
+    texture_resolution_min: IntProperty(name="Texture Resolution Min",
                                         description="texture resolution min, autofilled", default=0)
-    texture_resolution_max: IntProperty(name="Texture Eesolution Max",
+    texture_resolution_max: IntProperty(name="Texture Resolution Max",
                                         description="texture resolution max, autofilled", default=0)
 
     pbr: BoolProperty(name="PBR Compatible", description="Is compatible with PBR standard", default=False)
diff --git a/blenderkit/append_link.py b/blenderkit/append_link.py
index 56b2857d..66fa711f 100644
--- a/blenderkit/append_link.py
+++ b/blenderkit/append_link.py
@@ -48,22 +48,33 @@ def append_material(file_name, matname=None, link=False, fake_user=True):
     # in previous step there's check if the imported material
     # is already in the scene, so we know same name != same material
 
-    mats_before = bpy.data.materials.keys()
-
-    with bpy.data.libraries.load(file_name, link=link, relative=True) as (data_from, data_to):
-        for m in data_from.materials:
-            if m == matname or matname is None:
-                data_to.materials = [m]
-                # print(m, type(m))
-                matname = m
-                break;
-
+    mats_before = bpy.data.materials[:]
+    try:
+        with bpy.data.libraries.load(file_name, link=link, relative=True) as (data_from, data_to):
+            found = False
+            for m in data_from.materials:
+                if m == matname or matname is None:
+                    data_to.materials = [m]
+                    # print(m, type(m))
+                    matname = m
+                    found = True
+                    break;
+
+            #not found yet? probably some name inconsistency then.
+            # if not found and len(data_from.materials)>0:
+            #     data_to.materials = data_from.materials[0]
+            #     matname = data_from.materials[0]
+            #     print('had to assign')
+            # print('in the appended file the name is ', matname)
+
+    except Exception as e:
+        print(e)
+        print('failed to open the asset file')
     # we have to find the new material :(
-    for mname in bpy.data.materials.keys():
-        if mname not in mats_before:
-            mat = bpy.data.materials[mname]
+    for m in bpy.data.materials:
+        if m not in mats_before:
+            mat = m
             break
-
     if fake_user:
         mat.use_fake_user = True
 
@@ -88,13 +99,10 @@ 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 = []
         for col in data_from.collections:
-            print('linking this ', col)
             if col == kwargs['name']:
                 data_to.collections = [col]
 
@@ -106,7 +114,9 @@ def link_collection(file_name, obnames=[], location=(0, 0, 0), link=False, paren
     main_object = bpy.context.view_layer.objects.active
     main_object.instance_type = 'COLLECTION'
 
-    main_object.parent = parent
+    if parent is not None:
+        main_object.parent = bpy.data.objects.get(parent)
+
     main_object.matrix_world.translation = location
 
     for col in bpy.data.collections:
@@ -201,7 +211,6 @@ def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwar
         fc = utils.get_fake_context(bpy.context, area_type='VIEW_3D')
         bpy.ops.wm.append(fc, filename=object_name, directory=path)
 
-
         return_obs = []
         for ob in bpy.context.scene.objects:
             if ob.select_get():
@@ -262,8 +271,6 @@ def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwar
         for ob in hidden_objects:
             ob.hide_viewport = True
 
-    print(return_obs)
-    print(main_object)
     if kwargs.get('rotation') is not None:
         main_object.rotation_euler = kwargs['rotation']
 
diff --git a/blenderkit/asset_pack_bg.py b/blenderkit/asset_pack_bg.py
new file mode 100644
index 00000000..adde9515
--- /dev/null
+++ b/blenderkit/asset_pack_bg.py
@@ -0,0 +1,8 @@
+import sys
+import json
+from blenderkit import resolutions
+
+BLENDERKIT_EXPORT_DATA = sys.argv[-1]
+
+if __name__ == "__main__":
+    resolutions.run_bg(sys.argv[-1])
\ No newline at end of file
diff --git a/blenderkit/autothumb.py b/blenderkit/autothumb.py
index cf8edb10..ec0028f0 100644
--- a/blenderkit/autothumb.py
+++ b/blenderkit/autothumb.py
@@ -166,7 +166,7 @@ def start_thumbnailer(self, context):
         return {'FINISHED'}
 
 
-def start_material_thumbnailer(self, context):
+def start_material_thumbnailer(self, context, wait = False):
     # Prepare to save the file
     mat = bpy.context.active_object.active_material
     mat.blenderkit.is_generating_thumbnail = True
@@ -290,6 +290,7 @@ class GenerateMaterialThumbnailOperator(bpy.types.Operator):
     bl_label = "BlenderKit Material Thumbnail Generator"
     bl_options = {'REGISTER', 'INTERNAL'}
 
+
     @classmethod
     def poll(cls, context):
         return bpy.context.view_layer.objects.active is not None
diff --git a/blenderkit/bg_blender.py b/blenderkit/bg_blender.py
index c9ec43e4..a8597675 100644
--- a/blenderkit/bg_blender.py
+++ b/blenderkit/bg_blender.py
@@ -93,14 +93,21 @@ def progress(text, n=None):
     else:
         n = ' ' + ' ' + str(int(n * 1000) / 1000) + '% '
     spaces = ' ' * (len(text) + 55)
-    sys.stdout.write('progress{%s%s}\n' % (text, n))
-    sys.stdout.flush()
+    try:
+        sys.stdout.write('progress{%s%s}\n' % (text, n))
+
+        sys.stdout.flush()
+    except Exception as e:
+        print('background progress reporting race condition')
+        print(e)
 
 
 # @bpy.app.handlers.persistent
 def bg_update():
     '''monitoring of background process'''
     text = ''
+    #utils.p('timer search')
+
     s = bpy.context.scene
 
     global bg_processes
@@ -195,8 +202,6 @@ class KillBgProcess(bpy.types.Operator):
             # print(tcom.process_type, self.process_type)
             if tcom.process_type == self.process_type:
                 source = eval(tcom.eval_path)
-                print(source.bl_rna.name, self.process_source)
-                print(source.name)
                 kill = False
                 if source.bl_rna.name == 'Object' and self.process_source == 'MODEL':
                     if

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list