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