How to combine multiple polygons into 3d mesh (Python-trimesh)

854 Views Asked by At

I'm dealing with stl data which can be loaded by:

# load a file by name or from a buffer
mesh = trimesh.load_mesh('./dummydata.stl')
# preview mesh in a pyglet window from a terminal, or inline in a notebook
mesh.show()

This creates a 3D object which cannot be disclosed due to confidentiality issues. However, for the sake of the question I have constructed an example object. Example image. As you can see in the picture, there is an 'outer object', the box, and an inner object, the sphere.

My goal is to extract the sphere and create a separate mesh object which is just the sphere.

Currently my apporach is to slice through the mesh object at (many) different z-levels, so you would get 2D slices like in the following images Slice- no circle, or Slice - with circle. Then I can extract the circle polygon per slice using:

slice2D.polygons_closed[1]

However, this leaves me with a lot of 2Dpolygons instead of a 3D mesh object.

My question is: how do I combine these 2Dpolygons into a 3D mesh object. (Or how do I solve my problem in a different way?)

1

There are 1 best solutions below

1
On

Probably Trimesh.util.concatenate could give you some hints