Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/softbody.c
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_group_types.h" | #include "DNA_group_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BKE_collection.h" | |||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_group.h" | |||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_softbody.h" | #include "BKE_softbody.h" | ||||
| #include "BKE_pointcache.h" | #include "BKE_pointcache.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| ▲ Show 20 Lines • Show All 423 Lines • ▼ Show 20 Lines | if (ob->pd && ob->pd->deflect) { | ||||
| if (!BLI_ghash_ensure_p(hash, ob, &val_p)) { | if (!BLI_ghash_ensure_p(hash, ob, &val_p)) { | ||||
| ccd_Mesh *ccdmesh = ccd_mesh_make(ob); | ccd_Mesh *ccdmesh = ccd_mesh_make(ob); | ||||
| *val_p = ccdmesh; | *val_p = ccdmesh; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * \note group overrides scene when not NULL. | * \note collection overrides scene when not NULL. | ||||
| */ | */ | ||||
| static void ccd_build_deflector_hash(ViewLayer *view_layer, Group *group, Object *vertexowner, GHash *hash) | static void ccd_build_deflector_hash(ViewLayer *view_layer, Collection *collection, Object *vertexowner, GHash *hash) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| if (!hash) return; | if (!hash) return; | ||||
| /* Explicit collision group. */ | /* Explicit collision collection. */ | ||||
| if (group) { | Base *base = BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection); | ||||
| view_layer = group->view_layer; | |||||
| } | |||||
| for (Base *base = FIRSTBASE(view_layer); base; base = base->next) { | for (; base; base = base->next) { | ||||
| /* Only proceed for mesh object in same layer. */ | /* Only proceed for mesh object in same layer. */ | ||||
| if (base->object->type == OB_MESH) { | if (base->object->type == OB_MESH) { | ||||
| ob = base->object; | ob = base->object; | ||||
| if (ob == vertexowner) { | if (ob == vertexowner) { | ||||
| /* If vertexowner is given we don't want to check collision with owner object. */ | /* If vertexowner is given we don't want to check collision with owner object. */ | ||||
| continue; | continue; | ||||
| } | } | ||||
| ccd_build_deflector_hash_single(hash, ob); | ccd_build_deflector_hash_single(hash, ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void ccd_update_deflector_hash_single(GHash *hash, Object *ob) | static void ccd_update_deflector_hash_single(GHash *hash, Object *ob) | ||||
| { | { | ||||
| if (ob->pd && ob->pd->deflect) { | if (ob->pd && ob->pd->deflect) { | ||||
| ccd_Mesh *ccdmesh = BLI_ghash_lookup(hash, ob); | ccd_Mesh *ccdmesh = BLI_ghash_lookup(hash, ob); | ||||
| if (ccdmesh) { | if (ccdmesh) { | ||||
| ccd_mesh_update(ob, ccdmesh); | ccd_mesh_update(ob, ccdmesh); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * \note group overrides scene when not NULL. | * \note collection overrides scene when not NULL. | ||||
| */ | */ | ||||
| static void ccd_update_deflector_hash(ViewLayer *view_layer, Group *group, Object *vertexowner, GHash *hash) | static void ccd_update_deflector_hash(ViewLayer *view_layer, Collection *collection, Object *vertexowner, GHash *hash) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| if ((!hash) || (!vertexowner)) return; | if ((!hash) || (!vertexowner)) return; | ||||
| /* Explicit collision group. */ | /* Explicit collision collection. */ | ||||
| if (group) { | Base *base = BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection); | ||||
| view_layer = group->view_layer; | |||||
| } | |||||
| for (Base *base = FIRSTBASE(view_layer); base; base = base->next) { | for (; base; base = base->next) { | ||||
| /* Only proceed for mesh object in same layer. */ | /* Only proceed for mesh object in same layer. */ | ||||
| if (base->object->type == OB_MESH) { | if (base->object->type == OB_MESH) { | ||||
| ob = base->object; | ob = base->object; | ||||
| if (ob == vertexowner) { | if (ob == vertexowner) { | ||||
| /* If vertexowner is given we don't want to check collision with owner object. */ | /* If vertexowner is given we don't want to check collision with owner object. */ | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | |||||
| ** unless sbObjectStep( .. ) is called on sub frame timing level | ** unless sbObjectStep( .. ) is called on sub frame timing level | ||||
| ** BTW that also questions the use of a 'implicit' solvers on softbodies | ** BTW that also questions the use of a 'implicit' solvers on softbodies | ||||
| ** since that would only valid for 'slow' moving collision targets and dito particles | ** since that would only valid for 'slow' moving collision targets and dito particles | ||||
| */ | */ | ||||
| /* +++ dependency information functions*/ | /* +++ dependency information functions*/ | ||||
| /** | /** | ||||
| * \note group overrides scene when not NULL. | * \note collection overrides scene when not NULL. | ||||
| */ | */ | ||||
| static bool are_there_deflectors(ViewLayer *view_layer) | static bool are_there_deflectors(Base *first_base) | ||||
| { | { | ||||
| for (Base *base = FIRSTBASE(view_layer); base; base = base->next) { | for (Base *base = first_base; base; base = base->next) { | ||||
| if (base->object->pd) { | if (base->object->pd) { | ||||
| if (base->object->pd->deflect) | if (base->object->pd->deflect) | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static int query_external_colliders(ViewLayer *view_layer, Group *group) | static int query_external_colliders(ViewLayer *view_layer, Collection *collection) | ||||
| { | { | ||||
| return(are_there_deflectors(group != NULL ? group->view_layer : view_layer)); | return(are_there_deflectors(BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection))); | ||||
| } | } | ||||
| /* --- dependency information functions*/ | /* --- dependency information functions*/ | ||||
| /* +++ the aabb "force" section*/ | /* +++ the aabb "force" section*/ | ||||
| static int sb_detect_aabb_collisionCached(float UNUSED(force[3]), unsigned int UNUSED(par_layer), struct Object *vertexowner, float UNUSED(time)) | static int sb_detect_aabb_collisionCached(float UNUSED(force[3]), unsigned int UNUSED(par_layer), struct Object *vertexowner, float UNUSED(time)) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| ▲ Show 20 Lines • Show All 2,758 Lines • Show Last 20 Lines | |||||