[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3856] contrib/py/scripts/addons: added mesh_select_tools
Brendon Murphy
meta.androcto1 at gmail.com
Mon Oct 15 01:36:48 CEST 2012
Revision: 3856
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3856
Author: meta-androcto
Date: 2012-10-14 23:36:47 +0000 (Sun, 14 Oct 2012)
Log Message:
-----------
added mesh_select_tools
contributed to by Macouno, dustractor, liero, CoDEmanX, meta-androcto
Added Paths:
-----------
contrib/py/scripts/addons/mesh_select_tools/
contrib/py/scripts/addons/mesh_select_tools/__init__.py
contrib/py/scripts/addons/mesh_select_tools/mesh_extras.py
contrib/py/scripts/addons/mesh_select_tools/mesh_index_select.py
contrib/py/scripts/addons/mesh_select_tools/mesh_info_select.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_by_direction.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_by_edge_length.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_by_pi.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_by_type.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_checkered.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_connected_faces.py
contrib/py/scripts/addons/mesh_select_tools/mesh_select_innermost.py
contrib/py/scripts/addons/mesh_select_tools/mesh_selection_topokit.py
Added: contrib/py/scripts/addons/mesh_select_tools/__init__.py
===================================================================
--- contrib/py/scripts/addons/mesh_select_tools/__init__.py (rev 0)
+++ contrib/py/scripts/addons/mesh_select_tools/__init__.py 2012-10-14 23:36:47 UTC (rev 3856)
@@ -0,0 +1,173 @@
+# ##### 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 #####
+# menu & updates by meta-androcto #
+# contributed to by Macouno, dustractor, liero, CoDEmanX, meta-androcto #
+
+bl_info = {
+ "name": "Select Tools",
+ "author": "Multiple Authors",
+ "version": (0, 3),
+ "blender": (2, 6, 4),
+ "location": "Editmode select menu",
+ "description": "Adds More vert/face/edge select modes.",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+ "Scripts/",
+ "tracker_url": "http://projects.blender.org/tracker/index.php?"\
+ "func=detail&aid=32877",
+ "category": "Mesh"}
+
+
+if "bpy" in locals():
+ import imp
+ imp.reload(mesh_select_by_direction)
+ imp.reload(mesh_select_by_edge_length)
+ imp.reload(mesh_select_by_pi)
+ imp.reload(mesh_select_by_type)
+ imp.reload(mesh_select_connected_faces)
+ imp.reload(mesh_select_innermost)
+ imp.reload(mesh_index_select)
+ imp.reload(mesh_selection_topokit)
+ imp.reload(mesh_info_select)
+else:
+ from . import mesh_select_by_direction
+ from . import mesh_select_by_edge_length
+ from . import mesh_select_by_pi
+ from . import mesh_select_by_type
+ from . import mesh_select_connected_faces
+ from . import mesh_select_innermost
+ from . import mesh_index_select
+ from . import mesh_selection_topokit
+ from . import mesh_info_select
+
+import bpy, bmesh
+
+class VIEW3D_MT_selectface_edit_mesh_add(bpy.types.Menu):
+ # Define the "Mesh_Select_Tools" menu
+ bl_idname = "mesh.face_select_tools"
+ bl_label = "Select by Face"
+
+ def draw(self, context):
+ layout = self.layout
+ layout.operator_context = 'INVOKE_REGION_WIN'
+ layout.label(text = 'Face Select')
+ layout.separator()
+ layout.operator("data.facetype_select",
+ text="Triangles").face_type = "3"
+ layout.operator("data.facetype_select",
+ text="Quads").face_type = "4"
+ layout.operator("data.facetype_select",
+ text="Ngons").face_type = "5"
+ layout.separator()
+ layout.operator("mesh.select_vert_index",
+ text="By Face Index")
+ layout.operator("mesh.select_by_direction",
+ text="By Direction")
+ layout.operator("mesh.select_by_pi",
+ text="By Pi")
+ layout.operator("mesh.select_connected_faces",
+ text="By Connected Faces")
+ layout.operator("mesh.e2e_efe",
+ text="Neighbors by Face")
+ layout.operator("mesh.f2f_fvnef",
+ text="Neighbors by Vert not Edge")
+ layout.operator("mesh.conway",
+ text="Conway")
+
+class VIEW3D_MT_selectedge_edit_mesh_add(bpy.types.Menu):
+ # Define the "Mesh_Select_Tools" menu
+ bl_idname = "mesh.edge_select_tools"
+ bl_label = "Select by Edge"
+
+ def draw(self, context):
+ layout = self.layout
+ layout.operator_context = 'INVOKE_REGION_WIN'
+ layout.label(text = 'Edge Select')
+ layout.separator()
+ layout.operator("mesh.select_vert_index",
+ text="By Edge Index")
+ layout.operator("mesh.select_by_direction",
+ text="By Direction")
+ layout.operator("mesh.select_by_pi",
+ text="By Pi")
+ layout.operator("mesh.select_by_edge_length",
+ text="By Edge Length")
+ layout.separator()
+ layout.operator("mesh.e2e_eve",
+ text="Neighbors by Vert")
+ layout.operator("mesh.e2e_evfe",
+ text="Neighbors by Vert + Face")
+ layout.operator("mesh.e2e_efnve",
+ text="Lateral Neighbors")
+ layout.operator("mesh.e2e_evnfe",
+ text="Longitudinal Edges")
+# layout.operator("mesh.je",
+# text="only_edge_selection")
+
+class VIEW3D_MT_selectvert_edit_mesh_add(bpy.types.Menu):
+ # Define the "Mesh_Select_Tools" menu
+ bl_idname = "mesh.vert_select_tools"
+ bl_label = "Select by Vert"
+
+ def draw(self, context):
+ layout = self.layout
+ layout.operator_context = 'INVOKE_REGION_WIN'
+ layout.label(text = 'Vert Select')
+ layout.separator()
+ layout.operator("mesh.select_vert_index",
+ text="By Vert Index")
+ layout.operator("mesh.select_by_direction",
+ text="By Direction")
+ layout.operator("mesh.select_by_pi",
+ text="By Pi")
+# layout.operator("mesh.select_innermost",
+# text="innermost")
+ layout.separator()
+ layout.operator("mesh.v2v_by_edge",
+ text="Neighbors by Edge")
+ layout.operator("mesh.e2e_eve",
+ text="Neighbors by Vert")
+ layout.operator("mesh.e2e_efe",
+ text="Neighbors by Face")
+ layout.operator("mesh.v2v_facewise",
+ text="Neighbors by Face - Edge")
+# layout.operator("mesh.ie",
+# text="inner_edge_selection")
+
+# Register all operators and panels
+
+# Define "Extras" menu
+def menu_func(self, context):
+ if context.tool_settings.mesh_select_mode[2]:
+ self.layout.menu("mesh.face_select_tools", icon="PLUGIN")
+ if context.tool_settings.mesh_select_mode[1]:
+ self.layout.menu("mesh.edge_select_tools", icon="PLUGIN")
+ if context.tool_settings.mesh_select_mode[0]:
+ self.layout.menu("mesh.vert_select_tools", icon="PLUGIN")
+
+
+def register():
+ bpy.utils.register_module(__name__)
+ bpy.types.VIEW3D_MT_select_edit_mesh.append(menu_func)
+
+def unregister():
+ bpy.utils.unregister_module(__name__)
+ bpy.types.VIEW3D_MT_select_edit_mesh.remove(menu_func)
+
+if __name__ == "__main__":
+ register()
Added: contrib/py/scripts/addons/mesh_select_tools/mesh_extras.py
===================================================================
--- contrib/py/scripts/addons/mesh_select_tools/mesh_extras.py (rev 0)
+++ contrib/py/scripts/addons/mesh_select_tools/mesh_extras.py 2012-10-14 23:36:47 UTC (rev 3856)
@@ -0,0 +1,274 @@
+import bpy, mathutils, math
+from mathutils import geometry
+
+# Get a matrix for the selected faces that you can use to do local transforms
+def get_selection_matrix(faces=False):
+
+ me = bpy.context.active_object.data
+
+ if not faces:
+ faces = get_selected_faces()
+
+ yVec = mathutils.Vector()
+ zVec = mathutils.Vector()
+
+ # Ok so we have a basic matrix, but lets base it more on the mesh!
+ for f in faces:
+
+ v1 = me.vertices[f.vertices[0]].co
+ v2 = me.vertices[f.vertices[1]].co
+ edge = v2-v1
+
+ yVec += edge
+
+ if len(f.vertices) == 4:
+ v1 = me.vertices[f.vertices[2]].co
+ v2 = me.vertices[f.vertices[3]].co
+ edge = v1-v2
+
+ yVec += edge
+
+ zVec += mathutils.Vector(f.normal)
+
+ if not yVec.length:
+ quat = zVec.to_track_quat('-Z', 'Y')
+ tMat = quat.to_matrix()
+ yVec = tMat[1]
+ yVec = yVec.normalized()
+ else:
+ yVec = yVec.normalized()
+ zVec = zVec.normalized()
+
+ # Rotate yVec so it's 90 degrees to zVec
+ cross =yVec.cross(zVec)
+ vec = float(yVec.angle(zVec) - math.radians(90))
+ mat = mathutils.Matrix.Rotation(vec, 3, cross)
+ yVec = (mat * yVec)
+
+ xVec = yVec.cross(zVec)
+
+ xVec = xVec.normalized()
+
+ nMat = mathutils.Matrix((xVec, yVec, zVec))
+
+ return nMat
+
+
+
+# Get the selection radius (minimum distance of an outer edge to the centre)
+def get_selection_radius():
+
+ ob = bpy.context.active_object
+
+ radius = 0.0
+
+ # no use continueing if nothing is selected
+ if contains_selected_item(ob.data.polygons):
+
+ # Find the center of the selection
+ cent = mathutils.Vector()
+ nr = 0
+ nonVerts = []
+ selVerts = []
+ for f in ob.data.polygons:
+ if f.select:
+ nr += 1
+ cent += f.center
+ else:
+ nonVerts.extend(f.vertices)
+
+ cent /= nr
+
+ chk = 0
+
+ # Now that we know the center.. we can figure out how close the nearest point on an outer edge is
+ for e in get_selected_edges():
+
+ nonSection = [v for v in e.vertices if v in nonVerts]
+ if len(nonSection):
+
+ v0 = ob.data.vertices[e.vertices[0]].co
+ v1 = ob.data.vertices[e.vertices[1]].co
+
+ # If there's more than 1 vert of this edge on the outside... we need the edge length to be long enough too!
+ if len(nonSection) > 1:
+ edge = v0 - v1
+ edgeRad = edge.length * 0.5
+
+ if edgeRad < radius or not chk:
+ radius = edgeRad
+ chk += 1
+
+ int = geometry.intersect_point_line(cent, v0, v1)
+
+ rad = cent - int[0]
+ l = rad.length
+
+ if l < radius or not chk:
+ radius = l
+ chk += 1
+
+ return radius
+
+
+
+# Get the average length of the outer edges of the current selection
+def get_shortest_outer_edge_length():
+
+ ob = bpy.context.active_object
+
+ min = False
+ me = ob.data
+
+ delVerts = []
+ for f in me.faces:
+ if not f.select:
+ delVerts.extend(f.vertices)
+ selEdges = [e.vertices for e in me.edges if e.select]
+
+ if len(selEdges) and len(delVerts):
+
+ for eVerts in selEdges:
+
+ v0 = eVerts[0]
+ v1 = eVerts[1]
+
+ if v0 in delVerts and v1 in delVerts:
+ ln = (me.vertices[v0].co - me.vertices[v1].co).length
+ if min is False or (ln > 0.0 and ln < min):
+ min = ln
+
+ return min
+
+
+# Get the average length of the outer edges of the current selection
+def get_average_outer_edge_length():
+
+ ob = bpy.context.active_object
+
+ ave = 0.0
+ me = ob.data
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list