Getting the Volume of an Uneven Mesh

Let's say I have a cube, and that cube breaks apart into 100 different unevenly sized pieces.

How can I get the volume of each of those pieces compared to the cube's volume?

Using this in order to get the mass of each piece; for example, if the large cube is 100 mass, then the largest piece might be 30 and there might be some that are 0.2, etc...

Using C# and Unity with Rigidbodies

From here, this can be used to calculate the volume of an arbitrary 3D mesh.

public float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
{
float v321 = p3.x * p2.y * p1.z;
float v231 = p2.x * p3.y * p1.z;
float v312 = p3.x * p1.y * p2.z;
float v132 = p1.x * p3.y * p2.z;
float v213 = p2.x * p1.y * p3.z;
float v123 = p1.x * p2.y * p3.z;
return (1.0f / 6.0f) * (-v321 + v231 + v312 - v132 - v213 + v123);
}

public float VolumeOfMesh(Mesh mesh)
{
float volume = 0;
Vector3[] vertices = mesh.vertices;
int[] triangles = mesh.triangles;
for (int i = 0; i &lt; mesh.triangles.Length; i += 3)
{
Vector3 p1 = vertices[triangles[i + 0]];
Vector3 p2 = vertices[triangles[i + 1]];
Vector3 p3 = vertices[triangles[i + 2]];
volume += SignedVolumeOfTriangle(p1, p2, p3);
}
return Mathf.Abs(volume);
}


With VolumeOfMesh you can calculate the volume of each piece, and then sum them up to get the volume of the original shape.