Easy Guide on How to Repair Your .STL Files
99% of the time you will be 3D modelling in your favourite CAD programs using their native file formats, and this will likely look perfectly accurate on screen. However, to 3D print that design you will most likely be converting it to a .stl file, which can be a bit like taking a fresh sheet of white paper (your CAD model), scrunching it up (file conversion) and then opening the scrunched sheet of paper and trying to make it flat (the final .stl file).
Okay, it’s not normally quite that bad, but .stl files can be tricky to work with, and sometimes you’re going to come across problems that make them difficult, or even impossible to 3D print. As a follow-up to his last blog on how to modify a .stl file, award-winning designer James Novak, aka. edditive shows us some quick fixes to repair errors in files using Meshmixer, a free file repair software. There are other free software specifically for working with .stl files, including MeshLab and Netfabb Basic, however in James’ experience, Meshmixer is by far the most intuitive and easy tool to use for all levels of experience. For more details on these programs, check out the 3D Designer Handbook section on File Checking.
Key Learning Takeaways:
- How to repair holes and gaps in surfaces
- How to delete or trim unwanted surfaces, particularly useful for 3D scan data
- How to add thickness to surface geometry, turning it into a solid
- How to reduce file size
STL File Repair for Beginners
Problem 1: Surface Holes
Having a hole or gap in your .stl mesh is one of the most common errors that will prevent your file from 3D printing. It’s important that your object is watertight (also known as manifold), meaning there are no holes on the outside surface where water would pour out if your model was hypothetically filled with water. It’s a term you will come across a lot when reading about 3D printing. Luckily most software used to slice your models and send them to your 3D printer will have some level of built-in file checking. This will alert you of these problems before you waste any material (examples of 3D printing software alerts also shown in the 3D Designer Handbook).
Above, you can see an imported .stl file in Meshmixer (which I have deliberately left holes in for this example), and quite clearly notice two areas highlighted in blue of missing surfaces. If you rotate a model like this around in 3D, you will be able to see inside the object, which is exactly what you don’t want for 3D printing. Luckily, the repair process is extremely simple in Meshmixer:
- On the left panel click on Analysis>Inspector. This will bring up a number of coloured spheres pointing directly to any gaps in your model (even extremely tiny ones you might not be able to see with the naked eye).
- You have three options for patching a hole: Minimal Fill (which will fill the hole with the minimal number of polygons), Flat Fill (which will create a flat surface patch), and Smooth Fill (which will attempt to blend between all the surrounding surfaces). You will also notice an Auto Repair All button which will automatically attempt to patch every gap using whichever one of the fill settings you have selected. This can have mixed results, and in this model actually deletes the pink highlighted cylinder in the image above – however I want to keep this feature as it is used to connect to another part. So I will explain how to manually repair each hole.
- For the hole on the left I want to use the Smooth Fill option since it is on a curved edge – a Flat Fill would make it look like a piece has been sliced off. So I make sure Smooth Fill is selected, and then I click on the blue sphere pointing at this hole. Voila! The hole is patched and blended to fit in with the surrounding geometry.
- The hole at the bottom can be capped with the Flat Fill or Minimal Fill options. Again, just make sure the correct setting is selected in the Inspector, and click on the blue sphere pointing to the hole.
- Now the model looks completely closed and watertight, but you may notice in the above image the bright blue line around the bottom cylinder – this means there is still a gap. The Flat Fill has only closed the bottom section, but did not join it to the small cylinder previously highlighted in pink. If you click on Edit>Separate Shells you will get a pop-up window showing that there are two separate pieces of geometry in this model, but we want this to be one clean model.
- In the Object Browser window, select the Shell 2 which is the detached cylinder. You can now perform the same Flat Fill repair to this cylinder as you did to the larger model, closing it as a solid cylinder. However it’s still separate and not joined to the main model.
- Now that we have two separate closed forms, simply hold the Shift button on your keyboard and select both objects in the browser – this will bring up a variety of options for what you can do with multiple objects. The one we want to use is Combine, joining these two objects into one closed model.
- For most simple patches this should be all you need to do. However for extremely complex surfaces you may need to try a number of tools, and get into the Sculpt menu where you can manually push, pull and soften the created patches to give you the results you want. The best practice is to make these repairs in the 3D CAD software you used to create the model in the first place, but of course if you want to edit or repair a model you downloaded from Pinshape, this probably won’t be possible.
Problem 2: Floating Surfaces and Trimming Surfaces (often from 3D Scanning)
3D scanning is evolving just as rapidly as 3D printing and is a easy way to bring real objects into your CAD software and begin designing around them. Alternatively, you may simply want to reproduce a part and go direct from your 3D scan to 3D printer. Either way, chances are that some cleanup will be required for the imported data, and if this isn’t satisfactory done by your 3D scanning software, you can use Meshmixer to delete all of those pesky floating surfaces. You may also have forgotten to delete a lot of background ‘experiments’ from your CAD process and accidentally included these in your .stl file!
Deleting rogue surfaces and objects are very easy in Meshmixer, and can be simply done using the same process explained for Problem 1.
- Once you’ve imported your .stl file into Meshmixer, just click on Analysis>Inspector. This will highlight all of the floating surfaces in pink. By clicking on each of the corresponding pink spheres, the surfaces can be deleted one-by-one. Alternatively you can try clicking on the Auto Repair All button which should do a pretty good job of removing all surfaces automatically depending on your file.
- If for some reason some surfaces were missed, you can manually delete surfaces using the Select tool. At the top you can chose between a Brush selection method, or a Lasso method which I have used in the image below, clicking and dragging around groups of surfaces. Once selected just press the Delete button on your keyboard and your problems are gone.
- Lastly you may need to go and clean up some of the edges, or remove unwanted sections of a model/scan. Again, using the Lasso tool is an effective way to select regions of surfaces and delete them completely. Alternatively, after selecting your surfaces, you can hover over the Edit menu and select Separate, which will split the model into two separate surfaces. You will then be able to Hide/Show different sections as needed in the Object Browser window, clicking on the small eye icons. This means that rather than permanently deleting parts of your geometry, you can simply hide them and come back to them down the track if you realize you actually need them.
Problem 3: Surfaces are not Solids
There are two types of 3D modelling. Without a long-winded explanation, essentially the difference is that Solid Modellers like FreeCAD use solid pieces of geometry to construct 3D forms, a bit like pieces of clay. Mesh Modellers on the other hand like 123D Sculpt+ use surfaces that have no 3-dimensional thickness, so in essence they look good on screen but can’t actually exist until they are turned into a watertight solid. This is also true of 3D scans. If you want to know more about different types of modelling, check out our Designer Handbook.
If you’ve found yourself having constructed an object as a surface, or imported a 3D scan that has no thickness, Meshmixer can easily extrude that surface in 3D space, turning it into a solid suitable for 3D printing. Above is a simple surface that could be used for a bowl, and you’ll notice the bright blue line around it’s perimeter indicating that it is an open surface just like in the Problem 1 example.
To give this surface some thickness you first need to select all of it using one of the Select tools described earlier, or alternatively a shortcut is to press Ctrl + A on your keyboard to select all. In the menu that opens go to Edit>Extrude and here you will find a range of settings to control both the thickness and direction of extrusion. For this particular bowl I have gone to the Direction tab and changed it to Normal, meaning that it will give a uniform thickness to the bowl, rather than extending in just one particular axis. You can play around with the settings until you get the result you want.
Problem 4: File Size is too Large for 3D Printing
The last problem that you may stumble upon, particularly as your objects get larger and their complexity increases, is that the resulting .stl file size is too large for your 3D printer or 3D printing service of choice. Third party printing services like i.materialise or Shapeways have upload limits so you may have to change the size of your file (100MB limit at imaterialise and 64MB for Shapeways). It’s important to reduce the mesh without sacrificing the quality, which I should say at the outset is best done at the initial export from your CAD software to minimise any distortion. My quick tip is to make sure in the export settings that your saving in ‘Binary’ format, not ‘ASCII’ – it’s a significantly more compact file format for .stl’s without losing quality). However if it’s not an option, Meshmixer can be really useful to quickly reduce file size and visualise how this will affect the quality of your surfaces.
For this example I’m going to return to the leaf from Problem 1, which as a .stl file is 30.757MB – pretty large for such a small design and definitely over the limit for someone’s email if I wanted to send it. So let’s look at how we can get this under 10MB.
- Select the entire model by pressing Ctrl + A on your keyboard to select all.
- Go to Edit>Reduce to bring up the options to reduce the mesh. Essentially the file size of a .stl is directly related to the number of polygons (triangles) that make up all of the surfaces. We will use the Reduce tool to reduce the quantity of polygons, therefore reducing file size.
- The menu will give you a range of options to reduce the size of your file. The simplest is to use the default Percentage option, allowing you to determine the final file size you want rather than needing to know exactly how many triangles will be used to make up the file. In this case I have calculated that in order to get my original .stl file below 10MB’s, I need a reduction of 70% or more. As you adjust the values, you will get a preview of what your model will look like, allowing you to control how much reduction you employ before the model becomes too distorted and ‘pixelated.’
- Once you’re happy and have accepted the changes, you can click on the Export button or go to File>Export to save this new reduced .stl file. As you can see in the comparison below, there is almost no perceptible difference in the quality of the 30.757MB file compared with the final reduced version at 9.362MB. I have simply increased the size of the triangles, minimising the quantity needed to create the same volume. Your regular 3D printer, or even a highly accurate SLS printer will never even know the difference in a change like this. It’s only if you really go crazy with the file reduction that you might start to notice them in your final print (and in fact many of the low-poly models which are popular on Pinshape can be produced using this technique – start with a detailed .stl of the object you want, and then just keep reducing the number of triangles!).
Between this article and the previous article on how to modify a .stl file, you now have some useful skills to both edit and repair .stl files, giving you the ability to 3D print almost anything! These of course aren’t the only tools available in Meshmixer, be sure to check out the Autodesk Meshmixer 101 guide that provides video tutorials for many more of the tools that you may need for your projects. 3D printing is a lot of fun, but being able to customise 3D models and make repairs so that your uploads to Pinshape are the best quality models possible will really get you noticed as a designer.
About the Authour: James Novak is a 3D designer and creator of edditive.com. Check out his website and more of his designs on Pinshape!