[Bf-blender-cvs] [812f40c] asset-experiments: More borring boiling code for ob/group previews.

Bastien Montagne noreply at git.blender.org
Sat Dec 13 16:15:28 CET 2014


Commit: 812f40c49304325791b87df3e3ff8daa7bd13f6d
Author: Bastien Montagne
Date:   Sat Dec 13 15:48:18 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rB812f40c49304325791b87df3e3ff8daa7bd13f6d

More borring boiling code for ob/group previews.

Also, try to make brushes also save their previews.

Anyway, something fishy is going on here, in theory we should get
previews for brushes, worlds, lamps... for free, but so far looks like
lib 'peek' code only handles mat/texture previews correctly?

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

M	source/blender/blenkernel/intern/group.c
M	source/blender/blenkernel/intern/icons.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index 6ea6baf..bd91d9d 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -49,6 +49,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
+#include "BKE_icons.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
@@ -64,7 +65,9 @@ void BKE_group_free(Group *group)
 {
 	/* don't free group itself */
 	GroupObject *go;
-	
+
+	BKE_previewimg_free(&group->preview);
+
 	while ((go = BLI_pophead(&group->gobject))) {
 		free_group_object(go);
 	}
@@ -139,6 +142,9 @@ Group *BKE_group_add(Main *bmain, const char *name)
 	
 	group = BKE_libblock_alloc(bmain, ID_GR, name);
 	group->layer = (1 << 20) - 1;
+
+	group->preview = NULL;
+
 	return group;
 }
 
@@ -149,6 +155,10 @@ Group *BKE_group_copy(Group *group)
 	groupn = BKE_libblock_copy(&group->id);
 	BLI_duplicatelist(&groupn->gobject, &group->gobject);
 
+	if (group->preview) {
+		groupn->preview = BKE_previewimg_copy(group->preview);
+	}
+
 	return groupn;
 }
 
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 8bda957..e442727 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -37,11 +37,13 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_brush_types.h"
+#include "DNA_group_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
+#include "DNA_object_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
-#include "DNA_brush_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
@@ -202,6 +204,14 @@ void BKE_previewimg_free_id(ID *id)
 		Brush *br  = (Brush *)id;
 		BKE_previewimg_free(&br->preview);
 	}
+	else if (GS(id->name) == ID_OB) {
+		Object *ob  = (Object *)id;
+		BKE_previewimg_free(&ob->preview);
+	}
+	else if (GS(id->name) == ID_GR) {
+		Group *group  = (Group *)id;
+		BKE_previewimg_free(&group->preview);
+	}
 }
 
 PreviewImage *BKE_previewimg_get(ID *id)
@@ -238,6 +248,16 @@ PreviewImage *BKE_previewimg_get(ID *id)
 		if (!br->preview) br->preview = BKE_previewimg_create();
 		prv_img = br->preview;
 	}
+	else if (GS(id->name) == ID_OB) {
+		Object *ob  = (Object *)id;
+		if (!ob->preview) ob->preview = BKE_previewimg_create();
+		prv_img = ob->preview;
+	}
+	else if (GS(id->name) == ID_GR) {
+		Group *group  = (Group *)id;
+		if (!group->preview) group->preview = BKE_previewimg_create();
+		prv_img = group->preview;
+	}
 
 	return prv_img;
 }
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index a0d1b25..d94e255 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -87,6 +87,7 @@
 #include "BKE_effect.h"
 #include "BKE_fcurve.h"
 #include "BKE_group.h"
+#include "BKE_icons.h"
 #include "BKE_key.h"
 #include "BKE_lamp.h"
 #include "BKE_lattice.h"
@@ -408,6 +409,8 @@ void BKE_object_free_ex(Object *ob, bool do_id_user)
 			free_path(ob->curve_cache->path);
 		MEM_freeN(ob->curve_cache);
 	}
+
+	BKE_previewimg_free(&ob->preview);
 }
 
 void BKE_object_free(Object *ob)
@@ -1009,6 +1012,7 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
 	ob->fall_speed = 55.0f;
 	ob->col_group = 0x01;
 	ob->col_mask = 0xff;
+	ob->preview = NULL;
 
 	/* NT fluid sim defaults */
 	ob->fluidsimSettings = NULL;
@@ -1518,6 +1522,10 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches)
 	/* Copy runtime surve data. */
 	obn->curve_cache = NULL;
 
+	if (ob->preview) {
+		obn->preview = BKE_previewimg_copy(ob->preview);
+	}
+
 	return obn;
 }
 
@@ -1554,6 +1562,8 @@ static void extern_local_object(Object *ob)
 		id_lib_extern((ID *)psys->part);
 
 	modifiers_foreachIDLink(ob, extern_local_object__modifiersForeachIDLink, NULL);
+
+	ob->preview = NULL;
 }
 
 void BKE_object_make_local(Object *ob)
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 97dd2ca..ac7afea 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -161,6 +161,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *to
 				case ID_IM: /* fall through */
 				case ID_WO: /* fall through */
 				case ID_LA: /* fall through */
+				case ID_BR: /* fall through */
 				case ID_OB: /* fall through */
 				case ID_GR: /* fall through */
 					new_prv = MEM_callocN(sizeof(PreviewImage), "newpreview");
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 751fe55..1aba6fe 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1837,6 +1837,25 @@ static void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endi
 {
 }
 
+/* ************ READ IMAGE PREVIEW *************** */
+
+static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_prv)
+{
+	PreviewImage *prv = newdataadr(fd, old_prv);
+	
+	if (prv) {
+		int i;
+		for (i = 0; i < NUM_ICON_SIZES; ++i) {
+			if (prv->rect[i]) {
+				prv->rect[i] = newdataadr(fd, prv->rect[i]);
+			}
+			prv->gputexture[i] = NULL;
+		}
+	}
+	
+	return prv;
+}
+
 /* ************ READ ID *************** */
 
 static void direct_link_id(FileData *fd, ID *id)
@@ -1898,7 +1917,7 @@ static void direct_link_brush(FileData *fd, Brush *brush)
 	else
 		BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP);
 
-	brush->preview = NULL;
+	brush->preview = direct_link_preview_image(fd, brush->preview);
 	brush->icon_imbuf = NULL;
 }
 
@@ -1960,25 +1979,6 @@ static PackedFile *direct_link_packedfile(FileData *fd, PackedFile *oldpf)
 	return pf;
 }
 
-/* ************ READ IMAGE PREVIEW *************** */
-
-static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_prv)
-{
-	PreviewImage *prv = newdataadr(fd, old_prv);
-	
-	if (prv) {
-		int i;
-		for (i = 0; i < NUM_ICON_SIZES; ++i) {
-			if (prv->rect[i]) {
-				prv->rect[i] = newdataadr(fd, prv->rect[i]);
-			}
-			prv->gputexture[i] = NULL;
-		}
-	}
-	
-	return prv;
-}
-
 /* ************ READ ANIMATION STUFF ***************** */
 
 /* Legacy Data Support (for Version Patching) ----------------------------- */
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index dbea42e..45847a3 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3043,6 +3043,9 @@ static void write_brushes(WriteData *wd, ListBase *idbase)
 				write_curvemapping(wd, brush->curve);
 			if (brush->curve)
 				writestruct(wd, DATA, "ColorBand", 1, brush->gradient);
+			if (brush->preview) {
+				write_previews(wd, brush->preview);
+			}
 		}
 	}
 }




More information about the Bf-blender-cvs mailing list