8a770066b0b3ab2ec985436dcff7830605a1307f
[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
23 from properties_physics_common import point_cache_ui
24 from properties_physics_common import 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(bpy.types.Menu):
32     '''
33     Creates the menu items by scanning scripts/templates
34     '''
35     bl_label = "Cloth Presets"
36     preset_subdir = "cloth"
37     preset_operator = "script.execute_preset"
38     draw = bpy.types.Menu.draw_preset
39
40
41 class PhysicButtonsPanel():
42     bl_space_type = 'PROPERTIES'
43     bl_region_type = 'WINDOW'
44     bl_context = "physics"
45
46     @classmethod
47     def poll(cls, context):
48         ob = context.object
49         rd = context.scene.render
50         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
51
52
53 class PHYSICS_PT_cloth(PhysicButtonsPanel, bpy.types.Panel):
54     bl_label = "Cloth"
55
56     def draw(self, context):
57         layout = self.layout
58
59         md = context.cloth
60         ob = context.object
61
62         split = layout.split()
63
64         if md:
65             # remove modifier + settings
66             split.set_context_pointer("modifier", md)
67             split.operator("object.modifier_remove", text="Remove")
68
69             row = split.row(align=True)
70             row.prop(md, "show_render", text="")
71             row.prop(md, "show_viewport", text="")
72         else:
73             # add modifier
74             split.operator("object.modifier_add", text="Add").type = 'CLOTH'
75             split.label()
76
77         if md:
78             cloth = md.settings
79
80             split = layout.split()
81
82             split.active = cloth_panel_enabled(md)
83
84             col = split.column()
85
86             col.label(text="Presets:")
87             sub = col.row(align=True)
88             sub.menu("CLOTH_MT_presets", text=bpy.types.CLOTH_MT_presets.bl_label)
89             sub.operator("cloth.preset_add", text="", icon="ZOOMIN")
90
91             col.label(text="Quality:")
92             col.prop(cloth, "quality", text="Steps", slider=True)
93
94             col.label(text="Material:")
95             col.prop(cloth, "mass")
96             col.prop(cloth, "structural_stiffness", text="Structural")
97             col.prop(cloth, "bending_stiffness", text="Bending")
98
99             col = split.column()
100
101             col.label(text="Damping:")
102             col.prop(cloth, "spring_damping", text="Spring")
103             col.prop(cloth, "air_damping", text="Air")
104
105             col.prop(cloth, "pin_cloth", text="Pinning")
106             sub = col.column()
107             sub.active = cloth.pin_cloth
108             sub.prop_object(cloth, "mass_vertex_group", ob, "vertex_groups", text="")
109             sub.prop(cloth, "pin_stiffness", text="Stiffness")
110
111             col.label(text="Pre roll:")
112             col.prop(cloth, "pre_roll", text="Frame")
113
114             # Disabled for now
115             """
116             if cloth.mass_vertex_group:
117                 layout.label(text="Goal:")
118
119                 col = layout.column_flow()
120                 col.prop(cloth, "goal_default", text="Default")
121                 col.prop(cloth, "goal_spring", text="Stiffness")
122                 col.prop(cloth, "goal_friction", text="Friction")
123             """
124
125             key = ob.data.shape_keys
126
127             if key:
128                 col.label(text="Rest Shape Key:")
129                 col.prop_object(cloth, "rest_shape_key", key, "keys", text="")
130
131
132 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel, bpy.types.Panel):
133     bl_label = "Cloth Cache"
134     bl_default_closed = True
135
136     @classmethod
137     def poll(cls, 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), 'CLOTH')
143
144
145 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, bpy.types.Panel):
146     bl_label = "Cloth Collision"
147     bl_default_closed = True
148
149     @classmethod
150     def poll(cls, context):
151         return context.cloth
152
153     def draw_header(self, context):
154         cloth = context.cloth.collision_settings
155
156         self.layout.active = cloth_panel_enabled(context.cloth)
157         self.layout.prop(cloth, "enable_collision", text="")
158
159     def draw(self, context):
160         layout = self.layout
161
162         cloth = context.cloth.collision_settings
163         md = context.cloth
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         col = split.column()
175         col.prop(cloth, "enable_self_collision", text="Self Collision")
176         sub = col.column()
177         sub.active = cloth.enable_self_collision
178         sub.prop(cloth, "self_collision_quality", slider=True, text="Quality")
179         sub.prop(cloth, "self_min_distance", slider=True, text="Distance")
180
181         layout.prop(cloth, "group")
182
183
184 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, bpy.types.Panel):
185     bl_label = "Cloth Stiffness Scaling"
186     bl_default_closed = True
187
188     @classmethod
189     def poll(cls, context):
190         return context.cloth
191
192     def draw_header(self, context):
193         cloth = context.cloth.settings
194
195         self.layout.active = cloth_panel_enabled(context.cloth)
196         self.layout.prop(cloth, "stiffness_scaling", text="")
197
198     def draw(self, context):
199         layout = self.layout
200
201         md = context.cloth
202         ob = context.object
203         cloth = context.cloth.settings
204
205         layout.active = cloth.stiffness_scaling and cloth_panel_enabled(md)
206
207         split = layout.split()
208
209         col = split.column()
210         col.label(text="Structural Stiffness:")
211         col.prop_object(cloth, "structural_stiffness_vertex_group", ob, "vertex_groups", text="")
212         col.prop(cloth, "structural_stiffness_max", text="Max")
213
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, bpy.types.Panel):
221     bl_label = "Cloth Field Weights"
222     bl_default_closed = True
223
224     @classmethod
225     def poll(cls, context):
226         return (context.cloth)
227
228     def draw(self, context):
229         cloth = context.cloth.settings
230         effector_weights_ui(self, context, cloth.effector_weights)
231
232
233 def register():
234     pass
235
236
237 def unregister():
238     pass
239
240 if __name__ == "__main__":
241     register()