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