[Bf-blender-cvs] [cbf2415] asset-engine: First step towards supporting non-blender-data as assets.

Bastien Montagne noreply at git.blender.org
Tue Jun 14 15:49:03 CEST 2016


Commit: cbf241510d7f0873599b3ec892b74460137421a7
Author: Bastien Montagne
Date:   Mon Jun 13 17:39:02 2016 +0200
Branches: asset-engine
https://developer.blender.org/rBcbf241510d7f0873599b3ec892b74460137421a7

First step towards supporting non-blender-data as assets.

Idea is to avoid the need for asset engines to generate whole .blend files
with relevant datablocks in case they just need/want to provide files (images, videos, sounds...).

This commit introduces the concept of 'virtual' library, which in fact only exists to store
asset repository data. Datablocks from those virtual libs are then fully written in .blend file.

Much to do still, this is only preliminary/experimental work.

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

M	source/blender/blenkernel/intern/library.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/windowmanager/intern/wm_files_link.c

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

diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 6b1602a..569d7ce 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -2043,7 +2043,7 @@ static int library_asset_dependencies_rebuild_cb(void *userdata, ID *id_self, ID
 static void library_asset_dependencies_rebuild(ID *asset)
 {
 	Library *lib = asset->lib;
-	BLI_assert(lib->asset_repository);
+	BLI_assert(lib && lib->asset_repository);
 
 	asset->tag |= LIB_TAG_ASSET;
 
@@ -2132,6 +2132,11 @@ void BKE_id_ui_prefix(char name[MAX_ID_NAME + 1], const ID *id)
 
 void BKE_library_filepath_set(Library *lib, const char *filepath)
 {
+	if (lib->flag & LIBRARY_FLAG_VIRTUAL) {
+		/* Setting path for virtual libraries makes no sense. */
+		return;
+	}
+
 	/* in some cases this is used to update the absolute path from the
 	 * relative */
 	if (lib->name != filepath) {
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6d96b8a..1286995 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8037,6 +8037,12 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 		return blo_nextbhead(fd, bhead);
 	}
 	
+	/* If we have a real ID from a virtual library, tag ID as extern. */
+	if (id->lib && (id->lib->flag & LIBRARY_FLAG_VIRTUAL)) {
+		BLI_assert(ID_VIRTUAL_LIBRARY_VALID(id));
+		id->tag |= LIB_TAG_EXTERN;
+	}
+
 	/* need a name for the mallocN, just for debugging and sane prints on leaks */
 	allocname = dataname(GS(id->name));
 	
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d7d274c..91ca66e 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2879,70 +2879,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
 	mywrite(wd, MYWRITE_FLUSH, 0);
 }
 
-static void write_libraries(WriteData *wd, Main *main)
-{
-	ListBase *lbarray[MAX_LIBARRAY];
-	ID *id;
-	int a, tot;
-	bool found_one;
-
-	for (; main; main= main->next) {
-
-		a=tot= set_listbasepointers(main, lbarray);
-
-		/* test: is lib being used */
-		if (main->curlib && main->curlib->packedfile)
-			found_one = true;
-		else {
-			found_one = false;
-			while (tot--) {
-				for (id= lbarray[tot]->first; id; id= id->next) {
-					if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) {
-						found_one = true;
-						break;
-					}
-				}
-				if (found_one) break;
-			}
-		}
-		
-		/* to be able to restore quit.blend and temp saves, the packed blend has to be in undo buffers... */
-		/* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the]
-		 * quit.blend and temp saves */
-		if (found_one) {
-			writestruct(wd, ID_LI, "Library", 1, main->curlib);
-
-			if (main->curlib->packedfile) {
-				PackedFile *pf = main->curlib->packedfile;
-				writestruct(wd, DATA, "PackedFile", 1, pf);
-				writedata(wd, DATA, pf->size, pf->data);
-				if (wd->current == NULL)
-					printf("write packed .blend: %s\n", main->curlib->name);
-			}
-
-			if (main->curlib->asset_repository) {
-				writestruct(wd, DATA, "AssetRepositoryRef", 1, main->curlib->asset_repository);
-			}
-
-			while (a--) {
-				for (id= lbarray[a]->first; id; id= id->next) {
-					if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) {
-						if (!BKE_idcode_is_linkable(GS(id->name))) {
-							printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable "
-							       "but is flagged as directly linked", id->name, main->curlib->filepath);
-							BLI_assert(0);
-						}
-						writestruct(wd, ID_ID, "ID", 1, id);
-						if (id->uuid) {
-							writestruct(wd, DATA, "AssetUUID", 1, id->uuid);
-						}
-					}
-				}
-			}
-		}
-	}
-}
-
 static void write_bone(WriteData *wd, Bone *bone)
 {
 	Bone*	cbone;
@@ -3635,6 +3571,81 @@ static void write_linestyles(WriteData *wd, ListBase *idbase)
 	}
 }
 
+static void write_libraries(WriteData *wd, Main *main)
+{
+	ListBase *lbarray[MAX_LIBARRAY];
+	ID *id;
+	int a, tot;
+	bool found_one;
+
+	for (; main; main= main->next) {
+		a = tot = set_listbasepointers(main, lbarray);
+
+		/* test: is lib being used */
+		if (main->curlib && main->curlib->packedfile)
+			found_one = true;
+		else {
+			found_one = false;
+			while (tot--) {
+				for (id= lbarray[tot]->first; id; id= id->next) {
+					if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) {
+						found_one = true;
+						break;
+					}
+				}
+				if (found_one) break;
+			}
+		}
+
+		/* to be able to restore quit.blend and temp saves, the packed blend has to be in undo buffers... */
+		/* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the]
+		 * quit.blend and temp saves */
+		if (found_one) {
+			writestruct(wd, ID_LI, "Library", 1, main->curlib);
+
+			BLI_assert(!(main->curlib->flag & LIBRARY_FLAG_VIRTUAL) ||
+			           (!main->curlib->packedfile && main->curlib->asset_repository));
+
+			if (main->curlib->packedfile) {
+				PackedFile *pf = main->curlib->packedfile;
+				writestruct(wd, DATA, "PackedFile", 1, pf);
+				writedata(wd, DATA, pf->size, pf->data);
+				if (wd->current == NULL)
+					printf("write packed .blend: %s\n", main->curlib->name);
+			}
+
+			if (main->curlib->asset_repository) {
+				writestruct(wd, DATA, "AssetRepositoryRef", 1, main->curlib->asset_repository);
+			}
+
+			if (main->curlib->flag & LIBRARY_FLAG_VIRTUAL) {
+				/* Those should be the only datatypes found in a virtual library! */
+				write_images   (wd, &main->image);
+				write_vfonts   (wd, &main->vfont);
+				write_texts    (wd, &main->text);
+				write_sounds   (wd, &main->sound);
+			}
+			else {
+				while (a--) {
+					for (id= lbarray[a]->first; id; id= id->next) {
+						if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) {
+							if (!BKE_idcode_is_linkable(GS(id->name))) {
+								printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable "
+									   "but is flagged as directly linked", id->name, main->curlib->filepath);
+								BLI_assert(0);
+							}
+							writestruct(wd, ID_ID, "ID", 1, id);
+							if (id->uuid) {
+								writestruct(wd, DATA, "AssetUUID", 1, id->uuid);
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}
+
 /* context is usually defined by WM, two cases where no WM is available:
  * - for forward compatibility, curscreen has to be saved
  * - for undofile, curscene needs to be saved */
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index e45c733..da5302f 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -233,9 +233,16 @@ typedef struct Library {
 	AssetRepositoryRef *asset_repository;
 
 	int temp_index;
-	int _pad;
+
+	short flag;
+	short pad_s1;
 } Library;
 
+/* Library.flag */
+enum {
+	LIBRARY_FLAG_VIRTUAL,  /* The library does not actually exist, used to allow handling of files from asset engines. */
+};
+
 enum eIconSizes {
 	ICON_SIZE_ICON = 0,
 	ICON_SIZE_PREVIEW = 1,
@@ -355,6 +362,8 @@ typedef struct PreviewImage {
 #define ID_NEW_US(a)	if (      (a)->id.newid)       { (a) = (void *)(a)->id.newid;       (a)->id.us++; }
 #define ID_NEW_US2(a)	if (((ID *)a)->newid)          { (a) = ((ID  *)a)->newid;     ((ID *)a)->us++;    }
 
+#define ID_VIRTUAL_LIBRARY_VALID(_id) (ELEM(GS((_id)->name), ID_IM, ID_VF, ID_TXT, ID_SO))
+
 /* id->flag (persitent). */
 enum {
 	/* Flag asset IDs (the ones who should have a valid uuid). */
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index 1dbd230..67a7ca9 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -595,7 +595,7 @@ static void asset_update_engines_uuids_fetch(
 {
 	for (Library *lib = bmain->library.first; lib; lib = lib->id.next) {
 		if (lib->asset_repository) {
-			printf("Checking lib file %s (engine %s, ver. %d)\n", lib->filepath,
+			printf("Checking lib file '%s' (engine %s, ver. %d)\n", lib->filepath,
 			       lib->asset_repository->asset_engine, lib->asset_repository->asset_engine_version);
 
 			AssetUpdateCheckEngine *auce = NULL;




More information about the Bf-blender-cvs mailing list