Closed FaezAlkadi closed 3 years ago
You should have all variables available to make the calculation: https://numpy-stl.readthedocs.io/en/latest/stl.html?highlight=v0#stl.base.BaseMesh
I would assume that you can use either mesh.vectors
or mesh.points
with mesh.normals
to offset in the right direction.
How you actually want to do it can be tricky though... But I think this paper might be able to help a bit with that: http://www.cad-journal.net/files/vol_1/CAD_1(1-4)_2004_285-291.pdf
I have used the following code to call the STL file from my external folder:
Folder = os.path.join('0001-STL/test.stl');
Then used the following code to extract data from the STL file:
your_mesh = mesh.Mesh.from_file(Folder)
I successfully was able to get all the variables (your_mesh .vectors, your_mesh .points, your_mesh .normals, your_mesh .x, your_mesh .y , your_mesh .z ........ etc)
Now I wish to get the data of the offsetted STL file with name your_mesh _1
for example.
I would appreciate it if you could tell me how I do that ?
Thank you so much.
You can copy a mesh like this:
your_mesh_1 = mesh.Mesh(your_mesh.data.copy())
And you can save it to a file like this:
your_mesh.save('your_mesh.stl')
Thanks for your reply
I was actually asking how to offset the stl surface and get the data of the your_mesh1
file.
for example if I use pymadcad as in this link:
where the inputs are ([points, ...], [triangles, ...])
and output is my_thick_mesh
from madcad import *
surface = Mesh([points, ...], [triangles, ...])
my_thick_mesh = thicken(surface, distance)
from that I would end up with a new data named my_thick_mesh
for the offsetted part (thickened part)
SO, my question is:
How can I use numpy-stl
the same way I use pymadcad
where my inputs are ( your_mesh
, and the distance) instead of ([points, ...], [triangles, ...])
,
and my output is the your_mesh1
data, instead of my_thick_mesh
Thank you again
I haven't worked with pymadcad yet so I can't be sure, but it looks like pymadcad is already using this library to read stl files: https://github.com/jimy-byerley/pymadcad/blob/b7757d15f8ae952f7b25460dc7c3674f6569d391/madcad/io.py#L155-L178
Copying that code, I believe you can do this:
# stlmesh is your numpy-stl Mesh instance
trinum = stlmesh.points.shape[0]
ptsbuff = stlmesh.points.reshape(trinum*3, 3).astype('f8')
pts = glm.array(ptsbuff).to_list()
faces = [(i, i+1, i+2) for i in range(0, 3*trinum, 3)]
# This is the pymadcad Mesh
mesh = Mesh(pts, faces)
mesh.options['name'] = stlmesh.name
thick_mesh = thicken(mesh, distance)
I have seen this before. The problem is that pymadcad
is not working on my machine. So I tried to see if numpy-stl
has a specific function that works as same as thicken
function.
Thank you
No, not really. This library was meant as a quick way of storing and loading STL files, performing operations on that mesh are largely outside of the scope of this library.
Thank you for clarification.
Great work I was just wondering Is there any way to offset an STL surface using numpy-stl ? something like what Alec has done in the link below: https://www.alecjacobson.com/weblog/?p=4708
Thank you