Beispiel #1
0
    def execute(self, context):
        if not self.asset_index > -1:
            return {'CANCELLED'}

        # either get the data from search results
        sr = bpy.context.window_manager['search results']
        asset_data = sr[self.asset_index].to_dict()

        tempdir = tempfile.mkdtemp()

        an_slug = paths.slugify(asset_data['name'])
        thumb_path = os.path.join(tempdir, an_slug)

        args_dict = {
            "type": "material",
            "asset_name": asset_data['name'],
            "asset_data": asset_data,
            # "filepath": filepath,
            "thumbnail_path": thumb_path,
            "tempdir": tempdir,
            "do_download": True,
            "upload_after_render": True,
        }
        thumbnail_args = {
            "type": "model",
            "thumbnail_angle": self.thumbnail_angle,
            "thumbnail_snap_to": self.thumbnail_snap_to,
            "thumbnail_background_lightness":
            self.thumbnail_background_lightness,
            "thumbnail_resolution": self.thumbnail_resolution,
            "thumbnail_samples": self.thumbnail_samples,
            "thumbnail_denoising": self.thumbnail_denoising,
        }
        args_dict.update(thumbnail_args)

        start_thumbnailer(self, json_args=args_dict, wait=False)
        return {'FINISHED'}
        start_thumbnailer(self, context)
        return {'FINISHED'}
Beispiel #2
0
    def execute(self, context):
        asset = utils.get_active_model()
        asset.blenderkit.is_generating_thumbnail = True
        asset.blenderkit.thumbnail_generating_state = 'starting blender instance'

        tempdir = tempfile.mkdtemp()
        ext = '.blend'
        filepath = os.path.join(tempdir, "thumbnailer_blenderkit" + ext)

        path_can_be_relative = True
        file_dir = os.path.dirname(bpy.data.filepath)
        if file_dir == '':
            file_dir = tempdir
            path_can_be_relative = False

        an_slug = paths.slugify(asset.name)
        thumb_path = os.path.join(file_dir, an_slug)
        if path_can_be_relative:
            rel_thumb_path = os.path.join('//', an_slug)
        else:
            rel_thumb_path = thumb_path

        i = 0
        while os.path.isfile(thumb_path + '.jpg'):
            thumb_path = os.path.join(file_dir,
                                      an_slug + '_' + str(i).zfill(4))
            rel_thumb_path = os.path.join('//',
                                          an_slug + '_' + str(i).zfill(4))
            i += 1
        bkit = asset.blenderkit

        bkit.thumbnail = rel_thumb_path + '.jpg'
        bkit.thumbnail_generating_state = 'Saving .blend file'

        # save a copy of actual scene but don't interfere with the users models
        bpy.ops.wm.save_as_mainfile(filepath=filepath,
                                    compress=False,
                                    copy=True)
        # get all included objects
        obs = utils.get_hierarchy(asset)
        obnames = []
        for ob in obs:
            obnames.append(ob.name)

        args_dict = {
            "type": "material",
            "asset_name": asset.name,
            "filepath": filepath,
            "thumbnail_path": thumb_path,
            "tempdir": tempdir,
        }
        thumbnail_args = {
            "type": "model",
            "models": str(obnames),
            "thumbnail_angle": bkit.thumbnail_angle,
            "thumbnail_snap_to": bkit.thumbnail_snap_to,
            "thumbnail_background_lightness":
            bkit.thumbnail_background_lightness,
            "thumbnail_resolution": bkit.thumbnail_resolution,
            "thumbnail_samples": bkit.thumbnail_samples,
            "thumbnail_denoising": bkit.thumbnail_denoising,
        }
        args_dict.update(thumbnail_args)

        start_thumbnailer(self,
                          json_args=args_dict,
                          props=asset.blenderkit,
                          wait=False)
        return {'FINISHED'}