[Bf-extensions-cvs] [5e15b56] master: grace period in contrib. T42940
Brendon Murphy
noreply at git.blender.org
Sun May 24 12:51:26 CEST 2015
Commit: 5e15b567f2e8e3dd130bb10a0b00c9b25eed4b6c
Author: Brendon Murphy
Date: Sun May 24 20:50:03 2015 +1000
Branches: master
https://developer.blender.org/rBAC5e15b567f2e8e3dd130bb10a0b00c9b25eed4b6c
grace period in contrib. T42940
===================================================================
A space_view3d_panel_measure.py
===================================================================
diff --git a/space_view3d_panel_measure.py b/space_view3d_panel_measure.py
new file mode 100644
index 0000000..64a5689
--- /dev/null
+++ b/space_view3d_panel_measure.py
@@ -0,0 +1,1587 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+#
+# Uses volume calculation and manifold check code (GPL2+) from:
+# http://www.shapeways.com/forum/index.php?t=msg&goto=3639
+# Shapeways Volume Calculator by Benjamin Lauritzen (Loonsbury)
+#
+# #################################
+
+bl_info = {
+ "name": "Measure Panel",
+ "author": "Buerbaum Martin (Pontiac), TNae (Normal patch), "
+ "Benjamin Lauritzen (Loonsbury; Volume code), "
+ "Alessandro Sala (patch: Units in 3D View), "
+ "Daniel Ashby (callback removal code) ",
+ "version": (0, 9, 1),
+ "blender": (2, 60, 0),
+ "location": "View3D > Properties > Measure Panel",
+ "description": "Measure distances between objects",
+ "warning": "Script needs repairs",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "Scripts/3D_interaction/Panel_Measure",
+ "category": "3D View",
+}
+
+"""
+Measure panel
+
+This script displays in OBJECT MODE:
+* The distance of the 3D cursor to the origin of the
+ 3D space (if NOTHING is selected).
+* The distance of the 3D cursor to the center of an object
+ (if exactly ONE object is selected).
+* The distance between 2 object centers
+ (if exactly TWO objects are selected).
+* The surface area of any selected mesh object.
+* The average normal of the mesh surface of any selected mesh object.
+* The volume of any selected mesh object.
+
+Display in EDIT MODE (Local and Global space supported):
+* The distance of the 3D cursor to the origin
+ (in Local space it is the object center instead).
+* The distance of the 3D cursor to a selected vertex.
+* The distance between 2 selected vertices.
+
+Usage:
+
+This functionality can be accessed via the
+"Properties" panel in 3D View ([N] key).
+
+It's very helpful to use one or two "Empty" objects with
+"Snap during transform" enabled for fast measurement.
+
+More links:
+http://gitorious.org/blender-scripts/blender-measure-panel-script
+http://blenderartists.org/forum/showthread.php?t=177800
+"""
+
+import bpy
+from bpy.props import *
+from bpy.app.handlers import persistent
+from mathutils import Vector, Matrix
+import bgl
+import blf
+from bpy_extras.view3d_utils import location_3d_to_region_2d
+from bpy_extras.mesh_utils import ngon_tessellate
+
+
+# Precicion for display of float values.
+PRECISION = 5
+
+# Name of the custom properties as stored in the scene.
+COLOR_LOCAL = (1.0, 0.5, 0.0, 0.8)
+COLOR_GLOBAL = (0.5, 0.0, 1.0, 0.8)
+
+# 3D View - text offset
+OFFSET_LINE = 10 # Offset the text a bit to the right.
+OFFSET_Y = 15 # Offset of the lines.
+OFFSET_VALUE = 30 # Offset of value(s) from the text.
+
+# 3D View - line width
+LINE_WIDTH_XYZ = 1
+LINE_WIDTH_DIST = 2
+
+
+# Returns a tuple describing the current measuring system
+# and formatting options.
+# Returned data is meant to be passed to formatDistance().
+# Original by Alessandro Sala (Feb, 12th 2012)
+# Update by Alessandro Sala (Dec, 18th 2012)
+def getUnitsInfo():
+ scale = bpy.context.scene.unit_settings.scale_length
+ unit_system = bpy.context.scene.unit_settings.system
+ separate_units = bpy.context.scene.unit_settings.use_separate
+ if unit_system == 'METRIC':
+ scale_steps = ((1000, 'km'), (1, 'm'), (1 / 100, 'cm'),
+ (1 / 1000, 'mm'), (1 / 1000000, '\u00b5m'))
+ elif unit_system == 'IMPERIAL':
+ scale_steps = ((5280, 'mi'), (1, '\''),
+ (1 / 12, '"'), (1 / 12000, 'thou'))
+ scale /= 0.3048 # BU to feet
+ else:
+ scale_steps = ((1, ' BU'),)
+ separate_units = False
+
+ return (scale, scale_steps, separate_units)
+
+
+# Converts a distance from BU into the measuring system
+# described by units_info.
+# Original by Alessandro Sala (Feb, 12th 2012)
+# Update by Alessandro Sala (Dec, 18th 2012)
+def convertDistance(val, units_info):
+ scale, scale_steps, separate_units = units_info
+ sval = val * scale
+ idx = 0
+ while idx < len(scale_steps) - 1:
+ if sval >= scale_steps[idx][0]:
+ break
+ idx += 1
+ factor, suffix = scale_steps[idx]
+ sval /= factor
+ if not separate_units or idx == len(scale_steps) - 1:
+ dval = str(round(sval, PRECISION)) + suffix
+ else:
+ ival = int(sval)
+ dval = str(round(ival, PRECISION)) + suffix
+ fval = sval - ival
+ idx += 1
+ while idx < len(scale_steps):
+ fval *= scale_steps[idx - 1][0] / scale_steps[idx][0]
+ if fval >= 1:
+ dval += ' ' \
+ + ("%.1f" % fval) \
+ + scale_steps[idx][1]
+ break
+ idx += 1
+
+ return dval
+
+
+# Returns a single selected object.
+# Returns None if more than one (or nothing) is selected.
+# Note: Ignores the active object.
+def getSingleObject():
+ if len(bpy.context.selected_objects) == 1:
+ return bpy.context.selected_objects[0]
+
+ return None
+
+
+# Returns a list with 2 3D points (Vector) and a color (RGBA)
+# depending on the current view mode and the selection.
+def getMeasurePoints(context):
+ sce = context.scene
+ mode = context.mode
+
+ # Get a single selected object (or nothing).
+ obj = getSingleObject()
+
+ if mode == 'EDIT_MESH':
+ obj = context.active_object
+
+ if obj and obj.type == 'MESH' and obj.data:
+ # Get mesh data from Object.
+ mesh = obj.data
+
+ # 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) == 0:
+ # Nothing selected.
+ # We measure the distance from...
+ # local ... the object center to the 3D cursor.
+ # global ... the origin to the 3D cursor.
+ cur_loc = sce.cursor_location
+ obj_loc = obj.matrix_world.to_translation()
+
+ # Convert to local space, if needed.
+ if measureLocal(sce):
+ p1 = cur_loc
+ p2 = obj_loc
+ return (p1, p2, COLOR_GLOBAL)
+
+ else:
+ p1 = Vector((0.0, 0.0, 0.0))
+ p2 = cur_loc
+ return (p1, p2, COLOR_GLOBAL)
+
+ elif len(verts_selected) == 1:
+ # One vertex selected.
+ # We measure the distance from the
+ # selected vertex object to the 3D cursor.
+ cur_loc = sce.cursor_location
+ vert_loc = verts_selected[0].co.copy()
+
+ # Convert to local or global space.
+ if measureLocal(sce):
+ p1 = vert_loc
+ p2 = cur_loc
+ return (p1, p2, COLOR_LOCAL)
+
+ else:
+ p1 = obj.matrix_world * vert_loc
+ p2 = cur_loc
+ return (p1, p2, COLOR_GLOBAL)
+
+ elif len(verts_selected) == 2:
+ # Two vertices selected.
+ # We measure the distance between the
+ # two selected vertices.
+ obj_loc = obj.matrix_world.to_translation()
+ vert1_loc = verts_selected[0].co.copy()
+ vert2_loc = verts_selected[1].co.copy()
+
+ # Convert to local or global space.
+ if measureLocal(sce):
+ p1 = vert1_loc
+ p2 = vert2_loc
+ return (p1, p2, COLOR_LOCAL)
+
+ else:
+ p1 = obj.matrix_world * vert1_loc
+ p2 = obj.matrix_world * vert2_loc
+ return (p1, p2, COLOR_GLOBAL)
+
+ else:
+ return None
+
+ elif mode == 'OBJECT':
+ # We are working in object mode.
+
+ if len(context.selected_objects) > 2:
+ return None
+ elif len(context.selected_objects) == 2:
+ # 2 objects selected.
+ # We measure the distance between the 2 selected objects.
+ obj1, obj2 = context.selected_objects
+ obj1_loc = obj1.matrix_world.to_translation()
+ obj2_loc = obj2.matrix_world.to_translation()
+ 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.matrix_world.to_translation()
+ return (obj_loc, cur_loc, COLOR_GLOBAL)
+
+ elif not context.selected_objects:
+ # Nothing selected.
+ # We measure the distance from the origin to the 3D cursor.
+ p1 = Vector((0.0, 0.0, 0.0))
+ p2 = sce.cursor_location
+ return (p1, p2, COLOR_GLOBAL)
+
+ else:
+ re
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list