[Bf-extensions-cvs] [8f6903bc] master: BlenderKit: Rating refactorings

Vilém Duha noreply at git.blender.org
Mon Jul 27 13:00:41 CEST 2020


Commit: 8f6903bc92531aa8e5d4c64a0a108c2904506a83
Author: Vilém Duha
Date:   Mon Jul 27 12:59:38 2020 +0200
Branches: master
https://developer.blender.org/rBA8f6903bc92531aa8e5d4c64a0a108c2904506a83

BlenderKit: Rating refactorings

This mainly paves a way for removing the old and clumsy bgl UI and enable faster rating for users.
-Rating Ui is now more responsive -it can be dragged over the stars widget.
-fast rating operator (f shortcut over assetbar)
-wip on new ratings panel(disabled by now)
-if author didn't provide his webpage, the link now leads to his profile on the BlenderKit site.
-upload was partially broken thanks to a small bug
-perpendicular snap - This limits angled snapping in a reasonable way, should help when placing foliage or items on sloped ceilings e.t.c.
-removed the first_run property, it's replaced with a poput that informs the user about connecting to the internet.

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

M	blenderkit/__init__.py
M	blenderkit/paths.py
M	blenderkit/ratings.py
M	blenderkit/search.py
M	blenderkit/ui.py
M	blenderkit/ui_panels.py
M	blenderkit/upload.py

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

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index 23ee89c5..fba80a7e 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -250,6 +250,7 @@ def switch_search_results(self, context):
         s['search results orig'] = s.get('bkit brush search orig')
     search.load_previews()
 
+
 def asset_type_callback(self, context):
     '''
     Returns
@@ -650,29 +651,6 @@ class BlenderKitCommonUploadProps(object):
     )
 
 
-def stars_enum_callback(self, context):
-    items = []
-    for a in range(0, 10):
-        if self.rating_quality < a+1:
-            icon = 'SOLO_OFF'
-        else:
-            icon = 'SOLO_ON'
-        # has to have something before the number in the value, otherwise fails on registration.
-        items.append((f'{a+1}', f'{a+1}', '', icon, a+1))
-    return items
-
-
-def update_quality(self, context):
-    user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
-    if user_preferences.api_key == '':
-        # ui_panels.draw_not_logged_in(self, message='Please login/signup to rate assets.')
-        # bpy.ops.wm.call_menu(name='OBJECT_MT_blenderkit_login_menu')
-        # return
-        bpy.ops.wm.blenderkit_login('INVOKE_DEFAULT', message = 'Please login/signup to rate assets. Clicking OK takes you to web login.')
-        self.rating_quality_ui = '0'
-    self.rating_quality = int(self.rating_quality_ui)
-
-
 class BlenderKitRatingProps(PropertyGroup):
     rating_quality: IntProperty(name="Quality",
                                 description="quality of the material",
@@ -680,19 +658,20 @@ class BlenderKitRatingProps(PropertyGroup):
                                 min=-1, max=10,
                                 update=ratings.update_ratings_quality)
 
-    #the following enum is only to ease interaction - enums support 'drag over' and enable to draw the stars easily.
+    # the following enum is only to ease interaction - enums support 'drag over' and enable to draw the stars easily.
     rating_quality_ui: EnumProperty(name='rating_quality_ui',
-                                     items=stars_enum_callback,
-                                     description='Rating stars 0 - 10',
-                                     default=None,
-                                     update=update_quality,
-                                     )
+                                    items=ratings.stars_enum_callback,
+                                    description='Rating stars 0 - 10',
+                                    default=None,
+                                    update=ratings.update_quality_ui,
+                                    )
 
     rating_work_hours: FloatProperty(name="Work Hours",
                                      description="How many hours did this work take?",
                                      default=0.00,
                                      min=0.0, max=1000, update=ratings.update_ratings_work_hours
                                      )
+
     # rating_complexity: IntProperty(name="Complexity",
     #                                description="Complexity is a number estimating how much work was spent on the asset.aaa",
     #                                default=0, min=0, max=10)
@@ -1393,6 +1372,17 @@ class BlenderKitModelSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
                                         max=180,
                                         subtype='ANGLE')
 
+    perpendicular_snap: BoolProperty(name='Perpendicular snap',
+                                     description="Limit snapping that is close to perpendicular angles to be perpendicular.",
+                                     default=True)
+
+    perpendicular_snap_threshold: FloatProperty(name="Threshold",
+                                                description="Limit perpendicular snap to be below these values.",
+                                                default=.25,
+                                                min=0,
+                                                max=.5,
+                                                )
+
 
 class BlenderKitSceneSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
     search_keywords: StringProperty(
@@ -1586,12 +1576,13 @@ class BlenderKitAddonPreferences(AddonPreferences):
                                min=0,
                                max=20000)
 
-    first_run: BoolProperty(
-        name="First run",
-        description="Detects if addon was already registered/run.",
-        default=True,
-        update=utils.save_prefs
-    )
+    # this is now made obsolete by the new popup upon registration -ensures the user knows about the first search.
+    # first_run: BoolProperty(
+    #     name="First run",
+    #     description="Detects if addon was already registered/run.",
+    #     default=True,
+    #     update=utils.save_prefs
+    # )
 
     use_timers: BoolProperty(
         name="Use timers",
@@ -1729,7 +1720,8 @@ def register():
     for w in bpy.context.window_manager.windows:
         for a in w.screen.areas:
             if a.type == 'PREFERENCES':
-                tasks_queue.add_task((bpy.ops.wm.blenderkit_welcome,( 'INVOKE_DEFAULT',)),fake_context = True, fake_context_area = 'PREFERENCES')
+                tasks_queue.add_task((bpy.ops.wm.blenderkit_welcome, ('INVOKE_DEFAULT',)), fake_context=True,
+                                     fake_context_area='PREFERENCES')
 
 
 def unregister():
diff --git a/blenderkit/paths.py b/blenderkit/paths.py
index b4210a85..399e7555 100644
--- a/blenderkit/paths.py
+++ b/blenderkit/paths.py
@@ -75,6 +75,9 @@ def get_api_url():
 def get_oauth_landing_url():
     return get_bkit_url() + BLENDERKIT_OAUTH_LANDING_URL
 
+def get_author_gallery_url(author_id):
+    return f'{get_bkit_url()}/asset-gallery?query=author_id:{author_id}'
+
 
 def default_global_dict():
     from os.path import expanduser
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index 48c34a61..800749c8 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -94,7 +94,7 @@ def upload_review_thread(url, reviews, headers):
 
 
 def get_rating(asset_id):
-    #this function isn't used anywhere,should probably get removed.
+    # 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)
@@ -114,8 +114,13 @@ def update_ratings_quality(self, context):
 
     headers = utils.get_headers(api_key)
     asset = self.id_data
-    bkit_ratings = asset.bkit_ratings
-    url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+    if asset:
+        bkit_ratings = asset.bkit_ratings
+        url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+    else:
+        # this part is for operator rating:
+        bkit_ratings = self
+        url = paths.get_api_url() + f'assets/{self.asset_id}/rating/'
 
     if bkit_ratings.rating_quality > 0.1:
         ratings = [('quality', bkit_ratings.rating_quality)]
@@ -127,15 +132,19 @@ def update_ratings_work_hours(self, context):
     api_key = user_preferences.api_key
     headers = utils.get_headers(api_key)
     asset = self.id_data
-    bkit_ratings = asset.bkit_ratings
-    url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+    if asset:
+        bkit_ratings = asset.bkit_ratings
+        url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+    else:
+        # this part is for operator rating:
+        bkit_ratings = self
+        url = paths.get_api_url() + f'assets/{self.asset_id}/rating/'
 
     if bkit_ratings.rating_work_hours > 0.05:
         ratings = [('working_hours', round(bkit_ratings.rating_work_hours, 1))]
         tasks_queue.add_task((send_rating_to_thread_work_hours, (url, ratings, headers)), wait=1, only_last=True)
 
 
-
 def upload_rating(asset):
     user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
     api_key = user_preferences.api_key
@@ -173,6 +182,7 @@ def upload_rating(asset):
     if bkit_ratings.rating_quality > 0.1 and bkit_ratings.rating_work_hours > 0.1:
         s['assets rated'][asset['asset_data']['assetBaseId']] = True
 
+
 def get_assets_for_rating():
     '''
     gets assets from scene that could/should be rated by the user.
@@ -191,26 +201,6 @@ def get_assets_for_rating():
             assets.append(b)
     return assets
 
-# class StarRatingOperator(bpy.types.Operator):
-#     """Tooltip"""
-#     bl_idname = "object.blenderkit_rating"
-#     bl_label = "Rate the Asset Quality"
-#     bl_options = {'REGISTER', 'INTERNAL'}
-#
-#     property_name: StringProperty(
-#         name="Rating Property",
-#         description="Property that is rated",
-#         default="",
-#     )
-#
-#     rating: IntProperty(name="Rating", description="rating value", default=1, min=1, max=10)
-#
-#     def execute(self, context):
-#         asset = utils.get_active_asset()
-#         props = asset.bkit_ratings
-#         props.rating_quality = self.rating
-#         return {'FINISHED'}
-
 
 asset_types = (
     ('MODEL', 'Model', 'set of objects'),
@@ -254,43 +244,212 @@ class UploadRatingOperator(bpy.types.Operator):
         return wm.invoke_props_dialog(self)
 
 
+def stars_enum_callback(self, context):
+    '''regenerates the enum property used to display rating stars, so that there are filled/empty stars correctly.'''
+    items = []
+    for a in range(0, 10):
+        if self.rating_quality < a + 1:
+            icon = 'SOLO_OFF'
+        else:
+            icon = 'SOLO_ON'
+        # has to have something before the number in the value, otherwise fails on registration.
+        items.append((f'{a + 1}', f'{a + 1}', '', icon, a + 1))
+    return items
+
 
-def draw_rating(layout, props, prop_name, name):
-    # layout.label(name)
-
-    row = layout.row(align=True)
-    # test method - 10 booleans.
-    # propsx = bpy.context.active_object.bkit_ratings
-    # for a in range(0, 10):
-    #     pn = f'rq{str(a+1).zfill(2)}'
-    #     if eval('propsx.' + pn) == False:
-    #         icon = 'SOLO_O

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list