From a99dcab148ed209409f3b2479ada12d869ae84b6 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 22 Jun 2018 14:42:03 +0200 Subject: Depsgraph: cache collision relations, for performance and stability. Same reasoning as effector relations in earlier commit. --- source/blender/blenkernel/BKE_cloth.h | 6 +- source/blender/blenkernel/BKE_collision.h | 35 +++- source/blender/blenkernel/BKE_effect.h | 1 - source/blender/blenkernel/intern/cloth.c | 10 +- source/blender/blenkernel/intern/collision.c | 185 +++++++++++---------- source/blender/blenkernel/intern/dynamicpaint.c | 2 +- source/blender/blenkernel/intern/effect.c | 6 +- source/blender/blenkernel/intern/particle_system.c | 6 +- source/blender/blenkernel/intern/rigidbody.c | 2 +- source/blender/blenkernel/intern/smoke.c | 16 +- source/blender/blenkernel/intern/softbody.c | 8 +- 11 files changed, 154 insertions(+), 123 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 154875e5745..244054712f1 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -210,10 +210,10 @@ typedef struct ColliderContacts { } ColliderContacts; // needed for implicit.c -int cloth_bvh_objcollision (struct Scene *scene, struct Object *ob, struct ClothModifierData *clmd, float step, float dt ); -int cloth_points_objcollision(struct Scene *scene, struct Object *ob, struct ClothModifierData *clmd, float step, float dt); +int cloth_bvh_objcollision (struct Depsgraph *depsgraph, struct Object *ob, struct ClothModifierData *clmd, float step, float dt ); +int cloth_points_objcollision(struct Depsgraph *depsgraph, struct Object *ob, struct ClothModifierData *clmd, float step, float dt); -void cloth_find_point_contacts(struct Scene *scene, struct Object *ob, struct ClothModifierData *clmd, float step, float dt, +void cloth_find_point_contacts(struct Depsgraph *depsgraph, struct Object *ob, struct ClothModifierData *clmd, float step, float dt, ColliderContacts **r_collider_contacts, int *r_totcolliders); void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders); diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h index 2392c92bd84..a488851513c 100644 --- a/source/blender/blenkernel/BKE_collision.h +++ b/source/blender/blenkernel/BKE_collision.h @@ -49,6 +49,7 @@ struct MFace; struct MVert; struct Object; struct Scene; +struct Depsgraph; struct MVertTri; //////////////////////////////////////// @@ -143,14 +144,29 @@ void collision_move_object(struct CollisionModifierData *collmd, float step, flo void collision_get_collider_velocity(float vel_old[3], float vel_new[3], struct CollisionModifierData *collmd, struct CollPair *collpair); -///////////////////////////////////////////////// -// used in effect.c -///////////////////////////////////////////////// -/* explicit control over layer mask and dupli recursion */ -struct Object **get_collisionobjects_ext(struct Scene *scene, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type, bool dupli); +/* Collision relations for dependency graph build. */ + +typedef struct CollisionRelation { + struct CollisionRelation *next, *prev; + struct Object *ob; +} CollisionRelation; + +struct ListBase *BKE_collision_relations_create( + struct Depsgraph *depsgraph, + struct Collection *collection, + unsigned int modifier_type); +void BKE_collision_relations_free(struct ListBase *relations); + +/* Collision object lists for physics simulation evaluation. */ -struct Object **get_collisionobjects(struct Scene *scene, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type); +struct Object **BKE_collision_objects_create( + struct Depsgraph *depsgraph, + struct Object *self, + struct Collection *collection, + unsigned int *numcollobj, + unsigned int modifier_type); +void BKE_collision_objects_free(struct Object **objects); typedef struct ColliderCache { struct ColliderCache *next, *prev; @@ -158,8 +174,11 @@ typedef struct ColliderCache { struct CollisionModifierData *collmd; } ColliderCache; -struct ListBase *get_collider_cache(struct Scene *scene, struct Object *self, struct Collection *collection); -void free_collider_cache(struct ListBase **colliders); +struct ListBase *BKE_collider_cache_create( + struct Depsgraph *scene, + struct Object *self, + struct Collection *collection); +void BKE_collider_cache_free(struct ListBase **colliders); ///////////////////////////////////////////////// diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index a0af34d59e6..484cf957be1 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -130,7 +130,6 @@ void BKE_effector_relations_free(struct ListBase *lb); struct ListBase *BKE_effectors_create( struct Depsgraph *depsgraph, - struct Scene *scene, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index bfe59e5366d..680c6860f4c 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -350,7 +350,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int return 1; } -static int do_step_cloth(struct Depsgraph *depsgraph, Scene *scene, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr) +static int do_step_cloth(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr) { ClothVertex *verts = NULL; Cloth *cloth; @@ -375,7 +375,7 @@ static int do_step_cloth(struct Depsgraph *depsgraph, Scene *scene, Object *ob, mul_m4_v3(ob->obmat, verts->xconst); } - effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, clmd->sim_parms->effector_weights); + effectors = BKE_effectors_create(depsgraph, ob, NULL, clmd->sim_parms->effector_weights); if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH ) cloth_update_verts ( ob, clmd, result ); @@ -391,7 +391,7 @@ static int do_step_cloth(struct Depsgraph *depsgraph, Scene *scene, Object *ob, // TIMEIT_START(cloth_step) /* call the solver. */ - ret = BPH_cloth_solve(scene, ob, framenr, clmd, effectors); + ret = BPH_cloth_solve(depsgraph, ob, framenr, clmd, effectors); // TIMEIT_END(cloth_step) @@ -405,7 +405,7 @@ static int do_step_cloth(struct Depsgraph *depsgraph, Scene *scene, Object *ob, /************************************************ * clothModifier_do - main simulation function ************************************************/ -void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh, float (*vertexCos)[3]) +void clothModifier_do(ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh, float (*vertexCos)[3]) { PointCache *cache; PTCacheID pid; @@ -492,7 +492,7 @@ void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scen /* do simulation */ BKE_ptcache_validate(cache, framenr); - if (!do_step_cloth(depsgraph, scene, ob, clmd, mesh, framenr)) { + if (!do_step_cloth(depsgraph, ob, clmd, mesh, framenr)) { BKE_ptcache_invalidate(cache); } else diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index b41c4633ccb..f250ffdfaeb 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -58,6 +58,10 @@ #include "BLI_kdopbvh.h" #include "BKE_collision.h" +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_physics.h" +#include "DEG_depsgraph_query.h" + #ifdef WITH_ELTOPO #include "eltopo-capi.h" #endif @@ -479,147 +483,161 @@ static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, return collpair; } -static void add_collision_object(Object ***objs, unsigned int *numobj, unsigned int *maxobj, Object *ob, Object *self, int level, unsigned int modifier_type) +static void add_collision_object(ListBase *relations, Object *ob, int level, unsigned int modifier_type) { CollisionModifierData *cmd= NULL; - if (ob == self) - return; - /* only get objects with collision modifier */ if (((modifier_type == eModifierType_Collision) && ob->pd && ob->pd->deflect) || (modifier_type != eModifierType_Collision)) cmd= (CollisionModifierData *)modifiers_findByType(ob, modifier_type); if (cmd) { - /* extend array */ - if (*numobj >= *maxobj) { - *maxobj *= 2; - *objs= MEM_reallocN(*objs, sizeof(Object *)*(*maxobj)); - } - - (*objs)[*numobj] = ob; - (*numobj)++; + CollisionRelation *relation = MEM_callocN(sizeof(CollisionRelation), "CollisionRelation"); + relation->ob = ob; + BLI_addtail(relations, relation); } /* objects in dupli groups, one level only for now */ + /* TODO: this doesn't really work, we are not taking into account the + * dupli transforms and can get objects in the list multiple times. */ if (ob->dup_group && level == 0) { Collection *collection= ob->dup_group; /* add objects */ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) { - add_collision_object(objs, numobj, maxobj, object, self, level+1, modifier_type); + add_collision_object(relations, object, level+1, modifier_type); } FOREACH_COLLECTION_OBJECT_RECURSIVE_END; } } -// return all collision objects in scene -// collision object will exclude self -Object **get_collisionobjects_ext(Scene *scene, Object *self, Collection *collection, unsigned int *numcollobj, unsigned int modifier_type, bool dupli) +/* Create list of collision relations in the collection or entire scene. + * This is used by the depsgraph to build relations, as well as faster + * lookup of colliders during evaluation. */ +ListBase *BKE_collision_relations_create(Depsgraph *depsgraph, Collection *collection, unsigned int modifier_type) { - Object **objs; - unsigned int numobj= 0, maxobj= 100; - int level = dupli ? 0 : 1; - - objs= MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); + ListBase *relations = MEM_callocN(sizeof(ListBase), "CollisionRelation list"); + int level = 0; /* gather all collision objects */ if (collection) { /* use specified collection */ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) { - add_collision_object(&objs, &numobj, &maxobj, object, self, level, modifier_type); + add_collision_object(relations, object, level, modifier_type); } FOREACH_COLLECTION_OBJECT_RECURSIVE_END; } else { + Scene *scene = DEG_get_input_scene(depsgraph); Scene *sce_iter; Base *base; /* add objects in same layer in scene */ for (SETLOOPER(scene, sce_iter, base)) { if ((base->flag & BASE_VISIBLED) != 0) { - add_collision_object(&objs, &numobj, &maxobj, base->object, self, level, modifier_type); + add_collision_object(relations, base->object, level, modifier_type); } } } - *numcollobj= numobj; - - return objs; + return relations; } -Object **get_collisionobjects(Scene *scene, Object *self, Collection *collection, unsigned int *numcollobj, unsigned int modifier_type) +void BKE_collision_relations_free(ListBase *relations) { - /* Need to check for active layers, too. - Otherwise this check fails if the objects are not on the same layer - DG */ - return get_collisionobjects_ext(scene, self, collection, numcollobj, modifier_type, true); + if (relations) { + BLI_freelistN(relations); + MEM_freeN(relations); + } } -static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self, int level) +/* Create effective list of colliders from relations built beforehand. + * Self will be excluded. */ +Object **BKE_collision_objects_create(Depsgraph *depsgraph, Object *self, Collection *collection, unsigned int *numcollobj, unsigned int modifier_type) { - CollisionModifierData *cmd= NULL; - ColliderCache *col; + ListBase *relations; - if (ob == self) - return; + if (modifier_type == eModifierType_Smoke) { + relations = DEG_get_smoke_collision_relations(depsgraph, collection); + } + else { + relations = DEG_get_collision_relations(depsgraph, collection); + } - if (ob->pd && ob->pd->deflect) - cmd =(CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision); + if (!relations) { + return NULL; + } - if (cmd && cmd->bvhtree) { - if (*objs == NULL) - *objs = MEM_callocN(sizeof(ListBase), "ColliderCache array"); + int maxnum = BLI_listbase_count(relations); + int num = 0; + Object **objects = MEM_callocN(sizeof(Object*) * maxnum, __func__); - col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); - col->ob = ob; - col->collmd = cmd; - /* make sure collider is properly set up */ - collision_move_object(cmd, 1.0, 0.0); - BLI_addtail(*objs, col); + for (CollisionRelation *relation = relations->first; relation; relation = relation->next) { + /* Get evaluated object. */ + Object *ob = (Object*)DEG_get_evaluated_id(depsgraph, &relation->ob->id); + + if (ob != self) { + objects[num] = ob; + num++; + } } - /* objects in dupli collection, one level only for now */ - if (ob->dup_group && level == 0) { - Collection *collection= ob->dup_group; + if (num == 0) { + MEM_freeN(objects); + objects = NULL; + } - /* add objects */ - FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) - { - add_collider_cache_object(objs, object, self, level+1); - } - FOREACH_COLLECTION_OBJECT_RECURSIVE_END; + *numcollobj = num; + return objects; +} + +void BKE_collision_objects_free(Object **objects) +{ + if (objects) { + MEM_freeN(objects); } } -ListBase *get_collider_cache(Scene *scene, Object *self, Collection *collection) +/* Create effective list of colliders from relations built beforehand. + * Self will be excluded. */ +ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collection *collection) { - ListBase *objs= NULL; + /* TODO: does this get built? */ + ListBase *relations = DEG_get_collision_relations(depsgraph, collection); + ListBase *cache = NULL; - /* add object in same layer in scene */ - if (collection) { - FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) - { - add_collider_cache_object(&objs, object, self, 0); - } - FOREACH_COLLECTION_OBJECT_RECURSIVE_END; + if (!relations) { + return NULL; } - else { - Scene *sce_iter; - Base *base; - /* add objects in same layer in scene */ - for (SETLOOPER(scene, sce_iter, base)) { - if (!self || ((base->flag & BASE_VISIBLED) != 0)) - add_collider_cache_object(&objs, base->object, self, 0); + for (CollisionRelation *relation = relations->first; relation; relation = relation->next) { + /* Get evaluated object. */ + Object *ob = (Object*)DEG_get_evaluated_id(depsgraph, &relation->ob->id); + + if (ob == self) { + continue; + } + + CollisionModifierData *cmd = (CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision); + if (cmd && cmd->bvhtree) { + if (cache == NULL) { + cache = MEM_callocN(sizeof(ListBase), "ColliderCache array"); + } + ColliderCache *col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); + col->ob = ob; + col->collmd = cmd; + /* make sure collider is properly set up */ + collision_move_object(cmd, 1.0, 0.0); + BLI_addtail(cache, col); } } - return objs; + return cache; } -void free_collider_cache(ListBase **colliders) +void BKE_collider_cache_free(ListBase **colliders) { if (*colliders) { BLI_freelistN(*colliders); @@ -686,7 +704,7 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision } // cloth - object collisions -int cloth_bvh_objcollision(Scene *scene, Object *ob, ClothModifierData *clmd, float step, float dt ) +int cloth_bvh_objcollision(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt ) { Cloth *cloth= clmd->clothObject; BVHTree *cloth_bvh= cloth->bvhtree; @@ -712,7 +730,7 @@ int cloth_bvh_objcollision(Scene *scene, Object *ob, ClothModifierData *clmd, fl bvhtree_update_from_cloth ( clmd, 1 ); // 0 means STATIC, 1 means MOVING (see later in this function) bvhselftree_update_from_cloth ( clmd, 0 ); // 0 means STATIC, 1 means MOVING (see later in this function) - collobjs = get_collisionobjects(scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); + collobjs = BKE_collision_objects_create(depsgraph, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); if (!collobjs) return 0; @@ -894,8 +912,7 @@ int cloth_bvh_objcollision(Scene *scene, Object *ob, ClothModifierData *clmd, fl } while ( ret2 && ( clmd->coll_parms->loop_count>rounds ) ); - if (collobjs) - MEM_freeN(collobjs); + BKE_collision_objects_free(collobjs); return 1|MIN2 ( ret, 1 ); } @@ -1207,7 +1224,7 @@ static int cloth_points_objcollisions_resolve( } // cloth - object collisions -int cloth_points_objcollision(Scene *scene, Object *ob, ClothModifierData *clmd, float step, float dt) +int cloth_points_objcollision(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt) { Cloth *cloth= clmd->clothObject; BVHTree *cloth_bvh; @@ -1240,7 +1257,7 @@ int cloth_points_objcollision(Scene *scene, Object *ob, ClothModifierData *clmd, /* balance tree */ BLI_bvhtree_balance(cloth_bvh); - collobjs = get_collisionobjects(scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); + collobjs = BKE_collision_objects_create(depsgraph, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); if (!collobjs) return 0; @@ -1321,15 +1338,14 @@ int cloth_points_objcollision(Scene *scene, Object *ob, ClothModifierData *clmd, } while ( ret2 && ( clmd->coll_parms->loop_count>rounds ) ); - if (collobjs) - MEM_freeN(collobjs); + BKE_collision_objects_free(collobjs); BLI_bvhtree_free(cloth_bvh); return 1|MIN2 ( ret, 1 ); } -void cloth_find_point_contacts(Scene *scene, Object *ob, ClothModifierData *clmd, float step, float dt, +void cloth_find_point_contacts(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt, ColliderContacts **r_collider_contacts, int *r_totcolliders) { Cloth *cloth= clmd->clothObject; @@ -1363,7 +1379,7 @@ void cloth_find_point_contacts(Scene *scene, Object *ob, ClothModifierData *clmd /* balance tree */ BLI_bvhtree_balance(cloth_bvh); - collobjs = get_collisionobjects(scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); + collobjs = BKE_collision_objects_create(depsgraph, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); if (!collobjs) { *r_collider_contacts = NULL; *r_totcolliders = 0; @@ -1421,8 +1437,7 @@ void cloth_find_point_contacts(Scene *scene, Object *ob, ClothModifierData *clmd MEM_freeN(overlap); } - if (collobjs) - MEM_freeN(collobjs); + BKE_collision_objects_free(collobjs); BLI_bvhtree_free(cloth_bvh); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 173dc8050a1..0d694a4d25c 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -4926,7 +4926,7 @@ static int dynamicPaint_prepareEffectStep( /* Init force data if required */ if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) { - ListBase *effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, surface->effector_weights); + ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, surface->effector_weights); /* allocate memory for force data (dir vector + strength) */ *force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces"); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index adf5b5da35e..2894ff4f1e7 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -267,11 +267,11 @@ void BKE_effector_relations_free(ListBase *lb) /* Create effective list of effectors from relations built beforehand. */ ListBase *BKE_effectors_create( Depsgraph *depsgraph, - Scene *scene, Object *ob_src, ParticleSystem *psys_src, EffectorWeights *weights) { + Scene *scene = DEG_get_evaluated_scene(depsgraph); ListBase *relations = DEG_get_effector_relations(depsgraph, weights->group); ListBase *effectors = NULL; @@ -420,7 +420,7 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect return visibility; if (!colls) - colls = get_collider_cache(eff->scene, eff->ob, NULL); + colls = BKE_collider_cache_create(eff->depsgraph, eff->ob, NULL); if (!colls) return visibility; @@ -458,7 +458,7 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect } if (!colliders) - free_collider_cache(&colls); + BKE_collider_cache_free(&colls); return visibility; } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index d6a29531482..e8dbf95e286 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -1310,7 +1310,7 @@ static void psys_update_effectors(ParticleSimulationData *sim) { BKE_effectors_free(sim->psys->effectors); sim->psys->effectors = BKE_effectors_create(sim->depsgraph, - sim->scene, sim->ob, sim->psys, + sim->ob, sim->psys, sim->psys->part->effector_weights); precalc_guides(sim, sim->psys->effectors); } @@ -3540,7 +3540,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) psys_update_effectors(sim); if (part->type != PART_HAIR) - sim->colliders = get_collider_cache(sim->scene, sim->ob, part->collision_group); + sim->colliders = BKE_collider_cache_create(sim->depsgraph, sim->ob, part->collision_group); /* initialize physics type specific stuff */ switch (part->phystype) { @@ -3747,7 +3747,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) pa->state.time=cfra; } - free_collider_cache(&sim->colliders); + BKE_collider_cache_free(&sim->colliders); BLI_rng_free(sim->rng); sim->rng = NULL; } diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index ab324726812..833ac0a88fa 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1283,7 +1283,7 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Scene *scene, RigidBod ListBase *effectors; /* get effectors present in the group specified by effector_weights */ - effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, effector_weights); + effectors = BKE_effectors_create(depsgraph, ob, NULL, effector_weights); if (effectors) { float eff_force[3] = {0.0f, 0.0f, 0.0f}; float eff_loc[3], eff_vel[3]; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 5ba9b7ce4dc..c9b10e36ed1 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -893,7 +893,7 @@ static void obstacles_from_derivedmesh( } /* Animated obstacles: dx_step = ((x_new - x_old) / totalsteps) * substep */ -static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt, +static void update_obstacles(Depsgraph *depsgraph, Object *ob, SmokeDomainSettings *sds, float dt, int UNUSED(substep), int UNUSED(totalsteps)) { Object **collobjs = NULL; @@ -933,7 +933,7 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds, } - collobjs = get_collisionobjects(scene, ob, sds->coll_group, &numcollobj, eModifierType_Smoke); + collobjs = BKE_collision_objects_create(depsgraph, ob, sds->coll_group, &numcollobj, eModifierType_Smoke); // update obstacle tags in cells for (collIndex = 0; collIndex < numcollobj; collIndex++) @@ -950,8 +950,7 @@ static void update_obstacles(Scene *scene, Object *ob, SmokeDomainSettings *sds, } } - if (collobjs) - MEM_freeN(collobjs); + BKE_collision_objects_free(collobjs); /* obstacle cells should not contain any velocity from the smoke simulation */ for (z = 0; z < sds->res[0] * sds->res[1] * sds->res[2]; z++) @@ -2151,7 +2150,7 @@ static void update_flowsfluids( sds->p1[2] = sds->p0[2] + sds->cell_size[2] * sds->base_res[2]; } - flowobjs = get_collisionobjects(scene, ob, sds->fluid_group, &numflowobj, eModifierType_Smoke); + flowobjs = BKE_collision_objects_create(depsgraph, ob, sds->fluid_group, &numflowobj, eModifierType_Smoke); /* init emission maps for each flow */ emaps = MEM_callocN(sizeof(struct EmissionMap) * numflowobj, "smoke_flow_maps"); @@ -2452,8 +2451,7 @@ static void update_flowsfluids( } } - if (flowobjs) - MEM_freeN(flowobjs); + BKE_collision_objects_free(flowobjs); if (emaps) MEM_freeN(emaps); } @@ -2533,7 +2531,7 @@ static void update_effectors(struct Depsgraph *depsgraph, Scene *scene, Object * ListBase *effectors; /* make sure smoke flow influence is 0.0f */ sds->effector_weights->weight[PFIELD_SMOKEFLOW] = 0.0f; - effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, sds->effector_weights); + effectors = BKE_effectors_create(depsgraph, ob, NULL, sds->effector_weights); if (effectors) { // precalculate wind forces @@ -2636,7 +2634,7 @@ static void step( { // calc animated obstacle velocities update_flowsfluids(depsgraph, scene, ob, sds, dtSubdiv); - update_obstacles(scene, ob, sds, dtSubdiv, substep, totalSubsteps); + update_obstacles(depsgraph, ob, sds, dtSubdiv, substep, totalSubsteps); if (sds->total_cells > 1) { update_effectors(depsgraph, scene, ob, sds, dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index c552bfeb0dc..7a8dbeed031 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -1522,7 +1522,7 @@ static void scan_for_ext_spring_forces(struct Depsgraph *depsgraph, Scene *scene { SoftBody *sb = ob->soft; - ListBase *effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, sb->effector_weights); + ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, sb->effector_weights); _scan_for_ext_spring_forces(scene, ob, timenow, 0, sb->totspring, effectors); BKE_effectors_free(effectors); } @@ -1541,7 +1541,7 @@ static void sb_sfesf_threads_run(struct Depsgraph *depsgraph, Scene *scene, stru int i, totthread, left, dec; int lowsprings =100; /* wild guess .. may increase with better thread management 'above' or even be UI option sb->spawn_cf_threads_nopts */ - ListBase *effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, ob->soft->effector_weights); + ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, ob->soft->effector_weights); /* figure the number of threads while preventing pretty pointless threading overhead */ totthread= BKE_scene_num_threads(scene); @@ -2226,7 +2226,7 @@ static void softbody_calc_forcesEx(struct Depsgraph *depsgraph, Scene *scene, Ob sb_sfesf_threads_run(depsgraph, scene, ob, timenow, sb->totspring, NULL); /* after spring scan because it uses Effoctors too */ - ListBase *effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, sb->effector_weights); + ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, sb->effector_weights); if (do_deflector) { float defforce[3]; @@ -2287,7 +2287,7 @@ static void softbody_calc_forces(struct Depsgraph *depsgraph, Scene *scene, Obje if (do_springcollision || do_aero) scan_for_ext_spring_forces(depsgraph, scene, ob, timenow); /* after spring scan because it uses Effoctors too */ - ListBase *effectors = BKE_effectors_create(depsgraph, scene, ob, NULL, ob->soft->effector_weights); + ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, ob->soft->effector_weights); if (do_deflector) { float defforce[3]; -- cgit v1.2.3