Issue 119 – October 22, 2022

MeshLab Tip: Removing internal details from complex STLs

Hey there,

It’s Robin from CFD Engine & it’s been a while since I shared a tip for anything other than OpenFOAM or ParaView, so I’m dropping a MeshLab tip today.

If you want a quick way to remove unneeded internal detail from complex STLs/OBJs before heading to snappyHexMesh, then this one’s for you.

Let’s go…

Imagine this…

Picture the scene, our colleague/client/friend has sent us this “sporty” little number for aero testing. Not too bad, but it’s arrived as an OBJ file (i.e. a big dumb lump with no easy way to switch bits on/off). Plus, it’s got loads of details that we’re not interested in, like the interior & the headlight reflectors, for example.

A sporty little hot hatch with lots of internal faces to delete before meshing with snappyHexMesh

If it was a CAD model we could just re-export it without those bits, but what are our options when it’s just one big surface mesh?

Option Zero

Before I get into the MeshLab option, don’t forget, we could just mesh this as is – snappyHexMesh won’t be upset with us & it’ll discard any areas that it can’t reach from our locationsInMesh 👍

But if you’re old school (like me) you might want to remove as much of that extra detail before going into snappyHexMesh. This should give SHM an easier time (it doesn’t have to mesh areas & then throw them away), the input file will be smaller & it should be easier to debug if (when) it leaks.

This kind of job can be a pain in some CAD packages so, how can MeshLab help?

The MeshLab Option

If you’ve never heard of MeshLab, it’s an open-source mesh processing tool with loads of neat features for wrangling surface-meshes. You can read more about it in this previous email, but it’s well worth adding to your toolkit.

The general idea

Today’s tip works by identifying all of the faces which can’t be seen from the outside of our model. We do this using the ambient occlusion filter, essentially running around the model with a torch, giving each vertex a greyscale value based on how much light it received.

External surfaces end up with a nice diffuse fake shadow, but the inside faces are never illuminated & end up pure black. This makes them easy to select & then separate from the main mesh for deletion, or for further cleanup.

The steps

  1. File > Import your OBJ or STL mesh file
  2. Apply the ambient occlusion filter using Filters > Color Creation & Processing > Ambient Occlusion (use the default values for now)
  3. Select the interior (black) faces using Filters > Selection > Select Faces by Color. Use the default settings initially & tweak the sliders to refine which faces are selected (toggle the preview button to get a live view of the selected faces). Once you’re happy with your selection, click apply.
  4. Use Filters > Mesh Layer > Move selected faces to another layer to separate your chosen faces from the main mesh (leave Delete original selection checked)

You can now export the “no internals” mesh & go to SHM, or do some extra cleanup (or merge everything back together & have another go) – up to you.

Alternatively, if you want to keep the internal faces, just throw the outer surfaces away after Step 4 instead.

Our example

Going back to our hot hatch example, the internals represented 63% of all the faces in the model, well worth deleting in my book. Here are some MeshLab x-rays showing the original body assembly, the internal surfaces that we identified using this method & the final model, featuring just the external surfaces.

x-rays of our model in MeshLab showing the original surfaces, the internal surfaces we removed & our final external-only mesh

Any use?

There you go, a quick 4-click method for extracting the internal surfaces from a complex OBJ/STL file using MeshLab. Not something you’ll use every day, but it could save you an afternoon of messing around in CAD trying to achieve the same.

Is this something you have to deal with in your models? Might you give this technique a try? Or would you just go straight into snappyHexMesh & let it decide which surfaces to keep?

Let me know if you’d like more MeshLab tips & I’ll queue some up for future emails.

Until next week, stay safe,

Signed Robin K