Code cleanup: unused python vars & imports
[blender-staging.git] / release / scripts / startup / bl_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 from bpy.types import Menu, Panel
22
23 from bl_ui.properties_physics_common import (point_cache_ui,
24                                              effector_weights_ui)
25
26
27 def cloth_panel_enabled(md):
28     return md.point_cache.is_baked is False
29
30
31 class CLOTH_MT_presets(Menu):
32     bl_label = "Cloth Presets"
33     preset_subdir = "cloth"
34     preset_operator = "script.execute_preset"
35     draw = Menu.draw_preset
36
37
38 class PhysicButtonsPanel():
39     bl_space_type = 'PROPERTIES'
40     bl_region_type = 'WINDOW'
41     bl_context = "physics"
42
43     @classmethod
44     def poll(cls, context):
45         ob = context.object
46         rd = context.scene.render
47         return (ob and ob.type == 'MESH') and (not rd.use_game_engine) and (context.cloth)
48
49
50 class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
51     bl_label = "Cloth"
52
53     def draw(self, context):
54         layout = self.layout
55
56         md = context.cloth
57         ob = context.object
58         cloth = md.settings
59
60         split = layout.split()
61
62         split.active = cloth_panel_enabled(md)
63
64         col = split.column()
65
66         col.label(text="Presets:")
67         sub = col.row(align=True)
68         sub.menu("CLOTH_MT_presets", text=bpy.types.CLOTH_MT_presets.bl_label)
69         sub.operator("cloth.preset_add", text="", icon='ZOOMIN')
70         sub.operator("cloth.preset_add", text="", icon='ZOOMOUT').remove_active = True
71
72         col.label(text="Quality:")
73         col.prop(cloth, "quality", text="Steps", slider=True)
74
75         col.label(text="Material:")
76         col.prop(cloth, "mass")
77         col.prop(cloth, "structural_stiffness", text="Structural")
78         col.prop(cloth, "bending_stiffness", text="Bending")
79
80         col = split.column()
81
82         col.label(text="Damping:")
83         col.prop(cloth, "spring_damping", text="Spring")
84         col.prop(cloth, "air_damping", text="Air")
85         col.prop(cloth, "vel_damping", text="Velocity")
86
87         col.prop(cloth, "use_pin_cloth", text="Pinning")
88         sub = col.column()
89         sub.active = cloth.use_pin_cloth
90         sub.prop_search(cloth, "vertex_group_mass", ob, "vertex_groups", text="")
91         sub.prop(cloth, "pin_stiffness", text="Stiffness")
92
93         col.label(text="Pre roll:")
94         col.prop(cloth, "pre_roll", text="Frames")
95
96         # Disabled for now
97         """
98         if cloth.vertex_group_mass:
99             layout.label(text="Goal:")
100
101             col = layout.column_flow()
102             col.prop(cloth, "goal_default", text="Default")
103             col.prop(cloth, "goal_spring", text="Stiffness")
104             col.prop(cloth, "goal_friction", text="Friction")
105         """
106
107         key = ob.data.shape_keys
108
109         if key:
110             col.label(text="Rest Shape Key:")
111             col.prop_search(cloth, "rest_shape_key", key, "key_blocks", text="")
112
113
114 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel, Panel):
115     bl_label = "Cloth Cache"
116     bl_options = {'DEFAULT_CLOSED'}
117
118     def draw(self, context):
119         md = context.cloth
120         point_cache_ui(self, context, md.point_cache, cloth_panel_enabled(md), 'CLOTH')
121
122
123 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
124     bl_label = "Cloth Collision"
125     bl_options = {'DEFAULT_CLOSED'}
126
127     def draw_header(self, context):
128         cloth = context.cloth.collision_settings
129
130         self.layout.active = cloth_panel_enabled(context.cloth)
131         self.layout.prop(cloth, "use_collision", text="")
132
133     def draw(self, context):
134         layout = self.layout
135
136         cloth = context.cloth.collision_settings
137         md = context.cloth
138         ob = context.object
139
140         layout.active = cloth.use_collision and cloth_panel_enabled(md)
141
142         split = layout.split()
143
144         col = split.column()
145         col.prop(cloth, "collision_quality", slider=True, text="Quality")
146         col.prop(cloth, "distance_min", slider=True, text="Distance")
147         col.prop(cloth, "repel_force", slider=True, text="Repel")
148         col.prop(cloth, "distance_repel", slider=True, text="Repel Distance")
149         col.prop(cloth, "friction")
150
151         col = split.column()
152         col.prop(cloth, "use_self_collision", text="Self Collision")
153         sub = col.column()
154         sub.active = cloth.use_self_collision
155         sub.prop(cloth, "self_collision_quality", slider=True, text="Quality")
156         sub.prop(cloth, "self_distance_min", slider=True, text="Distance")
157         sub.prop_search(cloth, "vertex_group_self_collisions", ob, "vertex_groups", text="")
158
159         layout.prop(cloth, "group")
160
161
162 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, Panel):
163     bl_label = "Cloth Stiffness Scaling"
164     bl_options = {'DEFAULT_CLOSED'}
165
166     def draw_header(self, context):
167         cloth = context.cloth.settings
168
169         self.layout.active = cloth_panel_enabled(context.cloth)
170         self.layout.prop(cloth, "use_stiffness_scale", text="")
171
172     def draw(self, context):
173         layout = self.layout
174
175         md = context.cloth
176         ob = context.object
177         cloth = context.cloth.settings
178
179         layout.active = (cloth.use_stiffness_scale and cloth_panel_enabled(md))
180
181         split = layout.split()
182
183         col = split.column()
184         col.label(text="Structural Stiffness:")
185         col.prop_search(cloth, "vertex_group_structural_stiffness", ob, "vertex_groups", text="")
186         col.prop(cloth, "structural_stiffness_max", text="Max")
187
188         col = split.column()
189         col.label(text="Bending Stiffness:")
190         col.prop_search(cloth, "vertex_group_bending", ob, "vertex_groups", text="")
191         col.prop(cloth, "bending_stiffness_max", text="Max")
192
193
194 class PHYSICS_PT_cloth_sewing(PhysicButtonsPanel, Panel):
195     bl_label = "Cloth Sewing Springs"
196     bl_options = {'DEFAULT_CLOSED'}
197
198     def draw_header(self, context):
199         cloth = context.cloth.settings
200
201         self.layout.active = cloth_panel_enabled(context.cloth)
202         self.layout.prop(cloth, "use_sewing_springs", text="")
203
204     def draw(self, context):
205         layout = self.layout
206
207         md = context.cloth
208         ob = context.object
209         cloth = context.cloth.settings
210
211         layout.active = (cloth.use_sewing_springs and cloth_panel_enabled(md))
212
213         layout.prop(cloth, "sewing_force_max", text="Sewing Force")
214
215         split = layout.split()
216
217         col = split.column(align=True)
218         col.label(text="Shrinking:")
219         col.prop_search(cloth, "vertex_group_shrink", ob, "vertex_groups", text="")
220
221         col = split.column(align=True)
222         col.label()
223         col.prop(cloth, "shrink_min", text="Min")
224         col.prop(cloth, "shrink_max", text="Max")
225
226
227 class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel, Panel):
228     bl_label = "Cloth Field Weights"
229     bl_options = {'DEFAULT_CLOSED'}
230
231     def draw(self, context):
232         cloth = context.cloth.settings
233         effector_weights_ui(self, context, cloth.effector_weights, 'CLOTH')
234
235 if __name__ == "__main__":  # only for live edit.
236     bpy.utils.register_module(__name__)