Newer
Older
query["designYear_gte"] = props.search_design_year_min
query["designYear_lte"] = props.search_design_year_max
query["faceCount_gte"] = props.search_polycount_min
query["faceCount_lte"] = props.search_polycount_max
build_query_common(query, props)
return query
def build_query_scene():
'''use all search input to request results from server'''
props = bpy.context.scene.blenderkit_scene
query = {
"asset_type": 'scene',
# "engine": props.search_engine,
# "adult": props.search_adult,
}
build_query_common(query, props)
return query
def build_query_material():
props = bpy.context.scene.blenderkit_mat
query = {
"asset_type": 'material',
}
# if props.search_engine == 'NONE':
# query["engine"] = ''
# if props.search_engine != 'OTHER':
# query["engine"] = props.search_engine
# else:
# query["engine"] = props.search_engine_other
if props.search_style != 'ANY':
if props.search_style != 'OTHER':
query["style"] = props.search_style
else:
query["style"] = props.search_style_other
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
build_query_common(query, props)
return query
def build_query_texture():
props = bpy.context.scene.blenderkit_tex
query = {
"asset_type": 'texture',
}
if props.search_style != 'ANY':
if props.search_style != 'OTHER':
query["search_style"] = props.search_style
else:
query["search_style"] = props.search_style_other
build_query_common(query, props)
return query
def build_query_brush():
props = bpy.context.scene.blenderkit_brush
brush_type = ''
if bpy.context.sculpt_object is not None:
brush_type = 'sculpt'
elif bpy.context.image_paint_object: # could be just else, but for future p
brush_type = 'texture_paint'
query = {
"asset_type": 'brush',
}
build_query_common(query, props)
return query
def mt(text):
global search_start_time, prev_time
alltime = time.time() - search_start_time
since_last = time.time() - prev_time
prev_time = time.time()
def add_search_process(query, params):
global search_threads
while (len(search_threads) > 0):
old_thread = search_threads.pop(0)
old_thread[0].stop()
# TODO CARE HERE FOR ALSO KILLING THE THREADS...AT LEAST NOW SEARCH DONE FIRST WON'T REWRITE AN OLDER ONE
tempdir = paths.get_temp_dir('%s_search' % query['asset_type'])
thread = Searcher(query, params)
thread.start()
search_threads.append([thread, tempdir, query['asset_type']])
mt('thread started')
def search(category='', get_next=False, author_id=''):
''' initialize searching'''
global search_start_time
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
scene = bpy.context.scene
uiprops = scene.blenderkitUI
if uiprops.asset_type == 'MODEL':
if not hasattr(scene, 'blenderkit'):
return;
props = scene.blenderkit_models
query = build_query_model()
if uiprops.asset_type == 'SCENE':
if not hasattr(scene, 'blenderkit_scene'):
return;
props = scene.blenderkit_scene
query = build_query_scene()
if uiprops.asset_type == 'MATERIAL':
if not hasattr(scene, 'blenderkit_mat'):
return;
props = scene.blenderkit_mat
query = build_query_material()
if uiprops.asset_type == 'TEXTURE':
if not hasattr(scene, 'blenderkit_tex'):
return;
# props = scene.blenderkit_tex
# query = build_query_texture()
if uiprops.asset_type == 'BRUSH':
if not hasattr(scene, 'blenderkit_brush'):
return;
props = scene.blenderkit_brush
query = build_query_brush()
if props.is_searching and get_next == True:
return;
query['category_subtree'] = category
query['author_id'] = author_id
elif props.own_only:
# if user searches for [another] author, 'only my assets' is invalid. that's why in elif.
profile = bpy.context.window_manager.get('bkit profile')
if profile is not None:
query['author_id'] = str(profile['user']['id'])
props.is_searching = True
params = {
'scene_uuid': bpy.context.scene.get('uuid', None),
'addon_version': version_checker.get_addon_version(),
'api_key': user_preferences.api_key,
Vilem Duha
committed
# if free_only:
# query['keywords'] += '+is_free:true'
tasks_queue.add_task((ui.add_report, ('BlenderKit searching....', 2)))
props.report = 'BlenderKit searching....'
def search_update(self, context):
# if self.search_keywords != '':
ui_props = bpy.context.scene.blenderkitUI
if ui_props.down_up != 'SEARCH':
ui_props.down_up = 'SEARCH'
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
# here we tweak the input if it comes form the clipboard. we need to get rid of asset type and set it to
sprops = utils.get_search_props()
instr = 'asset_base_id:'
atstr = 'asset_type:'
kwds = sprops.search_keywords
idi = kwds.find(instr)
ati = kwds.find(atstr)
# if the asset type already isn't there it means this update function
# was triggered by it's last iteration and needs to cancel
if idi>-1 and ati == -1:
return;
if ati > -1:
at = kwds[ati:].lower()
# uncertain length of the remaining string - find as better method to check the presence of asset type
if at.find('model') > -1:
ui_props.asset_type = 'MODEL'
elif at.find('material') > -1:
ui_props.asset_type = 'MATERIAL'
elif at.find('brush') > -1:
ui_props.asset_type = 'BRUSH'
# now we trim the input copypaste by anything extra that is there,
# this is also a way for this function to recognize that it already has parsed the clipboard
# the search props can have changed and this needs to transfer the data to the other field
# this complex behaviour is here for the case where the user needs to paste manually into blender?
sprops = utils.get_search_props()
sprops.search_keywords = kwds[:ati].rstrip()
search()
class SearchOperator(Operator):
"""Tooltip"""
bl_idname = "view3d.blenderkit_search"
bl_label = "BlenderKit asset search"
bl_description = "Search online for assets"
own: BoolProperty(name="own assets only",
description="Find all own assets",
default=False)
category: StringProperty(
name="category",
description="search only subtree of this category",
author_id: StringProperty(
name="Author ID",
description="Author ID - search only assets by this author",
get_next: BoolProperty(name="next page",
description="get next page from previous search",
name="Keywords",
description="Keywords",
@classmethod
def poll(cls, context):
return True
def execute(self, context):
# TODO ; this should all get transferred to properties of the search operator, so sprops don't have to be fetched here at all.
sprops = utils.get_search_props()
if self.author_id != '':
sprops.search_keywords = ''
if self.keywords != '':
sprops.search_keywords = self.keywords
search(category=self.category, get_next=self.get_next, author_id=self.author_id)
return {'FINISHED'}
classes = [
SearchOperator
]
def register_search():
bpy.app.handlers.load_post.append(scene_load)
for c in classes:
bpy.utils.register_class(c)
bpy.app.timers.register(timer_update, persistent=True)
categories.load_categories()
def unregister_search():
bpy.app.handlers.load_post.remove(scene_load)
for c in classes:
bpy.utils.unregister_class(c)
if bpy.app.timers.is_registered(timer_update):
bpy.app.timers.unregister(timer_update)