[Bf-blender-cvs] [cf2c1a9] alembic_pointcache: Calculate bounding boxes for cached DMs to avoid visual popping when using the original Object's bb.

Lukas Tönne noreply at git.blender.org
Wed Mar 18 15:38:11 CET 2015


Commit: cf2c1a906271509857f7c2b098c18050d2899ebb
Author: Lukas Tönne
Date:   Wed Mar 18 15:37:08 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rBcf2c1a906271509857f7c2b098c18050d2899ebb

Calculate bounding boxes for cached DMs to avoid visual popping when
using the original Object's bb.

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

M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/makesdna/DNA_object_types.h

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

diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 5d26b87..9adb190 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1466,10 +1466,27 @@ DupliObjectData *BKE_dupli_cache_find_data(DupliCache *dupcache, Object *ob)
 	return data;
 }
 
+static void dupli_cache_calc_boundbox(DupliObjectData *data)
+{
+	float min[3], max[3];
+	
+	if (data->cache_dm) {
+		INIT_MINMAX(min, max);
+		data->cache_dm->getMinMax(data->cache_dm, min, max);
+	}
+	else {
+		zero_v3(min);
+		zero_v3(max);
+	}
+	
+	BKE_boundbox_init_from_minmax(&data->bb, min, max);
+}
+
 DupliObjectData *BKE_dupli_cache_add_mesh(DupliCache *dupcache, Object *ob, DerivedMesh *dm)
 {
 	DupliObjectData *data = dupli_cache_add_object_data(dupcache, ob);
 	data->cache_dm = dm;
+	dupli_cache_calc_boundbox(data);
 	
 	/* we own this dm now and need to protect it until we free it ourselves */
 	dm->needsFree = false;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 6bc5e17..297e586 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2051,10 +2051,13 @@ static void draw_dupli_objects_color(
 	if (dob) dob_next = dupli_step(dob->next);
 
 	for (; dob; dob_prev = dob, dob = dob_next, dob_next = dob_next ? dupli_step(dob_next->next) : NULL) {
-		DerivedMesh *final_dm; /* for restoring after override */
+		/* for restoring after override */
+		DerivedMesh *store_final_dm;
+		BoundBox *store_bb;
 
 		tbase.object = dob->ob;
-		final_dm = dob->ob->derivedFinal;
+		store_final_dm = dob->ob->derivedFinal;
+		store_bb = dob->ob->bb;
 
 		/* Make sure lod is updated from dupli's position */
 
@@ -2092,11 +2095,16 @@ static void draw_dupli_objects_color(
 		}
 		
 		/* override final DM */
+		bb_tmp = NULL;
 		if (base->object->dup_cache) {
 			DupliObjectData *dob_data = BKE_dupli_cache_find_data(base->object->dup_cache, tbase.object);
-			if (dob_data->cache_dm)
+			if (dob_data->cache_dm) {
 				tbase.object->derivedFinal = dob_data->cache_dm;
+				tbase.object->bb = bb_tmp = &dob_data->bb;
+			}
 		}
+		if (!bb_tmp)
+			bb_tmp = BKE_object_boundbox_get(dob->ob);
 		
 		/* generate displist, test for new object */
 		if (dob_prev && dob_prev->ob != dob->ob) {
@@ -2106,7 +2114,7 @@ static void draw_dupli_objects_color(
 			use_displist = false;
 		}
 		
-		if ((bb_tmp = BKE_object_boundbox_get(dob->ob))) {
+		if (bb_tmp) {
 			bb = *bb_tmp; /* must make a copy  */
 			testbb = true;
 		}
@@ -2167,7 +2175,10 @@ static void draw_dupli_objects_color(
 		tbase.object->dtx = dtx;
 		tbase.object->transflag = transflag;
 		tbase.object->currentlod = savedlod;
-		tbase.object->derivedFinal = final_dm;
+		
+		/* restore final DM */
+		tbase.object->derivedFinal = store_final_dm;
+		tbase.object->bb = store_bb;
 	}
 
 	if (apply_data) {
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 90ef299..e8e5be8 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -341,6 +341,7 @@ typedef struct DupliObjectData {
 	 * others make this too difficult
 	 */
 	struct Object *ob;
+	struct BoundBox bb;
 	struct DerivedMesh *cache_dm;
 } DupliObjectData;




More information about the Bf-blender-cvs mailing list