Sign in to follow this  
data2

D3DXWeldVertices messes up normals and texcoords

Recommended Posts

Hi there, for a mesh I'm using, D3DXComputeNormals complains because of bowties. Hence, I wanted to use D3DXWeldVertices to remove bowties. The function doesn't fail and everything is fine. However, my mesh normals and texture coordinates are messed up. Here is an example (left without welding, right including welding): messed tex coords and normals I'm using the function as follows:
void Mesh::Optimize()
{
    // (1) Compute adjacency
    DWORD* adjacency1 = new DWORD[m_mesh->GetNumFaces() * 3];

    HRESULT hr = m_mesh->GenerateAdjacency(1e-6f, adjacency1);
    if(hr != D3D_OK)
    {
        delete [] adjacency1;
        throw HResultException(_T("GenerateAdjacency() failed!"), hr, _T("Mesh"), _T("Optimize"), DXGetErrorDescription(hr));
    }

    // (2) Weld vertices in order to avoid bowties
    DWORD* adjacency2 = new DWORD[m_mesh->GetNumFaces() * 3];
    hr = D3DXWeldVertices(m_mesh, D3DXWELDEPSILONS_WELDALL, NULL, adjacency1, adjacency2, NULL, NULL);
    if(hr != D3D_OK)
    {
        delete [] adjacency1;
        delete [] adjacency2;
        throw HResultException(_T("D3DXWeldVertices() failed!"), hr, _T("Mesh"), _T("Optimize"), DXGetErrorDescription(hr));
    }

    // (3) Optimize the mesh
    hr = m_mesh->OptimizeInplace(D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, adjacency2, adjacency1, NULL, NULL);
    if(hr != D3D_OK)
    {
        delete [] adjacency1;
        delete [] adjacency2;
        throw HResultException(_T("OptimizeInplace() failed!"), hr, _T("Mesh"), _T("Optimize"), DXGetErrorDescription(hr));
    }

    // (4) Recompute normals
    hr = D3DXComputeNormals(m_mesh, adjacency1);
    if(hr != D3D_OK)
    {
        delete [] adjacency1;
        delete [] adjacency2;
        throw HResultException(_T("D3DXComputeNormals() failed!"), hr, _T("Mesh"), _T("Optimize"), DXGetErrorDescription(hr));
    }

    delete [] adjacency1;
    delete [] adjacency2;
}

Any ideas? Any suggestions? Many thanks, Data

Share this post


Link to post
Share on other sites
The only idea I have is to tinker with either of the inputs to D3DXWeldVertices():

1) D3DXWELDEPSILONSFLAGS, try sending D3DXWELDEPSILONS_DONOTREMOVEVERTICSE or DONOTSPLIT (if you have multiple attributes in your mesh).
2) Try filling in a D3DXWeldEpsilons structure and see if you can prevent the vertices in question from being "welded".

I personally wouldn't worry about the bowtie warning.

Share this post


Link to post
Share on other sites
Quote:
Original post by adt7
Shouldn't you be using the D3DXCleanMesh method to remove bowties? At least I thought that was it's purpose.
I tried with the following call, but it didn't remove the bowties :-(:

D3DXCleanMesh(D3DXCLEAN_BOWTIES, m_mesh, adjacency2, &clone, adjacency, &errors);
m_mesh->Release();
m_mesh = clone;

Share this post


Link to post
Share on other sites
The main reason that I (as a programmer) wouldn't worry about using a mesh that warns me about bowties are:

1. It's a problem more easily solved by the artists in their modeling program
2. It's a problem that doesn't stop me from rendering/using the mesh, in fact I think the only reason to remove bowties (by splitting the vertices) is to allow you to create a tangent frame for lighting purposes. Otherwise, just leave 'em in.

Share this post


Link to post
Share on other sites
Quote:
1. It's a problem more easily solved by the artists in their modeling program
Uhm, we're using commercial meshes exported as OBJ. I think we can't handle the bowties in the modeller and have to live with the OBJ as they are...

Quote:
2. It's a problem that doesn't stop me from rendering/using the mesh, in fact I think the only reason to remove bowties (by splitting the vertices) is to allow you to create a tangent frame for lighting purposes. Otherwise, just leave 'em in.
Yep, and that's exactly what I need to do ;-).

So, I'm back to where I started worrying, eh?

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