void CAnimationInstance::DrawMeshFrame( D3DXFRAME_ANIM * pFrame)
{
	//! TODO: Insert code to draw the mesh here.
	HRESULT hr = S_OK;
	D3DXFRAME_ANIM * pAnimFrame = pFrame;
	D3DXMESHCONTAINER_ANIM * pMeshContainer = (D3DXMESHCONTAINER_ANIM *)pFrame->pMeshContainer;
	CShader* pShader;
	CMaterial* pMat;

	unsigned int uiAttrib;
	LPD3DXBONECOMBINATION pBoneCombination;

	unsigned int uiMatrixIndex;
	unsigned int uiPaletteEntry;
	D3DXMATRIXA16 matrixTemp;
	D3DCAPS9 d3dCaps;
	m_pAnimatedMesh->m_pD3DDevice->GetDeviceCaps(&d3dCaps);

	//! Check to see that there is Skinning Information
	if( pFrame->pMeshContainer->pSkinInfo != NULL)
	{
		//! Draw via Indexed HLSL VertexShader
		pBoneCombination = reinterpret_cast<LPD3DXBONECOMBINATION>(pMeshContainer->pBoneCombinationBuffer->GetBufferPointer());

		for( uiAttrib = 0; uiAttrib < pMeshContainer->NumAttributeGroups; uiAttrib++)
		{
			//! Calculate all the world matrices.
			for( uiPaletteEntry = 0; uiPaletteEntry < pMeshContainer->NumPaletteEntries; uiPaletteEntry++)
			{
				uiMatrixIndex = pBoneCombination[uiAttrib].BoneId[uiPaletteEntry];

				if( uiMatrixIndex != UINT_MAX)
				{
					D3DXMatrixMultiply( &m_pAnimatedMesh->m_pBoneMatrices[uiPaletteEntry], &pMeshContainer->pBoneOffsetMatrices[uiMatrixIndex], pMeshContainer->ppBoneMatrixPointers[uiMatrixIndex]);
				}
			}

			// Draw Mesh
			// (MR): Modified rendering code to work with shader management
			if(uiAttrib < pMeshContainer->NumMaterials)
				pMat = pMeshContainer->ppMaterials[uiAttrib];
			else
				pMat = pMeshContainer->ppMaterials[0];
			pShader = pMat->getShader();
			CShaderParam& oMatWorldArray = pShader->getParamBySemantic("WorldMatrixArray");
			if(oMatWorldArray.isValid())
				oMatWorldArray.setMatrixArray(m_pAnimatedMesh->m_pBoneMatrices, pMeshContainer->NumPaletteEntries);
			CShaderParam& oBoneCount = pShader->getParamBySemantic("BlendIndexCount");
			if(oBoneCount.isValid())
				oBoneCount = pMeshContainer->NumInfl - 1;

			//! Start Effect.  All parameters should be updated at this point.
			CShaderManager::getInstance().beginObjectRender();

			pMat->begin();
			for(unsigned int uiPass = 0; uiPass < pMat->getNumPasses(); uiPass++)
			{
				CShaderManager::getInstance().beginPass();
				pMat->beginPass(uiPass);
				//! Draw the subset with the current material and world matrix palette
				pMeshContainer->MeshData.pMesh->DrawSubset(uiAttrib);
				pMat->endPass();
			}
			pMat->end();
		}
	}
	
}