#include <MRCMesh/MRFreeFormDeformer.h>
#include <MRCMesh/MRMesh.h>
#include <MRCMesh/MRMeshLoad.h>
#include <MRCMesh/MRMeshSave.h>
#include <MRCMisc/expected_MR_Mesh_std_string.h>
#include <MRCMisc/std_string.h>
#include <stdio.h>
#include <stdlib.h>
{
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 ) ) );
MR_expected_MR_Mesh_std_string_Destroy( meshEx );
return 1;
}
MR_Box3f box = MR_Mesh_computeBoundingBox_1( mesh, NULL );
MR_FreeFormDeformer* ffDeformer = MR_FreeFormDeformer_Construct_MR_Mesh( mesh, NULL );
MR_Vector3i resolution = MR_Vector3i_diagonal( 3 );
MR_FreeFormDeformer_init( ffDeformer, &resolution, &box );
MR_Vector3i controlPoints[] = {
{ 1, 1, 0 },
{ 1, 1, 2 },
{ 0, 1, 1 },
{ 2, 1, 1 },
{ 1, 0, 1 },
{ 1, 2, 1 },
};
MR_Vector3f center = MR_Box3f_center( &box );
for ( int i = 0; i < 6; ++i )
MR_FreeFormDeformer_setRefGridPointPosition( ffDeformer, &controlPoints[i], ¢er );
MR_FreeFormDeformer_apply( ffDeformer );
MR_Mesh_invalidateCaches( mesh, NULL );
MR_MeshSave_toAnySupportedFormat_3( mesh, "deformed_mesh.stl", NULL, NULL );
MR_FreeFormDeformer_Destroy( ffDeformer );
MR_expected_MR_Mesh_std_string_Destroy( meshEx );
return EXIT_SUCCESS;
}