svn merge ^/trunk/blender -r45364:HEAD --accept postpone
[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     @classmethod
76     def poll(cls, context):
77         return context.soft_body
78
79     def draw(self, context):
80         md = context.soft_body
81         point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY')
82
83
84 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, Panel):
85     bl_label = "Soft Body Goal"
86     bl_options = {'DEFAULT_CLOSED'}
87
88     @classmethod
89     def poll(cls, context):
90         return context.soft_body
91
92     def draw_header(self, context):
93         softbody = context.soft_body.settings
94
95         self.layout.active = softbody_panel_enabled(context.soft_body)
96         self.layout.prop(softbody, "use_goal", text="")
97
98     def draw(self, context):
99         layout = self.layout
100
101         md = context.soft_body
102         softbody = md.settings
103         ob = context.object
104
105         layout.active = softbody.use_goal and softbody_panel_enabled(md)
106
107         split = layout.split()
108
109         # Goal
110         split = layout.split()
111
112         col = split.column()
113         col.label(text="Goal Strengths:")
114         col.prop(softbody, "goal_default", text="Default")
115         sub = col.column(align=True)
116         sub.prop(softbody, "goal_min", text="Minimum")
117         sub.prop(softbody, "goal_max", text="Maximum")
118
119         col = split.column()
120         col.label(text="Goal Settings:")
121         col.prop(softbody, "goal_spring", text="Stiffness")
122         col.prop(softbody, "goal_friction", text="Damping")
123
124         layout.prop_search(softbody, "vertex_group_goal", ob, "vertex_groups", text="Vertex Group")
125
126
127 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, Panel):
128     bl_label = "Soft Body Edges"
129     bl_options = {'DEFAULT_CLOSED'}
130
131     @classmethod
132     def poll(cls, context):
133         return context.soft_body
134
135     def draw_header(self, context):
136         softbody = context.soft_body.settings
137
138         self.layout.active = softbody_panel_enabled(context.soft_body)
139         self.layout.prop(softbody, "use_edges", text="")
140
141     def draw(self, context):
142         layout = self.layout
143
144         md = context.soft_body
145         softbody = md.settings
146         ob = context.object
147
148         layout.active = softbody.use_edges and softbody_panel_enabled(md)
149
150         split = layout.split()
151
152         col = split.column()
153         col.label(text="Springs:")
154         col.prop(softbody, "pull")
155         col.prop(softbody, "push")
156         col.prop(softbody, "damping")
157         col.prop(softbody, "plastic")
158         col.prop(softbody, "bend")
159         col.prop(softbody, "spring_length", text="Length")
160         col.prop_search(softbody, "vertex_group_spring", ob, "vertex_groups", text="Springs:")
161
162         col = split.column()
163         col.prop(softbody, "use_stiff_quads")
164         sub = col.column()
165         sub.active = softbody.use_stiff_quads
166         sub.prop(softbody, "shear")
167
168         col.label(text="Aerodynamics:")
169         col.row().prop(softbody, "aerodynamics_type", expand=True)
170         col.prop(softbody, "aero", text="Factor")
171
172         #sub = col.column()
173         #sub.enabled = softbody.aero > 0
174
175         col.label(text="Collision:")
176         col.prop(softbody, "use_edge_collision", text="Edge")
177         col.prop(softbody, "use_face_collision", text="Face")
178
179
180 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel):
181     bl_label = "Soft Body Self Collision"
182     bl_options = {'DEFAULT_CLOSED'}
183
184     @classmethod
185     def poll(cls, context):
186         return context.soft_body
187
188     def draw_header(self, context):
189         softbody = context.soft_body.settings
190
191         self.layout.active = softbody_panel_enabled(context.soft_body)
192         self.layout.prop(softbody, "use_self_collision", text="")
193
194     def draw(self, context):
195         layout = self.layout
196
197         md = context.soft_body
198         softbody = md.settings
199
200         layout.active = softbody.use_self_collision and softbody_panel_enabled(md)
201
202         layout.label(text="Collision Ball Size Calculation:")
203         layout.prop(softbody, "collision_type", expand=True)
204
205         col = layout.column(align=True)
206         col.label(text="Ball:")
207         col.prop(softbody, "ball_size", text="Size")
208         col.prop(softbody, "ball_stiff", text="Stiffness")
209         col.prop(softbody, "ball_damp", text="Dampening")
210
211
212 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel):
213     bl_label = "Soft Body Solver"
214     bl_options = {'DEFAULT_CLOSED'}
215
216     @classmethod
217     def poll(cls, context):
218         return context.soft_body
219
220     def draw(self, context):
221         layout = self.layout
222
223         md = context.soft_body
224         softbody = md.settings
225
226         layout.active = softbody_panel_enabled(md)
227
228         # Solver
229         split = layout.split()
230
231         col = split.column(align=True)
232         col.label(text="Step Size:")
233         col.prop(softbody, "step_min")
234         col.prop(softbody, "step_max")
235         col.prop(softbody, "use_auto_step", text="Auto-Step")
236
237         col = split.column()
238         col.prop(softbody, "error_threshold")
239         col.label(text="Helpers:")
240         col.prop(softbody, "choke")
241         col.prop(softbody, "fuzzy")
242
243         layout.label(text="Diagnostics:")
244         layout.prop(softbody, "use_diagnose")
245         layout.prop(softbody, "use_estimate_matrix")
246
247
248 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, Panel):
249     bl_label = "Soft Body Field Weights"
250     bl_options = {'DEFAULT_CLOSED'}
251
252     @classmethod
253     def poll(cls, context):
254         return (context.soft_body)
255
256     def draw(self, context):
257         md = context.soft_body
258         softbody = md.settings
259
260         effector_weights_ui(self, context, softbody.effector_weights)
261
262 if __name__ == "__main__":  # only for live edit.
263     bpy.utils.register_module(__name__)