Merge from trunk -r 24182:24247. Skipped change 24182 (merge of this branch into...
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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.baked == False
29
30
31 class PhysicButtonsPanel(bpy.types.Panel):
32     bl_space_type = 'PROPERTIES'
33     bl_region_type = 'WINDOW'
34     bl_context = "physics"
35
36     def poll(self, context):
37         ob = context.object
38         rd = context.scene.render_data
39         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
40
41
42 class PHYSICS_PT_softbody(PhysicButtonsPanel):
43     bl_label = "Soft Body"
44
45     def draw(self, context):
46         layout = self.layout
47
48         md = context.soft_body
49         ob = context.object
50
51         split = layout.split()
52         split.operator_context = "EXEC_DEFAULT"
53
54         if md:
55             # remove modifier + settings
56             split.set_context_pointer("modifier", md)
57             split.itemO("object.modifier_remove", text="Remove")
58
59             row = split.row(align=True)
60             row.itemR(md, "render", text="")
61             row.itemR(md, "realtime", text="")
62         else:
63             # add modifier
64             split.item_enumO("object.modifier_add", "type", 'SOFT_BODY', text="Add")
65             split.itemL("")
66
67         if md:
68             softbody = md.settings
69
70             # General
71             split = layout.split()
72             split.enabled = softbody_panel_enabled(md)
73
74             col = split.column()
75             col.itemL(text="Object:")
76             col.itemR(softbody, "mass")
77             col.itemR(softbody, "friction")
78
79             col = split.column()
80             col.itemL(text="Simulation:")
81             col.itemR(softbody, "speed")
82
83
84 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel):
85     bl_label = "Soft Body Cache"
86     bl_default_closed = True
87
88     def poll(self, context):
89         return context.soft_body
90
91     def draw(self, context):
92         md = context.soft_body
93         point_cache_ui(self, md.point_cache, softbody_panel_enabled(md), 0, 0)
94
95
96 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel):
97     bl_label = "Soft Body Goal"
98     bl_default_closed = True
99
100     def poll(self, context):
101         return context.soft_body
102
103     def draw_header(self, context):
104         softbody = context.soft_body.settings
105
106         self.layout.active = softbody_panel_enabled(context.soft_body)
107         self.layout.itemR(softbody, "use_goal", text="")
108
109     def draw(self, context):
110         layout = self.layout
111
112         md = context.soft_body
113         softbody = md.settings
114         ob = context.object
115
116         layout.active = softbody.use_goal and softbody_panel_enabled(md)
117
118         split = layout.split()
119
120         # Goal
121         split = layout.split()
122
123         col = split.column()
124         col.itemL(text="Goal Strengths:")
125         col.itemR(softbody, "goal_default", text="Default")
126         sub = col.column(align=True)
127         sub.itemR(softbody, "goal_min", text="Minimum")
128         sub.itemR(softbody, "goal_max", text="Maximum")
129
130         col = split.column()
131         col.itemL(text="Goal Settings:")
132         col.itemR(softbody, "goal_spring", text="Stiffness")
133         col.itemR(softbody, "goal_friction", text="Damping")
134
135         layout.item_pointerR(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
136
137
138 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel):
139     bl_label = "Soft Body Edges"
140     bl_default_closed = True
141
142     def poll(self, context):
143         return context.soft_body
144
145     def draw_header(self, context):
146         softbody = context.soft_body.settings
147
148         self.layout.active = softbody_panel_enabled(context.soft_body)
149         self.layout.itemR(softbody, "use_edges", text="")
150
151     def draw(self, context):
152         layout = self.layout
153
154         md = context.soft_body
155         softbody = md.settings
156         ob = context.object
157
158         layout.active = softbody.use_edges and softbody_panel_enabled(md)
159
160         split = layout.split()
161
162         col = split.column()
163         col.itemL(text="Springs:")
164         col.itemR(softbody, "pull")
165         col.itemR(softbody, "push")
166         col.itemR(softbody, "damp")
167         col.itemR(softbody, "plastic")
168         col.itemR(softbody, "bending")
169         col.itemR(softbody, "spring_length", text="Length")
170
171         col = split.column()
172         col.itemR(softbody, "stiff_quads")
173         sub = col.column()
174         sub.active = softbody.stiff_quads
175         sub.itemR(softbody, "shear")
176
177         col.itemR(softbody, "new_aero", text="Aero")
178         sub = col.column()
179         sub.enabled = softbody.new_aero
180         sub.itemR(softbody, "aero", text="Factor")
181
182         col.itemL(text="Collision:")
183         col.itemR(softbody, "edge_collision", text="Edge")
184         col.itemR(softbody, "face_collision", text="Face")
185
186
187 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel):
188     bl_label = "Soft Body Collision"
189     bl_default_closed = True
190
191     def poll(self, context):
192         return context.soft_body
193
194     def draw_header(self, context):
195         softbody = context.soft_body.settings
196
197         self.layout.active = softbody_panel_enabled(context.soft_body)
198         self.layout.itemR(softbody, "self_collision", text="")
199
200     def draw(self, context):
201         layout = self.layout
202
203         md = context.soft_body
204         softbody = md.settings
205         ob = context.object
206
207         layout.active = softbody.self_collision and softbody_panel_enabled(md)
208
209         layout.itemL(text="Collision Type:")
210         layout.itemR(softbody, "collision_type", expand=True)
211
212         col = layout.column(align=True)
213         col.itemL(text="Ball:")
214         col.itemR(softbody, "ball_size", text="Size")
215         col.itemR(softbody, "ball_stiff", text="Stiffness")
216         col.itemR(softbody, "ball_damp", text="Dampening")
217
218
219 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel):
220     bl_label = "Soft Body Solver"
221     bl_default_closed = True
222
223     def poll(self, context):
224         return context.soft_body
225
226     def draw(self, context):
227         layout = self.layout
228
229         md = context.soft_body
230         softbody = md.settings
231         ob = context.object
232
233         layout.active = softbody_panel_enabled(md)
234
235         # Solver
236         split = layout.split()
237
238         col = split.column(align=True)
239         col.itemL(text="Step Size:")
240         col.itemR(softbody, "minstep")
241         col.itemR(softbody, "maxstep")
242         col.itemR(softbody, "auto_step", text="Auto-Step")
243
244         col = split.column()
245         col.itemR(softbody, "error_limit")
246         col.itemL(text="Helpers:")
247         col.itemR(softbody, "choke")
248         col.itemR(softbody, "fuzzy")
249
250         layout.itemL(text="Diagnostics:")
251         layout.itemR(softbody, "diagnose")
252
253
254 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel):
255     bl_label = "Soft Body Field Weights"
256     bl_default_closed = True
257
258     def poll(self, context):
259         return (context.soft_body)
260
261     def draw(self, context):
262         md = context.soft_body
263         softbody = md.settings
264         effector_weights_ui(self, softbody.effector_weights)
265
266 bpy.types.register(PHYSICS_PT_softbody)
267 bpy.types.register(PHYSICS_PT_softbody_cache)
268 bpy.types.register(PHYSICS_PT_softbody_goal)
269 bpy.types.register(PHYSICS_PT_softbody_edge)
270 bpy.types.register(PHYSICS_PT_softbody_collision)
271 bpy.types.register(PHYSICS_PT_softbody_solver)
272 bpy.types.register(PHYSICS_PT_softbody_field_weights)