// vytvori skinedmesh slozeny z vybranych dilu zdrojoveho meshe
		// source <- animated mesh bez zavolani metody finalize()
		// parts <- ukazatel na pole èástí
		// partsCount <- poèet èástí (velikost pole)
		ISkinnedMesh * makeMeshFromParts(WowKlient::Core::GameState * gState, IAnimatedMesh * source, int partsCount, int * parts)
		{
			ISkinnedMesh * skinned = (ISkinnedMesh *)source;

			ISkinnedMesh * clone = gState->irrDevice->getSceneManager()->createSkinnedMesh();

			for (int i = 0; i < partsCount; i++)
			{
				SSkinMeshBuffer * buf = clone->addMeshBuffer();

				buf->recalculateBoundingBox();
				buf->setDirty();

				for (u32 j = 0; j < ((SSkinMeshBuffer*)source->getMeshBuffer(parts[i]))->getVertexCount(); j++)
				{
					S3DVertex * v = new S3DVertex(*((SSkinMeshBuffer*)source->getMeshBuffer(parts[i]))->getVertex(j));
					buf->Vertices_Standard.push_back(*v);
				}

				for (u32 j = 0; j < ((SSkinMeshBuffer*)source->getMeshBuffer(parts[i]))->getIndexCount(); j++)
				{
					buf->Indices.push_back(u16(((SSkinMeshBuffer*)source->getMeshBuffer(parts[i]))->getIndices()[j]));
				}

				buf->Material = ((SSkinMeshBuffer*)source->getMeshBuffer(parts[i]))->getMaterial();


			}

			parseJointParents(clone, skinned->getAllJoints()[0], 0);

			for (u32 i = 0; i < skinned->getJointCount(); i++)
			{
				ISkinnedMesh::SJoint * joint;
				joint = clone->getAllJoints()[clone->getJointNumber(skinned->getAllJoints()[i]->Name.c_str())];

				for (u32 j = 0; j < skinned->getAllJoints()[i]->Weights.size(); j++)
				{
					s32 buffer = validPart(skinned->getAllJoints()[i]->Weights[j].buffer_id, partsCount, parts);
					if (buffer >= 0)
					{
						ISkinnedMesh::SWeight * w = clone->addWeight(joint);
						w->buffer_id = buffer;
						w->strength = skinned->getAllJoints()[i]->Weights[j].strength;
						w->vertex_id = skinned->getAllJoints()[i]->Weights[j].vertex_id;
					}
				}

			}

			clone->finalize();

			return clone;
		}
// render
// override render state
void CGameAnimatedMeshSceneNode::render()
{
#ifdef GSEDITOR
	CGameObject::EObjectState state = m_owner->getObjectState();
	
	// draw bbox on select
	if ( 
			state == CGameObject::Move ||
			state == CGameObject::Review		
		)
		setDebugDataVisible( EDS_BBOX );
	else
		setDebugDataVisible( 0 );

	// call object draw
	m_owner->drawObject();	
#endif

	// draw animesh
	CAnimatedMeshSceneNode::render();

#ifdef GSANIMATION		
	// get driver
	IVideoDriver* driver = getSceneManager()->getVideoDriver();

	ISkinnedMesh *mesh = (ISkinnedMesh*)getMesh();
	IView *pView = getIView();

	irr::gui::IGUIFont* font = getSceneManager()->getGUIEnvironment()->getBuiltInFont();

	video::SMaterial debug_mat;
	debug_mat.Lighting = false;
	debug_mat.AntiAliasing = 0;
	debug_mat.ZBuffer = video::ECFN_NEVER;
		
	for (u32 g=0; g < mesh->getAllJoints().size(); ++g)
	{
		ISkinnedMesh::SJoint *joint = mesh->getAllJoints()[g];
		core::vector3df v;
		
		//basic bone
		//core::matrix4 mat1 = joint->GlobalInversedMatrix;
		//mat1.makeInverse();

		//anim bone
		core::matrix4 mat1 = joint->GlobalAnimatedMatrix;

		// get position
		mat1.transformVect( v );
		
		// scale with character
		v *= m_owner->getScale();

		// draw name bone on screen
		int x, y;
		pView->getScreenCoordinatesFrom3DPosition( v, &x, &y );
		wchar_t text[1024];
		uiString::copy<wchar_t, const c8>( text, joint->Name.c_str() );		
		
		// draw bone position
		SColor c = SColor(255,0,0,255);	
		driver->setMaterial(debug_mat);
		driver->draw2DRectangle( c, core::rect<s32>( x - 2, y - 2, x + 2, y + 2 ) ); 

		// draw text
		font->draw( text, core::rect<s32>( x + 10, y, x + 100, y + 50), SColor(255, 255,255,0) );
	}
#endif

#ifdef GSEDITOR	
	// draw move
	if ( 
			state == CGameObject::Move || 
			state == CGameObject::Rotation ||
			state == CGameObject::Scale
		)
		m_owner->drawFrontUpLeftVector();	
	
	if ( state == CGameObject::Rotation )
		m_owner->drawCircleAroundObject();	
#endif

}