[Bf-extensions-cvs] [2b93a12] master: New Feature: Print vertices indices.

Eugenio Pignataro noreply at git.blender.org
Mon Apr 7 16:58:49 CEST 2014


Commit: 2b93a125164ba28e0c6be66bc48238c649238178
Author: Eugenio Pignataro
Date:   Mon Apr 7 11:58:37 2014 -0300
https://developer.blender.org/rBAC2b93a125164ba28e0c6be66bc48238c649238178

New Feature: Print vertices indices.

===================================================================

M	oscurart_tools/__init__.py
M	oscurart_tools/oscurart_meshes.py

===================================================================

diff --git a/oscurart_tools/__init__.py b/oscurart_tools/__init__.py
index 5a734cc..647f179 100644
--- a/oscurart_tools/__init__.py
+++ b/oscurart_tools/__init__.py
@@ -181,6 +181,8 @@ class OscPanelMesh(OscPollMesh, bpy.types.Panel):
         colrow=col.row(align=1)
         colrow.operator("mesh.overlap_uv_faces", icon="UV_FACESEL")               
         colrow=col.row(align=1)
+        colrow.operator("view3d.modal_operator", icon="STICKY_UVS_DISABLE")               
+        colrow=col.row(align=1)        
         colrow.operator("file.export_groups_osc", icon='GROUP_VCOL')
         colrow.operator("file.import_groups_osc", icon='GROUP_VCOL')
         colrow=col.row(align=1)
diff --git a/oscurart_tools/oscurart_meshes.py b/oscurart_tools/oscurart_meshes.py
index 67e1aa9..bc51467 100644
--- a/oscurart_tools/oscurart_meshes.py
+++ b/oscurart_tools/oscurart_meshes.py
@@ -6,6 +6,9 @@ import stat
 import bmesh
 import time
 import random
+import bgl
+import blf
+from bpy_extras.view3d_utils import location_3d_to_region_2d
 
 C = bpy.context
 D = bpy.data
@@ -330,4 +333,58 @@ class OscImportVC (bpy.types.Operator):
 
     def execute(self, context):
         DefOscImportVC()
-        return {'FINISHED'}              
\ No newline at end of file
+        return {'FINISHED'}              
+    
+    
+## ------------------ PRINT VERTICES ----------------------
+
+
+def dibuja_callback(self, context):
+    font_id = 0     
+    bm = bmesh.from_edit_mesh(bpy.context.object.data)    
+    for v in bm.verts:
+        cord = location_3d_to_region_2d(context.region, context.space_data.region_3d, v.co)
+        blf.position(font_id, cord[0], cord[1], 0)
+        blf.size(font_id, self.tsize, 72)
+        blf.draw(font_id, str(v.index))
+    
+    
+class ModalIndexOperator(bpy.types.Operator):
+    bl_idname = "view3d.modal_operator"
+    bl_label = "Print Vertices"    
+    
+    @classmethod
+    def poll(cls, context):
+        return True if context.active_object is not None and context.object.type == "MESH" else False
+    
+    def modal(self, context, event):
+        context.area.tag_redraw()        
+        if event.type == 'MOUSEMOVE':
+            self.x = event.mouse_region_x
+        elif event.type == 'LEFTMOUSE':
+            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
+            return {'FINISHED'}
+        elif event.type == 'PAGE_UP':
+            self.tsize += 1
+        elif event.type == 'PAGE_DOWN':
+            self.tsize -= 1            
+        elif event.type in {'RIGHTMOUSE', 'ESC', 'TAB'}:
+            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
+            context.area.header_text_set()
+            return {'CANCELLED'}
+
+        return {'PASS_THROUGH'}
+    
+    def invoke(self, context, event):
+        if context.area.type == "VIEW_3D":
+            context.area.header_text_set("Esc: exit, PageUP/Down: text size")
+            bpy.ops.object.mode_set(mode="EDIT")
+            self.tsize = 20
+            args = (self, context)
+            self._handle = bpy.types.SpaceView3D.draw_handler_add(dibuja_callback, args, "WINDOW", "POST_PIXEL")  
+            context.window_manager.modal_handler_add(self)
+            return{'RUNNING_MODAL'}
+        else:
+            self.report({"WARNING"}, "Is not a 3D Space")
+            return {'CANCELLED'}
+                
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list