Using btDbvt for collision detection in FEM simulation

Post Reply
Renoster
Posts: 3
Joined: Thu Oct 23, 2014 12:31 pm

Using btDbvt for collision detection in FEM simulation

Post by Renoster »

Hello everybody,

I am new to Bullet Physics and stuck with some things related to the AABB-Tree from btDbvt and I hope you can help me a bit.
I just started working on deformable haptic rendering with 3D-objects. We use the chai3d library for the haptic device and want to use VEGA FEM for the deformation simulation. A problem occurring with the VEGA lib is that it has no collision detection implemented. In my research i found a thesis by Ziyun Li in which they use the dtDbvt from bullet to detect collisions. (https://www.ruor.uottawa.ca/bitstream/1 ... thesis.pdf)

We planned to use this AABB-tree aswell but now i struggle a bit to get all working, especially the rayTest.

What i did by now is to try to import the mesh in the AABB-tree (what I am not sure if its correct like i try it):

Code: Select all

  btDbvt *tree = new btDbvt();
  btDbvtVolume volume;
  btDbvtNode node;

  // extract point data from loaded mesh 
  deformableObjectRenderingMesh->ExportMeshGeometry(&vertexCount, &vertexData, &triangleCount, &triangleData);
  
  // create AABB-tree with btDbvt from Bullet Physics Library
  int j = 0;
  for (int i = 0; i < vertexCount*3; i=i+3) {
	  btVector3 pointdata = btVector3(vertexData[i],vertexData[i+1],vertexData[i+2]);
	  volume.FromPoints(&pointdata,3);
	  cout << j << "  " << vertexData[i] << "  " << vertexData[i+1] << "  " << vertexData[i+2] << endl;
	  j = j+1;
	  tree->insert(volume,node.data);
  }
Im stuck now trying to run a raytest with the current and previous position of my haptic device.
All examples uses the world object. In general is it possible to use this AABB-Tree without the world object? And if yes, can you give me a quick help with how the DBVT_IPOLICY is to use.


I hope someone can help me . Thank you a lot.

cheers renoster
Renoster
Posts: 3
Joined: Thu Oct 23, 2014 12:31 pm

Re: Using btDbvt for collision detection in FEM simulation

Post by Renoster »

/edit:

i searched a bit more and tried some things and saw some things I am pretty sure i did wrong and hopefully fixed now. But some questions more appeared.

i changed the construction of the volume to so it really will be constructed from triangles:

Code: Select all

collisionTree = new btDbvt();
	for (int i = 0; i < triangleCount*3; i=i+3) {
		btVector3 trianglepoints[3];
		trianglepoints[0][0] = vertexData[triangleData[i]];
		trianglepoints[0][1] = vertexData[triangleData[i]+1];
		trianglepoints[0][2] = vertexData[triangleData[i]+2];
		trianglepoints[1][0] = vertexData[1+triangleData[i]];
		trianglepoints[1][1] = vertexData[1+triangleData[i+1]];
		trianglepoints[1][2] = vertexData[1+triangleData[i+2]];
		trianglepoints[2][0] = vertexData[2+triangleData[i]];
		trianglepoints[2][1] = vertexData[2+triangleData[i+1]];
		trianglepoints[2][2] = vertexData[2+triangleData[i+2]];

		volume.FromPoints(trianglepoints,3);
		collisionTree->insert(volume,node.data);
	}
But the next question appearing now is in the insert function. It is called as insert(const btDbvtVolume& box,void* data);. The btDbvtVolume is the loaded mesh if I understand it right. But the void* data what does it exactly contain? Its further information to the node?
The problem how to perform the raytest without all the collision world still remains.

I hope someone can help me . Thank you a lot.

cheers renoster
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Using btDbvt for collision detection in FEM simulation

Post by drleviathan »

Looking at the code it appears that the "data" argument of btDbvt::insert() is a just void* to whatever object is contained within the corresponding volume. That is, the btDbvt class is agnostic about "what" is actually contained in its nodes. The btDbvtNode struct keeps track of the volume and also a void* pointer to the thing inside (if it is a leaf node, otherwise it keeps a pointer to an array of pointers to child nodes). It is up to you to supply void* pointers to the right things and to also properly cast them back to the right type later when overlaps are harvested.
Renoster
Posts: 3
Joined: Thu Oct 23, 2014 12:31 pm

Re: Using btDbvt for collision detection in FEM simulation

Post by Renoster »

Thank you a lot. Than i was with my thoughts on the right way :)
Being new to the library can be very confusing but slowly i think i get more comfortable with it.
I hope i will get the raytest running soon too.

Cheers
lrkk1234
Posts: 2
Joined: Fri Feb 19, 2016 4:38 am

Re: Using btDbvt for collision detection in FEM simulation

Post by lrkk1234 »

Hi Renoster,
I am trying to do same thing with you on my research.
But I find updating btDbvt's aabb tree is very slow.

Code: Select all

btDbvtVolume volume;
	for (int i = 0; i < tri_mesh.indices.size() / 3; i++)
	{
		btVector3 trianglepoints[3];
		int v1, v2, v3;
		v1 = tri_mesh.indices.data()[i * 3 + 0];
		v2 = tri_mesh.indices.data()[i * 3 + 1];
		v3 = tri_mesh.indices.data()[i * 3 + 2];
		trianglepoints[0][0] = tri_mesh.positions->data()[v1 * 3] + tri_mesh.displacement.data()[v1 * 3];
		trianglepoints[0][1] = tri_mesh.positions->data()[v1 * 3 + 1] + tri_mesh.displacement.data()[v1 * 3 + 1];
		trianglepoints[0][2] = tri_mesh.positions->data()[v1 * 3 + 2] + tri_mesh.displacement.data()[v1 * 3 + 2];
		trianglepoints[1][0] = tri_mesh.positions->data()[v2 * 3] + tri_mesh.displacement.data()[v2 * 3];
		trianglepoints[1][1] = tri_mesh.positions->data()[v2 * 3 + 1] + tri_mesh.displacement.data()[v2 * 3 + 1];
		trianglepoints[1][2] = tri_mesh.positions->data()[v2 * 3 + 2] + tri_mesh.displacement.data()[v2 * 3 + 2];
		trianglepoints[2][0] = tri_mesh.positions->data()[v3 * 3] + tri_mesh.displacement.data()[v3 * 3];
		trianglepoints[2][1] = tri_mesh.positions->data()[v3 * 3 + 1] + tri_mesh.displacement.data()[v3 * 3 + 1];
		trianglepoints[2][2] = tri_mesh.positions->data()[v3 * 3 + 2] + tri_mesh.displacement.data()[v3 * 3 + 2];
		volume.FromPoints(trianglepoints, 3);
		tri_mesh.dynamic_aabb->update(tri_mesh.leaf[i], volume);
	}
I have 6300 triangles.
update aabb tree takes like 1.0 s;
This is a little slow for me, I want know if there is any trick to make update faster.
Thanks :roll:
Post Reply