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