Sign in to follow this  
Jmuulian

Problems using D3DXWeldVertices().

Recommended Posts

Hey all. I'm trying to eliminate duplicate (co-located) vertices from a given ID3DXMesh, and then update the mesh's triangle adjacency buffer to match the optimized mesh. So I've tried using the D3D9 function D3DXWeldVertices, but it doesn't seem to do anything. I've specified appropriate epsilon values for the position, and yet the input adjacency buffer is equal to the output adjacency buffer. I suspect that I'm missing something about how this function is supposed to work, so if anyone can set me straight I'd appreciate it. Here's the end of a function I'm using to test D3DXWeldVertices:
std::vector< uint > newAdjacency;
newAdjacency.resize(pMesh->GetNumFaces() * 3);
D3DXWELDEPSILONS epsilons;
ZeroMemory(&epsilons, sizeof(D3DXWELDEPSILONS));
epsilons.Position = 0.01f;
if (FAILED(D3DXWeldVertices(pMesh, D3DXWELDEPSILONS_WELDALL, &epsilons, (const DWORD *)&adjacency[0], (DWORD *)&newAdjacency[0], NULL, NULL)))
    return FAIL;

for (uint n = 0; n < pMesh->GetNumFaces() * 3; ++n)
{
	if (adjacency[n] != newAdjacency[n])
	{
		return OK;
	}
}

return FUNCTION_COMPLETED;
The above code is executed and returns FUNCTION_COMPLETED, so D3DXWeldVertices is not failing, yet its output adjacency buffer is identical to its input adjacency buffer.

Share this post


Link to post
Share on other sites
Is your mesh textured? If so, it may not be possible to weld any vertices as they may all have unique texture coordinates.

Quote:
From DXSDK Docs
This function combines logically-welded vertices that have similar components, such as normals or texture coordinates within pEpsilons.

Share this post


Link to post
Share on other sites
Here's an update:

The adjacency buffer I pass into D3DXWeldVertices is created using ID3DXMesh::GenerateAdjacency() using the same position epsilon parameter passed into D3DXWeldVertices. The documentation states that if the pAdjacencyIn parameter to D3DXWeldVertices is NULL, the function will call ID3DXMesh::GenerateAdjacency() for you, using your supplied position epsilon value. Yet when I pass NULL instead of generating it myself, the function appears to work correctly. The test function now returns OK.

Share this post


Link to post
Share on other sites
Yeah, I've considered that, but my understanding of the D3DXWELDEPSILONS_WELDALL flag is that it removes non-positional vertex components from the welding process:
Quote:
D3DXWELDEPSILONS_WELDALL
Weld together all vertices that are at the same location. Using this flag avoids an epsilon comparison between vertex components.

Share this post


Link to post
Share on other sites
As it turns out, this problem is still present. Although D3DXWeldVertices is now creating a new output adjacency buffer, this buffer is still not what I'm expecting. The mesh I'm testing with should not have any unjoined triangle edges once the duplicate vertices are removed. So my assumption is that D3DXWeldVertices is either failing to detect all the duplicate vertices, or it isn't updating the adjacency information properly.

I've tried just about every valid configuration of flags and parameters, and can't get it to work. Any suggestions?

Thanks.

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