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

Merge STL question #214

Closed DrPepper1234 closed 10 months ago

DrPepper1234 commented 10 months ago

Thank you for the work, it does a great job manipulating STL file. Is there a way to merge multiple STL files into one STL that is a single body? Right now I have some STL that import as separate bodies but would prefer a single body . Thank you

wolph commented 10 months ago

A Mesh object is simply a collection of points and consequent triangles so merging them can be as simple as concatenating them. This example demonstrates it: https://github.com/wolph/numpy-stl#extending-mesh-objects

Specifically:


cube = mesh.Mesh(numpy.concatenate([
    cube_back.data.copy(),
    cube_front.data.copy(),
]))
DrPepper1234 commented 10 months ago

Maybe my question was not phrased properly. Say I have two cubes, one with side of 1mm and one with side of 10mm, both being centered in origin, 0,0,0. If I concatenate the two meshes and save the stl, when importing the stl file in say SolidWorks I get two distinct meshes that SW will use to generate 2 bodies. What I would like is a single body so only a single all encompassing mesh. The example above is a simple one but imagine meshes that just intersect and not included into each other. Guess I'm after some sort of boolean operation but my programming expertise is limited, I'm a mechanical designer.

wolph commented 10 months ago

Ah, I misunderstood. That is certainly possible but it's a fairly complex operation and not something this library does out of the box.

I would suggest looking at the solutions offered by this stackoverflow question: https://stackoverflow.com/questions/51476722/intersection-3d-meshes-python

DrPepper1234 commented 10 months ago

Thank you for providing the link, seems it would help.