[Bf-blender-cvs] [a2ff84c] fracture_modifier: attempt to reduce flickering with autohide by memorizing which faces were not deleted in one autohide pass and keeping them, side effect: when playing the sim backwards autohiding wont work properly until reset to start frame again.

Martin Felke noreply at git.blender.org
Sun Sep 27 20:50:33 CEST 2015


Commit: a2ff84c66a01800dfd4137082b4064a9d6c27688
Author: Martin Felke
Date:   Sun Sep 27 20:50:07 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rBa2ff84c66a01800dfd4137082b4064a9d6c27688

attempt to reduce flickering with autohide by memorizing which faces were not deleted in one autohide pass and keeping them, side effect: when playing the sim backwards autohiding wont work properly until reset to start frame again.

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 1115355..e64bd10 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -74,6 +74,41 @@
 
 #ifdef WITH_BULLET
 
+static void do_refresh_autohide_deletion_map(FractureModifierData *fmd)
+{
+	//length of deletion map = poly count of shattered mesh !
+	if (fmd->visible_mesh_cached)
+	{
+		int num_polys = fmd->visible_mesh_cached->getNumPolys(fmd->visible_mesh_cached);
+		int i = 0;
+
+		if (fmd->autohide_deletion_map == NULL)
+		{
+			fmd->autohide_deletion_map = MEM_callocN(sizeof(int) * num_polys, "autohide_deletion_map");
+		}
+		else
+		{
+			for (i = 0; i < num_polys; i++)
+			{
+				fmd->autohide_deletion_map[i] = 0;
+			}
+		}
+	}
+}
+
+static void reset_autohide(RigidBodyWorld *rbw)
+{
+	GroupObject *go;
+
+	/*reset autohide deletion states of all modifier objects in the rigidbody world*/
+	for (go = rbw->group->gobject.first; go; go = go->next)	{
+		FractureModifierData *fmd = (FractureModifierData*)modifiers_findByType(go->ob, eModifierType_Fracture);
+		if (fmd) {
+			do_refresh_autohide_deletion_map(fmd);
+		}
+	}
+}
+
 static void validateShard(RigidBodyWorld *rbw, MeshIsland *mi, Object *ob, int rebuild, int transfer_speed);
 
 static void activateRigidbody(RigidBodyOb* rbo, RigidBodyWorld *UNUSED(rbw), MeshIsland *UNUSED(mi), Object *UNUSED(ob))
@@ -3537,6 +3572,9 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 		/* rebuild constraints */
 		rbw->flag |= RBW_FLAG_REBUILD_CONSTRAINTS;
 
+		/* reset autohide deletion state */
+		reset_autohide(rbw);
+
 		rbw->ltime = startframe;
 		if (rbw->flag & RBW_FLAG_OBJECT_CHANGED)
 		{       /* flag modifier refresh at their next execution XXX TODO -> still used ? */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 75a735a..852ae13 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4932,6 +4932,7 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 	fmd->face_pairs = NULL;
 	fmd->vert_index_map = NULL;
 	fmd->vertex_island_map = NULL;
+	fmd->autohide_deletion_map = NULL;
 
 	/*HARDCODING this for now, until we can version it properly, say with 2.75 ? */
 	if (fd->fileversion < 275) {
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 178a039..a3fe88b 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1559,6 +1559,7 @@ typedef struct FractureModifierData {
 	struct GHash *face_pairs;
 	struct GHash *vert_index_map; /*used for autoconversion of former objects to clusters, marks object membership of each vert*/
 	struct GHash *vertex_island_map; /* used for constraint building based on vertex proximity, temporary data */
+	int *autohide_deletion_map; /* store which shards broke and dont reconnect them again, means dont delete this face again */
 	ListBase shard_sequence; /* used as mesh cache / history for dynamic fracturing, for shards (necessary for conversion to DM) */
 	ListBase meshIsland_sequence; /* used as mesh cache / history for dynamic fracturing, for meshIslands (necessary for loc/rot "pointcache") */
 	ShardSequence *current_shard_entry; /*volatile storage of current shard entry, so we dont have to search in the list */
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index ab17416..f343f73 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -92,6 +92,7 @@ typedef enum eRigidBodyWorld_Flag {
 	RBW_FLAG_REFRESH_MODIFIERS	= (1 << 4),
 	/* Flag rebuild of constraints in fracture modifier objects */
 	RBW_FLAG_REBUILD_CONSTRAINTS = (1 << 5),
+
 } eRigidBodyWorld_Flag;
 
 /* ******************************** */
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index a9d6219..681cdb1 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -210,6 +210,7 @@ static void initData(ModifierData *md)
 	fmd->update_dynamic = false;
 	fmd->limit_impact = false;
 	fmd->reset_shards = false;
+	fmd->autohide_deletion_map = NULL;
 }
 
 static void freeMeshIsland(FractureModifierData *rmd, MeshIsland *mi, bool remove_rigidbody)
@@ -390,6 +391,11 @@ static void free_modifier(FractureModifierData *fmd, bool do_free_seq)
 		fmd->face_pairs = NULL;
 	}
 
+	if (fmd->autohide_deletion_map != NULL){
+		MEM_freeN(fmd->autohide_deletion_map);
+		fmd->autohide_deletion_map = NULL;
+	}
+
 	//called on deleting modifier, object or quitting blender...
 	//why was this necessary again ?!
 	if (fmd->dm) {
@@ -1400,6 +1406,7 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->dynamic_force = rmd->dynamic_force;
 	trmd->update_dynamic = false;
 	trmd->reset_shards = false;
+	trmd->autohide_deletion_map = NULL;
 }
 
 /* mi->bb, its for volume fraction calculation.... */
@@ -2600,6 +2607,18 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, BMFace
 		return;
 	}
 
+	if (fmd->autohide_deletion_map == NULL)
+	{
+		int num_polys = fmd->visible_mesh_cached->getNumPolys(fmd->visible_mesh_cached);
+		fmd->autohide_deletion_map = MEM_callocN(sizeof(int) * num_polys, "autohide_deletion_map");
+	}
+
+	if (fmd->autohide_deletion_map[i] || fmd->autohide_deletion_map[other])
+	{
+		/* do not delete this facepair again, keep it */
+		return;
+	}
+
 	f1 = BM_face_at_index(bm, i);
 	f2 = BM_face_at_index(bm, other);
 
@@ -2610,7 +2629,6 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, BMFace
 	BM_face_calc_center_mean(f1, f_centr);
 	BM_face_calc_center_mean(f2, f_centr_other);
 
-
 	if ((len_squared_v3v3(f_centr, f_centr_other) < (fmd->autohide_dist)) && (f1 != f2) &&
 	    (f1->mat_nr == 1) && (f2->mat_nr == 1))
 	{
@@ -2620,6 +2638,12 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, BMFace
 		(*faces)[(*del_faces) + 1] = f2;
 		(*del_faces) += 2;
 	}
+	else
+	{
+		/* broken face pairs */
+		fmd->autohide_deletion_map[i] = true;
+		fmd->autohide_deletion_map[other] = true;
+	}
 }
 
 static DerivedMesh *do_autoHide(FractureModifierData *fmd, DerivedMesh *dm)




More information about the Bf-blender-cvs mailing list