Returns a failure HRESULT if the mesh description is invalid, and optionally includes diagnostic messages describing the problem(s) encountered. Clean can fix many of these issues.

HRESULT Validate(
   _In_reads_(nFaces*3) const uint16_t* indices, _In_ size_t nFaces,
   _In_ size_t nVerts, _In_reads_opt_(nFaces*3) const uint32_t* adjacency,
   _In_ DWORD flags, _In_opt_ std::wstring* msgs );

HRESULT Validate(
   _In_reads_(nFaces*3) const uint32_t* indices, _In_ size_t nFaces,
   _In_ size_t nVerts, _In_reads_opt_(nFaces*3) const uint32_t* adjacency,
   _In_ DWORD flags, _In_opt_ std::wstring* msgs );

Parameters

flags: Combination of control flags to indicate what issues to detect.
  • VALIDATE_DEFAULT is used to detect the most basic problems such as invalid index entries. If adjacency is provided, then that array is also validated.
  • VALIDATE_BACKFACING is used to detect a duplicate neighbor which usually indicates inconsistent winding order. This requires adjacency.
  • VALIDATE_BOWTIES is used to detect two fans of triangles that use the same vertex, but are not adjacent. This requires adjacency.
  • VALIDATE_DEGENERATE is used to detect degenerate triangles (i.e. 3 points forming only a line or a point). This does not require adjacency.
  • VALIDATE_UNUSED is used to detect issues with 'unused' triangles such as partial 'unused' faces. If adjacency is provided, it also validates that 'unused' faces are not neighbors of other faces.
  • VALIDATE_ASYMMETRIC_ADJ is used to check that every neighbor face links back to the original face. This requires adjacency.
msgs: An optional string description of the problems encountered. This is an empty string if the mesh is valid.

Return values

Returns S_OK if the mesh is valid with respect to the provided control flags.

Will return E_FAIL if the mesh is not valid with respect to the provided control flags.

Other possible failure codes include E_INVALIDARG and E_OUTOFMEMORY.

Example

std::unique_ptr<WaveFrontReader<uint16_t>> mesh( new WaveFrontReader<uint16_t>() );

if ( FAILED( mesh->Load( L"test.obj" ) ) )
   // Error

size_t nFaces = mesh->indices.size() / 3;
size_t nVerts = mesh->vertices.size();

hr = Validate( &mesh->indices.front(), nFaces, nVerts, nullptr, VALIDATE_DEFAULT );
if ( FAILED(hr) )
   // E_FAIL indicates that mesh failed validation

Last edited Jun 25, 2014 at 9:07 PM by walbourn, version 9