Collision with box and mesh
-
- Posts: 29
- Joined: Sat Sep 23, 2006 1:35 pm
- Location: Northern Ireland
Collision with box and mesh
Hi Folks,
I am having trouble getting a mesh and a box to collide. When i change to a box / box it works fine.
I have used a btTriangleIndexVertexArray object which I put into the contructor of the btBvhTriangleMeshShape object.
I checked the AABB and it seems reasonable, If i replace the collision shape in the collision object with a btBoxShape a collision occurs correctly, but normally absolutely no collision is detected.
Any idea what I could have done wrong?
Thanks for your help
All the best,
Ash
I am having trouble getting a mesh and a box to collide. When i change to a box / box it works fine.
I have used a btTriangleIndexVertexArray object which I put into the contructor of the btBvhTriangleMeshShape object.
I checked the AABB and it seems reasonable, If i replace the collision shape in the collision object with a btBoxShape a collision occurs correctly, but normally absolutely no collision is detected.
Any idea what I could have done wrong?
Thanks for your help
All the best,
Ash
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
It is best to first use btTriangleMesh, instead of btTriangleIndexVertexArray.
The btTriangleIndexVertexArray is more complicated to setup: with btTriangleMesh you can easily add one triangle at a time.
Performance is the same, both use the same interface and can be added to btBvhTriangleMeshShape.
Erwin
The btTriangleIndexVertexArray is more complicated to setup: with btTriangleMesh you can easily add one triangle at a time.
Performance is the same, both use the same interface and can be added to btBvhTriangleMeshShape.
Erwin
-
- Posts: 29
- Joined: Sat Sep 23, 2006 1:35 pm
- Location: Northern Ireland
-
- Posts: 29
- Joined: Sat Sep 23, 2006 1:35 pm
- Location: Northern Ireland
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
-
- Posts: 29
- Joined: Sat Sep 23, 2006 1:35 pm
- Location: Northern Ireland
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
Re: Collision with box and mesh
I had a few problems setting up a btTriangleIndexVertexArray myself. If you've got a working btTriangleIndexVertexArray mesh, I'd be interested to know what values you used in the btIndexedMesh struct, especially the stride values.AshMcConnell wrote:Hi Folks,
I have used a btTriangleIndexVertexArray object which I put into the contructor of the btBvhTriangleMeshShape object.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Collision with box and mesh
There is a working example in Bullet:nomad wrote:I had a few problems setting up a btTriangleIndexVertexArray myself. If you've got a working btTriangleIndexVertexArray mesh, I'd be interested to know what values you used in the btIndexedMesh struct, especially the stride values.AshMcConnell wrote:Hi Folks,
I have used a btTriangleIndexVertexArray object which I put into the contructor of the btBvhTriangleMeshShape object.
Demos\ConcaveDemo\ConcavePhysicsDemo.cpp
The 3 indices for a single triangle are expected to be in contiguous memory, and the indexstride points to the start index for the next triangle.
Typically this is 3 * sizeof(int), if each triangle has its own indices, and no stripping/fanning happens. Remember that btTriangleIndexVertexArray just points to mesh (vertex/index) data, so don't delete this mesh data until the simulation ends.
But for most cases it's better to just stick with btTriangleMesh, instead of re-using the graphics data. Compare the much simpler btTriangleMesh setup:
Code: Select all
btTriangleMesh* trimesh = new btTriangleMesh();
for ( i=0;i<NUM_VERTS_X-1;i++)
{
for (int j=0;j<NUM_VERTS_Y-1;j++)
{
trimesh->addTriangle(gVertices[j*NUM_VERTS_X+i],gVertices[j*NUM_VERTS_X+i+1],gVertices[(j+1)*NUM_VERTS_X+i+1]);
trimesh->addTriangle(gVertices[j*NUM_VERTS_X+i],gVertices[(j+1)*NUM_VERTS_X+i+1],gVertices[(j+1)*NUM_VERTS_X+i]);
}
}
Code: Select all
int vertStride = sizeof(btVector3);
int indexStride = 3*sizeof(int);
const int NUM_VERTS_X = 50;
const int NUM_VERTS_Y = 50;
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
btVector3* gVertices = new btVector3[totalVerts];
int* gIndices = new int[totalTriangles*3];
int i;
for ( i=0;i<NUM_VERTS_X;i++)
{
for (int j=0;j<NUM_VERTS_Y;j++)
{
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
//0.f,
2.f*sinf((float)i)*cosf((float)j),
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
}
}
int index=0;
for ( i=0;i<NUM_VERTS_X-1;i++)
{
for (int j=0;j<NUM_VERTS_Y-1;j++)
{
gIndices[index++] = j*NUM_VERTS_X+i;
gIndices[index++] = j*NUM_VERTS_X+i+1;
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
gIndices[index++] = j*NUM_VERTS_X+i;
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
gIndices[index++] = (j+1)*NUM_VERTS_X+i;
}
}
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
gIndices,
indexStride,
totalVerts,(float*) &gVertices[0].x(),vertStride);
btCollisionShape* trimeshShape = new btBvhTriangleMeshShape(indexVertexArrays);
-
- Posts: 29
- Joined: Sat Sep 23, 2006 1:35 pm
- Location: Northern Ireland
Re: Collision with box and mesh
I had a look at the code here: -nomad wrote:I had a few problems setting up a btTriangleIndexVertexArray myself. If you've got a working btTriangleIndexVertexArray mesh, I'd be interested to know what values you used in the btIndexedMesh struct, especially the stride values.AshMcConnell wrote:Hi Folks,
I have used a btTriangleIndexVertexArray object which I put into the contructor of the btBvhTriangleMeshShape object.
http://continuousphysics.com/Bullet/php ... .php?t=769
I am using Ogre + Bullet Collision + a friend's physics
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
I'm working on a Bullet - Irrlicht demo. It is a basic framework that loads meshes and attaches the main Bullet collision shapes to them, hopefully it will be helpful to Irrlicht users.
I thought it would be more efficient to re-use the Irrlicht vertex and index data, when it didn't work I assumed I'd got the btTriangleIndexVertexArray wrong. The problem was the way the Irrlicht index data is arranged, and how I was using it.
I'd have to re-organise the index data to use it in a btTriangleIndexVertexArray, so it is better for me to use a btTriangleMesh.
Sorry, didn't realise there was a btTriangleIndexVertexArray example (bangs head repeatedly against wall chanting "search the source code" )
Thanks.
I thought it would be more efficient to re-use the Irrlicht vertex and index data, when it didn't work I assumed I'd got the btTriangleIndexVertexArray wrong. The problem was the way the Irrlicht index data is arranged, and how I was using it.
I'd have to re-organise the index data to use it in a btTriangleIndexVertexArray, so it is better for me to use a btTriangleMesh.
Sorry, didn't realise there was a btTriangleIndexVertexArray example (bangs head repeatedly against wall chanting "search the source code" )
Thanks.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
I'm curious how the index-layout is of Irrlicht? Can you describe what the incompatibility is?
Did you know you can add several subparts to the btTriangleIndexVertexArray? This might help if there are multiple sets of indices.
Thanks,
Erwin
Did you know you can add several subparts to the btTriangleIndexVertexArray? This might help if there are multiple sets of indices.
Thanks,
Erwin
nomad wrote:I'm working on a Bullet - Irrlicht demo. It is a basic framework that loads meshes and attaches the main Bullet collision shapes to them, hopefully it will be helpful to Irrlicht users.
I thought it would be more efficient to re-use the Irrlicht vertex and index data, when it didn't work I assumed I'd got the btTriangleIndexVertexArray wrong. The problem was the way the Irrlicht index data is arranged, and how I was using it.
I'd have to re-organise the index data to use it in a btTriangleIndexVertexArray, so it is better for me to use a btTriangleMesh.
Sorry, didn't realise there was a btTriangleIndexVertexArray example (bangs head repeatedly against wall chanting "search the source code" )
Thanks.
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
Yes, there are multiple sets of indices and using subparts would solve my problem, i.e. instead of having to extract all the index / vertex data to temporary buffers. There should be no reason why the Irrlicht index / vertex data cannot be used directly. I'll give it a go now I have btTriangleIndexVertexArrays working.
Regarding the data layout, there are 3 unique vertices for each triangle, no vertex re-use (when loading 3ds files... not sure about other formats) i.e. same number of vertices and indices. Somewhat inefficient, but not a compatibility problem.
Thanks.
Regarding the data layout, there are 3 unique vertices for each triangle, no vertex re-use (when loading 3ds files... not sure about other formats) i.e. same number of vertices and indices. Somewhat inefficient, but not a compatibility problem.
Thanks.
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
There does seem to be an incompatibility with the index layout in Irrlicht.Erwin Coumans wrote:I'm curious how the index-layout is of Irrlicht? Can you describe what the incompatibility is?
Irrlicht indices are stored as arrays of unsigned shorts, and Bullet won't accept an index array of 16 bit values. I think there is a byte-alignment issue here.
So to use the data in a btTriangleIndexVertexArray I need to first copy the index values to an int array, which works fine. But it's easier to just use btTriangleMeshes instead.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
It's best to use btTriangleMesh indeed. Bullet used to support 16 bits indices before, it was never used and probably disappeared during refactoring. We can add it back in, if desperately needed.nomad wrote:There does seem to be an incompatibility with the index layout in Irrlicht.Erwin Coumans wrote:I'm curious how the index-layout is of Irrlicht? Can you describe what the incompatibility is?
Irrlicht indices are stored as arrays of unsigned shorts, and Bullet won't accept an index array of 16 bit values. I think there is a byte-alignment issue here.
So to use the data in a btTriangleIndexVertexArray I need to first copy the index values to an int array, which works fine. But it's easier to just use btTriangleMeshes instead.
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
Thanks, but I'll just use btTriangleMeshes - if I need btTriangleIndexVertexArrays, it would probably just be easier to change the index layout in Irrlicht anyway. I'm really just working out how best to use Bullet at this stage.Erwin Coumans wrote: It's best to use btTriangleMesh indeed. Bullet used to support 16 bits indices before, it was never used and probably disappeared during refactoring. We can add it back in, if desperately needed.