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