forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVIEW3D_MT_select_edit_mesh.py
112 lines (96 loc) · 3.47 KB
/
VIEW3D_MT_select_edit_mesh.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
# 「3Dビュー」エリア > メッシュの「編集」モード > 「選択」メニュー
# "3D View" Area > "Edit" Mode with Mesh > "Select" Menu
import bpy
from bpy.props import *
################
# オペレーター #
################
class SelectAxisLimit(bpy.types.Operator):
bl_idname = "mesh.select_axis_limit"
bl_label = "Select Vertex (X=0)"
bl_description = "Select vertices which X-axis location is zero"
bl_options = {'REGISTER', 'UNDO'}
items = [
("0", "X Axis", "", 1),
("1", "Y Axis", "", 2),
("2", "Z Axis", "", 3),
]
axis : EnumProperty(items=items, name="Axis")
offset : FloatProperty(name="Offset", default=0.0, step=10, precision=3)
threshold : FloatProperty(name="Threshold", default=0.0000001, min=0.0, soft_min=0.0, step=0.1, precision=10)
def execute(self, context):
bpy.ops.object.mode_set(mode="OBJECT")
sel_mode = context.tool_settings.mesh_select_mode[:]
context.tool_settings.mesh_select_mode = [True, False, False]
obj = context.active_object
me = obj.data
if (obj.type == "MESH"):
for vert in me.vertices:
co = [vert.co.x, vert.co.y, vert.co.z][int(self.axis)]
if (-self.threshold <= co - self.offset <= self.threshold):
vert.select = True
bpy.ops.object.mode_set(mode="EDIT")
context.tool_settings.mesh_select_mode = sel_mode
return {'FINISHED'}
class SelectAxisOver(bpy.types.Operator):
bl_idname = "mesh.select_axis_over"
bl_label = "Select Vertex (One Side)"
bl_description = "Select vertices on one side"
bl_options = {'REGISTER', 'UNDO'}
items = [
("0", "X Axis", "", 1),
("1", "Y Axis", "", 2),
("2", "Z Axis", "", 3),
]
axis : EnumProperty(items=items, name="Axis")
direction : EnumProperty(name="Direction", items=[
("1", "Right / Top", "", 2),("-1", "Left / Bottom", "", 1)])
offset : FloatProperty(name="Offset", default=0, step=10, precision=3)
threshold : FloatProperty(name="Threshold", default=0.0000001, step=0.1, precision=10)
def execute(self, context):
bpy.ops.object.mode_set(mode="OBJECT")
sel_mode = context.tool_settings.mesh_select_mode[:]
context.tool_settings.mesh_select_mode = [True, False, False]
obj = context.active_object
me = obj.data
if (obj.type == "MESH"):
for vert in me.vertices:
co = [vert.co.x, vert.co.y, vert.co.z][int(self.axis)]
direct = int(self.direction)
if (self.offset * direct <= co * direct + self.threshold):
vert.select = True
bpy.ops.object.mode_set(mode="EDIT")
context.tool_settings.mesh_select_mode = sel_mode
return {'FINISHED'}
################
# クラスの登録 #
################
classes = [
SelectAxisLimit,
SelectAxisOver
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
################
# メニュー追加 #
################
# メニューのオン/オフの判定
def IsMenuEnable(self_id):
for id in bpy.context.preferences.addons[__name__.partition('.')[0]].preferences.disabled_menu.split(','):
if (id == self_id):
return False
else:
return True
# メニューを登録する関数
def menu(self, context):
if (IsMenuEnable(__name__.split('.')[-1])):
self.layout.separator()
self.layout.operator(SelectAxisLimit.bl_idname, icon="PLUGIN")
self.layout.operator(SelectAxisOver.bl_idname, icon="PLUGIN")
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.separator()
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]