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
624 stars 105 forks source link

Other methods to plot stl file instead of matplotlib. #119

Closed snowbugxs closed 4 years ago

snowbugxs commented 4 years ago

My stl file is so large (90MB) that the plot window gets stuck. Is there any method to show the stl from python script? I think i can save the file and the open it in another software. But is there a better way?

wolph commented 4 years ago

The matplotlib demo is mostly to show that you could, but it's probably not the best way to view the file.

You could try Cura, it uses this library internally but it offers much better display features :)

snowbugxs commented 4 years ago

Thanks. Could you give me some tips on how to find the boundary points a stl mesh (a open one)?

wolph commented 4 years ago

I would recommend trying scipy for that. It uses the qhull library internally to calculate a convex hull. There are a few examples on stackoverflow: https://stackoverflow.com/questions/26434726/return-surface-triangle-of-3d-scipy-spatial-delaunay

snowbugxs commented 4 years ago

Thanks. But i think the convex hull will miss some points not so convex, such as a concave between a convex. Is the numpy-stl able to write a mesh into a stl file with binary format while reading this mesh from an ascii format stl file? I am a bit confused by the mode parameter in the mesh.save function. I try to use the mode = "ASCII" but got an error of invalid mode.

wolph commented 4 years ago

That is very true. Calculating a hull including the concave section is far more complicated though. And the solution is also not a unique one, depending on the approach you get completely different results.

wolph commented 4 years ago

Forgot to answer your other question. You need to use the constants instead of a string.

Also, if you've installed the package you actually have a command available to be called from the commandline: https://github.com/WoLpH/numpy-stl/blob/develop/README.rst#initial-usage

snowbugxs commented 4 years ago

Thanks. The command line works but the mesh.save with mode does not. I am sorry to not understand the constants of ASCII. Could you give an example?

snowbugxs commented 4 years ago

I have write some functions to detect the edge of a mesh and add some mesh from periphery to enclose it. Can i make a pull request? BTW, i am a poor programmer.

wolph commented 4 years ago

There are a few examples in the examples and tests: https://github.com/WoLpH/numpy-stl/blob/develop/README.rst#combining-multiple-stl-files https://github.com/WoLpH/numpy-stl/blob/412d54bdd972921b3c1fb509cf5be48aac7bc28f/tests/test_convert.py#L8-L42

But it basically comes down to this:

import stl

your_mesh = stl.mesh.Mesh.from_file('some_file.stl')
your_mesh.save('ascii.stl', mode=stl.Mode.ASCII)
your_mesh.save('binary.stl', mode=stl.Mode.BINARY)

As for edge detection. All help is welcome :)

snowbugxs commented 4 years ago

Thanks.