How to Repair STL Files in MeshLab

Repair STL Files in MeshLab
(Image credit: Tom's Hardware)

It can be frustrating when you have invested a lot of time and effort in creating your STL file, and when you try to slice or 3D print, you find that you can’t proceed because of errors. An STL file represents a 3D model as a collection of triangles, and these triangles form the surface representing the shape and geometry. However, issues like intersecting and overlapping triangles can occur during 3D modeling or conversion from various file formats to STL. Intersecting triangles is where triangles cross each other in ways that create non-manifold edges. Overlapping triangles, on the other hand, are where two or more triangles share the same surface area. 

These errors and many others like holes and gaps can cause the slicer to struggle to process the design, resulting in errors. If you manage to slice the file, it can fail during 3D printing or result in prints with defects even if you are using one of the best 3D printers. To address these issues, you need to analyze the mesh, repair it, and optimize it for 3D printing, and that’s where MeshLab comes in. MeshLab is a free and open-source software useful for detecting and repairing errors in 3D models and ensures they are ready for 3D printing without compromising their integrity. Below we'll go over how to analyze and clean meshes in MeshLab.

Inspecting, Scaling, Rotating, and Positioning the Mesh

Once you import your file, you can rotate the view to see the model from different angles by holding the left button on your mouse and moving around. You can also pan by holding the control or command key on your keyboard and then move the design around the workspace. Zoom in closely to inspect areas that might require cleaning by moving the mouse wheel up and down. If you don’t have a mouse wheel, hold the shift key, then left drag on your touch pad or mouse. 

If you see any unwanted elements, you can select them, go to Filters > Selection, and then delete faces or edges. For the design below, for example, an unwanted part on the right was captured by a scanner.

(Image credit: Tom's Hardware)

Go and choose the face selection option on the menu bar.

(Image credit: Tom's Hardware)

Hold the control key to add the selection or shift key to subtract it.

(Image credit: Tom's Hardware)

Go to Filters > Selection > Delete Selected Faces and Vertices to delete it.

(Image credit: Tom's Hardware)

When you click on it, that part will disappear.

(Image credit: Tom's Hardware)

In addition to deleting unwanted features, you can also easily scale, position, and orient your 3D models in MeshLab. Follow the steps below to do that.

1. To scale the model, go to Filters > Normals, Curvatures and Orientation > Transform > Scale, Normalize.

(Image credit: Tom's Hardware)

2. In the window that launches, enter the scaling factors for the X, Y, and Z axes, then click Apply.

(Image credit: Tom's Hardware)

You can also preview the new resized model by clicking on the Preview checkbox.

3. To position the model, go to Filters > Normals, Curvatures and Orientation > Transform: Translate, Center, set Origin.

4. Input the desired values to move your model along the X, Y, and Z axes.

(Image credit: Tom's Hardware)

You can then click Apply.

5. Rotate the model by going to Filters > Normals, Curvatures and Orientation > Rotate.

6. Choose the axis to rotate your design, and when you are done, click Apply.

(Image credit: Tom's Hardware)

Cleaning up the Mesh

MeshLab comes with various tools for cleaning the mesh, which can be found in the Cleaning and Repairing section of Filters. For example, there are options for removing unused and duplicate vertices and faces that can make the model more complex than necessary. To use it, follow the steps below.

1. Remove duplicate faces by going to Filters > Cleaning and Repairing > Remove Duplicated Faces.

(Image credit: Tom's Hardware)

This will eliminate overlapping faces in your mesh. You can check the dialogue window on the bottom-right section of the workspace to see the details of the deleted faces if there were any.

You can remove duplicate vertices by going to Filters > Cleaning and Repairing > Remove Duplicated Vertices. And for checking and removing unused vertices you choose Remove Unused Vertices. This cleans up any vertices that are not part of the faces.

2. Repair Non-manifold geometry by going to Filters > Cleaning and Repairing > Repair Non manifold edges.

(Image credit: Tom's Hardware)

This feature will remove twisted or distorted edges that can cause issues later. You can also select Repair non Manifold Vertices by splitting to repair vertices that have problems.

3. Delete triangles and vertices you don’t want by selecting them, then go to the top right section and click on the appropriate option to delete them. For example, to delete the bottom faces, we select them first and then click on Delete Selected Faces in the top right section.

(Image credit: Tom's Hardware)

Below are the results after clicking it.

(Image credit: Tom's Hardware)

Smoothing Meshes in MeshLab

Smoothing meshes helps enhance the model's appearance by reducing the rough edges and surfaces. Follow the steps below to smooth meshes. 

1. Go to Filters > Smoothing, Fairing and Deformation where you can find a range of smoothing options.

(Image credit: Tom's Hardware)

2. Select Depth Smooth to move vertices in one single direction. When you click it, you will see a dialog box where you can specify the number of smoothing steps and the strength that controls the smoothing.

3. Apply Laplacian Smooth option if you would like to achieve a gentle and uniform smoothing effect across the entire mesh. It smooths the meshes by averaging the positions of the neighboring vertices. When you click on it, you will see a dialog box when you can apply the settings, and you can preview before you apply.

(Image credit: Tom's Hardware)

You can try other smoothing options in the filters section and adjust the settings on the dialog box that appears on each until you achieve your desired smoothness while preserving essential details and features in the mesh.

Simplifying Meshes and Filling Holes

If you are working on a complex design with a very high polygon count, it can take much time to 3D print, and the material consumption is high too hence, for such designs, it’s important to reduce the number of vertices and faces in the design. You can achieve that by following the steps below:

1. Go to Filters > Remeshing, Simplification, and Reconstruction > Quadric Edge Collapse Decimation.

(Image credit: Tom's Hardware)

2. Adjust the number of faces that appear in the dialog window.

(Image credit: Tom's Hardware)

You can also adjust other parameters for the simplification process manually. These options include:

  • Quality threshold: This influences the shape of the original model. You can set a value between 0 and 1. 
  • Preserve boundary of the mesh: When you click the checkbox for this option, it will tell the software to maintain the integrity of the mesh boundaries during the simplification process. This helps prevent issues like exposed edges from occurring. 
  • Preserve normal: This helps prevent the software from flipping face normals, hence preserving the orientation of the surfaces. This ensures that the visual appearance of your design is maintained.
  • Optimal position of simplified vertices: The check box for this option is checked by default, and you should not deselect it. It helps ensure that the edges don’t collapse and that the original shape of the mesh is maintained.
  • Planar simplification: You should activate this option when your design has a flat surface to ensure those areas are tessellated.

When you are satisfied with the settings, click Apply. MeshLab will then process the mesh and generate a simplified version while preserving the overall shape and structure of the design. You can also inspect it to ensure that all the essential details are retained and that the simplification process hasn’t introduced any distortion to the design.

3. To fill holes, go to Filters > Remeshing, Simplification and Reconstruction > Close Holes.

(Image credit: Tom's Hardware)

4. Adjust the settings in the dialog box that launches based on your requirements, then click Apply. The holes will be filled automatically.

When you are satisfied with editing and repairing your mesh, save it by going to File > Export Mesh.