[Bf-blender-cvs] [18c431b3a81] asset-metadata: Generate preview when making a data-block an asset

Julian Eisel noreply at git.blender.org
Sat Jul 4 15:16:41 CEST 2020


Commit: 18c431b3a81608be969e0d77d52917ca89ea07ab
Author: Julian Eisel
Date:   Thu Jul 2 18:17:15 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rB18c431b3a81608be969e0d77d52917ca89ea07ab

Generate preview when making a data-block an asset

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/asset/asset_ops.c
M	source/blender/editors/render/render_preview.c
M	source/blender/makesdna/DNA_asset_types.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fc1851a6fb9..7c393121698 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -45,6 +45,7 @@
 
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
+#include "DNA_asset_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_cachefile_types.h"
 #include "DNA_camera_types.h"
@@ -2839,6 +2840,7 @@ static void direct_link_id_common(
 
   if (id->asset_data) {
     BLO_read_data_address(reader, &id->asset_data);
+    BLO_read_data_address(reader, &id->asset_data->preview);
   }
 
   /*link direct data of ID properties*/
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
index e26d009a8c4..1ee5b876618 100644
--- a/source/blender/editors/asset/asset_ops.c
+++ b/source/blender/editors/asset/asset_ops.c
@@ -20,6 +20,7 @@
 
 #include "BKE_asset.h"
 #include "BKE_context.h"
+#include "BKE_icons.h"
 #include "BKE_lib_id.h"
 #include "BKE_report.h"
 
@@ -30,6 +31,8 @@
 #include "RNA_access.h"
 #include "RNA_define.h"
 
+#include "UI_interface_icons.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -61,8 +64,10 @@ static int asset_create_exec(bContext *C, wmOperator *op)
   }
 
   asset_id->asset_data = BKE_asset_data_create();
+  UI_id_icon_render(C, NULL, asset_id, true, false);
+  /* Store reference to the preview. The actual image is owned by the ID. */
+  asset_id->asset_data->preview = BKE_previewimg_id_ensure(asset_id);
 
-  /* TODO generate preview */
   /* TODO generate default meta-data */
   /* TODO create asset in the asset DB, not in the local file. */
 
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index 19e4f652963..33d9e599473 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -331,7 +331,7 @@ static World *preview_get_localized_world(ShaderPreview *sp, World *world)
   return sp->worldcopy;
 }
 
-static ID *duplicate_ids(ID *id)
+static ID *duplicate_ids(ID *id, bool allow_failure)
 {
   if (id == NULL) {
     /* Non-ID preview render. */
@@ -352,7 +352,9 @@ static ID *duplicate_ids(ID *id)
     case ID_SCR:
       return NULL;
     default:
-      BLI_assert(!"ID type preview not supported.");
+      if (!allow_failure) {
+        BLI_assert(!"ID type preview not supported.");
+      }
       return NULL;
   }
 }
@@ -1336,7 +1338,9 @@ void ED_preview_icon_render(Main *bmain, Scene *scene, ID *id, uint *rect, int s
   ip.scene = scene;
   ip.owner = BKE_previewimg_id_ensure(id);
   ip.id = id;
-  ip.id_copy = duplicate_ids(id);
+  /* Control isn't given back to the caller until the preview is done. So we don't need to copy
+   * the ID to avoid thread races. */
+  ip.id_copy = duplicate_ids(id, true);
 
   icon_preview_add_size(&ip, rect, sizex, sizey);
 
@@ -1376,7 +1380,7 @@ void ED_preview_icon_job(
   ip->scene = CTX_data_scene(C);
   ip->owner = owner;
   ip->id = id;
-  ip->id_copy = duplicate_ids(id);
+  ip->id_copy = duplicate_ids(id, false);
 
   icon_preview_add_size(ip, rect, sizex, sizey);
 
@@ -1445,7 +1449,7 @@ void ED_preview_shader_job(const bContext *C,
   sp->sizey = sizey;
   sp->pr_method = method;
   sp->id = id;
-  sp->id_copy = duplicate_ids(id);
+  sp->id_copy = duplicate_ids(id, false);
   sp->own_id_copy = true;
   sp->parent = parent;
   sp->slot = slot;
diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h
index 97e1bd8e474..6687dd28588 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -22,7 +22,8 @@
 #define __DNA_ASSET_TYPES_H__
 
 typedef struct AssetData {
-  char _pad[8];
+  /** Thumbnail image of the data-block. Non-owning pointer, the actual data-block owns it. */
+  struct PreviewImage *preview;
 } AssetData;
 
 #endif /* __DNA_ASSET_TYPES_H__ */



More information about the Bf-blender-cvs mailing list