Sign in to follow this  
mind in a box

[DirectX10/Assimp] Index buffer trouble

Recommended Posts

mind in a box    887
I've tried to build in Assimp into my engine, but I have some trouble with the index buffer. DirectX means that the values in the Index buffer are invalid:
D3DX10: ID3DX10Mesh: Fatal error: index buffer contains invalid entries
And after looking at the Assimp viewer I just got more questions. Here is what I try to do:
//-------------Indices--------------
	DWORD* Indices = new DWORD[MeshScene->mMeshes[NumMesh]->mNumFaces*3]; //A Vertex has 3 points, so *3
	UINT Face=0;
	for(UINT i=0;i<MeshScene->mMeshes[NumMesh]->mNumFaces;i++)
	{
		//Fill our index buffer
		int ii=0;
		for(ii=0;ii<MeshScene->mMeshes[NumMesh]->mFaces[Face].mNumIndices;ii++)
		{
			Indices[i]=MeshScene->mMeshes[NumMesh]->mFaces[Face].mIndices[ii];
			i++;
		}

		Face++;
		
	}
	*oIndices=Indices; //Finished filling the index buffer, set the output
	*IndicesSize=MeshScene->mMeshes[NumMesh]->mNumFaces*sizeof(DWORD)*3; //Set index buffer size in bytes

I used another loader before, and I set the Indices just the way I did it here. Here is a part of my old loading function, but the parameters are still the same:
Mesh->GetIndexBuffer(&mb);
void* MeshIndexData;
DWORD* IndexData=new DWORD[mb->GetSize()/sizeof(DWORD)];

mb->Map(&MeshIndexData,&size);

    memcpy(IndexData,MeshIndexData,mb->GetSize());

mb->Unmap();

*IndicesSize=mb->GetSize();
*oIndices=IndexData;
mb->Release();



In the code of the Assimp viewer I have seen this:
g_piDevice->CreateIndexBuffer( 2 * mesh->mNumFaces * nidx, ...
while nidx is the face-style (Point=1,Line=2,Triangle=3), so for most meshes it is 3. But why the *2? Please help me! :( Edit: I found some logical errors in the code above and updated it. But it still isn't working as it should! (Same error) [Edited by - mind in a box on May 5, 2010 11:40:02 AM]

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