I am using raycasting to place objects into the world. Besides a few checks based on the ray, I would like to do full collision detection to make sure that the resulting StaticMesh does not collide with any existing objects. BEPU obviously has this collision information somewhere, so I was wondering if it can expose it somehow. Given and input StaticMesh and a Transform, I would like to see if the resulting geometry intersects the world.
I could do this manually, but surely BEPU has some more advanced spatial partitioning schemes behind the curtains. This needs to be fast enough to execute on mouse move.
Is there support for collision queries?
Re: Is there support for collision queries?
There's a few ways to do it.
1) Put the object in the space so that the collision detection pipeline will create contacts for you, and then analyze the contacts by cycling through the query collidable's Pairs list. Each Pair has a Contacts list. If there is a contact with nonnegative penetration depth in that contacts list, they are touching. For contacts to update with this approach, a full Space.Update must run (so the query process would be spread out over more than one frame).
2) Use the Space.BroadPhase.QueryAccelerator.GetEntries method with the query collidable's bounding box to grab a set of candidates. Create collision pairs between these candidates and the query collidable. Update their contact listings and examine the results. The CharacterController's QueryManager.QueryContacts does something similar; check it out for an example of handling pair creation and updating properly. (The QueryContacts method uses the collidables available from the character's enlarged bounding box as opposed to a broadphase query, but that's a minor difference.)
3) Use the NarrowPhaseHelper.IsIntersecting method along with the broadphase query to find candidates. This does some of the work for you, but gives you less information than the character controller QueryContacts style approach.
1) Put the object in the space so that the collision detection pipeline will create contacts for you, and then analyze the contacts by cycling through the query collidable's Pairs list. Each Pair has a Contacts list. If there is a contact with nonnegative penetration depth in that contacts list, they are touching. For contacts to update with this approach, a full Space.Update must run (so the query process would be spread out over more than one frame).
2) Use the Space.BroadPhase.QueryAccelerator.GetEntries method with the query collidable's bounding box to grab a set of candidates. Create collision pairs between these candidates and the query collidable. Update their contact listings and examine the results. The CharacterController's QueryManager.QueryContacts does something similar; check it out for an example of handling pair creation and updating properly. (The QueryContacts method uses the collidables available from the character's enlarged bounding box as opposed to a broadphase query, but that's a minor difference.)
3) Use the NarrowPhaseHelper.IsIntersecting method along with the broadphase query to find candidates. This does some of the work for you, but gives you less information than the character controller QueryContacts style approach.
-
- Posts: 38
- Joined: Mon Aug 20, 2012 10:33 am
Re: Is there support for collision queries?
I tried number 3, but I'm not sure how to build the collision pair. I used a cast, but NarrowPhaseHelper.Intersecting gives me a null pointer exception. The StaticMesh is not added to the space.
Sorry for the sketchy details, but CharacterController is too advanced for me currently. It is going to be very hard to add two leg based walking to it and I need to study it a lot.
Code: Select all
StaticMesh mod = new StaticMesh(game.meshes[I].physVer[0], game.meshes[I].physInd[0], t);
List<BroadPhaseEntry> overlaps = new List<BroadPhaseEntry>();
game.space.BroadPhase.QueryAccelerator.GetEntries(mod.BoundingBox, overlaps);
foreach (BroadPhaseEntry b in overlaps) {
CollidablePair pair = new CollidablePair((Collidable)b, mod);
if (NarrowPhaseHelper.Intersecting(ref pair)) {
//insertion not possible
}
}
Re: Is there support for collision queries?
Not all possible pairs have associated pair handlers. Trying to intersect them with that method can trigger a null exception because no pair could be created.
Specifically, static objects cannot generate pairs with other static objects. There exist no pair handlers between those types. If you'd like to verify the placement of a StaticMesh against other StaticMeshes, use a mobile mesh as the query object. Mobile mesh collidables can generate pairs with static meshes and all other standard types.
Specifically, static objects cannot generate pairs with other static objects. There exist no pair handlers between those types. If you'd like to verify the placement of a StaticMesh against other StaticMeshes, use a mobile mesh as the query object. Mobile mesh collidables can generate pairs with static meshes and all other standard types.