How to use parseScene method With DotScenemanager? [SOLVED]

ProfesorX

22-09-2006 03:07:09

Hi friends, i am trying to use a FPS collision camera and TreeCollisionSceneParser::parseScene to parse a DotScene file so i can get the geometry of my level added to the physics simulation, and, in that way, get "simple" collision detection with walls/objects and camera movement using forces.

At the moment, i've been succesful using the code from here and now i have a camera moved with forces :), but then, when i try to add my level, using parseScene, still get no collisions :(.

I used the following code:


void IntroState::enter()
{
mInputDevice = INPUT_MGR.getInputDevice();

mRoot = Root::getSingletonPtr();

mSceneMgr = mRoot->getSceneManager(ST_GENERIC);

OgreNewt::Debugger::getSingleton().init(mSceneMgr);

mMoveScale = 1.0f;
mRotScale = 10.0f;
mRotateSpeed = 360;
mMoveSpeed = 100;
mTranslateVector = Vector3::ZERO;
mRotX = mRotY = 0;

// Creacion de la camara
mCamera = mSceneMgr->createCamera("IntroCamera");
mCamera->setPosition(Vector3(0.0, 0.0, 0.0));
mCamera->setNearClipDistance(5);

mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera);

exitGame = false;
mResGroup=loadScene("escenario.esc");

// Añadir el modelo del ninja
Entity *ent = mSceneMgr->createEntity("ninja", "ninja.mesh");
mNinjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode");//, Ogre::Vector3(50.0, 0.0, 0.0));
mNinjaNode->attachObject(ent);
mNinjaNode->setScale(0.15, 0.15, 0.15);

// Rotar el ninja para que quede de frente a la camara
mNinjaNode->yaw(Degree(180));

// Añadido Por ProfesorX
mPositionOverlay = Ogre::OverlayManager::getSingleton().getByName("PositionOverlay");
if (mPositionOverlay)
{
mPositionOverlay->show();
}
// Fin

// using the new "SceneParser" TreeCollision primitive. this will automatically parse an entire tree of
// SceneNodes (parsing all children), and add collision for all meshes in the tree.
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* m_ColSceneParser = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(mWorld);
m_ColSceneParser->parseScene(mSceneMgr->getRootSceneNode(), true);
OgreNewt::Body* bod = new OgreNewt::Body( mWorld, m_ColSceneParser );
delete m_ColSceneParser;

bod->attachToNode( mSceneMgr->getRootSceneNode() );
bod->setPositionOrientation( Ogre::Vector3(0.0,0.0,0.0), Ogre::Quaternion::IDENTITY );

mBodyCam = new CollisionCamera(mSceneMgr, mWorld, mCamera);
mBodyCam->createPhysicsCamera();
mBodyCam->setPositionOrientation(Ogre::Vector3(0,-35,50),Ogre::Quaternion::IDENTITY);
mRoot->startRendering();
}



It appears that only the ninja is added to OgreNewt, because i get debuglines only for the ninja and not all geometry, but even in the case of the ninja, can't get collision detection, so i can pass with the camera through it.

Is there something that i'm missing?

I am using 3D-Max/oFusion to get level, converting later to DotSceneFormat, and using DotSceneManager plugin.

Thanks in advance, and i'm sorry if i don't write correctly in english :)

walaber

22-09-2006 04:39:52

is the .scene node structure being added as a child to the root scene node?

ProfesorX

23-09-2006 02:47:34

I supose that the following code add the .scene node structure as a child of the Root Scene Node? (I don't put all the code, only a part, but is complete and taken from DotSceneManager Plugin)


....
if( XMLNodes )
{
TiXmlElement *XMLNode, *XMLPosition, *XMLRotation, *XMLScale, *XMLEntity, *XMLBillboardSet, *XMLLight;

XMLNode = XMLNodes->FirstChildElement( "node" );

while( XMLNode )
{
// Process the current node
// Grab the name of the node
String NodeName = XMLNode->Attribute("name");
// First create the new scene node
SceneNode* NewNode = static_cast<SceneNode*>( mSceneMgr->getRootSceneNode()->createChild( NodeName ) );

Vector3 TempVec;
String TempValue;

// Now position it...
XMLPosition = XMLNode->FirstChildElement("position");
if( XMLPosition )
{
TempValue = XMLPosition->Attribute("x");
TempVec.x = StringConverter::parseReal(TempValue);
TempValue = XMLPosition->Attribute("y");
TempVec.y = StringConverter::parseReal(TempValue);
TempValue = XMLPosition->Attribute("z");
TempVec.z = StringConverter::parseReal(TempValue);
NewNode->setPosition( TempVec );
}
...


Also as you can see, in the code of the first post the mNinjaNode is added as a child of root, but no collisions
if you need all the code, then i post it

ProfesorX

01-10-2006 22:31:49

I finally get collision with OgreNewt using DotSceneManager Plugin, so, to anyone asking how, i put the code that does the miracle (very simple) :)



mSceneMgr = (DotSceneManager *) mRoot->getSceneManager(ST_GENERIC);

int numMeshes = mSceneMgr->GetNumMeshes(NULL);
for (int meshIndex = 0; meshIndex < numMeshes; meshIndex++)
{
OgreNewt::CollisionPrimitives::TreeCollision* col_dotscene
= new OgreNewt::CollisionPrimitives::TreeCollision
(mWorld,
mSceneMgr->GetNumVertices(NULL, meshIndex),
mSceneMgr->GetNumIndex(NULL, meshIndex),
mSceneMgr->GetVerticesPtr(NULL, meshIndex ),
mSceneMgr->GetIndexPtr(NULL, meshIndex),
true);
OgreNewt::Body* bod = new OgreNewt::Body(mWorld, col_dotscene);
delete col_dotscene;
}


Thanks Walaber for this great Wrapper for Newton And Ogre ;)

Dirso

27-05-2007 21:31:25

I updated the code to work with Eihort (based on jacmoe's code), looks like it's work due to the low number of polygons I'm having right now:

int numMeshes;
mSceneMgr->getOption("NumMeshes", &numMeshes);
for (int meshIndex = 0; meshIndex < numMeshes; meshIndex++)
{
int numVerts = 0;
mSceneMgr->getOption("NumVertices" + StringConverter::toString(meshIndex), &numVerts);
int numIndices = 0;
mSceneMgr->getOption("NumIndex" + StringConverter::toString(meshIndex), &numIndices);
float* vertPtr = 0;
mSceneMgr->getOption("VerticesPtr" + StringConverter::toString(meshIndex), &vertPtr);
int* indicesPtr = 0;
mSceneMgr->getOption("IndexPtr" + StringConverter::toString(meshIndex), &indicesPtr);
OgreNewt::CollisionPrimitives::TreeCollision* col_dotscene
= new OgreNewt::CollisionPrimitives::TreeCollision
(m_World,numVerts,numIndices,vertPtr,indicesPtr, true);
OgreNewt::Body* bod = new OgreNewt::Body(m_World, col_dotscene);
delete col_dotscene;
}


@ProfesorX: I spent one week trying to make DotSceneOctree work with NxOgre and to put NxOgre to work at all. Your code saved my life and convinced me to change to OgreNewt and I'm happy with it :)

@walaber: You're the man!!! You have no idea how much I'm learning with your code!! Thank you very much!!!

Dirso

dudeabot

27-12-2007 23:11:59

that code is not working for me

if i use scenemanager->getkeys()
it returns a 0 sized vector, i think i need plugin_dotSceneManager.dll but cant find anywhere!

Dirso

28-12-2007 12:24:55

i think i need plugin_dotSceneManager.dll but cant find anywhere!It's on addon's cvs.

dudeabot

28-12-2007 14:37:04

which one?

if it is dotsceneoctree, that folder doenst exists anymore :(

Dirso

28-12-2007 14:52:45

which one?

if it is dotsceneoctree, that folder doenst exists anymore :(
PM me your email and I'll send it to.