[Bf-blender-cvs] [c258ff967de] asset-engine: Initial basic support for assets definition in .blend file itself, and RNA api access.

Bastien Montagne noreply at git.blender.org
Tue Nov 5 14:42:52 CET 2019


Commit: c258ff967de1464acbfa7ad68e0241a62f8548e3
Author: Bastien Montagne
Date:   Tue Nov 5 14:37:43 2019 +0100
Branches: asset-engine
https://developer.blender.org/rBc258ff967de1464acbfa7ad68e0241a62f8548e3

Initial basic support for assets definition in .blend file itself, and RNA api access.

This still *very* basic, but should be usable as proof of concept for
Cosmos pipeline tests...

Note that the question of where to put all asset metadata remains open,
we could extend AssetUUID struct, and/or add support of IDProps to it,
or just use some special-named IDProp in IDs themselves (like the
_RNA_UI thing for custo; props UI settings...).

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

M	source/blender/blenkernel/intern/library_asset.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesrna/intern/rna_ID.c

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

diff --git a/source/blender/blenkernel/intern/library_asset.c b/source/blender/blenkernel/intern/library_asset.c
index 255d027415f..e570f7194ea 100644
--- a/source/blender/blenkernel/intern/library_asset.c
+++ b/source/blender/blenkernel/intern/library_asset.c
@@ -45,8 +45,8 @@
 #include "BKE_library_query.h"
 #include "BKE_main.h"
 
-/* Asset managing - TODO: we most likely want to turn this into a hashing at some point, could become a bit slow
- *                        when having huge assets (or many of them)... */
+/* Asset managing - TODO: we most likely want to turn this into a hashing at some point, could
+ * become a bit slow when having huge assets (or many of them)... */
 void BKE_library_asset_repository_init(Library *lib,
                                        const AssetEngineType *aet,
                                        const char *repo_root)
@@ -198,18 +198,14 @@ static int library_asset_dependencies_rebuild_cb(void *userdata,
 static void library_asset_dependencies_rebuild(ID *asset)
 {
   Library *lib = asset->lib;
-  BLI_assert(lib && lib->asset_repository);
+
+  asset->tag |= LIB_TAG_ASSET;
 
   if (!(lib && lib->asset_repository)) {
-    printf("asset: %s\n", asset->name);
-    printf("lib: %p\n", lib);
-    printf("lib: %s\n", lib->id.name);
-    printf("lib: %s\n", lib->name);
-    printf("lib: %p\n\n\n", lib->asset_repository);
+    /* 'local' definition of an asset, nothing else to do. */
+    return;
   }
 
-  asset->tag |= LIB_TAG_ASSET;
-
   AssetRef *aref = BKE_library_asset_repository_asset_add(lib, asset);
 
   /* TODO: pass main and use Main->relations? */
@@ -253,7 +249,8 @@ AssetRef *BKE_libraries_asset_repository_uuid_find(Main *bmain, const AssetUUID
   return NULL;
 }
 
-/** Find or add the 'virtual' library datablock matching this asset engine, used for non-blend-data assets. */
+/** Find or add the 'virtual' library datablock matching this asset engine, used for non-blend-data
+ * assets. */
 Library *BKE_library_asset_virtual_ensure(Main *bmain, const AssetEngineType *aet)
 {
   Library *lib;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 62cb3ab997c..421f5a7a5df 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -710,7 +710,6 @@ static void write_iddata(void *wd, const ID *id)
     }
   }
   if (id->uuid) {
-    BLI_assert(id->lib && id->lib->asset_repository);
     writestruct(wd, DATA, AssetUUID, 1, id->uuid);
   }
 
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 635ff67e628..5503bec2833 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -607,6 +607,19 @@ static void rna_ID_animation_data_free(ID *id, Main *bmain)
   DEG_relations_tag_update(bmain);
 }
 
+static void rna_ID_asset_uuid_free(ID *id)
+{
+  MEM_SAFE_FREE(id->uuid);
+  id->tag &= ~LIB_TAG_ASSET;
+}
+
+static void rna_ID_asset_uuid_create(ID *id)
+{
+  rna_ID_asset_uuid_free(id);
+  id->uuid = MEM_callocN(sizeof(*id->uuid), __func__);
+  id->tag |= LIB_TAG_ASSET;
+}
+
 #  ifdef WITH_PYTHON
 void **rna_ID_instance(PointerRNA *ptr)
 {
@@ -1647,6 +1660,12 @@ static void rna_def_ID(BlenderRNA *brna)
                                   "e.g. when calling :class:`bpy.types.Scene.update`");
   RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform");
 
+  func = RNA_def_function(srna, "asset_uuid_create", "rna_ID_asset_uuid_create");
+  RNA_def_function_ui_description(func, "Create asset uuid data to this ID");
+
+  func = RNA_def_function(srna, "asset_uuid_clear", "rna_ID_asset_uuid_free");
+  RNA_def_function_ui_description(func, "Clear asset uuid from this ID");
+
 #  ifdef WITH_PYTHON
   RNA_def_struct_register_funcs(srna, NULL, NULL, "rna_ID_instance");
 #  endif



More information about the Bf-blender-cvs mailing list