[Bf-blender-cvs] [2ca8421] asset-engine: Assets: add uuid to linked data, write and read it from file.

Bastien Montagne noreply at git.blender.org
Tue Feb 2 14:15:01 CET 2016


Commit: 2ca8421987385aee7827cbf0df38ec8cc7b5f7fe
Author: Bastien Montagne
Date:   Thu Jan 21 16:12:08 2016 +0100
Branches: asset-engine
https://developer.blender.org/rB2ca8421987385aee7827cbf0df38ec8cc7b5f7fe

Assets: add uuid to linked data, write and read it from file.

Note that this is only very first steps, I think we'll need to 'propagate'
uuid to all data used/linked by asset itself, otherwise most things won't get
updated/reloaded. Still have to think about this.

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

M	source/blender/blenkernel/intern/blender.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 635fc1e..72e6efa 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -509,6 +509,25 @@ void BKE_userdef_state(void)
 
 }
 
+static void read_file_update_assets(bContext *C)
+{
+	Main *bmain = CTX_data_main(C);
+	ListBase *lb_array[MAX_LIBARRAY];
+	int i = set_listbasepointers(bmain, lb_array);
+
+	while (i--) {
+		for (ID *id = lb_array[i]->first; id; id = id->next) {
+			if (id->uuid && id->lib && (id->tag & LIB_TAG_EXTERN)) {
+				printf("We need to check for updated asset %s...\n", id->name);
+				id->tag |= LIB_TAG_DOIT;
+			}
+			else {
+				id->tag &= ~LIB_TAG_DOIT;
+			}
+		}
+	}
+}
+
 int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
 {
 	BlendFileData *bfd;
@@ -527,8 +546,12 @@ int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
 			bfd = NULL;
 			retval = BKE_READ_FILE_FAIL;
 		}
-		else
+		else {
 			setup_app_data(C, bfd, filepath);  // frees BFD
+
+			printf("Updating assets for: %s\n", filepath);
+			read_file_update_assets(C);
+		}
 	}
 	else
 		BKE_reports_prependf(reports, "Loading '%s' failed: ", filepath);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 202394b..886cb75 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7949,6 +7949,17 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
 	
 	/* this case cannot be direct_linked: it's just the ID part */
 	if (bhead->code == ID_ID) {
+		if (id->uuid) {
+			/* read all data into fd->datamap */
+			bhead = read_data_into_oldnewmap(fd, bhead, __func__);
+
+			id->uuid = newdataadr(fd, id->uuid);
+
+			oldnewmap_free_unused(fd->datamap);
+			oldnewmap_clear(fd->datamap);
+			return bhead;
+		}
+
 		return blo_nextbhead(fd, bhead);
 	}
 	
@@ -9762,6 +9773,11 @@ static ID *link_named_part_ex(
 			id->tag |= LIB_TAG_DOIT;
 	}
 
+	if (id && uuid) {
+		id->uuid = MEM_mallocN(sizeof(*id->uuid), __func__);
+		*id->uuid = *uuid;
+	}
+
 	return id;
 }
 
@@ -10137,6 +10153,11 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
 							 * (known case: some directly linked shapekey from a missing lib...). */
 							/* BLI_assert(realid != NULL); */
 
+							if (realid && id->uuid) {
+								/* we can give ownership of that pointer to new ID. */
+								realid->uuid = id->uuid;
+							}
+
 							change_idid_adr(mainlist, basefd, id, realid);
 
 							MEM_freeN(id);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index a2802db..250361c 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2929,6 +2929,9 @@ static void write_libraries(WriteData *wd, Main *main)
 							BLI_assert(0);
 						}
 						writestruct(wd, ID_ID, "ID", 1, id);
+						if (id->uuid) {
+							writestruct(wd, DATA, "AssetUUID", 1, id->uuid);
+						}
 					}
 				}
 			}




More information about the Bf-blender-cvs mailing list