MeshLib
 
Loading...
Searching...
No Matches
Loading and saving mesh files

Following code presents example of loading and saving mesh file

#include <MRMesh/MRMesh.h>
#include <iostream>
int main()
{
std::filesystem::path inFilePath = "mesh.stl";
auto loadRes = MR::MeshLoad::fromAnySupportedFormat( inFilePath );
if ( loadRes.has_value() )
{
std::filesystem::path outFilePath = "mesh.ply";
auto saveRes = MR::MeshSave::toAnySupportedFormat( loadRes.value(), outFilePath );
if ( !saveRes.has_value() )
std::cerr << saveRes.error() << std::endl;
}
else
std::cerr << loadRes.error() << std::endl;
return 0;
}
MRMESH_API Expected< Mesh > fromAnySupportedFormat(const std::filesystem::path &file, const MeshLoadSettings &settings={})
detects the format from file extension and loads mesh from it
MRMESH_API VoidOrErrStr toAnySupportedFormat(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
detects the format from file extension and save mesh to it

Further examples won't check return values for sake of clarity

See also
MR::MeshLoad
MR::MeshSave