BlenderKit: ratings fixes
This commit is contained in:
parent
1a74e18798
commit
4f961d71dc
|
@ -294,6 +294,7 @@ class FastRateMenu(Operator, ratings_utils.RatingsProperties):
|
|||
return {'CANCELLED'}
|
||||
self.message = f"{self.asset_name}"
|
||||
wm = context.window_manager
|
||||
self.prefill_ratings()
|
||||
|
||||
if self.asset_type in ('model', 'scene'):
|
||||
# spawn a wider one for validators for the enum buttons
|
||||
|
|
|
@ -30,7 +30,6 @@ from bpy.props import (
|
|||
PointerProperty,
|
||||
)
|
||||
|
||||
|
||||
import threading
|
||||
import requests
|
||||
import logging
|
||||
|
@ -69,24 +68,42 @@ def send_rating_to_thread_work_hours(url, ratings, headers):
|
|||
thread.start()
|
||||
|
||||
|
||||
def store_rating_local(asset_id, type='quality', value=0):
|
||||
context = bpy.context
|
||||
context.window_manager['asset ratings'] = context.window_manager.get('asset ratings', {})
|
||||
context.window_manager['asset ratings'][asset_id] = context.window_manager['asset ratings'].get(asset_id, {})
|
||||
context.window_manager['asset ratings'][asset_id][type] = value
|
||||
|
||||
|
||||
def get_rating_local(asset_id):
|
||||
context = bpy.context
|
||||
context.window_manager['asset ratings'] = context.window_manager.get('asset ratings', {})
|
||||
rating = context.window_manager['asset ratings'].get(asset_id)
|
||||
if rating:
|
||||
return rating.to_dict()
|
||||
return None
|
||||
|
||||
|
||||
def update_ratings_quality(self, context):
|
||||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
api_key = user_preferences.api_key
|
||||
|
||||
headers = utils.get_headers(api_key)
|
||||
|
||||
if not(hasattr(self, 'rating_quality')):
|
||||
if not (hasattr(self, 'rating_quality')):
|
||||
# first option is for rating of assets that are from scene
|
||||
asset = self.id_data
|
||||
bkit_ratings = asset.bkit_ratings
|
||||
url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
|
||||
asset_id = asset['asset_data']['id']
|
||||
else:
|
||||
# this part is for operator rating:
|
||||
bkit_ratings = self
|
||||
url = paths.get_api_url() + f'assets/{self.asset_id}/rating/'
|
||||
asset_id = self.asset_id
|
||||
|
||||
if bkit_ratings.rating_quality > 0.1:
|
||||
url = paths.get_api_url() + f'assets/{asset_id}/rating/'
|
||||
|
||||
store_rating_local(asset_id, type='quality', value=bkit_ratings.rating_quality)
|
||||
|
||||
ratings = [('quality', bkit_ratings.rating_quality)]
|
||||
tasks_queue.add_task((send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5, only_last=True)
|
||||
|
@ -96,17 +113,21 @@ def update_ratings_work_hours(self, context):
|
|||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
api_key = user_preferences.api_key
|
||||
headers = utils.get_headers(api_key)
|
||||
if not(hasattr(self, 'rating_work_hours')):
|
||||
if not (hasattr(self, 'rating_work_hours')):
|
||||
# first option is for rating of assets that are from scene
|
||||
asset = self.id_data
|
||||
bkit_ratings = asset.bkit_ratings
|
||||
url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
|
||||
asset_id = asset['asset_data']['id']
|
||||
else:
|
||||
# this part is for operator rating:
|
||||
bkit_ratings = self
|
||||
url = paths.get_api_url() + f'assets/{self.asset_id}/rating/'
|
||||
asset_id = self.asset_id
|
||||
|
||||
if bkit_ratings.rating_work_hours > 0.45:
|
||||
url = paths.get_api_url() + f'assets/{asset_id}/rating/'
|
||||
|
||||
store_rating_local(asset_id, type='working_hours', value=bkit_ratings.rating_work_hours)
|
||||
|
||||
ratings = [('working_hours', round(bkit_ratings.rating_work_hours, 1))]
|
||||
tasks_queue.add_task((send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5, only_last=True)
|
||||
|
||||
|
@ -174,6 +195,7 @@ def stars_enum_callback(self, context):
|
|||
items.append((f'{a + 1}', f'{a + 1}', '', icon, a + 1))
|
||||
return items
|
||||
|
||||
|
||||
class RatingsProperties():
|
||||
message: StringProperty(
|
||||
name="message",
|
||||
|
@ -282,4 +304,17 @@ class RatingsProperties():
|
|||
default='0',
|
||||
update=update_ratings_work_hours_ui_1_10,
|
||||
options={'SKIP_SAVE'}
|
||||
)
|
||||
)
|
||||
|
||||
def prefill_ratings(self):
|
||||
# pre-fill ratings
|
||||
ratings = get_rating_local(self.asset_id)
|
||||
if ratings and ratings.get('quality'):
|
||||
self.rating_quality = ratings['quality']
|
||||
if ratings and ratings.get('working_hours'):
|
||||
wh = int(ratings['working_hours'])
|
||||
self.rating_work_hours_ui = str(wh)
|
||||
if wh < 6:
|
||||
self.rating_work_hours_ui_1_5 = str(int(ratings['working_hours']))
|
||||
if wh < 11:
|
||||
self.rating_work_hours_ui_1_10 = str(int(ratings['working_hours']))
|
||||
|
|
|
@ -1386,7 +1386,7 @@ def label_or_url(layout, text='', tooltip='', url='', icon_value=None, icon=None
|
|||
else:
|
||||
op = layout.operator('wm.blenderkit_tooltip', text=text)
|
||||
op.tooltip = tooltip
|
||||
#these are here to move the text to left, since operators can only center text by default
|
||||
# these are here to move the text to left, since operators can only center text by default
|
||||
layout.label(text='')
|
||||
layout.label(text='')
|
||||
return
|
||||
|
@ -1397,6 +1397,7 @@ def label_or_url(layout, text='', tooltip='', url='', icon_value=None, icon=None
|
|||
else:
|
||||
layout.label(text=text)
|
||||
|
||||
|
||||
class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
|
||||
"""Generate Cycles thumbnail for model assets"""
|
||||
bl_idname = "wm.blenderkit_asset_popup"
|
||||
|
@ -1412,7 +1413,6 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
|
|||
col = layout.column()
|
||||
draw_asset_context_menu(col, context, self.asset_data, from_panel=False)
|
||||
|
||||
|
||||
def draw_property(self, layout, left, right, icon=None, icon_value=None, url='', tooltip=''):
|
||||
right = str(right)
|
||||
row = layout.row()
|
||||
|
@ -1515,14 +1515,12 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
|
|||
if resolution is not None:
|
||||
fs = self.asset_data['files']
|
||||
|
||||
|
||||
ress = f"{int(round(resolution / 1024, 0))}K"
|
||||
self.draw_property(box, 'Resolution', ress,
|
||||
tooltip='Maximal resolution of textures in this asset.\n' \
|
||||
'Most texture asset have also lower resolutions generated.\n' \
|
||||
'Go to BlenderKit add-on import settings to set default resolution')
|
||||
|
||||
|
||||
if fs and len(fs) > 2 and utils.profile_is_validator():
|
||||
resolutions = ''
|
||||
list.sort(fs, key=lambda f: f['fileType'])
|
||||
|
@ -1556,9 +1554,9 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
|
|||
fsmb = fs // (1024 * 1024)
|
||||
fskb = fs % 1024
|
||||
if fsmb == 0:
|
||||
self.draw_property(box,'Original size:', f'{fskb}KB')
|
||||
self.draw_property(box, 'Original size:', f'{fskb}KB')
|
||||
else:
|
||||
self.draw_property(box,'Original size:', f'{fsmb}MB')
|
||||
self.draw_property(box, 'Original size:', f'{fsmb}MB')
|
||||
# Tags section
|
||||
# row = box.row()
|
||||
# letters_on_row = 0
|
||||
|
@ -1615,8 +1613,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
|
|||
if utils.profile_is_validator():
|
||||
date = self.asset_data['created'][:10]
|
||||
date = f"{date[8:10]}. {date[5:7]}. {date[:4]}"
|
||||
self.draw_property(box,'Created:', date)
|
||||
|
||||
self.draw_property(box, 'Created:', date)
|
||||
|
||||
def draw_author_area(self, context, layout, width=330):
|
||||
self.draw_author(context, layout, width=width)
|
||||
|
@ -1802,6 +1799,10 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
|
|||
bl_label = asset_data['name']
|
||||
self.tip = search.get_random_tip()
|
||||
self.tip = self.tip.replace('\n', '')
|
||||
|
||||
# pre-fill ratings
|
||||
self.prefill_ratings()
|
||||
|
||||
return wm.invoke_popup(self, width=self.width)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue