How to get triangles within a convex shapes volume?

pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

How to get triangles within a convex shapes volume?

Post by pico »

Hi,

is there a way to find all triangles from meshes that lie in a convex shapes volume?
An OBB or AABB would also be ok, instead of a convex shape.

Thanks for any help
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: How to get triangles within a convex shapes volume?

Post by pico »

By the way, i need that for geometric decals. Footsteps on the ground etc. Maybe this could be a useful feature to bullet?
I would first gather the triangles, then clip them with the six planes of a cube and generate again triangles from the new polygons. Those could then be used to project the actual decal on them.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: How to get triangles within a convex shapes volume?

Post by Erwin Coumans »

For a triangle mesh rigidbody (triBody) that has a btBvhTriangleMeshShape, you can get all triangles that overlap with the AABB of a convex object (convexBody) using a callback, use the following code snippet:

Code: Select all

class YourTriangleCallback : public btTriangleCallback
{
public:
   virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
   {
      ///do something for the overlapping triangle
   }
};
YourTriangleCallback tmpCallback;
btVector3 aabbMin, aabbMax;

btTransform convexInTriangleSpace = triBody->getWorldTransform().inverse() * convexBody->getWorldTransform();
convexBody->getCollisionShape()->getAabb(convexInTriangleSpace,aabbMin,aabbMax);
btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*) triBody->getCollisionShape();

meshShape->processAllTriangles(&tmpCallback, aabbMin,aabbMax);
Hope this helps,
Erwin
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: How to get triangles within a convex shapes volume?

Post by pico »

Hi Erwin,

is there also a solution to get before all shapes within that AABB aswell?

I would first need to gather all shapes within that AABB, then i could iterate over them with the above callback.

thanks