Workspace: Move engines to workspace and Properties Editor cleanup
[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 COMPAT_OB_TYPES = {'MESH', 'LATTICE', 'CURVE', 'SURFACE', 'FONT'}
30
31
32 def softbody_panel_enabled(md):
33     return (md.point_cache.is_baked is False)
34
35
36 class PhysicButtonsPanel:
37     bl_space_type = 'PROPERTIES'
38     bl_region_type = 'WINDOW'
39     bl_context = "physics"
40
41     @classmethod
42     def poll(cls, context):
43         ob = context.object
44         view_render = context.scene.view_render
45         return ob and ob.type in COMPAT_OB_TYPES and view_render.engine in cls.COMPAT_ENGINES and context.soft_body
46
47
48 class PHYSICS_PT_softbody(PhysicButtonsPanel, Panel):
49     bl_label = "Soft Body"
50     COMPAT_ENGINES = {'BLENDER_RENDER'}
51
52     def draw(self, context):
53         layout = self.layout
54
55         md = context.soft_body
56         ob = context.object
57
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         layout.prop(softbody, "collision_group")
75
76
77 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, Panel):
78     bl_label = "Soft Body Cache"
79     bl_options = {'DEFAULT_CLOSED'}
80     COMPAT_ENGINES = {'BLENDER_RENDER'}
81
82     def draw(self, context):
83         md = context.soft_body
84         point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY')
85
86
87 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, Panel):
88     bl_label = "Soft Body Goal"
89     bl_options = {'DEFAULT_CLOSED'}
90     COMPAT_ENGINES = {'BLENDER_RENDER'}
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     COMPAT_ENGINES = {'BLENDER_RENDER'}
131
132     def draw_header(self, context):
133         softbody = context.soft_body.settings
134
135         self.layout.active = softbody_panel_enabled(context.soft_body)
136         self.layout.prop(softbody, "use_edges", text="")
137
138     def draw(self, context):
139         layout = self.layout
140
141         md = context.soft_body
142         softbody = md.settings
143         ob = context.object
144
145         layout.active = softbody.use_edges and softbody_panel_enabled(md)
146
147         split = layout.split()
148
149         col = split.column()
150         col.label(text="Springs:")
151         col.prop(softbody, "pull")
152         col.prop(softbody, "push")
153         col.prop(softbody, "damping")
154         col.prop(softbody, "plastic")
155         col.prop(softbody, "bend")
156         col.prop(softbody, "spring_length", text="Length")
157         col.prop_search(softbody, "vertex_group_spring", ob, "vertex_groups", text="Springs")
158
159         col = split.column()
160         col.prop(softbody, "use_stiff_quads")
161         sub = col.column()
162         sub.active = softbody.use_stiff_quads
163         sub.prop(softbody, "shear")
164
165         col.label(text="Aerodynamics:")
166         col.row().prop(softbody, "aerodynamics_type", expand=True)
167         col.prop(softbody, "aero", text="Factor")
168
169         #sub = col.column()
170         #sub.enabled = softbody.aero > 0
171
172         col.label(text="Collision:")
173         col.prop(softbody, "use_edge_collision", text="Edge")
174         col.prop(softbody, "use_face_collision", text="Face")
175
176
177 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel):
178     bl_label = "Soft Body Self Collision"
179     bl_options = {'DEFAULT_CLOSED'}
180     COMPAT_ENGINES = {'BLENDER_RENDER'}
181
182     def draw_header(self, context):
183         softbody = context.soft_body.settings
184
185         self.layout.active = softbody_panel_enabled(context.soft_body)
186         self.layout.prop(softbody, "use_self_collision", text="")
187
188     def draw(self, context):
189         layout = self.layout
190
191         md = context.soft_body
192         softbody = md.settings
193
194         layout.active = softbody.use_self_collision and softbody_panel_enabled(md)
195
196         layout.label(text="Collision Ball Size Calculation:")
197         layout.row().prop(softbody, "collision_type", expand=True)
198
199         col = layout.column(align=True)
200         col.label(text="Ball:")
201         col.prop(softbody, "ball_size", text="Size")
202         col.prop(softbody, "ball_stiff", text="Stiffness")
203         col.prop(softbody, "ball_damp", text="Dampening")
204
205
206 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel):
207     bl_label = "Soft Body Solver"
208     bl_options = {'DEFAULT_CLOSED'}
209     COMPAT_ENGINES = {'BLENDER_RENDER'}
210
211     def draw(self, context):
212         layout = self.layout
213
214         md = context.soft_body
215         softbody = md.settings
216
217         layout.active = softbody_panel_enabled(md)
218
219         # Solver
220         split = layout.split()
221
222         col = split.column(align=True)
223         col.label(text="Step Size:")
224         col.prop(softbody, "step_min")
225         col.prop(softbody, "step_max")
226         col.prop(softbody, "use_auto_step", text="Auto-Step")
227
228         col = split.column()
229         col.prop(softbody, "error_threshold")
230         col.label(text="Helpers:")
231         col.prop(softbody, "choke")
232         col.prop(softbody, "fuzzy")
233
234         layout.label(text="Diagnostics:")
235         layout.prop(softbody, "use_diagnose")
236         layout.prop(softbody, "use_estimate_matrix")
237
238
239 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, Panel):
240     bl_label = "Soft Body Field Weights"
241     bl_options = {'DEFAULT_CLOSED'}
242     COMPAT_ENGINES = {'BLENDER_RENDER'}
243
244     def draw(self, context):
245         md = context.soft_body
246         softbody = md.settings
247
248         effector_weights_ui(self, context, softbody.effector_weights, 'SOFTBODY')
249
250
251 classes = (
252     PHYSICS_PT_softbody,
253     PHYSICS_PT_softbody_cache,
254     PHYSICS_PT_softbody_goal,
255     PHYSICS_PT_softbody_edge,
256     PHYSICS_PT_softbody_collision,
257     PHYSICS_PT_softbody_solver,
258     PHYSICS_PT_softbody_field_weights,
259 )
260
261 if __name__ == "__main__":  # only for live edit.
262     from bpy.utils import register_class
263     for cls in classes:
264         register_class(cls)