here is how I build my collision tree:
- Code: Select all
NewtonCollision* CLPhysicEntity::BuildPhysicStaticBody(CTVMesh* Mesh, NewtonWorld* World) {
// Build the physics mesh and colision tree
float Temp;
int i, vec1, vec2, vec3, Group, color, NbrFaces, NbrVertex;
NbrFaces = Mesh->GetTriangleCount();
NbrVertex = Mesh->GetVertexCount();
char* name = Mesh->GetMeshName();
std::cout << "Creating " << name << " physic body" << "- Faces/Vertex: " << NbrFaces << "/" << NbrVertex << std::endl;
sVERTEX *sVertex = new sVERTEX[NbrFaces * 3];
for (int j = 0; j<NbrFaces * 3; j++)
{
sVertex[j].x = 0; // Initialize all elements to zero.
sVertex[j].y = 0;
sVertex[j].z = 0;
}
NewtonCollision* MeshCollision = NewtonCreateTreeCollision(World, 666);
NewtonTreeCollisionBeginBuild(MeshCollision);
for (i = 0; i < NbrFaces * 3; i = i + 3)
{
Mesh->GetTriangleInfo(i / 3, &vec1, &vec2, &vec3, &Group);
Mesh->GetVertex(vec1, &sVertex[i].x, &sVertex[i].y, &sVertex[i].z, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &color);
Mesh->GetVertex(vec2, &sVertex[i + 1].x, &sVertex[i + 1].y, &sVertex[i + 1].z, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &color);
Mesh->GetVertex(vec3, &sVertex[i + 2].x, &sVertex[i + 2].y, &sVertex[i + 2].z, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &Temp, &color);
NewtonTreeCollisionAddFace(MeshCollision, 3, &sVertex[i].x, sizeof(sVERTEX), 0);
}
// Finalize the collision tree build
NewtonTreeCollisionEndBuild(MeshCollision, 1);
delete[] sVertex; // When done, free memory pointed to by sVertex.
sVertex = NULL; // Clear a to prevent using invalid memory reference.
return(MeshCollision);
}
My application was doing fine with a 3.13 dll.
I changed my application to now use static lib with the latest newton code and I now have a few of my meshes that are giving me a debug assertion failed:
dgArray "i >=0"
I tried to debug that for a while now but cannot find what is wrong.
CallStack:
Graphysic.dll!dgArray<int>::operator[](int i) Line 94 C++
Graphysic.dll!dgPolygonSoupDatabaseBuilder::dgPolygonSoupDatabaseBuilder(const dgPolygonSoupDatabaseBuilder & source) Line 155 C++
Graphysic.dll!dgPolygonSoupDatabaseBuilder::End(bool optimize) Line 471 C++
Graphysic.dll!dgCollisionBVH::EndBuild(int optimize) Line 95 C++
Graphysic.dll!NewtonTreeCollisionEndBuild(const NewtonCollision * const treeCollision, int optimize) Line 3475 C++
Graphysic.dll!CLPhysicEntity::BuildPhysicStaticBody(CTVMesh * Mesh, NewtonWorld * World) Line 155 C++
All my other meshes are ok (all blender exported to directX format), and the rest of my physic application works fine as well, only a few meshes are giving me this error...
Any idea? I'm out of resources.... :S