Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/asset.c7
-rw-r--r--source/blender/blenkernel/intern/icons.c3
-rw-r--r--source/blender/blenkernel/intern/lib_query.c2
-rw-r--r--source/blender/blenloader/intern/readblenentry.c1
-rw-r--r--source/blender/blenloader/intern/readfile.c6
-rw-r--r--source/blender/blenloader/intern/writefile.c2
-rw-r--r--source/blender/editors/asset/asset_ops.c15
-rw-r--r--source/blender/makesdna/DNA_asset_types.h2
8 files changed, 30 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 6e358b55d6d..d2208dc9acb 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -20,7 +20,10 @@
#include <string.h>
+#include "BLI_utildefines.h"
+
#include "BKE_asset.h"
+#include "BKE_icons.h"
#include "BKE_idtype.h"
#include "BKE_lib_query.h"
@@ -43,7 +46,9 @@ static void asset_init_data(ID *id)
static void asset_free_data(ID *id)
{
Asset *asset = (Asset *)id;
- UNUSED_VARS(asset);
+
+ BKE_icon_id_delete((ID *)asset);
+ BKE_previewimg_free(&asset->preview);
}
static void asset_foreach_id(ID *id, LibraryForeachIDData *data)
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 6da48195aab..2090a41453d 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -29,6 +29,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_asset_types.h"
#include "DNA_brush_types.h"
#include "DNA_collection_types.h"
#include "DNA_gpencil_types.h"
@@ -339,6 +340,8 @@ PreviewImage **BKE_previewimg_id_get_p(const ID *id)
ID_PRV_CASE(ID_GR, Collection);
ID_PRV_CASE(ID_SCE, Scene);
ID_PRV_CASE(ID_SCR, bScreen);
+ ID_PRV_CASE(ID_AST, Asset);
+
#undef ID_PRV_CASE
default:
break;
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index 9fe6689848b..a2e290cf336 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -340,7 +340,7 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
case ID_LI:
return ELEM(id_type_used, ID_LI);
case ID_AST:
- return ELEM(id_type_used, ID_AST);
+ return true;
case ID_SCE:
return (ELEM(id_type_used,
ID_OB,
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index cb2094d050f..b2e765f3674 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -191,6 +191,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *to
case ID_OB: /* fall through */
case ID_GR: /* fall through */
case ID_SCE: /* fall through */
+ case ID_AST:
new_prv = MEM_callocN(sizeof(PreviewImage), "newpreview");
BLI_linklist_prepend(&previews, new_prv);
tot++;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 2f9106b6815..b23f5884719 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8073,9 +8073,11 @@ static void fix_relpaths_library(const char *basepath, Main *main)
/** \name Read ID: Asset
* \{ */
-static void direct_link_asset(FileData *UNUSED(fd), Asset *asset, Main *UNUSED(main))
+static void direct_link_asset(BlendDataReader *reader, Asset *asset)
{
id_fake_user_set(&asset->id);
+
+ asset->preview = direct_link_preview_image(reader, asset->preview);
}
static void lib_link_asset(BlendLibReader *reader, Asset *asset)
@@ -8922,7 +8924,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
direct_link_library(fd, (Library *)id, main);
break;
case ID_AST:
- direct_link_asset(fd, (Asset *)id, main);
+ direct_link_asset(&reader, (Asset *)id);
break;
case ID_CA:
direct_link_camera(&reader, (Camera *)id);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 030a4a663d6..fee411b381c 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3867,6 +3867,8 @@ static void write_asset(BlendWriter *writer, Asset *asset, const void *id_addres
if (asset->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Asset, id_address, &asset->id);
write_iddata(writer, &asset->id);
+
+ write_previews(writer, asset->preview);
}
}
/* Keep it last of write_foodata functions. */
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
index f1671f573f9..9862f14c145 100644
--- a/source/blender/editors/asset/asset_ops.c
+++ b/source/blender/editors/asset/asset_ops.c
@@ -45,6 +45,15 @@ static int asset_create_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ if (GS(id->name) == ID_AST) {
+ BKE_reportf(op->reports,
+ RPT_ERROR,
+ "The selected data-block '%s' is itself of the type asset. Creating an asset for "
+ "this is not supported.",
+ id->name + 2);
+ return OPERATOR_CANCELLED;
+ }
+
if (id->asset_data) {
BKE_reportf(op->reports, RPT_ERROR, "Data-block '%s' already is an asset", id->name + 2);
return OPERATOR_CANCELLED;
@@ -70,11 +79,11 @@ static int asset_create_exec(bContext *C, wmOperator *op)
copied_id->asset_data = BKE_asset_data_create();
UI_id_icon_render(C, NULL, copied_id, true, false);
- /* Store reference to the preview. The actual image is owned by the ID. */
- asset->preview = BKE_previewimg_id_ensure(copied_id);
+ /* Store copy of the preview for the asset. */
+ BKE_previewimg_id_copy(&asset->id, copied_id);
asset->referenced_id = copied_id;
- /* TODO generate default meta-data */
+ /* TODO generate more default meta-data */
/* TODO create asset in the asset DB, not in the local file. */
BKE_reportf(op->reports, RPT_INFO, "Asset '%s' created", copied_id->name + 2);
diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h
index ff3d286a290..d5d32d9adca 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -26,7 +26,7 @@
typedef struct Asset {
ID id;
- /** Thumbnail image of the data-block. Non-owning pointer, the actual data-block owns it. */
+ /** Thumbnail image of the data-block. Duplicate of the referenced ID preview. */
struct PreviewImage *preview;
ID *referenced_id;