Linaxys
21-08-2009 23:09:53
Hello,
I can't find any solution to load a BSP collision mesh, so I can post my own.
First, you have to create a manual object to store every BSP triangles, I've copied every BSPSceneManager files from the plugin's source code in my project, and I did like this inside OgreBspLevel.cpp :
You have to call it in the end of BspLevel::loadQuake3Level.
And this is my code to load the BSP mesh :
Now, I have to find out how to load patches (curves, bezier,...) correctly and the problem will be solved
Is there actually a way to parse vertices on a BSP level ?
Would I have to send every faces to a TreeCollision by modifying a bit the BSPSceneLoader ?
Thanks.
I can't find any solution to load a BSP collision mesh, so I can post my own.
First, you have to create a manual object to store every BSP triangles, I've copied every BSPSceneManager files from the plugin's source code in my project, and I did like this inside OgreBspLevel.cpp :
Ogre::MeshPtr BspLevel::ConvertToMesh(const Quake3Level& q3lvl){
int idxStart, numVertex;
int obCount = 0;
Ogre::SceneManager *sceneMgr = GetMySceneManagerHere();
Ogre::ManualObject *_manualObject = sceneMgr->createManualObject("BspMesh_mo");
Ogre::MeshPtr _mesh;
for (int u = 0; u < q3lvl.mNumFaces; u++) {
bsp_face_t* face = &q3lvl.mFaces[u];
if (face->type == BSP_FACETYPE_NORMAL)
{
_manualObject->begin("EmptyMaterial", Ogre::RenderOperation::OT_TRIANGLE_LIST);
for(int j=face->vert_start; j<face->vert_start+face->vert_count; j++){
_manualObject->textureCoord(q3lvl.mVertices[j].texture[0], q3lvl.mVertices[j].texture[1]);
_manualObject->normal(q3lvl.mVertices[j].normal[0], q3lvl.mVertices[j].normal[1], q3lvl.mVertices[j].normal[2]);
_manualObject->position(q3lvl.mVertices[j].point[0], q3lvl.mVertices[j].point[1], q3lvl.mVertices[j].point[2]);
}
for(int j=face->elem_start; j<face->elem_start+face->elem_count; j++){
_manualObject->index(static_cast<unsigned short>(q3lvl.mElements[j]));
}
_manualObject->end();
}
}
_mesh = _manualObject->convertToMesh("BspMesh", "General");
_mesh->buildTangentVectors();
_mesh->buildEdgeList();
return _mesh;
}
You have to call it in the end of BspLevel::loadQuake3Level.
And this is my code to load the BSP mesh :
Entity *bspEntity = mSceneMgr->createEntity("BspEntity", "BspMesh");
SceneNode *bspNode = mSceneMgr->createSceneNode("BspNode");
bspNode->attachObject(bspEntity);
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* bspParser = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(mWorld);
OgreNewt::CollisionPtr bspParserPtr = OgreNewt::CollisionPtr(bspParser);
bspParser->parseScene( bspNode, -1, true );
OgreNewt::Body *bspBody = new OgreNewt::Body(mWorld, bspParserPtr);
bspBody->attachNode(bspNode);
Ogre::AxisAlignedBox box = bspParser->getAABB(Quaternion::IDENTITY, Vector3(0,0,0));
mWorld->setWorldSize(box);
Now, I have to find out how to load patches (curves, bezier,...) correctly and the problem will be solved
Would I have to send every faces to a TreeCollision by modifying a bit the BSPSceneLoader ?
Thanks.