[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [655] moved fixed scripts back to contrib.
Brendon Murphy
meta.androcto1 at gmail.com
Sat May 1 14:18:06 CEST 2010
Revision: 655
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=655
Author: meta-androcto
Date: 2010-05-01 14:18:06 +0200 (Sat, 01 May 2010)
Log Message:
-----------
moved fixed scripts back to contrib. thanks to testscreenings
Added Paths:
-----------
contrib/py/scripts/addons/space_view3d_cursor_to_edge_intersection.py
contrib/py/scripts/addons/space_view3d_index_visualiser.py
Removed Paths:
-------------
repair_holding/space_view3d_cursor_to_edge_intersection.py
repair_holding/space_view3d_index_visualiser.py
Added: contrib/py/scripts/addons/space_view3d_cursor_to_edge_intersection.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_cursor_to_edge_intersection.py (rev 0)
+++ contrib/py/scripts/addons/space_view3d_cursor_to_edge_intersection.py 2010-05-01 12:18:06 UTC (rev 655)
@@ -0,0 +1,146 @@
+# cursor_to_edge_intersection.py Copyright (C) 2009-2010, Keith (Wahooney) Boshoff
+# parts based on Paul Bourke's Shortest Line Between 2 lines
+# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+
+bl_addon_info = {
+ 'name': '3D View: Cursor to Edge Intersection',
+ 'author': 'Keith (Wahooney) Boshoff',
+ 'version': '1.0',
+ 'blender': (2, 5, 3),
+ 'location': 'Snap',
+ 'description': 'adds Snap cursor to edge intersect to cursor tools',
+ 'url': '',
+ 'category': '3D View'}
+
+from mathutils import Vector, Matrix
+import math
+import bpy
+
+def abs(val):
+ if val > 0:
+ return val
+ return -val
+
+def LineLineIntersect (p1, p2, p3, p4):
+ # based on Paul Bourke's Shortest Line Between 2 lines
+
+ min = 0.0000001
+
+ v1 = Vector((p1.x - p3.x, p1.y - p3.y, p1.z - p3.z))
+ v2 = Vector((p4.x - p3.x, p4.y - p3.y, p4.z - p3.z))
+
+ if abs(v2.x) < min and abs(v2.y) < min and abs(v2.z) < min:
+ return None
+
+ v3 = Vector((p2.x - p1.x, p2.y - p1.y, p2.z - p1.z))
+
+ if abs(v3.x) < min and abs(v3.y) < min and abs(v3.z) < min:
+ return None
+
+ d1 = v1.dot(v2)
+ d2 = v2.dot(v3)
+ d3 = v1.dot(v3)
+ d4 = v2.dot(v2)
+ d5 = v3.dot(v3)
+
+ d = d5 * d4 - d2 * d2
+
+ if abs(d) < min:
+ return None
+
+ n = d1 * d2 - d3 * d4
+
+ mua = n / d
+ mub = (d1 + d2 * (mua)) / d4
+
+ return [Vector((p1.x + mua * v3.x, p1.y + mua * v3.y, p1.z + mua * v3.z)),
+ Vector((p3.x + mub * v2.x, p3.y + mub * v2.y, p3.z + mub * v2.z))]
+
+def edgeIntersect(context, operator):
+
+ obj = context.active_object
+
+ if (obj.type != "MESH"):
+ operator.report({'ERROR'}, "Object must be a mesh")
+ return None
+
+ edges = [];
+ mesh = obj.data
+ verts = mesh.verts
+
+ is_editmode = (obj.mode == 'EDIT')
+ if is_editmode:
+ bpy.ops.object.mode_set(mode='OBJECT')
+
+ for e in mesh.edges:
+ if e.selected:
+ edges.append(e)
+
+ if is_editmode:
+ bpy.ops.object.mode_set(mode='EDIT')
+
+ if len(edges) != 2:
+ operator.report({'ERROR'}, "Operator requires exactly 2 edges to be selected.")
+ return
+
+ line = LineLineIntersect(verts[edges[0].verts[0]].co, verts[edges[0].verts[1]].co, verts[edges[1].verts[0]].co, verts[edges[1].verts[1]].co)
+
+ if (line == None):
+ operator.report({'ERROR'}, "Selected edges are parallel.")
+ return
+
+ tm = obj.matrix.copy()
+ point = ((line[0] + line[1]) / 2)
+ point = tm * point
+
+ context.scene.cursor_location = point
+
+ return point
+
+class CursorToEdgeIntersection(bpy.types.Operator):
+ '''Finds the mid-point of the shortest distance between two edges, the point may not lie
+ between the edges as the edges are projected beyond their bounds'''
+
+ bl_idname = "view3d.snap_cursor_to_edge_intersection"
+ bl_label = "Cursor to Edge Intersection"
+
+ def poll(self, context):
+ obj = context.active_object
+ return obj != None and obj.type == 'MESH'
+
+ def execute(self, context):
+ edgeIntersect(context, self)
+ return {'FINISHED'}
+
+
+menu_func = (lambda self,
+ context: self.layout.operator(CursorToEdgeIntersection.bl_idname,
+ text="Cursor to Edge intersection"))
+
+def register():
+ bpy.types.register(CursorToEdgeIntersection)
+ bpy.types.VIEW3D_MT_snap.append(menu_func)
+
+def unregister():
+ bpy.types.unregister(CursorToEdgeIntersection)
+ bpy.types.VIEW3D_MT_snap.append(menu_func)
+
+if __name__ == "__main__":
+ register()
\ No newline at end of file
Added: contrib/py/scripts/addons/space_view3d_index_visualiser.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_index_visualiser.py (rev 0)
+++ contrib/py/scripts/addons/space_view3d_index_visualiser.py 2010-05-01 12:18:06 UTC (rev 655)
@@ -0,0 +1,180 @@
+# ##### 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 #####
+
+bl_addon_info = {
+ 'name': '3D View: Index Visualiser',
+ 'author': 'Bartius Crouch',
+ 'version': '2.2 2010/03/16',
+ 'blender': '2.5.2',
+ 'category': '3D View',
+ 'location': 'View3D > properties panel > display tab',
+ 'description': 'Display the indices of vertices, edges and faces in the 3d-view',
+ 'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Index_Visualiser',
+ "doc": """\
+Display the indices of vertices, edges and faces in the 3d-view.
+
+How to use:
+- Select a mesh and go into editmode
+- Display the properties panel (N-key)
+- Go to the Display tab (4th tab), it helps to fold the tabs above it
+- Press the 'Visualise indices button'
+
+"""}
+
+
+import bgl, blf, bpy, mathutils
+
+# calculate locations and store them as ID property in the mesh
+def calc_callback(self, context):
+ # polling
+ if context.mode != 'EDIT_MESH':
+ return
+
+ # get screen information
+ mid_x = context.region.width/2.0
+ mid_y = context.region.height/2.0
+ width = context.region.width
+ height = context.region.height
+
+ # get matrices
+ view_mat = context.space_data.region_3d.perspective_matrix
+ ob_mat = context.active_object.matrix
+ total_mat = view_mat*ob_mat
+
+ # calculate location info
+ texts = []
+ locs = []
+ me = context.active_object.data
+ # uncomment 2 lines below, to enable live updating of the selection
+ #bpy.ops.object.editmode_toggle()
+ #bpy.ops.object.editmode_toggle()
+ if bpy.context.scene.display_vert_index:
+ for v in me.verts:
+ if v.selected or not bpy.context.scene.display_sel_only:
+ locs.append([1.0, 1.0, 1.0, v.index, mathutils.Vector((v.co[:][0], v.co[:][1], v.co[:][2], 1.0))])
+ if bpy.context.scene.display_edge_index:
+ for ed in me.edges:
+ if ed.selected or not bpy.context.scene.display_sel_only:
+ v1, v2 = ed.verts
+ v1 = mathutils.Vector(me.verts[v1].co[:])
+ v2 = mathutils.Vector(me.verts[v2].co[:])
+ loc = v1 + ((v2-v1)/2.0)
+ locs.append([1.0, 1.0, 0.0, ed.index, mathutils.Vector((loc[0],loc[1],loc[2],1.0))])
+ if bpy.context.scene.display_face_index:
+ for f in me.faces:
+ if f.selected or not bpy.context.scene.display_sel_only:
+ locs.append([1.0, 0.0, 0.5, f.index, mathutils.Vector((f.center[0], f.center[1], f.center[2], 1.0))])
+
+ for loc in locs:
+ vec = total_mat*loc[4] # order is important
+ vec = mathutils.Vector((vec[0]/vec[3],vec[1]/vec[3],vec[2]/vec[3])) # dehomogenise
+ x = int(mid_x + vec[0]*width/2.0)
+ y = int(mid_y + vec[1]*height/2.0)
+ texts+=[loc[0], loc[1], loc[2], loc[3], x, y, 0]
+
+ # store as ID property in mesh
+ context.active_object.data['IndexVisualiser'] = texts
+
+# draw in 3d-view
+def draw_callback(self, context):
+ # polling
+ if context.mode != 'EDIT_MESH':
+ return
+ # retrieving ID property data
+ try:
+ texts = context.active_object.data['IndexVisualiser']
+ except:
+ return
+ if not texts:
+ return
+
+ # draw
+ blf.size(0, 13, 72)
+ for i in range(0,len(texts),7):
+ bgl.glColor3f(texts[i], texts[i+1], texts[i+2])
+ blf.position(0, texts[i+4], texts[i+5], texts[i+6])
+ blf.draw(0, str(int(texts[i+3])))
+
+# operator
+class IndexVisualiser(bpy.types.Operator):
+ bl_idname = "view3d.index_visualiser"
+ bl_label = "Index Visualiser"
+ bl_description = "Toggle the visualisation of indices"
+
+ def poll(self, context):
+ return context.mode=='EDIT_MESH'
+
+ def modal(self, context, event):
+ context.area.tag_redraw()
+
+ # removal of callbacks when operator is called again
+ if context.scene.display_indices == -1:
+ context.region.callback_remove(self.handle1)
+ context.region.callback_remove(self.handle2)
+ context.scene.display_indices = 0
+ return {'CANCELLED'}
+
+ return {'PASS_THROUGH'}
+
+ def invoke(self, context, event):
+ if context.area.type == 'VIEW_3D':
+ if context.scene.display_indices == 0:
+ # operator is called for the first time, start everything
+ context.scene.display_indices = 1
+ context.manager.add_modal_handler(self)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list