Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
"verificationStatus": "uploaded"
}
url = paths.get_api_url() + 'assets/'
headers = utils.get_headers(self.upload_data['token'])
url += self.upload_data["id"] + '/'
r = rerequests.patch(url, json=confirm_data, headers=headers, verify=True) # files = files,
self.end_upload('Upload finished successfully')
else:
self.end_upload('Upload failed')
except Exception as e:
self.end_upload(e)
print(e)
return {'CANCELLED'}
def check_missing_data(asset_type, props):
'''
checks if user did everything allright for particular assets and notifies him back if not.
Parameters
----------
asset_type
props
Returns
-------
'''
if asset_type == 'MODEL':
check_missing_data_model(props)
if asset_type == 'SCENE':
check_missing_data_scene(props)
elif asset_type == 'MATERIAL':
check_missing_data_material(props)
elif asset_type == 'BRUSH':
check_missing_data_brush(props)
def start_upload(self, context, asset_type, reupload, upload_set):
'''start upload process, by processing data, then start a thread that cares about the rest of the upload.'''
# fix the name first
utils.name_update(props)
storage_quota_ok = check_storage_quota(props)
if not storage_quota_ok:
self.report({'ERROR_INVALID_INPUT'}, props.report)
return {'CANCELLED'}
location = get_upload_location(props)
props.upload_state = 'preparing upload'
auto_fix(asset_type=asset_type)
# do this for fixing long tags in some upload cases
props.tags = props.tags[:]
# check for missing metadata
check_missing_data(asset_type, props)
# if previous check did find any problems then
if props.report != '':
self.report({'ERROR_INVALID_INPUT'}, props.report)
return {'CANCELLED'}
Vilem Duha
committed
props.asset_base_id = ''
props.id = ''
export_data, upload_data = get_upload_data(caller=self, context=context, asset_type=asset_type)
# check if thumbnail exists, generate for HDR:
if asset_type == 'HDR':
image_utils.generate_hdr_thumbnail()
elif not os.path.exists(export_data["thumbnail_path"]):
props.upload_state = 'Thumbnail not found'
props.uploading = False
return {'CANCELLED'}
if upload_set == {'METADATA'}:
props.upload_state = "Updating metadata. Please don't close Blender until upload finishes"
else:
props.upload_state = "Starting upload. Please don't close Blender until upload finishes"
# save a copy of the file for processing. Only for blend files
basename, ext = os.path.splitext(bpy.data.filepath)
if not ext:
ext = ".blend"
export_data['temp_dir'] = tempfile.mkdtemp()
export_data['source_filepath'] = os.path.join(export_data['temp_dir'], "export_blenderkit" + ext)
if asset_type != 'HDR':
bpy.ops.wm.save_as_mainfile(filepath=export_data['source_filepath'], compress=False, copy=True)
export_data['binary_path'] = bpy.app.binary_path
export_data['debug_value'] = bpy.app.debug_value
upload_thread = Uploader(upload_data=upload_data, export_data=export_data, upload_set=upload_set)
upload_thread.start()
return {'FINISHED'}
asset_types = (
('MODEL', 'Model', 'Set of objects'),
('SCENE', 'Scene', 'Scene'),
('HDR', 'HDR', 'HDR image'),
('MATERIAL', 'Material', 'Any .blend Material'),
('TEXTURE', 'Texture', 'A texture, or texture set'),
('BRUSH', 'Brush', 'Brush, can be any type of blender brush'),
('ADDON', 'Addon', 'Addnon'),
"""Tooltip"""
bl_idname = "object.blenderkit_upload"
bl_description = "Upload or re-upload asset + thumbnail + metadata"
bl_label = "BlenderKit asset upload"
# type of upload - model, material, textures, e.t.c.
asset_type: EnumProperty(
name="Type",
items=asset_types,
description="Type of upload",
default="MODEL",
)
reupload: BoolProperty(
name="reupload",
description="reupload but also draw so that it asks what to reupload",
default=False,
options={'SKIP_SAVE'}
)
metadata: BoolProperty(
name="metadata",
default=True,
options={'SKIP_SAVE'}
)
thumbnail: BoolProperty(
name="thumbnail",
default=False,
options={'SKIP_SAVE'}
)
main_file: BoolProperty(
name="main file",
default=False,
options={'SKIP_SAVE'}
)
@classmethod
def poll(cls, context):
def execute(self, context):
bpy.ops.object.blenderkit_auto_tags()
props = utils.get_upload_props()
# in case of name change, we have to reupload everything, since the name is stored in blender file,
# and is used for linking to scene
# if props.name_changed:
# # TODO: this needs to be replaced with new double naming scheme (metadata vs blend data)
# # print('has to reupload whole data, name has changed.')
# self.main_file = True
# props.name_changed = False
upload_set = []
if not self.reupload:
upload_set = ['METADATA', 'THUMBNAIL', 'MAINFILE']
else:
if self.metadata:
upload_set.append('METADATA')
if self.thumbnail:
upload_set.append('THUMBNAIL')
if self.main_file:
upload_set.append('MAINFILE')
#this is accessed later in get_upload_data and needs to be written.
# should pass upload_set all the way to it probably
if 'MAINFILE' in upload_set:
self.main_file = True
result = start_upload(self, context, self.asset_type, self.reupload, upload_set=upload_set, )
Vilem Duha
committed
props = utils.get_upload_props()
if self.reupload:
# layout.prop(self, 'metadata')
layout.prop(self, 'main_file')
layout.prop(self, 'thumbnail')
if props.asset_base_id != '' and not self.reupload:
Vilem Duha
committed
layout.label(text="Really upload as new? ")
layout.label(text="Do this only when you create a new asset from an old one.")
layout.label(text="For updates of thumbnail or model use reupload.")
if props.is_private == 'PUBLIC':
utils.label_multiline(layout, text='public assets are validated several hours'
' or days after upload. Remember always to '
'test download your asset to a clean file'
' to see if it uploaded correctly.'
, width=300)
Vilem Duha
committed
def invoke(self, context, event):
props = utils.get_upload_props()
ui_panels.draw_not_logged_in(self, message='To upload assets you need to login/signup.')
return context.window_manager.invoke_props_dialog(self)
else:
return self.execute(context)
class AssetDebugPrint(Operator):
"""Change verification status"""
bl_idname = "object.blenderkit_print_asset_debug"
bl_description = "BlenderKit print asset data for debug purposes"
bl_label = "BlenderKit print asset data"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
# type of upload - model, material, textures, e.t.c.
asset_id: StringProperty(
name="asset id",
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
preferences = bpy.context.preferences.addons['blenderkit'].preferences
if not bpy.context.window_manager['search results']:
print('no search results found')
return {'CANCELLED'};
# update status in search results for validator's clarity
sr = bpy.context.window_manager['search results']
sro = bpy.context.window_manager['search results orig']['results']
result = None
for r in sr:
if r['id'] == self.asset_id:
result = r.to_dict()
if not result:
for r in sro:
if r['id'] == self.asset_id:
result = r.to_dict()
if not result:
ad = bpy.context.active_object.get('asset_data')
if ad:
result = ad.to_dict()
if result:
t = bpy.data.texts.new(result['name'])
t.write(json.dumps(result, indent=4, sort_keys=True))
print(json.dumps(result, indent=4, sort_keys=True))
return {'FINISHED'}
class AssetVerificationStatusChange(Operator):
"""Change verification status"""
bl_idname = "object.blenderkit_change_status"
bl_description = "Change asset ststus"
bl_label = "Change verification status"
# type of upload - model, material, textures, e.t.c.
asset_id: StringProperty(
name="asset id",
)
state: StringProperty(
name="verification_status",
@classmethod
def poll(cls, context):
return True
def draw(self, context):
layout = self.layout
layout.label(text='Really delete asset from BlenderKit online storage?')
# layout.prop(self, 'state')
def execute(self, context):
preferences = bpy.context.preferences.addons['blenderkit'].preferences
if not bpy.context.window_manager['search results']:
# update status in search results for validator's clarity
sr = bpy.context.window_manager['search results']
sro = bpy.context.window_manager['search results orig']['results']
r['verificationStatus'] = self.state
for r in sro:
if r['id'] == self.asset_id:
r['verificationStatus'] = self.state
thread = threading.Thread(target=verification_status_change_thread,
args=(self.asset_id, self.state, preferences.api_key))
thread.start()
return {'FINISHED'}
wm = context.window_manager
return wm.invoke_props_dialog(self)
# bpy.utils.register_class(FastMetadataMenu)
bpy.utils.register_class(FastMetadata)
bpy.utils.register_class(AssetVerificationStatusChange)
# bpy.utils.unregister_class(FastMetadataMenu)
bpy.utils.unregister_class(FastMetadata)
bpy.utils.unregister_class(AssetVerificationStatusChange)