Repository navigation
In LoadMesh Tutorial #4192
In LoadMesh Tutorial
#4192
#include <MRMesh/MRMesh.h>
#include <MRMesh/MRMeshLoad.h>
#include <MRMesh/MRMeshSave.h>
#include <MRIOExtras/MRCtm.h>
#include <iostream>
int main()
{
// Load mesh
std::filesystem::path inFilePath = "mesh.stl";
auto loadRes = MR::MeshLoad::fromAnySupportedFormat( inFilePath );
if ( loadRes.has_value() )
{
std::cerr << loadRes.error() << std::endl;
return 1;
}
// Save mesh
std::filesystem::path outFilePath = "mesh.ply";
auto saveRes = MR::MeshSave::toAnySupportedFormat( loadRes.value(), outFilePath );
if ( !saveRes.has_value() )
{
std::cerr << saveRes.error() << std::endl;
return 1;
}
// More mesh formats are available in the MRIOExtras library
std::filesystem::path outCtmFilePath = "mesh.ctm";
saveRes = MR::MeshSave::toCtm( loadRes.value(), outCtmFilePath );
if ( !saveRes.has_value() )
{
std::cerr << saveRes.error() << std::endl;
return 1;
}
return 0;
}"This is a LoadMesh tutorial, but it says if ( loadRes.has_value() ) in the code. Is this a typo?" |
Answered by
Grantim
Feb 25, 2025
Replies: 2 comments
|
Hello! MeshLib/source/MRMesh/MRMeshLoad.h Lines 142 to 144 in 3d1872e which is https://github.com/MeshInspector/MeshLib/blob/master/source/MRMesh/MRExpected.h ( |
0 replies
Answer selected by
Fedr
|
Yes, the condition in that example was inverted: it must be |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Hello!
Please note that many of meshlib functions return values are
Expected<T>MeshLib/source/MRMesh/MRMeshLoad.h
Lines 142 to 144 in 3d1872e
which is https://github.com/MeshInspector/MeshLib/blob/master/source/MRMesh/MRExpected.h (
tl::expected<T>which is a lot likestd::expected<T>)So are valid operations for this type