Page 1 of 1

Getting a mesh from .irr file

Posted: Sat Jun 09, 2007 5:04 pm
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?

Posted: Sat Jun 09, 2007 5:33 pm
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.

Posted: Sat Jun 09, 2007 5:48 pm
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();

Posted: Sat Jun 09, 2007 10:38 pm
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.

Posted: Sat Jun 09, 2007 11:25 pm
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

Posted: Sun Jun 10, 2007 12:52 am
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: