示例#1
0
def upload_files(upload_data, files):
    uploaded_all = True
    for f in files:
        uploaded = upload_file(upload_data, f)
        if not uploaded:
            uploaded_all = False
        bg_blender.progress('finished uploading')
    return uploaded_all
示例#2
0
 def __iter__(self):
     with open(self.filename, 'rb') as file:
         while True:
             data = file.read(self.chunksize)
             if not data:
                 sys.stderr.write("\n")
                 break
             self.readsofar += len(data)
             percent = self.readsofar * 1e2 / self.totalsize
             bg_blender.progress('uploading %s' % self.report_name, percent)
             # sys.stderr.write("\r{percent:3.0f}%".format(percent=percent))
             yield data
示例#3
0
 def __iter__(self):
     with open(self.filename, 'rb') as file:
         while True:
             data = file.read(self.chunksize)
             if not data:
                 sys.stderr.write("\n")
                 break
             self.readsofar += len(data)
             percent = self.readsofar * 1e2 / self.totalsize
             bg_blender.progress('uploading %s' % self.report_name, percent)
             # sys.stderr.write("\r{percent:3.0f}%".format(percent=percent))
             yield data
示例#4
0
def upload_resolutions(files, data):
    preferences = bpy.context.preferences.addons['blenderkit'].preferences

    upload_data = {
        "token": preferences.api_key,
        "id": data['asset_data']['id']
    }

    uploaded = upload_bg.upload_files(upload_data, files)

    if uploaded:
        bg_blender.progress('upload finished successfully')
    else:
        bg_blender.progress('upload failed.')
示例#5
0
def upload_file(upload_data, f):
    headers = utils.get_headers(upload_data['token'])
    version_id = upload_data['id']
    bg_blender.progress(
        f"uploading {f['type']} {os.path.basename(f['file_path'])}")
    upload_info = {
        'assetId': version_id,
        'fileType': f['type'],
        'fileIndex': f['index'],
        'originalFilename': os.path.basename(f['file_path'])
    }
    upload_create_url = paths.get_api_url() + 'uploads/'
    upload = rerequests.post(upload_create_url,
                             json=upload_info,
                             headers=headers,
                             verify=True)
    upload = upload.json()
    #
    chunk_size = 1024 * 1024 * 2
    # utils.pprint(upload)
    # file gets uploaded here:
    uploaded = False
    # s3 upload is now the only option
    for a in range(0, 5):
        if not uploaded:
            try:
                upload_response = requests.put(upload['s3UploadUrl'],
                                               data=upload_in_chunks(
                                                   f['file_path'], chunk_size,
                                                   f['type']),
                                               stream=True,
                                               verify=True)

                if 250 > upload_response.status_code > 199:
                    uploaded = True
                else:
                    print(upload_response.text)
                    bg_blender.progress(f'Upload failed, retry. {a}')
            except Exception as e:
                print(e)
                bg_blender.progress('Upload %s failed, retrying' % f['type'])
                time.sleep(1)

            # confirm single file upload to bkit server
            print(upload)
            upload_done_url = paths.get_api_url(
            ) + 'uploads_s3/' + upload['id'] + '/upload-file/'
            upload_response = rerequests.post(upload_done_url,
                                              headers=headers,
                                              verify=True)

    bg_blender.progress('finished uploading')

    return uploaded
示例#6
0
def upload_files(filepath, upload_data, files):
    headers = utils.get_headers(upload_data['token'])

    version_id = upload_data['id']
    for f in files:
        bg_blender.progress('uploading %s' % f['type'])
        upload_info = {
            'assetId': version_id,
            'fileType': f['type'],
            'fileIndex': f['index'],
            'originalFilename': os.path.basename(f['file_path'])
        }
        upload_create_url = paths.get_bkit_url() + 'uploads/'
        upload = requests.post(upload_create_url, json=upload_info, headers=headers, verify=True)
        upload = upload.json()

        # upheaders = {
        #     "accept": "application/json",
        #     "Authorization": "Bearer %s" % upload_data['token'],
        #     "Content-Type": "multipart/form-data",
        #     "Content-Disposition": 'form-data; name="file"; filename=%s' % f['file_path']
        #
        # }
        chunk_size = 1024 * 256

        # file gets uploaded here:
        uploaded = False
        # s3 upload is now the only option
        for a in range(0, 20):
            if not uploaded:
                try:
                    upload_response = requests.put(upload['s3UploadUrl'],
                                                   data=upload_in_chunks(f['file_path'], chunk_size, f['type']),
                                                   stream=True, verify=True)

                    if upload_response.status_code == 200:
                        uploaded = True
                    else:
                        bg_blender.progress('Upload failed, retry.')
                except Exception as e:
                    bg_blender.progress('Upload %s failed, retrying' % f['type'])
                    time.sleep(1)

                # confirm single file upload to bkit server
                upload_done_url = paths.get_bkit_url() + 'uploads_s3/' + upload['id'] + '/upload-file/'
                upload_response = requests.post(upload_done_url, headers=headers, verify=True)

        bg_blender.progress('finished uploading')

    return {'FINISHED'}
示例#7
0
def upload_files(filepath, upload_data, files):
    headers = {"accept": "application/json", "Authorization": "Bearer %s" % upload_data['token']}
    version_id = upload_data['id']
    for f in files:
        bg_blender.progress('uploading %s' % f['type'])
        upload_info = {
            'assetId': version_id,
            'fileType': f['type'],
            'fileIndex': f['index'],
            'originalFilename': os.path.basename(f['file_path'])
        }
        upload_create_url = paths.get_bkit_url() + 'uploads/'
        upload = requests.post(upload_create_url, json=upload_info, headers=headers, verify=True)
        upload = upload.json()

        upheaders = {
            "accept": "application/json",
            "Authorization": "Bearer %s" % upload_data['token'],
            "Content-Type": "multipart/form-data",
            "Content-Disposition": 'form-data; name="file"; filename=%s' % f['file_path']

        }
        chunk_size = 1024 * 256

        # file gets uploaded here:
        uploaded = False
        # s3 upload is now the only option
        for a in range(0, 20):
            if not uploaded:
                try:
                    upload_response = requests.put(upload['s3UploadUrl'],
                                                   data=upload_in_chunks(f['file_path'], chunk_size, f['type']),
                                                   stream=True, verify=True)
                    # print('upload response')
                    # print(upload_response.text)
                    uploaded = True
                except Exception as e:
                    bg_blender.progress('Upload %s failed, retrying' % f['type'])
                    time.sleep(1)

                # confirm single file upload to bkit server
                upload_done_url = paths.get_bkit_url() + 'uploads_s3/' + upload['id'] + '/upload-file/'
                upload_response = requests.post(upload_done_url, headers=headers, verify=True)

        bg_blender.progress('finished uploading')

    return {'FINISHED'}
示例#8
0
    s.update()


def render_thumbnails():
    bpy.ops.render.render(write_still=True, animation=False)


if __name__ == "__main__":
    try:
        with open(BLENDERKIT_EXPORT_DATA, 'r') as s:
            data = json.load(s)

        user_preferences = bpy.context.preferences.addons[
            'blenderkit'].preferences

        bg_blender.progress('preparing thumbnail scene')
        obnames = get_obnames()
        main_object, allobs = append_link.append_objects(
            file_name=BLENDERKIT_EXPORT_FILE_INPUT, obnames=obnames, link=True)
        bpy.context.view_layer.update()

        camdict = {
            'GROUND': 'camera ground',
            'WALL': 'camera wall',
            'CEILING': 'camera ceiling',
            'FLOAT': 'camera float'
        }

        bpy.context.scene.camera = bpy.data.objects[camdict[
            data['thumbnail_snap_to']]]
        center_obs_for_thumbnail(allobs)
示例#9
0
                                                verify=True)

        bg_blender.progress('finished uploading')

    return {'FINISHED'}


if __name__ == "__main__":

    bpy.data.scenes.new('upload')
    for s in bpy.data.scenes:
        if s.name != 'upload':
            bpy.data.scenes.remove(s)
    try:
        # bg_blender.progress('preparing scene')
        bg_blender.progress('preparing scene - link objects')
        with open(BLENDERKIT_EXPORT_DATA, 'r') as s:
            data = json.load(s)

            bpy.app.debug_value = data.get('debug_value', 0)
            export_data = data['export_data']
            upload_data = data['upload_data']

            if export_data['type'] == 'MODEL':
                obnames = export_data['models']
                main_source, allobs = append_link.append_objects(
                    file_name=data['source_filepath'],
                    obnames=obnames,
                    rotation=(0, 0, 0))
                g = bpy.data.collections.new(upload_data['name'])
                for o in allobs:

def render_thumbnails():
    bpy.ops.render.render(write_still=True, animation=False)


def unhide_collection(cname):
    collection = bpy.context.scene.collection.children[cname]
    collection.hide_viewport = False
    collection.hide_render = False
    collection.hide_select = False


if __name__ == "__main__":
    try:
        bg_blender.progress('preparing thumbnail scene')
        with open(BLENDERKIT_EXPORT_DATA, 'r') as s:
            data = json.load(s)
            # append_material(file_name, matname = None, link = False, fake_user = True)
        mat = append_link.append_material(file_name=BLENDERKIT_EXPORT_FILE_INPUT, matname=data["material"], link=True,
                                          fake_user=False)

        user_preferences = bpy.context.preferences.addons['blenderkit'].preferences

        s = bpy.context.scene

        colmapdict = {
            'BALL': 'Ball',
            'CUBE': 'Cube',
            'FLUID': 'Fluid',
            'CLOTH': 'Cloth',
示例#11
0
def render_thumbnails():
    bpy.ops.render.render(write_still=True, animation=False)


if __name__ == "__main__":
    try:
        print('got to A')
        with open(BLENDERKIT_EXPORT_DATA, 'r', encoding='utf-8') as s:
            data = json.load(s)

        user_preferences = bpy.context.preferences.addons[
            'blenderkit'].preferences

        if data.get('do_download'):
            bg_blender.progress('Downloading asset')

            asset_data = data['asset_data']
            has_url = download.get_download_url(asset_data,
                                                download.get_scene_id(),
                                                user_preferences.api_key,
                                                tcom=None,
                                                resolution='blend')
            if not has_url == True:
                bg_blender.progress(
                    "couldn't download asset for thumnbail re-rendering")
            # download first, or rather make sure if it's already downloaded
            bg_blender.progress('downloading asset')
            fpath = download.download_asset_file(asset_data)
            data['filepath'] = fpath
            main_object, allobs = append_link.link_collection(
示例#12
0

def upload_files(upload_data, files):
    '''uploads several files in one run'''
    uploaded_all = True
    for f in files:
        uploaded = upload_file(upload_data, f)
        if not uploaded:
            uploaded_all = False
        bg_blender.progress('finished uploading')
    return uploaded_all


if __name__ == "__main__":
    try:
        bg_blender.progress('preparing scene - append data')
        with open(BLENDERKIT_EXPORT_DATA, 'r') as s:
            data = json.load(s)

        bpy.app.debug_value = data.get('debug_value', 0)
        export_data = data['export_data']
        upload_data = data['upload_data']

        upload_set = data['upload_set']
        if 'MAINFILE' in upload_set:
            bpy.data.scenes.new('upload')
            for s in bpy.data.scenes:
                if s.name != 'upload':
                    bpy.data.scenes.remove(s)

            if export_data['type'] == 'MODEL':
示例#13
0
                upload_response = requests.post(upload_done_url, headers=headers, verify=True)

        bg_blender.progress('finished uploading')

    return {'FINISHED'}


if __name__ == "__main__":

    bpy.data.scenes.new('upload')
    for s in bpy.data.scenes:
        if s.name != 'upload':
            bpy.data.scenes.remove(s)
    try:
        # bg_blender.progress('preparing scene')
        bg_blender.progress('preparing scene - link objects')
        with open(BLENDERKIT_EXPORT_DATA, 'r') as s:
            data = json.load(s)

            bpy.app.debug_value = data.get('debug_value', 0)
            export_data = data['export_data']
            upload_data = data['upload_data']

            if export_data['type'] == 'MODEL':
                obnames = export_data['models']
                main_source, allobs = append_link.append_objects(file_name=data['source_filepath'],
                                                                 obnames=obnames,
                                                                 rotation=(0, 0, 0))
                g = bpy.data.collections.new(upload_data['name'])
                for o in allobs:
                    g.objects.link(o)