[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2038] contrib/py/scripts/addons/ mesh_vertex_slide.py: Vertex slide add-on: Move to contrib
Valter Battioli
valter31 at interfree.it
Sun Jun 19 15:05:35 CEST 2011
Revision: 2038
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2038
Author: valtervb
Date: 2011-06-19 13:05:35 +0000 (Sun, 19 Jun 2011)
Log Message:
-----------
Vertex slide add-on: Move to contrib
Added Paths:
-----------
contrib/py/scripts/addons/mesh_vertex_slide.py
Added: contrib/py/scripts/addons/mesh_vertex_slide.py
===================================================================
--- contrib/py/scripts/addons/mesh_vertex_slide.py (rev 0)
+++ contrib/py/scripts/addons/mesh_vertex_slide.py 2011-06-19 13:05:35 UTC (rev 2038)
@@ -0,0 +1,414 @@
+# ##### 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_info = {
+ "name": "Vertex slide",
+ "author": "Valter Battioli (ValterVB) and PKHG",
+ "version": (1, 0, 8),
+ "blender": (2, 5, 7),
+ "api": 37603,
+ "location": "View3D > Mesh > Vertices (CTRL V-key) or search for 'VB Vertex 2'",
+ "description": "Slide a vertex along an edge",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Modeling/Vertex_Slide2",
+ "tracker_url": "http://projects.blender.org/tracker/index.php?func=detail&aid=27561",
+ "category": "Mesh"}
+
+#***********************************************************************
+#ver. 1.0.0: -First version
+#ver. 1.0.1: -Now the mouse wheel select in continuos mode the next vertex
+# -Add a marker for the vertex to move
+#ver. 1.0.2: -Add check for vertices not selected
+# -Some cleanup
+#ver. 1.0.3: -Now the movement is proportional to the mouse movement
+# 1/10 of the distance between 2 points for every pixel
+# mouse movement (1/100 with SHIFT)
+#ver. 1.0.4: all coordinate as far as possible replaced by vectors
+# view3d_utils are used to define length of an edge on screen!
+# partial simplified logic by PKHG
+#ver. 1.0.6: Restore continuous slide, code cleanup
+# Correct the crash with not linked vertex
+#ver. 1.0.7: Restore shift, and some code cleanup
+#ver. 1.0.8: Restore 2 type of sliding with 2 vertex selected
+#***********************************************************************
+
+import bpy
+import bgl
+import blf
+from mathutils import Vector
+from bpy_extras import view3d_utils # pkhg
+
+debugDenomiator = False # debugging info
+
+###global
+direction = 1.0
+mouseVec = None
+ActiveVertex = None
+drempel = 0
+
+class Point():
+ class Vertices():
+ def __init__(self):
+ self.co = Vector((0, 0, 0))
+ self.idx = -1
+
+ def __init__(self):
+ self.original = self.Vertices()
+ self.new = self.Vertices()
+ self.t = 0
+ self.selected = False
+
+
+#Equation of the line
+#Changing t, I have a new point coordinate on the line along v0 v1
+#With t from 0 to 1 I move from v0 to v1
+def NewCoordinate(v0, v1, t):
+ return v0 + t * (v1 - v0)
+
+
+def draw_callback_px(self, context):
+ #Copied from index visualiser
+ #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_world
+ total_mat = view_mat * ob_mat
+
+ Vertices = bpy.context.object.data.vertices
+ temp = Vertices[ActiveVertex].co
+
+ loc = Vertices[ActiveVertex].co.to_4d() # Where I want draw the text
+
+ vec = loc * total_mat # Order is important
+ if vec[3] != 0:
+ vec = vec / vec[3]
+ else:
+ vec = vec # PKHG TODO: what to do now? VB I think that is correct
+ x = int(mid_x + vec[0] * width / 2.0)
+ y = int(mid_y + vec[1] * height / 2.0)
+
+ # draw some a star at the active vertex
+ blf.position(0, x, y, 0)
+ blf.size(0, 26, 72)
+ blf.draw(0, "*")
+
+
+class VertexSlideOperator(bpy.types.Operator):
+ bl_idname = "vertex.slide"
+ bl_label = "VB Vertex Slide 2" # PKHG easy to searc for ;-)
+
+ Vert1 = Point()
+ Vert2 = Point()
+ LinkedVerts = []
+ VertLinkedIdx = 0 # Index of the linked vertex selected
+ temp_mouse_x = 0
+ tmpMouse = Vector((0, 0))
+
+ first_vertex_move = True
+ left_alt_press = False
+ left_shift_press = False
+
+ #compute the screendistance of two vertices (here an edge, I hope)!
+ def denominator(self, vertex_zero_co, vertex_one_co):
+ global denom
+ matw = bpy.context.active_object.matrix_world
+ V0 = vertex_zero_co * matw
+ res0 = view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d, V0) # make global?
+ V1 = vertex_one_co * matw
+ res1 = view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d, V1)
+ result = (res0 - res1).length
+ if debugDenomiator:
+ print("denomiator info:")
+ print("matw", matw)
+ print("edge vertices are\n", vertex_zero_co, "\n", vertex_one_co)
+ print("V0 = ", V0)
+ print("=>location_3d_to_region_2(bpy.context.region,bpy.context.space_data.region_3d,vzero) = \n", res0)
+ print("V1 = ", V1)
+ print("=>location_3d_to_region_2(bpy.context.region,bpy.context.space_data.region_3d,vone) = \n", res1)
+ print("edgelength = ", result)
+ denom = result # global denom if < eps =>> error?
+ return result
+
+ def modal(self, context, event):
+ global ActiveVertex, mouseVec, direction
+ context.area.tag_redraw()
+ if event.type == 'MOUSEMOVE':
+ Vertices = bpy.context.object.data.vertices
+ bpy.ops.object.mode_set(mode='OBJECT')
+ if self.Vert2.original.idx != -1: # Starting with 2 vertex selected
+ denom = self.denominator(self.Vert1.original.co, self.Vert2.original.co) # check on too small denom?! Done some test, I think isn't a problem
+ tmpMouse = Vector((event.mouse_x, event.mouse_y))
+ t_diff = (tmpMouse - self.tmpMouse).length
+ self.tmpMouse = tmpMouse
+ td = t_diff * direction / denom
+ mouseDir = "right"
+ if event.mouse_x < self.temp_mouse_x:
+ mouseDir = "left"
+ td = -td
+ if self.first_vertex_move:
+ self.Vert1.t = self.Vert1.t + td
+ Vertices[self.Vert1.original.idx].co = NewCoordinate(self.Vert1.original.co, self.Vert2.original.co, self.Vert1.t)
+ Vertices[self.Vert2.original.idx].co = NewCoordinate(self.Vert2.original.co, self.Vert1.original.co, self.Vert2.t)
+ else:
+ self.Vert2.t = self.Vert2.t + td
+ Vertices[self.Vert1.original.idx].co = NewCoordinate(self.Vert1.original.co, self.Vert2.original.co, self.Vert1.t)
+ Vertices[self.Vert2.original.idx].co = NewCoordinate(self.Vert2.original.co, self.Vert1.original.co, self.Vert2.t)
+ else: # Starting with 1 vertex selected
+ denom = self.denominator(self.Vert1.original.co, self.LinkedVerts[self.VertLinkedIdx].original.co) # check on too small denom?! Done some test, I think isn't a problem
+ tmpMouse = Vector((event.mouse_x, event.mouse_y))
+ t_diff = (tmpMouse - self.tmpMouse).length
+ self.tmpMouse = tmpMouse
+ td = t_diff * direction / denom
+ mouseDir = "right"
+ if event.mouse_x < self.temp_mouse_x:
+ mouseDir = "left"
+ td = -td
+ if self.left_alt_press: # Continuous slide (Starting from last position, not from original position)
+ self.Vert2.t = self.Vert2.t + td
+ Vertices[self.Vert1.original.idx].co = NewCoordinate(self.Vert2.original.co, self.LinkedVerts[self.VertLinkedIdx].original.co, self.Vert2.t)
+ ActiveVertex = self.Vert1.original.idx
+ else:
+ self.LinkedVerts[self.VertLinkedIdx].t = self.LinkedVerts[self.VertLinkedIdx].t + td
+ Vertices[self.Vert1.original.idx].co = NewCoordinate(self.Vert1.original.co, self.LinkedVerts[self.VertLinkedIdx].original.co, self.LinkedVerts[self.VertLinkedIdx].t)
+ ActiveVertex = self.Vert1.original.idx
+ self.temp_mouse_x = event.mouse_x
+ bpy.ops.object.mode_set(mode='EDIT')
+
+ elif event.type == 'LEFT_ALT': # Hold ALT to use continuous slide
+ self.left_alt_press = not self.left_alt_press
+ if self.left_alt_press and self.Vert2.original.idx == -1:
+ vert = bpy.context.object.data.vertices[self.Vert1.original.idx]
+ self.Vert2.original.co = Vector((vert.co.x, vert.co.y, vert.co.z))
+ self.Vert2.t = 0
+
+ elif event.type == 'LEFT_SHIFT': # Hold left SHIFT to slide lower
+ self.left_shift_press = not self.left_shift_press
+ if self.left_shift_press:
+ direction *= 0.1
+ else:
+ if direction < 0:
+ direction = -1
+ else:
+ direction = 1
+
+ elif event.type == 'WHEELDOWNMOUSE':
+ if self.Vert2.original.idx == -1: # Starting with 1 vertex selected
+ if self.left_alt_press:
+ vert = bpy.context.object.data.vertices[self.Vert1.original.idx]
+ self.Vert2.original.co = Vector((vert.co.x, vert.co.y, vert.co.z))
+ self.Vert2.t = 0
+ self.VertLinkedIdx = self.VertLinkedIdx + 1
+ if self.VertLinkedIdx > len(self.LinkedVerts) - 1:
+ self.VertLinkedIdx = 0
+ bpy.ops.mesh.select_all(action='DESELECT')
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list