Collision between meshes

Post Reply
AlTerz93
Posts: 6
Joined: Wed Jan 22, 2020 2:45 pm

Collision between meshes

Post by AlTerz93 »

Hello everyone!

I'm trying to create a simulation where I need to check the collision between two meshes. I'm using BulletSharp.
For the moment I tried to insert the mesh both as BvhTriangleMeshShape:

Code: Select all

var localScaling = new Vector3((float)scale);
var _triangleMesh = CreateTriangleMesh(wavefrontModel.Indices, wavefrontModel.Vertices, localScaling);

var concaveShape = new BvhTriangleMeshShape(_triangleMesh, true);
and as GImpactMeshShape, which is more suitable for dynamic objects (true?):

Code: Select all

var tri = new TriangleIndexVertexArray(wavefrontModel.Indices, wavefrontModel.Vertices);
var g_tri = new GImpactMeshShape(tri);
g_tri.Margin = 0;
g_tri.UpdateBound();
g_tri.LocalScaling = new Vector3((float)scale);
One of the objects is a container and the other one is an object which falls into it. So the first one is static and the second one dynamic.

No collision is currently detected. I tried to vary the scale and increase the stepSimulation but nothing has changed.

I know that collisions among meshes are not optimal but I don't need speed but precision and also I don't have to consider many objects.

How can I solve this problem?

Thanks in advance
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Collision between meshes

Post by drleviathan »

You are right: two BvhTriangleMeshShape's do not collide. The fact of the matter is: the mesh-vs-mesh collision algorithm is not written.

Options that might work:

(1) Use a CompoundShape approximation, which is a collection of convex parts, for the dynamic object. If your approximate shape is very close to the original then perhaps your collision information will suit your purposes. If you truly don't care about performance, and your dynamic shape doesn't have too many triangles (what is "too many"? maybe more than a few 100k triangles), then you could just make your convex parts be the triangles themselves -- might work.

(2) Supposedly concave meshes can mutually collide using the GImpactShapes. Dunno if they are supported in BulletSharp. So maybe you could move to C++ to take this path.
AlTerz93
Posts: 6
Joined: Wed Jan 22, 2020 2:45 pm

Re: Collision between meshes

Post by AlTerz93 »

drleviathan wrote: Fri Apr 24, 2020 10:01 pm You are right: two BvhTriangleMeshShape's do not collide. The fact of the matter is: the mesh-vs-mesh collision algorithm is not written.
Ok there was a reason. Thanks.

I also tried with GImpactShapes but nothing changes: no collision detected. But a question arose: looking at the GImpactTestDemo, the bunnies are created as GImpactShape and collisions among them are detected. I've tried to use bunnies also in my simulation but there was no collision among them. Could be (but I don't think so) a problem related to the solver in multithreading?
This is my configuration:

Code: Select all

CreateSchedulers();
NextTaskScheduler();
using (var collisionConfigurationInfo = new DefaultCollisionConstructionInfo
{
	DefaultMaxPersistentManifoldPoolSize = 80000,
        DefaultMaxCollisionAlgorithmPoolSize = 80000
})
{
	colConfiguration = new DefaultCollisionConfiguration(collisionConfigurationInfo);
};
        colDispatcher = new CollisionDispatcherMultiThreaded(colConfiguration);
        broadphase = new DbvtBroadphase();
	_solverPool = new ConstraintSolverPoolMultiThreaded(MaxThreadCount);
        _parallelSolver = new SequentialImpulseConstraintSolverMultiThreaded();

	colWorld = new DiscreteDynamicsWorldMultiThreaded(colDispatcher, broadphase, _solverPool, _parallelSolver, colConfiguration);
        colWorld.SolverInfo.SolverMode = SolverModes.Simd | SolverModes.UseWarmStarting;

        debugDrawer = new elBulletDebugDrawer(application, this);
        colWorld.DebugDrawer = debugDrawer;

        colWorld.Gravity = new Vector3(0, 0, -9.81f);
I also thought of another way: use a softBody and in some way make the object as rigid as possible. I tried but I had some problems with the pose update: is the WorldTransform different wrt the one for rigidBodies?
anthrax11
Posts: 72
Joined: Wed Feb 24, 2010 9:49 pm

Re: Collision between meshes

Post by anthrax11 »

The GImpact algorithm needs to be explicitly registered:

Code: Select all

var collisionDispatcher = new CollisionDispatcher(collisionConfiguration);
GImpactCollisionAlgorithm.RegisterAlgorithm(collisionDispatcher);
Just to confirm what everyone said :) :
BvhTriangleMeshShapes work well as static concave or convex shapes. But since they are meant to be static, there is no algorithm to make them collide with each other.
ConvexTriangleMeshShapes are efficient as dynamic convex shapes.
GImpact shapes are well optimized for when you need dynamic concave shapes.
Convex decomposition can be used to decompose concave shapes into convex shapes. The resulting convex shapes can then be combined into a CompoundShape, which is also an efficient way to model dynamic concave shapes.
Post Reply