-
I'm trying to use a To give a more concrete example, say I have a In theory it seems like this should be possible, considering the signature of I set up the above mentioned scenario as a Is there a bug here or am I doing something wrong, or is there perhaps some other way to go about this? I would expect to see this: CastShapeTest_Expected.mp4But instead I end up seeing this: CastShapeTest_Actual.mp4(The video with the expected outcome was achieved by swapping the order of the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I've been successfully using that functionality quite extensively, my code looks like this: bool XShapeFilter::ShouldCollide(const JPH::SubShapeID& inSubShapeID2) const
{
if (inSubShapeID2.IsEmpty()) {
return true;
}
JPH::BodyLockWrite lock(BodyLockInterface, mBodyID2);
if (lock.Succeeded()) {
const JPH::Body* body = &lock.GetBody();
if (size_t userdata = body->GetShape()->GetSubShapeUserData(inSubShapeID2)) {
const XCompoundChildShape* childshape = reinterpret_cast<const XCompoundChildShape*>(userdata);
// a bunch of code that checks whether the filter properties allow collisions with this child chape
}
return true;
}
return false;
}
bool XShapeFilter::ShouldCollide(const JPH::SubShapeID& inSubShapeID1, const JPH::SubShapeID& inSubShapeID2) const
{
return ShouldCollide(inSubShapeID1) && ShouldCollide(inSubShapeID2);
} |
Beta Was this translation helpful? Give feedback.
-
Hello, There's indeed a problem here. We call ShouldCollide at every level in the hierarchy, so for a compound with a box you'll get 2 callbacks. The problem is that you currently cannot determine if you're at the compound stage or at the box stage. The SubShape ID is basically a string of bits where at each level some bits are pushed in from the right. The compound shape has 2 shapes, meaning it uses 1 bit.
So you see you cannot distinguish the compound from the box. I could reserve an extra bit for the compound shape but we're already really short on bits. I think the best alternative is to pass in the shapes to the ShouldCollide filter so that you can check if you're at a leaf shape or not (see #474). The thing I don't like about the solution is that now you have a sub shape ID that doesn't belong to the shape that's being passed in, but tracking the relative sub shape ID is going to be costly. With this change you can change your code to:
Oh and b.t.w. thanks for the demo, this makes debugging so much easier! |
Beta Was this translation helpful? Give feedback.
Hello,
There's indeed a problem here. We call ShouldCollide at every level in the hierarchy, so for a compound with a box you'll get 2 callbacks. The problem is that you currently cannot determine if you're at the compound stage or at the box stage. The SubShape ID is basically a string of bits where at each level some bits are pushed in from the right. The compound shape has 2 shapes, meaning it uses 1 bit.