Arbitrary Mesh - how to create collision shape?

Post Reply
monty_hall
Posts: 4
Joined: Tue Feb 23, 2016 10:59 pm

Arbitrary Mesh - how to create collision shape?

Post by monty_hall »

Suppose I have some closed blob mesh (non selft intersecting and possibly non convex) that I created in blender. How do I create a collision shape for it using the *exact* triangles that make it up? btGImpactShape?

Thanks,

Monty
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Arbitrary Mesh - how to create collision shape?

Post by Flix »

1) btGImpactShape
2) Convex decomposition: decompose the mesh into convex child shapes of a btCompoundShape (or of a btGImpactConvexDecompositionShape that's probably deprecated...). Known algorithms:
-> V-HACD: https://github.com/kmammou/v-hacd (good for closed (=waterproof) meshes) -> includes a Blender plugin
-> HACD: https://sourceforge.net/projects/hacd (good for other meshes)

See also the Bullet ConvexDecompositionDemo.

Please note that convex decomposition is used in every physic library (well, at least most of them).
monty_hall
Posts: 4
Joined: Tue Feb 23, 2016 10:59 pm

Re: Arbitrary Mesh - how to create collision shape?

Post by monty_hall »

Do you know where I can find ConvexDecompositionDemo.cpp?

I see it here "https://bullet.googlecode.com/svn/trunk ... onDemo.cpp" But I cannot seem to find it in my git repo in "origin/master". Further it would appear that the web page is pointing to some subversion repo.

Thanks,

M
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Arbitrary Mesh - how to create collision shape?

Post by Flix »

Yes, that demo has not been ported to the Bullet3 package...

However, there's still a libConvexDecomposition (that is built by default and it's based on John Ratcliff's work) and there are still the two files: btGImpactConvexDecompositionShape.h btGImpactConvexDecompositionShape.cpp: AFAIR they were used in the GImpact demo, but they needed a change in a preprocessor definition to use btGImpactConvexDecompositionShape instead of btGImpactMeshShape.

The problem is that I think that the GImpact demo is missing from Bullet3 too, but I'm sure you can retrieve it somewhere...

Alternatively, if you want to use HACD (not V-HACD), you may try and see if my OLD header-only helper file still works, but you need to clone the HACD library from the link I posted, the SVN repository, and you can't use the one that used to be bundled with Bullet2 (... hoping that it'is still compatible):
btHACDCompoundShape.h
Header-only HACD binding for Bullet
(53.97 KiB) Downloaded 599 times
Hope it helps.
Evan407
Posts: 22
Joined: Sun Jan 17, 2016 2:37 am

Re: Arbitrary Mesh - how to create collision shape?

Post by Evan407 »

You have to make an IndexedMesh so you can make a TriangleIndexVertexArray to load in the geometry. Here is some code I use for jBullet

Code: Select all

  BvhTriangleMeshShape createBvhTriangleMeshShape(){
	ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(templateFaces.length*3*4);//number of triangles * 3 verticies * 4 bytes
	ByteBuffer vertexBase = BufferUtils.createByteBuffer(points.length * 3 * 4);//vertecies * 3 dimensions * 4 bytes
	IntBuffer triangleIndexBaseIB = triangleIndexBase.asIntBuffer();
	FloatBuffer vertexBaseFB = vertexBase.asFloatBuffer();
	for(TemplateFace f : templateFaces){
	  triangleIndexBaseIB.put(f.p1Number);//the index number
	  triangleIndexBaseIB.put(f.p2Number);//points.indexOf(f.p2)
	  triangleIndexBaseIB.put(f.p3Number);
	}
	for(Point p : points){
	  vertexBaseFB.put(p.x * GameLogic.DEVERSION); //"deversion" is the inverse conversion i know it's silly
	  vertexBaseFB.put(p.y * GameLogic.DEVERSION);
	  vertexBaseFB.put(-p.z * GameLogic.DEVERSION);
	}
	IndexedMesh indexedMesh = new IndexedMesh();
	indexedMesh.numTriangles = templateFaces.length;
	indexedMesh.numVertices = points.length;
	indexedMesh.triangleIndexBase = triangleIndexBase;
	indexedMesh.triangleIndexStride = 12;
	indexedMesh.vertexBase = vertexBase;
	indexedMesh.vertexStride = 12;
	TriangleIndexVertexArray triangleIndexVertexArray = new TriangleIndexVertexArray();
	triangleIndexVertexArray.addIndexedMesh(indexedMesh);
	return new BvhTriangleMeshShape(triangleIndexVertexArray,true);
  }
The BvhTriangleMeshShape is for static world objects. For making a GImpactMeshShape you'll still need the TriangleIndexVertexArray.

Code: Select all

new GImpactMeshShape(triangleIndexVertexArray)
Post Reply