#include <MRCMesh/MRBuffer.h>
#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( "mesh.stl", NULL, NULL );
MR_Mesh*
mesh = MR_expected_MR_Mesh_std_string_value_mut( meshEx );
{
fprintf( stderr, "Failed to load mesh: %s\n", MR_std_string_data( MR_expected_MR_Mesh_std_string_error( meshEx ) ) );
goto fail;
}
bool preserveAABBTree = false;
MR_PackMapping_Destroy( MR_Mesh_packOptimally_1(
mesh, &preserveAABBTree ) );
MR_DecimateSettings* params = MR_DecimateSettings_DefaultConstruct();
MR_DecimateSettings_Set_maxDeletedFaces( params, 1000 );
MR_DecimateSettings_Set_maxError( params, 0.05f );
MR_DecimateSettings_Set_subdivideParts( params, 16 );
MR_DecimateResult_Destroy( MR_decimateMesh(
mesh, params ) );
MR_DecimateSettings_Destroy( params );
MR_expected_void_std_string* saveEx = MR_MeshSave_toAnySupportedFormat(
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