[Bf-blender-cvs] [f1fc895] asset-experiments: Assets: add uuid to linked data, write and read it from file.
Bastien Montagne
noreply at git.blender.org
Thu Jan 21 16:14:06 CET 2016
Commit: f1fc8959dbe92f42834c8b7b3a2a88752c051a3e
Author: Bastien Montagne
Date: Thu Jan 21 16:12:08 2016 +0100
Branches: asset-experiments
https://developer.blender.org/rBf1fc8959dbe92f42834c8b7b3a2a88752c051a3e
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 e7026f7..799f4c9 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 192d2d9..52a3ce4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7943,6 +7943,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);
}
@@ -9763,6 +9774,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;
}
@@ -10141,6 +10157,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