Skip to content
Chuck Walbourn edited this page Jan 21, 2022 · 8 revisions
DirectXMesh

These functions "clean" a mesh by eliminating common problems (see Validate) by modifying indices, adjacency, and/or duplicating vertices.

HRESULT Clean(
   uint16_t* indices, size_t nFaces, size_t nVerts,
   uint32_t* adjacency, const uint32_t* attributes,
   std::vector<uint32_t>& dupVerts, bool breakBowties=false );

HRESULT Clean(
   uint32_t* indices, size_t nFaces, size_t nVerts,
   uint32_t* adjacency, const uint32_t* attributes,
   std::vector<uint32_t>& dupVerts, bool breakBowties=false );

Parameters

The indices array is provided as an input, and is modified by the cleanup.

If adjacency is provided, then BACKFACING cleanup is performed. Any neighbor adjacency connections that are ASYMMETRIC are removed. Otherwise, can be nullptr.

If attributes is provided, then cleanup ensures that each vertex is only used by one attribute. Otherwise, can be nullptr.

dupVerts is a vector of duplicated vertices to add to the end of the vertex buffer. indices are updated to reference these new vertices by the function. Each element of the dupVerts vector indicates the original vertex index to duplicate at that position at the end of the existing vertex buffer. See FinalizeVB and FinalizeVBAndPointReps for more details.

If breakBowties is true, BOWTIES cleanup of adjacency is also performed.

Return values

This function will fail if the indices or adjacency values are out-of-range (i.e. it fails a Validate call with VALIDATE_DEFAULT).

The return value of HRESULT_FROM_WIN32( ERROR_ARITHMETIC_OVERFLOW ) indicates that the combined input nVerts plus the number of duplicated dupVerts exceeds 32-bits.

Since that cleanup occurs in phases, so some changes may have already been applied to provided buffers even on an error result.

Remarks

This does not eliminate degenerate triangles, but if adjacency is provided it ensures that degenerate triangles are not neighbors of other faces.

This function will ensure partial 'unused' faces are fully marked as unused, and if adjacency is provided it ensures that unused triangles are not neighbors of other faces.

This is an initial step in performing full mesh optimization, particularly the attribute duplication. Use of breakBowties is optional for mesh optimization.

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();

auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
for( size_t j = 0; j < nVerts; ++j )
   pos[ j ] = mesh->vertices[ j ].position;

auto adj = std::make_unique<uint32_t[]>(mesh->indices.size());
if ( FAILED( GenerateAdjacencyAndPointReps( mesh->indices.data(), nFaces,
   pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
   // Error

auto indices = std::make_unique<uint16_t[]>(nFaces * 3);
memcpy( indices.get(), mesh->indices.data(), sizeof(uint16_t) * nFaces * 3 ) );

std::vector<uint32_t> dupVerts;
hr = Clean( indices.get(), nFaces, nVerts, adj.get(), nullptr, dupVerts, true );
if ( FAILED(hr) )
   // Error

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Windows 7 Service Pack 1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v16
  • GCC 9.4, 11.3
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXTex

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally