2.5 Single Column Layout:
[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, "friction")
77             col.itemR(softbody, "mass")
78             col.item_pointerR(softbody, "mass_vertex_group", ob, "vertex_groups", text="Mass:")
79
80             col = split.column()
81             col.itemL(text="Simulation:")
82             col.itemR(softbody, "speed")
83
84
85 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel):
86     bl_label = "Soft Body Cache"
87     bl_default_closed = True
88
89     def poll(self, context):
90         return context.soft_body
91
92     def draw(self, context):
93         md = context.soft_body
94         point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 0, 0)
95
96
97 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel):
98     bl_label = "Soft Body Goal"
99     bl_default_closed = True
100
101     def poll(self, context):
102         return context.soft_body
103
104     def draw_header(self, context):
105         softbody = context.soft_body.settings
106
107         self.layout.active = softbody_panel_enabled(context.soft_body)
108         self.layout.itemR(softbody, "use_goal", text="")
109
110     def draw(self, context):
111         layout = self.layout
112
113         md = context.soft_body
114         softbody = md.settings
115         ob = context.object
116
117         layout.active = softbody.use_goal and softbody_panel_enabled(md)
118
119         split = layout.split()
120
121         # Goal
122         split = layout.split()
123
124         col = split.column()
125         col.itemL(text="Goal Strengths:")
126         col.itemR(softbody, "goal_default", text="Default")
127         sub = col.column(align=True)
128         sub.itemR(softbody, "goal_min", text="Minimum")
129         sub.itemR(softbody, "goal_max", text="Maximum")
130
131         col = split.column()
132         col.itemL(text="Goal Settings:")
133         col.itemR(softbody, "goal_spring", text="Stiffness")
134         col.itemR(softbody, "goal_friction", text="Damping")
135
136         layout.item_pointerR(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
137
138
139 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel):
140     bl_label = "Soft Body Edges"
141     bl_default_closed = True
142
143     def poll(self, context):
144         return context.soft_body
145
146     def draw_header(self, context):
147         softbody = context.soft_body.settings
148
149         self.layout.active = softbody_panel_enabled(context.soft_body)
150         self.layout.itemR(softbody, "use_edges", text="")
151
152     def draw(self, context):
153         layout = self.layout
154
155         md = context.soft_body
156         softbody = md.settings
157         ob = context.object
158
159         layout.active = softbody.use_edges and softbody_panel_enabled(md)
160
161         split = layout.split()
162
163         col = split.column()
164         col.itemL(text="Springs:")
165         col.itemR(softbody, "pull")
166         col.itemR(softbody, "push")
167         col.itemR(softbody, "damp")
168         col.itemR(softbody, "plastic")
169         col.itemR(softbody, "bending")
170         col.itemR(softbody, "spring_length", text="Length")
171         col.item_pointerR(softbody, "spring_vertex_group", ob, "vertex_groups", text="Springs:")
172
173         col = split.column()
174         col.itemR(softbody, "stiff_quads")
175         sub = col.column()
176         sub.active = softbody.stiff_quads
177         sub.itemR(softbody, "shear")
178
179         col.itemR(softbody, "new_aero", text="Aero")
180         sub = col.column()
181         sub.enabled = softbody.new_aero
182         sub.itemR(softbody, "aero", text="Factor")
183
184         col.itemL(text="Collision:")
185         col.itemR(softbody, "edge_collision", text="Edge")
186         col.itemR(softbody, "face_collision", text="Face")
187
188
189 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel):
190     bl_label = "Soft Body Collision"
191     bl_default_closed = True
192
193     def poll(self, context):
194         return context.soft_body
195
196     def draw_header(self, context):
197         softbody = context.soft_body.settings
198
199         self.layout.active = softbody_panel_enabled(context.soft_body)
200         self.layout.itemR(softbody, "self_collision", text="")
201
202     def draw(self, context):
203         layout = self.layout
204
205         md = context.soft_body
206         softbody = md.settings
207
208         layout.active = softbody.self_collision and softbody_panel_enabled(md)
209
210         layout.itemL(text="Collision Type:")
211         layout.itemR(softbody, "collision_type", expand=True)
212
213         col = layout.column(align=True)
214         col.itemL(text="Ball:")
215         col.itemR(softbody, "ball_size", text="Size")
216         col.itemR(softbody, "ball_stiff", text="Stiffness")
217         col.itemR(softbody, "ball_damp", text="Dampening")
218
219
220 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel):
221     bl_label = "Soft Body Solver"
222     bl_default_closed = True
223
224     def poll(self, context):
225         return context.soft_body
226
227     def draw(self, context):
228         layout = self.layout
229
230         md = context.soft_body
231         softbody = md.settings
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, context, 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)