Fix [#22120] Physics modifiers can't be removed
[blender-staging.git] / release / scripts / ui / properties_physics_cloth.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 narrowui = 180
23
24
25 from properties_physics_common import point_cache_ui
26 from properties_physics_common import effector_weights_ui
27
28
29 def cloth_panel_enabled(md):
30     return md.point_cache.baked is False
31
32
33 class CLOTH_MT_presets(bpy.types.Menu):
34     '''
35     Creates the menu items by scanning scripts/templates
36     '''
37     bl_label = "Cloth Presets"
38     preset_subdir = "cloth"
39     preset_operator = "script.execute_preset"
40     draw = bpy.types.Menu.draw_preset
41
42
43 class PhysicButtonsPanel(bpy.types.Panel):
44     bl_space_type = 'PROPERTIES'
45     bl_region_type = 'WINDOW'
46     bl_context = "physics"
47
48     def poll(self, context):
49         ob = context.object
50         rd = context.scene.render
51         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
52
53
54 class PHYSICS_PT_cloth(PhysicButtonsPanel):
55     bl_label = "Cloth"
56
57     def draw(self, context):
58         layout = self.layout
59
60         md = context.cloth
61         ob = context.object
62         wide_ui = context.region.width > narrowui
63
64         split = layout.split()
65
66         if md:
67             # remove modifier + settings
68             split.set_context_pointer("modifier", md)
69             split.operator("object.modifier_remove", text="Remove")
70
71             row = split.row(align=True)
72             row.prop(md, "render", text="")
73             row.prop(md, "realtime", text="")
74         else:
75             # add modifier
76             split.operator("object.modifier_add", text="Add").type = 'CLOTH'
77             if wide_ui:
78                 split.column()
79
80         if md:
81             cloth = md.settings
82
83             split = layout.split()
84
85             split.active = cloth_panel_enabled(md)
86
87             col = split.column()
88
89             col.label(text="Presets:")
90             sub = col.row(align=True).split(percentage=0.75)
91             sub.menu("CLOTH_MT_presets", text=bpy.types.CLOTH_MT_presets.bl_label)
92             sub.operator("cloth.preset_add", text="", icon="ZOOMIN")
93
94             col.label(text="Quality:")
95             col.prop(cloth, "quality", text="Steps", slider=True)
96
97             col.label(text="Material:")
98             col.prop(cloth, "mass")
99             col.prop(cloth, "structural_stiffness", text="Structural")
100             col.prop(cloth, "bending_stiffness", text="Bending")
101
102             if wide_ui:
103                 col = split.column()
104
105             col.label(text="Damping:")
106             col.prop(cloth, "spring_damping", text="Spring")
107             col.prop(cloth, "air_damping", text="Air")
108
109             col.prop(cloth, "pin_cloth", text="Pinning")
110             sub = col.column()
111             sub.active = cloth.pin_cloth
112             sub.prop_object(cloth, "mass_vertex_group", ob, "vertex_groups", text="")
113             sub.prop(cloth, "pin_stiffness", text="Stiffness")
114
115             col.label(text="Pre roll:")
116             col.prop(cloth, "pre_roll", text="Frame")
117
118             # Disabled for now
119             """
120             if cloth.mass_vertex_group:
121                 layout.label(text="Goal:")
122
123                 col = layout.column_flow()
124                 col.prop(cloth, "goal_default", text="Default")
125                 col.prop(cloth, "goal_spring", text="Stiffness")
126                 col.prop(cloth, "goal_friction", text="Friction")
127             """
128
129             key = ob.data.shape_keys
130
131             if key:
132                 col.label(text="Rest Shape Key:")
133                 col.prop_object(cloth, "rest_shape_key", key, "keys", text="")
134
135
136 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel):
137     bl_label = "Cloth Cache"
138     bl_default_closed = True
139
140     def poll(self, context):
141         return context.cloth
142
143     def draw(self, context):
144         md = context.cloth
145         point_cache_ui(self, context, md.point_cache, cloth_panel_enabled(md), 0, 0)
146
147
148 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel):
149     bl_label = "Cloth Collision"
150     bl_default_closed = True
151
152     def poll(self, context):
153         return context.cloth
154
155     def draw_header(self, context):
156         cloth = context.cloth.collision_settings
157
158         self.layout.active = cloth_panel_enabled(context.cloth)
159         self.layout.prop(cloth, "enable_collision", text="")
160
161     def draw(self, context):
162         layout = self.layout
163
164         cloth = context.cloth.collision_settings
165         md = context.cloth
166         wide_ui = context.region.width > narrowui
167
168         layout.active = cloth.enable_collision and cloth_panel_enabled(md)
169
170         split = layout.split()
171
172         col = split.column()
173         col.prop(cloth, "collision_quality", slider=True, text="Quality")
174         col.prop(cloth, "min_distance", slider=True, text="Distance")
175         col.prop(cloth, "friction")
176
177         if wide_ui:
178             col = split.column()
179         col.prop(cloth, "enable_self_collision", text="Self Collision")
180         sub = col.column()
181         sub.active = cloth.enable_self_collision
182         sub.prop(cloth, "self_collision_quality", slider=True, text="Quality")
183         sub.prop(cloth, "self_min_distance", slider=True, text="Distance")
184
185         layout.prop(cloth, "group")
186
187
188 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
189     bl_label = "Cloth Stiffness Scaling"
190     bl_default_closed = True
191
192     def poll(self, context):
193         return context.cloth
194
195     def draw_header(self, context):
196         cloth = context.cloth.settings
197
198         self.layout.active = cloth_panel_enabled(context.cloth)
199         self.layout.prop(cloth, "stiffness_scaling", text="")
200
201     def draw(self, context):
202         layout = self.layout
203
204         md = context.cloth
205         ob = context.object
206         cloth = context.cloth.settings
207         wide_ui = context.region.width > narrowui
208
209         layout.active = cloth.stiffness_scaling and cloth_panel_enabled(md)
210
211         split = layout.split()
212
213         col = split.column()
214         col.label(text="Structural Stiffness:")
215         col.prop_object(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
216         col.prop(cloth, "structural_stiffness_max", text="Max")
217
218         if wide_ui:
219             col = split.column()
220         col.label(text="Bending Stiffness:")
221         col.prop_object(cloth, "bending_vertex_group", ob, "vertex_groups", text="")
222         col.prop(cloth, "bending_stiffness_max", text="Max")
223
224
225 class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel):
226     bl_label = "Cloth Field Weights"
227     bl_default_closed = True
228
229     def poll(self, context):
230         return (context.cloth)
231
232     def draw(self, context):
233         cloth = context.cloth.settings
234         effector_weights_ui(self, context, cloth.effector_weights)
235
236
237 classes = [
238     CLOTH_MT_presets,
239
240     PHYSICS_PT_cloth,
241     PHYSICS_PT_cloth_cache,
242     PHYSICS_PT_cloth_collision,
243     PHYSICS_PT_cloth_stiffness,
244     PHYSICS_PT_cloth_field_weights]
245
246
247 def register():
248     register = bpy.types.register
249     for cls in classes:
250         register(cls)
251
252
253 def unregister():
254     unregister = bpy.types.unregister
255     for cls in classes:
256         unregister(cls)
257
258 if __name__ == "__main__":
259     register()