[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1314] trunk/py/scripts/addons/ space_view3d_panel_measure.py: * Measure Panel - Version 0.7.12
Martin Buerbaum
martin.buerbaum at gmx.at
Wed Dec 29 10:14:39 CET 2010
Revision: 1314
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1314
Author: pontiac
Date: 2010-12-29 10:14:38 +0100 (Wed, 29 Dec 2010)
Log Message:
-----------
* Measure Panel - Version 0.7.12
* Moved setting of properties to callback function (it is bad practise to set it in the draw code).
* Fixed distance calculation of parented objects.
* API change: add_modal_handler -> modal_handler_add
* Regression: I had to disable area display for selection with more than 2 meshes (for now, still searching for a nice solution).
* Fixed Local/Global vert-loc calculations in EditMode.
Modified Paths:
--------------
trunk/py/scripts/addons/space_view3d_panel_measure.py
Modified: trunk/py/scripts/addons/space_view3d_panel_measure.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_panel_measure.py 2010-12-27 16:15:05 UTC (rev 1313)
+++ trunk/py/scripts/addons/space_view3d_panel_measure.py 2010-12-29 09:14:38 UTC (rev 1314)
@@ -19,9 +19,9 @@
bl_addon_info = {
"name": "Measure Panel",
"author": "Buerbaum Martin (Pontiac)",
- "version": (0, 7, 11),
- "blender": (2, 5, 3),
- "api": 33331,
+ "version": (0, 7, 12),
+ "blender": (2, 5, 5),
+ "api": 33931,
"location": "View3D > Properties > Measure",
"description": "Measure distances between objects",
"warning": "",
@@ -58,6 +58,13 @@
"Snap during transform" enabled for fast measurement.
Version history:
+v0.7.12 - Moved setting of properties to callback function
+ (it is bad practise to set it in the draw code).
+ Fixed distance calculation of parented objects.
+ API change: add_modal_handler -> modal_handler_add
+ Regression: Had to disable area display for selection with
+ more than 2 meshes.
+ Fixed Local/Global vert-loc calculations in EditMode.
v0.7.11 - Applied patch by Filiciss Muhgue that fixes the text in quad view.
v0.7.10 - Applied patch by Filiciss Muhgue that (mostly) fixes the quad view.
Patch link: https://projects.blender.org/tracker/?func=
@@ -220,13 +227,6 @@
# Get mesh data from Object.
mesh = obj.data
- # Get transformation matrix from object.
- ob_mat = obj.matrix_world
- # Also make an inversed copy! of the matrix.
- ob_mat_inv = ob_mat.copy().invert()
- # And a transposed one...
- ob_mat_trans = ob_mat.copy().transpose()
-
# Get the selected vertices.
# @todo: Better (more efficient) way to do this?
verts_selected = [v for v in mesh.vertices if v.select == 1]
@@ -237,7 +237,7 @@
# local ... the object center to the 3D cursor.
# global ... the origin to the 3D cursor.
cur_loc = sce.cursor_location
- obj_loc = obj.location.copy()
+ obj_loc = obj.matrix_world.translation_part()
# Convert to local space, if needed.
if measureLocal(sce):
@@ -256,16 +256,15 @@
# selected vertex object to the 3D cursor.
cur_loc = sce.cursor_location
vert_loc = verts_selected[0].co.copy()
- obj_loc = obj.location.copy()
# Convert to local or global space.
if measureLocal(sce):
- p1 = obj_loc + vert_loc
+ p1 = vert_loc
p2 = cur_loc
return (p1, p2, COLOR_LOCAL)
else:
- p1 = vert_loc * ob_mat_trans
+ p1 = vert_loc * obj.matrix_world
p2 = cur_loc
return (p1, p2, COLOR_GLOBAL)
@@ -273,26 +272,26 @@
# Two vertices selected.
# We measure the distance between the
# two selected vertices.
- obj_loc = obj.location.copy()
+ obj_loc = obj.matrix_world.translation_part()
vert1_loc = verts_selected[0].co.copy()
vert2_loc = verts_selected[1].co.copy()
# Convert to local or global space.
if measureLocal(sce):
- p1 = obj_loc + vert1_loc
- p2 = obj_loc + vert2_loc
+ p1 = vert1_loc
+ p2 = vert2_loc
return (p1, p2, COLOR_LOCAL)
else:
- p1 = vert1_loc * ob_mat_trans
- p2 = vert2_loc * ob_mat_trans
+ p1 = vert1_loc * obj.matrix_world
+ p2 = vert2_loc * obj.matrix_world
return (p1, p2, COLOR_GLOBAL)
else:
return None
elif (context.mode == 'OBJECT'):
- # We are working on object mode.
+ # We are working in object mode.
if len(context.selected_objects) > 2:
return None
@@ -300,15 +299,15 @@
# 2 objects selected.
# We measure the distance between the 2 selected objects.
obj1, obj2 = context.selected_objects
- obj1_loc = obj1.location.copy()
- obj2_loc = obj2.location.copy()
+ obj1_loc = obj1.matrix_world.translation_part()
+ obj2_loc = obj2.matrix_world.translation_part()
return (obj1_loc, obj2_loc, COLOR_GLOBAL)
elif (obj):
# One object selected.
# We measure the distance from the object to the 3D cursor.
cur_loc = sce.cursor_location
- obj_loc = obj.location.copy()
+ obj_loc = obj.matrix_world.translation_part()
return (obj_loc, cur_loc, COLOR_GLOBAL)
elif not context.selected_objects:
@@ -576,6 +575,12 @@
OFFSET_VALUE = 30 # Offset of value(s) from the text.
dist = (p1 - p2).length
+ # Write distance value into the scene property,
+ # so we can display it in the panel & refresh the panel.
+ if hasattr(sce, "measure_panel_dist"):
+ sce.measure_panel_dist = dist
+ context.area.tag_redraw()
+
texts = [("Dist:", round(dist, PRECISION)),
("X:", round(abs(p1[0] - p2[0]), PRECISION)),
("Y:", round(abs(p1[1] - p2[1]), PRECISION)),
@@ -599,7 +604,91 @@
loc_y -= OFFSET_Y
+ # Handle mesh surface area calulations
+ if (sce.measure_panel_calc_area):
+ # Get a single selected object (or nothing).
+ obj = getSingleObject(context)
+ if (context.mode == 'EDIT_MESH'):
+ obj = context.active_object
+
+ if (obj and obj.type == 'MESH' and obj.data):
+ # "Note: a Mesh will return the selection state of the mesh
+ # when EditMode was last exited. A Python script operating
+ # in EditMode must exit EditMode before getting the current
+ # selection state of the mesh."
+ # http://www.blender.org/documentation/249PythonDoc/
+ # /Mesh.MVert-class.html#sel
+ # We can only provide this by existing & re-entering EditMode.
+ # @todo: Better way to do this?
+
+ # Get mesh data from Object.
+ mesh = obj.data
+
+ # Get transformation matrix from object.
+ ob_mat = obj.matrix_world
+ # Also make an inversed copy! of the matrix.
+ ob_mat_inv = ob_mat.copy()
+ Matrix.invert(ob_mat_inv)
+
+ # Get the selected vertices.
+ # @todo: Better (more efficient) way to do this?
+ verts_selected = [v for v in mesh.vertices if v.select == 1]
+
+ if len(verts_selected) >= 3:
+ # Get selected faces
+ # @todo: Better (more efficient) way to do this?
+ faces_selected = [f for f in mesh.faces
+ if f.select == 1]
+
+ if len(faces_selected) > 0:
+ area = objectSurfaceArea(obj, True,
+ measureGlobal(sce))
+ if (area >= 0):
+ sce.measure_panel_area1 = area
+
+ elif (context.mode == 'OBJECT'):
+ # We are working in object mode.
+
+ if len(context.selected_objects) > 2:
+ return
+# @todo Make this work again.
+# # We have more that 2 objects selected...
+#
+# mesh_objects = [o for o in context.selected_objects
+# if (o.type == 'MESH')]
+
+# if (len(mesh_objects) > 0):
+# # ... and at least one of them is a mesh.
+#
+# for o in mesh_objects:
+# area = objectSurfaceArea(o, False,
+# measureGlobal(sce))
+# if (area >= 0):
+# #row.label(text=o.name, icon='OBJECT_DATA')
+# #row.label(text=str(round(area, PRECISION))
+# # + " BU^2")
+
+ elif len(context.selected_objects) == 2:
+ # 2 objects selected.
+
+ obj1, obj2 = context.selected_objects
+
+ # Calculate surface area of the objects.
+ area1 = objectSurfaceArea(obj1, False, measureGlobal(sce))
+ area2 = objectSurfaceArea(obj2, False, measureGlobal(sce))
+ sce.measure_panel_area1 = area1
+ sce.measure_panel_area2 = area2
+
+ elif (obj):
+ # One object selected.
+
+ # Calculate surface area of the object.
+ area = objectSurfaceArea(obj, False, measureGlobal(sce))
+ if (area >= 0):
+ sce.measure_panel_area1 = area
+
+
class VIEW3D_OT_display_measurements(bpy.types.Operator):
'''Display the measurements made in the 'Measure' panel'''
# Do not use bl_idname here (class name is used instead),
@@ -767,13 +856,6 @@
# local ... the object center to the 3D cursor.
# global ... the origin to the 3D cursor.
- # Get the 2 measure points
- line = getMeasurePoints(context)
- if line != 0:
- dist_vec = line[0] - line[1]
-
- sce.measure_panel_dist = dist_vec.length
-
row = layout.row()
row.prop(sce, "measure_panel_dist")
@@ -805,13 +887,6 @@
# We measure the distance from the
# selected vertex object to the 3D cursor.
- # Get the 2 measure points
- line = getMeasurePoints(context)
- if line != 0:
- dist_vec = line[0] - line[1]
-
- sce.measure_panel_dist = dist_vec.length
-
row = layout.row()
row.prop(sce, "measure_panel_dist")
@@ -834,13 +909,6 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list