BMesh calc_volume() reports an incorrect volume, off by a significant factor #79369

Closed
opened 2020-07-29 14:06:36 +02:00 by Dion Moult · 7 comments

System Information
Operating system: Gentoo Linux
Graphics card:

Blender Version
Broken: 2.83.1

I have a funny pipe shaped object. The following script produces a volume of 0.124:

>>> bm = bmesh.new()
>>> bm.from_mesh(bpy.context.active_object.data) # Ensure funny pipe shaped object is selected
>>> bm.calc_volume() # returns 0.124

The actual volume should be approximately 0.521.

The attached file has the script and object ready for you to run :)

wormdebug.blend

**System Information** Operating system: Gentoo Linux Graphics card: **Blender Version** Broken: 2.83.1 I have a funny pipe shaped object. The following script produces a volume of 0.124: ``` >>> bm = bmesh.new() >>> bm.from_mesh(bpy.context.active_object.data) # Ensure funny pipe shaped object is selected >>> bm.calc_volume() # returns 0.124 ``` The actual volume should be approximately 0.521. The attached file has the script and object ready for you to run :) [wormdebug.blend](https://archive.blender.org/developer/F8728409/wormdebug.blend)
Author

Added subscriber: @Moult

Added subscriber: @Moult
Member

Added subscribers: @ideasman42, @lichtwerk

Added subscribers: @ideasman42, @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Can confirm the difference.

Note: still works correctly when you triangulate prior (same as 3D printing does by default)

import bmesh
import bpy
bm = bmesh.new()
bm.from_mesh(bpy.data.objects['IfcActuator/BezierCurve'].data)

# triangulate prior makes the difference
bmesh.ops.triangulate(bm, faces=bm.faces)

print(bm.calc_volume()) # Will return 0.124, correct value should be ~0.52.
# You can confirm this using the 3D print add-on which gives the correct result ias ~0.521m3

Without prior triangulation:

  • normals are already consistent here (would asume this would have caused errors as well)
  • calc_volume code then uses BM_face_calc_tessellation (this seems to be different from BM_face_triangulate which the bmesh.ops.triangulate uses)

For your mesh it already improves splitting non planar faces:

  • Mesh > Clean Up > Split Non-Planar Faces (up to a reported volume of ~0.332)

Then if you move all of the geometry in the quadrant of only positive vertex coordinates it improves further

  • up to a reported volume of ~0.445

This might all be a limitation of the algorithm used, but I would like to ask @ideasman42 if this is to be expected? Could this be more robust?
Tempted to call this a bug, but there might be reasons to do it the way it is now...

Can confirm the difference. Note: still works correctly when you triangulate prior (same as 3D printing does by default) ``` import bmesh import bpy bm = bmesh.new() bm.from_mesh(bpy.data.objects['IfcActuator/BezierCurve'].data) # triangulate prior makes the difference bmesh.ops.triangulate(bm, faces=bm.faces) print(bm.calc_volume()) # Will return 0.124, correct value should be ~0.52. # You can confirm this using the 3D print add-on which gives the correct result ias ~0.521m3 ``` Without prior triangulation: - normals are already consistent here (would asume this would have caused errors as well) - calc_volume code then uses `BM_face_calc_tessellation` (this seems to be different from `BM_face_triangulate` which the bmesh.ops.triangulate uses) For your mesh it already improves splitting non planar faces: - `Mesh` > `Clean Up` > `Split Non-Planar Faces` (up to a reported volume of ~0.332) Then if you move all of the geometry in the quadrant of only positive vertex coordinates it improves further - up to a reported volume of ~0.445 This might all be a limitation of the algorithm used, but I would like to ask @ideasman42 if this is to be expected? Could this be more robust? Tempted to call this a bug, but there might be reasons to do it the way it is now...
Author

If it helps, this is the algorithm I use in Python (which I think I stole from the 3D print add-on), which also gets the correct result of 0.521:

https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/ifcblenderexport/blenderbim/bim/qto.py#L100

If it helps, this is the algorithm I use in Python (which I think I stole from the 3D print add-on), which also gets the correct result of 0.521: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/ifcblenderexport/blenderbim/bim/qto.py#L100

This issue was referenced by 0ab66dd63f

This issue was referenced by 0ab66dd63f543bf6c3374155699a86e90da61037

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Campbell Barton self-assigned this 2020-07-30 06:20:50 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#79369
No description provided.