[Bf-extensions-cvs] [ae7be84e] blender-v2.93-release: BlenderKit: fix an error when trying to assign material to unsupported object type

Vilem Duha noreply at git.blender.org
Mon Jul 26 08:52:18 CEST 2021


Commit: ae7be84e2d6cc55102682793baffb415f03ab911
Author: Vilem Duha
Date:   Wed Jul 7 19:21:20 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rBAae7be84e2d6cc55102682793baffb415f03ab911

BlenderKit: fix an error when trying to assign material to unsupported object type

-do same warning for drag-drop although that can be now further improved since it seems ray cast to other object types works already)
-remove some old prints

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

M	blenderkit/__init__.py
M	blenderkit/append_link.py
M	blenderkit/asset_bar_op.py
M	blenderkit/asset_inspector.py
M	blenderkit/autothumb.py
M	blenderkit/download.py
M	blenderkit/ratings.py
M	blenderkit/search.py
M	blenderkit/ui.py
M	blenderkit/utils.py

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

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index c58e5d99..37fa907f 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -141,8 +141,6 @@ from bpy.types import (
 
 @persistent
 def scene_load(context):
-    print('loading in background')
-    print(bpy.context.window_manager)
     if not bpy.app.background:
         search.load_previews()
     ui_props = bpy.context.scene.blenderkitUI
diff --git a/blenderkit/append_link.py b/blenderkit/append_link.py
index 28b0d24e..5b54a81b 100644
--- a/blenderkit/append_link.py
+++ b/blenderkit/append_link.py
@@ -67,7 +67,6 @@ def append_material(file_name, matname=None, link=False, fake_user=True):
     # we have to find the new material , due to possible name changes
     mat = None
     for m in bpy.data.materials:
-        print(m.name)
         if m not in mats_before:
             mat = m
             break;
diff --git a/blenderkit/asset_bar_op.py b/blenderkit/asset_bar_op.py
index 30d94e27..0ad63a83 100644
--- a/blenderkit/asset_bar_op.py
+++ b/blenderkit/asset_bar_op.py
@@ -633,7 +633,7 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
                 properties_width = r.width
         tooltip_x = min(widget.x_screen + widget.width,
                         bpy.context.region.width - self.tooltip_panel.width - properties_width)
-        print(widget.x_screen + widget.width, bpy.context.region.width - self.tooltip_panel.width)
+        # print(widget.x_screen + widget.width, bpy.context.region.width - self.tooltip_panel.width)
 
 
 def register():
diff --git a/blenderkit/asset_inspector.py b/blenderkit/asset_inspector.py
index ecc2ccf1..72b9827d 100644
--- a/blenderkit/asset_inspector.py
+++ b/blenderkit/asset_inspector.py
@@ -174,7 +174,7 @@ def check_printable(props, obs):
         for item in info:
             passed = item[0].endswith(' 0')
             if not passed:
-                print(item[0])
+                # print(item[0])
                 printable = False
 
         props.printable_3d = printable
diff --git a/blenderkit/autothumb.py b/blenderkit/autothumb.py
index b7f2a8d0..8eb891b0 100644
--- a/blenderkit/autothumb.py
+++ b/blenderkit/autothumb.py
@@ -68,7 +68,7 @@ def get_texture_ui(tpath, iname):
 
 def check_thumbnail(props, imgpath):
     img = utils.get_hidden_image(imgpath, 'upload_preview', force_reload=True)
-    print(' check thumbnail ', img)
+    # print(' check thumbnail ', img)
     if img is not None:  # and img.size[0] == img.size[1] and img.size[0] >= 512 and (
         # img.file_format == 'JPEG' or img.file_format == 'PNG'):
         props.has_thumbnail = True
diff --git a/blenderkit/download.py b/blenderkit/download.py
index f0c101a1..a217cc83 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -319,7 +319,6 @@ def append_asset(asset_data, **kwargs):  # downloaders=[], location=None,
         if scene is not None:
             props = scene.blenderkit
             asset_main = scene
-            # print(sprops.switch_after_append)
             if sprops.switch_after_append:
                 bpy.context.window_manager.windows[0].scene = scene
 
@@ -1036,7 +1035,6 @@ def asset_in_scene(asset_data):
     au = scene.get('assets used', {})
 
     id = asset_data['assetBaseId']
-    print(id)
     if id in au.keys():
         ad = au[id]
         if ad.get('files'):
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index cde57893..2a3ac76b 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -58,21 +58,6 @@ def upload_review_thread(url, reviews, headers):
     #     print('reviews upload failed: %s' % str(e))
 
 
-def get_rating(asset_id):
-    # this function isn't used anywhere,should probably get removed.
-    user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
-    api_key = user_preferences.api_key
-    headers = utils.get_headers(api_key)
-    rl = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
-    rtypes = ['quality', 'working_hours']
-    for rt in rtypes:
-        params = {
-            'rating_type': rt
-        }
-        r = rerequests.get(r1, params=data, verify=True, headers=headers)
-        print(r.text)
-
-
 def upload_rating(asset):
     user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
     api_key = user_preferences.api_key
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 3683a1ed..310d1138 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -443,14 +443,14 @@ def search_timer():
                         result_field.append(asset_data)
 
                 # Get ratings from BlenderKit server
-                # if utils.profile_is_validator():
                 user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
                 api_key = user_preferences.api_key
                 headers = utils.get_headers(api_key)
-                for r in rdata['results']:
-                    if ratings_utils.get_rating_local(asset_data['id']) is None:
-                        rating_thread = threading.Thread(target=ratings_utils.get_rating, args=([r['id'], headers]), daemon=True)
-                        rating_thread.start()
+                if utils.profile_is_validator():
+                    for r in rdata['results']:
+                        if ratings_utils.get_rating_local(asset_data['id']) is None:
+                            rating_thread = threading.Thread(target=ratings_utils.get_rating, args=([r['id'], headers]), daemon=True)
+                            rating_thread.start()
 
                 wm[search_name] = result_field
                 wm['search results'] = result_field
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index 7b51eb65..580a66e5 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -767,9 +767,8 @@ def deep_ray_cast(depsgraph, ray_origin, vec):
     empty_set = False, Vector((0, 0, 0)), Vector((0, 0, 1)), None, None, None
     if not object:
         return empty_set
-
     try_object = object
-
+    print(object.type)
     while try_object and (try_object.display_type == 'BOUNDS' or object_in_particle_collection(try_object)):
         ray_origin = snapped_location + vec.normalized() * 0.0003
         try_has_hit, try_snapped_location, try_snapped_normal, try_face_index, try_object, try_matrix = bpy.context.scene.ray_cast(
@@ -1535,7 +1534,7 @@ class AssetBarOperator(bpy.types.Operator):
                         else:
                             # first, test if object can have material applied.
                             # TODO add other types here if droppable.
-                            if object is not None and not object.is_library_indirect and object.type == 'MESH':
+                            if object is not None and not object.is_library_indirect and object.type in utils.supported_material_drag:
                                 target_object = object.name
                                 # create final mesh to extract correct material slot
                                 depsgraph = bpy.context.evaluated_depsgraph_get()
@@ -1549,7 +1548,11 @@ class AssetBarOperator(bpy.types.Operator):
                                                          message="Please select the model,"
                                                                  "go to the 'Selected Model' panel "
                                                                  "in BlenderKit and hit 'Bring to Scene' first.")
-
+                                print(object.type)
+                                if object.type not in utils.supported_material_drag:
+                                    ui_panels.ui_message(title='Unsupported object type',
+                                                         message="Only meshes are supported for material drag-drop.\n "
+                                                                 "Use click interaction for other object types.")
                                 self.report({'WARNING'}, "Invalid or library object as input:")
                                 target_object = ''
                                 target_slot = ''
@@ -1561,12 +1564,17 @@ class AssetBarOperator(bpy.types.Operator):
                     if ui_props.asset_type in ('MATERIAL',
                                                'MODEL'):  # this was meant for particles, commenting for now or ui_props.asset_type == 'MODEL':
                         ao = bpy.context.active_object
-                        if ao != None and not ao.is_library_indirect:
+                        supported_material_click = ('MESH', 'CURVE', 'META', 'FONT', 'SURFACE', 'VOLUME', 'GPENCIL')
+                        if ao != None and not ao.is_library_indirect and ao.type in supported_material_click:
                             target_object = bpy.context.active_object.name
                             target_slot = bpy.context.active_object.active_material_index
                             # change snapped location for placing material downloader.
                             ui_props.snapped_location = bpy.context.active_object.location
                         else:
+                            if ao != None and ui_props.asset_type == 'MATERIAL' and ao.type not in supported_material_click:
+                                ui_panels.ui_message(title='Unsupported object type',
+                                                     message="Can't assign material to this object type."
+                                                             "Please select another object.")
                             target_object = ''
                             target_slot = ''
                 # FIRST START SEARCH
diff --git a/blenderkit/utils.py b/blenderkit/utils.py
index 930fbd79..fd01e74b 100644
--- a/blenderkit/utils.py
+++ b/blenderkit/utils.py
@@ -38,6 +38,10 @@ IDLE_PRIORITY_CLASS = 0x00000040
 NORMAL_PRIORITY_CLASS = 0x00000020
 REALTIME_PRIORITY_CLASS = 0x00000100
 
+supported_material_click = ('MESH', 'CURVE', 'META', 'FONT', 'SURFACE', 'VOLUME', 'GPENCIL')
+# supported_material_drag = ('MESH', 'CURVE', 'META', 'FONT', 'SURFACE', 'VOLUME', 'GPENCIL')
+supported_material_drag = ('MESH')
+
 
 def experimental_enabled():
     preferences = bpy.con

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list