[Bf-blender-cvs] [cc00da8] fracture_modifier: dynamic fracture: added back constraint support for it
Martin Felke
noreply at git.blender.org
Mon Oct 3 01:21:48 CEST 2016
Commit: cc00da895ecab3e280b0fe84c808d45daf0e9f48
Author: Martin Felke
Date: Mon Oct 3 01:21:23 2016 +0200
Branches: fracture_modifier
https://developer.blender.org/rBcc00da895ecab3e280b0fe84c808d45daf0e9f48
dynamic fracture: added back constraint support for it
===================================================================
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/blenloader/intern/readfile.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 ddb1f60..604c289 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -2173,6 +2173,17 @@ void BKE_free_constraints(FractureModifierData *fmd)
MeshIsland *mi = NULL;
RigidBodyShardCon *rbsc = NULL;
+ //hmm after loading the pointers might be out of sync...
+ if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC) {
+ if (fmd->current_mi_entry) {
+ fmd->meshIslands = fmd->current_mi_entry->meshIslands;
+ }
+ else {
+ fmd->meshIslands.first = NULL;
+ fmd->meshIslands.last = NULL;
+ }
+ }
+
for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
if (mi->participating_constraints != NULL && mi->participating_constraint_count > 0) {
MEM_freeN(mi->participating_constraints);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 7b9a822..8234507 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2137,12 +2137,21 @@ 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 || (/*force > fmd1->dynamic_force &&*/ s && ob2 && (fmd1->limit_impact &&
- can_break(ob2, ob1, fmd1->limit_impact, s))))
+ if ((force > fmd1->dynamic_force && (!fmd1->limit_impact || (fmd1->limit_impact && s && (s->parent_id > 0 || s->shard_id > 0)) ||
+ (s && ob2 && (fmd1->limit_impact && can_break(ob2, ob1, fmd1->limit_impact, s))))))
{
if (s) {
float size[3];
- BKE_object_dimensions_get(ob2, size);
+
+ if (ob1 == ob2 || (ob2 && ob2->rigidbody_object && ob2->rigidbody_object->type == RBO_TYPE_PASSIVE)) {
+ size[0] = -1.0f; //mark as invalid, so the regular object size is used
+ size[1] = -1.0f;
+ size[2] = -1.0f;
+ }
+ else {
+ BKE_object_dimensions_get(ob2, size);
+ }
+
copy_v3_v3(s->impact_loc, cp->contact_pos_world_onA);
copy_v3_v3(s->impact_size, size);
}
@@ -2173,12 +2182,19 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
int id = rbw->cache_index_map[linear_index2]->meshisland_index;
Shard *s = findShard(fmd2, id);
- if (force > fmd2->dynamic_force || ( /*force > fmd2->dynamic_force &&*/ ob1 && s && (fmd2->limit_impact &&
- can_break(ob1, ob2, fmd2->limit_impact, s))))
+ if (force > fmd2->dynamic_force && (!fmd2->limit_impact || (fmd2->limit_impact && s && (s->parent_id > 0 || s->shard_id > 0)) ||
+ (ob1 && s && (fmd2->limit_impact && can_break(ob1, ob2, fmd2->limit_impact, s)))))
{
if (s) {
float size[3];
- BKE_object_dimensions_get(ob1, size);
+ if (ob1 == ob2 || (ob1 && ob1->rigidbody_object && ob1->rigidbody_object->type == RBO_TYPE_PASSIVE)) {
+ size[0] = -1.0f; //mark as invalid, so the regular object size is used
+ size[1] = -1.0f;
+ size[2] = -1.0f;
+ }
+ else {
+ BKE_object_dimensions_get(ob1, size);
+ }
copy_v3_v3(s->impact_loc, cp->contact_pos_world_onB);
copy_v3_v3(s->impact_size, size);
}
@@ -3696,7 +3712,7 @@ static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bo
//TODO ensure evaluation on transform change too
}
- else if (rbsc->flag & RBC_FLAG_NEEDS_VALIDATE) {
+ else if (rbsc->flag & RBC_FLAG_NEEDS_VALIDATE || fmd->fracture_mode == MOD_FRACTURE_DYNAMIC) {
BKE_rigidbody_validate_sim_shard_constraint(rbw, fmd, ob, rbsc, false);
//if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
// BKE_rigidbody_start_dist_angle(rbsc, true);
@@ -4354,6 +4370,11 @@ static void resetDynamic(RigidBodyWorld *rbw, bool do_reset_always)
if (mti->applyModifier)
{
DerivedMesh *ndm;
+
+ if (md == (ModifierData*)fmd) {
+ BLI_mutex_unlock(&reset_lock);
+ }
+
ndm = mti->applyModifier(md, ob, dm, 0);
if (ndm != dm)
{
@@ -4370,7 +4391,7 @@ static void resetDynamic(RigidBodyWorld *rbw, bool do_reset_always)
break;
}
}
- BLI_mutex_unlock(&reset_lock);
+ //BLI_mutex_unlock(&reset_lock);
//DAG_id_tag_update(go->ob, OB_RECALC_ALL);
//WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, go->ob);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 817776b..688499c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5407,6 +5407,10 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
Shard *s;
fmd->dm = NULL;
+ fmd->refresh_constraints = true;
+ fmd->meshConstraints.first = NULL;
+ fmd->meshConstraints.last = NULL;
+
link_list(fd, &fmd->shard_sequence);
for (ssq = fmd->shard_sequence.first; ssq; ssq = ssq->next)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index c6c3281..d017f7a 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -1180,7 +1180,7 @@ static FracPointCloud get_points_global(FractureModifierData *emd, Object *ob, D
if (emd->fracture_mode == MOD_FRACTURE_DYNAMIC && emd->limit_impact) {
//shrink pointcloud container around impact point, to a size
s = BKE_shard_by_id(emd->frac_mesh, id, fracmesh);
- if (s != NULL && (s->shard_id == 0 || s->parent_id == 0)) {
+ if (s != NULL && (s->shard_id == 0 || s->parent_id == 0 || s->impact_size[0] > 0.0f)) {
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);
@@ -2358,7 +2358,7 @@ static void mesh_separate_loose(FractureModifierData *rmd, Object *ob, DerivedMe
static void do_constraint(FractureModifierData* fmd, MeshIsland *mi1, MeshIsland *mi2, int con_type, float thresh)
{
RigidBodyShardCon *rbsc;
- rbsc = BKE_rigidbody_create_shard_constraint(fmd->modifier.scene, con_type, true);
+ rbsc = BKE_rigidbody_create_shard_constraint(fmd->modifier.scene, con_type, fmd->fracture_mode != MOD_FRACTURE_DYNAMIC);
rbsc->mi1 = mi1;
rbsc->mi2 = mi2;
More information about the Bf-blender-cvs
mailing list