Sign in to follow this  
CodeReaver

Problems with saving skin info:

Recommended Posts

I create a mesh with D3DXCreateMeshFVF and it saves without any problem whether I just use D3DXSaveMeshToX or embed it in a frame and use D3DXSaveMeshHierarchyToFile. I had a look at tiny.x in text form and saw that the first frame contains all the vertices and indices of the mesh etc and the skin info. After looking up D3DXMESHCONTAINER I found that I can put the skin info (D3DXMESHCONTAINER->pSkinInfo) in the frame along with my mesh (D3DXMESHCONTAINER->MeshData). So I tried doing that and all that happens is that D3DXSaveMeshHierarchyToFile crashes the program. I also tried converting the mesh to a blended mesh and then giving that as the mesh that goes in my container. However ConvertToBlendedMesh fails as well. Does anyone know what I might be doing wrong? Where I've used exSegments[s].vFirst and exSegments[s].vLast, that's meaning the first and last vertex in my vertex buffer. The vertices in the buffer are sorted according to the bones they belong too. The idea is that the transformation of any vertex in my mesh is transformed the product of it's bone's matrix and all it's ancestor bones' matrices.
	// [CREATE THE SKIN INFO]
	// Get rid of any existing skin info
	if (pSkinInfo != NULL) pSkinInfo->Release();
	// Create Skin Info
	if(FAILED(D3DXCreateSkinInfoFVF(
		vertexCount,
	    D3DFVF_EX_VERTEX,
	    segmentCount,
		&pSkinInfo
	))) {
		lastError = "Couldn't create skin info";
		goto FailLoadGex;
	}
	DWORD noOfInfluences = 0;
	DWORD* inflVertices = NULL;
	FLOAT* inflWeights  = NULL;
	D3DXMATRIX boneTrans;
	for (DWORD s=0; s<segmentCount; s++) {
		if (exSegments[s].vFirst==0xFFFF)
			noOfInfluences = segmentCount;
		else
			noOfInfluences = exSegments[s].vLast-exSegments[s].vFirst;
		inflVertices = new DWORD[noOfInfluences];
		inflWeights  = new FLOAT[noOfInfluences];
		for (DWORD v=0; v<noOfInfluences; v++) {
			if (exSegments[s].vFirst==0xFFFF)
				inflVertices[v] = v;
			else
				inflVertices[v] = v+exSegments[s].vFirst;
			inflWeights[v]=1.0f;
		}
		pSkinInfo->SetBoneInfluence(
			s,
			noOfInfluences,
			inflVertices,
		    inflWeights
		);
		D3DXMatrixIdentity(&boneTrans);
		boneTrans._41 = exSegments[s].x;
		boneTrans._42 = exSegments[s].y;
		boneTrans._43 = exSegments[s].z;
		pSkinInfo->SetBoneOffsetMatrix(s, &boneTrans);
	}
	// [/CREATE THE SKIN INFO]
	DWORD* adjIn = new DWORD[pD3DXMesh->GetNumFaces()*3];
	DWORD* adjOut = new DWORD[pD3DXMesh->GetNumFaces()*3];
	DWORD  maxVertInfl = 0;
	DWORD  noOfBoneCombos = 0;
	LPD3DXBUFFER* boneComboTable = (LPD3DXBUFFER*) new D3DXBONECOMBINATION[segmentCount];
	if(FAILED(pD3DXMesh->GenerateAdjacency(0.01f, adjIn))) {
		lastError = "Couldn't generate adjacancy";
		goto FailLoadGex;
	}
	/*LPD3DXMESH outputMesh;
	if(FAILED(
		pSkinInfo->ConvertToBlendedMesh(
			pD3DXMesh, NULL,
			adjIn, adjOut,
			NULL, NULL, &maxVertInfl, &noOfBoneCombos, boneComboTable,
			&outputMesh
		)
	)) {
		lastError = "Couldn't convert to blended mesh";
		goto FailLoadGex;
	}*/
	exKeyFrames = new D3DXFRAME;
	ZeroMemory(exKeyFrames, sizeof(D3DXFRAME));
	exKeyFrames->pMeshContainer = new D3DXMESHCONTAINER;
	ZeroMemory(exKeyFrames->pMeshContainer, sizeof(D3DXMESHCONTAINER));
	exKeyFrames->pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
	exKeyFrames->pMeshContainer->MeshData.pMesh = pD3DXMesh;
	// exKeyFrames->pMeshContainer->pSkinInfo = pSkinInfo;
	// exKeyFrames->pMeshContainer->pAdjacency = adjIn;
	D3DXMatrixIdentity(&(exKeyFrames->TransformationMatrix));
	//D3DXSaveMeshToX("razOne.x", outputMesh, NULL, NULL, NULL, 0, D3DXF_FILEFORMAT_TEXT);
	if (FAILED(
		D3DXSaveMeshHierarchyToFile(
		"razZero.x",
		D3DXF_FILEFORMAT_TEXT,
		exKeyFrames,
		NULL,
		NULL
	))) {
		lastError = "Couldn't save file";
		goto FailLoadGex;
	}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this