[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4306] Cursor control addon: Update for API change (draw handlers).
Sebastian Nell
codemanx at gmx.de
Tue Feb 19 13:51:21 CET 2013
Revision: 4306
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4306
Author: codemanx
Date: 2013-02-19 12:51:21 +0000 (Tue, 19 Feb 2013)
Log Message:
-----------
Cursor control addon: Update for API change (draw handlers). Uses Panel.poll() to init overlays and doesn't remove draw handlers - wth? But no crash on quit like for other addons, see http://projects.blender.org/tracker/?func=detail&atid=498&aid=34312&group_id=9
Removing mesh_vertex_slide.py from contrib, unmaintained copy in branches/broken_stuff/
Modified Paths:
--------------
contrib/py/scripts/addons/cursor_control/__init__.py
contrib/py/scripts/addons/cursor_control/history.py
contrib/py/scripts/addons/cursor_control/memory.py
Removed Paths:
-------------
branches/broken_stuff/mesh_vertex_slide.py
Deleted: branches/broken_stuff/mesh_vertex_slide.py
===================================================================
--- branches/broken_stuff/mesh_vertex_slide.py 2013-02-18 22:53:10 UTC (rev 4305)
+++ branches/broken_stuff/mesh_vertex_slide.py 2013-02-19 12:51:21 UTC (rev 4306)
@@ -1,473 +0,0 @@
-# ##### 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 #####
-
-# <pep8 compliant>
-
-bl_info = {
- "name": "Vertex slide for Bmesh",
- "author": "Valter Battioli (ValterVB) and PKHG",
- "version": (2, 0, 0),
- "blender": (2, 62, 0),
- "location": "View3D > Mesh > Vertices (CTRL V-key)",
- "description": "Slide a vertex along an edge or a line",
- "warning": "Work only with Blender 2.62 or higher",
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/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
-#ver. 1.0.9: Fix for reverse vector multiplication
-#ver. 1.1.0: Delete debug info, some cleanup and add some comments
-#ver. 1.1.1: Now UNDO work properly
-#ver. 1.1.2: Refactory and some clean of the code.
-# Add edge drawing (from chromoly vertex slide)
-# Add help on screen (from chromooly vertex slide)
-#ver. 1.1.3: Now work also with Continuos Grab, some clean on code
-#ver. 1.1.4: Remove a lot of mode switching in Invoke. It was too slow
-# with big mesh.
-#ver. 1.1.5: Changed Lay out of the Help and the Key for reverse the
-# movement. Left/Right arrow rather than Pus/Minus numpad
-#ver. 1.1.6: Now the vertex movement is always coherent with Mouse movement
-#ver. 2.0.0: Update to Bmesh and remove all mode switching
-#ver. 2.0.1: Replaced Conv3DtoScreen2D function with location_3d_to_region_2d
-#ver. 2.0.2: Fix crash if there are some duplicate vertices
-#***********************************************************************
-
-import bpy
-import bmesh
-import bgl
-import blf
-from mathutils import Vector
-from bpy_extras.view3d_utils import location_3d_to_region_2d as loc3d2d
-
-# Equation of the line
-# Changing t we 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)
-
-# This class store Vertex data
-class Point():
- def __init__(self):
- self.original = self.Vertex() # Original position
- self.new = self.Vertex() # New position
- self.t = 0 # Used for move the vertex
- self.x2D = 0 # Screen 2D cooord of the point
- self.y2D = 0 # Screen 2D cooord of the point
- self.selected = False
-
- class Vertex():
- def __init__(self):
- self.co = None
- self.idx = None
-
-class BVertexSlideOperator(bpy.types.Operator):
- bl_idname = "vertex.slide"
- bl_label = "Vertex Slide"
- bl_options = {'REGISTER', 'UNDO', 'GRAB_POINTER', 'BLOCKING', 'INTERNAL'}
-
- Vertex1 = Point() # First selected vertex data
- LinkedVertices1 = [] # List of index of linked verts of Vertex1
- Vertex2 = Point() # Second selected vertex data
- LinkedVertices2 = [] # List of index of linked verts of Vertex2
- ActiveVertex = None # Index of vertex to be moved
- tmpMouse_x = 0
- tmpMouse = Vector((0, 0))
- Direction = 1.0 # Used for direction and precision of the movement
- FirstVertexMove = True # If true move the first vertex
- VertLinkedIdx = 0 # Index of LinkedVertices1. Used only for 1 vertex select case
- LeftAltPress = False # Flag to know if ALT is hold on
- LeftShiftPress = False # Flag to know if SHIFT is hold on
- obj = None # Object
- mesh = None # Mesh
- bm = None # BMesh
-
- # OpenGL Function to draw on the screen help and pointer *
- def draw_callback_px(self, context):
- x, y = loc3d2d(context.region, context.space_data.region_3d, self.bm.verts[self.ActiveVertex].co)
-
- # Draw an * at the active vertex
- blf.position(0, x, y, 0)
- blf.size(0, 26, 72)
- blf.draw(0, "*")
-
- #Draw Help
- yPos=30
- blf.size(0, 11, context.user_preferences.system.dpi)
- txtHelp1 = "{SHIFT}:Precision"
- txtHelp2 = "{WHEEL}:Change the vertex/edge"
- txtHelp3 = "{ALT}:Continuos slide"
- txtHelp4 = "{LEFT ARROW}:Reverse the movement"
- txtHelp5 = "{RIGHT ARROW}:Restore the movement"
- blf.position(0, 70, yPos, 0)
- blf.draw(0, txtHelp5)
- yPos += (int(blf.dimensions(0, txtHelp4)[1]*2))
- blf.position(0 , 70, yPos, 0)
- blf.draw(0, txtHelp4)
- yPos += (int(blf.dimensions(0, txtHelp3)[1]*2))
- blf.position(0 , 70, yPos, 0)
- blf.draw(0, txtHelp3)
- yPos += (int(blf.dimensions(0, txtHelp2)[1]*2))
- blf.position(0 , 70, yPos, 0)
- blf.draw(0, txtHelp2)
- yPos += (int(blf.dimensions(0, txtHelp1)[1]*2))
- blf.position(0 , 70, yPos, 0)
- blf.draw(0, txtHelp1)
-
- # Draw edge
- bgl.glEnable(bgl.GL_BLEND)
- bgl.glColor4f(1.0, 0.1, 0.8, 1.0)
- bgl.glBegin(bgl.GL_LINES)
- for p in self.LinkedVertices1:
- bgl.glVertex2f(self.Vertex1.x2D, self.Vertex1.y2D)
- bgl.glVertex2f(p.x2D, p.y2D)
- for p in self.LinkedVertices2:
- bgl.glVertex2f(self.Vertex2.x2D, self.Vertex2.y2D)
- bgl.glVertex2f(p.x2D, p.y2D)
- bgl.glEnd()
-
- # Compute the screen distance of two vertices
- def ScreenDistance(self, vertex_zero_co, vertex_one_co):
- matw = bpy.context.active_object.matrix_world
- V0 = matw * vertex_zero_co
- res0 = loc3d2d(bpy.context.region, bpy.context.space_data.region_3d, V0)
- V1 = matw * vertex_one_co
- res1 = loc3d2d(bpy.context.region, bpy.context.space_data.region_3d, V1)
- result = (res0 - res1).length
- return result
-
- def modal(self, context, event):
- if event.type == 'MOUSEMOVE':
- Vertices = self.bm.verts
- # Calculate the temp t value. Stored in td
- tmpMouse = Vector((event.mouse_x, event.mouse_y))
- t_diff = (tmpMouse - self.tmpMouse).length
- self.tmpMouse = tmpMouse
- if self.Vertex2.original.idx is not None: # 2 vertex selected
- td = t_diff * self.Direction / self.ScreenDistance(self.Vertex1.original.co,
- self.Vertex2.original.co)
- else: # 1 vertex selected
- td = t_diff * self.Direction / self.ScreenDistance(self.Vertex1.original.co,
- self.LinkedVertices1[self.VertLinkedIdx].original.co)
- if event.mouse_x < self.tmpMouse_x:
- td = -td
-
- if self.Vertex2.original.idx is not None: # 2 vertex selected
- # Calculate the t valuse
- if self.FirstVertexMove:
- self.Vertex1.t = self.Vertex1.t + td
- else:
- self.Vertex2.t = self.Vertex2.t + td
- # Move the vertex
- Vertices[self.Vertex1.original.idx].co = NewCoordinate(self.Vertex1.original.co,
- self.Vertex2.original.co,
- self.Vertex1.t)
- Vertices[self.Vertex2.original.idx].co = NewCoordinate(self.Vertex2.original.co,
- self.Vertex1.original.co,
- self.Vertex2.t)
- else: # 1 vertex selected
- if self.LeftAltPress: # Continuous slide
- # Calculate the t valuse
- self.Vertex2.t = self.Vertex2.t + td
- # Move the vertex
- Vertices[self.Vertex1.original.idx].co = NewCoordinate(self.Vertex2.original.co,
- self.LinkedVertices1[self.VertLinkedIdx].original.co,
- self.Vertex2.t)
- else:
- # Calculate the t valuse
- self.LinkedVertices1[self.VertLinkedIdx].t = self.LinkedVertices1[self.VertLinkedIdx].t + td
- # Move the vertex
- Vertices[self.Vertex1.original.idx].co = NewCoordinate(self.Vertex1.original.co,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list