I have a prog. that can import 3ds file for terrain.
Should I use btTriangleMesh for collision detection?
Thanks in advance.
should btTriangleMesh for 3ds file for terrain??
-
- Posts: 3
- Joined: Mon Aug 06, 2007 6:15 am
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Yes, you can create a btTriangleMesh and add all triangles to this container. Then pass this mesh interface to btBvhTriangleMeshShape. Note that you can still use compression/quantization for the Bvh tree, the comment in the code is obsolete (is updated for next version). See Demos\UserCollisionAlgorithm\UserCollisionAlgorithm.cpp for an example:
Instead of duplicating the mesh data, you can also reference existing vertices/indices in-memory, using btTriangleIndexVertexArray. See ConcaveDemo for an example:
Hope this helps,
Erwin
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]);
}
}
delete[] gVertices;
bool useQuantizedBvhTree = true;
btCollisionShape* trimeshShape = new btBvhTriangleMeshShape(trimesh,useQuantizedBvhTree);
Code: Select all
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
gIndices,
indexStride,
totalVerts,(btScalar*) &gVertices[0].x(),vertStride);
bool useQuantizedAabbCompression = true;
trimeshShape = new btBvhTriangleMeshShape(indexVertexArrays,useQuantizedAabbCompression);
Erwin
-
- Posts: 3
- Joined: Mon Aug 06, 2007 6:15 am
Thx a lot

Erwin Coumans wrote:Yes, you can create a btTriangleMesh and add all triangles to this container. Then pass this mesh interface to btBvhTriangleMeshShape. Note that you can still use compression/quantization for the Bvh tree, the comment in the code is obsolete (is updated for next version). See Demos\UserCollisionAlgorithm\UserCollisionAlgorithm.cpp for an example:
Instead of duplicating the mesh data, you can also reference existing vertices/indices in-memory, using btTriangleIndexVertexArray. See ConcaveDemo for an example: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]); } } delete[] gVertices; bool useQuantizedBvhTree = true; btCollisionShape* trimeshShape = new btBvhTriangleMeshShape(trimesh,useQuantizedBvhTree);
Hope this helps,Code: Select all
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles, gIndices, indexStride, totalVerts,(btScalar*) &gVertices[0].x(),vertStride); bool useQuantizedAabbCompression = true; trimeshShape = new btBvhTriangleMeshShape(indexVertexArrays,useQuantizedAabbCompression);
Erwin
-
- Posts: 12
- Joined: Mon Sep 03, 2007 3:32 pm
Re: should btTriangleMesh for 3ds file for terrain??
I just don't understand a thing.
This method implement a way to create the mesh collision, but how can i assign my 3ds model to this collision mesh ?
And another question, all the vertices must be in a vector off one dimension, i mean,does all of then must be aligned like , vertex1.x then vertex1.y and then vertex1.z, all in line ?
This method implement a way to create the mesh collision, but how can i assign my 3ds model to this collision mesh ?
And another question, all the vertices must be in a vector off one dimension, i mean,does all of then must be aligned like , vertex1.x then vertex1.y and then vertex1.z, all in line ?
-
- Posts: 12
- Joined: Mon Sep 03, 2007 3:32 pm
Re: should btTriangleMesh for 3ds file for terrain??
Hey ,can we talk bout how to use a 3ds file in bullet ?
i am using it too and i can't understand the part
the gVertices by the way have the informations about the point as a unidimensional array ? i am using like this
but it's not working, you can tell me what is my mistake
the strange is, when i use
for convex way, does it works
i am using it too and i can't understand the part
Code: Select all
addTriangle(gVertices[j*NUM_VERTS_X+i],gVertices[j*NUM_VERTS_X+i+1],gV
ertices[(j+1)*NUM_VERTS_X+i+1]);
the gVertices by the way have the informations about the point as a unidimensional array ? i am using like this
Code: Select all
int index0 = pObject->pFaces[j].vertIndex[0];
int index1 = pObject->pFaces[j].vertIndex[1];
int index2 = pObject->pFaces[j].vertIndex[2];
btVector3 vertex0(pObject->pVerts[index0].x,pObject->pVerts[index0].y,pObject->pVerts[index0].z);
btVector3 vertex1(pObject->pVerts[index1].x,pObject->pVerts[index1].y,pObject->pVerts[index1].z);
btVector3 vertex2(pObject->pVerts[index2].x,pObject->pVerts[index2].y,pObject->pVerts[index2].z);
trimesh->addTriangle(vertex0,vertex1,vertex2);
the strange is, when i use
Code: Select all
//convex way************************************************************************
btCollisionShape* convexShape = new btConvexTriangleMeshShape(trimesh);
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,0));
localCreateRigidBody(0.0f, startTransform,convexShape);
/****************************************************************/