Welds together replicated vertices that have equal attributes. This method uses specified epsilon values for equality comparisons.
HRESULT D3DXWeldVertices( LPD3DXMESH pMesh, DWORD Flags, CONST D3DXWeldEpsilons * pEpsilons, CONST DWORD * pAdjacencyIn, DWORD * pAdjacencyOut, DWORD * pFaceRemap, LPD3DXBUFFER * ppVertexRemap );
If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, E_OUTOFMEMORY.
This function uses supplied adjacency information to determine the points that are replicated. Vertices are merged based on an epsilon comparison. Vertices with equal position must already have been calculated and represented by point-representative data.
This function combines logically-welded vertices that have similar components, such as normals or texture coordinates within pEpsilons.
The following example code calls this function with welding enabled. Vertices are compared using epsilon values for normal vector and vertex position. A pointer is returned to a face remapping array (pFaceRemap).
TCHAR strMediaPath[512]; // X-file path
LPD3DXBUFFER pAdjacencyBuffer = NULL; // adjacency data buffer
LPD3DXBUFFER pD3DXMtrlBuffer = NULL; // material buffer
LPD3DXMESH pMesh = NULL; // mesh object
DWORD m_dwNumMaterials; // number of materials
D3DXWELDEPSILONS Epsilons; // structure with epsilon values
DWORD *pFaceRemap[65536]; // face remapping array
DWORD i; // internal variable
// Load the mesh from the specified file
hr = D3DXLoadMeshFromX ( strMediaPath,
D3DXMESH_MANAGED,
m_pd3dDevice,
&pAdjacencyBuffer,
&pD3DXMtrlBuffer,
NULL,
&m_dwNumMaterials,
&pMesh ) )
if( FAILED( hr ) )
goto End; // Go to error handling
// Set epsilon values
Epsilons.Normal = 0.001;
Epsilons.Position = 0.1;
// Weld the vertices
for( i=0; i < 65536; i++ )
{
pFaceRemap[i] = 0;
}
hr = D3DXWeldVertices ( pMesh,
D3DXWELDEPSILONS_WELDPARTIALMATCHES,
&Epsilons,
(DWORD*)pAdjacencyBuffer->GetBufferPointer(),
(DWORD*)pAdjacencyBuffer->GetBufferPointer(),
(DWORD*)pFaceRemap,
NULL )
if( FAILED( hr ) )
goto End; // Go to error handling
Header: Declared in D3dx9mesh.h.