[Bf-blender-cvs] [1f88e48] fracture_modifier: dynamic fracture can now react to multiple impacts on initial shard and 1st level shards
Martin Felke
noreply at git.blender.org
Sat Oct 1 14:25:51 CEST 2016
Commit: 1f88e48d088b0ff1e784e44e9b3baefa86bfec65
Author: Martin Felke
Date: Sat Oct 1 14:25:27 2016 +0200
Branches: fracture_modifier
https://developer.blender.org/rB1f88e48d088b0ff1e784e44e9b3baefa86bfec65
dynamic fracture can now react to multiple impacts on initial shard and 1st level shards
===================================================================
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/pointcache.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 de88b68..ddb1f60 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -997,9 +997,6 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
{
j = 1;
- //if (mode == MOD_FRACTURE_DYNAMIC)
- // j = 1;
-
if (fm->shard_map.last)
{
j += ((Shard*)(fm->shard_map.last))->shard_id;
@@ -1007,7 +1004,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
}
else
{
- j = 0;
+ j = 1;
}
for (i = 0; i < expected_shards; i++) {
@@ -1016,7 +1013,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
if (s != NULL) {
add_shard(fm, s, mat);
- s->shard_id += j+1;
+ s->shard_id += j;
s->parent_id = parent_id;
s->setting_id = active_setting;
//printf("ADDED: %d %d %d\n", i, j, s->shard_id);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 20645ec..7453f39 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1277,6 +1277,21 @@ static int ptcache_dynamicpaint_read(PTCacheFile *pf, void *dp_v)
return 1;
}
+static MeshIsland *find_meshisland(FractureModifierData *fmd, int id)
+{
+ MeshIsland *mi = (MeshIsland*)fmd->meshIslands.first;
+ while (mi)
+ {
+ if (mi->id == id)
+ {
+ return mi;
+ }
+ mi = mi->next;
+ }
+
+ return NULL;
+}
+
/* Rigid Body functions */
static int ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra)
{
@@ -1319,7 +1334,8 @@ static int ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra
}
else if (fmd && fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
{
- MeshIsland *mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
+ //MeshIsland *mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
+ MeshIsland *mi = find_meshisland(fmd, rbo->meshisland_index);
int frame = (int)floor(cfra);
// if (!mi)
@@ -1397,7 +1413,7 @@ static void ptcache_rigidbody_read(int index, void *rb_v, void **data, float cfr
MeshIsland *mi = NULL;
int frame = (int)floor(cfra);
- mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
+ mi = find_meshisland(fmd, rbo->meshisland_index);
// if (!mi)
// return;
@@ -1458,7 +1474,8 @@ static void ptcache_rigidbody_interpolate(int index, void *rb_v, void **data, fl
{
float loc[3], rot[4];
- MeshIsland *mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
+ MeshIsland *mi = find_meshisland(fmd, rbo->meshisland_index);
+
int frame = (int)floor(cfra);
frame = frame - mi->start_frame;
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 8dd04cc..7b9a822 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2027,14 +2027,11 @@ static int filterCallback(void* world, void* island1, void* island2, void *blend
return check_colgroup_ghost(ob1, ob2);
}
-static bool contains(float loc[3], Object* collider, float point[3], Object* ob, bool limit)
+static bool can_break(Object* collider, Object* ob, bool limit, Shard *s)
{
- float size[3];
- BKE_object_dimensions_get(collider, size);
-
- if ((fabsf(loc[0] - point[0]) < size[0]) &&
- (fabsf(loc[1] - point[1]) < size[1]) &&
- (fabsf(loc[2] - point[2]) < size[2]))
+ //allow limit impact only on initial shard and 1st level shards ?
+ if (collider && collider->rigidbody_object && (collider->rigidbody_object->flag & RBO_FLAG_IS_TRIGGER &&
+ s && (s->parent_id == 0 || s->shard_id == 0)))
{
if (limit && (collider == ob)) {
return false;
@@ -2043,7 +2040,7 @@ static bool contains(float loc[3], Object* collider, float point[3], Object* ob,
return true;
}
- return false;
+ return !limit;
}
static Shard* findShard(FractureModifierData *fmd, int id)
@@ -2140,8 +2137,8 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
int id = rbw->cache_index_map[linear_index1]->meshisland_index;
Shard *s = findShard(fmd1, id);
- if (force > fmd1->dynamic_force || (s && ob2 && (fmd1->limit_impact &&
- contains(cp->contact_pos_world_onA, ob2, s->centroid, ob1, fmd1->limit_impact))))
+ if (force > fmd1->dynamic_force || (/*force > fmd1->dynamic_force &&*/ s && ob2 && (fmd1->limit_impact &&
+ can_break(ob2, ob1, fmd1->limit_impact, s))))
{
if (s) {
float size[3];
@@ -2154,7 +2151,7 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
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;
+ fid1->shardID = id;
BLI_addtail(&fmd1->fracture_ids, fid1);
fmd1->update_dynamic = true;
}
@@ -2173,11 +2170,11 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
{
if (fmd2->current_shard_entry && fmd2->current_shard_entry->is_new)
{
- int id = rbw->cache_index_map[linear_index1]->meshisland_index;
+ int id = rbw->cache_index_map[linear_index2]->meshisland_index;
Shard *s = findShard(fmd2, id);
- if (force > fmd2->dynamic_force || (ob1 && s && (fmd2->limit_impact &&
- contains(cp->contact_pos_world_onB, ob1, s->centroid, ob2, fmd2->limit_impact))))
+ if (force > fmd2->dynamic_force || ( /*force > fmd2->dynamic_force &&*/ ob1 && s && (fmd2->limit_impact &&
+ can_break(ob1, ob2, fmd2->limit_impact, s))))
{
if (s) {
float size[3];
@@ -2985,8 +2982,10 @@ void BKE_rigidbody_update_ob_array(RigidBodyWorld *rbw)
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;
- if (mi->rigidbody)
- mi->rigidbody->meshisland_index = j;
+ if (mi->rigidbody) {
+ //as we search by id now in the pointcache, we set the id here too
+ mi->rigidbody->meshisland_index = mi->id;
+ }
counter++;
j++;
}
@@ -4344,8 +4343,9 @@ static void resetDynamic(RigidBodyWorld *rbw, bool do_reset_always)
{
float (*vertexCos)[3];
int totvert = dm->getNumVerts(dm);
- dm->getVertCos(dm, vertexCos);
+
vertexCos = MEM_callocN(sizeof(float) * 3 * totvert, "Vertex Cos");
+ dm->getVertCos(dm, vertexCos);
mti->deformVerts(md, ob, dm, vertexCos, totvert, 0);
CDDM_apply_vert_coords(dm, vertexCos);
MEM_freeN(vertexCos);
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 8d71fa9..c67df79 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -90,6 +90,7 @@ static void do_prehalving(FractureModifierData *fmd, Object* ob, DerivedMesh* de
static Shard* copy_shard(Shard *s);
static void arrange_shard(FractureModifierData *fmd, ShardID id, bool do_verts, float cent[]);
static Shard* find_shard(ListBase *shards, ShardID id);
+static void cleanup_arrange_shard(FractureModifierData *fmd, Shard *s, float cent[]);
//TODO XXX Make BKE
static FracMesh* copy_fracmesh(FracMesh* fm)
@@ -1163,40 +1164,54 @@ static FracPointCloud get_points_global(FractureModifierData *emd, Object *ob, D
{
float cent[3], bmin[3], bmax[3];
int count = emd->shard_count;
+ Shard *s = NULL;
+
INIT_MINMAX(min, max);
+ //for limit impact we need entire container always, because we need to determine secondary impacts on the shards at their original pos
if (!BKE_get_shard_minmax(emd->frac_mesh, id, min, max, fracmesh))
return points; //id 0 should be entire mesh
+ //arrange shards according to their original centroid (parent centroid sum) position in shard-space (else they are centered at 0, 0, 0)
arrange_shard(emd, id, false, cent);
add_v3_v3v3(bmax, max, cent);
add_v3_v3v3(bmin, min, cent);
//first impact only, so shard has id 0
- if (emd->fracture_mode == MOD_FRACTURE_DYNAMIC && emd->limit_impact && id == 0) {
+ if (emd->fracture_mode == MOD_FRACTURE_DYNAMIC && emd->limit_impact) {
//shrink pointcloud container around impact point, to a size
- Shard *s = BKE_shard_by_id(emd->frac_mesh, 0, fracmesh);
- if (s != NULL) {
+ s = BKE_shard_by_id(emd->frac_mesh, id, fracmesh);
+ if (s != NULL && (s->shard_id == 0 || s->parent_id == 0)) {
float size[3], nmin[3], nmax[3], loc[3], imat[4][4], tmin[3], tmax[3], quat[4];
print_v3("Impact Loc\n", s->impact_loc);
print_v3("Impact Size\n", s->impact_size);
//invert_m4_m4(imat, ob->obmat);
//mul_v3_m4v3(loc, imat, s->impact_loc);
- //mat4_to_quat(quat, imat);
//sub_v3_v3v3(loc, s->impact_loc, ob->loc);
+ //mat4_to_quat(quat, imat);
//mul_qt_v3(quat, loc);
copy_v3_v3(loc, s->impact_loc);
- mul_v3_v3fl(size, s->impact_size, 0.5f);
+ copy_v3_v3(tmax, s->max);
+ copy_v3_v3(tmin, s->min);
+
+ //sub_v3_v3(loc, cent);
+ //sub_v3_v3(loc, s->centroid);
+
+ mul_v3_v3fl(size, s->impact_size, 0.75f);
sub_v3_v3v3(nmin, loc, size);
add_v3_v3v3(nmax, loc, size);
- copy_v3_v3(tmin, min);
- copy_v3_v3(tmax, max);
+ /*sub_v3_v3(tmin, cent);
+ sub_v3_v3(tmin, s->centroid);
+
+ sub_v3_v3(tmax, cent);
+ sub_v3_v3(tmax, s->centroid);
- /*mat4_to_quat(quat, ob->obmat);
+ mat4_to_quat(quat, ob->obmat);
mul_qt_v3(quat, tmin);
- mul_qt_v3(quat, tmax);
- add_v3_v3(tmin, ob->loc);
+ mul_qt_v3(quat, tmax);*/
+
+ /*add_v3_v3(tmin, ob->loc);
add_v3_v3(tmax, ob->loc);*/
//clamp
@@ -1229,8 +1244,6 @@ static FracPointCloud get_points_global(FractureModifierData *emd, Object *ob, D
}
}
- printf("min, max: (%f %f %f), (%f %f %f)\n", min[0], min[1], min[2], max[0], max[1], max[2]);
-
if (emd->frac_algorithm == MOD_FRACTURE_BISECT_FAST || emd->frac_algorithm == MOD_FRACTURE_BISECT_FAST_FILL ||
emd->fra
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list