cleanup for addon python internals, fix filtering bug.
[blender.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.python_file_run"
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         split.operator_context = 'EXEC_DEFAULT'
66
67         if md:
68             # remove modifier + settings
69             split.set_context_pointer("modifier", md)
70             split.operator("object.modifier_remove", text="Remove")
71
72             row = split.row(align=True)
73             row.prop(md, "render", text="")
74             row.prop(md, "realtime", text="")
75         else:
76             # add modifier
77             split.operator("object.modifier_add", text="Add").type = 'CLOTH'
78             if wide_ui:
79                 split.column()
80
81         split.operator_context = 'INVOKE_DEFAULT'
82
83         if md:
84             cloth = md.settings
85
86             split = layout.split()
87
88             split.active = cloth_panel_enabled(md)
89
90             col = split.column()
91
92             col.label(text="Presets:")
93             sub = col.row(align=True).split(percentage=0.75)
94             sub.menu("CLOTH_MT_presets", text="Presets")
95             sub.operator("cloth.preset_add", text="Add")
96
97             col.label(text="Quality:")
98             col.prop(cloth, "quality", text="Steps", slider=True)
99
100             col.label(text="Material:")
101             col.prop(cloth, "mass")
102             col.prop(cloth, "structural_stiffness", text="Structural")
103             col.prop(cloth, "bending_stiffness", text="Bending")
104
105             if wide_ui:
106                 col = split.column()
107
108             col.label(text="Damping:")
109             col.prop(cloth, "spring_damping", text="Spring")
110             col.prop(cloth, "air_damping", text="Air")
111
112             col.prop(cloth, "pin_cloth", text="Pinning")
113             sub = col.column()
114             sub.active = cloth.pin_cloth
115             sub.prop_object(cloth, "mass_vertex_group", ob, "vertex_groups", text="")
116             sub.prop(cloth, "pin_stiffness", text="Stiffness")
117
118             col.label(text="Pre roll:")
119             col.prop(cloth, "pre_roll", text="Frame")
120
121             # Disabled for now
122             """
123             if cloth.mass_vertex_group:
124                 layout.label(text="Goal:")
125
126                 col = layout.column_flow()
127                 col.prop(cloth, "goal_default", text="Default")
128                 col.prop(cloth, "goal_spring", text="Stiffness")
129                 col.prop(cloth, "goal_friction", text="Friction")
130             """
131
132
133 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel):
134     bl_label = "Cloth Cache"
135     bl_default_closed = True
136
137     def poll(self, context):
138         return context.cloth
139
140     def draw(self, context):
141         md = context.cloth
142         point_cache_ui(self, context, md.point_cache, cloth_panel_enabled(md), 0, 0)
143
144
145 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel):
146     bl_label = "Cloth Collision"
147     bl_default_closed = True
148
149     def poll(self, context):
150         return context.cloth
151
152     def draw_header(self, context):
153         cloth = context.cloth.collision_settings
154
155         self.layout.active = cloth_panel_enabled(context.cloth)
156         self.layout.prop(cloth, "enable_collision", text="")
157
158     def draw(self, context):
159         layout = self.layout
160
161         cloth = context.cloth.collision_settings
162         md = context.cloth
163         wide_ui = context.region.width > narrowui
164
165         layout.active = cloth.enable_collision and cloth_panel_enabled(md)
166
167         split = layout.split()
168
169         col = split.column()
170         col.prop(cloth, "collision_quality", slider=True, text="Quality")
171         col.prop(cloth, "min_distance", slider=True, text="Distance")
172         col.prop(cloth, "friction")
173
174         if wide_ui:
175             col = split.column()
176         col.prop(cloth, "enable_self_collision", text="Self Collision")
177         sub = col.column()
178         sub.active = cloth.enable_self_collision
179         sub.prop(cloth, "self_collision_quality", slider=True, text="Quality")
180         sub.prop(cloth, "self_min_distance", slider=True, text="Distance")
181
182
183 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
184     bl_label = "Cloth Stiffness Scaling"
185     bl_default_closed = True
186
187     def poll(self, context):
188         return context.cloth
189
190     def draw_header(self, context):
191         cloth = context.cloth.settings
192
193         self.layout.active = cloth_panel_enabled(context.cloth)
194         self.layout.prop(cloth, "stiffness_scaling", text="")
195
196     def draw(self, context):
197         layout = self.layout
198
199         md = context.cloth
200         ob = context.object
201         cloth = context.cloth.settings
202         wide_ui = context.region.width > narrowui
203
204         layout.active = cloth.stiffness_scaling and cloth_panel_enabled(md)
205
206         split = layout.split()
207
208         col = split.column()
209         col.label(text="Structural Stiffness:")
210         col.prop_object(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
211         col.prop(cloth, "structural_stiffness_max", text="Max")
212
213         if wide_ui:
214             col = split.column()
215         col.label(text="Bending Stiffness:")
216         col.prop_object(cloth, "bending_vertex_group", ob, "vertex_groups", text="")
217         col.prop(cloth, "bending_stiffness_max", text="Max")
218
219
220 class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel):
221     bl_label = "Cloth Field Weights"
222     bl_default_closed = True
223
224     def poll(self, context):
225         return (context.cloth)
226
227     def draw(self, context):
228         cloth = context.cloth.settings
229         effector_weights_ui(self, context, cloth.effector_weights)
230
231
232 classes = [
233     CLOTH_MT_presets,
234
235     PHYSICS_PT_cloth,
236     PHYSICS_PT_cloth_cache,
237     PHYSICS_PT_cloth_collision,
238     PHYSICS_PT_cloth_stiffness,
239     PHYSICS_PT_cloth_field_weights]
240
241
242 def register():
243     register = bpy.types.register
244     for cls in classes:
245         register(cls)
246
247
248 def unregister():
249     unregister = bpy.types.unregister
250     for cls in classes:
251         unregister(cls)
252
253 if __name__ == "__main__":
254     register()