diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-25 15:21:15 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-25 18:15:07 +0300 |
commit | c2110213ca7a6b8ba2392cf6e8f5a61b7ba4b554 (patch) | |
tree | dfdf68849767fc5f04dda17b0b8db5c97b3e7e07 /source/blender/blenkernel/intern | |
parent | 2c9b32949bc00e73603bcabadb74e5b3176a161a (diff) |
Physics: update softbody and dynamic paint to get colliders from depsgraph.
Because looping over the scene is unsafe and slow.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collision.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/dynamicpaint.c | 51 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 59 |
5 files changed, 44 insertions, 98 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 8a3d27ca790..1d9cc9bb8d0 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -364,36 +364,13 @@ void BKE_collection_object_cache_free(Collection *collection) collection_object_cache_free(collection); } -Base *BKE_collection_or_layer_objects(const Depsgraph *depsgraph, - const Scene *scene, - const ViewLayer *view_layer, - Collection *collection) +Base *BKE_collection_or_layer_objects(const ViewLayer *view_layer, Collection *collection) { - // TODO: this is used by physics to get objects from a collection, but the - // the physics systems are not all using the depsgraph correctly which means - // we try different things. Instead we should explicitly get evaluated or - // non-evaluated data and always have the depsgraph available when needed - if (collection) { return BKE_collection_object_cache_get(collection).first; } - else if (depsgraph) { - view_layer = DEG_get_evaluated_view_layer(depsgraph); - - if (view_layer) { - return FIRSTBASE(view_layer); - } - else { - view_layer = DEG_get_input_view_layer(depsgraph); - return FIRSTBASE(view_layer); - } - } - else if (view_layer) { - return FIRSTBASE(view_layer); - } else { - /* depsgraph is NULL during deg build */ - return FIRSTBASE(BKE_view_layer_context_active_PLACEHOLDER(scene)); + return FIRSTBASE(view_layer); } } diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 1debdbb847e..a734e140932 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -518,7 +518,7 @@ static void add_collision_object(ListBase *relations, Object *ob, int level, uns ListBase *BKE_collision_relations_create(Depsgraph *depsgraph, Collection *collection, unsigned int modifier_type) { ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - Base *base = BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection); + Base *base = BKE_collection_or_layer_objects(view_layer, collection); const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT; @@ -548,6 +548,7 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph, Object *self, Collec ListBase *relations = DEG_get_collision_relations(depsgraph, collection, modifier_type); if (!relations) { + *numcollobj = 0; return NULL; } diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 0d694a4d25c..c1bdfc42a05 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -56,6 +56,7 @@ #include "BKE_armature.h" #include "BKE_bvhutils.h" /* bvh tree */ #include "BKE_collection.h" +#include "BKE_collision.h" #include "BKE_colorband.h" #include "BKE_cdderivedmesh.h" #include "BKE_constraint.h" @@ -490,28 +491,17 @@ static void scene_setSubframe(Scene *scene, float subframe) scene->r.subframe = subframe; } -static int surface_getBrushFlags(DynamicPaintSurface *surface, const Depsgraph *depsgraph) +static int surface_getBrushFlags(DynamicPaintSurface *surface, Depsgraph *depsgraph) { - Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, surface->brush_group); - Object *brushObj = NULL; - ModifierData *md = NULL; + unsigned int numobjects; + Object **objects = BKE_collision_objects_create(depsgraph, NULL, surface->brush_group, &numobjects, eModifierType_DynamicPaint); int flags = 0; - while (base) { - brushObj = NULL; + for (int i = 0; i < numobjects; i++) { + Object *brushObj = objects[i]; - /* select object */ - brushObj = base->object; - - /* next item */ - base = base->next; - - if (!brushObj) { - continue; - } - - md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); + ModifierData *md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; @@ -524,6 +514,8 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, const Depsgraph * } } + BKE_collision_objects_free(objects); + return flags; } @@ -5758,7 +5750,7 @@ static void dynamic_paint_generate_bake_data_cb( } } -static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Depsgraph *depsgraph, Object *ob) +static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Depsgraph *depsgraph, Object *ob) { PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; @@ -5911,29 +5903,18 @@ static int dynamicPaint_doStep( * Loop through surface's target paint objects and do painting */ { - Object *brushObj = NULL; - ModifierData *md = NULL; - Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, surface->brush_group); + unsigned int numobjects; + Object **objects = BKE_collision_objects_create(depsgraph, NULL, surface->brush_group, &numobjects, eModifierType_DynamicPaint); /* backup current scene frame */ int scene_frame = scene->r.cfra; float scene_subframe = scene->r.subframe; - while (base) { - brushObj = NULL; - /* select object */ - brushObj = base->object; - - /* next item */ - base = base->next; - - if (!brushObj) { - /* skip item */ - continue; - } + for (int i = 0; i < numobjects; i++) { + Object *brushObj = objects[i]; /* check if target has an active dp modifier */ - md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); + ModifierData *md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; /* make sure we're dealing with a brush */ @@ -5995,6 +5976,8 @@ static int dynamicPaint_doStep( } } } + + BKE_collision_objects_free(objects); } /* surfaces operations that use adjacency data */ diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index a3a766b2d1d..bb4cf1c5753 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -228,7 +228,7 @@ ListBase *BKE_effector_relations_create( ViewLayer *view_layer, Collection *collection) { - Base *base = BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection); + Base *base = BKE_collection_or_layer_objects(view_layer, collection); const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 7a8dbeed031..49280821667 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -72,6 +72,7 @@ variables on the UI for now #include "BLI_threads.h" #include "BKE_collection.h" +#include "BKE_collision.h" #include "BKE_curve.h" #include "BKE_effect.h" #include "BKE_global.h" @@ -521,20 +522,18 @@ static void ccd_build_deflector_hash(Depsgraph *depsgraph, Collection *collectio { if (!hash) return; - /* Explicit collision collection. */ - Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, collection); + unsigned int numobjects; + Object **objects = BKE_collision_objects_create(depsgraph, vertexowner, collection, &numobjects, eModifierType_Collision); - for (; base; base = base->next) { - /* Only proceed for mesh object in same layer. */ - if (base->object->type == OB_MESH) { - Object *ob = base->object; - if (ob == vertexowner) { - /* If vertexowner is given we don't want to check collision with owner object. */ - continue; - } + for (int i = 0; i < numobjects; i++) { + Object *ob = objects[i]; + + if (ob->type == OB_MESH) { ccd_build_deflector_hash_single(hash, ob); } } + + BKE_collision_objects_free(objects); } static void ccd_update_deflector_hash_single(GHash *hash, Object *ob) @@ -554,23 +553,19 @@ static void ccd_update_deflector_hash(Depsgraph *depsgraph, Collection *collecti { if ((!hash) || (!vertexowner)) return; - /* Explicit collision collection. */ - Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, collection); + unsigned int numobjects; + Object **objects = BKE_collision_objects_create(depsgraph, vertexowner, collection, &numobjects, eModifierType_Collision); - for (; base; base = base->next) { - /* Only proceed for mesh object in same layer. */ - if (base->object->type == OB_MESH) { - Object *ob = base->object; - if (ob == vertexowner) { - /* If vertexowner is given we don't want to check collision with owner object. */ - continue; - } + for (int i = 0; i < numobjects; i++) { + Object *ob = objects[i]; + if (ob->type == OB_MESH) { ccd_update_deflector_hash_single(hash, ob); } } -} + BKE_collision_objects_free(objects); +} /*--- collider caching and dicing ---*/ @@ -959,21 +954,13 @@ static void free_softbody_intern(SoftBody *sb) /** * \note collection overrides scene when not NULL. */ -static bool are_there_deflectors(Base *first_base) -{ - for (Base *base = first_base; base; base = base->next) { - if (base->object->pd) { - if (base->object->pd->deflect) - return 1; - } - } - - return 0; -} - static int query_external_colliders(Depsgraph *depsgraph, Collection *collection) { - return(are_there_deflectors(BKE_collection_or_layer_objects(depsgraph, NULL, NULL, collection))); + unsigned int numobjects; + Object **objects = BKE_collision_objects_create(depsgraph, NULL, collection, &numobjects, eModifierType_Collision); + BKE_collision_objects_free(objects); + + return (numobjects != 0); } /* --- dependency information functions*/ @@ -3491,9 +3478,7 @@ static void softbody_step(struct Depsgraph *depsgraph, Scene *scene, Object *ob, ccd_update_deflector_hash(depsgraph, sb->collision_group, ob, sb->scratch->colliderhash); if (sb->scratch->needstobuildcollider) { - if (query_external_colliders(depsgraph, sb->collision_group)) { - ccd_build_deflector_hash(depsgraph, sb->collision_group, ob, sb->scratch->colliderhash); - } + ccd_build_deflector_hash(depsgraph, sb->collision_group, ob, sb->scratch->colliderhash); sb->scratch->needstobuildcollider=0; } |