Page 1 of 1

how to highlight part of mesh?

Posted: Fri Jan 07, 2011 10:19 pm
by openglman
Hi,

I have a model that I created in milkshape that has 3 groups. I export the model as a DirectX .x file format and load it using irrlicht.

All of the groups are loaded as Joints which is great. I applied a shader to the entire mesh just to test and it worked great. Now what I want to do is get one of the joint nodes and apply a shader only to that joint. So I tried the following:

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("../../media/test.x");
IAnimatedMeshSceneNode* mynode = smgr->addAnimatedMeshSceneNode( mesh );
ISkinnedMesh* smesh = static_cast<irr::scene::ISkinnedMesh*>(mesh);
ISceneNode* tank = mynode->getJointNode("tanks");
if(tank)
{
  tank->setMaterialFlag(EMF_LIGHTING, false);
  tank->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType2);
}
The tank node is retrieved successfully, but when I try to apply my shader to the tank joint node it fails because it says my tank scenenode has a material count of 0. I used separate textures for each group in my model so I am not sure why it is saying that the material count is 0 for my joint nodes.

Is it possible to apply a shader to a joint node? Or should I be trying a different approach to highlight only portions of a model?

Thanks

Posted: Fri Jan 07, 2011 10:40 pm
by hybrid
Well, the animation and joint system in Irrlicht works differently. The animated mesh has several mesh buffers, at least for each material and each animated segment one. The joint node that you get in return from the method is a dummy node. It lets you attach other scene nodes as childs. The meshbuffers of the mesh are also moved along with the joints, but there's no direct relation between the joints and the materials of the meshbuffers. You need to find those on your own, maybe the joint sytem can also give hints for this.

Posted: Sat Jan 08, 2011 12:01 am
by openglman
Thank you so much! You were 100% correct! I managed to use the joint system in conjunction with the meshbuffer collection to use shaders on separate groups of the model!! Here is my code in case anyone else ever has this same problem. I basically just added the below code to the shaders example to get my desired effect.

Code: Select all

	IAnimatedMesh* mesh = smgr->getMesh("../../media/test.x");
	if (!mesh)
	{
		device->drop();
		return 1;
	}

	IMeshSceneNode* mynode = smgr->addMeshSceneNode( mesh );


	ISkinnedMesh* smesh = static_cast<irr::scene::ISkinnedMesh*>(mesh);
	//start at 1 cuz first joint is scene root
	//we want to skip that one for our purposes
	for(int i=1; i<smesh->getJointCount(); i++)
	{
		int materialindex = i-1;
		int jointindex = i;
		stringc str = smesh->getJointName(jointindex);
		if(strcmpi(str.c_str(), "tanks")==0)
		{
			mynode->getMaterial(materialindex).MaterialType = (video::E_MATERIAL_TYPE)newMaterialType2;
			mynode->getMaterial(materialindex).setFlag(EMF_LIGHTING, false);
		}
	}

	smgr->addCameraSceneNode(0, vector3df(0,0,180), vector3df(0,0,0));
	mynode->setScale(vector3df(15.0, 15.0, 15.0));
	mynode->setMaterialFlag(EMF_LIGHTING, false);