[Bf-blender-cvs] [a035b9f6091] temp-fracture-modifier-2.8: some more fix attempts for dynamic fracture cache behavior
Martin Felke
noreply at git.blender.org
Thu Nov 15 21:21:59 CET 2018
Commit: a035b9f6091e577922465c292e1976146c599475
Author: Martin Felke
Date: Thu Nov 15 21:21:39 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBa035b9f6091e577922465c292e1976146c599475
some more fix attempts for dynamic fracture cache behavior
===================================================================
M source/blender/blenkernel/BKE_fracture.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/pointcache.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/editors/object/object_modifier.c
M source/blender/makesrna/intern/rna_fracture.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index eec805c63c0..4dc787385a9 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -100,7 +100,7 @@ void BKE_fracture_meshislands_free(struct FractureModifierData* fmd, struct Scen
void BKE_fracture_free(struct FractureModifierData *fmd, struct Scene *scene);
void BKE_fracture_do(struct FractureModifierData *fmd, struct MeshIsland *mi, struct Object *obj,
- struct Depsgraph *depsgraph, struct Main *bmain, struct Scene *scene);
+ struct Depsgraph *depsgraph, struct Main *bmain, struct Scene *scene, bool is_init);
void BKE_fracture_animated_loc_rot(struct FractureModifierData *fmd, struct Object *ob, bool do_bind, struct Depsgraph *depsgraph);
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 36d4c1e5958..07d051e73d0 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1264,7 +1264,8 @@ void BKE_fracture_clear_cache(FractureModifierData* fmd, Object* ob, Scene *scen
mi = fmd->shared->mesh_islands.first;
while (mi) {
- if (mi->startframe > startframe || (!fmd->use_dynamic && mi->id == 0)) {
+ if (mi->startframe > startframe ||
+ (fmd->use_dynamic && mi->id > 0)) {
next = mi->next;
BLI_remlink(&fmd->shared->mesh_islands, mi);
BKE_fracture_mesh_island_free(mi, scene);
@@ -2586,12 +2587,24 @@ static void cleanup_splinters(FractureModifierData *fmd, float mat[4][4], MeshIs
void BKE_fracture_points(FractureModifierData *fmd, Object* obj, MeshIsland *mi, Depsgraph* depsgraph, Main *bmain,
- Scene *scene)
+ Scene *scene, bool is_initial)
{
/* dummy point cloud, random */
FracPointCloud points;
- points = BKE_fracture_points_get(depsgraph, fmd, obj, mi);
+ if (fmd->use_dynamic && is_initial)
+ {
+ //skip initial refracture on dynamic (pressing execute fracture)
+ //because we need just the original shard then
+ points.totpoints = 1;
+ points.points = MEM_callocN(sizeof(FracPoint), "frac point");
+ //points.points[0] = MEM_callocN(sizeof(FracPoint), "frac point");
+ copy_v3_v3(points.points[0].co, mi->centroid);
+ zero_v3(points.points[0].offset);
+ }
+ else {
+ points = BKE_fracture_points_get(depsgraph, fmd, obj, mi);
+ }
if (points.totpoints > 0 || fmd->use_greasepencil_edges) {
// short mat_index = 0;
@@ -2622,13 +2635,14 @@ void BKE_fracture_points(FractureModifierData *fmd, Object* obj, MeshIsland *mi,
}
//this is the main fracture function, outsource to BKE, so op or rb system can call it
-void BKE_fracture_do(FractureModifierData *fmd, MeshIsland *mi, Object *obj, Depsgraph *depsgraph, Main* bmain, Scene *scene)
+void BKE_fracture_do(FractureModifierData *fmd, MeshIsland *mi, Object *obj, Depsgraph *depsgraph, Main* bmain,
+ Scene *scene, bool is_init)
{
MeshIsland *mii = NULL;
int frame = (int)(BKE_scene_frame_get(scene)); //TODO ensure original scene !!!
/* no pointsource means re-use existing mesh islands*/
- if (fmd->point_source == 0 && !fmd->use_dynamic) {
+ if (fmd->point_source == 0 && is_init) {
int count = 1, i, j = 1;
Mesh** temp_meshs = MEM_callocN(sizeof(Mesh*) * count, "temp_islands no pointsource");
@@ -2679,7 +2693,7 @@ void BKE_fracture_do(FractureModifierData *fmd, MeshIsland *mi, Object *obj, Dep
/*decouple from listbase because it will continue growing ... */
for (i = 0; i < count; i++)
{
- BKE_fracture_points(fmd, obj, mi_tmp[i], depsgraph, bmain, scene);
+ BKE_fracture_points(fmd, obj, mi_tmp[i], depsgraph, bmain, scene, is_init);
mi_tmp[i]->endframe = frame;
}
@@ -2687,7 +2701,7 @@ void BKE_fracture_do(FractureModifierData *fmd, MeshIsland *mi, Object *obj, Dep
}
}
else {
- BKE_fracture_points(fmd, obj, mi, depsgraph, bmain, scene);
+ BKE_fracture_points(fmd, obj, mi, depsgraph, bmain, scene, is_init);
}
}
diff --git a/source/blender/blenkernel/intern/fracture_dynamic.c b/source/blender/blenkernel/intern/fracture_dynamic.c
index 763cbc84ed1..401e047da87 100644
--- a/source/blender/blenkernel/intern/fracture_dynamic.c
+++ b/source/blender/blenkernel/intern/fracture_dynamic.c
@@ -68,7 +68,7 @@ void BKE_fracture_dynamic_do(FractureModifierData *fmd, Object* ob, Scene* scene
fid = (FractureID*)fmd->shared->fracture_ids.first;
while(fid){
if (!fid->mi->fractured) {
- BKE_fracture_do(fmd, fid->mi, ob, depsgraph, bmain, scene);
+ BKE_fracture_do(fmd, fid->mi, ob, depsgraph, bmain, scene, false);
}
fid->mi->fractured = true;
count++;
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index f748fbf055c..f8bc090935c 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -139,7 +139,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
/*free old stuff here */
BKE_fracture_constraints_free(fmd, scene);
- if (!fmd->use_dynamic && fmd->dm_group && !BLI_listbase_is_empty(&fmd->shared->mesh_islands))
+ if (/*!fmd->use_dynamic && */fmd->dm_group && !BLI_listbase_is_empty(&fmd->shared->mesh_islands))
{
int i = 0;
int count = BLI_listbase_count(&fmd->shared->mesh_islands);
@@ -153,7 +153,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
/*decouple from listbase because it will continue growing ... */
for (mi = mi_tmp, i = 0; i < count; i++)
{
- BKE_fracture_do(fmd, mi_tmp[i], ob, depsgraph, bmain, scene);
+ BKE_fracture_do(fmd, mi_tmp[i], ob, depsgraph, bmain, scene, true);
mi_tmp[i]->endframe = frame;
}
@@ -161,16 +161,14 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
}
else
{
- BKE_fracture_meshislands_free(fmd, fmd->use_dynamic ? NULL : scene);
+ BKE_fracture_meshislands_free(fmd, /*fmd->use_dynamic ? NULL :*/ scene);
me_tmp = BKE_fracture_mesh_copy(me, ob);
mi = BKE_fracture_mesh_island_create(me_tmp, bmain, scene, ob, frame);
mi->id = 0;
BLI_addtail(&fmd->shared->mesh_islands, mi);
- if (!fmd->use_dynamic)
- /*if refresh, perform fracture */
- BKE_fracture_do(fmd, mi, ob, depsgraph, bmain, scene);
+ BKE_fracture_do(fmd, mi, ob, depsgraph, bmain, scene, true);
if ((fmd->point_source & MOD_FRACTURE_CUSTOM) == 0)
mi->endframe = frame;
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index b590c05cf26..b9f8007c2f7 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1488,8 +1488,9 @@ static void ptcache_rigidbody_interpolate(int index, void *rb_v, void **data, fl
MeshIsland *mi;
for (mi = fmd->shared->mesh_islands.first; mi; mi = mi->next)
{
- int frame = (int)cfra;
- int frame2 = (int)cfra2;
+ int frame = (int)cfra; //currentframe
+ int frame1 = (int)cfra1; //old frame(-step?)
+ int frame2 = (int)cfra2; //new frame(+step?)
if (BKE_fracture_meshisland_check_frame(fmd, mi, frame)) {
continue;
@@ -1508,11 +1509,12 @@ static void ptcache_rigidbody_interpolate(int index, void *rb_v, void **data, fl
}
frame = calc_frame(rbw, mi, frame);
+ frame1 = calc_frame(rbw, mi, frame1);
frame2 = calc_frame(rbw, mi, frame2);
rbo = mi->rigidbody;
- if (rbo->type == RBO_TYPE_ACTIVE) {
-
+ if (rbo->type == RBO_TYPE_ACTIVE /* && frame1 > 0*/) {
+ /* do not interpolate right after fracture event, might cause jitter movement */
copy_v3_v3(keys[1].co, rbo->pos);
copy_qt_qt(keys[1].rot, rbo->orn);
copy_v3_v3(keys[1].vel, rbo->lin_vel);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 6efe7c3873d..a1f534f6c26 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2140,12 +2140,11 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
BKE_rigidbody_cache_reset(scene);
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
}
-
}
/* try to read from cache */
// RB_TODO deal with interpolated, old and baked results
- bool can_simulate = (ctime == rbw->ltime + 1) && !(cache->flag & PTCACHE_BAKED);
+ bool can_simulate = /*(ctime == rbw->ltime + 1) &&*/ !(cache->flag & PTCACHE_BAKED);
if (BKE_ptcache_read(&pid, ctime, can_simulate) == PTCACHE_READ_EXACT) {
BKE_ptcache_validate(cache, (int)ctime);
@@ -2168,8 +2167,8 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
}
/* advance simulation, we can only step one frame forward */
- if (compare_ff_relative(ctime, rbw->ltime + 1, FLT_EPSILON, 64) && !(cache->flag & PTCACHE_BAKED))
- //if (can_simulate)
+ //if (compare_ff_relative(ctime, rbw->ltime + 1, FLT_EPSILON, 64) && !(cache->flag & PTCACHE_BAKED))
+ if (can_simulate)
{
/* write cache for first frame when on second frame */
if (rbw->ltime == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
@@ -2188,7 +2187,6 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
/* step simulation by the requested timestep, steps per second are adjusted to take time scale into account */
RB_dworld_step_simulation(rbw->shared->physics_world, timestep, INT_MAX,
1.0f / (float)rbw->steps_per_second * min_ff(rbw->time_scale, 1.0f));
-
rigidbody_update_simulation_post_step(depsgraph, rbw);
/* write cache for current frame */
@@ -2225,7 +2223,7 @@ void BKE_rigidbody_remove_constraint(Scene *scene, Object *ob) {}
void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) {}
void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {}
bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) { return false; }
-void BKE_rigidbody_cache_re
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list