Advanced Walkthrough - ExeVirus/boxgen GitHub Wiki

PART I: Watertight Meshes

Okay, so you've downloaded or created a mesh and you want to use it in minetest and you have this great shiny tool called boxgen to do the heavy lifting for you. You run it through the boxgen and out comes... garbage:

Why is this happening? You guessed it, your object is not watertight. This means that if you submerged your object water would get inside your object. If you have many objects in one mesh, it means that at least one of them is not watertight.

Another way to describe a mesh that is watertight is that there are no holes on the surface anywhere, every triangle is connected to 3 other triangles, every edge is touching 2 triangles, etc.

This is extremely important for boxgen to work, because it has to figure out what is "inside" and "outside" the object. If there is a hole anywhere, then "inside" is technically the same as "outside".

Some things to know:

  • Even if an object looks watertight, it can be filled with holes.
  • The fastest rendered mesh is often the NOT watertight one because it uses less triangles. We only use watertight meshes for calculating bounding boxes, and then we don't need them anymore.
  • If your object comes from CAD, it's typically watertight. If it came from blender or similar, it's probably not.

Part II: Bridge.obj and Meshlab

The object I will be working with is a rickety bridge from a mod I will be releasing soon, and is a typical example of a game graphics model that is not watertight:

The tell-tale sign that this mesh is not watertight, even before testing with boxgen, is that it has single faces that enclose no space. For example, the walls of the bridge are a single triangle thick, same for most every other part of the bridge.

In general, to fix thin wall issues, we need to grow our mesh a bit, so that those walled areas actually enclose something. The tool we will use for this is meshlab, an open-source tool available online, and that I cover in more detail in the Meshlab Tutorial. What is important to understand is why I do things and not necessarily how at this point.

So, in order:

1. We must first import this mesh into meshlab:

2. Now to "stretch" or blow up our model like a balloon. To do so, we use multiple steps. First we do a "create solid wireframe", default settings will enlarge the mesh some

3. Then a montecarlo sampling (points on the mesh), 3,000,000 samples, this is so we can recreate the look of our current mesh.

4. Then a "surface reconstruction: VCG", but with "vertex splatting" on. (basically a voxelizer)

5. Now we are getting closer. Next to fill in all those holes, do a uniform mesh resample, but increase the offset to 51.5%, 1% accuracy:

6. Now let's shrink it back down a bit with uniform mesh resample, but at 49.0% offset:

7. At this point, we have a watertight mesh, because uniform mesh resample does so, but there are too many faces at 12,000 for my liking, so we will do a "simplification: quadratic edge collapse decimation" with a target number of faces of 2000:

And there we have it, a mushy, watertight approximation of our mesh that boxgen can boxify correctly. Just export to obj and we can move on to part III.

Part III: Boxgen with Watertight Model (the easy part)

We now have our watertight bridge model, so let's boxify it. If you don't know how to do this, please complete the simple walkthrough. For those that have already, I used the following parameters:

  • spacing: 0.08
  • minfill: 0.7
  • minvol: 0.01
  • minqual: 0.01

...and got this as my result:

26 boxes per 3x3x3 node area, which I about the sweet spot for my liking. Though again, still haven't had much in terms of performance issues reported yet :)

Happy boxing!