Newer
Older
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)
# print(export_data)
# print(upload_data)
# 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')
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)
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
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.scene['search results']:
print('no search results found')
return {'CANCELLED'};
# update status in search results for validator's clarity
sr = bpy.context.scene['search results']
sro = bpy.context.scene['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:
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.scene['search results']:
# update status in search results for validator's clarity
sr = bpy.context.scene['search results']
sro = bpy.context.scene['search results orig']['results']
for r in sr:
if r['id'] == self.asset_id:
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)