Moving classes to separate listing broke panel order
[blender-staging.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 (rd.engine in cls.COMPAT_ENGINES) and (context.soft_body)
43
44
45 class PHYSICS_PT_softbody(PhysicButtonsPanel, Panel):
46     bl_label = "Soft Body"
47     COMPAT_ENGINES = {'BLENDER_RENDER'}
48
49     def draw(self, context):
50         layout = self.layout
51
52         md = context.soft_body
53         ob = context.object
54
55         softbody = md.settings
56
57         # General
58         split = layout.split()
59         split.enabled = softbody_panel_enabled(md)
60
61         col = split.column()
62         col.label(text="Object:")
63         col.prop(softbody, "friction")
64         col.prop(softbody, "mass")
65         col.prop_search(softbody, "vertex_group_mass", ob, "vertex_groups", text="Mass")
66
67         col = split.column()
68         col.label(text="Simulation:")
69         col.prop(softbody, "speed")
70
71         layout.prop(softbody, "collision_group")
72
73
74 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, Panel):
75     bl_label = "Soft Body Cache"
76     bl_options = {'DEFAULT_CLOSED'}
77     COMPAT_ENGINES = {'BLENDER_RENDER'}
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     COMPAT_ENGINES = {'BLENDER_RENDER'}
88
89     def draw_header(self, context):
90         softbody = context.soft_body.settings
91
92         self.layout.active = softbody_panel_enabled(context.soft_body)
93         self.layout.prop(softbody, "use_goal", text="")
94
95     def draw(self, context):
96         layout = self.layout
97
98         md = context.soft_body
99         softbody = md.settings
100         ob = context.object
101
102         layout.active = softbody.use_goal and softbody_panel_enabled(md)
103
104         split = layout.split()
105
106         # Goal
107         split = layout.split()
108
109         col = split.column()
110         col.label(text="Goal Strengths:")
111         col.prop(softbody, "goal_default", text="Default")
112         sub = col.column(align=True)
113         sub.prop(softbody, "goal_min", text="Minimum")
114         sub.prop(softbody, "goal_max", text="Maximum")
115
116         col = split.column()
117         col.label(text="Goal Settings:")
118         col.prop(softbody, "goal_spring", text="Stiffness")
119         col.prop(softbody, "goal_friction", text="Damping")
120
121         layout.prop_search(softbody, "vertex_group_goal", ob, "vertex_groups", text="Vertex Group")
122
123
124 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, Panel):
125     bl_label = "Soft Body Edges"
126     bl_options = {'DEFAULT_CLOSED'}
127     COMPAT_ENGINES = {'BLENDER_RENDER'}
128
129     def draw_header(self, context):
130         softbody = context.soft_body.settings
131
132         self.layout.active = softbody_panel_enabled(context.soft_body)
133         self.layout.prop(softbody, "use_edges", text="")
134
135     def draw(self, context):
136         layout = self.layout
137
138         md = context.soft_body
139         softbody = md.settings
140         ob = context.object
141
142         layout.active = softbody.use_edges and softbody_panel_enabled(md)
143
144         split = layout.split()
145
146         col = split.column()
147         col.label(text="Springs:")
148         col.prop(softbody, "pull")
149         col.prop(softbody, "push")
150         col.prop(softbody, "damping")
151         col.prop(softbody, "plastic")
152         col.prop(softbody, "bend")
153         col.prop(softbody, "spring_length", text="Length")
154         col.prop_search(softbody, "vertex_group_spring", ob, "vertex_groups", text="Springs")
155
156         col = split.column()
157         col.prop(softbody, "use_stiff_quads")
158         sub = col.column()
159         sub.active = softbody.use_stiff_quads
160         sub.prop(softbody, "shear")
161
162         col.label(text="Aerodynamics:")
163         col.row().prop(softbody, "aerodynamics_type", expand=True)
164         col.prop(softbody, "aero", text="Factor")
165
166         #sub = col.column()
167         #sub.enabled = softbody.aero > 0
168
169         col.label(text="Collision:")
170         col.prop(softbody, "use_edge_collision", text="Edge")
171         col.prop(softbody, "use_face_collision", text="Face")
172
173
174 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel):
175     bl_label = "Soft Body Self Collision"
176     bl_options = {'DEFAULT_CLOSED'}
177     COMPAT_ENGINES = {'BLENDER_RENDER'}
178
179     def draw_header(self, context):
180         softbody = context.soft_body.settings
181
182         self.layout.active = softbody_panel_enabled(context.soft_body)
183         self.layout.prop(softbody, "use_self_collision", text="")
184
185     def draw(self, context):
186         layout = self.layout
187
188         md = context.soft_body
189         softbody = md.settings
190
191         layout.active = softbody.use_self_collision and softbody_panel_enabled(md)
192
193         layout.label(text="Collision Ball Size Calculation:")
194         layout.prop(softbody, "collision_type", expand=True)
195
196         col = layout.column(align=True)
197         col.label(text="Ball:")
198         col.prop(softbody, "ball_size", text="Size")
199         col.prop(softbody, "ball_stiff", text="Stiffness")
200         col.prop(softbody, "ball_damp", text="Dampening")
201
202
203 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel):
204     bl_label = "Soft Body Solver"
205     bl_options = {'DEFAULT_CLOSED'}
206     COMPAT_ENGINES = {'BLENDER_RENDER'}
207
208     def draw(self, context):
209         layout = self.layout
210
211         md = context.soft_body
212         softbody = md.settings
213
214         layout.active = softbody_panel_enabled(md)
215
216         # Solver
217         split = layout.split()
218
219         col = split.column(align=True)
220         col.label(text="Step Size:")
221         col.prop(softbody, "step_min")
222         col.prop(softbody, "step_max")
223         col.prop(softbody, "use_auto_step", text="Auto-Step")
224
225         col = split.column()
226         col.prop(softbody, "error_threshold")
227         col.label(text="Helpers:")
228         col.prop(softbody, "choke")
229         col.prop(softbody, "fuzzy")
230
231         layout.label(text="Diagnostics:")
232         layout.prop(softbody, "use_diagnose")
233         layout.prop(softbody, "use_estimate_matrix")
234
235
236 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, Panel):
237     bl_label = "Soft Body Field Weights"
238     bl_options = {'DEFAULT_CLOSED'}
239     COMPAT_ENGINES = {'BLENDER_RENDER'}
240
241     def draw(self, context):
242         md = context.soft_body
243         softbody = md.settings
244
245         effector_weights_ui(self, context, softbody.effector_weights, 'SOFTBODY')
246
247
248 classes = (
249     PHYSICS_PT_softbody,
250     PHYSICS_PT_softbody_cache,
251     PHYSICS_PT_softbody_goal,
252     PHYSICS_PT_softbody_edge,
253     PHYSICS_PT_softbody_collision,
254     PHYSICS_PT_softbody_solver,
255     PHYSICS_PT_softbody_field_weights,
256 )
257
258 if __name__ == "__main__":  # only for live edit.
259     from bpy.utils import register_class
260     for cls in classes:
261         register_class(cls)