Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/collision.c
| Show First 20 Lines • Show All 462 Lines • ▼ Show 20 Lines | else { | ||||
| collpair->flag |= COLLISION_IN_FUTURE; | collpair->flag |= COLLISION_IN_FUTURE; | ||||
| collpair++; | collpair++; | ||||
| } | } | ||||
| }*/ | }*/ | ||||
| } | } | ||||
| return collpair; | 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(Object ***objs, unsigned int *numobj, unsigned int *maxobj, Object *ob, Object *self, int level, unsigned int modifier_type, CollobjFilterFunction fn) | ||||
| { | { | ||||
| CollisionModifierData *cmd= NULL; | ModifierData *cmd= NULL; | ||||
| if (ob == self) | if (ob == self) | ||||
| return; | return; | ||||
| /* only get objects with collision modifier */ | /* only get objects with collision modifier */ | ||||
| if (((modifier_type == eModifierType_Collision) && ob->pd && ob->pd->deflect) || (modifier_type != eModifierType_Collision)) | if (((modifier_type == eModifierType_Collision) && ob->pd && ob->pd->deflect) || (modifier_type != eModifierType_Collision)) | ||||
| cmd= (CollisionModifierData *)modifiers_findByType(ob, modifier_type); | cmd = modifiers_findByType(ob, modifier_type); | ||||
| if (cmd) { | if (cmd && (fn == NULL || fn(ob, cmd))) { | ||||
| /* extend array */ | /* extend array */ | ||||
| if (*numobj >= *maxobj) { | if (*numobj >= *maxobj) { | ||||
| *maxobj *= 2; | *maxobj *= 2; | ||||
| *objs= MEM_reallocN(*objs, sizeof(Object *)*(*maxobj)); | *objs= MEM_reallocN(*objs, sizeof(Object *)*(*maxobj)); | ||||
| } | } | ||||
| (*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) { | ||||
| GroupObject *go; | GroupObject *go; | ||||
| Group *group= ob->dup_group; | Group *group= ob->dup_group; | ||||
| /* add objects */ | /* add objects */ | ||||
| for (go= group->gobject.first; go; go= go->next) | for (go= group->gobject.first; go; go= go->next) | ||||
| add_collision_object(objs, numobj, maxobj, go->ob, self, level+1, modifier_type); | add_collision_object(objs, numobj, maxobj, go->ob, self, level+1, modifier_type, fn); | ||||
| } | } | ||||
| } | } | ||||
| // 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(Scene *scene, Object *self, Group *group, unsigned int *numcollobj, unsigned int modifier_type) | Object **get_filtered_collisionobjects(Scene *scene, Object *self, Group *group, int layer, unsigned int *numcollobj, unsigned int modifier_type, CollobjFilterFunction fn, bool dupli) | ||||
| { | { | ||||
| Base *base; | Base *base; | ||||
| Object **objs; | Object **objs; | ||||
| GroupObject *go; | GroupObject *go; | ||||
| unsigned int numobj= 0, maxobj= 100; | unsigned int numobj= 0, maxobj= 100; | ||||
| 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 (group) { | ||||
| /* use specified group */ | /* use specified group */ | ||||
| for (go= group->gobject.first; go; go= go->next) | for (go= group->gobject.first; go; go= go->next) | ||||
| add_collision_object(&objs, &numobj, &maxobj, go->ob, self, 0, modifier_type); | add_collision_object(&objs, &numobj, &maxobj, go->ob, self, level, modifier_type, fn); | ||||
| } | } | ||||
| else { | else { | ||||
| Scene *sce_iter; | Scene *sce_iter; | ||||
| /* 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)) { | ||||
| /* Need to check for active layers, too. | if ( base->lay & layer ) | ||||
| Otherwise this check fails if the objects are not on the same layer - DG */ | add_collision_object(&objs, &numobj, &maxobj, base->object, self, level, modifier_type, fn); | ||||
| if ((base->lay & self->lay) || (base->lay & scene->lay)) | |||||
| add_collision_object(&objs, &numobj, &maxobj, base->object, self, 0, 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) | |||||
| { | |||||
| /* Need to check for active layers, too. | |||||
| Otherwise this check fails if the objects are not on the same layer - DG */ | |||||
| return get_filtered_collisionobjects(scene, self, group, self->lay | scene->lay, numcollobj, modifier_type, NULL, 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) | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 890 Lines • Show Last 20 Lines | |||||