diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-25 17:04:56 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-25 18:15:07 +0300 |
commit | 2c9b32949bc00e73603bcabadb74e5b3176a161a (patch) | |
tree | f6bb1ee5b514cce92db337c3116ac967821a4c65 /source/blender/depsgraph/intern/depsgraph_physics.cc | |
parent | 26251282e093d4c0d04c4c667b0b32ad66d329b2 (diff) |
Cleanup: refactor depsgraph physics API functions.
Diffstat (limited to 'source/blender/depsgraph/intern/depsgraph_physics.cc')
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_physics.cc | 176 |
1 files changed, 125 insertions, 51 deletions
diff --git a/source/blender/depsgraph/intern/depsgraph_physics.cc b/source/blender/depsgraph/intern/depsgraph_physics.cc index ba42ef96365..2745a6c8722 100644 --- a/source/blender/depsgraph/intern/depsgraph_physics.cc +++ b/source/blender/depsgraph/intern/depsgraph_physics.cc @@ -31,55 +31,132 @@ #include "BLI_compiler_compat.h" #include "BLI_ghash.h" +#include "BLI_listbase.h" extern "C" { #include "BKE_collision.h" #include "BKE_effect.h" +#include "BKE_modifier.h" } /* extern "C" */ #include "DNA_group_types.h" +#include "DNA_object_force_types.h" +#include "DEG_depsgraph_build.h" #include "DEG_depsgraph_physics.h" #include "depsgraph.h" #include "depsgraph_intern.h" -/************************ Public API *************************/ +/*********************** Evaluation Query API *************************/ + +static ePhysicsRelationType modifier_to_relation_type(unsigned int modifier_type) +{ + switch (modifier_type) { + case eModifierType_Collision: + return DEG_PHYSICS_COLLISION; + case eModifierType_Smoke: + return DEG_PHYSICS_SMOKE_COLLISION; + case eModifierType_DynamicPaint: + return DEG_PHYSICS_DYNAMIC_BRUSH; + }; + + BLI_assert(!"Unknown collision modifier type"); + return DEG_PHYSICS_RELATIONS_NUM; +} ListBase *DEG_get_effector_relations(const Depsgraph *graph, Collection *collection) { const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); - if (deg_graph->effector_relations == NULL) { + if (deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] == NULL) { return NULL; } - return (ListBase *)BLI_ghash_lookup(deg_graph->effector_relations, collection); + return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR], collection); } ListBase *DEG_get_collision_relations(const Depsgraph *graph, - Collection *collection) + Collection *collection, + unsigned int modifier_type) { const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); - if (deg_graph->collision_relations == NULL) { + const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); + if (deg_graph->physics_relations[type] == NULL) { return NULL; } - return (ListBase*)BLI_ghash_lookup(deg_graph->collision_relations, collection); + return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[type], collection); } -ListBase *DEG_get_smoke_collision_relations(const Depsgraph *graph, - Collection *collection) +/********************** Depsgraph Building API ************************/ + +void DEG_add_collision_relations(DepsNodeHandle *handle, + Object *object, + Collection *collection, + unsigned int modifier_type, + DEG_CollobjFilterFunction fn, + const char *name) { - const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); - if (deg_graph->smoke_collision_relations == NULL) { - return NULL; + Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); + DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; + ListBase *relations = deg_build_collision_relations(deg_graph, collection, modifier_type); + + LISTBASE_FOREACH (CollisionRelation *, relation, relations) { + Object *ob1 = relation->ob; + if (ob1 != object) { + if (!fn || fn(ob1, modifiers_findByType(ob1, (ModifierType)modifier_type))) { + DEG_add_object_relation(handle, ob1, DEG_OB_COMP_TRANSFORM, name); + DEG_add_object_relation(handle, ob1, DEG_OB_COMP_GEOMETRY, name); + } + } } +} - return (ListBase*)BLI_ghash_lookup(deg_graph->smoke_collision_relations, collection); +void DEG_add_forcefield_relations(DepsNodeHandle *handle, + Object *object, + EffectorWeights *effector_weights, + bool add_absorption, + int skip_forcefield, + const char *name) +{ + Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); + DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; + ListBase *relations = deg_build_effector_relations(deg_graph, effector_weights->group); + + LISTBASE_FOREACH (EffectorRelation *, relation, relations) { + if (relation->ob != object && relation->pd->forcefield != skip_forcefield) { + DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_TRANSFORM, name); + if (relation->psys) { + DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_EVAL_PARTICLES, name); + /* TODO: remove this when/if EVAL_PARTICLES is sufficient + * for up to date particles. + */ + DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_GEOMETRY, name); + } + if (relation->pd->forcefield == PFIELD_SMOKEFLOW && relation->pd->f_source) { + DEG_add_object_relation(handle, + relation->pd->f_source, + DEG_OB_COMP_TRANSFORM, + "Smoke Force Domain"); + DEG_add_object_relation(handle, + relation->pd->f_source, + DEG_OB_COMP_GEOMETRY, + "Smoke Force Domain"); + } + if (add_absorption && (relation->pd->flag & PFIELD_VISIBILITY)) { + DEG_add_collision_relations(handle, + object, + NULL, + eModifierType_Collision, + NULL, + "Force Absorption"); + } + } + } } -/*********************** Internal API ************************/ +/**************************** Internal API ****************************/ namespace DEG { @@ -87,49 +164,38 @@ namespace DEG ListBase *deg_build_effector_relations(Depsgraph *graph, Collection *collection) { - if (graph->effector_relations == NULL) { - graph->effector_relations = BLI_ghash_ptr_new("Depsgraph effector relations hash"); + GHash *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; + if (hash == NULL) { + graph->physics_relations[DEG_PHYSICS_EFFECTOR] = BLI_ghash_ptr_new("Depsgraph physics relations hash"); + hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; } - ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(graph->effector_relations, collection)); + ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection)); if (relations == NULL) { ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); relations = BKE_effector_relations_create(depsgraph, graph->view_layer, collection); - BLI_ghash_insert(graph->effector_relations, collection, relations); + BLI_ghash_insert(hash, collection, relations); } return relations; } ListBase *deg_build_collision_relations(Depsgraph *graph, - Collection *collection) + Collection *collection, + unsigned int modifier_type) { - if (graph->collision_relations == NULL) { - graph->collision_relations = BLI_ghash_ptr_new("Depsgraph collision relations hash"); + const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); + GHash *hash = graph->physics_relations[type]; + if (hash == NULL) { + graph->physics_relations[type] = BLI_ghash_ptr_new("Depsgraph physics relations hash"); + hash = graph->physics_relations[type]; } - ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(graph->collision_relations, collection)); + ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection)); if (relations == NULL) { ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); - relations = BKE_collision_relations_create(depsgraph, collection, eModifierType_Collision); - BLI_ghash_insert(graph->collision_relations, collection, relations); - } - - return relations; -} - -ListBase *deg_build_smoke_collision_relations(Depsgraph *graph, - Collection *collection) -{ - if (graph->smoke_collision_relations == NULL) { - graph->smoke_collision_relations = BLI_ghash_ptr_new("Depsgraph smoke collision relations hash"); - } - - ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(graph->smoke_collision_relations, collection)); - if (relations == NULL) { - ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); - relations = BKE_collision_relations_create(depsgraph, collection, eModifierType_Smoke); - BLI_ghash_insert(graph->smoke_collision_relations, collection, relations); + relations = BKE_collision_relations_create(depsgraph, collection, modifier_type); + BLI_ghash_insert(hash, collection, relations); } return relations; @@ -147,17 +213,25 @@ static void free_collision_relations(void *value) void deg_clear_physics_relations(Depsgraph *graph) { - if (graph->collision_relations) { - BLI_ghash_free(graph->collision_relations, NULL, free_collision_relations); - graph->collision_relations = NULL; - } - if (graph->smoke_collision_relations) { - BLI_ghash_free(graph->smoke_collision_relations, NULL, free_collision_relations); - graph->smoke_collision_relations = NULL; - } - if (graph->effector_relations) { - BLI_ghash_free(graph->effector_relations, NULL, free_effector_relations); - graph->effector_relations = NULL; + for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) { + if (graph->physics_relations[i]) { + ePhysicsRelationType type = (ePhysicsRelationType)i; + + switch (type) { + case DEG_PHYSICS_EFFECTOR: + BLI_ghash_free(graph->physics_relations[i], NULL, free_effector_relations); + break; + case DEG_PHYSICS_COLLISION: + case DEG_PHYSICS_SMOKE_COLLISION: + case DEG_PHYSICS_DYNAMIC_BRUSH: + BLI_ghash_free(graph->physics_relations[i], NULL, free_collision_relations); + break; + case DEG_PHYSICS_RELATIONS_NUM: + break; + } + + graph->physics_relations[i] = NULL; + } } } |