Get the index of child shape on btGImpactShape collision.

Post Reply
cuckon
Posts: 3
Joined: Sun Mar 04, 2012 4:54 pm

Get the index of child shape on btGImpactShape collision.

Post by cuckon »

Hi all, bullet can get index of child shape of common convex compoundshape by extracting m_index0 and m_index1 from btManifoldPoint (as being done in the App_FractureDemo), but when the shape is btGImpactShape, what I get is the triangle id, instead of child id. And I could not find an easy to retrieve the right child index :( :(

Help please!
Bock
Posts: 4
Joined: Thu Sep 27, 2012 3:31 pm

Re: Get the index of child shape on btGImpactShape collision

Post by Bock »

Has this been solved by anyone?

I am trying to derive user parameters (game material, etc.) from collision callback and running into similar issue.
It feels like the part/index passing mechanism is unfinished as it appears inconsistent.

Providing callstack below to help understand what kind of shapes/algorithms are involved.

(A). Sphere vs btBvhTriangleMeshShape:
- Receiving part index (not sure of the exact wording here) which seems to correspond to the addIndexedMesh() calls order
- Receiving triangle index in 'index0'/'index1'
I am happy with that!

Code: Select all

>	wip.exe!`MyHitCallback::addSingleResult(btManifoldPoint & pt, const btCollisionObject * colObj0, int partId0, int index0, const btCollisionObject * colObj1, int partId1, int index1)  Line 832	C++
 	wip.exe!btBridgedManifoldResult::addContactPoint(const btVector3 & normalOnBInWorld, const btVector3 & pointInWorld, float depth)  Line 1095 + 0x4a bytes	C++
 	wip.exe!SphereTriangleDetector::getClosestPoints(const btDiscreteCollisionDetectorInterface::ClosestPointInput & input, btDiscreteCollisionDetectorInterface::Result & output, btIDebugDraw * debugDraw, bool swapResults)  Line 58	C++
 	wip.exe!btSphereTriangleCollisionAlgorithm::processCollision(btCollisionObject * col0, btCollisionObject * col1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 70	C++
 	wip.exe!btConvexTriangleCallback::processTriangle(btVector3 * triangle, int partId, int triangleIndex)  Line 126	C++
 	wip.exe!`btBvhTriangleMeshShape::processAllTriangles'::`2'::MyNodeOverlapCallback::processNode(int nodeSubPart, int nodeTriangleIndex)  Line 316	C++
 	wip.exe!btQuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback * nodeCallback, unsigned short * quantizedQueryAabbMin, unsigned short * quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex)  Line 716	C++
 	wip.exe!btQuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback * nodeCallback, const btVector3 & aabbMin, const btVector3 & aabbMax)  Line 329	C++
 	wip.exe!btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback * callback, const btVector3 & aabbMin, const btVector3 & aabbMax)  Line 329	C++
 	wip.exe!btConvexConcaveCollisionAlgorithm::processCollision(btCollisionObject * body0, btCollisionObject * body1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 190	C++
 	wip.exe!btSingleContactCallback::process(const btBroadphaseProxy * proxy)  Line 1134	C++
 	wip.exe!BroadphaseAabbTester::Process(const btDbvtNode * leaf)  Line 265	C++
 	wip.exe!btDbvt::collideTV<BroadphaseAabbTester>(const btDbvtNode * root, const btDbvtAabbMm & vol, BroadphaseAabbTester & policy)  Line 941	C++
 	wip.exe!btDbvtBroadphase::aabbTest(const btVector3 & aabbMin, const btVector3 & aabbMax, btBroadphaseAabbCallback & aabbCallback)  Line 275	C++
 	wip.exe!btCollisionWorld::contactTest(btCollisionObject * colObj, btCollisionWorld::ContactResultCallback & resultCallback)  Line 1152	C++
(B). Sphere vs Compound Shape made of simple Shapes (not mesh)
- part is -1
- Receiving child shape index in 'index0'/'index1' - that's within the compound shape (not sure how it works with hierarchical shape, I have no hierarchy within my compound here).
Also happy with that.

Code: Select all

>	wip.exe!`MyHitCallback::addSingleResult(btManifoldPoint & pt, const btCollisionObject * colObj0, int partId0, int index0, const btCollisionObject * colObj1, int partId1, int index1)  Line 832	C++
 	wip.exe!btBridgedManifoldResult::addContactPoint(const btVector3 & normalOnBInWorld, const btVector3 & pointInWorld, float depth)  Line 1095 + 0x4a bytes	C++
 	wip.exe!btGjkPairDetector::getClosestPointsNonVirtual(const btDiscreteCollisionDetectorInterface::ClosestPointInput & input, btDiscreteCollisionDetectorInterface::Result & output, btIDebugDraw * debugDraw)  Line 452	C++
 	wip.exe!btGjkPairDetector::getClosestPoints(const btDiscreteCollisionDetectorInterface::ClosestPointInput & input, btDiscreteCollisionDetectorInterface::Result & output, btIDebugDraw * debugDraw, bool swapResults)  Line 77	C++
 	wip.exe!btConvexConvexAlgorithm::processCollision(btCollisionObject * body0, btCollisionObject * body1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 755	C++
 	wip.exe!btCompoundLeafCallback::ProcessChildShape(btCollisionShape * childShape, int index)  Line 156	C++
 	wip.exe!btCompoundLeafCallback::Process(const btDbvtNode * leaf)  Line 184	C++
 	wip.exe!btDbvt::collideTV<btCompoundLeafCallback>(const btDbvtNode * root, const btDbvtAabbMm & vol, btCompoundLeafCallback & policy)  Line 941	C++
 	wip.exe!btCompoundCollisionAlgorithm::processCollision(btCollisionObject * body0, btCollisionObject * body1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 254	C++
 	wip.exe!btSingleContactCallback::process(const btBroadphaseProxy * proxy)  Line 1134	C++
 	wip.exe!BroadphaseAabbTester::Process(const btDbvtNode * leaf)  Line 265	C++
 	wip.exe!btDbvt::collideTV<BroadphaseAabbTester>(const btDbvtNode * root, const btDbvtAabbMm & vol, BroadphaseAabbTester & policy)  Line 941	C++
 	wip.exe!btDbvtBroadphase::aabbTest(const btVector3 & aabbMin, const btVector3 & aabbMax, btBroadphaseAabbCallback & aabbCallback)  Line 275	C++
 	wip.exe!btCollisionWorld::contactTest(btCollisionObject * colObj, btCollisionWorld::ContactResultCallback & resultCallback)  Line 1152	C++
(C). But now, Sphere vs compound shape containing a btBvhTriangleMeshShape:
I get the same information as in A but no way to tell which collision shape within the compound shape has been hit. .
Within the callstack you can see btCompoundLeafCallback::ProcessChildShape(), which is storing the child shape index by calling 'm_resultOut->setShapeIdentifiersA(-1,index);' (or 'setShapeIdentifiersB') but as the point of digging within the triangle mesh that data is not passed through.

Code: Select all

>	wip.exe!`MyHitCallback::addSingleResult(btManifoldPoint & pt, const btCollisionObject * colObj0, int partId0, int index0, const btCollisionObject * colObj1, int partId1, int index1)  Line 832	C++
 	wip.exe!btBridgedManifoldResult::addContactPoint(const btVector3 & normalOnBInWorld, const btVector3 & pointInWorld, float depth)  Line 1095 + 0x4a bytes	C++
 	wip.exe!SphereTriangleDetector::getClosestPoints(const btDiscreteCollisionDetectorInterface::ClosestPointInput & input, btDiscreteCollisionDetectorInterface::Result & output, btIDebugDraw * debugDraw, bool swapResults)  Line 58	C++
 	wip.exe!btSphereTriangleCollisionAlgorithm::processCollision(btCollisionObject * col0, btCollisionObject * col1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 70	C++
 	wip.exe!btConvexTriangleCallback::processTriangle(btVector3 * triangle, int partId, int triangleIndex)  Line 126	C++
 	wip.exe!`btBvhTriangleMeshShape::processAllTriangles'::`2'::MyNodeOverlapCallback::processNode(int nodeSubPart, int nodeTriangleIndex)  Line 316	C++
 	wip.exe!btQuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback * nodeCallback, unsigned short * quantizedQueryAabbMin, unsigned short * quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex)  Line 716	C++
 	wip.exe!btQuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback * nodeCallback, const btVector3 & aabbMin, const btVector3 & aabbMax)  Line 329	C++
 	wip.exe!btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback * callback, const btVector3 & aabbMin, const btVector3 & aabbMax)  Line 329	C++
 	wip.exe!btConvexConcaveCollisionAlgorithm::processCollision(btCollisionObject * body0, btCollisionObject * body1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 190	C++
 	wip.exe!btCompoundLeafCallback::ProcessChildShape(btCollisionShape * childShape, int index)  Line 156	C++
 	wip.exe!btCompoundLeafCallback::Process(const btDbvtNode * leaf)  Line 184	C++
 	wip.exe!btDbvt::collideTV<btCompoundLeafCallback>(const btDbvtNode * root, const btDbvtAabbMm & vol, btCompoundLeafCallback & policy)  Line 941	C++
 	wip.exe!btCompoundCollisionAlgorithm::processCollision(btCollisionObject * body0, btCollisionObject * body1, const btDispatcherInfo & dispatchInfo, btManifoldResult * resultOut)  Line 254	C++
 	wip.exe!btSingleContactCallback::process(const btBroadphaseProxy * proxy)  Line 1134	C++
 	wip.exe!BroadphaseAabbTester::Process(const btDbvtNode * leaf)  Line 265	C++
 	wip.exe!btDbvt::collideTV<BroadphaseAabbTester>(const btDbvtNode * root, const btDbvtAabbMm & vol, BroadphaseAabbTester & policy)  Line 941	C++
 	wip.exe!btDbvtBroadphase::aabbTest(const btVector3 & aabbMin, const btVector3 & aabbMax, btBroadphaseAabbCallback & aabbCallback)  Line 275	C++
 	wip.exe!btCollisionWorld::contactTest(btCollisionObject * colObj, btCollisionWorld::ContactResultCallback & resultCallback)  Line 1152	C++
It seems like to be more consistent and allow for passing of those data, the "part"/"index" duo of variables which should be a trio, adding a consistent way to retrieve the btCollisionShape (perhaps a direct btCollisionShape* pointer passed to the addSingleResult() callback along with part/index.

I may attempt to change this within Bullet if it seems to makes sense? Erwin what do you think?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Get the index of child shape on btGImpactShape collision

Post by Erwin Coumans »

Can you please update to the latest Bullet trunk version, the callback interface has improved:

Code: Select all

bool ContactCallback(btManifoldPoint& cp,	const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1);
The btCollisionObjectWrapper contains the current child shape, and the parent btCollisionObjectWrapper.
You can use this hierarchy to figure out the chain of collision shapes that are used. If someone has time, we should add an example how to use this.

Thanks!
Erwin
Bock
Posts: 4
Joined: Thu Sep 27, 2012 3:31 pm

Re: Get the index of child shape on btGImpactShape collision

Post by Bock »

Thank you Erwin. We have now successfully updated to r2600 and got access to the btCollisionObjectWrapper* structure which makes our code more consistent and supporting more collision code paths.
Bock
Posts: 4
Joined: Thu Sep 27, 2012 3:31 pm

Post by Bock »

The code-path from ContactResultCallback::addSingleResult() now gives me the btCollisionObjectWrapper* data from which I can find the data I need.

However there's two other code-paths that do not provide the information:
A. rayTest() and associated callback RayResultCallback::addSingleResult() with LocalRayResult parameter.
B. manifolds stored in btDispatcher
Neither of those provide the same amount of details equivalent to what btCollisionObjectWrapper*

I think the first one can reasonably be modified to provide a btCollisionObjectWrapper* pointer to addSingleResult() or within the LocalRayResult.
Does that make sense within Bullet architecture? Is a similar update already planned? Will you likely accept a patch if I make that happen?

On the second one, manifolds are stored persisently so we can't easily store the info we need into them - because btCollisionObjectWrapper are stack objects as well as some btCollisionShape involved (depending on the collision algorithm). Instead it looks like we can use gContactAddedCallback described as "experimental feature info, for per-triangle material etc." which is basically calling a function when the contact is stored, and at this time we've got access to all details. So that's problem solved thanks to writing this post / rubber ducking.
panzergame
Posts: 3
Joined: Fri May 15, 2015 9:48 am

Re: Get the index of child shape on btGImpactShape collision

Post by panzergame »

Hello, it seems that this technique doesn't work currently. Because the object wrapper shape is the shape contained in the rigid body, line 1195 btCollisionWorld.cpp for function contactPairTest and line 1159 for contactTest.

Anyone has a solution with the actual bullet lib to find the child shape hited during a collision ?
Post Reply