[Bf-blender-cvs] [5760dc3da52] asset-metadata: Initial "Make Asset" operator

Julian Eisel noreply at git.blender.org
Wed Jul 1 20:32:07 CEST 2020


Commit: 5760dc3da5240e8d6e7a7f78c106f47806db527f
Author: Julian Eisel
Date:   Wed Jul 1 20:15:54 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rB5760dc3da5240e8d6e7a7f78c106f47806db527f

Initial "Make Asset" operator

Accessible via the Outliner context menu (ID Data submenu).

The operator currently copies the data-block and creates empty asset data for
it. This will later contain all the meta-data to "give the data-block meaning".

Of course there are many TODOs and questions remaining. This is the first step
so I can work more on meta-data support.
I created some files and that I think make sense.

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

M	doc/doxygen/doxygen.source.h
M	source/blender/CMakeLists.txt
A	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/asset.c
M	source/blender/blenkernel/intern/lib_id_delete.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/CMakeLists.txt
A	source/blender/editors/asset/CMakeLists.txt
A	source/blender/editors/asset/asset_ops.c
A	source/blender/editors/include/ED_asset.h
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/makesdna/DNA_ID.h
A	source/blender/makesdna/DNA_asset_types.h
M	source/blender/makesdna/DNA_text_types.h
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/intern/CMakeLists.txt

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

diff --git a/doc/doxygen/doxygen.source.h b/doc/doxygen/doxygen.source.h
index 613e513bcc6..510f3fe8ffe 100644
--- a/doc/doxygen/doxygen.source.h
+++ b/doc/doxygen/doxygen.source.h
@@ -121,6 +121,10 @@
  *  \ingroup editors
  */
 
+/** \defgroup edasset asset
+ *  \ingroup editors
+ */
+
 /** \defgroup edcurve curve
  *  \ingroup editors
  */
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 593d972b0af..36b6f2d5c71 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -23,6 +23,7 @@ set(SRC_DNA_INC
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_action_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_anim_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_armature_types.h
+  ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_asset_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_boid_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_brush_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_cachefile_types.h
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
new file mode 100644
index 00000000000..670325b9bb3
--- /dev/null
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __BKE_ASSET_H__
+#define __BKE_ASSET_H__
+
+/** \file
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AssetData *BKE_asset_data_create(void);
+void BKE_asset_data_free(struct AssetData *asset_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_ASSET_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index b9054d29752..e5e8e0e1676 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -76,6 +76,7 @@ set(SRC
   intern/armature.c
   intern/armature_deform.c
   intern/armature_update.c
+  intern/asset.c
   intern/autoexec.c
   intern/blender.c
   intern/blender_copybuffer.c
@@ -267,6 +268,7 @@ set(SRC
   BKE_appdir.h
   BKE_armature.h
   BKE_autoexec.h
+  BKE_asset.h
   BKE_blender.h
   BKE_blender_copybuffer.h
   BKE_blender_undo.h
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
new file mode 100644
index 00000000000..e12a3a248ba
--- /dev/null
+++ b/source/blender/blenkernel/intern/asset.c
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BKE_asset.h"
+
+#include "DNA_asset_types.h"
+
+#include "MEM_guardedalloc.h"
+
+AssetData *BKE_asset_data_create(void)
+{
+  return MEM_callocN(sizeof(AssetData), __func__);
+}
+
+void BKE_asset_data_free(AssetData *asset_data)
+{
+  MEM_SAFE_FREE(asset_data);
+}
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index b4f2caac861..7e83f39d0a9 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -31,6 +31,7 @@
 #include "BLI_listbase.h"
 
 #include "BKE_anim_data.h"
+#include "BKE_asset.h"
 #include "BKE_idprop.h"
 #include "BKE_idtype.h"
 #include "BKE_key.h"
@@ -62,6 +63,10 @@ void BKE_libblock_free_data(ID *id, const bool do_id_user)
     BKE_lib_override_library_free(&id->override_library, do_id_user);
   }
 
+  if (id->asset_data) {
+    BKE_asset_data_free(id->asset_data);
+  }
+
   BKE_animdata_free(id, do_id_user);
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index e4822c4cb7f..fc1851a6fb9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2837,6 +2837,10 @@ static void direct_link_id_common(
     return;
   }
 
+  if (id->asset_data) {
+    BLO_read_data_address(reader, &id->asset_data);
+  }
+
   /*link direct data of ID properties*/
   if (id->properties) {
     BLO_read_data_address(reader, &id->properties);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 4e0325e72fa..a9f89290b69 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -95,6 +95,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"
@@ -734,6 +735,10 @@ void IDP_WriteProperty(const IDProperty *prop, BlendWriter *writer)
 
 static void write_iddata(BlendWriter *writer, ID *id)
 {
+  if (id->asset_data) {
+    BLO_write_struct(writer, AssetData, id->asset_data);
+  }
+
   /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
   if (id->properties && !ELEM(GS(id->name), ID_WM)) {
     IDP_WriteProperty(id->properties, writer);
diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt
index 7910cf47a33..fd3b887716d 100644
--- a/source/blender/editors/CMakeLists.txt
+++ b/source/blender/editors/CMakeLists.txt
@@ -22,6 +22,7 @@ if(WITH_BLENDER)
 
   add_subdirectory(animation)
   add_subdirectory(armature)
+  add_subdirectory(asset)
   add_subdirectory(curve)
   add_subdirectory(gpencil)
   add_subdirectory(interface)
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
new file mode 100644
index 00000000000..76f02ceae61
--- /dev/null
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -0,0 +1,37 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+    ../include
+    ../../blenlib
+    ../../blenkernel
+    ../../makesdna
+    ../../makesrna
+    ../../windowmanager
+)
+
+set(INC_SYS
+)
+
+set(SRC
+  asset_ops.c
+)
+
+set(LIB
+)
+
+blender_add_lib(bf_editor_asset "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.c
new file mode 100644
index 00000000000..e26d009a8c4
--- /dev/null
+++ b/source/blender/editors/asset/asset_ops.c
@@ -0,0 +1,91 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#include "BKE_asset.h"
+#include "BKE_context.h"
+#include "BKE_lib_id.h"
+#include "BKE_report.h"
+
+#include "ED_asset.h"
+
+#include "DNA_asset_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+static int asset_create_exec(bContext *C, wmOperator *op)
+{
+  PointerRNA idptr = RNA_pointer_get(op->ptr, "id");
+  ID *id = idptr.data;
+
+  if (!id || !RNA_struct_is_ID(idptr.type)) {
+    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;
+  }
+
+  struct Main *bmain = CTX_data_main(C);
+  ID *asset_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)) {
+    BKE_reportf(op->reports,
+                RPT_ERROR,
+                "Data-block '%s' could not be copied into an asset data-block",
+                id->name);
+    return OPERATOR_CANCELLED;
+  }
+
+  asset_id->asset_data = BKE_asset_data_create();
+
+  /* TODO generate preview */
+  /* TODO generate default meta-data */
+  /* TODO create asset in the asset DB, not in the local file. */
+
+  WM_event_add_notifier(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list