From 4a9eba45170c7fdb6c78906340769ba6355dc495 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 May 2013 00:12:13 +0000 Subject: use bmesh volume function, show cubit inches for volume/area statistics. --- object_print3d_utils/mesh_helpers.py | 20 -------------------- object_print3d_utils/operators.py | 24 ++++++++++++++++-------- 2 files changed, 16 insertions(+), 28 deletions(-) (limited to 'object_print3d_utils') diff --git a/object_print3d_utils/mesh_helpers.py b/object_print3d_utils/mesh_helpers.py index faf16d2e..4996ca69 100644 --- a/object_print3d_utils/mesh_helpers.py +++ b/object_print3d_utils/mesh_helpers.py @@ -88,26 +88,6 @@ def bmesh_to_object(obj, bm): 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. diff --git a/object_print3d_utils/operators.py b/object_print3d_utils/operators.py index 8db7f429..7548d165 100644 --- a/object_print3d_utils/operators.py +++ b/object_print3d_utils/operators.py @@ -62,14 +62,18 @@ class Print3DInfoVolume(Operator): 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), - None)) - info.append(("%s cm³" % clean_float("%.4f" % ((volume * (scale * scale * scale)) / (0.01 * 0.01 * 0.01))), + info.append(("Volume: %s³" % clean_float("%.8f" % volume), 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 @@ class Print3DInfoArea(Operator): bm.free() info = [] - info.append(("Area: %s²" % clean_float("%.4f" % area), - None)) - info.append(("%s cm²" % clean_float("%.4f" % ((area * (scale * scale)) / (0.01 * 0.01))), + info.append(("Area: %s²" % clean_float("%.8f" % area), 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 @@ class Print3DScaleToVolume(Operator): 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 -- cgit v1.2.3