[Bf-extensions-cvs] [e84b6c25] master: BlenderKit: display assets with missing thumbnail

Vilém Duha noreply at git.blender.org
Sat Sep 19 18:23:05 CEST 2020


Commit: e84b6c2587ae626ee24ff44a76461ef07b34321f
Author: Vilém Duha
Date:   Thu Sep 17 09:24:55 2020 +0200
Branches: master
https://developer.blender.org/rBAe84b6c2587ae626ee24ff44a76461ef07b34321f

BlenderKit: display assets with missing thumbnail

This way creatorc can see better if they upload things with wrong format. These shouldn't ever get to public db.

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

M	blenderkit/search.py
A	blenderkit/thumbnails/thumbnail_not_available.jpg
M	blenderkit/thumbnails/thumbnail_notready.jpg
M	blenderkit/ui.py
M	blenderkit/utils.py

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

diff --git a/blenderkit/search.py b/blenderkit/search.py
index b72ade93..5ae8aa48 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -232,64 +232,63 @@ def parse_result(r):
             if f['fileType'] == 'blend':
                 durl = f['downloadUrl'].split('?')[0]
                 # fname = paths.extract_filename_from_url(f['filePath'])
-        if durl and tname:
-
-            tooltip = generate_tooltip(r)
-            # for some reason, the id was still int on some occurances. investigate this.
-            r['author']['id'] = str(r['author']['id'])
-
-            # some helper props, but generally shouldn't be renaming/duplifiying original properties,
-            # so blender's data is same as on server.
-            asset_data = {'thumbnail': tname,
-                          'thumbnail_small': small_tname,
-                          # 'thumbnails':allthumbs,
-                          'download_url': durl,
-                          # 'id': r['id'],
-                          # 'asset_base_id': r['assetBaseId'],#this should stay ONLY for compatibility with older scenes
-                          # 'name': r['name'],
-                          # 'asset_type': r['assetType'], #this should stay ONLY for compatibility with older scenes
-                          'tooltip': tooltip,
-                          # 'tags': r['tags'],
-                          # 'can_download': r.get('canDownload', True),#this should stay ONLY for compatibility with older scenes
-                          # 'verification_status': r['verificationStatus'],#this should stay ONLY for compatibility with older scenes
-                          # 'author_id': r['author']['id'],#this should stay ONLY for compatibility with older scenes
-                          # 'author': r['author']['firstName'] + ' ' + r['author']['lastName']
-                          # 'description': r['description'],
-                          }
-            asset_data['downloaded'] = 0
-
-            # parse extra params needed for blender here
-            params = utils.params_to_dict(r['parameters'])
 
-            if asset_type == 'model':
-                if params.get('boundBoxMinX') != None:
-                    bbox = {
-                        'bbox_min': (
-                            float(params['boundBoxMinX']),
-                            float(params['boundBoxMinY']),
-                            float(params['boundBoxMinZ'])),
-                        'bbox_max': (
-                            float(params['boundBoxMaxX']),
-                            float(params['boundBoxMaxY']),
-                            float(params['boundBoxMaxZ']))
-                    }
-
-                else:
-                    bbox = {
-                        'bbox_min': (-.5, -.5, 0),
-                        'bbox_max': (.5, .5, 1)
-                    }
-                asset_data.update(bbox)
-            if asset_type == 'material':
-                asset_data['texture_size_meters'] = params.get('textureSizeMeters', 1.0)
+        tooltip = generate_tooltip(r)
+        # for some reason, the id was still int on some occurances. investigate this.
+        r['author']['id'] = str(r['author']['id'])
+
+        # some helper props, but generally shouldn't be renaming/duplifiying original properties,
+        # so blender's data is same as on server.
+        asset_data = {'thumbnail': tname,
+                      'thumbnail_small': small_tname,
+                      # 'thumbnails':allthumbs,
+                      'download_url': durl,
+                      # 'id': r['id'],
+                      # 'asset_base_id': r['assetBaseId'],#this should stay ONLY for compatibility with older scenes
+                      # 'name': r['name'],
+                      # 'asset_type': r['assetType'], #this should stay ONLY for compatibility with older scenes
+                      'tooltip': tooltip,
+                      # 'tags': r['tags'],
+                      # 'can_download': r.get('canDownload', True),#this should stay ONLY for compatibility with older scenes
+                      # 'verification_status': r['verificationStatus'],#this should stay ONLY for compatibility with older scenes
+                      # 'author_id': r['author']['id'],#this should stay ONLY for compatibility with older scenes
+                      # 'author': r['author']['firstName'] + ' ' + r['author']['lastName']
+                      # 'description': r['description'],
+                      }
+        asset_data['downloaded'] = 0
+
+        # parse extra params needed for blender here
+        params = utils.params_to_dict(r['parameters'])
+
+        if asset_type == 'model':
+            if params.get('boundBoxMinX') != None:
+                bbox = {
+                    'bbox_min': (
+                        float(params['boundBoxMinX']),
+                        float(params['boundBoxMinY']),
+                        float(params['boundBoxMinZ'])),
+                    'bbox_max': (
+                        float(params['boundBoxMaxX']),
+                        float(params['boundBoxMaxY']),
+                        float(params['boundBoxMaxZ']))
+                }
+
+            else:
+                bbox = {
+                    'bbox_min': (-.5, -.5, 0),
+                    'bbox_max': (.5, .5, 1)
+                }
+            asset_data.update(bbox)
+        if asset_type == 'material':
+            asset_data['texture_size_meters'] = params.get('textureSizeMeters', 1.0)
 
-            asset_data.update(tdict)
-            if r['assetBaseId'] in scene.get('assets used', {}).keys():
-                asset_data['downloaded'] = 100
+        asset_data.update(tdict)
+        if r['assetBaseId'] in scene.get('assets used', {}).keys():
+            asset_data['downloaded'] = 100
 
-            # attempt to switch to use original data gradually, since the parsing as itself should become obsolete.
-            asset_data.update(r)
-            return asset_data
+        # attempt to switch to use original data gradually, since the parsing as itself should become obsolete.
+        asset_data.update(r)
+        return asset_data
 
 
 # @bpy.app.handlers.persistent
@@ -406,23 +405,25 @@ def load_previews():
 
         i = 0
         for r in results:
-
             tpath = os.path.join(directory, r['thumbnail_small'])
+            if not r['thumbnail_small']:
+                tpath = paths.get_addon_thumbnail_path('thumbnail_not_available.jpg')
 
             iname = utils.previmg_name(i)
 
-            if os.path.exists(tpath):  # sometimes we are unlucky...
-                img = bpy.data.images.get(iname)
-                if img is None:
-                    img = bpy.data.images.load(tpath)
-                    img.name = iname
-                elif img.filepath != tpath:
-                    # had to add this check for autopacking files...
-                    if img.packed_file is not None:
-                        img.unpack(method='USE_ORIGINAL')
-                    img.filepath = tpath
-                    img.reload()
-                img.colorspace_settings.name = 'sRGB'
+            # if os.path.exists(tpath):  # sometimes we are unlucky...
+            img = bpy.data.images.get(iname)
+            if img is None:
+                img = bpy.data.images.load(tpath)
+                img.name = iname
+            elif img.filepath != tpath:
+                # had to add this check for autopacking files...
+                if img.packed_file is not None:
+                    img.unpack(method='USE_ORIGINAL')
+                img.filepath = tpath
+                img.reload()
+            img.colorspace_settings.name = 'sRGB'
+
             i += 1
     # print('previews loaded')
 
diff --git a/blenderkit/thumbnails/thumbnail_not_available.jpg b/blenderkit/thumbnails/thumbnail_not_available.jpg
new file mode 100644
index 00000000..c5b5172a
Binary files /dev/null and b/blenderkit/thumbnails/thumbnail_not_available.jpg differ
diff --git a/blenderkit/thumbnails/thumbnail_notready.jpg b/blenderkit/thumbnails/thumbnail_notready.jpg
index 2628d1e5..a32cb096 100644
Binary files a/blenderkit/thumbnails/thumbnail_notready.jpg and b/blenderkit/thumbnails/thumbnail_notready.jpg differ
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index ed197ec9..38cb494a 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -856,6 +856,9 @@ def draw_callback_2d_search(self, context):
             if sr != None and -1 < ui_props.active_index < len(sr):
                 r = sr[ui_props.active_index]
                 tpath = os.path.join(directory, r['thumbnail'])
+                if not r['thumbnail']:
+                    tpath = paths.get_addon_thumbnail_path('thumbnail_not_available.jpg')
+
 
                 img = bpy.data.images.get(iname)
                 if img == None or img.filepath != tpath:
diff --git a/blenderkit/utils.py b/blenderkit/utils.py
index bd15c72e..6b7ddd94 100644
--- a/blenderkit/utils.py
+++ b/blenderkit/utils.py
@@ -288,7 +288,7 @@ def get_hidden_image(tpath, bdata_name, force_reload=False):
     if img == None or (img.filepath != tpath):
         if tpath.startswith('//'):
             tpath = bpy.path.abspath(tpath)
-        if not os.path.exists(tpath) or tpath == '':
+        if not os.path.exists(tpath) or os.path.isdir(tpath):
             tpath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')
 
         if img is None:
@@ -653,6 +653,7 @@ def get_largest_area(area_type='VIEW_3D'):
 def get_fake_context(context, area_type='VIEW_3D'):
     C_dict = {}  # context.copy() #context.copy was a source of problems - incompatibility with addons that also define context
     C_dict.update(region='WINDOW')
+
     if context.area is None or context.area.type != area_type:
         w, a, r = get_largest_area(area_type=area_type)



More information about the Bf-extensions-cvs mailing list