fix [#26754] Live Edit and Editing UI scripts don't work
[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
22
23 from bl_ui.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(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():
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, bpy.types.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
64         if md:
65             cloth = md.settings
66
67             split = layout.split()
68
69             split.active = cloth_panel_enabled(md)
70
71             col = split.column()
72
73             col.label(text="Presets:")
74             sub = col.row(align=True)
75             sub.menu("CLOTH_MT_presets", text=bpy.types.CLOTH_MT_presets.bl_label)
76             sub.operator("cloth.preset_add", text="", icon="ZOOMIN")
77             sub.operator("cloth.preset_add", text="", icon="ZOOMOUT").remove_active = True
78
79             col.label(text="Quality:")
80             col.prop(cloth, "quality", text="Steps", slider=True)
81
82             col.label(text="Material:")
83             col.prop(cloth, "mass")
84             col.prop(cloth, "structural_stiffness", text="Structural")
85             col.prop(cloth, "bending_stiffness", text="Bending")
86
87             col = split.column()
88
89             col.label(text="Damping:")
90             col.prop(cloth, "spring_damping", text="Spring")
91             col.prop(cloth, "air_damping", text="Air")
92
93             col.prop(cloth, "use_pin_cloth", text="Pinning")
94             sub = col.column()
95             sub.active = cloth.use_pin_cloth
96             sub.prop_search(cloth, "vertex_group_mass", ob, "vertex_groups", text="")
97             sub.prop(cloth, "pin_stiffness", text="Stiffness")
98
99             col.label(text="Pre roll:")
100             col.prop(cloth, "pre_roll", text="Frame")
101
102             # Disabled for now
103             """
104             if cloth.vertex_group_mass:
105                 layout.label(text="Goal:")
106
107                 col = layout.column_flow()
108                 col.prop(cloth, "goal_default", text="Default")
109                 col.prop(cloth, "goal_spring", text="Stiffness")
110                 col.prop(cloth, "goal_friction", text="Friction")
111             """
112
113             key = ob.data.shape_keys
114
115             if key:
116                 col.label(text="Rest Shape Key:")
117                 col.prop_search(cloth, "rest_shape_key", key, "key_blocks", text="")
118
119
120 class PHYSICS_PT_cloth_cache(PhysicButtonsPanel, bpy.types.Panel):
121     bl_label = "Cloth Cache"
122     bl_options = {'DEFAULT_CLOSED'}
123
124     @classmethod
125     def poll(cls, context):
126         return context.cloth
127
128     def draw(self, context):
129         md = context.cloth
130         point_cache_ui(self, context, md.point_cache, cloth_panel_enabled(md), 'CLOTH')
131
132
133 class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, bpy.types.Panel):
134     bl_label = "Cloth Collision"
135     bl_options = {'DEFAULT_CLOSED'}
136
137     @classmethod
138     def poll(cls, context):
139         return context.cloth
140
141     def draw_header(self, context):
142         cloth = context.cloth.collision_settings
143
144         self.layout.active = cloth_panel_enabled(context.cloth)
145         self.layout.prop(cloth, "use_collision", text="")
146
147     def draw(self, context):
148         layout = self.layout
149
150         cloth = context.cloth.collision_settings
151         md = context.cloth
152
153         layout.active = cloth.use_collision and cloth_panel_enabled(md)
154
155         split = layout.split()
156
157         col = split.column()
158         col.prop(cloth, "collision_quality", slider=True, text="Quality")
159         col.prop(cloth, "distance_min", slider=True, text="Distance")
160         col.prop(cloth, "friction")
161
162         col = split.column()
163         col.prop(cloth, "use_self_collision", text="Self Collision")
164         sub = col.column()
165         sub.active = cloth.use_self_collision
166         sub.prop(cloth, "self_collision_quality", slider=True, text="Quality")
167         sub.prop(cloth, "self_distance_min", slider=True, text="Distance")
168
169         layout.prop(cloth, "group")
170
171
172 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, bpy.types.Panel):
173     bl_label = "Cloth Stiffness Scaling"
174     bl_options = {'DEFAULT_CLOSED'}
175
176     @classmethod
177     def poll(cls, context):
178         return context.cloth
179
180     def draw_header(self, context):
181         cloth = context.cloth.settings
182
183         self.layout.active = cloth_panel_enabled(context.cloth)
184         self.layout.prop(cloth, "use_stiffness_scale", text="")
185
186     def draw(self, context):
187         layout = self.layout
188
189         md = context.cloth
190         ob = context.object
191         cloth = context.cloth.settings
192
193         layout.active = cloth.use_stiffness_scale       and cloth_panel_enabled(md)
194
195         split = layout.split()
196
197         col = split.column()
198         col.label(text="Structural Stiffness:")
199         col.prop_search(cloth, "vertex_group_structural_stiffness", ob, "vertex_groups", text="")
200         col.prop(cloth, "structural_stiffness_max", text="Max")
201
202         col = split.column()
203         col.label(text="Bending Stiffness:")
204         col.prop_search(cloth, "vertex_group_bending", ob, "vertex_groups", text="")
205         col.prop(cloth, "bending_stiffness_max", text="Max")
206
207
208 class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel, bpy.types.Panel):
209     bl_label = "Cloth Field Weights"
210     bl_options = {'DEFAULT_CLOSED'}
211
212     @classmethod
213     def poll(cls, context):
214         return (context.cloth)
215
216     def draw(self, context):
217         cloth = context.cloth.settings
218         effector_weights_ui(self, context, cloth.effector_weights)
219
220 if __name__ == "__main__":  # only for live edit.
221     bpy.utils.register_module(__name__)