Skip to content

How to union mesh with many connected components in python? #2671

Answered by Grantim
jesuchristu asked this question in Q&A
Discussion options

You must be logged in to vote

Hello!

Such code should work for you:

from meshlib import mrmeshpy as mm

# load mesh with several components
mesh = mm.loadMesh("in/path/filename.stl")

# separate components 
components = mm.getAllComponents(mesh)

meshes = []
vecMeshes = mm.vectorConstMeshPtr()
vecMeshes.resize(len(components))
for i in range(len(components)):
    # create meshes from separated components
    meshes.append(mm.Mesh())
    meshes[i].addPartByMask(mesh,components[i])
    vecMeshes[i] = meshes[i]

# commented part will be available in next release and will provide better result for cases with nested components
#params = mm.UniteManyMeshesParams()
#params.nestedComponentsMode = mm.NestedComponenetsMode.Merge

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jesuchristu
Comment options

Answer selected by jesuchristu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants