BSP Solution

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 :

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 :D

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.

neoranga974

26-08-2009 07:53:38

Man i feel very good when i see those white lines, this makes me think "all is woking fine" :p

Jorisma

25-10-2009 19:08:36

How can use your Func correctly ??
I mean how can my SceneManager* send to BspLevel class ?
and your Func has return value but you don't use it in your code.

I want to make BspMesh like you..
but i am totally new to Ogre3D.
Please help me

nand

29-03-2010 19:14:32

How do I use this with Mogre? I can't seem to access the Quake3Level type anywhere.

Failing that, is there a C# script out there that lets me parse a .bsp file manually?

Edit: Oh nevermind, I get it now. The mesh is loaded into an available mesh (named BspMesh) inside the Plugin_BSPSceneManager.dll.
I would very greatly appreciate it if somebody could add those lines to the manager and rebuild it (v1.6), so I can use the .dll with Mogre.

rush

19-05-2010 17:14:00

mmm, I can't make it work..here's my code, there is something wrong?
m_World = new OgreNewt::World();
ConvertToMesh();
Entity *bspEntity = mSceneMgr->createEntity("BspEntity", "BspMesh");
SceneNode *bspNode = mSceneMgr->createSceneNode("BspNode");
bspNode->attachObject(bspEntity);


OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* bspParser = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(m_World);
OgreNewt::CollisionPtr bspParserPtr = OgreNewt::CollisionPtr(bspParser);
bspParser->parseScene( bspNode, -1, true );
OgreNewt::Body *bspBody = new OgreNewt::Body(m_World, bspParserPtr);
bspBody->attachNode(bspNode);

Ogre::AxisAlignedBox box = bspParser->getAABB(Quaternion::IDENTITY, Vector3(0,0,0));
m_World->setWorldSize(box);


the VC express 2008 debugges stops here:
void TreeCollisionSceneParser::_parseNode(Ogre::SceneNode *node, const Ogre::Quaternion &curOrient, const Ogre::Vector3 &curPos, const Ogre::Vector3 &curScale, FaceWinding fw)
{
// parse this scene node.
// do children first.
Ogre::Quaternion thisOrient = curOrient * node->getOrientation();
Ogre::Vector3 thisPos = curPos + (curOrient * (node->getPosition() * curScale));
Ogre::Vector3 thisScale = curScale * node->getScale();

Ogre::SceneNode::ChildNodeIterator child_it = node->getChildIterator();

while (child_it.hasMoreElements())
{
_parseNode( (Ogre::SceneNode*)child_it.getNext(), thisOrient, thisPos, thisScale, fw );
}


thank you.

SFCBias

22-05-2010 13:11:52

What version on OgreNewt do you have and are you running windows or Linux. I ask because i fixed this problem on Linux by compiling OgreNewt agains Newton 2.19 which you can find here. I think the same fix should work on Windows as well.

skylabs

16-12-2010 22:00:47

Hello,

first sorry for my poor english, i'm french.

Actually, I'm creating a small game for a projet. (Collision in a map *.BSP). The programmation language is C# with the wrapper Mogre.

I've search for BSP parsing, BSP collision for MogreNewt and Mogre but nothing on the internet. (Source or tutorial with Mogre)

For this reason, i have try to convert the C++ Code to C#. Unfornately, i don't undestand this line and can not convert:

Ogre::MeshPtr BspLevel::ConvertToMesh(const Quake3Level& q3lvl) {...

Can you help me?



More below, i can read this:
Edit: Oh nevermind, I get it now. The mesh is loaded into an available mesh (named BspMesh) inside the Plugin_BSPSceneManager.dll.
I would very greatly appreciate it if somebody could add those lines to the manager and rebuild it (v1.6), so I can use the .dll with Mogre.

If it's true, how can we access to this "Available mesh" ?

Thanks.

Je vous remercie d'avance =)