c17d6e3bcf9fca7db109c28e6e604ebbef6dea11
[blender.git] / release / ui / buttons_physics_softbody.py
1
2 import bpy
3
4 class PhysicButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.object
11                 rd = context.scene.render_data
12                 return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
13                 
14 class PHYSICS_PT_softbody(PhysicButtonsPanel):
15         __label__ = "Soft Body"
16
17         def draw(self, context):
18                 layout = self.layout
19                 
20                 md = context.soft_body
21                 ob = context.object
22
23                 split = layout.split()
24                 split.operator_context = "EXEC_DEFAULT"
25
26                 if md:
27                         # remove modifier + settings
28                         split.set_context_pointer("modifier", md)
29                         split.itemO("object.modifier_remove", text="Remove")
30
31                         row = split.row(align=True)
32                         row.itemR(md, "render", text="")
33                         row.itemR(md, "realtime", text="")
34                 else:
35                         # add modifier
36                         split.item_enumO("object.modifier_add", "type", 'SOFT_BODY', text="Add")
37                         split.itemL("")
38                         
39                 if md:
40                         softbody = md.settings
41
42                         # General
43                         split = layout.split()
44                         
45                         col = split.column()
46                         col.itemL(text="Object:")
47                         col.itemR(softbody, "mass")
48                         col.itemR(softbody, "friction")
49
50                         col = split.column()
51                         col.itemL(text="Simulation:")
52                         col.itemR(softbody, "gravity")
53                         col.itemR(softbody, "speed")
54                         
55 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel):
56         __label__ = "Soft Body Cache"
57         __default_closed__ = True
58
59         def poll(self, context):
60                 return (context.soft_body)
61
62         def draw(self, context):
63                 layout = self.layout
64
65                 cache = context.soft_body.point_cache
66                 
67                 row = layout.row()
68                 row.itemR(cache, "name")
69                 
70                 row = layout.row()
71                 row.itemR(cache, "start_frame")
72                 row.itemR(cache, "end_frame")
73                 
74                 row = layout.row()
75                 
76                 if cache.baked == True:
77                         row.itemO("ptcache.free_bake_softbody", text="Free Bake")
78                 else:
79                         row.item_booleanO("ptcache.cache_softbody", "bake", True, text="Bake")
80                 
81                 sub = row.row()
82                 sub.enabled = cache.frames_skipped or cache.outdated
83                 sub.itemO("ptcache.cache_softbody", text="Calculate to Current Frame")
84                         
85                 row = layout.row()
86                 row.itemO("ptcache.bake_from_softbody_cache", text="Current Cache to Bake")
87                 row.itemR(cache, "step");
88         
89                 row = layout.row()
90                 row.itemR(cache, "quick_cache")
91                 row.itemR(cache, "disk_cache")
92                 
93                 layout.itemL(text=cache.info)
94                 
95                 layout.itemS()
96                 
97                 row = layout.row()
98                 row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics")
99                 row.itemO("ptcache.free_bake_all", text="Free All Bakes")
100                 layout.itemO("ptcache.bake_all", text="Update All Dynamics to current frame")
101                 
102 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel):
103         __label__ = "Soft Body Goal"
104         
105         def poll(self, context):
106                 return (context.soft_body)
107                 
108         def draw_header(self, context):
109                 layout = self.layout
110                 
111                 softbody = context.soft_body.settings
112         
113                 layout.itemR(softbody, "use_goal", text="")
114                 
115         def draw(self, context):
116                 layout = self.layout
117                 
118                 md = context.soft_body
119                 ob = context.object
120
121                 split = layout.split()
122                         
123                 if md:
124                         softbody = md.settings
125                         layout.active = softbody.use_goal
126
127                         # Goal 
128                         split = layout.split()
129
130                         col = split.column()
131                         col.itemL(text="Goal Strengths:")
132                         col.itemR(softbody, "goal_default", text="Default")
133                         sub = col.column(align=True)
134                         sub.itemR(softbody, "goal_min", text="Minimum")
135                         sub.itemR(softbody, "goal_max", text="Maximum")
136                         
137                         col = split.column()
138                         col.itemL(text="Goal Settings:")
139                         col.itemR(softbody, "goal_spring", text="Stiffness")
140                         col.itemR(softbody, "goal_friction", text="Damping")
141                         
142                         layout.item_pointerR(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
143
144 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel):
145         __label__ = "Soft Body Edges"
146         
147         def poll(self, context):
148                 return (context.soft_body)
149                 
150         def draw_header(self, context):
151                 layout = self.layout
152                 
153                 softbody = context.soft_body.settings
154         
155                 layout.itemR(softbody, "use_edges", text="")
156                 
157         def draw(self, context):
158                 layout = self.layout
159                 
160                 md = context.soft_body
161                 ob = context.object
162                         
163                 if md:
164                         softbody = md.settings
165                         
166                         layout.active = softbody.use_edges
167                         
168                         split = layout.split()
169                         
170                         col = split.column()
171                         col.itemL(text="Springs:")
172                         col.itemR(softbody, "pull")
173                         col.itemR(softbody, "push")
174                         col.itemR(softbody, "damp")
175                         col.itemR(softbody, "plastic")
176                         col.itemR(softbody, "bending")
177                         col.itemR(softbody, "spring_length", text="Length")
178                         
179                         col = split.column()
180                         col.itemR(softbody, "stiff_quads")
181                         sub = col.column()
182                         sub.active = softbody.stiff_quads
183                         sub.itemR(softbody, "shear")
184                         
185                         col.itemR(softbody, "new_aero", text="Aero")
186                         sub = col.column()
187                         sub.enabled = softbody.new_aero
188                         sub.itemR(softbody, "aero", text="Factor")
189
190                         col.itemL(text="Collision:")
191                         col.itemR(softbody, "edge_collision", text="Edge")
192                         col.itemR(softbody, "face_collision", text="Face")
193                         
194 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel):
195         __label__ = "Soft Body Collision"
196         
197         def poll(self, context):
198                 return (context.soft_body)
199                 
200         def draw_header(self, context):
201                 layout = self.layout
202                 
203                 softbody = context.soft_body.settings
204         
205                 layout.itemR(softbody, "self_collision", text="")
206                 
207         def draw(self, context):
208                 layout = self.layout
209                 
210                 md = context.soft_body
211                 ob = context.object
212                         
213                 if md:
214                         softbody = md.settings
215
216                         layout.active = softbody.self_collision
217                         
218                         layout.itemL(text="Collision Type:")
219                         layout.itemR(softbody, "collision_type", expand=True)
220                         
221                         col = layout.column(align=True)
222                         col.itemL(text="Ball:")
223                         col.itemR(softbody, "ball_size", text="Size")
224                         col.itemR(softbody, "ball_stiff", text="Stiffness")
225                         col.itemR(softbody, "ball_damp", text="Dampening")
226
227 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel):
228         __label__ = "Soft Body Solver"
229         
230         def poll(self, context):
231                 return (context.soft_body)
232                 
233         def draw(self, context):
234                 layout = self.layout
235                 
236                 md = context.soft_body
237                 ob = context.object
238                 
239                 if md:
240                         softbody = md.settings
241
242                         # Solver
243                         split = layout.split()
244                         
245                         col = split.column(align=True)
246                         col.itemL(text="Step Size:")
247                         col.itemR(softbody, "minstep")
248                         col.itemR(softbody, "maxstep")
249                         col.itemR(softbody, "auto_step", text="Auto-Step")
250                         
251                         col = split.column()
252                         col.itemR(softbody, "error_limit")
253                         col.itemL(text="Helpers:")
254                         col.itemR(softbody, "choke")
255                         col.itemR(softbody, "fuzzy")
256                         
257                         layout.itemL(text="Diagnostics:")
258                         layout.itemR(softbody, "diagnose")
259         
260 bpy.types.register(PHYSICS_PT_softbody)
261 bpy.types.register(PHYSICS_PT_softbody_cache)
262 bpy.types.register(PHYSICS_PT_softbody_goal)
263 bpy.types.register(PHYSICS_PT_softbody_edge)
264 bpy.types.register(PHYSICS_PT_softbody_collision)
265 bpy.types.register(PHYSICS_PT_softbody_solver)