3
$\begingroup$

Is there a function in blender to measure the volume of the mesh that you input in the geometry nodes? For example let's say I have a cube with the dimensions (10,10,10), then it should output 1000.0 because that is the volume of the cube.

$\endgroup$
2
  • 1
    $\begingroup$ Hello and welcome! No, unfortunately this functionality does not currently exist. With a simple geometric shape it could be calculated (for example in case of a cube), but for more complex meshes there is no built-in way here. $\endgroup$
    – quellenform
    Dec 27, 2022 at 18:24
  • $\begingroup$ When I've wanted to do this (actually, I wanted to find the center of gravity of a mesh, something slightly different) I've boolean'd it with a bunch of cubes, then counted the number of cubes in the output (which you can do by scaling along individual origins to 0, merging by distance, and then reading the statistics.) But that's a sampled solution; you probably want to see analytic solutions like discussed at blender.stackexchange.com/questions/63113/… . $\endgroup$
    – Nathan
    Dec 27, 2022 at 18:29

3 Answers 3

4
$\begingroup$

Using Blender 3.4's topology nodes and recreating this answer will give you the volume of a mesh.

public float SignedVolumeOfTriangle(Vector p1, Vector p2, Vector p3) {
    var v321 = p3.X*p2.Y*p1.Z;
    var v231 = p2.X*p3.Y*p1.Z;
    var v312 = p3.X*p1.Y*p2.Z;
    var v132 = p1.X*p3.Y*p2.Z;
    var v213 = p2.X*p1.Y*p3.Z;
    var v123 = p1.X*p2.Y*p3.Z;
    return (1.0f/6.0f)*(-v321 + v231 + v312 - v132 - v213 + v123);
}
public float VolumeOfMesh(Mesh mesh) {
    var vols = from t in mesh.Triangles
               select SignedVolumeOfTriangle(t.P1, t.P2, t.P3);
    return Math.Abs(vols.Sum());
}

The above code recreated in nodes:

geo nodes

Apologies for the spaghetti, Blend file is attached so no one has to recreate it.

You can check the results by enabling and using the built-in "3D-Print Toolbox" addon.

$\endgroup$
2
  • $\begingroup$ Very nice and efficient approach. $\endgroup$
    – Fred I. R.
    Dec 31, 2022 at 6:41
  • 1
    $\begingroup$ This is awesome ! I would just replace the "Points Count" output type to Float instead of Integer so that you don't lose on precision. $\endgroup$
    – Gorgious
    Jan 2, 2023 at 8:43
1
$\begingroup$

There is at list a possibility of volume calculation but it’s painfully slow, you have to stop the calculation on the last frame so it’s not very practical, furthermore it doesn't work with moving objects.

enter image description here

It’s based on the buffer hack. At every frame it increment the Z position of a plane accordingly to the index and with a Mesh Boolean it calculate the surface of this cross section of the mesh. Then the mesh section is instanced and the surface is stored in a Store Attribute node.

enter image description here

At the end, after the buffer hack, a Statistic Attribute calculate the mean of all the surfaces (except the first and the last witch are those of tangent planes and cause problem with the boolean, any way there surfaces is equal to 0), multiply it by the height and this volume value is stored too.

enter image description here

You have to set the definition by setting the Start Frame and the End Frame with a Driver. I hope it will help somebody one day...

$\endgroup$
0
$\begingroup$

You can use rigid body ops.

bpy.ops.rigidbody.object_add()
bpy.ops.rigidbody.mass_calculate(material='Custom', density=1) # density in kg/m^3
volume = ob.rigid_body.mass

https://blender.stackexchange.com/a/304033/72020

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .