[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4509] trunk/py/scripts/addons/ object_print3d_utils: use bmesh volume function, show cubit inches for volume/area statistics.
Campbell Barton
ideasman42 at gmail.com
Tue May 7 02:12:14 CEST 2013
Revision: 4509
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4509
Author: campbellbarton
Date: 2013-05-07 00:12:13 +0000 (Tue, 07 May 2013)
Log Message:
-----------
use bmesh volume function, show cubit inches for volume/area statistics.
Modified Paths:
--------------
trunk/py/scripts/addons/object_print3d_utils/mesh_helpers.py
trunk/py/scripts/addons/object_print3d_utils/operators.py
Modified: trunk/py/scripts/addons/object_print3d_utils/mesh_helpers.py
===================================================================
--- trunk/py/scripts/addons/object_print3d_utils/mesh_helpers.py 2013-05-06 14:57:56 UTC (rev 4508)
+++ trunk/py/scripts/addons/object_print3d_utils/mesh_helpers.py 2013-05-07 00:12:13 UTC (rev 4509)
@@ -88,26 +88,6 @@
me.vertices[0].co[0] = me.vertices[0].co[0]
-def bmesh_calc_volume(bm):
- """
- Calculate the volume of a triangulated bmesh.
- """
- def tri_signed_volume(p1, p2, p3):
- return p1.dot(p2.cross(p3)) / 6.0
- return abs(sum((tri_signed_volume(*(v.co for v in f.verts))
- for f in bm.faces)))
-
-
-def bmesh_calc_volume_signed(bm):
- """
- Calculate the volume of a triangulated bmesh.
- """
- def tri_signed_volume(p1, p2, p3):
- return p1.dot(p2.cross(p3)) / 6.0
- return sum((tri_signed_volume(*(v.co for v in f.verts))
- for f in bm.faces))
-
-
def bmesh_calc_area(bm):
"""
Calculate the surface area.
Modified: trunk/py/scripts/addons/object_print3d_utils/operators.py
===================================================================
--- trunk/py/scripts/addons/object_print3d_utils/operators.py 2013-05-06 14:57:56 UTC (rev 4508)
+++ trunk/py/scripts/addons/object_print3d_utils/operators.py 2013-05-07 00:12:13 UTC (rev 4509)
@@ -62,14 +62,18 @@
obj = context.active_object
bm = mesh_helpers.bmesh_copy_from_object(obj, apply_modifiers=True)
- volume = mesh_helpers.bmesh_calc_volume(bm)
+ volume = bm.calc_volume()
bm.free()
info = []
- info.append(("Volume: %s³" % clean_float("%.4f" % volume),
+ info.append(("Volume: %s³" % clean_float("%.8f" % volume),
None))
- info.append(("%s cm³" % clean_float("%.4f" % ((volume * (scale * scale * scale)) / (0.01 * 0.01 * 0.01))),
- None))
+ if unit.system == 'IMPERIAL':
+ info.append(("%s \"³" % clean_float("%.4f" % ((volume * (scale * scale * scale)) / (0.0254 * 0.0254 * 0.0254))),
+ None))
+ else:
+ info.append(("%s cm³" % clean_float("%.4f" % ((volume * (scale * scale * scale)) / (0.01 * 0.01 * 0.01))),
+ None))
report.update(*info)
return {'FINISHED'}
@@ -91,10 +95,14 @@
bm.free()
info = []
- info.append(("Area: %s²" % clean_float("%.4f" % area),
+ info.append(("Area: %s²" % clean_float("%.8f" % area),
None))
- info.append(("%s cm²" % clean_float("%.4f" % ((area * (scale * scale)) / (0.01 * 0.01))),
- None))
+ if unit.system == 'IMPERIAL':
+ info.append(("%s \"²" % clean_float("%.4f" % ((area * (scale * scale)) / (0.0254 * 0.0254))),
+ None))
+ else:
+ info.append(("%s cm²" % clean_float("%.4f" % ((area * (scale * scale)) / (0.01 * 0.01))),
+ None))
report.update(*info)
return {'FINISHED'}
@@ -525,7 +533,7 @@
def calc_volume(obj):
bm = mesh_helpers.bmesh_copy_from_object(obj, apply_modifiers=True)
- volume = mesh_helpers.bmesh_calc_volume_signed(bm)
+ volume = bm.calc_volume(signed=True)
bm.free()
return volume
More information about the Bf-extensions-cvs
mailing list