D3DXWeldVertices
Microsoft DirectX 9.0 SDK Update (October 2004)

D3DXWeldVertices Function


Welds together replicated vertices that have equal attributes. This method uses specified epsilon values for equality comparisons.

Syntax

HRESULT WINAPI D3DXWeldVertices(      

    LPD3DXMESH pMesh,     DWORD Flags,     const D3DXWELDEPSILONS *pEpsilons,     const DWORD *pAdjacencyIn,     DWORD *pAdjacencyOut,     DWORD *pFaceRemap,     LPD3DXBUFFER *ppVertexRemap );

Parameters

pMesh
[in] Pointer to an ID3DXMesh object, the mesh from which to weld vertices.
Flags
[in] Combination of one or more flags from D3DXWELDEPSILONSFLAGS.
pEpsilons
[in] Pointer to a D3DXWELDEPSILONS structure, specifying the epsilon values to be used for this method. If NULL, a default value of 1.0e-6f is used for all members of D3DXWELDEPSILONS.
pAdjacencyIn
[in] Pointer to an array of three DWORDs per face that specify the three neighbors for each face in the source mesh. If the edge has no adjacent faces, the value is 0xffffffff. If this parameter is set to NULL, ID3DXBaseMesh::GenerateAdjacency will be called to create logical adjacency information.
pAdjacencyOut
[in, out] Pointer to a destination buffer for the face adjacency array of the optimized mesh. The face adjacency is stored as an array of arrays. The innermost array is three indices of adjacent triangles, and the outer array is one set of face adjacency per triangle in the mesh.
pFaceRemap
[out] Pointer to a destination array containing the new index for each face. The array has the same number of elements as the original number of faces. Each element of the array contains either the index of the original face, or 0xffffffff if the original face has been removed in the vertex welding.
ppVertexRemap
[out] Address of a pointer to an ID3DXBuffer interface, containing the new index for each vertex.

Return Value

If the function succeeds, the return value is D3D_OK.

If the function fails, the return value can be one of the following values.

D3DERR_INVALIDCALLThe method call is invalid. For example, a method's parameter may have an invalid value.
E_OUTOFMEMORYMicrosoft Direct3D could not allocate sufficient memory to complete the call.


Remarks

This function uses supplied adjacency information to determine the points that are replicated. Vertices are merged based upon 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 within pEpsilons 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
.
.
.

Function Information

Headerd3dx9mesh.h
Import libraryd3dx9.lib
Minimum operating systems Windows 98


© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.