Jump to content
  • Advertisement
Sign in to follow this  
Luth

Loading Animation from XFile & Adding a D3DFVF_DIFFUSE tag breaks animation

This topic is 4853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Wow, title says it all.... I'm using most of the code from the DX Tutorials for loading an animation. It all loads fine, but with one difference: My engine has LIGHTING enabled. With that, the model is displayed as invisible. Why? Well thats easy... it has no ALPHA value for lighting, and the following setting makes it invisible: m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); So, we comment that out, so it will ignore the alpha blending for now. Problem is now, along with the alpha being zero, so are the diffuse colors. So the model is completely black. Why? Because the FVF loaded from the XFile (in this case "tiny.x" which you should probably be familiar with) does not contain any DIFFUSE information in it. Until now, I would have done the following, as it worked perfectly for loading static meshes:
#define D3DFVF_CVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1)

........................

bool hasNormals = ((m_pMesh->GetFVF() & D3DFVF_NORMAL) != 0);
bool hasColors = ((m_pMesh->GetFVF() & D3DFVF_DIFFUSE) != 0);

if (!hasNormals || !hasColors)	// if there's no normals
{
	//set FVF to custom_vertex format
	LPD3DXMESH pTempMesh = NULL;
	if(FAILED(m_pMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_CVERTEX, Direct3D::InstancePtr()->GetDevice(), &pTempMesh)))
	{
		SAFE_RELEASE(pTempMesh);
		Cleanup();
		return false;
	}

	SAFE_RELEASE(m_pMesh);
	m_pMesh = pTempMesh;
	
	if(!hasNormals)
		D3DXComputeNormals(m_pMesh, NULL);
}

of course modified for the animation code in the tutorial, it looks similiar to:
void AnimModel::SetupBoneMatrices(LPFRAME pFrame, LPD3DXMATRIX pParentMatrix)
{
	LPMESHCONTAINER pMesh = (LPMESHCONTAINER)pFrame->pMeshContainer;

	//Set up the bones on the mesh
	if(pMesh)
	{
		if(!m_pFirstMesh)
			m_pFirstMesh = pMesh;
		
		// if there is a skinmesh, then setup the bone matrices
		if(pMesh->pSkinInfo)
		{
			LPD3DXMESH pTempMesh = NULL;
			//Create a copy of the mesh
			if(FAILED(pMesh->MeshData.pMesh->CloneMeshFVF(D3DXMESH_MANAGED, 
									D3DFVF_CVERTEX,
									m_pd3dDevice, 
									&pTempMesh)))
			{
				SAFE_RELEASE(pTempMesh);
				gamelog<<"Could not clone mesh"<<endlog;
				return;
			}
			SAFE_RELEASE(pMesh->pSkinMesh);
			pMesh->pSkinMesh = pTempMesh;
....

Simply Cloning from the original mesh to my Custom Vertex. But, as you're probably guessing, this screws up and/or loses information, and the model is no longer recognizable as anything even remotely resembling Tiny. What do I need to do to get an FVF for an animated model that includes a DIFFUSE tag so that I can enable LIGHTING and not have an all-black model?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!