27

How can I display volume of any mesh object?

I can display length of an edge, the area of the face, but nothing for volume. Is it possible?

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
karpi
  • 533
  • 1
  • 4
  • 12

4 Answers4

30

You can use the 3D Print Toolbox add-on for that. Activate it in the Preferences and it will appear in the Tool Shelf of the 3D View. Top line buttons let you calculate volume and total area.

3D Print View

quellenform
  • 35,177
  • 10
  • 50
  • 133
Lepelaar
  • 510
  • 5
  • 3
10

First activate the 3D-Print Toolbox addon: Edit > Preference >Add-ons and search 'print'. Now you can find the toolbox in the sidebar panel (press n if it does not show) Look in the 3D-print tab under statistics.

enter image description here

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
Lepelaar
  • 510
  • 5
  • 3
3

You don't need an addon for this.

In general, the methods for calculating the volume of a mesh can be divided into two categories: (1) Analytical methods which are based on mathematical formulas, these methods are efficient and accurate but are limited to simple shapes. (2) Numerical methods which involve breaking the mesh into smaller parts and summing the volume of those parts. These methods can be applied to any shape, but the accuracy of the results may vary depending on the number of parts used and the method for calculating the volume of each part.

Here's a script that uses the Numerical Method to calculate the volume of a mesh.

import bpy
import bmesh
from mathutils import Vector

obj = bpy.context.active_object me = obj.data

bm = bmesh.new() bm.from_mesh(me) bm.transform(obj.matrix_world) bmesh.ops.triangulate(bm, faces=bm.faces)

volume = 0 for f in bm.faces: v1 = f.verts[0].co v2 = f.verts[1].co v3 = f.verts[2].co volume += v1.dot(v2.cross(v3)) / 6

print("Volume:", volume)

bm.free()

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
  • 1
    This can also calculate the total volume of multiple separate meshes within an object, but take note that mesh overlapping is not taken into consideration and will still result in the sum of all mesh volumes regardless. – Harry McKenzie Jan 13 '23 at 02:03
  • 1
    Very nice. I use this to find duplicate meshes with flipped normals and it works very well. – relaxed Sep 28 '23 at 10:25
1

For performance reasons I came up with the following solution based on rigid body ops.

def select_object(ob):
    for o in bpy.context.selected_objects:
        o.select_set(False)
    ob.select_set(True)
    bpy.context.view_layer.objects.active = ob

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