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
This commit is contained in:
Vilem Duha 2021-07-07 19:21:20 +02:00 committed by Jeroen Bakker
parent 29db4b5feb
commit ae7be84e2d
10 changed files with 25 additions and 33 deletions

View File

@ -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

View File

@ -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;

View File

@ -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():

View File

@ -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

View File

@ -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

View File

@ -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'):

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.context.preferences.addons['blenderkit'].preferences