-
Notifications
You must be signed in to change notification settings - Fork 151
Clean
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 );
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.
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.
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.
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
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- 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
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- GCC 10.5, 11.4, 12.3
- MinGW 12.2, 13.2
- CMake 3.20
DirectX Tool Kit for DirectX 11