diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2016-10-07 13:27:11 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2016-10-07 21:47:00 +0300 |
commit | 0a2a006775543292786e8642b20a594771fdc81c (patch) | |
tree | a4691a5ef1775477db13dae13ee9d9dd80efa2bc /source/blender/modifiers | |
parent | 2dccf5a6e881973858de2c230cb610a2ea3a03e1 (diff) |
Collision: skip expensive BVH update if the collider doesn't move.
Since the collision modifier cannot be disabled, it causes a constant
hit on the viewport animation playback FPS. Most of this overhead can
be automatically removed in the case when the collider is static.
The updates are only skipped when the collider was stationary during
the preceding update as well, so the state is stored in a field.
Knowing that the collider is static can also be used to disable similar
BVH updates for substeps in the actual cloth simulation code.
Differential Revision: https://developer.blender.org/D2277
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_collision.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index ff0c6500479..e7ff0a90fbc 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -60,6 +60,7 @@ static void initData(ModifierData *md) collmd->time_x = collmd->time_xnew = -1000; collmd->mvert_num = 0; collmd->tri_num = 0; + collmd->is_static = false; collmd->bvhtree = NULL; } @@ -87,6 +88,7 @@ static void freeData(ModifierData *md) collmd->time_x = collmd->time_xnew = -1000; collmd->mvert_num = 0; collmd->tri_num = 0; + collmd->is_static = false; } } @@ -169,6 +171,7 @@ static void deformVerts(ModifierData *md, Object *ob, ob->pd->pdef_sboft); collmd->time_x = collmd->time_xnew = current_time; + collmd->is_static = true; } else if (mvert_num == collmd->mvert_num) { /* put positions to old positions */ @@ -179,14 +182,19 @@ static void deformVerts(ModifierData *md, Object *ob, memcpy(collmd->xnew, dm->getVertArray(dm), mvert_num * sizeof(MVert)); + bool is_static = true; + for (i = 0; i < mvert_num; i++) { /* we save global positions */ mul_m4_v3(ob->obmat, collmd->xnew[i].co); + + /* detect motion */ + is_static = is_static && equals_v3v3(collmd->x[i].co, collmd->xnew[i].co); } - + memcpy(collmd->current_xnew, collmd->x, mvert_num * sizeof(MVert)); memcpy(collmd->current_x, collmd->x, mvert_num * sizeof(MVert)); - + /* check if GUI setting has changed for bvh */ if (collmd->bvhtree) { if (ob->pd->pdef_sboft != BLI_bvhtree_get_epsilon(collmd->bvhtree)) { @@ -206,7 +214,7 @@ static void deformVerts(ModifierData *md, Object *ob, collmd->tri, collmd->tri_num, ob->pd->pdef_sboft); } - else { + else if (!collmd->is_static || !is_static) { /* recalc static bounding boxes */ bvhtree_update_from_mvert( collmd->bvhtree, @@ -214,7 +222,8 @@ static void deformVerts(ModifierData *md, Object *ob, collmd->tri, collmd->tri_num, true); } - + + collmd->is_static = is_static; collmd->time_xnew = current_time; } else if (mvert_num != collmd->mvert_num) { |