#include <MRCMesh/MRMesh.h>
#include <MRCMesh/MRMeshDecimate.h>
#include <MRCMesh/MRMeshLoad.h>
#include <MRCMesh/MRMeshSave.h>
#include <MRCMesh/MRString.h>
#include <MRCMisc/expected_MR_Mesh_std_string.h>
#include <MRCMisc/expected_void_std_string.h>
#include <MRCMisc/std_string.h>
#include <stdio.h>
#include <stdlib.h>
{
int rc = EXIT_FAILURE;
MR_expected_MR_Mesh_std_string* meshEx = MR_MeshLoad_fromAnySupportedFormat_2( "mesh.stl", NULL, NULL );
MR_Mesh* mesh = MR_expected_MR_Mesh_std_string_value_mut( meshEx );
if ( !mesh )
{
fprintf( stderr, "Failed to load mesh: %s\n", MR_std_string_data( MR_expected_MR_Mesh_std_string_error( meshEx ) ) );
goto fail;
}
MR_DecimateSettings* params = MR_DecimateSettings_DefaultConstruct();
MR_DecimateSettings_Set_maxDeletedFaces( params, 1000 );
MR_DecimateSettings_Set_maxError( params, 0.05f );
MR_DecimateSettings_Set_subdivideParts( params, 64 );
MR_DecimateResult* result = MR_decimateMesh( mesh, params );
MR_DecimateSettings_Destroy( params );
printf( "Removed %d vertices, %d faces\n", *MR_DecimateResult_Get_vertsDeleted( result ), *MR_DecimateResult_Get_facesDeleted( result ) );
MR_DecimateResult_Destroy( result );
MR_expected_void_std_string* saveEx = MR_MeshSave_toAnySupportedFormat_3( mesh, "decimated_mesh.stl", NULL, NULL);
if ( MR_expected_void_std_string_error( saveEx ) )
{
fprintf( stderr, "Failed to save mesh: %s\n", MR_std_string_data( MR_expected_void_std_string_error( saveEx ) ) );
goto fail;
}
rc = EXIT_SUCCESS;
fail:
MR_expected_MR_Mesh_std_string_Destroy( meshEx );
return rc;
}
Source mesh