[Bf-blender-cvs] [bda7f7d61fb] temp-fracture-modifier-2.8: attempt to stabilize dynamic fracture
Martin Felke
noreply at git.blender.org
Sun Mar 17 14:48:24 CET 2019
Commit: bda7f7d61fb545729dbe002b01a2870bc67ee1e0
Author: Martin Felke
Date: Sun Mar 17 14:12:48 2019 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBbda7f7d61fb545729dbe002b01a2870bc67ee1e0
attempt to stabilize dynamic fracture
===================================================================
M source/blender/blenkernel/BKE_rigidbody.h
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/fracture_dynamic.c
M source/blender/blenkernel/intern/fracture_prefractured.c
M source/blender/blenkernel/intern/fracture_rigidbody.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M source/blender/windowmanager/intern/wm_event_system.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index 4652f401185..e782b1e9762 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -189,6 +189,7 @@ bool BKE_restoreKinematic(struct RigidBodyWorld *rbw, bool override_bind);
void BKE_rigidbody_update_simulation(struct Depsgraph *depsgraph, struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild);
void BKE_rigidbody_physics_visualize(struct RigidBodyWorld *rbw);
+void BKE_rigidbody_dynamic_stop(struct Scene *scene);
#endif /* __BKE_RIGIDBODY_H__ */
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 9581341281c..732ffac6197 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -452,9 +452,14 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
fmd->frac_algorithm == MOD_FRACTURE_BISECT_FAST_FILL ||
fmd->frac_algorithm == MOD_FRACTURE_BOOLEAN_FRACTAL);
+ bool is_dynamic = (fmd->flag & MOD_FRACTURE_USE_DYNAMIC);
+
/*global preparations */
- islands = MEM_callocN(sizeof(Shard*) * count, "islands");
- tree = BLI_kdtree_new(count);
+ if (!is_dynamic) {
+ islands = MEM_callocN(sizeof(Shard*) * count, "islands");
+ tree = BLI_kdtree_new(count);
+ }
+
temp_meshs = MEM_callocN(sizeof(Mesh*) * count_new, "temp_meshs");
mii->endframe = frame;
@@ -471,11 +476,13 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
/* parse to raw meshisland*/
Shard *mi = parse_cell(c[i]);
- BLI_kdtree_insert(tree, i, mi->loc);
- islands[i] = mi;
+ if (!is_dynamic) {
+ BLI_kdtree_insert(tree, i, mi->loc);
+ islands[i] = mi;
+ }
/* check whether it needs to be processed */
- if (needs_process(fmd, mi))
+ if (is_dynamic || needs_process(fmd, mi))
{
/* meshB is for "halving" algorithms like fractal and bisectfast/bisectfastfill*/
Mesh *meshA = NULL, *meshB = NULL;
@@ -560,34 +567,44 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
BKE_fracture_postprocess_meshisland(fmd, ob, mii, &temp_meshs, count, scene, frame, islands);
- BLI_kdtree_balance(tree);
-
/* swap old last islands and tree against new for next run */
if (fmd->shared->last_island_tree)
{
BLI_kdtree_free(fmd->shared->last_island_tree);
+ fmd->shared->last_island_tree = NULL;
}
- fmd->shared->last_island_tree = tree;
+ if (!is_dynamic) {
+ BLI_kdtree_balance(tree);
+ fmd->shared->last_island_tree = tree;
+ }
if (fmd->shared->last_islands)
{
- int k = 0;
- for (k = 0; k < fmd->shared->last_islands_count; k++)
- {
- if (fmd->shared->last_islands[k])
+ if (!is_dynamic) {
+ int k = 0;
+ for (k = 0; k < fmd->shared->last_islands_count; k++)
{
- //BLI_remlink(&fmd->shared->shards, fmd->shared->last_islands[k]);
- BKE_fracture_mesh_island_free(fmd, fmd->shared->last_islands[k], scene);
+ if (fmd->shared->last_islands[k])
+ {
+ //BLI_remlink(&fmd->shared->shards, fmd->shared->last_islands[k]);
+ BKE_fracture_mesh_island_free(fmd, fmd->shared->last_islands[k], scene);
+ }
}
}
MEM_freeN(fmd->shared->last_islands);
+ fmd->shared->last_islands_count = 0;
+ fmd->shared->last_islands = NULL;
}
MEM_freeN(temp_meshs);
- fmd->shared->last_islands = islands;
- fmd->shared->last_islands_count = count;
+
+ if (!is_dynamic)
+ {
+ fmd->shared->last_islands = islands;
+ fmd->shared->last_islands_count = count;
+ }
}
static Shard *parse_cell(cell c)
@@ -901,6 +918,7 @@ void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
float size[3];
bool* deletemap = MEM_callocN(sizeof(bool) * count_new, "deletemap");
mat4_to_size(size, ob->obmat);
+ int last_id = 0;
if (fmd->flag & MOD_FRACTURE_USE_SPLIT_TO_ISLANDS)
{
@@ -932,6 +950,8 @@ void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
}
}
+ last_id = BLI_listbase_count(&fmd->shared->shards);
+
for (i = 0; i < count_new; i++)
{
if ((*temp_meshs)[i] && !deletemap[i])
@@ -942,7 +962,7 @@ void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
Shard *result = BKE_fracture_mesh_island_create((*temp_meshs)[i], scene, ob, frame);
fracture_meshisland_add(fmd, result);
- result->id = mi->id + j;
+ result->id = last_id + j;
result->rigidbody->flag = mi->rigidbody->flag;
/* dont forget copying over the neighborhood info, we expose this to python so it might be useful */
@@ -1854,7 +1874,7 @@ void BKE_fracture_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool d
bool BKE_fracture_meshisland_check_frame(FractureModifierData *fmd, Shard* mi, int frame)
{
return ((frame < mi->startframe && mi->startframe > fmd->shared->last_cache_start) ||
- (frame > mi->endframe && mi->endframe < fmd->shared->last_cache_end));
+ (frame >= mi->endframe && mi->endframe < fmd->shared->last_cache_end));
}
void BKE_fracture_meshisland_check_realloc_cache(FractureModifierData *fmd, RigidBodyWorld *rbw, Shard* mi, int frame)
diff --git a/source/blender/blenkernel/intern/fracture_dynamic.c b/source/blender/blenkernel/intern/fracture_dynamic.c
index d157c9cda9a..a5e88907262 100644
--- a/source/blender/blenkernel/intern/fracture_dynamic.c
+++ b/source/blender/blenkernel/intern/fracture_dynamic.c
@@ -52,12 +52,14 @@
void BKE_fracture_dynamic_do(FractureModifierData *fmd, Object* ob, Scene* scene, Depsgraph* depsgraph, Main* bmain)
{
FractureQueueEntry *fid = fmd->shared->dynamic_fracture_queue.first;
+ int frame = (int)DEG_get_ctime(depsgraph);
while(fid){
if (!fid->mi->fractured) {
BKE_fracture_do(fmd, fid->mi, ob, depsgraph, bmain, scene, false);
fid->mi->fractured = true;
+ fid->mi->endframe = frame;
}
BLI_remlink(&fmd->shared->dynamic_fracture_queue, fid);
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index 8e398248ab6..a1a3f4a2503 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -31,6 +31,7 @@
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_ghash.h"
+#include "BLI_threads.h"
#include "BKE_fracture.h"
#include "BKE_pointcache.h"
@@ -269,7 +270,8 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
BKE_fracture_dynamic_do(fmd, ob, scene, depsgraph, bmain);
fmd->shared->flag &= ~ MOD_FRACTURE_REFRESH_DYNAMIC;
- //fmd->shared->flag |= MOD_FRACTURE_REFRESH_AUTOHIDE;
+ fmd->shared->flag |= MOD_FRACTURE_REFRESH_CONSTRAINTS;
+ fmd->shared->flag |= MOD_FRACTURE_REFRESH_AUTOHIDE;
}
if ((fmd->flag & MOD_FRACTURE_USE_ANIMATED_MESH) && fmd->anim_mesh_ob)
diff --git a/source/blender/blenkernel/intern/fracture_rigidbody.c b/source/blender/blenkernel/intern/fracture_rigidbody.c
index a07c46d33ff..d307415412e 100644
--- a/source/blender/blenkernel/intern/fracture_rigidbody.c
+++ b/source/blender/blenkernel/intern/fracture_rigidbody.c
@@ -1237,7 +1237,7 @@ int BKE_rigidbody_filter_callback(void* scene, void* island1, void* island2, voi
bool validOb = true, check_activate = false;
// oh man... the pleasures of CoW.., mooo
- sc_orig = (Scene*)DEG_get_original_id(&sc->id);
+ sc_orig = sc; // (Scene*)DEG_get_original_id(&sc->id);
rbw = sc_orig->rigidbody_world;
mi1 = (Shard*)island1;
@@ -1544,14 +1544,10 @@ static void check_fracture(rbContactPoint* cp, Scene *scene)
cp = NULL;
}
-static ThreadMutex dynamic_lock = BLI_MUTEX_INITIALIZER;
void BKE_rigidbody_contact_callback(rbContactPoint* cp, void* sc)
{
- Scene* scene = (Scene*)DEG_get_original_id(sc);
-
- BLI_mutex_lock(&dynamic_lock);
+ Scene* scene = (Scene*)sc; //DEG_get_original_id(sc);
check_fracture(cp,scene);
- BLI_mutex_unlock(&dynamic_lock);
}
void BKE_rigidbody_id_callback(void* island, int* objectId, int* islandId)
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index a1ff23440aa..a15d057a8bd 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1837,6 +1837,7 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
Shard *mi;
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, ob) {
+ modFound = false;
rmd = (FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
if (BKE_rigidbody_modifier_active(rmd)) {
for (mi = rmd->shared->shards.first; mi; mi = mi->next) {
@@ -1861,19 +1862,19 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
RB_body_get_angular_velocity(rbo->shared->physics_object, rbo->ang_vel);
}
}
-
- /* purge constraints after sim step in case of dynamic, so they can be rebuilt by the modifier running next,
- * before the next rigidbody step */
- if ((rmd->flag & MOD_FRACTURE_USE_DYNAMIC)) {
- if (rmd->shared->flag & MOD_FRACTURE_REFRESH_DYNAMIC) {
- /* very important, since old constraints may mess up the simulation after stopping and restarting */
- BKE_fracture_constraints_free(rmd, rbw);
- rmd->shared->flag |= MOD_FRACTURE_REFRESH_CONSTRAINTS;
- }
+ }
+#if 0
+ /* purge constraints after sim step in case of dynamic, so they can be rebuilt by the modifier running next,
+ * before the next rigidbody step */
+ if ((rmd->flag & MOD_FRACTURE_USE_DYNAMIC)) {
+ if (rmd->shared->flag & MOD_FRACTURE_REFRESH_DYNAMIC) {
+ /* very important, since old constraints may mess up the simulation after stopping and restarting */
+ BKE_fracture_constraints_free(rmd, rbw);
+ rmd->shared->flag |= MOD_FRACTURE_REFRESH_CONSTRAINTS;
}
}
+#endif
modFound = true;
- break;
}
/* handle regular rigidbodies */
@@ -1893,7 +1894,6 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
RB_body_get_linear_velocity(rbo->shared->physics_object, rbo->lin_vel);
RB_body_get_angular_velocity(rbo->shared->physics_object, rbo->ang_vel);
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list