9 Validate
Chuck Walbourn редактировал(а) эту страницу 2022-01-20 17:34:24 -08:00
DirectXMesh

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(
   const uint16_t* indices, size_t nFaces, size_t nVerts,
   const uint32_t* adjacency,
   VALIDATE_FLAGS flags, std::wstring* msgs );

HRESULT Validate(
   const uint32_t* indices, size_t nFaces, size_t nVerts,
   const uint32_t* adjacency,
   VALIDATE_FLAGS flags, 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.

Depending on the flags combinations, adjacency can be nullptr.

msgs: An optional string description of the problems encountered. This is an empty string if the mesh is valid. Can be nullptr if messages are not desired.

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

auto mesh = std::make_unique<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.data(), nFaces, nVerts, nullptr, VALIDATE_DEFAULT );
if ( FAILED(hr) )
   // E_FAIL indicates that mesh failed validation