[Bf-blender-cvs] [fff746f00ae] asset-metadata: Use new Asset data-block type for "Create Asset" operator
Julian Eisel
noreply at git.blender.org
Wed Jul 8 12:44:47 CEST 2020
Commit: fff746f00ae36fcd67c0d8796bf3ba8a28d4e281
Author: Julian Eisel
Date: Wed Jul 8 12:42:59 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rBfff746f00ae36fcd67c0d8796bf3ba8a28d4e281
Use new Asset data-block type for "Create Asset" operator
AssetData is unused now. Just keeping it in case it's useful later (to avoid
having to do the monkey work to add it again).
===================================================================
M source/blender/blenkernel/intern/asset.c
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/asset/asset_ops.c
M source/blender/makesdna/DNA_asset_types.h
===================================================================
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 04ad12375bc..6e358b55d6d 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -22,6 +22,7 @@
#include "BKE_asset.h"
#include "BKE_idtype.h"
+#include "BKE_lib_query.h"
#include "BLT_translation.h"
@@ -45,6 +46,13 @@ static void asset_free_data(ID *id)
UNUSED_VARS(asset);
}
+static void asset_foreach_id(ID *id, LibraryForeachIDData *data)
+{
+ Asset *asset = (Asset *)id;
+
+ BKE_LIB_FOREACHID_PROCESS_ID(data, asset->referenced_id, IDWALK_CB_USER);
+}
+
IDTypeInfo IDType_ID_AST = {
/* id_code */ ID_AST,
/* id_filter */ FILTER_ID_AST,
@@ -52,14 +60,14 @@ IDTypeInfo IDType_ID_AST = {
/* struct_size */ sizeof(Asset),
/* name */ "Asset",
/* name_plural */ "assets",
- /* translation_context */ BLT_I18NCONTEXT_ID_SIMULATION,
+ /* translation_context */ BLT_I18NCONTEXT_ID_ASSET,
/* flags */ 0,
/* init_data */ asset_init_data,
/* copy_data */ NULL,
/* free_data */ asset_free_data,
/* make_local */ NULL,
- /* foreach_id */ NULL,
+ /* foreach_id */ asset_foreach_id,
};
AssetData *BKE_asset_data_create(void)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7e7ed4b2a3c..2f9106b6815 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2666,7 +2666,6 @@ 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*/
@@ -8079,8 +8078,9 @@ static void direct_link_asset(FileData *UNUSED(fd), Asset *asset, Main *UNUSED(m
id_fake_user_set(&asset->id);
}
-static void lib_link_asset(BlendLibReader *UNUSED(reader), Asset *UNUSED(asset))
+static void lib_link_asset(BlendLibReader *reader, Asset *asset)
{
+ BLO_read_id_address(reader, asset->id.lib, &asset->referenced_id);
}
/** \} */
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
index f78f8cc0d75..f1671f573f9 100644
--- a/source/blender/editors/asset/asset_ops.c
+++ b/source/blender/editors/asset/asset_ops.c
@@ -51,28 +51,33 @@ static int asset_create_exec(bContext *C, wmOperator *op)
}
struct Main *bmain = CTX_data_main(C);
- ID *asset_id = NULL;
+ Asset *asset = BKE_id_new(bmain, ID_AST, id->name + 2);
+ ID *copied_id = NULL;
/* TODO this should probably be somewhere in BKE. */
/* TODO this is not a deep copy... */
- if (!BKE_id_copy(bmain, id, &asset_id)) {
+ if (!BKE_id_copy(bmain, id, &copied_id)) {
BKE_reportf(op->reports,
RPT_ERROR,
"Data-block '%s' could not be copied into an asset data-block",
id->name);
return OPERATOR_CANCELLED;
}
- id_fake_user_set(asset_id);
+ id_fake_user_set(copied_id);
+ id_fake_user_set(&asset->id);
- asset_id->asset_data = BKE_asset_data_create();
- UI_id_icon_render(C, NULL, asset_id, true, false);
+ /* Asset data is a dummy right now. Keeping it in case it's useful later. */
+ 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_id->asset_data->preview = BKE_previewimg_id_ensure(asset_id);
+ asset->preview = BKE_previewimg_id_ensure(copied_id);
+ asset->referenced_id = copied_id;
/* TODO generate default meta-data */
/* TODO create asset in the asset DB, not in the local file. */
- BKE_reportf(op->reports, RPT_INFO, "Asset '%s' created", asset_id->name + 2);
+ BKE_reportf(op->reports, RPT_INFO, "Asset '%s' created", copied_id->name + 2);
WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h
index 82cb4c37fac..ff3d286a290 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -25,11 +25,16 @@
typedef struct Asset {
ID id;
-} Asset;
-typedef struct AssetData {
/** Thumbnail image of the data-block. Non-owning pointer, the actual data-block owns it. */
struct PreviewImage *preview;
+
+ ID *referenced_id;
+} Asset;
+
+/* TODO unused, keeping in case it's useful later. */
+typedef struct AssetData {
+ int dummy;
} AssetData;
#endif /* __DNA_ASSET_TYPES_H__ */
More information about the Bf-blender-cvs
mailing list