Calculating the volume of a closed custom mesh?

How to calculate it’s inside volume?

Not box, neither sphere.

Is there something on JME that already does that?

Also, has someone used the already existing bounding volume value to do some cool thing?

I don’t know if there’s already a function for that, but the algorithm is fairly straight-forward:

  • Define a random apex point a . Inside or outside the model, it doesn’t matter. Though, it should be more accurate if you use a close one, like the center of the bounding box.
  • Iterate over all triangles. Take the face consisting of these 3 vertices and connect it with the apex to form a pyramid.
  • Calculate the volume of this pyramid. It is equal to one sixth of the parallelepiped / triple product.
  • Sum up the volumes of the pyramids.

In the image below, the green volumes are added and the yellow volumes are automatically subtracted. Yellow volumes are negative because of the normal which points towards the apex.
Below’s the formula for a single pyramid’s volume.

Note that this won’t work if your model has inside faces. It needs to be a simple shell.

Fun fact: You can use this to check if a model has holes or other “errors”. For that, repeat the volume calculation several times with different apex points. If there’s a big variance in the values, it indicates “errors”.


If that’s the kind of “volume” that you mean then “no” JME doesn’t have anything built in to do that.

a) it’s a lot of work
b) almost no one would ever need it for anything

This won’t work well for concave shapes, right? Unless you combine it with something like vhacd

1 Like

It does indeed work for arbitrary/concave shapes because the positive and negative values cancel out correctly :slight_smile:
The restriction to “shells” (I think the technical term is “2d manifold”) is more of a problem. You can’t have open disconnected partitions / islands of triangles. All edges must sit between two triangles.
(hm… could work with certain T-junctions too)

1 Like

If an “island” is a “shell” itself, it seems easy to exclude that from the result. The other question is what to do when you have “shell inside of a shell inside of a shell”, you’d need to specify some “medium type” for each volume or something… but yeah, all that looks closer to some physical modelling than to game development anyway

wow! cool!

I think that can be a step in-between to the pseudo-famous DMM (digital molecular matter (matters hehe)).

well, I am quite sure some cuts and slashes with boolean operations will make the model ready to be fully volumetricized.
@wcomohundro do you believe it could be easier to re-use the calculations perfomed on your library to achieve this custom/hollowed mesh volume calculation result?

That’s the point, “effort” vs “need”. But… there is another variable: “fun”! I mean, I think it will be quite fun and cool to use it, or if there is no implementation, to spend some time trying to make it work, because IMO it will be a lot fun to be able to use it to provide more options in a 3D game or application :smiley:

…which would quickly lead us to “universal program” concept :wink:

1 Like

I dont mean anything utterly precise, just enough to be fun, fast and sufficiently useful :slight_smile:

the more we want to embrace, the more energy, time and lifespan will be necessary to let it be achieved xD

But… if we have the basics, an initial imprecise something of most things, “somethings” that are not perfect but useful, then we can have many options in not that much time, and still let it all evolve and improve becoming more and more perfect, each thing would feed mainly on ppl interest. Now about game balance complexity, that may become quite scaring to think about :D.

This is the part I wonder about. What’s useful about knowing that Jaime has a volume of X units?

that specific use case would be to determine if he is attending to his fitness sessions :slight_smile:


sum that result, for each triangle of the mesh, and get the abs of the final value!