Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVilém Duha <vilda.novak@gmail.com>2021-05-02 11:35:04 +0300
committerVilém Duha <vilda.novak@gmail.com>2021-05-02 11:35:04 +0300
commit4d6b09c94fcd8030d85b631eee85c7a9cb97bb02 (patch)
treeaa235f93ad8338bf3815a8142c0de7e40fee8eb7
parentc12dc2b19968b3e222e5b0c41ea918a8a15c4ad0 (diff)
BlenderKit: cleanup and code de-duplication
with some tiny tweaks to how asset card works
-rw-r--r--blenderkit/autothumb_material_bg.py3
-rw-r--r--blenderkit/autothumb_model_bg.py17
-rw-r--r--blenderkit/ratings.py110
-rw-r--r--blenderkit/ratings_utils.py122
-rw-r--r--blenderkit/ui.py2
-rw-r--r--blenderkit/ui_panels.py140
6 files changed, 148 insertions, 246 deletions
diff --git a/blenderkit/autothumb_material_bg.py b/blenderkit/autothumb_material_bg.py
index 3ae0d5dd..b5d2651b 100644
--- a/blenderkit/autothumb_material_bg.py
+++ b/blenderkit/autothumb_material_bg.py
@@ -84,8 +84,6 @@ if __name__ == "__main__":
tscale = data["thumbnail_scale"]
bpy.context.view_layer.objects['scaler'].scale = (tscale, tscale, tscale)
bpy.context.view_layer.update()
- print('we have this materialB')
- print(mat)
for ob in bpy.context.visible_objects:
if ob.name[:15] == 'MaterialPreview':
@@ -103,7 +101,6 @@ if __name__ == "__main__":
if data["thumbnail_type"] in ['BALL', 'BALL_COMPLEX', 'CLOTH']:
utils.automap(ob.name, tex_size = ts / tscale, just_scale = True, bg_exception=True)
bpy.context.view_layer.update()
- print('got to C')
s.cycles.volume_step_size = tscale * .1
diff --git a/blenderkit/autothumb_model_bg.py b/blenderkit/autothumb_model_bg.py
index 36945b52..df9872fa 100644
--- a/blenderkit/autothumb_model_bg.py
+++ b/blenderkit/autothumb_model_bg.py
@@ -18,7 +18,7 @@
-from blenderkit import utils, append_link, bg_blender, download, upload_bg
+from blenderkit import utils, append_link, bg_blender, download, upload_bg, upload
import sys, json, math, os
import bpy
@@ -136,7 +136,6 @@ if __name__ == "__main__":
}
s = bpy.context.scene
s.frame_set(fdict[data['thumbnail_angle']])
- print( 'got to C')
snapdict = {
'GROUND': 'Ground',
@@ -156,7 +155,6 @@ if __name__ == "__main__":
s.cycles.samples = data['thumbnail_samples']
bpy.context.view_layer.cycles.use_denoising = data['thumbnail_denoising']
bpy.context.view_layer.update()
- print( 'got to D')
# import blender's HDR here
# hdr_path = Path('datafiles/studiolights/world/interior.exr')
@@ -180,9 +178,10 @@ if __name__ == "__main__":
render_thumbnails()
fpath = data['thumbnail_path'] + '.jpg'
if data.get('upload_after_render') and data.get('asset_data'):
+ # try to patch for the sake of older assets where thumbnail update doesn't work for the reasont
+ # that original thumbnail files aren't available.
+ # upload.patch_individual_metadata(data['asset_data']['id'], {}, user_preferences)
bg_blender.progress('uploading thumbnail')
- preferences = bpy.context.preferences.addons['blenderkit'].preferences
- print('uploading A')
file = {
"type": "thumbnail",
"index": 0,
@@ -190,20 +189,14 @@ if __name__ == "__main__":
}
upload_data = {
"name": data['asset_data']['name'],
- "token": preferences.api_key,
+ "token": user_preferences.api_key,
"id": data['asset_data']['id']
}
- print('uploading B')
upload_bg.upload_file(upload_data, file)
- print('uploading C')
bg_blender.progress('background autothumbnailer finished successfully')
-
- print( 'got to E')
-
-
except:
import traceback
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index ae3127b1..1d7b843d 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -210,120 +210,12 @@ def draw_ratings_menu(self, context, layout):
row.prop(self, 'rating_work_hours_ui_1_5', expand=True, icon_only=False, emboss=True)
-class FastRateMenu(Operator):
+class FastRateMenu(Operator, ratings_utils.RatingsProperties):
"""Rating of the assets , also directly from the asset bar - without need to download assets"""
bl_idname = "wm.blenderkit_menu_rating_upload"
bl_label = "Rate asset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
- message: StringProperty(
- name="message",
- description="message",
- default="Rating asset",
- options={'SKIP_SAVE'})
-
- asset_id: StringProperty(
- name="Asset Base Id",
- description="Unique id of the asset (hidden)",
- default="",
- options={'SKIP_SAVE'})
-
- asset_name: StringProperty(
- name="Asset Name",
- description="Name of the asset (hidden)",
- default="",
- options={'SKIP_SAVE'})
-
- asset_type: StringProperty(
- name="Asset type",
- description="asset type",
- default="",
- options={'SKIP_SAVE'})
-
- rating_quality: IntProperty(name="Quality",
- description="quality of the material",
- default=0,
- min=-1, max=10,
- # update=ratings_utils.update_ratings_quality,
- options={'SKIP_SAVE'})
-
- # 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=ratings_utils.stars_enum_callback,
- description='Rating stars 0 - 10',
- default=0,
- update=ratings_utils.update_quality_ui,
- options={'SKIP_SAVE'})
-
- rating_work_hours: FloatProperty(name="Work Hours",
- description="How many hours did this work take?",
- default=0.00,
- min=0.0, max=300,
- # update=ratings_utils.update_ratings_work_hours,
- options={'SKIP_SAVE'}
- )
-
- high_rating_warning = "This is a high rating, please be sure to give such rating only to amazing assets"
-
- rating_work_hours_ui: EnumProperty(name="Work Hours",
- description="How many hours did this work take?",
- items=[('0', '0', ''),
- ('.5', '0.5', ''),
- ('1', '1', ''),
- ('2', '2', ''),
- ('3', '3', ''),
- ('4', '4', ''),
- ('5', '5', ''),
- ('6', '6', ''),
- ('8', '8', ''),
- ('10', '10', ''),
- ('15', '15', ''),
- ('20', '20', ''),
- ('30', '30', high_rating_warning),
- ('50', '50', high_rating_warning),
- ('100', '100', high_rating_warning),
- ('150', '150', high_rating_warning),
- ('200', '200', high_rating_warning),
- ('250', '250', high_rating_warning),
- ],
- default='0', update=ratings_utils.update_ratings_work_hours_ui,
- options={'SKIP_SAVE'}
- )
-
- rating_work_hours_ui_1_5: EnumProperty(name="Work Hours",
- description="How many hours did this work take?",
- items=[('0', '0', ''),
- ('.2', '0.2', ''),
- ('.5', '0.5', ''),
- ('1', '1', ''),
- ('2', '2', ''),
- ('3', '3', ''),
- ('4', '4', ''),
- ('5', '5', '')
- ],
- default='0',
- update=ratings_utils.update_ratings_work_hours_ui_1_5,
- options={'SKIP_SAVE'}
- )
-
- rating_work_hours_ui_1_10: EnumProperty(name="Work Hours",
- description="How many hours did this work take?",
- items=[('0', '0', ''),
- ('1', '1', ''),
- ('2', '2', ''),
- ('3', '3', ''),
- ('4', '4', ''),
- ('5', '5', ''),
- ('6', '6', ''),
- ('7', '7', ''),
- ('8', '8', ''),
- ('9', '9', ''),
- ('10', '10', '')
- ],
- default='0',
- update=ratings_utils.update_ratings_work_hours_ui_1_10,
- options={'SKIP_SAVE'}
- )
@classmethod
def poll(cls, context):
diff --git a/blenderkit/ratings_utils.py b/blenderkit/ratings_utils.py
index be698300..9ceea9d0 100644
--- a/blenderkit/ratings_utils.py
+++ b/blenderkit/ratings_utils.py
@@ -19,6 +19,18 @@
# mainly update functions and callbacks for ratings properties, here to avoid circular imports.
import bpy
from blenderkit import utils, paths, tasks_queue, rerequests
+
+from bpy.props import (
+ IntProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ StringProperty,
+ EnumProperty,
+ BoolProperty,
+ PointerProperty,
+)
+
+
import threading
import requests
import logging
@@ -158,3 +170,113 @@ def stars_enum_callback(self, context):
# 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
+
+class RatingsProperties():
+ message: StringProperty(
+ name="message",
+ description="message",
+ default="Rating asset",
+ options={'SKIP_SAVE'})
+
+ asset_id: StringProperty(
+ name="Asset Base Id",
+ description="Unique id of the asset (hidden)",
+ default="",
+ options={'SKIP_SAVE'})
+
+ asset_name: StringProperty(
+ name="Asset Name",
+ description="Name of the asset (hidden)",
+ default="",
+ options={'SKIP_SAVE'})
+
+ asset_type: StringProperty(
+ name="Asset type",
+ description="asset type",
+ default="",
+ options={'SKIP_SAVE'})
+
+ rating_quality: IntProperty(name="Quality",
+ description="quality of the material",
+ default=0,
+ min=-1, max=10,
+ update=update_ratings_quality,
+ options={'SKIP_SAVE'})
+
+ # 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=0,
+ update=update_quality_ui,
+ options={'SKIP_SAVE'})
+
+ rating_work_hours: FloatProperty(name="Work Hours",
+ description="How many hours did this work take?",
+ default=0.00,
+ min=0.0, max=300,
+ update=update_ratings_work_hours,
+ options={'SKIP_SAVE'}
+ )
+
+ high_rating_warning = "This is a high rating, please be sure to give such rating only to amazing assets"
+
+ rating_work_hours_ui: EnumProperty(name="Work Hours",
+ description="How many hours did this work take?",
+ items=[('0', '0', ''),
+ ('.5', '0.5', ''),
+ ('1', '1', ''),
+ ('2', '2', ''),
+ ('3', '3', ''),
+ ('4', '4', ''),
+ ('5', '5', ''),
+ ('6', '6', ''),
+ ('8', '8', ''),
+ ('10', '10', ''),
+ ('15', '15', ''),
+ ('20', '20', ''),
+ ('30', '30', high_rating_warning),
+ ('50', '50', high_rating_warning),
+ ('100', '100', high_rating_warning),
+ ('150', '150', high_rating_warning),
+ ('200', '200', high_rating_warning),
+ ('250', '250', high_rating_warning),
+ ],
+ default='0', update=update_ratings_work_hours_ui,
+ options={'SKIP_SAVE'}
+ )
+
+ rating_work_hours_ui_1_5: EnumProperty(name="Work Hours",
+ description="How many hours did this work take?",
+ items=[('0', '0', ''),
+ ('.2', '0.2', ''),
+ ('.5', '0.5', ''),
+ ('1', '1', ''),
+ ('2', '2', ''),
+ ('3', '3', ''),
+ ('4', '4', ''),
+ ('5', '5', '')
+ ],
+ default='0',
+ update=update_ratings_work_hours_ui_1_5,
+ options={'SKIP_SAVE'}
+ )
+
+ rating_work_hours_ui_1_10: EnumProperty(name="Work Hours",
+ description="How many hours did this work take?",
+ items=[('0', '0', ''),
+ ('1', '1', ''),
+ ('2', '2', ''),
+ ('3', '3', ''),
+ ('4', '4', ''),
+ ('5', '5', ''),
+ ('6', '6', ''),
+ ('7', '7', ''),
+ ('8', '8', ''),
+ ('9', '9', ''),
+ ('10', '10', '')
+ ],
+ default='0',
+ update=update_ratings_work_hours_ui_1_10,
+ options={'SKIP_SAVE'}
+ ) \ No newline at end of file
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index 644980de..182ab99a 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -1131,6 +1131,7 @@ class ParticlesDropDialog(bpy.types.Operator):
# wm = context.window_manager
# return wm.invoke_props_dialog(self, width=400)
+
class AssetBarOperator(bpy.types.Operator):
'''runs search and displays the asset bar at the same time'''
bl_idname = "view3d.blenderkit_asset_bar"
@@ -1174,6 +1175,7 @@ class AssetBarOperator(bpy.types.Operator):
ui_props.assetbar_on = False
def modal(self, context, event):
+
# This is for case of closing the area or changing type:
ui_props = context.scene.blenderkitUI
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index daa374c1..3cd7b7af 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -1402,121 +1402,14 @@ def label_or_url(layout, text='', tooltip='', url='', icon_value=None, icon=None
layout.label(text=text)
-class AssetPopupCard(bpy.types.Operator):
+class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
"""Generate Cycles thumbnail for model assets"""
bl_idname = "wm.blenderkit_asset_popup"
bl_label = "BlenderKit asset popup"
width = 700
- message: StringProperty(
- name="message",
- description="message",
- default="Rating asset",
- options={'SKIP_SAVE'})
-
- asset_id: StringProperty(
- name="Asset Base Id",
- description="Unique id of the asset (hidden)",
- default="",
- options={'SKIP_SAVE'})
-
- asset_name: StringProperty(
- name="Asset Name",
- description="Name of the asset (hidden)",
- default="",
- options={'SKIP_SAVE'})
-
- asset_type: StringProperty(
- name="Asset type",
- description="asset type",
- default="",
- options={'SKIP_SAVE'})
-
- rating_quality: IntProperty(name="Quality",
- description="quality of the material",
- default=0,
- min=-1, max=10,
- update=ratings_utils.update_ratings_quality,
- options={'SKIP_SAVE'})
-
- # 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=ratings_utils.stars_enum_callback,
- description='Rating stars 0 - 10',
- default=0,
- update=ratings_utils.update_quality_ui,
- options={'SKIP_SAVE'})
-
- rating_work_hours: FloatProperty(name="Work Hours",
- description="How many hours did this work take?",
- default=0.00,
- min=0.0, max=300,
- update=ratings_utils.update_ratings_work_hours,
- options={'SKIP_SAVE'}
- )
-
- high_rating_warning = "This is a high rating, please be sure to give such rating only to amazing assets"
-
- rating_work_hours_ui: EnumProperty(name="Work Hours",
- description="How many hours did this work take?",
- items=[('0', '0', ''),
- ('.5', '0.5', ''),
- ('1', '1', ''),
- ('2', '2', ''),
- ('3', '3', ''),
- ('4', '4', ''),
- ('5', '5', ''),
- ('6', '6', ''),
- ('8', '8', ''),
- ('10', '10', ''),
- ('15', '15', ''),
- ('20', '20', ''),
- ('30', '30', high_rating_warning),
- ('50', '50', high_rating_warning),
- ('100', '100', high_rating_warning),
- ('150', '150', high_rating_warning),
- ('200', '200', high_rating_warning),
- ('250', '250', high_rating_warning),
- ],
- default='0', update=ratings_utils.update_ratings_work_hours_ui,
- options={'SKIP_SAVE'}
- )
-
- rating_work_hours_ui_1_5: EnumProperty(name="Work Hours",
- description="How many hours did this work take?",
- items=[('0', '0', ''),
- ('.2', '0.2', ''),
- ('.5', '0.5', ''),
- ('1', '1', ''),
- ('2', '2', ''),
- ('3', '3', ''),
- ('4', '4', ''),
- ('5', '5', '')
- ],
- default='0',
- update=ratings_utils.update_ratings_work_hours_ui_1_5,
- options={'SKIP_SAVE'}
- )
-
- rating_work_hours_ui_1_10: EnumProperty(name="Work Hours",
- description="How many hours did this work take?",
- items=[('0', '0', ''),
- ('1', '1', ''),
- ('2', '2', ''),
- ('3', '3', ''),
- ('4', '4', ''),
- ('5', '5', ''),
- ('6', '6', ''),
- ('7', '7', ''),
- ('8', '8', ''),
- ('9', '9', ''),
- ('10', '10', '')
- ],
- default='0',
- update=ratings_utils.update_ratings_work_hours_ui_1_10,
- options={'SKIP_SAVE'}
- )
+
@classmethod
def poll(cls, context):
@@ -1551,7 +1444,7 @@ class AssetPopupCard(bpy.types.Operator):
return
self.draw_property(layout, pretext, parameter)
- def draw_properties(self, layout):
+ def draw_properties(self, layout, width = 250):
if type(self.asset_data['parameters']) == list:
mparams = utils.params_to_dict(self.asset_data['parameters'])
@@ -1563,7 +1456,7 @@ class AssetPopupCard(bpy.types.Operator):
box = layout.box()
box.scale_y = 0.8
box.label(text='Description')
- utils.label_multiline(box, self.asset_data['description'], width=200)
+ utils.label_multiline(box, self.asset_data['description'], width=width)
pcoll = icons.icon_collections["main"]
@@ -1659,8 +1552,8 @@ class AssetPopupCard(bpy.types.Operator):
# Free/Full plan or private Access
plans_tooltip = 'BlenderKit has 2 plans:\n'\
' * Free plan - more than 50% of all assets\n'\
- ' * Full plan - unlimited access to everything'\
- 'Click to go to subscriptions page.'
+ ' * Full plan - unlimited access to everything\n'\
+ 'Click to go to subscriptions page'
plans_link = 'https://www.blenderkit.com/plans/pricing/'
if self.asset_data['isPrivate']:
t = 'Private'
@@ -1681,7 +1574,7 @@ class AssetPopupCard(bpy.types.Operator):
url=plans_link)
def draw_author_area(self, context, layout, width=330):
- self.draw_author(context, layout, width=330)
+ self.draw_author(context, layout, width=width)
def draw_author(self, context, layout, width=330):
image_split = 0.25
@@ -1746,8 +1639,9 @@ class AssetPopupCard(bpy.types.Operator):
box_thumbnail.scale_y = .4
box_thumbnail.template_icon(icon_value=self.img.preview.icon_id, scale=34.0)
+
# row = box_thumbnail.row()
- # row.scale_y = 4
+ # row.scale_y = 3
# op = row.operator('view3d.asset_drag_drop', text='Drag & Drop from here', depress=True)
row = box_thumbnail.row()
@@ -1795,21 +1689,22 @@ class AssetPopupCard(bpy.types.Operator):
box_thumbnail.label(text=f"This asset has only {rcount} rating{'' if rcount == 1 else 's'} , please rate.")
# box_thumbnail.label(text=f"Please rate this asset.")
- def draw_menu_desc_author(self, context, layout):
+ def draw_menu_desc_author(self, context, layout, width = 330):
box = layout.column()
box.emboss = 'NORMAL'
# left - tooltip & params
row = box.row()
- split_left_left = row.split(factor=0.7)
- self.draw_properties(split_left_left)
+ split_factor = 0.7
+ split_left_left = row.split(factor=split_factor)
+ self.draw_properties(split_left_left, width = int(width*split_factor))
# right - menu
col1 = split_left_left.split()
self.draw_menu(context, col1)
# author
- self.draw_author_area(context, box, width=330)
+ self.draw_author_area(context, box, width=width)
def draw(self, context):
ui_props = context.scene.blenderkitUI
@@ -1821,17 +1716,18 @@ class AssetPopupCard(bpy.types.Operator):
# top draggabe bar with name of the asset
top_row = layout.row()
top_drag_bar = top_row.box()
- top_drag_bar.alignment = 'CENTER'
-
top_drag_bar.label(text=asset_data['displayName'])
+
# left side
row = layout.row(align=True)
+
+ split_ratio = 0.5
split_left = row.split(factor=0.5)
self.draw_thumbnail_box(split_left)
# right split
split_right = split_left.split()
- self.draw_menu_desc_author(context, split_right)
+ self.draw_menu_desc_author(context, split_right, width = int(self.width*split_ratio))
ratings_box = layout.box()
ratings_box.scale_y = 0.7