Merge branch 'master' into blender2.8
[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         effector_weights_ui,
25         )
26
27
28 def softbody_panel_enabled(md):
29     return True
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_goal(PhysicButtonsPanel, Panel):
75     bl_label = "Soft Body Goal"
76     bl_options = {'DEFAULT_CLOSED'}
77     COMPAT_ENGINES = {'BLENDER_RENDER'}
78
79     def draw_header(self, context):
80         softbody = context.soft_body.settings
81
82         self.layout.active = softbody_panel_enabled(context.soft_body)
83         self.layout.prop(softbody, "use_goal", text="")
84
85     def draw(self, context):
86         layout = self.layout
87
88         md = context.soft_body
89         softbody = md.settings
90         ob = context.object
91
92         layout.active = softbody.use_goal and softbody_panel_enabled(md)
93
94         split = layout.split()
95
96         # Goal
97         split = layout.split()
98
99         col = split.column()
100         col.label(text="Goal Strengths:")
101         col.prop(softbody, "goal_default", text="Default")
102         sub = col.column(align=True)
103         sub.prop(softbody, "goal_min", text="Minimum")
104         sub.prop(softbody, "goal_max", text="Maximum")
105
106         col = split.column()
107         col.label(text="Goal Settings:")
108         col.prop(softbody, "goal_spring", text="Stiffness")
109         col.prop(softbody, "goal_friction", text="Damping")
110
111         layout.prop_search(softbody, "vertex_group_goal", ob, "vertex_groups", text="Vertex Group")
112
113
114 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, Panel):
115     bl_label = "Soft Body Edges"
116     bl_options = {'DEFAULT_CLOSED'}
117     COMPAT_ENGINES = {'BLENDER_RENDER'}
118
119     def draw_header(self, context):
120         softbody = context.soft_body.settings
121
122         self.layout.active = softbody_panel_enabled(context.soft_body)
123         self.layout.prop(softbody, "use_edges", text="")
124
125     def draw(self, context):
126         layout = self.layout
127
128         md = context.soft_body
129         softbody = md.settings
130         ob = context.object
131
132         layout.active = softbody.use_edges and softbody_panel_enabled(md)
133
134         split = layout.split()
135
136         col = split.column()
137         col.label(text="Springs:")
138         col.prop(softbody, "pull")
139         col.prop(softbody, "push")
140         col.prop(softbody, "damping")
141         col.prop(softbody, "plastic")
142         col.prop(softbody, "bend")
143         col.prop(softbody, "spring_length", text="Length")
144         col.prop_search(softbody, "vertex_group_spring", ob, "vertex_groups", text="Springs")
145
146         col = split.column()
147         col.prop(softbody, "use_stiff_quads")
148         sub = col.column()
149         sub.active = softbody.use_stiff_quads
150         sub.prop(softbody, "shear")
151
152         col.label(text="Aerodynamics:")
153         col.row().prop(softbody, "aerodynamics_type", expand=True)
154         col.prop(softbody, "aero", text="Factor")
155
156         #sub = col.column()
157         #sub.enabled = softbody.aero > 0
158
159         col.label(text="Collision:")
160         col.prop(softbody, "use_edge_collision", text="Edge")
161         col.prop(softbody, "use_face_collision", text="Face")
162
163
164 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel):
165     bl_label = "Soft Body Self Collision"
166     bl_options = {'DEFAULT_CLOSED'}
167     COMPAT_ENGINES = {'BLENDER_RENDER'}
168
169     def draw_header(self, context):
170         softbody = context.soft_body.settings
171
172         self.layout.active = softbody_panel_enabled(context.soft_body)
173         self.layout.prop(softbody, "use_self_collision", text="")
174
175     def draw(self, context):
176         layout = self.layout
177
178         md = context.soft_body
179         softbody = md.settings
180
181         layout.active = softbody.use_self_collision and softbody_panel_enabled(md)
182
183         layout.label(text="Collision Ball Size Calculation:")
184         layout.prop(softbody, "collision_type", expand=True)
185
186         col = layout.column(align=True)
187         col.label(text="Ball:")
188         col.prop(softbody, "ball_size", text="Size")
189         col.prop(softbody, "ball_stiff", text="Stiffness")
190         col.prop(softbody, "ball_damp", text="Dampening")
191
192
193 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel):
194     bl_label = "Soft Body Solver"
195     bl_options = {'DEFAULT_CLOSED'}
196     COMPAT_ENGINES = {'BLENDER_RENDER'}
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     COMPAT_ENGINES = {'BLENDER_RENDER'}
230
231     def draw(self, context):
232         md = context.soft_body
233         softbody = md.settings
234
235         effector_weights_ui(self, context, softbody.effector_weights, 'SOFTBODY')
236
237 if __name__ == "__main__":  # only for live edit.
238     bpy.utils.register_module(__name__)