[Bf-blender-cvs] [809402e] fracture_modifier: still fighting with proper transformations in case of multiple fractures

Martin Felke noreply at git.blender.org
Mon Jun 1 21:29:22 CEST 2015


Commit: 809402e927193742b6f7e7139687ce63609f3c19
Author: Martin Felke
Date:   Tue May 19 15:55:40 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB809402e927193742b6f7e7139687ce63609f3c19

still fighting with proper transformations in case of multiple fractures

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index f876b2a..8f117ed 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -334,7 +334,7 @@ Shard *BKE_create_fracture_shard(MVert *mvert, MPoly *mpoly, MLoop *mloop, int t
 	}
 
 	shard->shard_id = -1;
-	shard->flag |= SHARD_INTACT;
+	shard->flag = SHARD_INTACT;
 	BKE_shard_calc_minmax(shard);
 
 	BKE_fracture_shard_center_centroid(shard, shard->centroid);
@@ -618,8 +618,8 @@ static void do_prepare_cells(FracMesh *fm, cell *cells, int expected_shards, int
 static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, FracMesh *fm, int algorithm, Object *obj, DerivedMesh *dm, short inner_material_index, float mat[4][4], int num_cuts, float fractal, bool smooth, int num_levels, int mode)
 {
 	/*Parse voronoi raw data*/
-	int i = 0;
-	Shard *p = BKE_shard_by_id(fm, parent_id, dm);
+	int i = 0, j = 0;
+	Shard *p = BKE_shard_by_id(fm, parent_id, dm), *t;
 	float obmat[4][4]; /* use unit matrix for now */
 	float centroid[3];
 	BMesh *bm_parent = NULL;
@@ -697,13 +697,52 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 	fm->shard_count = 0; /* may be not matching with expected shards, so reset... did increment this for
 	                      *progressbar only */
 
+#if 0
+	if (mode == MOD_FRACTURE_DYNAMIC)
+	{
+		Shard *t;
+		/* correct ids of shards here,
+		 * count how many new shards we have*/
+		for (i = 0; i < expected_shards; i++) {
+			Shard *s = tempresults[i];
+			if (s != NULL) {
+				j++;
+			}
+		}
+
+		/* and start reassigning ids for existing shards */
+		for (t = fm->shard_map.first; t; t = t->next)
+		{
+			//t->parent_id = parent_id;
+			//if (t->shard_id > parent_id)
+			{
+				t->shard_id += j;
+				t->parent_id = t->shard_id;
+			}
+		}
+	}
+	//keep empty ids... need to catch this later
+	if (mode == MOD_FRACTURE_DYNAMIC)
+	{
+		j = BLI_listbase_count(&fm->shard_map);//parent_id + 1;
+	}
+	else
+	{
+		j = 0;
+	}
+#endif
+
+	//j = 0;
+
 	for (i = 0; i < expected_shards; i++) {
 		Shard *s = tempresults[i];
 		Shard *t = tempshards[i];
 
 		if (s != NULL) {
 			add_shard(fm, s, mat);
-			s->shard_id = i+1;
+			//s->shard_id += j;
+			//s->parent_id = parent_id;
+			//j++;
 		}
 
 		if (t != NULL) {
@@ -711,6 +750,11 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 		}
 	}
 
+	for (t = fm->shard_map.first; t; t = t->next)
+	{
+		printf("SHARD: %d %d\n", t->shard_id, t->parent_id);
+	}
+
 	MEM_freeN(tempshards);
 	MEM_freeN(tempresults);
 }
@@ -1122,7 +1166,7 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
 #endif
 	
 	shard = BKE_shard_by_id(fmesh, id, dm);
-	if (!shard /*|| shard->flag & SHARD_FRACTURED*/)
+	if (!shard || shard->flag & SHARD_FRACTURED)
 		return;
 
 	
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 18c16c4..e26ada5 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -48,6 +48,7 @@
 #  include "RBI_api.h"
 #endif
 
+#include "DNA_fracture_types.h"
 #include "DNA_group_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -58,6 +59,7 @@
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_effect.h"
+#include "BKE_fracture.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
 #include "BKE_library.h"
@@ -1816,6 +1818,42 @@ static int filterCallback(void* world, void* island1, void* island2, void *blend
 	return check_colgroup_ghost(ob1, ob2);
 }
 
+static bool check_shard_size(FractureModifierData *fmd, int id)
+{
+	FractureID *fid;
+	float size = 0.1f;
+	//Shard *s = BLI_findlink(&fmd->frac_mesh->shard_map, id);
+
+	return true;
+#if 0
+
+	printf("FRACTURE : %d\n", id);
+	if (s == NULL || s->flag & SHARD_FRACTURED)
+	{
+		return false;
+	}
+
+	BKE_shard_calc_minmax(s);
+
+	if ((fabs(s->max[0] - s->min[0]) < size) ||
+	   (fabs(s->max[1] - s->min[1]) < size) ||
+	   (fabs(s->max[2] - s->min[2]) < size))
+	{
+		return false;
+	}
+
+	for (fid = fmd->fracture_ids.first; fid; fid = fid->next)
+	{
+		if (fid->shardID == id)
+		{
+			return false;
+		}
+	}
+
+	return true;
+#endif
+}
+
 static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
 {
 	int linear_index1, linear_index2;
@@ -1845,15 +1883,19 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
 
 		if (fmd1 && fmd1->fracture_mode == MOD_FRACTURE_DYNAMIC) {
 			if (force > fmd1->dynamic_force) {
-				if (fmd1->current_shard_entry && fmd1->current_shard_entry->is_new)
+				//if (fmd1->current_shard_entry && fmd1->current_shard_entry->is_new)
 				{
 					/*only fracture on new entries, this is necessary because after loading a file
 					 *the pointcache thinks it is empty and a fracture is attempted ! */
-					FractureID* fid1 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid1");
-					fid1->shardID = rbw->cache_index_map[linear_index1]->meshisland_index;
-					BLI_addtail(&fmd1->fracture_ids, fid1);
-					//fmd1->refresh = true;
-					rbw->refresh_modifiers = true;
+					int id = rbw->cache_index_map[linear_index1]->meshisland_index;
+					if(check_shard_size(fmd1, id))
+					{
+						FractureID* fid1 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid1");
+						fid1->shardID = rbw->cache_index_map[linear_index1]->meshisland_index;
+						BLI_addtail(&fmd1->fracture_ids, fid1);
+						//fmd1->refresh = true;
+						rbw->refresh_modifiers = true;
+					}
 				}
 			}
 		}
@@ -1867,13 +1909,17 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
 
 		if (fmd2 && fmd2->fracture_mode == MOD_FRACTURE_DYNAMIC) {
 			if (force > fmd2->dynamic_force){
-				if (fmd2->current_shard_entry && fmd2->current_shard_entry->is_new)
+				//if (fmd2->current_shard_entry && fmd2->current_shard_entry->is_new)
 				{
-					FractureID* fid2 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid2");
-					fid2->shardID = rbw->cache_index_map[linear_index2]->meshisland_index;
-					BLI_addtail(&fmd2->fracture_ids, fid2);
-					//fmd2->refresh = true;
-					rbw->refresh_modifiers = true;
+					int id = rbw->cache_index_map[linear_index2]->meshisland_index;
+					if(check_shard_size(fmd2, id))
+					{
+						FractureID* fid2 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid2");
+						fid2->shardID = id;
+						BLI_addtail(&fmd2->fracture_ids, fid2);
+						//fmd2->refresh = true;
+						rbw->refresh_modifiers = true;
+					}
 				}
 			}
 		}
@@ -2473,7 +2519,7 @@ static void rigidbody_update_ob_array(RigidBodyWorld *rbw)
 	ModifierData *md;
 	FractureModifierData *rmd;
 	MeshIsland *mi;
-	int i, j, l = 0, m = 0, n = 0, counter = 0;
+	int i, j = 0, l = 0, m = 0, n = 0, counter = 0;
 	bool ismapped = false;
 	
 	if (rbw->objects != NULL) {
@@ -2508,7 +2554,7 @@ static void rigidbody_update_ob_array(RigidBodyWorld *rbw)
 			if (md->type == eModifierType_Fracture) {
 				rmd = (FractureModifierData *)md;
 				if (isModifierActive(rmd)) {
-					for (mi = rmd->meshIslands.first, j = 0; mi; mi = mi->next) {
+					for (mi = rmd->meshIslands.first; mi; mi = mi->next) {
 						rbw->cache_index_map[counter] = mi->rigidbody; /* map all shards of an object to this object index*/
 						rbw->cache_offset_map[counter] = i;
 						mi->linear_index = counter;
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 5cdb4c2..b319e22 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -89,6 +89,7 @@ static FracMesh* copy_fracmesh(FracMesh* fm)
 {
 	FracMesh *fmesh;
 	Shard* s, *t;
+	int i = 0;
 
 	fmesh = MEM_mallocN(sizeof(FracMesh), __func__);
 	//BLI_duplicatelist(&fmesh->shard_map, &fm->shard_map);
@@ -98,6 +99,8 @@ static FracMesh* copy_fracmesh(FracMesh* fm)
 	for (s = fm->shard_map.first; s; s = s->next)
 	{
 		t = BKE_create_fracture_shard(s->mvert, s->mpoly, s->mloop, s->totvert, s->totpoly, s->totloop, true);
+		t->parent_id = s->shard_id;
+		t->shard_id = i;
 
 		CustomData_reset(&t->vertData);
 		CustomData_reset(&t->loopData);
@@ -108,6 +111,7 @@ static FracMesh* copy_fracmesh(FracMesh* fm)
 		CustomData_add_layer(&t->polyData, CD_MTEXPOLY, CD_DUPLICATE, CustomData_get_layer(&s->polyData, CD_MTEXPOLY), s->totpoly);
 
 		BLI_addtail(&fmesh->shard_map, t);
+		i++;
 	}
 
 	fmesh->shard_count = fm->shard_count;
@@ -1518,7 +1522,7 @@ static void do_rigidbody(FractureModifierData *fmd, MeshIsland* mi, Object* ob,
 	mi->rigidbody = NULL;
 	mi->rigidbody = BKE_rigidbody_create_shard(fmd->modifier.scene, ob, mi);
 	mi->rigidbody->type = rb_type;
-	mi->rigidbody->meshisland_index = i;
+	//mi->rigidbody->meshisland_index = i;
 	BKE_rigidbody_calc_shard_mass(ob, mi, orig_dm);
 
 	if (fmd->frac_algorithm == MOD_FRACTURE_BOOLEAN_FRACTAL)
@@ -2793,14 +2797,11 @@ static void do_match_vertex_coords(MeshIsland* mi, MeshIsland *par, Object *ob,
 	rot[3] = par->rots[4*frame+3];
 
 	mul_m4_v3(ob->imat, loc);
-	mat4_to_quat(irot, ob->imat);
-	mul_qt_qtqt(rot, irot, rot);
+	//mat4_to_quat(irot, ob->imat);
+	//mul_qt_qtqt(rot, irot, rot);
 
 	add_v3_v3(mi->centroid, loc);
-	//mul_qt_qtqt(mi->rot, mi->rot, rot);
-
-	//add_v3_v3(mi->centroid, par->centroid);
-	//add_v3_v3(loc, par->centroid);
+	mul_qt_qtqt(mi->rot, mi->rot, rot);
 
 	//match vertices and vertco, perhaps vertno too, yuck...
 	for (j = 0; j < mi->vertex_count; j++)
@@ -2820,12 +2821,19 @@ static void do_match_vertex_coords(MeshIsland* mi, MeshIsland *par, Object *ob,
 		mi->vertco[3*j]   = co[0];
 		mi->vertco[3*j+1] = co[1];
 		mi->vertco[3*j+2] = co[2];
-
-		//mul_qt_v3(rot, mvert[j].co);
-		//sub_v3_v3(mvert[j].co, mi->centroid);
 	}
 }
 
+static void do_handle_parent_mi(FractureModifierData *fmd, MeshIsland *mi, MeshIsland *par, Object* ob, int frame)
+{
+	frame -= par->start_frame;
+	do_match_vertex_coords(mi, par, ob, frame);
+
+	BKE_rigidbody_remove_shard(fmd->modifier.scene, par);
+	fmd->modifier.scene->rigidbody_world->object_changed = true;
+	par->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
+}
+
 static void do_island_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list