b377f0b6027b29c58a8bc8c25dd36df3fea025d1
[blender-staging.git] / release / scripts / 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
22
23 from properties_physics_common import point_cache_ui
24 from properties_physics_common import 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') and (not rd.use_game_engine)
41 # i really hate touching things i do not understand completely .. but i think this should read (bjornmose)
42         return (ob and (ob.type == 'MESH' or ob.type == 'LATTICE'or ob.type == 'CURVE')) and (not rd.use_game_engine)
43
44
45 class PHYSICS_PT_softbody(PhysicButtonsPanel, bpy.types.Panel):
46     bl_label = "Soft Body"
47
48     def draw(self, context):
49         layout = self.layout
50
51         md = context.soft_body
52         ob = context.object
53
54         split = layout.split()
55
56         if md:
57             # remove modifier + settings
58             split.set_context_pointer("modifier", md)
59             split.operator("object.modifier_remove", text="Remove")
60
61             row = split.row(align=True)
62             row.prop(md, "show_render", text="")
63             row.prop(md, "show_viewport", text="")
64         else:
65             # add modifier
66             split.operator("object.modifier_add", text="Add").type = 'SOFT_BODY'
67             split.column()
68
69         if md:
70             softbody = md.settings
71
72             # General
73             split = layout.split()
74             split.enabled = softbody_panel_enabled(md)
75
76             col = split.column()
77             col.label(text="Object:")
78             col.prop(softbody, "friction")
79             col.prop(softbody, "mass")
80             col.prop_object(softbody, "mass_vertex_group", ob, "vertex_groups", text="Mass:")
81
82             col = split.column()
83             col.label(text="Simulation:")
84             col.prop(softbody, "speed")
85
86
87 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, bpy.types.Panel):
88     bl_label = "Soft Body Cache"
89     bl_default_closed = True
90
91     @classmethod
92     def poll(cls, context):
93         return context.soft_body
94
95     def draw(self, context):
96         md = context.soft_body
97         point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY')
98
99
100 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, bpy.types.Panel):
101     bl_label = "Soft Body Goal"
102     bl_default_closed = True
103
104     @classmethod
105     def poll(cls, context):
106         return context.soft_body
107
108     def draw_header(self, context):
109         softbody = context.soft_body.settings
110
111         self.layout.active = softbody_panel_enabled(context.soft_body)
112         self.layout.prop(softbody, "use_goal", text="")
113
114     def draw(self, context):
115         layout = self.layout
116
117         md = context.soft_body
118         softbody = md.settings
119         ob = context.object
120
121         layout.active = softbody.use_goal and softbody_panel_enabled(md)
122
123         split = layout.split()
124
125         # Goal
126         split = layout.split()
127
128         col = split.column()
129         col.label(text="Goal Strengths:")
130         col.prop(softbody, "goal_default", text="Default")
131         sub = col.column(align=True)
132         sub.prop(softbody, "goal_min", text="Minimum")
133         sub.prop(softbody, "goal_max", text="Maximum")
134
135         col = split.column()
136         col.label(text="Goal Settings:")
137         col.prop(softbody, "goal_spring", text="Stiffness")
138         col.prop(softbody, "goal_friction", text="Damping")
139
140         layout.prop_object(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
141
142
143 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, bpy.types.Panel):
144     bl_label = "Soft Body Edges"
145     bl_default_closed = True
146
147     @classmethod
148     def poll(cls, context):
149         return context.soft_body
150
151     def draw_header(self, context):
152         softbody = context.soft_body.settings
153
154         self.layout.active = softbody_panel_enabled(context.soft_body)
155         self.layout.prop(softbody, "use_edges", text="")
156
157     def draw(self, context):
158         layout = self.layout
159
160         md = context.soft_body
161         softbody = md.settings
162         ob = context.object
163
164         layout.active = softbody.use_edges and softbody_panel_enabled(md)
165
166         split = layout.split()
167
168         col = split.column()
169         col.label(text="Springs:")
170         col.prop(softbody, "pull")
171         col.prop(softbody, "push")
172         col.prop(softbody, "damp")
173         col.prop(softbody, "plastic")
174         col.prop(softbody, "bending")
175         col.prop(softbody, "spring_length", text="Length")
176         col.prop_object(softbody, "spring_vertex_group", ob, "vertex_groups", text="Springs:")
177
178         col = split.column()
179         col.prop(softbody, "stiff_quads")
180         sub = col.column()
181         sub.active = softbody.stiff_quads
182         sub.prop(softbody, "shear")
183
184         col.label(text="Aerodynamics:")
185         col.row().prop(softbody, "aerodynamics_type", expand=True)
186         col.prop(softbody, "aero", text="Factor")
187
188         #sub = col.column()
189         #sub.enabled = softbody.aero > 0
190
191
192         col.label(text="Collision:")
193         col.prop(softbody, "edge_collision", text="Edge")
194         col.prop(softbody, "face_collision", text="Face")
195
196
197 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, bpy.types.Panel):
198     bl_label = "Soft Body Self Collision"
199     bl_default_closed = True
200
201     @classmethod
202     def poll(cls, context):
203         return context.soft_body
204
205     def draw_header(self, context):
206         softbody = context.soft_body.settings
207
208         self.layout.active = softbody_panel_enabled(context.soft_body)
209         self.layout.prop(softbody, "self_collision", text="")
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.self_collision and softbody_panel_enabled(md)
218
219         layout.label(text="Collision Ball Size Calculation:")
220         layout.prop(softbody, "collision_type", expand=True)
221
222         col = layout.column(align=True)
223         col.label(text="Ball:")
224         col.prop(softbody, "ball_size", text="Size")
225         col.prop(softbody, "ball_stiff", text="Stiffness")
226         col.prop(softbody, "ball_damp", text="Dampening")
227
228
229 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, bpy.types.Panel):
230     bl_label = "Soft Body Solver"
231     bl_default_closed = True
232
233     @classmethod
234     def poll(cls, context):
235         return context.soft_body
236
237     def draw(self, context):
238         layout = self.layout
239
240         md = context.soft_body
241         softbody = md.settings
242
243         layout.active = softbody_panel_enabled(md)
244
245         # Solver
246         split = layout.split()
247
248         col = split.column(align=True)
249         col.label(text="Step Size:")
250         col.prop(softbody, "minstep")
251         col.prop(softbody, "maxstep")
252         col.prop(softbody, "use_auto_step", text="Auto-Step")
253
254         col = split.column()
255         col.prop(softbody, "error_limit")
256         col.label(text="Helpers:")
257         col.prop(softbody, "choke")
258         col.prop(softbody, "fuzzy")
259
260         layout.label(text="Diagnostics:")
261         layout.prop(softbody, "diagnose")
262         layout.prop(softbody, "estimate_matrix")
263
264
265 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, bpy.types.Panel):
266     bl_label = "Soft Body Field Weights"
267     bl_default_closed = True
268
269     @classmethod
270     def poll(cls, context):
271         return (context.soft_body)
272
273     def draw(self, context):
274         md = context.soft_body
275         softbody = md.settings
276
277         effector_weights_ui(self, context, softbody.effector_weights)
278
279
280 def register():
281     pass
282
283
284 def unregister():
285     pass
286
287 if __name__ == "__main__":
288     register()