Change collision filters

Post Reply
PaulMartz
Posts: 28
Joined: Mon Jun 02, 2008 7:21 pm

Change collision filters

Post by PaulMartz »

Can anyone tell me how to change collision filters?

I've tried setting the new filter group and filter mask directly in the BroadphaseHandle of the rigid body, but this doesn't appear to have any effect. I suppose I could remove the rigid body from the simultation and add it again with new filter group and filter mask, but this seems inelegant.

Any help would be appreciated.
-Paul
PaulMartz
Posts: 28
Joined: Mon Jun 02, 2008 7:21 pm

Re: Change collision filters

Post by PaulMartz »

Hm. I figured out why setting the filters in the broadphase proxy didn't work, sort of...

The body was part of a slider constraint, and I was using the filters to avoid collisions between the two constrained bodies. When I disabled the constraiont (with setDisable(false)), then setting the filters in the broadphase proxy had no effect.

However, if I actually removed the constraint from the simulation, then changing the filters in the broadphase proxy did work.

Can I assume from this that the constraint is keeping a second copy of the collision filters somewhere? Ideally, I'd like to change the filters without removing the constraint; I want to keep it in the simultation so I can re-enable it later.

Thanks,
-Paul
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: Change collision filters

Post by dphil »

I believe you are supposed to remove and re-add a body for which you are changing collision masks. That is what I do in my code. Granted if it's part of a constraint, it's slightly trickier, as you'd have to detach and re-enable that too. I suppose it might not always be necessary to remove/re-add the body, as in your case removing the constraint it was a part of seemed to work. I don't know if that's a recommended or reliable solution though.
PaulMartz
Posts: 28
Joined: Mon Jun 02, 2008 7:21 pm

Re: Change collision filters

Post by PaulMartz »

Thanks for the info. If I have to remove things, and re-add the bodies, then I'll re-work my code to accomodate that.
-Paul
VicariousEnt
Posts: 50
Joined: Fri Oct 29, 2010 1:37 am

Re: Change collision filters

Post by VicariousEnt »

Yeah I just had to do the same thing. Remove the RB and re-add it to the simulation world, thats all you have to do, even if it is constrained to something else. Those functions don't check dependencies so it doesn't matter if its constrained. Suprisingly doing this during runtime hasn't caused any issues, noticable overhead or hitchs for me.
20k
Posts: 1
Joined: Tue Aug 23, 2016 5:02 pm

Re: Change collision filters

Post by 20k »

This is an old thread, but still the top result for "bullet physics change group" on google, so I'll post my findings

Using the above method of removing/adding an object to a scene seems to cause a one frame stutter (while also swapping from kinematic <-> dynamic) for that body that's difficult to notice. I never would have spotted it if I wasn't using this for real time motion control interaction, where the stutter was just perceptually noticeable when changing group while interacting with an object (leap motion hands)

I instead use

btBroadphaseProxy* proxy = body->getBroadphaseProxy();
proxy->m_collisionFilterGroup = group;
proxy->m_collisionFilterMask = collidesWithMask;

This fixes my issue
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Change collision filters

Post by benelot »

One guy on the forum did this by inheriting from btCollisionDispatcher and overwriting needsCollision and needsResponse. And returning false or calling the base implementation whether a check is needed between two bodies or not.
Post Reply