Problems with btBvhTriangleMeshShape

amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Problems with btBvhTriangleMeshShape

Post by amrishkum »

Hi

When I try to add any triangular mesh to btBvhTriangleMeshShape, trimeshShape1 crashes. I even used indexVertexArrays but no help. Can someone tell if they had experienced same type of problem? Is there a sequencing of triangles I need to follow. Pleasee the code below.

Thanks Amrish Kumar



int AddTringularMeshObject2(float VertexXArray[],float VertexYArray[],float VertexZArray[],int IndexArray[])
{
try
{

int vertStride = sizeof(btVector3);
int indexStride = 3*sizeof(int);


const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
const int NoOfIndices = totalTriangles*3;
btVector3* gVertices=0;
int* gIndices=0;

gVertices = new btVector3[ totalVerts];
gIndices = new int[ NoOfIndices ];

for (int i =0; i< totalVerts; i++)
{
gVertices.setValue(VertexXArray,VertexYArray,VertexZArray);
}
for (int i =0; i< NoOfIndices; i++)
{
gIndices[i++] = IndexArray[i++];
}


btTriangleMesh* trimesh = new btTriangleMesh();

for ( int i=0;i<NoOfIndices;i+=3)
{
trimesh->addTriangle(gVertices[gIndices[i+2]],gVertices[gIndices[i+1]],gVertices[gIndices]);

}
/*m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
gIndices,
indexStride,
totalVerts,(btScalar*) &gVertices[0].x(),vertStride);*/


bool useQuantizedAabbCompression = true;

btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000);


btCollisionShape *trimeshShape1 = new btBvhTriangleMeshShape(trimesh,useQuantizedAabbCompression);

/* trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArraysObj1,useQuantizedAabbCompression);

m_collisionShapes.push_back(trimeshShape);*/


m_collisionShapes.push_back(trimeshShape1);
}
catch(...)
{
}

return 0;
}
amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Re: Problems with btBvhTriangleMeshShape

Post by amrishkum »

I found the bug...thanks for the help