This project has moved and is read-only. For the latest updates, please go here.
These functions "clean" a mesh by eliminating common problems (see Validate) by modifying indices, adjacency, and/or duplicating vertices.

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

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

Parameters

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

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

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

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.

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

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

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

std::unique_ptr<uint32_t[]> adj( new uint32_t[ mesh->indices.size() ] );
if ( FAILED( GenerateAdjacencyAndPointReps( &mesh->indices.front(), nFaces,
   pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
   // Error

std::unique_ptr<uint16_t[]> indices( new uint16_t[ nFaces * 3 ] );
memcpy( indices.get(), &mesh->indices.front(), 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

Last edited Nov 20, 2014 at 7:57 PM by walbourn, version 21