Getting a mesh from .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.
Post Reply
Alex Stan
Posts: 4
Joined: Sat Jun 09, 2007 5:00 pm

Getting a mesh from .irr file

Post by Alex Stan »

Hello,

I would like to do a triangle selector for scene loaded from a .irr file. I successfully got a pointer to the node i am interested in but i can't seem to get a pointer to the mesh. I need a pointer to the mesh so i can use it when calling the createOctTreeTriangleSelector function.

Is there a way to get the pointer to the mesh or is there an easyer way to do a triangle selector for a .irr file?
Alex Stan
Posts: 4
Joined: Sat Jun 09, 2007 5:00 pm

Post by Alex Stan »

News:
I discovered that i can use getMeshByIndex(0) (My mesh id in irredit is 0)
Problem is that i don't know how i can properly call the function. I tried smgr.getMeshByIndex(0); but it didn't work

In the documentation it says that the function is part of IMeshCache but i'm not that used to classes. I'm not use how to use it.
Alex Stan
Posts: 4
Joined: Sat Jun 09, 2007 5:00 pm

Post by Alex Stan »

Nevermind, i figured it out:

Code: Select all

	// load the scene
	smgr->loadScene("main.irr");

	// prepare node & mesh for triangle selector(get the pointer)
	scene::ISceneNode* node = node=smgr->getSceneNodeFromId(0);
	scene::IAnimatedMesh* mesh = smgr->getMeshCache()->getMeshByIndex(0);

	//triangle selector
	scene::ITriangleSelector* selector = 0;
	if (node)
	{		
		selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0),node,128);
		node->setTriangleSelector(selector);
		selector->drop();
	}

	// add a user controlled camera with collision response
	scene::ICameraSceneNode* camera = 	
		camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
	camera->setPosition(core::vector3df(0,1000,0));

	scene::ISceneNodeAnimator* anim =
    smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(30,50,30),
		core::vector3df(0,-0.5,0),
		core::vector3df(0,5,0));

	camera->addAnimator(anim);
	anim->drop();
Viniterra
Posts: 12
Joined: Sun Dec 17, 2006 5:44 am

Post by Viniterra »

Hi Alex
Your code helped me to add collision to my irr file.
But I have a problem, the map is duplicated. I have the version I created with the smgr->loadScene(), and the mesh I setted up with the command
scene::ISceneNode* node = node=smgr->getSceneNodeFromId(0);
is there any way to delete the map created with the loadscene, and let the map with the collision response?
Or is there any other way to add collision to an irr file, without duplicate it?

By the way, I have the .obj of my map, I ussually use it instead of the .irr, but I cant load the file with textures.

Thanks.
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

@Alex Stan
Nice work figuring it out for yourself, you got further with .irr files than I ever did :D

@Viniterra
You can add collision to an .irr file, there's plenty of people in Beginners Help who have asked and gotten answers, so the search and look for something like "collision .irr" and you should find what your after
Tell me what you cherish most. Give me the pleasure of taking it away.
TheMiss
Posts: 14
Joined: Sun Apr 15, 2007 6:46 pm

Post by TheMiss »

vitek has already posted code how to do that at http://irrlicht.sourceforge.net/phpBB2/ ... sc&start=0

certainly! it's quite perfect. from the link I recommend you to use smgr->smgr->createTriangleSelectorFromBoundingBox();
instead of all smgr->createTriangleSelector(msn->getMesh(), msn) :lol:

sorry for my bad english :wink:
Post Reply