wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
605 stars 103 forks source link

Delete specific triangles from the mesh #179

Closed uffacci closed 10 months ago

uffacci commented 2 years ago

Hi, I want to know if there is an easy way to delete specific triangles from a mesh from an STL file. I can delete the vertices of the triangles that I want to reject, but then I cannot visualize the new result ... any ideas? Thanks a lot

wolph commented 2 years ago

Since numpy arrays have a fixed size, the only way you can delete them is by creating a new array (or a view).

One option would be to create a view, simply put, you can slice a numpy array by passing a list of selected indices:

>>> import numpy
>>> a = numpy.arange(10, 19).reshape((3, 3))
>>> a
array([[10, 11, 12],
       [13, 14, 15],
       [16, 17, 18]])
>>> a[[1, 2]]
array([[13, 14, 15],
       [16, 17, 18]])

If you create a new Mesh object with the sliced data argument you can easily delete triangles like that.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.