Collsion with irr file

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
kiranmaya
Posts: 31
Joined: Tue Jan 30, 2007 9:10 am

Collsion with irr file

Post by kiranmaya »

i have seen all the collision related topic in this forum,and i find one,but that code is only apllicable for one and only one single octtree mesh...what about other meshes that i include in the file..............
............
.....
give plz me complete code from
smgr->loadscene(string);
to
drop

is .irr is best for level or .bsp
if .bsp best then tell a compiler for Maya to create BSP"S or an export plugin or an mel ..
.....
...
ofcourse there is alternative....
from MAya to Ac3d to quakemsp to gradient to gmax tempest
it's is very lenghty process..........and i don't create any single cube bsp
.......
.....
............................
..................................................................
kompromis
Posts: 98
Joined: Mon Sep 11, 2006 2:36 pm
Location: sweden/stockholm

Post by kompromis »

you can alwas load a .irr file then finde the nodes by using getSceneNodeFromName(const c8 *);
kiranmaya
Posts: 31
Joined: Tue Jan 30, 2007 9:10 am

Post by kiranmaya »

so,i have to call each and every mesh in irr file?

is there is any alternative
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You have to setup collision information for everything that is collidable. There is no other option. The nice thing is that you only have to write a few functions for setting up the collisions, and then you just call those functions for every node in the scene graph. It is not like you need to write pages of code.

Travis
kiranmaya
Posts: 31
Joined: Tue Jan 30, 2007 9:10 am

Post by kiranmaya »

i have seen this level example from this forum only,he just assin collision for octree mesh ,but not,but collision is applied all other meshes ..how is it
is possible..................

note :-i have to found that all object's are inside the octree .obj mesh,not the child nodes to octree

here is the code




smgr->loadScene("media/levels/ship.irr");

/*
That was it already. Now add a camera and draw the scene
*/

// add a user controlled camera

ISceneNode* scene_node = smgr->getSceneNodeFromName("SpaceShip");

scene::ICameraSceneNode* camera;
if (scene_node && scene_node->getType() == ESNT_OCT_TREE)
{
irr::io::IAttributes* attribs = device->getFileSystem()->createEmptyAttributes();
if (attribs)
{
scene_node->serializeAttributes(attribs);

// get the mesh name out
core::stringc mesh_name = attribs->getAttributeAsString("Mesh");
const c8 *meshName = mesh_name.c_str();
attribs->drop();

// get a mesh from the name
IAnimatedMesh* mesh = smgr->getMesh(meshName);

ITriangleSelector* selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), scene_node, 128);
scene_node->setTriangleSelector(selector);

camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(-30,15,4));

scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(3,3,3),
core::vector3df(0,-1,0),
core::vector3df(0,6,0));
camera->addAnimator(anim);
anim->drop();

selector->drop();

}
}




.........plz can any 1 tell me a single function which is applicable to all meshes that include in .irr..................
..and bye the way ,plz treat me as baby in irrlicht and C++
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Like I said, there is no single function. You have to write the code. Well, I guess now I've written the code...

Code: Select all

void ISceneNode_assignTriangleSelector(scene::ISceneNode* node, scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
  if (!node || !smgr || !ifs)
    return;

  if (node->getType() == scene::ESNT_OCT_TREE)
  {
    io::IAttributes* attribs = ifs->createEmptyAttributes();
    if (attribs)
    {
      node->serializeAttributes(attribs);

      // get the mesh name out 
      core::stringc name = attribs->getAttributeAsString("Mesh"); 

      attribs->drop();

      // get the animated mesh for the object
      scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
      if (mesh)
      { 
        scene::ITriangleSelector* selector =
          smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128); 
        node->setTriangleSelector(selector);
        selector->drop();
      }
    }
  }
  else if (node->getType() == scene::ESNT_MESH)
  {
    scene::IMeshSceneNode* msn = (scene::IMeshSceneNode*)node;

    if (msn->getMesh())
    {
      scene::ITriangleSelector* selector =
        smgr->createTriangleSelector(msn->getMesh(), msn);
      msn->setTriangleSelector(selector);
      selector->drop();
    }
  }
  else if (node->getType() == scene::ESNT_ANIMATED_MESH)
  {
    scene::IAnimatedMeshSceneNode* msn = (scene::IAnimatedMeshSceneNode*)node;

    scene::IAnimatedMesh* am = msn->getMesh();
    if (am)
    {
      scene::ITriangleSelector* selector =
        smgr->createTriangleSelector(am->getMesh(0), msn);
      msn->setTriangleSelector(selector);
      selector->drop();
    }
  }
  else if (node->getType() == scene::ESNT_TERRAIN)
  {
    scene::ITerrainSceneNode* tsn = (scene::ITerrainSceneNode*)node;

    scene::ITriangleSelector* selector =
      smgr->createTerrainTriangleSelector(tsn, 0); // probably don't want lod 0 all the time...
    tsn->setTriangleSelector(selector);
    selector->drop();
  }
  else if (node->getType() == scene::ESNT_CUBE)
  {
    scene::ITriangleSelector* selector =
      smgr->createTriangleSelectorFromBoundingBox(node);
    node->setTriangleSelector(selector);
    selector->drop();   
  }
  else
  {
    // not something we want to collide with
  }
}

void ISceneNode_assignTriangleSelectors(scene::ISceneNode* node, scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
  // assign a selector for this node
  ISceneNode_assignTriangleSelector(node, smgr, ifs);

  // now recurse on children...
  core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
  core::list<scene::ISceneNode*>::ConstIterator end   = node->getChildren().end();

  for (/**/; begin != end; ++begin)
    ISceneNode_assignTriangleSelectors(*begin, smgr, ifs);
}

void ISceneManager_assignTriangleSelectors(scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
  ISceneNode_assignTriangleSelectors(smgr->getRootSceneNode(), smgr, ifs);
}
Now you can create a triangle selector for most scene node types. I would probably split that function up a bit and maybe write some code to see if the nodes were supposed to get collision information generated at all, but you should be able to figure it out on your own. Now all you need to do now is create a meta selector for those selectors.

Code: Select all

void ISceneNode_gatherTriangleSelectors(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta)
{
  scene::ITriangleSelector* selector = node->getTriangleSelector();
  if (selector)
    meta->addTriangleSelector(selector);

  // now recurse on children...
  core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
  core::list<scene::ISceneNode*>::ConstIterator end   = node->getChildren().end();

  for (/**/; begin != end; ++begin)
    ISceneNode_gatherTriangleSelectors(*begin, meta);
}

void ISceneManager_gatherTriangleSelectors(scene::ISceneManager* smgr, scene::IMetaTriangleSelector* meta)
{
  ISceneNode_gatherTriangleSelectors(smgr->getRootSceneNode(), meta);
}
And you'd use the code like this...

Code: Select all

  // recursively assign selectors to nodes

  ISceneManager_assignTriangleSelectors(smgr, device->getFileSystem());

  // recursively gather triangle selectors into a meta selector

  scene::IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector();
  ISceneManager_gatherTriangleSelectors(smgr, meta);

  // add a user controlled camera

  scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();

  // create collision response using all objects for collision detection

  scene::ISceneNodeAnimator* anim =
    smgr->createCollisionResponseAnimator(meta, camera, core::vector3df(30,30,30), core::vector3df(0,-1,0), core::vector3df(0,6,0)); 
    camera->addAnimator(anim); 
  anim->drop(); 

  // drop the meta selector. it is owned by the animator
  meta->drop();
Travis
Last edited by vitek on Sun Jul 06, 2008 3:08 am, edited 3 times in total.
kiranmaya
Posts: 31
Joined: Tue Jan 30, 2007 9:10 am

Post by kiranmaya »

thanks ....................not thanks ,more than that....this information is enough for me............U R THE MAN .................


bye the way ..have u developed any games .................
...........
.
...
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

kiranmaya, dou you have a braille translator in your browser, or do you use very small letters? You r posts are full of dots that don't make any sense to me. So pardon me if it's indeed an accessibility enhancement, but otherwise it would save lots of space and make your posts at least a little more readable if you just leave them out.
kiranmaya
Posts: 31
Joined: Tue Jan 30, 2007 9:10 am

Post by kiranmaya »

sorry,i don't know english well, i have my questions ,that's i keep .....
it's is very nasty to waste such a space and bytes in server
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

Post by Eldritch »

I am in the middle of trying to port your code to C#, but I have ran into major problems.

- There is no equivalence of ESNT_OCT_TREE.
- There is no Attributes class and no CreateEmptyAttributes in FileSystem.
- There is no MeshSceneNode, only AnimatedMeshSceneNode.

Am I blind or is it so that these have not been ported over to Irrlicht.NET (using Irrlicht .NET CP)?

Update: also found out that it is not possible to convert a SceneNode to an AnimatedMeshSceneNode for some dang reason... :(

Update: I vote that the LoadScene() function returns a reference/pointer to an Irr class/structure. Would make things so much easier.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm guessing that most of this stuff isn't in the .net version. Is there a reason that you can't add it yourself?
I vote that the LoadScene() function returns a reference/pointer to an Irr class/structure. Would make things so much easier.
Really? Why? What makes you think this would make anything easier. The loadScene method loads the scene into the scene manager's scene graph. All you need to do to get that scene graph is get the root scene node from the scene manager.

Travis
Chemist
Posts: 3
Joined: Tue Apr 03, 2007 6:26 pm

Post by Chemist »

It is strange to me, but this code don't working properly:
(I used Vitek's collision code):

Code: Select all

 smgr->loadScene("MainTown.irr",0); //my irr file, it contains only static meshes (.3ds), but I tried also example.irr - the same result 
  ISceneManager_assignTriangleSelectors(smgr, device->getFileSystem()); //Although  all meshes have type ESNT_MESH, "else if (node->getType() == scene::ESNT_ANIMATED_MESH) " skiped
  scene::IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector(); 
  ISceneManager_gatherTriangleSelectors(smgr, meta); 
  scene::ICameraSceneNode* camera = smgr->   addCameraSceneNodeFPS(0,50,10); 
  camera->setPosition(core::vector3df(20,4,30)); 
  scene::ISceneNodeAnimator* anim = 
	  smgr->createCollisionResponseAnimator(meta, camera,
	  core::vector3df(3,3,3), 
	  core::vector3df(0,0,0), 
	  core::vector3df(0,6,0));  
  camera->addAnimator(anim);  
  anim->drop(); 
  meta->drop(); 	
I tried everything (?), but result the same - no collision at all.
PS I'm appologizing for my bad English.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If you are using Irrlicht 1.3, there is a bug that causes the code to not work. You can find details about that bug here.

Travis
Chemist
Posts: 3
Joined: Tue Apr 03, 2007 6:26 pm

Post by Chemist »

But if I execute directly

Code: Select all

    scene::IMeshSceneNode* msn = (scene::IMeshSceneNode*)node;
 	scene::ITriangleSelector* selector = 
	 smgr->createTriangleSelector(msn->getMesh(), msn); 
	 msn->setTriangleSelector(selector);    
	 selector->drop();    
"Unhandled exception at 0x100bc75d in 15.LoadIrrFile.exe: 0xC0000005: Access violation reading location 0x00720069." appeared. What can I do?
Last edited by Chemist on Wed Apr 04, 2007 1:43 pm, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Well, unless you know with 100% certainty that node is actually an IMeshSceneNode you cannot cast the pointer like that. If it is actually some other type, then you will get a crash, just like you say you are getting.

If you are unable to fix the problem yourself, or use the SVN version of Irrlicht, I suggest you go back to using Irrlicht 1.2.

Travis
Post Reply