[Closed] Negative Volume Calculation
I’m trying to calculate the volume of various objects in my scene using the MaxScript function given in the 3ds Max documentation (slightly modified to add surface area as well), and the majority of the time it returns the exact same result as the measure utility, but for a few objects it’s returning a negative value (while the measure utility gives a positive value, as expected). What could be causing this?
fn meshVolSurfAreaCenter obj = (
local vol = 0.0
local surf_area = 0.0
local center = [0.0, 0.0, 0.0]
local n = meshop.getNumFaces obj
for i = 1 to n do (
local face = getface obj i
local v0 = getVert obj face.x
local v1 = getVert obj face.y
local v2 = getVert obj face.z
surf_area += meshop.getFaceArea obj i
local dv = Dot(Cross(v1 - v0) (v2 - v0)) v0
vol += dv
center += (v0 + v1 + v2) * dv
)
vol /= 6
center /= 24
center /= vol
#(vol, surf_area, center)
)
Sorry I should have specified further, the absolute value is wrong as well. The actual volume of the object I checked was 2.69 and the function returned -4.7
Unfortunately I can’t share the models I’m using, but I am fairly sure they don’t have any holes in the mesh. They do however have holes in the actual physical object sense, but so do plenty of the objects that calculate correctly. Is there a way I can check the manifold in 3ds Max to confirm there isn’t an error in the mesh?
LOL, you may have flipped axis in those objects’ transform matrix.
Try resetting xForm on them.
I am not applying any modifiers to the objects before I calculate the volumes, I’m just importing CAD data into my scene and checking immediately, so I didn’t think this would be the issue but I tried and confirmed that it didn’t work.
some face normals are flipped ?
Create a 1x1x1 box, note its volume…
Now pick a corner of the box, flip the normals of the 3 faces of that corner…vol is now negative…and abs is also different…
Yeah imported CAD data is kinda notorious for having all kinds of possible issues…
for example; flipped normals, double face, unwelded vertexes, etc…
Which all can be related to the problem you seem to be having.