Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/collision.c
| Show All 40 Lines | |||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_edgehash.h" | #include "BLI_edgehash.h" | ||||
| #include "BKE_cloth.h" | #include "BKE_cloth.h" | ||||
| #include "BKE_collection.h" | |||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_group.h" | |||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #ifdef WITH_BULLET | #ifdef WITH_BULLET | ||||
| #include "Bullet-C-Api.h" | #include "Bullet-C-Api.h" | ||||
| #endif | #endif | ||||
| #include "BLI_kdopbvh.h" | #include "BLI_kdopbvh.h" | ||||
| ▲ Show 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | if (cmd) { | ||||
| } | } | ||||
| (*objs)[*numobj] = ob; | (*objs)[*numobj] = ob; | ||||
| (*numobj)++; | (*numobj)++; | ||||
| } | } | ||||
| /* objects in dupli groups, one level only for now */ | /* objects in dupli groups, one level only for now */ | ||||
| if (ob->dup_group && level == 0) { | if (ob->dup_group && level == 0) { | ||||
| Group *group= ob->dup_group; | Collection *collection= ob->dup_group; | ||||
| /* add objects */ | /* add objects */ | ||||
| FOREACH_GROUP_OBJECT_BEGIN(group, object) | FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) | ||||
| { | { | ||||
| add_collision_object(objs, numobj, maxobj, object, self, level+1, modifier_type); | add_collision_object(objs, numobj, maxobj, object, self, level+1, modifier_type); | ||||
| } | } | ||||
| FOREACH_GROUP_OBJECT_END; | FOREACH_COLLECTION_OBJECT_RECURSIVE_END; | ||||
| } | } | ||||
| } | } | ||||
| // return all collision objects in scene | // return all collision objects in scene | ||||
| // collision object will exclude self | // collision object will exclude self | ||||
| Object **get_collisionobjects_ext(Scene *scene, Object *self, Group *group, unsigned int *numcollobj, unsigned int modifier_type, bool dupli) | Object **get_collisionobjects_ext(Scene *scene, Object *self, Collection *collection, unsigned int *numcollobj, unsigned int modifier_type, bool dupli) | ||||
| { | { | ||||
| Object **objs; | Object **objs; | ||||
| unsigned int numobj= 0, maxobj= 100; | unsigned int numobj= 0, maxobj= 100; | ||||
| int level = dupli ? 0 : 1; | int level = dupli ? 0 : 1; | ||||
| objs= MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); | objs= MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray"); | ||||
| /* gather all collision objects */ | /* gather all collision objects */ | ||||
| if (group) { | if (collection) { | ||||
| /* use specified group */ | /* use specified collection */ | ||||
| FOREACH_GROUP_OBJECT_BEGIN(group, object) | FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) | ||||
| { | { | ||||
| add_collision_object(&objs, &numobj, &maxobj, object, self, level, modifier_type); | add_collision_object(&objs, &numobj, &maxobj, object, self, level, modifier_type); | ||||
| } | } | ||||
| FOREACH_GROUP_OBJECT_END; | FOREACH_COLLECTION_OBJECT_RECURSIVE_END; | ||||
| } | } | ||||
| else { | else { | ||||
| Scene *sce_iter; | Scene *sce_iter; | ||||
| Base *base; | Base *base; | ||||
| /* add objects in same layer in scene */ | /* add objects in same layer in scene */ | ||||
| for (SETLOOPER(scene, sce_iter, base)) { | for (SETLOOPER(scene, sce_iter, base)) { | ||||
| if ((base->flag & BASE_VISIBLED) != 0) { | if ((base->flag & BASE_VISIBLED) != 0) { | ||||
| add_collision_object(&objs, &numobj, &maxobj, base->object, self, level, modifier_type); | add_collision_object(&objs, &numobj, &maxobj, base->object, self, level, modifier_type); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| *numcollobj= numobj; | *numcollobj= numobj; | ||||
| return objs; | return objs; | ||||
| } | } | ||||
| Object **get_collisionobjects(Scene *scene, Object *self, Group *group, unsigned int *numcollobj, unsigned int modifier_type) | Object **get_collisionobjects(Scene *scene, Object *self, Collection *collection, unsigned int *numcollobj, unsigned int modifier_type) | ||||
| { | { | ||||
| /* Need to check for active layers, too. | /* Need to check for active layers, too. | ||||
| Otherwise this check fails if the objects are not on the same layer - DG */ | Otherwise this check fails if the objects are not on the same layer - DG */ | ||||
| return get_collisionobjects_ext(scene, self, group, numcollobj, modifier_type, true); | return get_collisionobjects_ext(scene, self, collection, numcollobj, modifier_type, true); | ||||
| } | } | ||||
| static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self, int level) | static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self, int level) | ||||
| { | { | ||||
| CollisionModifierData *cmd= NULL; | CollisionModifierData *cmd= NULL; | ||||
| ColliderCache *col; | ColliderCache *col; | ||||
| if (ob == self) | if (ob == self) | ||||
| Show All 9 Lines | if (cmd && cmd->bvhtree) { | ||||
| col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); | col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); | ||||
| col->ob = ob; | col->ob = ob; | ||||
| col->collmd = cmd; | col->collmd = cmd; | ||||
| /* make sure collider is properly set up */ | /* make sure collider is properly set up */ | ||||
| collision_move_object(cmd, 1.0, 0.0); | collision_move_object(cmd, 1.0, 0.0); | ||||
| BLI_addtail(*objs, col); | BLI_addtail(*objs, col); | ||||
| } | } | ||||
| /* objects in dupli groups, one level only for now */ | /* objects in dupli collection, one level only for now */ | ||||
| if (ob->dup_group && level == 0) { | if (ob->dup_group && level == 0) { | ||||
| Group *group= ob->dup_group; | Collection *collection= ob->dup_group; | ||||
| /* add objects */ | /* add objects */ | ||||
| FOREACH_GROUP_OBJECT_BEGIN(group, object) | FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) | ||||
| { | { | ||||
| add_collider_cache_object(objs, object, self, level+1); | add_collider_cache_object(objs, object, self, level+1); | ||||
| } | } | ||||
| FOREACH_GROUP_OBJECT_END; | FOREACH_COLLECTION_OBJECT_RECURSIVE_END; | ||||
| } | } | ||||
| } | } | ||||
| ListBase *get_collider_cache(Scene *scene, Object *self, Group *group) | ListBase *get_collider_cache(Scene *scene, Object *self, Collection *collection) | ||||
| { | { | ||||
| ListBase *objs= NULL; | ListBase *objs= NULL; | ||||
| /* add object in same layer in scene */ | /* add object in same layer in scene */ | ||||
| if (group) { | if (collection) { | ||||
| FOREACH_GROUP_OBJECT_BEGIN(group, object) | FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) | ||||
| { | { | ||||
| add_collider_cache_object(&objs, object, self, 0); | add_collider_cache_object(&objs, object, self, 0); | ||||
| } | } | ||||
| FOREACH_GROUP_OBJECT_END; | FOREACH_COLLECTION_OBJECT_RECURSIVE_END; | ||||
| } | } | ||||
| else { | else { | ||||
| Scene *sce_iter; | Scene *sce_iter; | ||||
| Base *base; | Base *base; | ||||
| /* add objects in same layer in scene */ | /* add objects in same layer in scene */ | ||||
| for (SETLOOPER(scene, sce_iter, base)) { | for (SETLOOPER(scene, sce_iter, base)) { | ||||
| if (!self || ((base->flag & BASE_VISIBLED) != 0)) | if (!self || ((base->flag & BASE_VISIBLED) != 0)) | ||||
| ▲ Show 20 Lines • Show All 849 Lines • Show Last 20 Lines | |||||