Is mass a good method to get volume from meshes?

Is calculating the mesh’s mass / mesh’s density a viable solution to calculate accurately the volume of meshes?

My results have to be accurate since I’m working on a realistic metallurgy game.

Checking the volume on meshes of containers I get extremely wrong answers
image
image
Real is the mass/density, rough is the x, y and z of the size multiplied together
The last number is just a percentage of real/rough

Since XYZ creates a rectangular parallelepiped shape, it will be incorrect if your shape is not a rectangular parallelepiped. You could use the mass, but you have to remeber that different materials on roblox have different densities (every base part has a property named density).

Despite the material, mass/density will result the same number.

Anyone know of a more reliable method for finding mesh volume?

Do you need to do it at runtime, or is precalculating the volume and loading that data at runtime an option for you? I’d bet there’s a plugin for blender that allows you to calculate the volume of meshes

has to be calculated at any time within the game, and I’ve tried blender volumes and they dont intergrate well

and the amount of modules that would need to be put back in blender and recalculated wouldn’t be efficient

Multiply mass by PhysicalProperties.new(part.Material).Density to get the absolute mass.

I’m not trying to get absolute mass, and basepart.Mass / basepart.CurrentPhysicalProperties.Density will return the same number no matter the material, as basepart.CurrentPhysicalProperties.Density = material Density

I think mass/density is the best you’re going to get while the game is running. The players can’t really tell what the volume is anyways, so ±5% from the actual visual volume shouldn’t be too big of a problem.

You might want to consider running some tests:

  • Use blender to calculate the volumes of a few of your meshes, compare with the studio results, see if the average error is acceptable
  • Check that the volumes calculated in game are constant. If they aren’t it might cause problems for your game and it could be better to pre compute the values and store them.
  • Check if collision fidelity affects the object’s mass/volume. (I’m pretty sure it won’t but it might be worth looking into.)

If you’re trying to get volumes of percentages of shapes (ex: quarter full container) you’ll need to know some calculus or basic volume formulas to estimate the volume. (For the image you have above the estimation should be really accurate.)


I meant even if the game’s calculation is consistently slightly off the players won’t be able to tell. You could probably use this formula to convert the volumes between blender and Roblox: ExpectedForRoblox = (HeightInRoblox/HeightInBlender)^3 / BlenderVolume

The player doesn’t need to see the volume. The volume needs to be calculated for how much can fit in a container or when melting metals.

Me and my modeller have tried to use blender’s volume but we tend to have trouble converting it into roblox.

2 Likes

There are algorithms for calculating the volume of a mesh. Apparently Shoelace algorithm can be extended to 3D, try searching around for how to do that

Thank you for reading!

The mesh’s mass is not related to its volume. The density is, but that’s only because mass = density * volume.
The mesh could be made of one material with a constant density, or several materials with a different density for each. The volume is the only thing that’s relevant.
For a single simple shape, you can probably use its function’s parameters directly to calculate its volume (e.g. volume of a cylinder = pi * r^2 * height). For more complicated shapes, you have to break them down into smaller pieces.

Found this method to make a function for getting mesh volume accuratetly, not sure if it works, havent tested it yet.

function getVolume(part)
    local mesh = part:GetRenderMesh()
    local vertices = mesh.Vertices
    local faces = mesh.TriangleCount
    local volume = 0
    for i = 0, faces - 1 do
        local v1 = vertices[mesh.Triangles[i].X + 1].Position
        local v2 = vertices[mesh.Triangles[i].Y + 1].Position
        local v3 = vertices[mesh.Triangles[i].Z + 1].Position
        volume = volume + (v1.X*v2.Y*v3.Z + v1.Y*v2.Z*v3.X + v1.Z*v2.X*v3.Y) - (v3.X*v2.Y*v1.Z + v3.Y*v2.Z*v1.X + v3.Z*v2.X*v1.Y)
    end
    volume = volume / 6
    return volume
end