diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-22 15:42:03 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-25 14:35:41 +0300 |
commit | a99dcab148ed209409f3b2479ada12d869ae84b6 (patch) | |
tree | 2b7fc55752cbe3538fc05c8f77fd86b18a0d6df7 /source/blender/physics | |
parent | 5b3ff9f7d890554ae87e63095f24ac6d31a36d3c (diff) |
Depsgraph: cache collision relations, for performance and stability.
Same reasoning as effector relations in earlier commit.
Diffstat (limited to 'source/blender/physics')
-rw-r--r-- | source/blender/physics/BPH_mass_spring.h | 4 | ||||
-rw-r--r-- | source/blender/physics/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/physics/intern/BPH_mass_spring.cpp | 14 | ||||
-rw-r--r-- | source/blender/physics/intern/hair_volume.cpp | 4 |
4 files changed, 14 insertions, 9 deletions
diff --git a/source/blender/physics/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h index fd648222174..f1eb049dd52 100644 --- a/source/blender/physics/BPH_mass_spring.h +++ b/source/blender/physics/BPH_mass_spring.h @@ -40,7 +40,7 @@ struct Implicit_Data; struct Object; struct ClothModifierData; struct ListBase; -struct Scene; +struct Depsgraph; struct VoxelData; typedef enum eMassSpringSolverStatus { @@ -56,7 +56,7 @@ int BPH_mass_spring_solver_numvert(struct Implicit_Data *id); int BPH_cloth_solver_init(struct Object *ob, struct ClothModifierData *clmd); void BPH_cloth_solver_free(struct ClothModifierData *clmd); -int BPH_cloth_solve(struct Scene *scene, struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors); +int BPH_cloth_solve(struct Depsgraph *depsgraph, struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors); void BKE_cloth_solver_set_positions(struct ClothModifierData *clmd); #ifdef __cplusplus diff --git a/source/blender/physics/CMakeLists.txt b/source/blender/physics/CMakeLists.txt index 0a4ff3fe0f0..b8663a384a7 100644 --- a/source/blender/physics/CMakeLists.txt +++ b/source/blender/physics/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC intern ../blenlib ../blenkernel + ../depsgraph ../imbuf ../makesdna ../../../intern/guardedalloc diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index 1ce6407161e..2f24231f992 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -51,6 +51,9 @@ extern "C" { #include "BPH_mass_spring.h" #include "implicit.h" +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + static float I3[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; /* Number of off-diagonal non-zero matrix blocks. @@ -848,7 +851,7 @@ static void cloth_calc_volume_force(ClothModifierData *clmd) * until a good replacement is ready */ static void cloth_collision_solve_extra( - Scene *scene, Object *ob, ClothModifierData *clmd, ListBase *effectors, + Depsgraph *depsgraph, Scene *scene, Object *ob, ClothModifierData *clmd, ListBase *effectors, float frame, float step, float dt) { Cloth *cloth = clmd->clothObject; @@ -882,7 +885,7 @@ static void cloth_collision_solve_extra( // call collision function // TODO: check if "step" or "step+dt" is correct - dg do_extra_solve = cloth_bvh_objcollision( - scene, ob, clmd, step / clmd->sim_parms->timescale, dt / clmd->sim_parms->timescale); + depsgraph, ob, clmd, step / clmd->sim_parms->timescale, dt / clmd->sim_parms->timescale); // copy corrected positions back to simulation for (i = 0; i < mvert_num; i++) { @@ -970,12 +973,13 @@ static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *r sres->status |= result->status; } -int BPH_cloth_solve(Scene *scene, Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors) +int BPH_cloth_solve(Depsgraph *depsgraph, Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors) { /* Hair currently is a cloth sim in disguise ... * Collision detection and volumetrics work differently then. * Bad design, TODO */ + Scene *scene = DEG_get_evaluated_scene(depsgraph); const bool is_hair = (clmd->hairdata != NULL); unsigned int i=0; @@ -1020,7 +1024,7 @@ int BPH_cloth_solve(Scene *scene, Object *ob, float frame, ClothModifierData *cl if (is_hair) { /* determine contact points */ if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) { - cloth_find_point_contacts(scene, ob, clmd, 0.0f, tf, &contacts, &totcolliders); + cloth_find_point_contacts(depsgraph, ob, clmd, 0.0f, tf, &contacts, &totcolliders); } /* setup vertex constraints for pinned vertices and contacts */ @@ -1059,7 +1063,7 @@ int BPH_cloth_solve(Scene *scene, Object *ob, float frame, ClothModifierData *cl BPH_mass_spring_solve_positions(id, dt); if (!is_hair) { - cloth_collision_solve_extra(scene, ob, clmd, effectors, frame, step, dt); + cloth_collision_solve_extra(depsgraph, scene, ob, clmd, effectors, frame, step, dt); } BPH_mass_spring_apply_result(id); diff --git a/source/blender/physics/intern/hair_volume.cpp b/source/blender/physics/intern/hair_volume.cpp index b59ac46abbc..d2d43882a2d 100644 --- a/source/blender/physics/intern/hair_volume.cpp +++ b/source/blender/physics/intern/hair_volume.cpp @@ -1054,7 +1054,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, } /* gather colliders */ - colliders = get_collider_cache(clmd->scene, NULL, NULL); + colliders = BKE_collider_cache_create(depsgraph, NULL, NULL); if (colliders && collfac > 0.0f) { for (col = colliders->first; col; col = col->next) { MVert *loc0 = col->collmd->x; @@ -1087,7 +1087,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, } } } - free_collider_cache(&colliders); + BKE_collider_cache_free(&colliders); /* divide velocity with density */ for (i = 0; i < size; i++) { |