cleanup: pep8
[blender.git] / release / scripts / startup / bl_ui / properties_physics_softbody.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 Panel
22
23 from bl_ui.properties_physics_common import (
24         point_cache_ui,
25         effector_weights_ui,
26         )
27
28
29 def softbody_panel_enabled(md):
30     return (md.point_cache.is_baked is False)
31
32
33 class PhysicButtonsPanel:
34     bl_space_type = 'PROPERTIES'
35     bl_region_type = 'WINDOW'
36     bl_context = "physics"
37
38     @classmethod
39     def poll(cls, context):
40         ob = context.object
41         rd = context.scene.render
42         return (ob and (ob.type == 'MESH' or ob.type == 'LATTICE'or ob.type == 'CURVE')) and (not rd.use_game_engine) and (context.soft_body)
43
44
45 class PHYSICS_PT_softbody(PhysicButtonsPanel, Panel):
46     bl_label = "Soft Body"
47
48     def draw(self, context):
49         layout = self.layout
50
51         md = context.soft_body
52         ob = context.object
53
54         softbody = md.settings
55
56         # General
57         split = layout.split()
58         split.enabled = softbody_panel_enabled(md)
59
60         col = split.column()
61         col.label(text="Object:")
62         col.prop(softbody, "friction")
63         col.prop(softbody, "mass")
64         col.prop_search(softbody, "vertex_group_mass", ob, "vertex_groups", text="Mass")
65
66         col = split.column()
67         col.label(text="Simulation:")
68         col.prop(softbody, "speed")
69
70
71 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, Panel):
72     bl_label = "Soft Body Cache"
73     bl_options = {'DEFAULT_CLOSED'}
74
75     def draw(self, context):
76         md = context.soft_body
77         point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY')
78
79
80 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, Panel):
81     bl_label = "Soft Body Goal"
82     bl_options = {'DEFAULT_CLOSED'}
83
84     def draw_header(self, context):
85         softbody = context.soft_body.settings
86
87         self.layout.active = softbody_panel_enabled(context.soft_body)
88         self.layout.prop(softbody, "use_goal", text="")
89
90     def draw(self, context):
91         layout = self.layout
92
93         md = context.soft_body
94         softbody = md.settings
95         ob = context.object
96
97         layout.active = softbody.use_goal and softbody_panel_enabled(md)
98
99         split = layout.split()
100
101         # Goal
102         split = layout.split()
103
104         col = split.column()
105         col.label(text="Goal Strengths:")
106         col.prop(softbody, "goal_default", text="Default")
107         sub = col.column(align=True)
108         sub.prop(softbody, "goal_min", text="Minimum")
109         sub.prop(softbody, "goal_max", text="Maximum")
110
111         col = split.column()
112         col.label(text="Goal Settings:")
113         col.prop(softbody, "goal_spring", text="Stiffness")
114         col.prop(softbody, "goal_friction", text="Damping")
115
116         layout.prop_search(softbody, "vertex_group_goal", ob, "vertex_groups", text="Vertex Group")
117
118
119 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, Panel):
120     bl_label = "Soft Body Edges"
121     bl_options = {'DEFAULT_CLOSED'}
122
123     def draw_header(self, context):
124         softbody = context.soft_body.settings
125
126         self.layout.active = softbody_panel_enabled(context.soft_body)
127         self.layout.prop(softbody, "use_edges", text="")
128
129     def draw(self, context):
130         layout = self.layout
131
132         md = context.soft_body
133         softbody = md.settings
134         ob = context.object
135
136         layout.active = softbody.use_edges and softbody_panel_enabled(md)
137
138         split = layout.split()
139
140         col = split.column()
141         col.label(text="Springs:")
142         col.prop(softbody, "pull")
143         col.prop(softbody, "push")
144         col.prop(softbody, "damping")
145         col.prop(softbody, "plastic")
146         col.prop(softbody, "bend")
147         col.prop(softbody, "spring_length", text="Length")
148         col.prop_search(softbody, "vertex_group_spring", ob, "vertex_groups", text="Springs")
149
150         col = split.column()
151         col.prop(softbody, "use_stiff_quads")
152         sub = col.column()
153         sub.active = softbody.use_stiff_quads
154         sub.prop(softbody, "shear")
155
156         col.label(text="Aerodynamics:")
157         col.row().prop(softbody, "aerodynamics_type", expand=True)
158         col.prop(softbody, "aero", text="Factor")
159
160         #sub = col.column()
161         #sub.enabled = softbody.aero > 0
162
163         col.label(text="Collision:")
164         col.prop(softbody, "use_edge_collision", text="Edge")
165         col.prop(softbody, "use_face_collision", text="Face")
166
167
168 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel):
169     bl_label = "Soft Body Self Collision"
170     bl_options = {'DEFAULT_CLOSED'}
171
172     def draw_header(self, context):
173         softbody = context.soft_body.settings
174
175         self.layout.active = softbody_panel_enabled(context.soft_body)
176         self.layout.prop(softbody, "use_self_collision", text="")
177
178     def draw(self, context):
179         layout = self.layout
180
181         md = context.soft_body
182         softbody = md.settings
183
184         layout.active = softbody.use_self_collision and softbody_panel_enabled(md)
185
186         layout.label(text="Collision Ball Size Calculation:")
187         layout.prop(softbody, "collision_type", expand=True)
188
189         col = layout.column(align=True)
190         col.label(text="Ball:")
191         col.prop(softbody, "ball_size", text="Size")
192         col.prop(softbody, "ball_stiff", text="Stiffness")
193         col.prop(softbody, "ball_damp", text="Dampening")
194
195
196 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel):
197     bl_label = "Soft Body Solver"
198     bl_options = {'DEFAULT_CLOSED'}
199
200     def draw(self, context):
201         layout = self.layout
202
203         md = context.soft_body
204         softbody = md.settings
205
206         layout.active = softbody_panel_enabled(md)
207
208         # Solver
209         split = layout.split()
210
211         col = split.column(align=True)
212         col.label(text="Step Size:")
213         col.prop(softbody, "step_min")
214         col.prop(softbody, "step_max")
215         col.prop(softbody, "use_auto_step", text="Auto-Step")
216
217         col = split.column()
218         col.prop(softbody, "error_threshold")
219         col.label(text="Helpers:")
220         col.prop(softbody, "choke")
221         col.prop(softbody, "fuzzy")
222
223         layout.label(text="Diagnostics:")
224         layout.prop(softbody, "use_diagnose")
225         layout.prop(softbody, "use_estimate_matrix")
226
227
228 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, Panel):
229     bl_label = "Soft Body Field Weights"
230     bl_options = {'DEFAULT_CLOSED'}
231
232     def draw(self, context):
233         md = context.soft_body
234         softbody = md.settings
235
236         effector_weights_ui(self, context, softbody.effector_weights, 'SOFTBODY')
237
238 if __name__ == "__main__":  # only for live edit.
239     bpy.utils.register_module(__name__)