MeshLib Documentation
Loading...
Searching...
No Matches
Mesh extrude

Example of extrude faces on mesh

  • C++
    #include <MRMesh/MRBitSet.h>
    #include <MRMesh/MRId.h>
    #include <MRMesh/MRMesh.h>
    #include <MRMesh/MRMeshLoad.h>
    #include <MRMesh/MRMeshSave.h>
    #include <MRMesh/MRRegionBoundary.h>
    int main()
    {
    // Load mesh
    // Select faces to extrude
    MR::FaceBitSet facesToExtrude;
    facesToExtrude.autoResizeSet( MR::FaceId( 1 ) );
    facesToExtrude.autoResizeSet( MR::FaceId( 2 ) );
    // Create duplicated verts on region boundary
    MR::makeDegenerateBandAroundRegion( mesh, facesToExtrude );
    // Find vertices that will be moved
    auto vertsForMove = MR::getIncidentVerts( mesh.topology, facesToExtrude );
    MR::BitSetParallelFor( vertsForMove, [&] ( MR::VertId v )
    {
    // Move each vertex
    mesh.points[v] += MR::Vector3f::plusZ();
    } );
    // Invalidate internal caches after manual changing
    // Save mesh
    MR::MeshSave::toAnySupportedFormat( mesh, "extrudedMesh.stl" );
    }
    auto BitSetParallelFor(const BS &bs, F &&f, Cb &&... cb)
    MRMESH_API Expected< Mesh > fromAnySupportedFormat(const std::filesystem::path &file, const MeshLoadSettings &settings={})
    MRMESH_API Expected< void > toAnySupportedFormat(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
    MRMESH_API void makeDegenerateBandAroundRegion(Mesh &mesh, const FaceBitSet &region, const MakeDegenerateBandAroundRegionParams &params={})
    MRMESH_API VertBitSet getIncidentVerts(const MeshTopology &topology, const FaceBitSet &faces)
    MeshTopology topology
    VertCoords points
    MRMESH_API void invalidateCaches(bool pointsChanged=true)
  • Python
    import meshlib.mrmeshpy as mrmeshpy
    # Load mesh
    mesh = mrmeshpy.loadMesh("mesh.stl")
    # Prepare region to extrude
    faces_to_extrude = mrmeshpy.FaceBitSet()
    faces_to_extrude.resize(3, False)
    faces_to_extrude.set(mrmeshpy.FaceId(1), True)
    faces_to_extrude.set(mrmeshpy.FaceId(2), True)
    # Create duplicated verts on region boundary
    mrmeshpy.makeDegenerateBandAroundRegion(mesh, faces_to_extrude)
    # Find vertices that will be moved
    verts_for_move = mrmeshpy.getIncidentVerts(mesh.topology, faces_to_extrude)
    # Move each vertex
    for v in range(verts_for_move.size()):
    if verts_for_move.test(mrmeshpy.VertId(v)):
    mesh.points.vec[v] += mrmeshpy.Vector3f(0.0, 0.0, 1.0)
    # Invalidate internal caches after manual changing
    mesh.invalidateCaches()
    # Save mesh
    mrmeshpy.saveMesh(mesh, "extrudedMesh.stl")