-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
123 lines (84 loc) · 2.81 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import bpy
bl_info = {
"name": "Vertex Traversal",
"blender": (3, 0, 0),
"category": "3D View",
}
def set_object_mode():
bpy.ops.object.mode_set(mode='OBJECT')
def set_edit_mode():
bpy.ops.object.mode_set(mode='EDIT')
def deselect():
bpy.ops.mesh.select_all(action='DESELECT')
def get_active_object():
return bpy.context.active_object
def get_vertex_data():
set_object_mode()
obj = get_active_object()
set_edit_mode()
bpy.ops.mesh.select_mode(type='VERT')
current_vertex_index = 0
vertices_length = len(obj.data.vertices)
for key, value in obj.data.vertices.items():
if value.select:
current_vertex_index = key
return {'current_vertex_index': current_vertex_index,
'vertices_length': vertices_length}
def get_prev_vertex_index(data):
return data['vertices_length'] - 1 if data['current_vertex_index'] - 1 < 0 else data['current_vertex_index'] - 1
def get_next_vertex_index(data):
return 0 if data['current_vertex_index'] + 1 >= data['vertices_length'] else data['current_vertex_index'] + 1
def select_next_vertex():
data = get_vertex_data()
obj = get_active_object()
deselect()
set_object_mode()
next_vertex_index = get_next_vertex_index(data)
obj.data.vertices[next_vertex_index].select = True
set_edit_mode()
def select_prev_vertex():
data = get_vertex_data()
obj = get_active_object()
deselect()
set_object_mode()
prev_vertex_index = get_prev_vertex_index(data)
obj.data.vertices[prev_vertex_index].select = True
set_edit_mode()
class Panel(bpy.types.Panel):
"""Show Vertex Traversal side panel in 3D View"""
bl_idname = "VERTEX_TRAVERSAL_PT_PANEL"
bl_label = "Vertex Traversal"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Vertex Traversal"
@classmethod
def poll(cls, context):
return context.mode in {'EDIT_MESH', 'EDIT_CURVE'}
def draw(self, context):
layout = self.layout
box = layout.box()
row = box.row()
row.operator("vertex.prev")
row.operator("vertex.next")
class OpNextVertex(bpy.types.Operator):
bl_idname = 'vertex.next'
bl_label = 'Next Vertex'
def execute(self, context):
select_next_vertex()
return {'FINISHED'}
class OpPrevVertex(bpy.types.Operator):
bl_idname = 'vertex.prev'
bl_label = 'Prev Vertex'
def execute(self, context):
select_prev_vertex()
return {'FINISHED'}
def register():
bpy.utils.register_class(OpNextVertex)
bpy.utils.register_class(OpPrevVertex)
bpy.utils.register_class(Panel)
def unregister():
bpy.utils.unregister_class(OpNextVertex)
bpy.utils.unregister_class(OpPrevVertex)
bpy.utils.unregister_class(Panel)
if __name__ == "__main__":
register()