Outputting an STL file that contains multiple objects for import into Blender
I want to print a object that looks like a flat board with a set of matchbox-like lumps on top of it.
I have written a script that outputs an STL file. To keep the script simple, it creates an object that includes non-manifold edges. To be precise, the board and the boxes are a single model, but each has 6 faces made from 2 triangles. The underside of each matchbox rests on the top of the larger flat board.
If I understand correctly, the top face of the board should be broken up into many smaller triangles to take into account the position of the matchboxes, but coding this by hand (although it might be an interesting Exercise For The Reader) would not be a good use of time. Well-written code that already does this is built into FOSS applications like Blender.
However, Blender cannot merge or fuse shapes that are part of the same object. My current understanding is that I will need to:
- Provide Blender with multiple objects
- Select all the objects
- Use Ctrl-J to merge them
- Export the world in STL format
Is this a valid approach?
If so, my key question is: how do I format the STL file so that Blender will recognize that it contains multiple separate objects?
(I have found references to STL files containing multiple objects, but I have seen nothing in any of the STL files that I have examined that tells me: here is the end of one object and the beginning of another.)
Or should I just be clunky and export two STL files — one for the board and one for all the matchboxes — and then import both into Blender?
NOTE: I know that there are free services like Netfabb that will correct my simple files for me, but I would prefer not to include that in my workflow if possible.
Blender imports all STL files as if they are a single object. If you have multiple meshes in the object that you want to be separated, you can press tab to enter edit mode, select the parts that need to be separated, then hit P and separate by selected.
If you want to print those pieces as one part you have to get rid of any internal faces. The easiest way to do that is to select an object and then use the boolean modifier in union mode. Once you have the object that you want to fuse selected and in place, apply the modifier, that should leave you with an object without internal faces.
I think there's an easier way to do this - if you're not committed to using Blender, and it sounds as if you're not.
Take a look at http://www.openscad.org/ (which should run anywhere that Blender does). It's very easy to write code to produce your desired shape (in this case it would be a union of cuboids) in OpenSCAD's description language, and then you can use OpenSCAD itself to render that to STL. (It's even possible to automate this from the command line.)
Let's look at it...
It's something like this: a closed box with protrusions that have no inner surface. like this cobbled together thing.
Let's just for fun export it as a .stl. yes, a single .stl file. And now open it in MeshMixer:
Looks not half bad, right? But a red box? What shall that mean? look at the blender model again: Oh right, the normals on those surfaces are backwards!
Fin blender flips the normals, reexport the .stl, reload into MeshMixer!
Now we are talking! Let's look how we can fix this...
Edit > Make Solidwith a high
Solid Accuracywith both a high
Mesh Densityresults in reasonable sharp corners and... DANG! One solid body, all neatly closed.
Yet, we got a problem: this thing that had been 11 faces and 16 vertices became almost 1.2 million vertices and 2.4 million faces. This surely can be condensed some, but we just achieved a well printable merge of the objects.