-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path__init__.py
251 lines (191 loc) · 7.74 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# 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 3 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
# MERCHANTIBILITY 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, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.props import FloatProperty
from bpy.types import PropertyGroup
bl_info = {
"name" : "SimpleLattice",
"author" : "benjamin.sauder, Eugene Dudavkin",
"version": (0, 1, 6),
"blender" : (2, 93, 0),
"location": "View3D",
"description" : "A tool to simplify the workflow with lattice objects.",
"doc_url": "https://blenderartists.org/t/simplelattice-deform-with-pleasure/1321032",
"tracker_url": "https://github.com/BenjaminSauder/SimpleLattice",
"category" : "Object",
}
from . import op_LatticeCreate
from . import op_LatticeApply
from . import op_LatticeRemove
from . import preferences
def get_u(self):
lattice = bpy.context.active_object
res = bpy.data.lattices[lattice.name]
return res.points_u
def set_u(self, value):
lattice = bpy.context.active_object
res = bpy.data.lattices[lattice.name]
res.points_u = value
def get_v(self):
lattice = bpy.context.active_object
res = bpy.data.lattices[lattice.name]
return res.points_v
def set_v(self, value):
lattice = bpy.context.active_object
res = bpy.data.lattices[lattice.name]
res.points_v = value
def get_w(self):
lattice = bpy.context.active_object
res = bpy.data.lattices[lattice.name]
return res.points_w
def set_w(self, value):
lattice = bpy.context.active_object
res = bpy.data.lattices[lattice.name]
res.points_w = value
class MODIFIERSTRENGTH_PG_main(PropertyGroup):
def update_modifierstrength(self, context):
lattice = context.active_object
for o in bpy.data.objects:
for modifier in o.modifiers:
if modifier.type == 'LATTICE' and "SimpleLattice" in modifier.name:
if modifier.object == lattice:
modifier.strength = self.str_obj
str_obj: bpy.props.FloatProperty(
description = "Change strength for Lattice modifier in objects affected by lattice",
name = "Strength",
min = 0.0,
max = 1.0,
step = 1,
default = 1,
update = update_modifierstrength
)
class RESOLUTIONUVW_PG_main(PropertyGroup):
change_u: bpy.props.IntProperty(
min = 2,
max = 20,
get=get_u,
set=set_u
)
change_v: bpy.props.IntProperty(
min = 2,
max = 20,
get=get_v,
set=set_v
)
change_w: bpy.props.IntProperty(
min = 2,
max = 20,
get=get_w,
set=set_w
)
classes = [
preferences.SimpleLatticePrefs,
op_LatticeCreate.Op_LatticeCreateOperator,
op_LatticeApply.Op_LatticeApplyOperator,
op_LatticeRemove.Op_LatticeRemoveOperator,
MODIFIERSTRENGTH_PG_main,
RESOLUTIONUVW_PG_main
]
prepend_menus = [
# removing this as it add top menu entry
# bpy.types.VIEW3D_MT_edit_mesh,
# bpy.types.VIEW3D_MT_object,
bpy.types.VIEW3D_MT_object_context_menu,
bpy.types.VIEW3D_MT_edit_mesh_context_menu,
bpy.types.VIEW3D_MT_gpencil_edit_context_menu,
bpy.types.VIEW3D_MT_edit_lattice_context_menu,
bpy.types.VIEW3D_MT_edit_lattice,
]
append_menus = [
# removing this as it add bottom menu entry
bpy.types.VIEW3D_MT_edit_mesh,
bpy.types.VIEW3D_MT_object,
]
def context_menu(self, context):
#selected_objects = context.selected_objects
#lattice = context.active_object
layout = self.layout
show_apply_op = op_LatticeApply.Op_LatticeApplyOperator.poll(context)
show_remove_op = op_LatticeRemove.Op_LatticeRemoveOperator.poll(context)
show_create_op = op_LatticeCreate.Op_LatticeCreateOperator.poll(context)
do_show = show_apply_op or show_create_op
if do_show and type(self in append_menus):
layout.separator()
if show_apply_op:
layout.operator("object.op_lattice_apply")
if show_remove_op:
layout.operator("object.op_lattice_remove")
if show_create_op and not show_apply_op:
layout.operator("object.op_lattice_create")
if do_show and type(self in prepend_menus):
layout.separator()
layout.separator()
if (context.active_object is not None) and (context.active_object.type == 'LATTICE') \
and ("SimpleLattice" in context.active_object.name) \
and (context.active_object.mode == 'EDIT'):
layout.label(text="Simple Lattice Resolution:")
col = layout.column()
sub = col.column(align=True)
res = context.scene.RESOLUTIONUVW_PG_main
sub.prop(res, "change_u", text=" U")
sub.prop(res, "change_v", text=" V")
sub.prop(res, "change_w", text=" W")
layout.separator()
if (context.active_object is not None) and (context.active_object.type == 'LATTICE') \
and ("SimpleLattice" in context.active_object.name) \
and (context.active_object.mode == 'EDIT'):
props = context.scene.MODIFIERSTRENGTH_PG_main
layout.prop(props, "str_obj", text=" Simple Lattice Strength")
layout.separator()
def object_mesh_menu(self, context):
layout = self.layout
show_apply_op = op_LatticeApply.Op_LatticeApplyOperator.poll(context)
show_remove_op = op_LatticeRemove.Op_LatticeRemoveOperator.poll(context)
show_create_op = op_LatticeCreate.Op_LatticeCreateOperator.poll(context)
do_show = show_apply_op or show_create_op
if do_show and type(self in append_menus):
layout.separator()
if show_apply_op:
layout.operator("object.op_lattice_apply")
if show_remove_op:
layout.operator("object.op_lattice_remove")
if show_create_op and not show_apply_op:
layout.operator("object.op_lattice_create")
# if (context.active_object is not None) and (context.active_object.type == 'LATTICE') \
# and ("SimpleLattice" in context.active_object.name):
# props = context.scene.MODIFIERSTRENGTH_PG_main
# layout.prop(props, "str_obj", text=" Simple Lattice Strength")
def register():
for menu in prepend_menus:
menu.prepend(context_menu)
for menu in append_menus:
menu.append(object_mesh_menu)
for c in classes:
bpy.utils.register_class(c)
bpy.types.Scene.MODIFIERSTRENGTH_PG_main = bpy.props.PointerProperty(type = MODIFIERSTRENGTH_PG_main)
bpy.types.Scene.RESOLUTIONUVW_PG_main = bpy.props.PointerProperty(type = RESOLUTIONUVW_PG_main)
def unregister():
# menus = prepend_menus
# menus.extend(append_menus)
# for menu in menus:
# menu.remove(context_menu)
for menu in prepend_menus:
menu.remove(context_menu)
for menu in append_menus:
menu.remove(object_mesh_menu)
for c in classes:
bpy.utils.unregister_class(c)
del bpy.types.Scene.MODIFIERSTRENGTH_PG_main
del bpy.types.Scene.RESOLUTIONUVW_PG_main
if __name__ == "__main__":
register()