Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I? #4

Closed
mydana opened this issue Feb 4, 2015 · 3 comments
Closed

How do I? #4

mydana opened this issue Feb 4, 2015 · 3 comments

Comments

@mydana
Copy link

mydana commented Feb 4, 2015

So far this library looks really cool.
Perhaps I'm missing something really obvious but there are two actions I don't see in the documentation.

How do I create and save a new stl file?

How do I extend or reduce the mesh for an existing mesh object?

@wolph
Copy link
Owner

wolph commented Feb 4, 2015

Thanks, you're right that they're missing from the documentation. I'll put them on the todo to add :)
(they're in #5 and #6). I've updated the docs a bit already, apparently readthedocs didn't work correctly before: http://numpy-stl.readthedocs.org/en/latest/stl.html

Creating a new STL file from scratch is a bit tricky right now, mainly because this library was initially written for the purpose of reading and modifying existing STL files. I'll modify that in a future version, for now there's only a hack available.

Here's the current way to create a new StlMesh object:

from stl.mesh import Mesh
from stl.stl import StlMesh

VERTICE_COUNT = 100
data = numpy.zeros(VERTICE_COUNT, dtype=Mesh.dtype)
mesh = Mesh(data, remove_empty_areas=False)

# And to convert that to an STL object (NOTE THAT THIS IS NOT RECOMMENDED):
stl_mesh = StlMesh.__new__(StlMesh)
Mesh.__init__(stl_mesh, mesh.data)

Where VERTICE_COUNT is the amount of vertices you are going to use.

This is a hack to work around the current limitations as it wasn't designed with this purpose in mind, I can easily modify this in a future version but I would need a bit of info about how you plan to use the library :)

Extending or reducing the mesh currently uses a similar process, the library is designed to take an existing mesh and rotate/translate/scale/etc. that mesh. If you want to extend/reduce it a new object would have to be created since the numpy storage used in the background doesn't have the features to shrink/grow either.

Can you tell me how you plan to use the library? I can probably add the features you need easily :)

@mydana
Copy link
Author

mydana commented Feb 4, 2015

I'm looking to experiment with 3-D printing, and want to use this library to create STL files that will be sent to a service bureau to have printed.

For my use case it's easy enough to pre-compute the number of vertices, so extending and reducing isn't that important.

As to saving a file, perhaps consider moving the save methods to the Mesh base class, possibly with a wrapper in the StlMesh class. This will allow saving of meshes that are created new and those that are loaded from files.

@wolph
Copy link
Owner

wolph commented Feb 9, 2015

I've just created a new release which supports creating a new mesh and saving it to file by using a common base class. This should provide enough extensibility for the future while still keeping the code separate :)

Please give it a try and see if it works for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants