How to union mesh with many connected components in python? #2671
Answered
by
Grantim
jesuchristu
asked this question in
Q&A
-
Hi, I see the uniteManyMeshes(), getAllComponents() functions in the API, but honestly, I'm not sure how to work with them. Thank for help. |
Beta Was this translation helpful? Give feedback.
Answered by
Grantim
May 2, 2024
Replies: 1 comment 1 reply
-
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
#resMesh = mm.uniteManyMeshes(vecMeshes, params)
# unite separated meshes
resMesh = mm.uniteManyMeshes(vecMeshes)
# save united mesh
mm.saveMesh(resMesh,"out/path/filename.stl") |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jesuchristu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
Such code should work for you: