MeshLib Documentation
Loading...
Searching...
No Matches
Convert text to mesh

Following code presents example of converting text to mesh

  • C++
    #include <MRMesh/MRMesh.h>
    #include <MRMesh/MRMeshSave.h>
    #include <iostream>
    int main( int argc, char* argv[] )
    {
    if ( argc < 3 )
    {
    std::cerr << "Usage: MeshFromText fontpath text" << std::endl;
    return EXIT_FAILURE;
    }
    const auto* fontPath = argv[1];
    const auto* text = argv[2];
    // set text-to-mesh parameters
    // input text
    .text = text,
    // font file name
    .pathToFontFile = fontPath,
    };
    auto convRes = MR::createSymbolsMesh( params );
    if ( !convRes )
    {
    std::cerr << "Failed to convert text to mesh: " << convRes.error() << std::endl;
    return EXIT_FAILURE;
    }
    auto saveRes = MR::MeshSave::toAnySupportedFormat( *convRes, "mesh.ply" );
    if ( !saveRes )
    {
    std::cerr << "Failed to save result: " << saveRes.error() << std::endl;
    return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
    }
    int main()
    Definition LaplacianDeformation.cpp:4
    MRMESH_API Expected< void > toAnySupportedFormat(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
    MRSYMBOLMESH_API Expected< Mesh > createSymbolsMesh(const SymbolMeshParams &params)
    See also
    MR::createSymbolsMesh
  • Python
    import sys
    import meshlib.mrmeshpy as mrmeshpy
    if len(sys.argv) < 3:
    print("Usage: ./MeshFromText fontpath text", file=sys.stderr)
    sys.exit(1)
    font_path = sys.argv[1]
    text = sys.argv[2]
    params.text = text
    params.pathToFontFile = font_path
    try:
    conv_res = mrmeshpy.createSymbolsMesh(params)
    except ValueError as e:
    print(f"Failed to convert text to mesh: {e}", file=sys.stderr)
    sys.exit(1)
    mrmeshpy.saveMesh(conv_res, "mesh.ply")
    None saveMesh(Mesh mesh, os.PathLike|str|bytes file, SaveSettings settings='{}')
    Mesh createSymbolsMesh(SymbolMeshParams params)