i want to use trimeshes for levels/rooms in my game, but when I try to implement something like this I get stuck. First of all, which trimesh type is for levels/rooms recommended by you? I tried to use "btTriangleMeshShape" but that's impossible for me , because of this little error:
(Here's my code)
Code: Select all
void Trimesh::create(std::string modelfile, float mass, Vector3D scale)
{
trimesh = new btTriangleMesh();
// Load the mesh with Irrlicht
std::string filename = FileSystem::get()->getFileExists(std::string("models/") + modelfile);
irr::scene::IAnimatedMesh *animmesh = GraphicsEngine::get()->getSceneManager()->getMesh(filename.c_str());
irr::scene::IMesh *mesh = animmesh->getMesh(0);
// Test whether the mesh has got one mesh buffer. (Multiple meshbuffers aren't supported yet)
if (mesh->getMeshBufferCount())
{
irr::scene::IMeshBuffer *buffer = mesh->getMeshBuffer(0);
LDEBUG("Number of meshbuffers: %d\n", mesh->getMeshBufferCount());
int tricount = buffer->getVertexCount() / 3;
unsigned short int *indices = new unsigned short int[buffer->getIndexCount()];
indices = buffer->getIndices();
LDEBUG("Got all indices...\n");
irr::video::S3DVertex *vecdata = (irr::video::S3DVertex*)buffer->getVertices();
float *vertices = new float[buffer->getVertexCount() * 3];
for(int j = 0; j < buffer->getVertexCount(); j++)
{
vertices[j] = vecdata[j].Pos.X;
vertices[j+1] = vecdata[j].Pos.Y;
vertices[j+2] = vecdata[j].Pos.Z;
}
LDEBUG("Got all vertices...\n");
int index0, index1, index2;
btVector3 vertex0, vertex1, vertex2;
for(int i = 0; i < tricount; i++)
{
index0 = indices[i*3];
index1 = indices[i*3+1];
index2 = indices[i*3+2];
btVector3 vertex0(vertices[index0*3], vertices[index0*3+1], vertices[index0*3+2]);
btVector3 vertex1(vertices[index1*3], vertices[index1*3+1], vertices[index1*3+2]);
btVector3 vertex2(vertices[index2*3], vertices[index2*3+1], vertices[index2*3+2]);
trimesh->addTriangle(vertex0,vertex1,vertex2);
}
LDEBUG("Overgived mesh to bullet...\n");
delete indices;
delete vertices;
/*btConvexShape *tmpshape = new btConvexTriangleMeshShape(trimesh);
btShapeHull *hull = new btShapeHull(tmpshape);
btScalar margin = tmpshape->getMargin();
hull->buildHull(margin);
tmpshape->setUserPointer(hull);
shape = new btConvexHullShape();
btConvexHullShape *convexshape = (btConvexHullShape*)(shape);
for (int k = 0; k < hull->numVertices() ; k++)
{
convexshape->addPoint(btPoint3(hull->getVertexPointer()[k]));
}
delete tmpshape;
delete hull;*/
shape = (btCollisionShape*)(new btTriangleMeshShape(trimesh));
LDEBUG("Sucessfully generated trimesh shape (or only without runtime error)\n");
}
I get the following error(s):
You See: I am using Irrlicht to load the mesh files. When I am using the commented code, my objects just fall through the trimesh level. How can I use a standard btTriangleMeshShapeF:\Entwicklung\peakengine\branches\entity-rewrite\engine\src\physics\Trimesh.cpp||In member function `void peak::Trimesh::create(std::string, float, peak::Vector3D)':|
F:\Entwicklung\peakengine\branches\entity-rewrite\engine\src\physics\Trimesh.cpp|95|error: cannot allocate an object of type `btTriangleMeshShape'|
F:\Entwicklung\peakengine\branches\entity-rewrite\engine\src\physics\Trimesh.cpp|95|error: because the following virtual functions are abstract:|
include\bullet\BulletCollision\CollisionShapes\btCollisionShape.h|79|error: virtual int btCollisionShape::getShapeType() const|
(I didn't find anything with the forum search :-[ )
Thank You,
Chris